/******************************************************************************** * * * 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 . * * * ********************************************************************************/ /******************************************************************************** * * * Implementations of the various conversion functions defined in IfcRegister.h * * * ********************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef USE_IFC4 #include #endif #include "../ifcgeom/IfcGeom.h" 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 ) { Logger::Message(Logger::LOG_ERROR, "Radius not greater than zero for:", l->entity); return false; } gp_Trsf trsf; IfcSchema::IfcAxis2Placement* placement = l->Position(); if (placement->is(IfcSchema::Type::IfcAxis2Placement3D)) { IfcGeom::Kernel::convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf); } else { gp_Trsf2d trsf2d; IfcGeom::Kernel::convert((IfcSchema::IfcAxis2Placement2D*)placement,trsf2d); trsf = trsf2d; } gp_Ax2 ax = gp_Ax2().Transformed(trsf); curve = new Geom_Circle(ax, r); return true; } bool IfcGeom::Kernel::convert(const IfcSchema::IfcEllipse* l, Handle(Geom_Curve)& curve) { double x = l->SemiAxis1() * getValue(GV_LENGTH_UNIT); double y = l->SemiAxis2() * getValue(GV_LENGTH_UNIT); if (x < ALMOST_ZERO || y < ALMOST_ZERO) { Logger::Message(Logger::LOG_ERROR, "Radius not greater than zero for:", l->entity); return false; } // Open Cascade does not allow ellipses of which the minor radius // is greater than the major radius. Hence, in this case, the // ellipse is rotated. Note that special care needs to be taken // when creating a trimmed curve off of an ellipse like this. const bool rotated = y > x; gp_Trsf trsf; IfcSchema::IfcAxis2Placement* placement = l->Position(); if (placement->is(IfcSchema::Type::IfcAxis2Placement3D)) { convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf); } else { gp_Trsf2d trsf2d; convert((IfcSchema::IfcAxis2Placement2D*)placement,trsf2d); trsf = trsf2d; } gp_Ax2 ax = gp_Ax2(); if (rotated) { ax.Rotate(ax.Axis(), M_PI / 2.); std::swap(x, y); } ax.Transform(trsf); curve = new Geom_Ellipse(ax, x, y); return true; } bool IfcGeom::Kernel::convert(const IfcSchema::IfcLine* l, Handle(Geom_Curve)& curve) { gp_Pnt pnt;gp_Vec vec; convert(l->Pnt(),pnt); convert(l->Dir(),vec); // See note at IfcGeomWires.cpp:237 curve = new Geom_Line(pnt,vec); return true; } #ifdef USE_IFC4 bool IfcGeom::Kernel::convert(const IfcSchema::IfcBSplineCurveWithKnots* l, Handle(Geom_Curve)& curve) { const bool is_rational = l->is(IfcSchema::Type::IfcRationalBSplineCurveWithKnots); const IfcSchema::IfcCartesianPoint::list::ptr cps = l->ControlPointsList(); const std::vector mults = l->KnotMultiplicities(); const std::vector knots = l->Knots(); TColgp_Array1OfPnt Poles(0, cps->size() - 1); TColStd_Array1OfReal Weights(0, cps->size() - 1); TColStd_Array1OfReal Knots(0, (int)knots.size() - 1); TColStd_Array1OfInteger Mults(0, (int)mults.size() - 1); Standard_Integer Degree = l->Degree(); Standard_Boolean Periodic = l->ClosedCurve(); int i; if (is_rational) { IfcSchema::IfcRationalBSplineCurveWithKnots* rl = (IfcSchema::IfcRationalBSplineCurveWithKnots*)l; std::vector weights = rl->WeightsData(); i = 0; for (std::vector::const_iterator it = weights.begin(); it != weights.end(); ++it, ++i) { Weights(i) = *it; } } i = 0; for (IfcSchema::IfcCartesianPoint::list::it it = cps->begin(); it != cps->end(); ++it, ++i) { gp_Pnt pnt; if (!convert(*it, pnt)) return false; Poles(i) = pnt; } i = 0; for (std::vector::const_iterator it = mults.begin(); it != mults.end(); ++it, ++i) { Mults(i) = *it; } i = 0; for (std::vector::const_iterator it = knots.begin(); it != knots.end(); ++it, ++i) { Knots(i) = *it; } if (is_rational) { curve = new Geom_BSplineCurve(Poles, Weights, Knots, Mults, Degree, Periodic); } else { curve = new Geom_BSplineCurve(Poles, Knots, Mults, Degree, Periodic); } return true; } #endif