diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 90697d839e..a29ddd66cc 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -551,7 +551,7 @@ if(NOT MSVC) endif() endif() -set(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom IfcGeom_ifc2x3 IfcGeom_ifc4 Iterator) +set(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom_ifc2x3 IfcGeom_ifc4 Iterator) # IfcParse file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index d0f9e46f6a..88e3e74bb1 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -148,7 +148,7 @@ void parse_filter(geom_filter &, const std::vector&); std::vector setup_filters(const std::vector&, const std::string&); */ -bool init_input_file(const std::string& filename, IfcParse::IfcFile& ifc_file, bool no_progress, bool mmap); +bool init_input_file(const std::string& filename, IfcParse::IfcFile* ifc_file, bool no_progress, bool mmap); int main(int argc, char** argv) { @@ -440,7 +440,7 @@ int main(int argc, char** argv) Logger::SetOutput(&std::cout, &log_stream); Logger::Verbosity(verbose ? Logger::LOG_NOTICE : Logger::LOG_ERROR); - IfcParse::IfcFile ifc_file; + IfcParse::IfcFile* ifc_file = 0; /* if (!filter_filename.empty()) { @@ -576,7 +576,7 @@ int main(int argc, char** argv) return EXIT_FAILURE; } - IfcGeom::Iterator context_iterator(settings, &ifc_file); + IfcGeom::Iterator context_iterator(settings, ifc_file); if (!context_iterator.initialize()) { /// @todo It would be nice to know and print separate error prints for a case where we found no entities /// and for a case we found no entities that satisfy our filtering criteria. diff --git a/src/ifcconvert/WavefrontObjSerializer.cpp b/src/ifcconvert/WavefrontObjSerializer.cpp index 26b8b39306..259030f496 100644 --- a/src/ifcconvert/WavefrontObjSerializer.cpp +++ b/src/ifcconvert/WavefrontObjSerializer.cpp @@ -20,7 +20,7 @@ #include "WavefrontObjSerializer.h" -#include "../ifcgeom/IfcGeomRenderStyles.h" +#include "../iterator/IfcGeomRenderStyles.h" #include #include diff --git a/src/ifcexpressparser/implementation.py b/src/ifcexpressparser/implementation.py index 915dee134b..2ced238fff 100644 --- a/src/ifcexpressparser/implementation.py +++ b/src/ifcexpressparser/implementation.py @@ -203,6 +203,11 @@ class Implementation(codegen.Base): simple_type_impl = [] for class_name, type in mapping.schema.simpletypes.items(): + if class_name == "IfcPropertySetDefinitionSet": + print(repr(type), type) + print(mapping.flatten_type_string(type)) + print(mapping.make_type_string(mapping.flatten_type_string(type))) + type_str = mapping.make_type_string(mapping.flatten_type_string(type)) attr_type = mapping.make_argument_type(type) superclass = mapping.simple_type_parent(class_name) diff --git a/src/ifcexpressparser/mapping.py b/src/ifcexpressparser/mapping.py index 02696d2f89..ef80b97fd4 100644 --- a/src/ifcexpressparser/mapping.py +++ b/src/ifcexpressparser/mapping.py @@ -58,7 +58,7 @@ class Mapping: def make_type_string(self, type): if isinstance(type, (str, nodes.BinaryType, nodes.StringType)): - return self.express_to_cpp_typemapping.get(str(type), type) + return self.express_to_cpp_typemapping.get(str(type), "::%s::%s" % (self.schema.name.capitalize(), type)) else: is_list = self.schema.is_entity(type.type) is_nested_list = isinstance(type.type, nodes.AggregationType) diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index dcf3e1ffb8..84eead4cba 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -53,6 +53,9 @@ inline static bool ALMOST_THE_SAME(const T& a, const T& b, double tolerance=ALMO #include "../ifcgeom/IfcGeomRepresentation.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" #include "../ifcgeom/IfcGeomShapeType.h" + +#include "../iterator/Kernel.h" + #include "ifc_geom_api.h" // Define this in case you want to conserve memory usage at all cost. This has been @@ -72,15 +75,19 @@ if ( it != cache.T.end() ) { e = it->second; return true; } #endif +#define MAKE_TYPE_NAME__(a, b) a ## b +#define MAKE_TYPE_NAME_(a, b) MAKE_TYPE_NAME__(a, b) +#define MAKE_TYPE_NAME(t) MAKE_TYPE_NAME_(t, IfcSchema) + namespace IfcGeom { -class IFC_GEOM_API Cache { +class IFC_GEOM_API MAKE_TYPE_NAME(Cache) { public: #include "IfcRegisterCreateCache.h" std::map Shape; }; -class IFC_GEOM_API Kernel { +class IFC_GEOM_API MAKE_TYPE_NAME(Kernel) : public IfcGeom::Kernel { private: double deflection_tolerance; @@ -93,7 +100,7 @@ private: double dimensionality; #ifndef NO_CACHE - Cache cache; + MAKE_TYPE_NAME(Cache) cache; #endif std::map style_cache; @@ -104,7 +111,7 @@ private: const IfcParse::declaration* placement_rel_to; public: - Kernel() + MAKE_TYPE_NAME(Kernel)() : deflection_tolerance(0.001) , wire_creation_tolerance(0.0001) , point_equality_tolerance(0.00001) @@ -116,11 +123,11 @@ public: , placement_rel_to(0) {} - Kernel(const Kernel& other) { + MAKE_TYPE_NAME(Kernel)(const MAKE_TYPE_NAME(Kernel)& other) { *this = other; } - Kernel& operator=(const Kernel& other) { + MAKE_TYPE_NAME(Kernel)& operator=(const MAKE_TYPE_NAME(Kernel)& other) { setValue(GV_DEFLECTION_TOLERANCE, other.getValue(GV_DEFLECTION_TOLERANCE)); setValue(GV_WIRE_CREATION_TOLERANCE, other.getValue(GV_WIRE_CREATION_TOLERANCE)); setValue(GV_POINT_EQUALITY_TOLERANCE, other.getValue(GV_POINT_EQUALITY_TOLERANCE)); @@ -133,40 +140,6 @@ public: return *this; } - // Tolerances and settings for various geometrical operations: - enum GeomValue { - // Specifies the deflection of the mesher - // Default: 0.001m / 1mm - GV_DEFLECTION_TOLERANCE, - // Specifies the tolerance of the wire builder, most notably for trimmed curves - // Defailt: 0.0001m / 0.1mm - GV_WIRE_CREATION_TOLERANCE, - // Specifies the minimal area of a face to be included in an IfcConnectedFaceset - // Read-only - GV_MINIMAL_FACE_AREA, - // Specifies the treshold distance under which cartesian points are deemed equal - // Default: 0.00001m / 0.01mm - GV_POINT_EQUALITY_TOLERANCE, - // Specifies maximum number of faces for a shell to be sewed. Sewing shells - // that consist of many faces is really detrimental for the performance. - // Default: 1000 - GV_MAX_FACES_TO_SEW, - // The length unit used the creation of TopoDS_Shapes, primarily affects the - // interpretation of IfcCartesianPoints and IfcVector magnitudes - // DefaultL 1.0 - GV_LENGTH_UNIT, - // The plane angle unit used for the creation of TopoDS_Shapes, primarily affects - // the interpretation of IfcParamaterValues of IfcTrimmedCurves - // Default: -1.0 (= not set, fist try degrees, then radians) - GV_PLANEANGLE_UNIT, - // The precision used in boolean operations, setting this value too low results - // in artefacts and potentially modelling failures - // Default: 0.00001 (obtained from IfcGeometricRepresentationContext if available) - GV_PRECISION, - // Whether to process shapes of type Face or higher (1) Wire or lower (-1) or all (0) - GV_DIMENSIONALITY - }; - bool convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face& face); bool convert_curve_to_wire(const Handle(Geom_Curve)& curve, TopoDS_Wire& wire); bool convert_shapes(const IfcUtil::IfcBaseClass* L, IfcRepresentationShapeItems& result); @@ -318,7 +291,7 @@ public: // for large files. SurfaceStyles need to be kept at all costs, as they // are read later on when serializing Collada files. #ifndef NO_CACHE - cache = Cache(); + cache = MAKE_TYPE_NAME(Cache)(); #endif } diff --git a/src/ifcgeom/IfcGeomCurves.cpp b/src/ifcgeom/IfcGeomCurves.cpp index d068c63f84..d2acb0523b 100644 --- a/src/ifcgeom/IfcGeomCurves.cpp +++ b/src/ifcgeom/IfcGeomCurves.cpp @@ -83,6 +83,8 @@ #include "../ifcgeom/IfcGeom.h" +#define Kernel MAKE_TYPE_NAME(Kernel) + bool IfcGeom::Kernel::convert(const IfcSchema::IfcCircle* l, Handle(Geom_Curve)& curve) { const double r = l->Radius() * getValue(GV_LENGTH_UNIT); if ( r < ALMOST_ZERO ) { diff --git a/src/ifcgeom/IfcGeomFaces.cpp b/src/ifcgeom/IfcGeomFaces.cpp index d9dd45b323..de09110692 100644 --- a/src/ifcgeom/IfcGeomFaces.cpp +++ b/src/ifcgeom/IfcGeomFaces.cpp @@ -103,6 +103,8 @@ #include "../ifcgeom/IfcGeom.h" +#define Kernel MAKE_TYPE_NAME(Kernel) + bool IfcGeom::Kernel::convert(const IfcSchema::IfcFace* l, TopoDS_Shape& face) { IfcSchema::IfcFaceBound::list::ptr bounds = l->Bounds(); diff --git a/src/ifcgeom/IfcGeomFilter.h b/src/ifcgeom/IfcGeomFilter.h index 292e4024c5..31d44f55d7 100644 --- a/src/ifcgeom/IfcGeomFilter.h +++ b/src/ifcgeom/IfcGeomFilter.h @@ -62,6 +62,8 @@ namespace IfcGeom static bool traverse_match(IfcSchema::IfcProduct* prod, const filter_t& pred) { + throw std::runtime_error("todo"); + /* IfcSchema::IfcProduct* parent, *current = prod; while ((parent = dynamic_cast(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) { if (pred(parent)) { @@ -69,6 +71,7 @@ namespace IfcGeom } current = parent; } + */ return false; } }; @@ -216,8 +219,11 @@ namespace IfcGeom bool match(IfcSchema::IfcProduct* prod) const { + throw std::runtime_error("todo"); + /* layer_map_t layers = IfcGeom::Kernel::get_layers(prod); return std::find_if(layers.begin(), layers.end(), wildcards_match(values)) != layers.end(); + */ } bool operator()(IfcSchema::IfcProduct* prod) const diff --git a/src/ifcgeom/IfcGeomFunctions.cpp b/src/ifcgeom/IfcGeomFunctions.cpp index ac9ffb9ed7..4f4bdc2857 100644 --- a/src/ifcgeom/IfcGeomFunctions.cpp +++ b/src/ifcgeom/IfcGeomFunctions.cpp @@ -145,6 +145,8 @@ #endif #endif +#define Kernel MAKE_TYPE_NAME(Kernel) + bool IfcGeom::Kernel::create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& shape) { TopTools_ListOfShape face_list; TopExp_Explorer exp(compound, TopAbs_FACE); @@ -833,29 +835,33 @@ double IfcGeom::Kernel::getValue(GeomValue var) const { return 0; } -// Returns the vertex part of an TopoDS_Edge edge that is not TopoDS_Vertex vertex -TopoDS_Vertex find_other(const TopoDS_Edge& edge, const TopoDS_Vertex& vertex) { - TopExp_Explorer exp(edge, TopAbs_VERTEX); - while (exp.More()) { - if (!exp.Current().IsSame(vertex)) { - return TopoDS::Vertex(exp.Current()); - } - exp.Next(); - } - return TopoDS_Vertex(); -} +namespace { -TopoDS_Edge find_next(const TopTools_IndexedMapOfShape& edge_set, const TopTools_IndexedDataMapOfShapeListOfShape& vertex_to_edges, const TopoDS_Vertex& current, const TopoDS_Edge& previous_edge) { - const TopTools_ListOfShape& edges = vertex_to_edges.FindFromKey(current); - TopTools_ListIteratorOfListOfShape eit; - for (eit.Initialize(edges); eit.More(); eit.Next()) { - const TopoDS_Edge& edge = TopoDS::Edge(eit.Value()); - if (edge.IsSame(previous_edge)) continue; - if (edge_set.Contains(edge)) { - return edge; + // Returns the vertex part of an TopoDS_Edge edge that is not TopoDS_Vertex vertex + TopoDS_Vertex find_other(const TopoDS_Edge& edge, const TopoDS_Vertex& vertex) { + TopExp_Explorer exp(edge, TopAbs_VERTEX); + while (exp.More()) { + if (!exp.Current().IsSame(vertex)) { + return TopoDS::Vertex(exp.Current()); + } + exp.Next(); } + return TopoDS_Vertex(); } - return TopoDS_Edge(); + + TopoDS_Edge find_next(const TopTools_IndexedMapOfShape& edge_set, const TopTools_IndexedDataMapOfShapeListOfShape& vertex_to_edges, const TopoDS_Vertex& current, const TopoDS_Edge& previous_edge) { + const TopTools_ListOfShape& edges = vertex_to_edges.FindFromKey(current); + TopTools_ListIteratorOfListOfShape eit; + for (eit.Initialize(edges); eit.More(); eit.Next()) { + const TopoDS_Edge& edge = TopoDS::Edge(eit.Value()); + if (edge.IsSame(previous_edge)) continue; + if (edge_set.Contains(edge)) { + return edge; + } + } + return TopoDS_Edge(); + } + } bool IfcGeom::Kernel::fill_nonmanifold_wires_with_planar_faces(TopoDS_Shape& shape) { diff --git a/src/ifcgeom/IfcGeomHelpers.cpp b/src/ifcgeom/IfcGeomHelpers.cpp index 0b7b179e4c..0b6df4d931 100644 --- a/src/ifcgeom/IfcGeomHelpers.cpp +++ b/src/ifcgeom/IfcGeomHelpers.cpp @@ -77,51 +77,56 @@ #include "../ifcgeom/IfcGeom.h" -// Helper functions (re)set gp_(G)Trsf(2d) forms explicitly to 'Identity' -// so that it can be easily identified in the IfcMappedItem processing +#define Kernel MAKE_TYPE_NAME(Kernel) -// For axis placements detect equality early in order for the -// relatively computionaly expensive gp_Trsf calculation to be skipped -template -bool axis_equal(const T& a, const T& b, double tolerance); -template <> -bool axis_equal(const gp_Ax3& a, const gp_Ax3& b, double tolerance) { - if (!a.Location().IsEqual(b.Location(), tolerance)) return false; - // Note that the tolerance below is angular, above is linear. Since architectural - // objects are about 1m'ish in scale, it should be somewhat equivalent. Besides, - // this is mostly a filter for NULL or default values in the placements. - if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false; - if (!a.XDirection().IsEqual(b.XDirection(), tolerance)) return false; - if (!a.YDirection().IsEqual(b.YDirection(), tolerance)) return false; - return true; -} +namespace { -bool axis_equal(const gp_Ax2d& a, const gp_Ax2d& b, double tolerance) { - if (!a.Location().IsEqual(b.Location(), tolerance)) return false; - if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false; - return true; -} + // Helper functions (re)set gp_(G)Trsf(2d) forms explicitly to 'Identity' + // so that it can be easily identified in the IfcMappedItem processing -template struct dimension_count {}; -template <> struct dimension_count { static const int n = 2; }; -template <> struct dimension_count { static const int n = 2; }; -template <> struct dimension_count < gp_Trsf > { static const int n = 3; }; -template <> struct dimension_count < gp_GTrsf > { static const int n = 3; }; + // For axis placements detect equality early in order for the + // relatively computionaly expensive gp_Trsf calculation to be skipped + template + bool axis_equal(const T& a, const T& b, double tolerance); + template <> + bool axis_equal(const gp_Ax3& a, const gp_Ax3& b, double tolerance) { + if (!a.Location().IsEqual(b.Location(), tolerance)) return false; + // Note that the tolerance below is angular, above is linear. Since architectural + // objects are about 1m'ish in scale, it should be somewhat equivalent. Besides, + // this is mostly a filter for NULL or default values in the placements. + if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false; + if (!a.XDirection().IsEqual(b.XDirection(), tolerance)) return false; + if (!a.YDirection().IsEqual(b.YDirection(), tolerance)) return false; + return true; + } -template -bool is_identity(const T& t, double tolerance) { - // Note the {1, n+1} range due to Open Cascade's 1-based indexing - // Note the {1, n+2} range due to the translation part of the matrix - for (int i = 1; i < dimension_count::n + 2; ++i) { - for (int j = 1; j < dimension_count::n + 1; ++j) { - const double iden_value = i == j ? 1. : 0.; - const double trsf_value = t.Value(j, i); - if (fabs(trsf_value - iden_value) > tolerance) { - return false; + bool axis_equal(const gp_Ax2d& a, const gp_Ax2d& b, double tolerance) { + if (!a.Location().IsEqual(b.Location(), tolerance)) return false; + if (!a.Direction().IsEqual(b.Direction(), tolerance)) return false; + return true; + } + + template struct dimension_count {}; + template <> struct dimension_count { static const int n = 2; }; + template <> struct dimension_count { static const int n = 2; }; + template <> struct dimension_count < gp_Trsf > { static const int n = 3; }; + template <> struct dimension_count < gp_GTrsf > { static const int n = 3; }; + + template + bool is_identity(const T& t, double tolerance) { + // Note the {1, n+1} range due to Open Cascade's 1-based indexing + // Note the {1, n+2} range due to the translation part of the matrix + for (int i = 1; i < dimension_count::n + 2; ++i) { + for (int j = 1; j < dimension_count::n + 1; ++j) { + const double iden_value = i == j ? 1. : 0.; + const double trsf_value = t.Value(j, i); + if (fabs(trsf_value - iden_value) > tolerance) { + return false; + } } } + return true; } - return true; } bool IfcGeom::Kernel::convert(const IfcSchema::IfcCartesianPoint* l, gp_Pnt& point) { diff --git a/src/ifcgeom/IfcGeomIteratorImplementation.h b/src/ifcgeom/IfcGeomIteratorImplementation.h index 2c4c5f68e8..76340c1f14 100644 --- a/src/ifcgeom/IfcGeomIteratorImplementation.h +++ b/src/ifcgeom/IfcGeomIteratorImplementation.h @@ -77,7 +77,7 @@ #include "../ifcgeom/IfcGeom.h" #include "../ifcgeom/IfcGeomElement.h" -#include "../ifcgeom/IfcGeomMaterial.h" +#include "../iterator/IfcGeomMaterial.h" #include "../ifcgeom/IfcGeomIteratorSettings.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" #include "../ifcgeom/IfcGeomFilter.h" @@ -92,10 +92,6 @@ #undef max #endif -#define MAKE_TYPE_NAME__(a, b) a ## b -#define MAKE_TYPE_NAME_(a, b) MAKE_TYPE_NAME__(a, b) -#define MAKE_TYPE_NAME(t) MAKE_TYPE_NAME_(t, IfcSchema) - namespace IfcGeom { template @@ -105,7 +101,7 @@ namespace IfcGeom { MAKE_TYPE_NAME(IteratorImplementation_)(const MAKE_TYPE_NAME(IteratorImplementation_)&); // N/I MAKE_TYPE_NAME(IteratorImplementation_)& operator=(const MAKE_TYPE_NAME(IteratorImplementation_)&); // N/I - Kernel kernel; + MAKE_TYPE_NAME(Kernel) kernel; IteratorSettings settings; IfcParse::IfcFile* ifc_file; diff --git a/src/ifcgeom/IfcGeomRenderStyles.cpp b/src/ifcgeom/IfcGeomRenderStyles.cpp index 6fa5bee8e0..dfe6e87131 100644 --- a/src/ifcgeom/IfcGeomRenderStyles.cpp +++ b/src/ifcgeom/IfcGeomRenderStyles.cpp @@ -21,34 +21,40 @@ #include "IfcGeom.h" -bool process_colour(IfcSchema::IfcColourRgb* colour, double* rgb) { - if (colour != 0) { - rgb[0] = colour->Red(); - rgb[1] = colour->Green(); - rgb[2] = colour->Blue(); +namespace { + + bool process_colour(IfcSchema::IfcColourRgb* colour, double* rgb) { + if (colour != 0) { + rgb[0] = colour->Red(); + rgb[1] = colour->Green(); + rgb[2] = colour->Blue(); + } + return colour != 0; } - return colour != 0; + + bool process_colour(IfcSchema::IfcNormalisedRatioMeasure* factor, double* rgb) { + if (factor != 0) { + const double f = *factor; + rgb[0] = rgb[1] = rgb[2] = f; + } + return factor != 0; + } + + bool process_colour(IfcSchema::IfcColourOrFactor* colour_or_factor, double* rgb) { + if (colour_or_factor == 0) { + return false; + } else if (colour_or_factor->declaration().is(IfcSchema::IfcColourRgb::Class())) { + return process_colour(static_cast(colour_or_factor), rgb); + } else if (colour_or_factor->declaration().is(IfcSchema::IfcNormalisedRatioMeasure::Class())) { + return process_colour(static_cast(colour_or_factor), rgb); + } else { + return false; + } + } + } -bool process_colour(IfcSchema::IfcNormalisedRatioMeasure* factor, double* rgb) { - if (factor != 0) { - const double f = *factor; - rgb[0] = rgb[1] = rgb[2] = f; - } - return factor != 0; -} - -bool process_colour(IfcSchema::IfcColourOrFactor* colour_or_factor, double* rgb) { - if (colour_or_factor == 0) { - return false; - } else if (colour_or_factor->declaration().is(IfcSchema::IfcColourRgb::Class())) { - return process_colour(static_cast(colour_or_factor), rgb); - } else if (colour_or_factor->declaration().is(IfcSchema::IfcNormalisedRatioMeasure::Class())) { - return process_colour(static_cast(colour_or_factor), rgb); - } else { - return false; - } -} +#define Kernel MAKE_TYPE_NAME(Kernel) const IfcGeom::SurfaceStyle* IfcGeom::Kernel::internalize_surface_style(const std::pair& shading_styles) { if (shading_styles.second == 0) { @@ -127,57 +133,3 @@ const IfcGeom::SurfaceStyle* IfcGeom::Kernel::get_style(const IfcSchema::IfcMate } return 0; } - -static std::map default_materials; -static IfcGeom::SurfaceStyle default_material; -static bool default_materials_initialized = false; - -void InitDefaultMaterials() { - default_materials.insert(std::make_pair("IfcSite", IfcGeom::SurfaceStyle("IfcSite"))); - default_materials["IfcSite" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.8, 0.65)); - - default_materials.insert(std::make_pair("IfcSlab", IfcGeom::SurfaceStyle("IfcSlab"))); - default_materials["IfcSlab" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.4 , 0.4, 0.4 )); - - default_materials.insert(std::make_pair("IfcWallStandardCase", IfcGeom::SurfaceStyle("IfcWallStandardCase"))); - default_materials["IfcWallStandardCase"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.9 , 0.9, 0.9 )); - - default_materials.insert(std::make_pair("IfcWall", IfcGeom::SurfaceStyle("IfcWall"))); - default_materials["IfcWall" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.9 , 0.9, 0.9 )); - - default_materials.insert(std::make_pair("IfcWindow", IfcGeom::SurfaceStyle("IfcWindow"))); - default_materials["IfcWindow" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.8, 0.75)); - default_materials["IfcWindow" ].Transparency().reset(0.3); - - default_materials.insert(std::make_pair("IfcDoor", IfcGeom::SurfaceStyle("IfcDoor"))); - default_materials["IfcDoor" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.55, 0.3, 0.15)); - - default_materials.insert(std::make_pair("IfcBeam", IfcGeom::SurfaceStyle("IfcBeam"))); - default_materials["IfcBeam" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.7, 0.7 )); - - default_materials.insert(std::make_pair("IfcRailing", IfcGeom::SurfaceStyle("IfcRailing"))); - default_materials["IfcRailing" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.65, 0.6, 0.6 )); - - default_materials.insert(std::make_pair("IfcMember", IfcGeom::SurfaceStyle("IfcMember"))); - default_materials["IfcMember" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.65, 0.6, 0.6 )); - - default_materials.insert(std::make_pair("IfcPlate", IfcGeom::SurfaceStyle("IfcPlate"))); - default_materials["IfcPlate" ].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.8 , 0.8, 0.8 )); - - default_material = IfcGeom::SurfaceStyle("DefaultMaterial"); - default_material.Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.7, 0.7, 0.7)); - - default_materials_initialized = true; -} - -const IfcGeom::SurfaceStyle* IfcGeom::get_default_style(const std::string& s) { - if (!default_materials_initialized) InitDefaultMaterials(); - std::map::const_iterator it = default_materials.find(s); - if (it == default_materials.end()) { - default_materials.insert(std::make_pair(s, IfcGeom::SurfaceStyle(s))); - default_materials[s].Diffuse().reset(*default_material.Diffuse()); - it = default_materials.find(s); - } - const IfcGeom::SurfaceStyle& surface_style = it->second; - return &surface_style; -} diff --git a/src/ifcgeom/IfcGeomRepresentation.cpp b/src/ifcgeom/IfcGeomRepresentation.cpp index 01e4c5ec60..7c653aa10a 100644 --- a/src/ifcgeom/IfcGeomRepresentation.cpp +++ b/src/ifcgeom/IfcGeomRepresentation.cpp @@ -54,6 +54,31 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep) brep_data_ = sstream.str(); } +// todo copied from kernel +#include +#include + +TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_Trsf& t) { + if (t.Form() == gp_Identity) { + return s; + } else { + /// @todo set to 1. and exactly 1. or use epsilon? + if (t.ScaleFactor() != 1.) { + return BRepBuilderAPI_Transform(s, t, true); + } else { + return s.Moved(t); + } + } +} + +TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t) { + if (t.Form() == gp_Other) { + return BRepBuilderAPI_GTransform(s, t, true); + } else { + return apply_transformation(s, t.Trsf()); + } +} + TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const { TopoDS_Compound compound; BRep_Builder builder; @@ -68,7 +93,7 @@ TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const { trsf.PreMultiply(scale); } - const TopoDS_Shape moved_shape = IfcGeom::Kernel::apply_transformation(s, trsf); + const TopoDS_Shape moved_shape = apply_transformation(s, trsf); builder.Add(compound, moved_shape); } return compound; diff --git a/src/ifcgeom/IfcGeomRepresentation.h b/src/ifcgeom/IfcGeomRepresentation.h index 32caccabb1..eadd03b2c5 100644 --- a/src/ifcgeom/IfcGeomRepresentation.h +++ b/src/ifcgeom/IfcGeomRepresentation.h @@ -35,7 +35,7 @@ #include #include "../ifcgeom/IfcGeomIteratorSettings.h" -#include "../ifcgeom/IfcGeomMaterial.h" +#include "../iterator/IfcGeomMaterial.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" #include diff --git a/src/ifcgeom/IfcGeomShapes.cpp b/src/ifcgeom/IfcGeomShapes.cpp index 756acc7a4a..d0a6723045 100644 --- a/src/ifcgeom/IfcGeomShapes.cpp +++ b/src/ifcgeom/IfcGeomShapes.cpp @@ -103,6 +103,8 @@ #include "../ifcgeom/IfcGeom.h" +#define Kernel MAKE_TYPE_NAME(Kernel) + bool IfcGeom::Kernel::convert(const IfcSchema::IfcExtrudedAreaSolid* l, TopoDS_Shape& shape) { const double height = l->Depth() * getValue(GV_LENGTH_UNIT); if (height < getValue(GV_PRECISION)) { diff --git a/src/ifcgeom/IfcGeomWires.cpp b/src/ifcgeom/IfcGeomWires.cpp index 18e679a85b..b5ace50216 100644 --- a/src/ifcgeom/IfcGeomWires.cpp +++ b/src/ifcgeom/IfcGeomWires.cpp @@ -88,6 +88,8 @@ #include "../ifcgeom/IfcGeom.h" +#define Kernel MAKE_TYPE_NAME(Kernel) + bool IfcGeom::Kernel::convert(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wire& wire) { if ( getValue(GV_PLANEANGLE_UNIT)<0 ) { Logger::Message(Logger::LOG_WARNING,"Creating a composite curve without unit information:",l); diff --git a/src/ifcgeom/IfcRegister.cpp b/src/ifcgeom/IfcRegister.cpp index 530d85e586..514effeeba 100644 --- a/src/ifcgeom/IfcRegister.cpp +++ b/src/ifcgeom/IfcRegister.cpp @@ -20,6 +20,8 @@ #include "IfcGeom.h" #include "IfcGeomShapeType.h" +#define Kernel MAKE_TYPE_NAME(Kernel) + using namespace IfcUtil; bool IfcGeom::Kernel::convert_shapes(const IfcBaseClass* l, IfcRepresentationShapeItems& r) { diff --git a/src/ifcgeom/IfcRepresentationShapeItem.h b/src/ifcgeom/IfcRepresentationShapeItem.h index 29d5ca264b..204f30a516 100644 --- a/src/ifcgeom/IfcRepresentationShapeItem.h +++ b/src/ifcgeom/IfcRepresentationShapeItem.h @@ -23,7 +23,7 @@ #include #include -#include "../ifcgeom/IfcGeomRenderStyles.h" +#include "../iterator/IfcGeomRenderStyles.h" namespace IfcGeom { class IFC_GEOM_API IfcRepresentationShapeItem { diff --git a/src/ifcparse/Ifc2x3.cpp b/src/ifcparse/Ifc2x3.cpp index 737d0e2f71..09061dc600 100644 --- a/src/ifcparse/Ifc2x3.cpp +++ b/src/ifcparse/Ifc2x3.cpp @@ -24,8 +24,6 @@ * * ********************************************************************************/ -#ifndef USE_IFC4 - #include "../ifcparse/Ifc2x3.h" #include "../ifcparse/IfcSchema.h" #include "../ifcparse/IfcException.h" @@ -13158,4 +13156,3 @@ const IfcParse::entity& Ifc2x3::IfcZone::Class() { return *IFC2X3_IfcZone_type; Ifc2x3::IfcZone::IfcZone(IfcEntityInstanceData* e) : IfcGroup((IfcEntityInstanceData*)0) { if (!e) return; if (e->type() != IFC2X3_IfcZone_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; } Ifc2x3::IfcZone::IfcZone(std::string v1_GlobalId, ::Ifc2x3::IfcOwnerHistory* v2_OwnerHistory, boost::optional< std::string > v3_Name, boost::optional< std::string > v4_Description, boost::optional< std::string > v5_ObjectType) : IfcGroup((IfcEntityInstanceData*)0) {data_ = new IfcEntityInstanceData(IFC2X3_IfcZone_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((v1_GlobalId));data_->setArgument(0,attr);}{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((v2_OwnerHistory));data_->setArgument(1,attr);} if (v3_Name) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v3_Name));data_->setArgument(2,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(2, attr); } if (v4_Description) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v4_Description));data_->setArgument(3,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(3, attr); } if (v5_ObjectType) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v5_ObjectType));data_->setArgument(4,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(4, attr); } } -#endif diff --git a/src/ifcparse/Ifc4.cpp b/src/ifcparse/Ifc4.cpp index d448e08b65..9dbe906dbf 100644 --- a/src/ifcparse/Ifc4.cpp +++ b/src/ifcparse/Ifc4.cpp @@ -24,8 +24,6 @@ * * ********************************************************************************/ -#ifdef USE_IFC4 - #include "../ifcparse/Ifc4.h" #include "../ifcparse/IfcSchema.h" #include "../ifcparse/IfcException.h" @@ -5253,8 +5251,8 @@ Ifc4::IfcPressureMeasure::operator double() const { return *data_->getArgument(0 const IfcParse::type_declaration& Ifc4::IfcPropertySetDefinitionSet::Class() { return *IFC4_IfcPropertySetDefinitionSet_type; } const IfcParse::type_declaration& Ifc4::IfcPropertySetDefinitionSet::declaration() const { return *IFC4_IfcPropertySetDefinitionSet_type; } Ifc4::IfcPropertySetDefinitionSet::IfcPropertySetDefinitionSet(IfcEntityInstanceData* e) { data_ = e; } -Ifc4::IfcPropertySetDefinitionSet::IfcPropertySetDefinitionSet(IfcTemplatedEntityList< IfcPropertySetDefinition >::ptr v) { data_ = new IfcEntityInstanceData(IFC4_IfcPropertySetDefinitionSet_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);} } -Ifc4::IfcPropertySetDefinitionSet::operator IfcTemplatedEntityList< IfcPropertySetDefinition >::ptr() const { IfcEntityList::ptr es = *data_->getArgument(0); return es->as<::Ifc4::IfcPropertySetDefinition>(); } +Ifc4::IfcPropertySetDefinitionSet::IfcPropertySetDefinitionSet(IfcTemplatedEntityList< ::Ifc4::IfcPropertySetDefinition >::ptr v) { data_ = new IfcEntityInstanceData(IFC4_IfcPropertySetDefinitionSet_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(v->generalize()); data_->setArgument(0, attr);} } +Ifc4::IfcPropertySetDefinitionSet::operator IfcTemplatedEntityList< ::Ifc4::IfcPropertySetDefinition >::ptr() const { IfcEntityList::ptr es = *data_->getArgument(0); return es->as<::Ifc4::IfcPropertySetDefinition>(); } // Function implementations for IfcRadioActivityMeasure const IfcParse::type_declaration& Ifc4::IfcRadioActivityMeasure::Class() { return *IFC4_IfcRadioActivityMeasure_type; } @@ -15616,4 +15614,3 @@ const IfcParse::entity& Ifc4::IfcZone::Class() { return *IFC4_IfcZone_type; } Ifc4::IfcZone::IfcZone(IfcEntityInstanceData* e) : IfcSystem((IfcEntityInstanceData*)0) { if (!e) return; if (e->type() != IFC4_IfcZone_type) throw IfcException("Unable to find find keyword in schema"); data_ = e; } Ifc4::IfcZone::IfcZone(std::string v1_GlobalId, ::Ifc4::IfcOwnerHistory* v2_OwnerHistory, boost::optional< std::string > v3_Name, boost::optional< std::string > v4_Description, boost::optional< std::string > v5_ObjectType, boost::optional< std::string > v6_LongName) : IfcSystem((IfcEntityInstanceData*)0) {data_ = new IfcEntityInstanceData(IFC4_IfcZone_type); {IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((v1_GlobalId));data_->setArgument(0,attr);}{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((v2_OwnerHistory));data_->setArgument(1,attr);} if (v3_Name) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v3_Name));data_->setArgument(2,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(2, attr); } if (v4_Description) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v4_Description));data_->setArgument(3,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(3, attr); } if (v5_ObjectType) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v5_ObjectType));data_->setArgument(4,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(4, attr); } if (v6_LongName) {{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set((*v6_LongName));data_->setArgument(5,attr);} } else { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(boost::blank()); data_->setArgument(5, attr); } } -#endif diff --git a/src/ifcparse/Ifc4.h b/src/ifcparse/Ifc4.h index f3dae173fd..960ba16d54 100644 --- a/src/ifcparse/Ifc4.h +++ b/src/ifcparse/Ifc4.h @@ -7140,8 +7140,8 @@ public: virtual const IfcParse::type_declaration& declaration() const; static const IfcParse::type_declaration& Class(); explicit IfcPropertySetDefinitionSet (IfcEntityInstanceData* e); - IfcPropertySetDefinitionSet (IfcTemplatedEntityList< IfcPropertySetDefinition >::ptr v); - operator IfcTemplatedEntityList< IfcPropertySetDefinition >::ptr() const; + IfcPropertySetDefinitionSet (IfcTemplatedEntityList< ::Ifc4::IfcPropertySetDefinition >::ptr v); + operator IfcTemplatedEntityList< ::Ifc4::IfcPropertySetDefinition >::ptr() const; }; /// IfcRadioActivityMeasure is a measure of activity of radionuclide. /// Usually measured in Becquerel (Bq, 1/s). diff --git a/src/ifcparse/IfcEntityList.h b/src/ifcparse/IfcEntityList.h index cdee2615f2..263ab2cf6b 100644 --- a/src/ifcparse/IfcEntityList.h +++ b/src/ifcparse/IfcEntityList.h @@ -133,7 +133,7 @@ public: const std::vector& from = *outer; typename std::vector to; for (inner_it inner = from.begin(); inner != from.end(); ++inner) { - if (all || (*inner)->is(U::Class())) to.push_back((U*)*inner); + if (all || (*inner)->declaration().is(U::Class())) to.push_back((U*)*inner); } r->push(to); } diff --git a/src/ifcparse/IfcSIPrefix.cpp b/src/ifcparse/IfcSIPrefix.cpp index 651a54c0e1..4f88f577be 100644 --- a/src/ifcparse/IfcSIPrefix.cpp +++ b/src/ifcparse/IfcSIPrefix.cpp @@ -16,8 +16,12 @@ * along with this program. If not, see . * * * ********************************************************************************/ + #include "IfcSIPrefix.h" +#include "../ifcparse/Ifc2x3.h" +#include "../ifcparse/Ifc4.h" + double IfcParse::IfcSIPrefixToValue(const std::string& v) { if ( v == "EXA" ) return 1.e18; else if ( v == "PETA" ) return 1.e15; @@ -41,23 +45,23 @@ double IfcParse::IfcSIPrefixToValue(const std::string& v) { template double IfcParse::get_SI_equivalent(typename Schema::IfcNamedUnit* named_unit) { double scale = 1.; - IfcSchema::IfcSIUnit* si_unit = 0; + typename Schema::IfcSIUnit* si_unit = 0; - if (named_unit->declaration().is(IfcSchema::Type::IfcConversionBasedUnit)) { - IfcSchema::IfcConversionBasedUnit* conv_unit = named_unit->as(); - IfcSchema::IfcMeasureWithUnit* factor = conv_unit->ConversionFactor(); - IfcSchema::IfcUnit* component = factor->UnitComponent(); - if (component->declaration().is(IfcSchema::Type::IfcSIUnit)) { - si_unit = component->as(); - IfcSchema::IfcValue* v = factor->ValueComponent(); + if (named_unit->declaration().is(Schema::IfcConversionBasedUnit::Class())) { + typename Schema::IfcConversionBasedUnit* conv_unit = named_unit->as(); + typename Schema::IfcMeasureWithUnit* factor = conv_unit->ConversionFactor(); + typename Schema::IfcUnit* component = factor->UnitComponent(); + if (component->declaration().is(Schema::IfcSIUnit::Class())) { + si_unit = component->as(); + typename Schema::IfcValue* v = factor->ValueComponent(); scale = *v->data().getArgument(0); } - } else if (named_unit->declaration().is(IfcSchema::Type::IfcSIUnit)) { - si_unit = named_unit->as(); + } else if (named_unit->declaration().is(Schema::IfcSIUnit::Class())) { + si_unit = named_unit->as(); } if (si_unit) { if (si_unit->hasPrefix()) { - scale *= IfcSIPrefixToValue(si_unit->Prefix()); + scale *= IfcSIPrefixToValue(Schema::IfcSIPrefix::ToString(si_unit->Prefix())); } } else { scale = 0.; @@ -65,3 +69,6 @@ double IfcParse::get_SI_equivalent(typename Schema::IfcNamedUnit* named_unit) { return scale; } + +template double IfcParse::get_SI_equivalent(typename Ifc2x3::IfcNamedUnit* named_unit); +template double IfcParse::get_SI_equivalent(typename Ifc4::IfcNamedUnit* named_unit); diff --git a/src/ifcparse/IfcSchema.cpp b/src/ifcparse/IfcSchema.cpp index 0de6424dd3..6bd3f9031f 100644 --- a/src/ifcparse/IfcSchema.cpp +++ b/src/ifcparse/IfcSchema.cpp @@ -60,7 +60,7 @@ IfcParse::schema_definition::~schema_definition() { } } -const IfcParse::schema_definition* schema_by_name(const std::string& name) { +const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& name) { std::map::const_iterator it = schemas.find(name); if (it == schemas.end()) { throw IfcParse::IfcException("No schema named " + name); diff --git a/src/ifcparse/IfcUtil.cpp b/src/ifcparse/IfcUtil.cpp index ebd8e4f850..5edc5e4f03 100644 --- a/src/ifcparse/IfcUtil.cpp +++ b/src/ifcparse/IfcUtil.cpp @@ -165,7 +165,7 @@ void IfcUtil::unescape_xml(std::string &str) boost::replace_all(str, ">", ">"); } -Argument* IfcUtil::IfcBaseEntity::getArgumentByName(const std::string& name) const { +Argument* IfcUtil::IfcBaseEntity::get(const std::string& name) const { return data().getArgument(declaration().attribute_index(name)); } diff --git a/src/ifcgeom/IfcGeomMaterial.cpp b/src/iterator/IfcGeomMaterial.cpp similarity index 100% rename from src/ifcgeom/IfcGeomMaterial.cpp rename to src/iterator/IfcGeomMaterial.cpp diff --git a/src/ifcgeom/IfcGeomMaterial.h b/src/iterator/IfcGeomMaterial.h similarity index 98% rename from src/ifcgeom/IfcGeomMaterial.h rename to src/iterator/IfcGeomMaterial.h index ead890698f..e7892c3bf2 100644 --- a/src/ifcgeom/IfcGeomMaterial.h +++ b/src/iterator/IfcGeomMaterial.h @@ -22,7 +22,7 @@ #include -#include "../ifcgeom/IfcGeomRenderStyles.h" +#include "../iterator/IfcGeomRenderStyles.h" namespace IfcGeom { diff --git a/src/ifcgeom/IfcGeomRenderStyles.h b/src/iterator/IfcGeomRenderStyles.h similarity index 97% rename from src/ifcgeom/IfcGeomRenderStyles.h rename to src/iterator/IfcGeomRenderStyles.h index 39a67136dd..7ba1440207 100644 --- a/src/ifcgeom/IfcGeomRenderStyles.h +++ b/src/iterator/IfcGeomRenderStyles.h @@ -20,15 +20,13 @@ #ifndef IFCGEOMRENDERSTYLES_H #define IFCGEOMRENDERSTYLES_H -#include "ifc_geom_api.h" -#ifdef USE_IFC4 -#include "../ifcparse/Ifc4.h" -#else -#include "../ifcparse/Ifc2x3.h" -#endif +#include "../ifcgeom/ifc_geom_api.h" #include #include +#include + +#include namespace IfcGeom { class IFC_GEOM_API SurfaceStyle { diff --git a/src/iterator/Kernel.h b/src/iterator/Kernel.h new file mode 100644 index 0000000000..8d3451f86c --- /dev/null +++ b/src/iterator/Kernel.h @@ -0,0 +1,45 @@ +#ifndef ITERATOR_KERNEL_H +#define ITERATOR_KERNEL_H + +namespace IfcGeom { + class Kernel { + public: + // Tolerances and settings for various geometrical operations: + enum GeomValue { + // Specifies the deflection of the mesher + // Default: 0.001m / 1mm + GV_DEFLECTION_TOLERANCE, + // Specifies the tolerance of the wire builder, most notably for trimmed curves + // Defailt: 0.0001m / 0.1mm + GV_WIRE_CREATION_TOLERANCE, + // Specifies the minimal area of a face to be included in an IfcConnectedFaceset + // Read-only + GV_MINIMAL_FACE_AREA, + // Specifies the treshold distance under which cartesian points are deemed equal + // Default: 0.00001m / 0.01mm + GV_POINT_EQUALITY_TOLERANCE, + // Specifies maximum number of faces for a shell to be sewed. Sewing shells + // that consist of many faces is really detrimental for the performance. + // Default: 1000 + GV_MAX_FACES_TO_SEW, + // The length unit used the creation of TopoDS_Shapes, primarily affects the + // interpretation of IfcCartesianPoints and IfcVector magnitudes + // DefaultL 1.0 + GV_LENGTH_UNIT, + // The plane angle unit used for the creation of TopoDS_Shapes, primarily affects + // the interpretation of IfcParamaterValues of IfcTrimmedCurves + // Default: -1.0 (= not set, fist try degrees, then radians) + GV_PLANEANGLE_UNIT, + // The precision used in boolean operations, setting this value too low results + // in artefacts and potentially modelling failures + // Default: 0.00001 (obtained from IfcGeometricRepresentationContext if available) + GV_PRECISION, + // Whether to process shapes of type Face or higher (1) Wire or lower (-1) or all (0) + GV_DIMENSIONALITY + }; + + virtual ~Kernel() {} + }; +} + +#endif \ No newline at end of file diff --git a/src/iterator/SurfaceStyle.cpp b/src/iterator/SurfaceStyle.cpp new file mode 100644 index 0000000000..33ad4b0339 --- /dev/null +++ b/src/iterator/SurfaceStyle.cpp @@ -0,0 +1,57 @@ +#include "../iterator/IfcGeomRenderStyles.h" + +#include + +static std::map default_materials; +static IfcGeom::SurfaceStyle default_material; +static bool default_materials_initialized = false; + +void InitDefaultMaterials() { + default_materials.insert(std::make_pair("IfcSite", IfcGeom::SurfaceStyle("IfcSite"))); + default_materials["IfcSite"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.8, 0.65)); + + default_materials.insert(std::make_pair("IfcSlab", IfcGeom::SurfaceStyle("IfcSlab"))); + default_materials["IfcSlab"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.4, 0.4, 0.4)); + + default_materials.insert(std::make_pair("IfcWallStandardCase", IfcGeom::SurfaceStyle("IfcWallStandardCase"))); + default_materials["IfcWallStandardCase"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.9, 0.9, 0.9)); + + default_materials.insert(std::make_pair("IfcWall", IfcGeom::SurfaceStyle("IfcWall"))); + default_materials["IfcWall"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.9, 0.9, 0.9)); + + default_materials.insert(std::make_pair("IfcWindow", IfcGeom::SurfaceStyle("IfcWindow"))); + default_materials["IfcWindow"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.8, 0.75)); + default_materials["IfcWindow"].Transparency().reset(0.3); + + default_materials.insert(std::make_pair("IfcDoor", IfcGeom::SurfaceStyle("IfcDoor"))); + default_materials["IfcDoor"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.55, 0.3, 0.15)); + + default_materials.insert(std::make_pair("IfcBeam", IfcGeom::SurfaceStyle("IfcBeam"))); + default_materials["IfcBeam"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.75, 0.7, 0.7)); + + default_materials.insert(std::make_pair("IfcRailing", IfcGeom::SurfaceStyle("IfcRailing"))); + default_materials["IfcRailing"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.65, 0.6, 0.6)); + + default_materials.insert(std::make_pair("IfcMember", IfcGeom::SurfaceStyle("IfcMember"))); + default_materials["IfcMember"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.65, 0.6, 0.6)); + + default_materials.insert(std::make_pair("IfcPlate", IfcGeom::SurfaceStyle("IfcPlate"))); + default_materials["IfcPlate"].Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.8, 0.8, 0.8)); + + default_material = IfcGeom::SurfaceStyle("DefaultMaterial"); + default_material.Diffuse().reset(IfcGeom::SurfaceStyle::ColorComponent(0.7, 0.7, 0.7)); + + default_materials_initialized = true; +} + +const IfcGeom::SurfaceStyle* IfcGeom::get_default_style(const std::string& s) { + if (!default_materials_initialized) InitDefaultMaterials(); + std::map::const_iterator it = default_materials.find(s); + if (it == default_materials.end()) { + default_materials.insert(std::make_pair(s, IfcGeom::SurfaceStyle(s))); + default_materials[s].Diffuse().reset(*default_material.Diffuse()); + it = default_materials.find(s); + } + const IfcGeom::SurfaceStyle& surface_style = it->second; + return &surface_style; +}