Skip to content

Commit ddef0da

Browse files
author
Luke Brooks
committed
Merge branch 'master' of https://github.com/LukeB42/IfcOpenShell
2 parents 71b0e22 + ebfe8f9 commit ddef0da

File tree

20 files changed

+459
-93
lines changed

20 files changed

+459
-93
lines changed

src/ifcconvert/IfcConvert.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int main(int argc, char** argv)
322322
print_usage();
323323
return EXIT_FAILURE;
324324
} catch (...) {
325+
std::cerr << "[Error] Unknown error parsing command line options\n\n";
325326
print_usage();
326327
return EXIT_FAILURE;
327328
}
@@ -441,7 +442,9 @@ int main(int argc, char** argv)
441442
rename_file(output_temp_filename, output_filename);
442443
exit_code = EXIT_SUCCESS;
443444
}
444-
} catch (...) {}
445+
} catch (const std::exception& e) {
446+
Logger::Error(e);
447+
}
445448
write_log();
446449
return exit_code;
447450
}
@@ -704,6 +707,7 @@ bool init_input_file(const std::string &filename, IfcParse::IfcFile &ifc_file, b
704707
#ifdef USE_MMAP
705708
if (!ifc_file.Init(filename, mmap)) {
706709
#else
710+
(void)mmap;
707711
if (!ifc_file.Init(filename)) {
708712
#endif
709713
Logger::Error("Unable to parse input file '" + filename + "'");

src/ifcconvert/XmlSerializer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, pt
149149
boost::optional<std::string> value;
150150
try {
151151
value = format_attribute(argument, argument_type, qualified_name);
152-
} catch (...) {}
152+
} catch (const std::exception& e) {
153+
Logger::Error(e);
154+
}
153155

154156
if (value) {
155157
if (as_link) {

src/ifcexpressparser/header.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# #
1818
###############################################################################
1919

20+
import operator
21+
2022
import codegen
2123
import templates
2224
import documentation
@@ -106,8 +108,14 @@ def case_norm(n):
106108
argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
107109

108110
argument_name_function_body = argument_name_function_body_switch_stmt + argument_name_function_body_tail
109-
110-
argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
111+
112+
derived = mapping.derived_in_supertype(type)
113+
attribute_names = list(map(operator.attrgetter('name'), mapping.arguments(type)))
114+
derived_in_supertype = set(derived) & set(attribute_names)
115+
derived_in_supertype_indices = sorted(attribute_names.index(nm) for nm in derived_in_supertype)
116+
attribute_type_cases = ['case %d: return IfcUtil::Argument_DERIVED; ' % idx for idx in derived_in_supertype_indices]
117+
attribute_type_cases += ['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)]
118+
argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(attribute_type_cases)) if len(type.attributes) else ""
111119
argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' (void)i; throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
112120

113121
argument_type_function_body = argument_type_function_body_switch_stmt + argument_type_function_body_tail

src/ifcgeom/IfcGeomElement.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ namespace IfcGeom {
142142
} else {
143143
try {
144144
oss << "product-" << IfcParse::IfcGlobalId(guid).formatted();
145-
} catch (const std::exception&) {
145+
} catch (const std::exception& e) {
146146
oss << "product";
147+
Logger::Error(e);
147148
}
148149
}
149150

src/ifcgeom/IfcGeomFilter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ namespace IfcGeom
189189
IfcUtil::IfcBaseClass* base = IfcSchema::SchemaEntity(&dummy);
190190
try {
191191
ss << " " << IfcSchema::Type::ToString(it->first) << "." << base->getArgumentName(it->second);
192-
} catch(...) {}
192+
} catch (const std::exception& e) {
193+
Logger::Error(e);
194+
}
193195
delete base;
194196
}
195197

src/ifcgeom/IfcGeomFunctions.cpp

Lines changed: 102 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,15 @@ bool IfcGeom::Kernel::create_solid_from_faces(const TopTools_ListOfShape& face_l
177177
builder.Perform();
178178
shape = builder.SewedShape();
179179
valid_shell = BRepCheck_Analyzer(shape).IsValid() != 0 && count(shape, TopAbs_SHELL) > 0;
180-
} catch (...) {}
180+
} catch (const Standard_Failure& e) {
181+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
182+
Logger::Error(e.GetMessageString());
183+
} else {
184+
Logger::Error("Unknown error sewing shell");
185+
}
186+
} catch (...) {
187+
Logger::Error("Unknown error sewing shell");
188+
}
181189

182190
if (valid_shell) {
183191
TopoDS_Shape complete_shape;
@@ -197,9 +205,25 @@ bool IfcGeom::Kernel::create_solid_from_faces(const TopTools_ListOfShape& face_l
197205
if (classifier.State() == TopAbs_IN) {
198206
shape.Reverse();
199207
}
200-
} catch (...) {}
208+
} catch (const Standard_Failure& e) {
209+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
210+
Logger::Error(e.GetMessageString());
211+
} else {
212+
Logger::Error("Unknown error classifying solid");
213+
}
214+
} catch (...) {
215+
Logger::Error("Unknown error classifying solid");
216+
}
217+
}
218+
} catch (const Standard_Failure& e) {
219+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
220+
Logger::Error(e.GetMessageString());
221+
} else {
222+
Logger::Error("Unknown error creating solid");
201223
}
202-
} catch (...) {}
224+
} catch (...) {
225+
Logger::Error("Unknown error creating solid");
226+
}
203227

204228
if (complete_shape.IsNull()) {
205229
complete_shape = result_shape;
@@ -269,7 +293,11 @@ bool IfcGeom::Kernel::convert_openings(const IfcSchema::IfcProduct* entity, cons
269293
if (fes->hasObjectPlacement()) {
270294
try {
271295
convert(fes->ObjectPlacement(),opening_trsf);
272-
} catch (...) {}
296+
} catch (const std::exception& e) {
297+
Logger::Error(e);
298+
} catch (...) {
299+
Logger::Error("Failed to construct placement");
300+
}
273301
}
274302

275303
// Move the opening into the coordinate system of the IfcProduct
@@ -438,7 +466,11 @@ bool IfcGeom::Kernel::convert_openings_fast(const IfcSchema::IfcProduct* entity,
438466
if (fes->hasObjectPlacement()) {
439467
try {
440468
convert(fes->ObjectPlacement(),opening_trsf);
441-
} catch (...) {}
469+
} catch (const std::exception& e) {
470+
Logger::Error(e);
471+
} catch (...) {
472+
Logger::Error("Failed to construct placement");
473+
}
442474
}
443475

444476
// Move the opening into the coordinate system of the IfcProduct
@@ -513,7 +545,11 @@ bool IfcGeom::Kernel::convert_openings_fast(const IfcSchema::IfcProduct* entity,
513545
if (fes->hasObjectPlacement()) {
514546
try {
515547
convert(fes->ObjectPlacement(),opening_trsf);
516-
} catch (...) {}
548+
} catch (const std::exception& e) {
549+
Logger::Error(e);
550+
} catch (...) {
551+
Logger::Error("Failed to construct placement");
552+
}
517553
}
518554

519555
// Move the opening into the coordinate system of the IfcProduct
@@ -597,8 +633,17 @@ bool IfcGeom::Kernel::convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face&
597633
bool IfcGeom::Kernel::convert_curve_to_wire(const Handle(Geom_Curve)& curve, TopoDS_Wire& wire) {
598634
try {
599635
wire = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(curve));
600-
} catch(...) { return false; }
601-
return true;
636+
return true;
637+
} catch (const Standard_Failure& e) {
638+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
639+
Logger::Error(e.GetMessageString());
640+
} else {
641+
Logger::Error("Unknown error convering curve to wire");
642+
}
643+
} catch (...) {
644+
Logger::Error("Unknown error convering curve to wire");
645+
}
646+
return false;
602647
}
603648

604649
bool IfcGeom::Kernel::profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Shape& face_shape) {
@@ -717,10 +762,12 @@ gp_Pnt IfcGeom::Kernel::point_above_plane(const gp_Pln& pln, bool agree) {
717762
}
718763

719764
void IfcGeom::Kernel::apply_tolerance(TopoDS_Shape& s, double t) {
765+
/*
766+
// This does not result in actionable error messages and has been disabled.
720767
ShapeAnalysis_ShapeTolerance toler;
721768
if (Logger::LOG_WARNING >= Logger::Verbosity()) {
722-
if (toler.Tolerance(s, 0) > t + ALMOST_ZERO) {
723-
Handle_TopTools_HSequenceOfShape shapes = toler.OverTolerance(s, t + ALMOST_ZERO);
769+
if (toler.Tolerance(s, 0) > t * 10.) {
770+
Handle_TopTools_HSequenceOfShape shapes = toler.OverTolerance(s, t * 10.);
724771
for (int i = 1; i <= shapes->Length(); ++i) {
725772
const TopoDS_Shape& sub = shapes->Value(i);
726773
std::stringstream ss;
@@ -729,6 +776,7 @@ void IfcGeom::Kernel::apply_tolerance(TopoDS_Shape& s, double t) {
729776
}
730777
}
731778
}
779+
*/
732780
ShapeFix_ShapeTolerance tol;
733781
tol.LimitTolerance(s, t);
734782
}
@@ -896,7 +944,15 @@ bool IfcGeom::Kernel::fill_nonmanifold_wires_with_planar_faces(TopoDS_Shape& sha
896944
ShapeFix_Solid solid;
897945
solid.LimitTolerance(getValue(GV_POINT_EQUALITY_TOLERANCE));
898946
shape = solid.SolidFromShell(TopoDS::Shell(shape));
899-
} catch(...) {}
947+
} catch (const Standard_Failure& e) {
948+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
949+
Logger::Error(e.GetMessageString());
950+
} else {
951+
Logger::Error("Unknown error creating solid");
952+
}
953+
} catch (...) {
954+
Logger::Error("Unknown error creating solid");
955+
}
900956

901957
return true;
902958
}
@@ -1133,15 +1189,21 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_pro
11331189
if (parent_object) {
11341190
parent_id = parent_object->entity->id();
11351191
}
1136-
} catch (...) {}
1192+
} catch (const std::exception& e) {
1193+
Logger::Error(e);
1194+
}
11371195

11381196
const std::string name = product->hasName() ? product->Name() : "";
11391197
const std::string guid = product->GlobalId();
11401198

11411199
gp_Trsf trsf;
11421200
try {
11431201
convert(product->ObjectPlacement(),trsf);
1144-
} catch (...) {}
1202+
} catch (const std::exception& e) {
1203+
Logger::Error(e);
1204+
} catch (...) {
1205+
Logger::Error("Failed to construct placement");
1206+
}
11451207

11461208
// Does the IfcElement have any IfcOpenings?
11471209
// Note that openings for IfcOpeningElements are not processed
@@ -1225,15 +1287,21 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_processed_representati
12251287
if (parent_object) {
12261288
parent_id = parent_object->entity->id();
12271289
}
1228-
} catch (...) {}
1290+
} catch (const std::exception& e) {
1291+
Logger::Error(e);
1292+
}
12291293

12301294
const std::string name = product->hasName() ? product->Name() : "";
12311295
const std::string guid = product->GlobalId();
12321296

12331297
gp_Trsf trsf;
12341298
try {
12351299
convert(product->ObjectPlacement(),trsf);
1236-
} catch (...) {}
1300+
} catch (const std::exception& e) {
1301+
Logger::Error(e);
1302+
} catch (...) {
1303+
Logger::Error("Failed to construct placement");
1304+
}
12371305

12381306
std::string context_string = "";
12391307
if (representation->hasRepresentationIdentifier()) {
@@ -1486,9 +1554,16 @@ bool IfcGeom::Kernel::convert_layerset(const IfcSchema::IfcProduct* product, std
14861554
IfcSchema::IfcExtrudedAreaSolid* extrusion = *extrusions->begin();
14871555

14881556
gp_Trsf extrusion_position;
1489-
if (!convert(extrusion->Position(), extrusion_position)) {
1490-
Logger::Message(Logger::LOG_ERROR, "Failed to convert placement for extrusion of:", product->entity);
1491-
return false;
1557+
1558+
bool has_position = true;
1559+
#ifdef USE_IFC4
1560+
has_position = extrusion->hasPosition();
1561+
#endif
1562+
if (has_position) {
1563+
if (!convert(extrusion->Position(), extrusion_position)) {
1564+
Logger::Message(Logger::LOG_ERROR, "Failed to convert placement for extrusion of:", product->entity);
1565+
return false;
1566+
}
14921567
}
14931568

14941569
gp_Dir extrusion_direction;
@@ -2255,7 +2330,15 @@ bool IfcGeom::Kernel::split_solid_by_shell(const TopoDS_Shape& input, const Topo
22552330
if (fix.Perform()) {
22562331
shape = fix.Shape();
22572332
}
2258-
} catch(...) {}
2333+
} catch (const Standard_Failure& e) {
2334+
if (e.GetMessageString() && strlen(e.GetMessageString())) {
2335+
Logger::Error(e.GetMessageString());
2336+
} else {
2337+
Logger::Error("Unknown error performing fixes");
2338+
}
2339+
} catch (...) {
2340+
Logger::Error("Unknown error performing fixes");
2341+
}
22592342
BRepCheck_Analyzer analyser(shape);
22602343
bool is_valid = analyser.IsValid() != 0;
22612344
if (!is_valid) {

0 commit comments

Comments
 (0)