2021-11-05 16:54:16 +01:00
|
|
|
/********************************************************************************
|
2011-07-25 14:56:40 +00: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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <gp_Trsf.hxx>
|
|
|
|
|
#include <gp_Trsf2d.hxx>
|
|
|
|
|
#include <Geom_Ellipse.hxx>
|
2019-06-26 13:50:46 +02:00
|
|
|
#include "../ifcgeom/IfcGeom.h"
|
2015-06-02 15:56:09 +00:00
|
|
|
|
2017-12-20 16:38:55 +01:00
|
|
|
#define Kernel MAKE_TYPE_NAME(Kernel)
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
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);
|
2014-04-02 15:28:04 +00:00
|
|
|
if (x < ALMOST_ZERO || y < ALMOST_ZERO) {
|
2017-12-11 15:07:40 +01:00
|
|
|
Logger::Message(Logger::LOG_ERROR, "Radius not greater than zero for:", l);
|
2014-04-02 15:28:04 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-03-03 19:07:39 +00:00
|
|
|
// 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;
|
2011-07-25 14:56:40 +00:00
|
|
|
gp_Trsf trsf;
|
2021-09-13 13:19:56 +02:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcAxis2Placement* placement = l->Position();
|
2021-09-13 13:19:56 +02:00
|
|
|
if (placement->as<IfcSchema::IfcAxis2Placement3D>()) {
|
|
|
|
|
IfcGeom::Kernel::convert(placement->as<IfcSchema::IfcAxis2Placement3D>(), trsf);
|
2011-07-25 14:56:40 +00:00
|
|
|
} else {
|
|
|
|
|
gp_Trsf2d trsf2d;
|
2021-09-13 13:19:56 +02:00
|
|
|
IfcGeom::Kernel::convert(placement->as<IfcSchema::IfcAxis2Placement2D>(), trsf2d);
|
2011-07-25 14:56:40 +00:00
|
|
|
trsf = trsf2d;
|
|
|
|
|
}
|
2021-09-13 13:19:56 +02:00
|
|
|
|
2014-03-03 19:07:39 +00:00
|
|
|
gp_Ax2 ax = gp_Ax2();
|
|
|
|
|
if (rotated) {
|
|
|
|
|
ax.Rotate(ax.Axis(), M_PI / 2.);
|
|
|
|
|
std::swap(x, y);
|
|
|
|
|
}
|
|
|
|
|
ax.Transform(trsf);
|
2011-07-25 14:56:40 +00:00
|
|
|
curve = new Geom_Ellipse(ax, x, y);
|
|
|
|
|
return true;
|
|
|
|
|
}
|