Geogram Version 1.9.7
A programming library of geometric algorithms
Loading...
Searching...
No Matches
mesh_CSG_compiler.h
1/*
2 * Copyright (c) 2000-2025 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef H_GEOGRAM_MESH_MESH_CSG_COMPILER_H
41#define H_GEOGRAM_MESH_MESH_CSG_COMPILER_H
42
44#include <geogram/mesh/mesh_CSG_builder.h>
45
46#include <filesystem>
47#include <map>
48
49namespace GEO {
50
51 class ProgressTask;
52
57 class GEOGRAM_API CSGCompiler {
58 public:
59
60 typedef GEOCSG::Value Value;
62
64
65 std::shared_ptr<Mesh> compile_file(
66 const std::filesystem::path& input_filename
67 );
68 std::shared_ptr<Mesh> compile_string(const std::string& source);
69
75 void set_verbose(bool x) {
76 builder_->set_verbose(x);
77 }
78
84 void set_detailed_verbose(bool x) {
85 builder_->set_detailed_verbose(x);
86 }
87
93 return *builder_;
94 }
95
100 const CSGBuilder& builder() const {
101 return *builder_;
102 }
103
104 protected:
105
106 /***** Parser *******************************************/
107
108 void parse_instruction_or_object();
109 void parse_object();
110 void parse_instruction();
111 ArgList parse_arg_list();
112 Value parse_value();
113 Value parse_array();
114 bool is_object(const std::string& id) const;
115 bool is_instruction(const std::string& id) const;
116
126 bool is_modifier(int toktype) const;
127
128 /***** Parser internals ********************************/
129
130 struct Token {
131 Token();
132 std::string to_string() const;
133 int type;
134 std::string str_val;
135 int int_val;
136 double double_val;
137 bool boolean_val;
138 };
139
146 void next_token_check(char c);
147
153
159
167
171 int lines() const;
172
176 int line() const;
177
182 [[noreturn]] void syntax_error(const char* msg);
183
190 [[noreturn]] void syntax_error(const char* msg, const Token& tok);
191
192 protected:
193 void compute_lines() const;
194
195 private:
196 std::filesystem::path filename_;
197 void* lex_;
198 Token lookahead_token_;
199 ProgressTask* progress_;
200 std::shared_ptr<CSGBuilder> builder_;
201 mutable index_t lines_;
202 mutable index_t line_;
203 mutable const char* line_ptr_;
204 };
205
206}
207
208#endif
A parsed argument list in a .csg file.
Implements CSG objects and instructions.
Creates meshes from OpenSCAD .csg files.
void syntax_error(const char *msg, const Token &tok)
Throws an exception with an error message.
Token next_token_internal()
Function to actually get the next token from the stream.
bool is_modifier(int toktype) const
Checks if a token corresponds to an instruction or object modifier.
const CSGBuilder & builder() const
Gets the CSGbuilder.
void next_token_check(char c)
Checks that the next token is a given character.
int line() const
Gets the currently parsed line source.
void set_detailed_verbose(bool x)
Displays (even more) additional information.
Token lookahead_token()
Gets the next token without any side effect.
void set_verbose(bool x)
Displays (lots of) additional information.
CSGBuilder & builder()
Gets the CSGbuilder.
void syntax_error(const char *msg)
Throws an exception with an error message.
Token next_token()
Gets the next token.
int lines() const
Gets the total number of lines of the currently parsed source.
Tracks the progress of a task.
Definition progress.h:240
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
A parsed value in a .csg file.