2022-06-14 15:02:54 +02:00
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
2023-03-21 20:15:01 +01:00
# include "mapping.h"
# define mapping POSTFIX_SCHEMA(mapping)
using namespace ifcopenshell : : geometry ;
2022-06-14 15:02:54 +02:00
2023-07-27 16:42:06 +08:00
taxonomy : : ptr mapping : : map_impl ( const IfcSchema : : IfcCompositeCurve * inst ) {
auto loop = taxonomy : : make < taxonomy : : loop > ( ) ;
2022-06-14 15:02:54 +02:00
2023-03-21 20:15:01 +01:00
# ifdef SCHEMA_HAS_IfcSegment
// 4x3
IfcSchema : : IfcSegment : : list : : ptr segments = inst - > Segments ( ) ;
# else
IfcSchema : : IfcCompositeCurveSegment : : list : : ptr segments = inst - > Segments ( ) ;
# endif
2023-09-16 22:23:04 +02:00
for ( auto & segment : * segments ) {
if ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) & & segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > ParentCurve ( ) - > as < IfcSchema : : IfcLine > ( ) ) {
2023-03-21 20:15:01 +01:00
Logger : : Notice ( " Infinite IfcLine used as ParentCurve of segment, treating as a segment " , segment ) ;
double u0 = 0.0 ;
2023-09-16 22:23:04 +02:00
double u1 = segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > ParentCurve ( ) - > as < IfcSchema : : IfcLine > ( ) - > Dir ( ) - > Magnitude ( ) * length_unit_ ;
2023-03-21 20:15:01 +01:00
if ( u1 < conv_settings_ . getValue ( ConversionSettings : : GV_PRECISION ) ) {
Logger : : Warning ( " Segment length below tolerance " , segment ) ;
2022-06-14 15:02:54 +02:00
}
2023-07-27 16:42:06 +08:00
auto e = taxonomy : : make < taxonomy : : edge > ( ) ;
2023-09-16 22:23:04 +02:00
e - > basis = map ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > ParentCurve ( ) ) ;
2023-03-21 20:15:01 +01:00
e - > start = u0 ;
e - > end = u1 ;
2023-09-16 22:23:04 +02:00
e - > orientation_2 . reset ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > SameSense ( ) ) ;
2023-03-21 20:15:01 +01:00
loop - > children . push_back ( e ) ;
2023-09-16 22:23:04 +02:00
} else if ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) ) {
auto crv = map ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > ParentCurve ( ) ) ;
2023-03-21 20:15:01 +01:00
if ( crv ) {
if ( crv - > kind ( ) = = taxonomy : : EDGE ) {
2023-07-27 16:42:06 +08:00
auto ecrv = taxonomy : : cast < taxonomy : : edge > ( crv ) ;
2023-09-16 22:23:04 +02:00
ecrv - > orientation_2 . reset ( segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > SameSense ( ) ) ;
2023-07-27 16:42:06 +08:00
loop - > children . push_back ( ecrv ) ;
2023-03-21 20:15:01 +01:00
} else if ( crv - > kind ( ) = = taxonomy : : LOOP ) {
2023-09-16 22:23:04 +02:00
if ( ! segment - > as < IfcSchema : : IfcCompositeCurveSegment > ( ) - > SameSense ( ) ) {
2023-03-21 20:15:01 +01:00
crv - > reverse ( ) ;
}
2023-07-27 16:42:06 +08:00
for ( auto & s : taxonomy : : cast < taxonomy : : loop > ( crv ) - > children ) {
2023-03-21 20:15:01 +01:00
loop - > children . push_back ( s ) ;
}
}
2022-06-14 15:02:54 +02:00
}
}
2023-09-16 22:23:04 +02:00
# ifdef SCHEMA_HAS_IfcCurveSegment
else if ( segment - > as < IfcSchema : : IfcCurveSegment > ( ) ) {
2023-09-22 13:52:48 -07:00
auto crv = map ( segment - > as < IfcSchema : : IfcCurveSegment > ( ) ) ;
2023-09-29 08:02:33 -07:00
auto crv_as_loop = taxonomy : : cast < taxonomy : : loop > ( crv ) ;
// The end of the previous segment must be at the same location as the start of this segment
// @todo - need to apply some tolerancing
if ( ! loop - > children . empty ( ) and ! crv_as_loop - > children . empty ( )
and
boost : : get < ifcopenshell : : geometry : : taxonomy : : point3 : : ptr > ( loop - > children . back ( ) - > end ) - > components ( ) ! = boost : : get < ifcopenshell : : geometry : : taxonomy : : point3 : : ptr > ( crv_as_loop - > children . front ( ) - > start ) - > components ( ) )
{
std : : ostringstream os ;
auto & prev = boost : : get < ifcopenshell : : geometry : : taxonomy : : point3 : : ptr > ( loop - > children . back ( ) - > end ) - > components ( ) ;
auto & next = boost : : get < ifcopenshell : : geometry : : taxonomy : : point3 : : ptr > ( crv_as_loop - > children . front ( ) - > start ) - > components ( ) ;
os < < " Common points are not continuous: ( " < < prev . x ( ) < < " , " < < prev . y ( ) < < " , " < < prev . z ( ) < < " ) " < < " " < < " ( " < < next . x ( ) < < " , " < < next . y ( ) < < " , " < < next . z ( ) < < " ) " < < std : : endl ;
Logger : : Notice ( os . str ( ) ) ;
2023-09-16 22:23:04 +02:00
}
2023-09-29 08:02:33 -07:00
loop - > children . insert ( loop - > children . end ( ) , crv_as_loop - > children . begin ( ) , crv_as_loop - > children . end ( ) ) ;
2023-09-16 22:23:04 +02:00
}
# endif
2023-03-21 20:15:01 +01:00
}
2022-06-14 15:02:54 +02:00
2023-03-21 20:15:01 +01:00
aggregate_of_instance : : ptr profile = inst - > data ( ) . getInverse ( & IfcSchema : : IfcProfileDef : : Class ( ) , - 1 ) ;
const bool force_close = profile & & profile - > size ( ) > 0 ;
loop - > closed = force_close ;
return loop ;
}
2022-06-14 15:02:54 +02:00
2023-03-21 20:15:01 +01:00
/*
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Wire.hxx>
#include <TopTools_ListOfShape.hxx>
#include <ShapeFix_ShapeTolerance.hxx>
#include "mapping.h"
#include "../ifcgeom_schema_agnostic/wire_builder.h"
#define _USE_MATH_DEFINES
#define mapping POSTFIX_SCHEMA(mapping)
2023-07-27 16:42:06 +08:00
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wire& wire) {
2022-06-14 15:02:54 +02:00
TopTools_ListOfShape converted_segments;
for (auto it = segments->begin(); it != segments->end(); ++it) {
if (!(*it)->declaration().is(IfcSchema::IfcCompositeCurveSegment::Class())) {
Logger::Error("Not implemented", *it);
return false;
}
IfcSchema::IfcCurve* curve = ((IfcSchema::IfcCompositeCurveSegment*)(*it))->ParentCurve();
// The type of ParentCurve is IfcCurve, but the documentation says:
// ParentCurve: The *bounded curve* which defines the geometry of the segment.
// At least let's exclude IfcLine as an infinite linear segment
// definitely does not make any sense.
TopoDS_Wire segment;
if (curve->as<IfcSchema::IfcLine>()) {
Logger::Notice("Infinite IfcLine used as ParentCurve of segment, treating as a segment", *it);
Handle_Geom_Curve handle;
convert_curve(curve, handle);
double u0 = 0.0;
2023-03-21 20:15:01 +01:00
double u1 = curve->as<IfcSchema::IfcLine>()->Dir()->Magnitude() * length_unit_;
2022-06-14 15:02:54 +02:00
if (u1 < getValue(GV_PRECISION)) {
Logger::Warning("Segment length below tolerance", *it);
}
BRepBuilderAPI_MakeEdge me(handle, u0, u1);
if (me.IsDone()) {
BRep_Builder B;
B.MakeWire(segment);
B.Add(segment, me.Edge());
}
} else if (!convert_wire(curve, segment)) {
const bool failed_on_purpose = curve->as<IfcSchema::IfcPolyline>() && !segment.IsNull();
Logger::Message(failed_on_purpose ? Logger::LOG_WARNING : Logger::LOG_ERROR, "Failed to convert curve:", curve);
continue;
}
if (!((IfcSchema::IfcCompositeCurveSegment*)(*it))->SameSense()) {
segment.Reverse();
}
ShapeFix_ShapeTolerance FTol;
FTol.SetTolerance(segment, getValue(GV_PRECISION), TopAbs_WIRE);
converted_segments.Append(segment);
}
if (converted_segments.Extent() == 0) {
Logger::Message(Logger::LOG_ERROR, "No segment succesfully converted:", l);
return false;
}
BRepBuilderAPI_MakeWire w;
TopoDS_Vertex wire_first_vertex, wire_last_vertex, edge_first_vertex, edge_last_vertex;
TopTools_ListIteratorOfListOfShape it(converted_segments);
2023-03-21 20:15:01 +01:00
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
2022-06-14 15:02:54 +02:00
const bool force_close = profile && profile->size() > 0;
util::wire_builder bld(getValue(GV_PRECISION), l);
util::shape_pair_enumerate(it, bld, force_close);
wire = bld.wire();
return true;
}
2023-03-21 20:15:01 +01:00
2023-03-22 09:55:04 +01:00
*/