Skip to content

Commit

Permalink
Improved csg error detection and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
arnholm committed Nov 21, 2020
1 parent 97e40b9 commit cf07e71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions csg_parser/csg_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ size_t csg_node::dimension()
else if(this_tag == "polyhedron")dim=3;
else if(this_tag == "linear_extrude")dim=3;
else if(this_tag == "rotate_extrude")dim=3;
else if(this_tag == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'text' is not supported, line\n"+ m_func);
else if(this_tag == "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'surface' is not supported\n"+ m_func );
else if(this_tag == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'import' is not supported\n"+ m_func);
else if(this_tag == "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'resize' is not supported\n"+ m_func);
else if(this_tag == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'text' is not supported: "+ m_func);
else if(this_tag == "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'surface' is not supported: "+ m_func );
else if(this_tag == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'import' is not supported with this file type: "+ m_func);
else if(this_tag == "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'resize' is not supported: "+ m_func);

if(dim>0)return dim;

Expand Down Expand Up @@ -350,10 +350,10 @@ size_t csg_node::dimension()
else if(c->tag().substr(0,4) == "rend")dim= c->dimension();
else if(c->tag().substr(0,4) == "hull")dim= c->dimension();

else if(c->tag() == "text") throw std::runtime_error("OpenSCAD csg: 'text' is not supported, line "+ std::to_string(m_line_no));
else if(c->tag() == "surface") throw std::runtime_error("OpenSCAD csg: 'surface' is not supported, line "+ std::to_string(m_line_no));
else if(c->tag() == "import") throw std::runtime_error("OpenSCAD csg: 'import' is not supported, line "+ std::to_string(m_line_no));
else if(c->tag() == "resize") throw std::runtime_error("OpenSCAD csg: 'resize' is not supported, line "+ std::to_string(m_line_no));
else if(c->tag() == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'text' is not supported: "+ c->func());
else if(c->tag()== "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'surface' is not supported: "+ c->func() );
else if(c->tag() == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'import' is not supported with this file type: "+ c->func());
else if(c->tag()== "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'resize' is not supported: "+ c->func());

if(dim>0)return dim;
}
Expand Down
5 changes: 5 additions & 0 deletions csg_parser/csg_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class csg_node {
// return naked function name
std::string tag() const;

// return full function string
std::string func() const { return m_func; }

size_t line_no() const { return m_line_no; }

// look up parameter
par_iterator par_find(const std::string& name) { return m_par.find(name); };
par_iterator par_begin() { return m_par.begin(); }
Expand Down
2 changes: 2 additions & 0 deletions csg_parser/csg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void csg_parser::init_func(const std::string& csg)

}

if(func.size() == 0) throw std::runtime_error("csg tree has 0 elements!");

// build the tree
size_t index = 0;
m_root->build_tree(func,index);
Expand Down

0 comments on commit cf07e71

Please sign in to comment.