23
#include "PreCompiled.h"
25
# include <Approx_Curve3d.hxx>
26
# include <BRepAdaptor_Curve.hxx>
27
# include <BRepAdaptor_Surface.hxx>
28
# include <BRepBuilderAPI_MakeEdge.hxx>
29
# include <BRepBuilderAPI_MakeFace.hxx>
30
# include <BRepBuilderAPI_MakeVertex.hxx>
31
# include <BSplCLib.hxx>
32
# include <GC_MakeArcOfCircle.hxx>
33
# include <GC_MakeArcOfEllipse.hxx>
34
# include <GC_MakeArcOfHyperbola.hxx>
35
# include <GC_MakeArcOfParabola.hxx>
36
# include <GC_MakeCircle.hxx>
37
# include <GC_MakeEllipse.hxx>
38
# include <GC_MakeHyperbola.hxx>
39
# include <GC_MakeSegment.hxx>
40
# include <GCPnts_AbscissaPoint.hxx>
41
# include <gce_ErrorType.hxx>
42
# include <gce_MakeParab.hxx>
43
# include <Geom_BezierCurve.hxx>
44
# include <Geom_BezierSurface.hxx>
45
# include <Geom_BSplineCurve.hxx>
46
# include <Geom_BSplineSurface.hxx>
47
# include <Geom_CartesianPoint.hxx>
48
# include <Geom_Circle.hxx>
49
# include <Geom_ConicalSurface.hxx>
50
# include <Geom_Curve.hxx>
51
# include <Geom_CylindricalSurface.hxx>
52
# include <Geom_Ellipse.hxx>
53
# include <Geom_Hyperbola.hxx>
54
# include <Geom_Line.hxx>
55
# include <Geom_OffsetCurve.hxx>
56
# include <Geom_OffsetSurface.hxx>
57
# include <Geom_Parabola.hxx>
58
# include <Geom_Plane.hxx>
59
# include <Geom_RectangularTrimmedSurface.hxx>
60
# include <Geom_SphericalSurface.hxx>
61
# include <Geom_Surface.hxx>
62
# include <Geom_SurfaceOfLinearExtrusion.hxx>
63
# include <Geom_SurfaceOfRevolution.hxx>
64
# include <Geom_ToroidalSurface.hxx>
65
# include <Geom_TrimmedCurve.hxx>
66
# include <GeomAPI_ExtremaCurveCurve.hxx>
67
# include <GeomAPI_Interpolate.hxx>
68
# include <GeomAPI_PointsToBSpline.hxx>
69
# include <GeomAPI_ProjectPointOnCurve.hxx>
70
# include <GeomConvert.hxx>
71
# include <GeomConvert_CompCurveToBSplineCurve.hxx>
72
# include <GeomLProp_CLProps.hxx>
73
# include <GeomLProp_SLProps.hxx>
74
# include <GeomLib_IsPlanarSurface.hxx>
75
# include <GeomPlate_Surface.hxx>
78
# include <gp_Circ.hxx>
79
# include <gp_Cone.hxx>
80
# include <gp_Cylinder.hxx>
81
# include <gp_Elips.hxx>
82
# include <gp_Hypr.hxx>
84
# include <gp_Parab.hxx>
87
# include <gp_Sphere.hxx>
88
# include <gp_Torus.hxx>
89
# include <LProp_NotDefined.hxx>
90
# include <Precision.hxx>
91
# include <ShapeConstruct_Curve.hxx>
92
# include <Standard_ConstructionError.hxx>
93
# include <Standard_Real.hxx>
94
# include <Standard_Version.hxx>
95
# include <TColgp_Array2OfPnt.hxx>
96
# include <TColgp_HArray1OfPnt.hxx>
97
# include <TColStd_Array1OfReal.hxx>
98
# include <TColStd_HArray1OfBoolean.hxx>
100
# if OCC_VERSION_HEX < 0x070600
101
# include <GeomAdaptor_HSurface.hxx>
102
# include <GeomAdaptor_HCurve.hxx>
105
# include <boost/random.hpp>
110
#include <Base/Console.h>
111
#include <Base/Exception.h>
112
#include <Base/Reader.h>
113
#include <Base/Writer.h>
114
#include <BRep_Tool.hxx>
117
#include <boost/thread/mutex.hpp>
118
#include <boost/thread/thread.hpp>
121
#include "ArcOfCirclePy.h"
122
#include "ArcOfEllipsePy.h"
123
#include "ArcOfHyperbolaPy.h"
124
#include "ArcOfParabolaPy.h"
125
#include "BezierCurvePy.h"
126
#include "BezierSurfacePy.h"
127
#include "BSplineCurveBiArcs.h"
128
#include "BSplineCurvePy.h"
129
#include "BSplineSurfacePy.h"
132
#include "CylinderPy.h"
133
#include "EllipsePy.h"
134
#include "GeometryMigrationExtension.h"
135
#include "HyperbolaPy.h"
137
#include "LineSegmentPy.h"
138
#include "OffsetCurvePy.h"
139
#include "OffsetSurfacePy.h"
140
#include "ParabolaPy.h"
142
#include "PlateSurfacePy.h"
144
#include "RectangularTrimmedSurfacePy.h"
146
#include "SurfaceOfExtrusionPy.h"
147
#include "SurfaceOfRevolutionPy.h"
150
#include "TopoShape.h"
153
#if OCC_VERSION_HEX >= 0x070600
154
using GeomAdaptor_HCurve = GeomAdaptor_Curve;
160
const char* gce_ErrorStatusText(gce_ErrorType et)
165
return "Construction was successful";
166
case gce_ConfusedPoints:
167
return "Two points are coincident";
168
case gce_NegativeRadius:
169
return "Radius value is negative";
170
case gce_ColinearPoints:
171
return "Three points are collinear";
172
case gce_IntersectionError:
173
return "Intersection cannot be computed";
175
return "Axis is undefined";
177
return "Angle value is invalid (usually null)";
179
return "Radius is null";
181
return "Axis value is invalid";
183
return "Angle value is invalid";
184
case gce_InvertRadius:
185
return "Radius value is incorrect (usually with respect to another radius)";
186
case gce_NullFocusLength:
187
return "Focal distance is null";
189
return "Vector is null";
190
case gce_BadEquation:
191
return "Coefficients are incorrect (applies to the equation of a geometric object)";
193
return "Creation of geometry failed";
199
TYPESYSTEM_SOURCE_ABSTRACT(Part::Geometry,Base::Persistence)
206
Geometry::~Geometry() = default;
208
bool Geometry::hasSameExtensions(const Geometry& other) const
213
for (const auto& ext : extensions) {
214
if (auto persistExt =
215
Base::freecad_dynamic_cast<const GeometryPersistenceExtension>(ext.get())) {
216
for (; index < other.extensions.size(); ++index) {
217
if (auto extOther = Base::freecad_dynamic_cast<const GeometryPersistenceExtension>(
218
other.extensions[index].get())) {
219
if (!persistExt->isSame(*extOther)) {
225
if (index >= other.extensions.size()) {
231
for (; index < other.extensions.size(); ++index) {
232
if (Base::freecad_dynamic_cast<const GeometryPersistenceExtension>(
233
other.extensions[index].get())) {
241
unsigned int Geometry::getMemSize () const
246
std::unique_ptr<Geometry> Geometry::fromShape(const TopoDS_Shape &shape, bool silent)
248
std::unique_ptr<Geometry> geom;
250
if (shape.IsNull()) {
252
throw Base::ValueError("Null shape");
256
switch (shape.ShapeType()) {
257
case TopAbs_VERTEX: {
258
gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(shape));
259
geom = std::make_unique<GeomPoint>(Base::Vector3d(p.X(),p.Y(),p.Z()));
263
const TopoDS_Edge& e = TopoDS::Edge(shape);
264
BRepAdaptor_Curve adapt(e);
265
geom = makeFromCurveAdaptor(adapt, silent);
269
const TopoDS_Face& f = TopoDS::Face(shape);
270
BRepAdaptor_Surface adapt(f);
271
geom = makeFromSurfaceAdaptor(adapt, silent);
276
FC_THROWM(Base::TypeError, "Unsupported shape type " << TopoShape::shapeName(shape.ShapeType()));
281
void Geometry::Save(Base::Writer &writer) const
287
for(const auto& att : extensions) {
288
if(att->isDerivedFrom(Part::GeometryPersistenceExtension::getClassTypeId()))
292
writer.Stream() << writer.ind() << "<GeoExtensions count=\"" << counter << "\">" << std::endl;
296
for(const auto& att : extensions) {
297
if(att->isDerivedFrom(Part::GeometryPersistenceExtension::getClassTypeId()))
298
std::static_pointer_cast<Part::GeometryPersistenceExtension>(att)->Save(writer);
302
writer.Stream() << writer.ind() << "</GeoExtensions>" << std::endl;
305
void Geometry::Restore(Base::XMLReader &reader)
309
reader.readElement();
311
if(strcmp(reader.localName(),"GeoExtensions") == 0) {
313
long count = reader.getAttributeAsInteger("count");
315
for (long index = 0; index < count; index++) {
316
reader.readElement("GeoExtension");
317
const char* TypeName = reader.getAttribute("type");
318
Base::Type type = Base::Type::fromName(TypeName);
319
auto *newExtension = static_cast<GeometryPersistenceExtension *>(type.createInstance());
321
newExtension->Restore(reader);
323
extensions.push_back(std::shared_ptr<GeometryExtension>(newExtension));
326
Base::Console().Warning("Cannot restore geometry extension of type: %s\n", TypeName);
330
reader.readEndElement("GeoExtensions");
332
else if(strcmp(reader.localName(),"Construction") == 0) {
334
bool construction = (int)reader.getAttributeAsInteger("value") != 0;
337
if(!this->hasExtension(GeometryMigrationExtension::getClassTypeId()))
338
this->setExtension(std::make_unique<GeometryMigrationExtension>());
340
auto ext = std::static_pointer_cast<GeometryMigrationExtension>(this->getExtension(GeometryMigrationExtension::getClassTypeId()).lock());
342
ext->setMigrationType(GeometryMigrationExtension::Construction);
343
ext->setConstruction(construction);
349
boost::uuids::uuid Geometry::getTag() const
354
std::vector<std::weak_ptr<const GeometryExtension>> Geometry::getExtensions() const
356
std::vector<std::weak_ptr<const GeometryExtension>> wp;
358
for (auto& ext : extensions) {
365
bool Geometry::hasExtension(const Base::Type & type) const
367
return std::any_of(extensions.begin(),
369
[type](auto geoExt) {
370
return geoExt->getTypeId() == type;
374
bool Geometry::hasExtension(const std::string & name) const
376
return std::any_of(extensions.begin(),
378
[name](auto geoExt) {
379
return geoExt->getName() == name;
383
std::weak_ptr<GeometryExtension> Geometry::getExtension(const Base::Type & type)
385
for(const auto& ext : extensions) {
386
if(ext->getTypeId() == type)
390
throw Base::ValueError("No geometry extension of the requested type.");
393
std::weak_ptr<GeometryExtension> Geometry::getExtension(const std::string & name)
395
for(const auto& ext : extensions) {
396
if(ext->getName() == name)
400
throw Base::ValueError("No geometry extension with the requested name.");
403
std::weak_ptr<const GeometryExtension> Geometry::getExtension(const Base::Type & type) const
405
return const_cast<Geometry*>(this)->getExtension(type).lock();
408
std::weak_ptr<const GeometryExtension> Geometry::getExtension(const std::string & name) const
410
return const_cast<Geometry*>(this)->getExtension(name).lock();
414
void Geometry::setExtension(std::unique_ptr<GeometryExtension> && geoext )
418
for( auto & ext : extensions) {
420
if( ext->getTypeId() == geoext->getTypeId() &&
421
ext->getName() == geoext->getName()){
422
ext = std::move( geoext );
423
ext->notifyAttachment(this);
430
extensions.push_back(std::move( geoext ));
431
extensions.back()->notifyAttachment(this);
435
void Geometry::deleteExtension(const Base::Type & type)
438
std::remove_if( extensions.begin(),
440
[&type](const std::shared_ptr<GeometryExtension>& ext){
441
return ext->getTypeId() == type;
446
void Geometry::deleteExtension(const std::string & name)
449
std::remove_if( extensions.begin(),
451
[&name](const std::shared_ptr<GeometryExtension>& ext){
452
return ext->getName() == name;
458
void Geometry::createNewTag()
463
static boost::mt19937 ran;
464
static bool seeded = false;
465
static boost::mutex random_number_mutex;
467
boost::lock_guard<boost::mutex> guard(random_number_mutex);
470
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
473
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
478
void Geometry::assignTag(const Part::Geometry * geo)
480
if(geo->getTypeId() == this->getTypeId())
481
this->tag = geo->tag;
483
throw Base::TypeError("Geometry tag can not be assigned as geometry types do not match.");
486
void Geometry::copyNonTag(const Part::Geometry* src)
488
for (auto& ext : src->extensions) {
489
this->extensions.push_back(ext->copy());
490
extensions.back()->notifyAttachment(this);
494
Geometry *Geometry::clone() const
496
Geometry* cpy = this->copy();
497
cpy->tag = this->tag;
504
void Geometry::mirror(const Base::Vector3d& point) const
506
gp_Pnt pnt(point.x, point.y, point.z);
507
handle()->Mirror(pnt);
510
void Geometry::mirror(const Base::Vector3d& point, const Base::Vector3d& dir) const
512
gp_Ax1 ax1(gp_Pnt(point.x,point.y,point.z), gp_Dir(dir.x,dir.y,dir.z));
513
handle()->Mirror(ax1);
516
void Geometry::rotate(const Base::Placement& plm) const
518
Base::Rotation rot(plm.getRotation());
519
Base::Vector3d pnt, dir;
523
rot.getValue(dir, angle);
524
pnt = plm.getPosition();
526
gp_Ax1 ax1(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(dir.x,dir.y,dir.z));
527
handle()->Rotate(ax1, angle);
530
void Geometry::scale(const Base::Vector3d& vec, double scale) const
532
gp_Pnt pnt(vec.x, vec.y, vec.z);
533
handle()->Scale(pnt, scale);
536
void Geometry::transform(const Base::Matrix4D& mat) const
539
trf.SetValues(mat[0][0],mat[0][1],mat[0][2],mat[0][3],
540
mat[1][0],mat[1][1],mat[1][2],mat[1][3],
541
mat[2][0],mat[2][1],mat[2][2],mat[2][3]);
542
handle()->Transform(trf);
545
void Geometry::translate(const Base::Vector3d& vec) const
547
gp_Vec trl(vec.x, vec.y, vec.z);
548
handle()->Translate(trl);
554
TYPESYSTEM_SOURCE(Part::GeomPoint,Part::Geometry)
556
GeomPoint::GeomPoint()
558
this->myPoint = new Geom_CartesianPoint(0,0,0);
561
GeomPoint::GeomPoint(const Handle(Geom_CartesianPoint)& p)
566
GeomPoint::GeomPoint(const Base::Vector3d& p)
568
this->myPoint = new Geom_CartesianPoint(p.x,p.y,p.z);
571
GeomPoint::~GeomPoint() = default;
573
const Handle(Geom_Geometry)& GeomPoint::handle() const
579
void GeomPoint::setHandle(const Handle(Geom_CartesianPoint)& p)
581
myPoint = Handle(Geom_CartesianPoint)::DownCast(p->Copy());
584
Geometry *GeomPoint::copy() const
586
auto newPoint = new GeomPoint(myPoint);
587
newPoint->copyNonTag(this);
591
TopoDS_Shape GeomPoint::toShape() const
593
return BRepBuilderAPI_MakeVertex(myPoint->Pnt());
596
Base::Vector3d GeomPoint::getPoint()const
598
return Base::Vector3d(myPoint->X(),myPoint->Y(),myPoint->Z());
601
void GeomPoint::setPoint(const Base::Vector3d& p)
603
this->myPoint->SetCoord(p.x,p.y,p.z);
607
unsigned int GeomPoint::getMemSize () const
609
return sizeof(Geom_CartesianPoint);
612
void GeomPoint::Save(Base::Writer &writer) const
615
Geometry::Save(writer);
617
Base::Vector3d Point = getPoint();
621
<< "X=\"" << Point.x <<
622
"\" Y=\"" << Point.y <<
623
"\" Z=\"" << Point.z <<
627
void GeomPoint::Restore(Base::XMLReader &reader)
630
Geometry::Restore(reader);
634
reader.readElement("GeomPoint");
636
X = reader.getAttributeAsFloat("X");
637
Y = reader.getAttributeAsFloat("Y");
638
Z = reader.getAttributeAsFloat("Z");
641
setPoint(Base::Vector3d(X,Y,Z) );
644
PyObject *GeomPoint::getPyObject()
646
return new PointPy(new GeomPoint(getPoint()));
649
bool GeomPoint::isSame(const Geometry &other, double tol, double) const
651
return other.getTypeId() == getTypeId()
652
&& Base::DistanceP2(dynamic_cast<const GeomPoint &>(other).getPoint(),getPoint()) <= tol*tol;
657
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomCurve,Part::Geometry)
659
GeomCurve::GeomCurve() = default;
661
GeomCurve::~GeomCurve() = default;
663
TopoDS_Shape GeomCurve::toShape() const
665
Handle(Geom_Curve) c = Handle(Geom_Curve)::DownCast(handle());
666
BRepBuilderAPI_MakeEdge mkBuilder(c, c->FirstParameter(), c->LastParameter());
667
return mkBuilder.Shape();
675
static Standard_Boolean IsLinear(const Adaptor3d_Curve& theC)
677
const GeomAbs_CurveType aCT = theC.GetType();
678
if(aCT == GeomAbs_OffsetCurve)
680
return IsLinear(GeomAdaptor_Curve(theC.OffsetCurve()->BasisCurve()));
683
if((aCT == GeomAbs_BSplineCurve) || (aCT == GeomAbs_BezierCurve))
689
return ((theC.Degree() == 1) &&
690
(theC.Continuity() != GeomAbs_C0));
693
if(aCT == GeomAbs_Line)
695
return Standard_True;
698
return Standard_False;
701
bool GeomCurve::isLinear(Base::Vector3d *dir, Base::Vector3d *base) const
703
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
704
return isLinear(curve, dir, base);
707
bool GeomCurve::isLinear(const Handle(Geom_Curve) &curve, Base::Vector3d *dir, Base::Vector3d *base)
709
GeomAdaptor_Curve adaptor(curve);
710
if (!IsLinear(adaptor))
714
if (adaptor.GetType() == GeomAbs_Line) {
716
Handle(Geom_Line) curv = Handle(Geom_Line)::DownCast(curve);
718
gp_Pnt Pos = curv->Lin().Location();
719
*base = Base::Vector3d(Pos.X(), Pos.Y(), Pos.Z());
722
gp_Dir Dir = curv->Lin().Direction();
723
*dir = Base::Vector3d(Dir.X(), Dir.Y(), Dir.Z());
728
GeomLProp_CLProps prop1(curve,curve->FirstParameter(),0,Precision::Confusion());
729
GeomLProp_CLProps prop2(curve,curve->LastParameter(),0,Precision::Confusion());
730
const gp_Pnt &p1 = prop1.Value();
731
const gp_Pnt &p2 = prop2.Value();
733
*base = Base::Vector3d(p1.X(), p1.Y(), p1.Z());
735
*dir = Base::Vector3d(p2.X() - p1.X(), p2.Y() - p1.Y(), p2.Z() - p1.Z());
737
catch (Standard_Failure& e) {
738
THROWM(Base::CADKernelError,e.GetMessageString())
744
GeomLine* GeomCurve::toLine(KeepTag clone) const
749
auto p1 = pointAtParameter(getFirstParameter());
750
auto p2 = pointAtParameter(getLastParameter());
751
auto res = new GeomLine(p1, p2-p1);
752
res->copyNonTag(this);
753
if (clone == CopyTag) {
754
res->tag = this->tag;
759
GeomLineSegment* GeomCurve::toLineSegment(KeepTag clone) const
764
Base::Vector3d start, end;
765
if (isDerivedFrom(GeomBoundedCurve::getClassTypeId())) {
766
start = dynamic_cast<const GeomBoundedCurve*>(this)->getStartPoint();
767
end = dynamic_cast<const GeomBoundedCurve*>(this)->getEndPoint();
769
start = pointAtParameter(getFirstParameter());
770
end = pointAtParameter(getLastParameter());
772
auto res = new GeomLineSegment;
773
res->setPoints(start, end);
774
res->copyNonTag(this);
775
if (clone == CopyTag) {
776
res->tag = this->tag;
781
GeomBSplineCurve* GeomCurve::toBSpline(double first, double last) const
783
ShapeConstruct_Curve scc;
784
Handle(Geom_Curve) c = Handle(Geom_Curve)::DownCast(handle());
785
Handle(Geom_BSplineCurve) spline = scc.ConvertToBSpline(c, first, last, Precision::Confusion());
787
THROWM(Base::CADKernelError,"Conversion to B-spline failed")
788
return new GeomBSplineCurve(spline);
791
GeomBSplineCurve* GeomCurve::toNurbs(double first, double last) const
793
return toBSpline(first, last);
796
bool GeomCurve::tangent(double u, gp_Dir& dir) const
798
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
799
GeomLProp_CLProps prop(curve, u,1,Precision::Confusion());
800
if (prop.IsTangentDefined()) {
808
bool GeomCurve::tangent(double u, Base::Vector3d& dir) const
812
if (tangent(u, gdir)) {
813
dir = Base::Vector3d(gdir.X(),gdir.Y(),gdir.Z());
821
Base::Vector3d GeomCurve::value(double u) const
823
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
825
const gp_Pnt &point = curve->Value(u);
827
return Base::Vector3d(point.X(),point.Y(),point.Z());
830
Base::Vector3d GeomCurve::pointAtParameter(double u) const
832
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
833
GeomLProp_CLProps prop(curve, u,0,Precision::Confusion());
835
const gp_Pnt &point=prop.Value();
837
return Base::Vector3d(point.X(),point.Y(),point.Z());
840
Base::Vector3d GeomCurve::firstDerivativeAtParameter(double u) const
842
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
843
GeomLProp_CLProps prop(curve, u,1,Precision::Confusion());
845
const gp_Vec &vec=prop.D1();
847
return Base::Vector3d(vec.X(),vec.Y(),vec.Z());
850
Base::Vector3d GeomCurve::secondDerivativeAtParameter(double u) const
852
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
853
GeomLProp_CLProps prop(curve, u,2,Precision::Confusion());
855
const gp_Vec &vec=prop.D2();
857
return Base::Vector3d(vec.X(),vec.Y(),vec.Z());
860
bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const
862
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
865
if (!curve.IsNull()) {
866
GeomLProp_CLProps prop(curve, u,2,Precision::Confusion());
869
dir = Base::Vector3d(gdir.X(), gdir.Y(), gdir.Z());
874
catch (const LProp_NotDefined&) {
878
catch (Standard_Failure& exc) {
879
THROWM(Base::CADKernelError, exc.GetMessageString())
885
bool GeomCurve::normalAt(const Base::Vector3d & curvepoint, Base::Vector3d & dir) const
888
closestParameter(curvepoint, u);
890
return normalAt(u, dir);
893
bool GeomCurve::intersect( const GeomCurve *curve,
894
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
897
Handle(Geom_Curve) curve1 = Handle(Geom_Curve)::DownCast(handle());
898
Handle(Geom_Curve) curve2 = Handle(Geom_Curve)::DownCast(curve->handle());
900
if(!curve1.IsNull() && !curve2.IsNull()) {
901
return intersect(curve1,curve2,points, tol);
908
bool GeomCurve::intersect(const Handle(Geom_Curve)& curve1, const Handle(Geom_Curve)& curve2,
909
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
913
if (curve1->IsKind(STANDARD_TYPE(Geom_BoundedCurve)) &&
914
curve2->IsKind(STANDARD_TYPE(Geom_BoundedCurve))){
916
Handle(Geom_BoundedCurve) bcurve1 = Handle(Geom_BoundedCurve)::DownCast(curve1);
917
Handle(Geom_BoundedCurve) bcurve2 = Handle(Geom_BoundedCurve)::DownCast(curve2);
919
gp_Pnt c1s = bcurve1->StartPoint();
920
gp_Pnt c2s = bcurve2->StartPoint();
921
gp_Pnt c1e = bcurve1->EndPoint();
922
gp_Pnt c2e = bcurve2->EndPoint();
924
auto checkendpoints = [&points,tol]( gp_Pnt p1, gp_Pnt p2) {
925
if(p1.Distance(p2) < tol)
926
points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z()));
929
checkendpoints(c1s,c2s);
930
checkendpoints(c1s,c2e);
931
checkendpoints(c1e,c2s);
932
checkendpoints(c1e,c2e);
938
GeomAPI_ExtremaCurveCurve intersector(curve1, curve2);
940
if (intersector.NbExtrema() == 0 || intersector.LowerDistance() > tol) {
945
for (int index = 1; index <= intersector.NbExtrema(); index++) {
946
if (intersector.Distance(index) > tol)
950
intersector.Points(index, p1, p2);
951
points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z()));
954
catch (Standard_Failure& exc) {
957
return !points.empty();
959
THROWM(Base::CADKernelError,exc.GetMessageString())
963
return !points.empty();
966
bool GeomCurve::closestParameter(const Base::Vector3d& point, double &u) const
968
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
970
if (!curve.IsNull()) {
971
gp_Pnt pnt(point.x,point.y,point.z);
972
GeomAPI_ProjectPointOnCurve ppc(pnt, curve);
973
u = ppc.LowerDistanceParameter();
977
catch (StdFail_NotDone& exc) {
978
if (curve->IsKind(STANDARD_TYPE(Geom_BoundedCurve))){
979
Base::Vector3d firstpoint = this->pointAtParameter(curve->FirstParameter());
980
Base::Vector3d lastpoint = this->pointAtParameter(curve->LastParameter());
982
if((firstpoint-point).Length() < (lastpoint-point).Length())
983
u = curve->FirstParameter();
985
u = curve->LastParameter();
988
THROWM(Base::CADKernelError, exc.GetMessageString())
992
catch (Standard_Failure& exc) {
993
THROWM(Base::CADKernelError, exc.GetMessageString())
999
bool GeomCurve::closestParameterToBasisCurve(const Base::Vector3d& point, double &u) const
1001
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1003
if (curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))){
1004
Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(handle());
1005
Handle(Geom_Curve) bc = tc->BasisCurve();
1008
gp_Pnt pnt(point.x,point.y,point.z);
1009
GeomAPI_ProjectPointOnCurve ppc(pnt, bc);
1010
u = ppc.LowerDistanceParameter();
1014
catch (Standard_Failure& exc) {
1015
THROWM(Base::CADKernelError, exc.GetMessageString())
1021
return this->closestParameter(point, u);
1025
double GeomCurve::getFirstParameter() const
1027
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1031
return curve->FirstParameter();
1033
catch (Standard_Failure& exc) {
1035
THROWM(Base::CADKernelError, exc.GetMessageString())
1039
double GeomCurve::getLastParameter() const
1041
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1045
return curve->LastParameter();
1047
catch (Standard_Failure& exc) {
1049
THROWM(Base::CADKernelError, exc.GetMessageString())
1053
double GeomCurve::curvatureAt(double u) const
1055
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1058
GeomLProp_CLProps prop(curve, u,2,Precision::Confusion());
1059
return prop.Curvature();
1061
catch (Standard_Failure& exc) {
1063
THROWM(Base::CADKernelError, exc.GetMessageString())
1067
double GeomCurve::length(double u, double v) const
1070
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1073
GeomAdaptor_Curve adaptor(curve);
1074
return GCPnts_AbscissaPoint::Length(adaptor,u,v,Precision::Confusion());
1076
catch (Standard_Failure& exc) {
1078
THROWM(Base::CADKernelError, exc.GetMessageString())
1082
void GeomCurve::reverse()
1084
Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(handle());
1089
catch (Standard_Failure& exc) {
1091
THROWM(Base::CADKernelError, exc.GetMessageString())
1098
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomBoundedCurve, Part::GeomCurve)
1100
GeomBoundedCurve::GeomBoundedCurve() = default;
1102
GeomBoundedCurve::~GeomBoundedCurve() = default;
1104
Base::Vector3d GeomBoundedCurve::getStartPoint() const
1106
Handle(Geom_BoundedCurve) curve = Handle(Geom_BoundedCurve)::DownCast(handle());
1107
gp_Pnt pnt = curve->StartPoint();
1109
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
1112
Base::Vector3d GeomBoundedCurve::getEndPoint() const
1114
Handle(Geom_BoundedCurve) curve = Handle(Geom_BoundedCurve)::DownCast(handle());
1115
gp_Pnt pnt = curve->EndPoint();
1117
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
1123
TYPESYSTEM_SOURCE(Part::GeomBezierCurve, Part::GeomBoundedCurve)
1125
GeomBezierCurve::GeomBezierCurve()
1127
TColgp_Array1OfPnt poles(1,2);
1128
poles(1) = gp_Pnt(0.0,0.0,0.0);
1129
poles(2) = gp_Pnt(0.0,0.0,1.0);
1130
Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(poles);
1131
this->myCurve = bezier;
1134
GeomBezierCurve::GeomBezierCurve(const Handle(Geom_BezierCurve)& bezier)
1139
GeomBezierCurve::GeomBezierCurve( const std::vector<Base::Vector3d>& poles, const std::vector<double>& weights)
1141
if (poles.size() != weights.size())
1142
throw Base::ValueError("poles and weights mismatch");
1144
TColgp_Array1OfPnt poleArray(1,poles.size());
1145
TColStd_Array1OfReal weightArray(1,poles.size());
1146
for (std::size_t index = 1; index <= poles.size(); index++) {
1147
poleArray.SetValue(index, gp_Pnt(poles[index-1].x,poles[index-1].y,poles[index-1].z));
1148
weightArray.SetValue(index, weights[index-1]);
1150
this->myCurve = new Geom_BezierCurve (poleArray, weightArray);
1153
GeomBezierCurve::~GeomBezierCurve() = default;
1155
void GeomBezierCurve::setHandle(const Handle(Geom_BezierCurve)& curve)
1157
myCurve = Handle(Geom_BezierCurve)::DownCast(curve->Copy());
1160
const Handle(Geom_Geometry)& GeomBezierCurve::handle() const
1165
Geometry *GeomBezierCurve::copy() const
1167
auto *newCurve = new GeomBezierCurve(myCurve);
1168
newCurve->copyNonTag(this);
1172
std::vector<Base::Vector3d> GeomBezierCurve::getPoles() const
1174
std::vector<Base::Vector3d> poles;
1175
poles.reserve(myCurve->NbPoles());
1176
TColgp_Array1OfPnt poleArray(1,myCurve->NbPoles());
1177
myCurve->Poles(poleArray);
1179
for (Standard_Integer index=poleArray.Lower(); index<=poleArray.Upper(); index++) {
1180
const gp_Pnt& pnt = poleArray(index);
1181
poles.emplace_back(pnt.X(), pnt.Y(), pnt.Z());
1186
std::vector<double> GeomBezierCurve::getWeights() const
1188
std::vector<double> weights;
1189
weights.reserve(myCurve->NbPoles());
1190
TColStd_Array1OfReal weightArray(1,myCurve->NbPoles());
1191
myCurve->Weights(weightArray);
1193
for (Standard_Integer index=weightArray.Lower(); index<=weightArray.Upper(); index++) {
1194
const Standard_Real& real = weightArray(index);
1195
weights.push_back(real);
1201
unsigned int GeomBezierCurve::getMemSize () const
1203
return sizeof(Geom_BezierCurve);
1206
void GeomBezierCurve::Save(Base::Writer& writer) const
1209
GeomCurve::Save(writer);
1211
std::vector<Base::Vector3d> poles = this->getPoles();
1212
std::vector<double> weights = this->getWeights();
1217
<< "PolesCount=\"" << poles.size() <<
1222
std::vector<Base::Vector3d>::const_iterator itp;
1223
std::vector<double>::const_iterator itw;
1225
for (itp = poles.begin(), itw = weights.begin(); itp != poles.end() && itw != weights.end(); ++itp, ++itw) {
1229
<< "X=\"" << (*itp).x <<
1230
"\" Y=\"" << (*itp).y <<
1231
"\" Z=\"" << (*itp).z <<
1232
"\" Weight=\"" << (*itw) <<
1233
"\"/>" << std::endl;
1237
writer.Stream() << writer.ind() << "</BezierCurve>" << std::endl ;
1240
void GeomBezierCurve::Restore(Base::XMLReader& reader)
1243
GeomCurve::Restore(reader);
1245
reader.readElement("BezierCurve");
1247
int polescount = reader.getAttributeAsInteger("PolesCount");
1249
TColgp_Array1OfPnt poleArray(1,polescount);
1250
TColStd_Array1OfReal weightArray(1,polescount);
1252
for (int index = 1; index <= polescount; index++) {
1253
reader.readElement("Pole");
1254
double X = reader.getAttributeAsFloat("X");
1255
double Y = reader.getAttributeAsFloat("Y");
1256
double Z = reader.getAttributeAsFloat("Z");
1257
double W = reader.getAttributeAsFloat("Weight");
1258
poleArray.SetValue(index, gp_Pnt(X,Y,Z));
1259
weightArray.SetValue(index, W);
1262
reader.readEndElement("BezierCurve");
1265
Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(poleArray, weightArray);
1267
if (!bezier.IsNull())
1268
this->myCurve = bezier;
1270
THROWM(Base::CADKernelError,"BezierCurve restore failed")
1272
catch (Standard_Failure& exc) {
1274
THROWM(Base::CADKernelError, exc.GetMessageString())
1278
PyObject *GeomBezierCurve::getPyObject()
1280
return new BezierCurvePy(dynamic_cast<GeomBezierCurve*>(this->clone()));
1283
bool GeomBezierCurve::isSame(const Geometry &_other, double tol, double) const
1285
if(_other.getTypeId() != getTypeId())
1288
auto &other = dynamic_cast<const GeomBezierCurve &>(_other);
1290
Standard_Integer c = myCurve->NbPoles();
1291
if(c!= other.myCurve->NbPoles())
1294
double tol2 = tol*tol;
1295
for(Standard_Integer index =1; index <=c; ++index) {
1296
if(myCurve->Pole(index).SquareDistance(other.myCurve->Pole(index)) > tol2
1297
|| fabs(myCurve->Weight(index) - other.myCurve->Weight(index)) > tol)
1305
TYPESYSTEM_SOURCE(Part::GeomBSplineCurve,Part::GeomBoundedCurve)
1307
GeomBSplineCurve::GeomBSplineCurve()
1309
TColgp_Array1OfPnt poles(1,2);
1310
poles(1) = gp_Pnt(0.0,0.0,0.0);
1311
poles(2) = gp_Pnt(1.0,0.0,0.0);
1313
TColStd_Array1OfReal knots(1,2);
1317
TColStd_Array1OfInteger mults(1,2);
1321
this->myCurve = new Geom_BSplineCurve(poles, knots, mults, 1);
1324
GeomBSplineCurve::GeomBSplineCurve(const Handle(Geom_BSplineCurve)& b)
1329
GeomBSplineCurve::GeomBSplineCurve( const std::vector<Base::Vector3d>& poles, const std::vector<double>& weights,
1330
const std::vector<double>& knots, const std::vector<int>& multiplicities,
1331
int degree, bool periodic, bool checkrational)
1333
if (poles.size() != weights.size())
1334
throw Base::ValueError("poles and weights mismatch");
1336
if (knots.size() != multiplicities.size())
1337
throw Base::ValueError("knots and multiplicities mismatch");
1339
TColgp_Array1OfPnt p(1,poles.size());
1340
TColStd_Array1OfReal w(1,poles.size());
1341
TColStd_Array1OfReal k(1,knots.size());
1342
TColStd_Array1OfInteger m(1,knots.size());
1344
for (std::size_t index = 1; index <= poles.size(); index++) {
1345
p.SetValue(index, gp_Pnt(poles[index -1].x,poles[index -1].y,poles[index -1].z));
1346
w.SetValue(index, weights[index -1]);
1349
for (std::size_t index = 1; index <= knots.size(); index++) {
1350
k.SetValue(index, knots[index -1]);
1351
m.SetValue(index, multiplicities[index -1]);
1354
this->myCurve = new Geom_BSplineCurve (p, w, k, m, degree, periodic?Standard_True:Standard_False, checkrational?Standard_True:Standard_False);
1359
GeomBSplineCurve::~GeomBSplineCurve() = default;
1361
void GeomBSplineCurve::setHandle(const Handle(Geom_BSplineCurve)& curve)
1363
myCurve = Handle(Geom_BSplineCurve)::DownCast(curve->Copy());
1366
const Handle(Geom_Geometry)& GeomBSplineCurve::handle() const
1371
Geometry *GeomBSplineCurve::copy() const
1374
auto *newCurve = new GeomBSplineCurve(myCurve);
1375
newCurve->copyNonTag(this);
1378
catch (Standard_Failure& exc) {
1379
THROWM(Base::CADKernelError, exc.GetMessageString())
1383
int GeomBSplineCurve::countPoles() const
1385
return myCurve->NbPoles();
1388
int GeomBSplineCurve::countKnots() const
1390
return myCurve->NbKnots();
1393
void GeomBSplineCurve::setPole(int index, const Base::Vector3d& pole, double weight)
1396
gp_Pnt pnt(pole.x,pole.y,pole.z);
1398
myCurve->SetPole(index,pnt);
1400
myCurve->SetPole(index,pnt,weight);
1402
catch (Standard_Failure& e) {
1403
THROWM(Base::CADKernelError,e.GetMessageString())
1407
std::list<Geometry*> GeomBSplineCurve::toBiArcs(double tolerance) const
1409
BSplineCurveBiArcs arcs(this->myCurve);
1410
return arcs.toBiArcs(tolerance);
1413
void GeomBSplineCurve::workAroundOCCTBug(const std::vector<double>& weights)
1423
if (weights.size() < 2)
1426
auto lastindex = myCurve->NbPoles();
1427
auto lastbutonevalue = myCurve->Weight(lastindex-1);
1428
double fakelastvalue = lastbutonevalue + weights[weights.size()-2];
1429
myCurve->SetWeight(weights.size(),fakelastvalue);
1432
void GeomBSplineCurve::setPoles(const std::vector<Base::Vector3d>& poles, const std::vector<double>& weights)
1434
if (poles.size() != weights.size())
1435
throw Base::ValueError("poles and weights mismatch");
1437
workAroundOCCTBug(weights);
1439
Standard_Integer index=1;
1441
for (std::size_t i = 0; i < poles.size(); i++, index++) {
1442
setPole(index, poles[i], weights[i]);
1446
void GeomBSplineCurve::setPoles(const std::vector<Base::Vector3d>& poles)
1448
Standard_Integer index=1;
1450
for (auto it = poles.begin(); it != poles.end(); ++it, index++){
1451
setPole(index, *it);
1455
std::vector<Base::Vector3d> GeomBSplineCurve::getPoles() const
1457
std::vector<Base::Vector3d> poles;
1458
poles.reserve(myCurve->NbPoles());
1459
TColgp_Array1OfPnt p(1,myCurve->NbPoles());
1462
for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
1463
const gp_Pnt& pnt = p(i);
1464
poles.emplace_back(pnt.X(), pnt.Y(), pnt.Z());
1469
std::vector<double> GeomBSplineCurve::getWeights() const
1471
std::vector<double> weights;
1472
weights.reserve(myCurve->NbPoles());
1473
TColStd_Array1OfReal w(1,myCurve->NbPoles());
1474
myCurve->Weights(w);
1476
for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
1477
const Standard_Real& real = w(i);
1478
weights.push_back(real);
1483
void GeomBSplineCurve::setWeights(const std::vector<double>& weights)
1485
workAroundOCCTBug(weights);
1488
Standard_Integer index=1;
1490
for (auto it = weights.begin(); it != weights.end(); ++it, index++){
1491
myCurve->SetWeight(index, *it);
1494
catch (Standard_Failure& e) {
1496
THROWM(Base::CADKernelError,e.GetMessageString())
1500
void GeomBSplineCurve::setKnot(int index, const double val, int mult)
1504
myCurve->SetKnot(index, val);
1506
myCurve->SetKnot(index, val, mult);
1508
catch (Standard_Failure& e) {
1510
THROWM(Base::CADKernelError,e.GetMessageString())
1514
void GeomBSplineCurve::setKnots(const std::vector<double>& knots)
1516
Standard_Integer index=1;
1518
for (auto it = knots.begin(); it != knots.end(); ++it, index++) {
1519
setKnot(index, *it);
1523
void GeomBSplineCurve::setKnots(const std::vector<double>& knots, const std::vector<int>& multiplicities)
1525
if (knots.size() != multiplicities.size())
1526
throw Base::ValueError("knots and multiplicities mismatch");
1528
Standard_Integer index=1;
1530
for (std::size_t it = 0; it < knots.size(); it++, index++) {
1531
setKnot(index, knots[it], multiplicities[it]);
1535
std::vector<double> GeomBSplineCurve::getKnots() const
1537
std::vector<double> knots;
1538
knots.reserve(myCurve->NbKnots());
1539
TColStd_Array1OfReal k(1,myCurve->NbKnots());
1542
for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) {
1543
const Standard_Real& real = k(i);
1544
knots.push_back(real);
1549
std::vector<int> GeomBSplineCurve::getMultiplicities() const
1551
std::vector<int> mults;
1552
mults.reserve(myCurve->NbKnots());
1553
TColStd_Array1OfInteger m(1,myCurve->NbKnots());
1554
myCurve->Multiplicities(m);
1556
for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) {
1557
const Standard_Integer& nm = m(i);
1558
mults.push_back(nm);
1563
int GeomBSplineCurve::getMultiplicity(int index) const
1566
return myCurve->Multiplicity(index);
1568
catch (Standard_Failure& e) {
1570
THROWM(Base::CADKernelError,e.GetMessageString())
1574
int GeomBSplineCurve::getDegree() const
1576
return myCurve->Degree();
1579
bool GeomBSplineCurve::isPeriodic() const
1581
return myCurve->IsPeriodic()==Standard_True;
1584
void GeomBSplineCurve::setPeriodic() const
1586
myCurve->SetPeriodic();
1589
bool GeomBSplineCurve::isRational() const
1591
return myCurve->IsRational()==Standard_True;
1594
bool GeomBSplineCurve::join(const Handle(Geom_BoundedCurve)& other)
1596
GeomConvert_CompCurveToBSplineCurve ccbc(this->myCurve);
1597
if (!ccbc.Add(other, Precision::Approximation()))
1599
this->myCurve = ccbc.BSplineCurve();
1603
void GeomBSplineCurve::interpolate(const std::vector<gp_Pnt>& p, Standard_Boolean periodic)
1606
Standard_ConstructionError::Raise();
1608
double tol3d = Precision::Approximation();
1609
Handle(TColgp_HArray1OfPnt) pts = new TColgp_HArray1OfPnt(1, p.size());
1610
for (std::size_t i=0; i<p.size(); i++) {
1611
pts->SetValue(i+1, p[i]);
1614
GeomAPI_Interpolate interpolate(pts, periodic, tol3d);
1615
interpolate.Perform();
1616
this->myCurve = interpolate.Curve();
1619
void GeomBSplineCurve::interpolate(const std::vector<gp_Pnt>& p,
1620
const std::vector<gp_Vec>& t)
1623
Standard_ConstructionError::Raise();
1624
if (p.size() != t.size())
1625
Standard_ConstructionError::Raise();
1627
double tol3d = Precision::Approximation();
1628
Handle(TColgp_HArray1OfPnt) pts = new TColgp_HArray1OfPnt(1, p.size());
1629
for (std::size_t i=0; i<p.size(); i++) {
1630
pts->SetValue(i+1, p[i]);
1633
TColgp_Array1OfVec tgs(1, t.size());
1634
Handle(TColStd_HArray1OfBoolean) fgs = new TColStd_HArray1OfBoolean(1, t.size());
1635
for (std::size_t i=0; i<p.size(); i++) {
1636
tgs.SetValue(i+1, t[i]);
1637
fgs->SetValue(i+1, Standard_True);
1640
GeomAPI_Interpolate interpolate(pts, Standard_False, tol3d);
1641
interpolate.Load(tgs, fgs);
1642
interpolate.Perform();
1643
this->myCurve = interpolate.Curve();
1646
void GeomBSplineCurve::getCardinalSplineTangents(const std::vector<gp_Pnt>& p,
1647
const std::vector<double>& c,
1648
std::vector<gp_Vec>& t) const
1652
Standard_ConstructionError::Raise();
1653
if (p.size() != c.size())
1654
Standard_ConstructionError::Raise();
1657
if (p.size() == 2) {
1658
t[0] = gp_Vec(p[0], p[1]);
1659
t[1] = gp_Vec(p[0], p[1]);
1662
std::size_t e = p.size() - 1;
1664
for (std::size_t i = 1; i < e; i++) {
1665
gp_Vec v = gp_Vec(p[i-1], p[i+1]);
1666
double f = 0.5 * (1-c[i]);
1672
t[t.size()-1] = t[t.size()-2];
1676
void GeomBSplineCurve::getCardinalSplineTangents(const std::vector<gp_Pnt>& p, double c,
1677
std::vector<gp_Vec>& t) const
1681
Standard_ConstructionError::Raise();
1684
if (p.size() == 2) {
1685
t[0] = gp_Vec(p[0], p[1]);
1686
t[1] = gp_Vec(p[0], p[1]);
1689
std::size_t e = p.size() - 1;
1690
double f = 0.5 * (1-c);
1692
for (std::size_t i = 1; i < e; i++) {
1693
gp_Vec v = gp_Vec(p[i-1], p[i+1]);
1699
t[t.size()-1] = t[t.size()-2];
1703
void GeomBSplineCurve::makeC1Continuous(double tol, double ang_tol)
1705
GeomConvert::C0BSplineToC1BSplineCurve(this->myCurve, tol, ang_tol);
1708
void GeomBSplineCurve::increaseDegree(int degree)
1711
Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(this->handle());
1712
curve->IncreaseDegree(degree);
1714
catch (Standard_Failure& e) {
1715
THROWM(Base::CADKernelError,e.GetMessageString())
1726
void GeomBSplineCurve::approximate(double tol3d, int maxSegments, int maxDegree,
1727
GeomAbs_Shape continuity)
1730
GeomAdaptor_Curve adapt(myCurve);
1731
Handle(GeomAdaptor_HCurve) hCurve = new GeomAdaptor_HCurve(adapt);
1732
Approx_Curve3d approx(hCurve, tol3d, continuity, maxSegments, maxDegree);
1733
if (approx.IsDone()) {
1734
this->setHandle(approx.Curve());
1736
else if (approx.HasResult()) {
1737
throw Standard_Failure("Approximation of B-Spline succeeded but is outside of tolerance");
1740
throw Standard_Failure("Approximation of B-Spline failed");
1743
catch (Standard_Failure& e) {
1744
THROWM(Base::CADKernelError, e.GetMessageString())
1748
void GeomBSplineCurve::approximate(const std::vector<Base::Vector3d>& pnts,
1749
int minDegree, int maxDegree,
1750
GeomAbs_Shape continuity, double tol3d)
1753
TColgp_Array1OfPnt coords(1, static_cast<int>(pnts.size()));
1754
Standard_Integer index = 1;
1755
for (const auto& it : pnts) {
1756
coords(index++) = gp_Pnt(it.x, it.y, it.z);
1759
GeomAPI_PointsToBSpline fit(coords, minDegree, maxDegree, continuity, tol3d);
1760
const Handle(Geom_BSplineCurve)& spline = fit.Curve();
1761
if (!spline.IsNull()) {
1765
throw Standard_Failure("Failed to approximate B-Spline");
1768
catch (Standard_Failure& e) {
1769
THROWM(Base::CADKernelError, e.GetMessageString())
1773
void GeomBSplineCurve::approximate(const std::vector<Base::Vector3d>& pnts,
1774
Approx_ParametrizationType parType,
1775
int minDegree, int maxDegree,
1776
GeomAbs_Shape continuity, double tol3d)
1779
TColgp_Array1OfPnt coords(1, static_cast<int>(pnts.size()));
1780
Standard_Integer index = 1;
1781
for (const auto& it : pnts) {
1782
coords(index++) = gp_Pnt(it.x, it.y, it.z);
1785
GeomAPI_PointsToBSpline fit(coords, parType, minDegree, maxDegree, continuity, tol3d);
1786
const Handle(Geom_BSplineCurve)& spline = fit.Curve();
1787
if (!spline.IsNull()) {
1791
throw Standard_Failure("Failed to approximate B-Spline");
1794
catch (Standard_Failure& e) {
1795
THROWM(Base::CADKernelError, e.GetMessageString())
1810
void GeomBSplineCurve::approximate(const std::vector<Base::Vector3d>& pnts,
1811
double weight1, double weight2, double weight3,
1812
int maxDegree, GeomAbs_Shape continuity, double tol3d)
1815
TColgp_Array1OfPnt coords(1, static_cast<int>(pnts.size()));
1816
Standard_Integer index = 1;
1817
for (const auto& it : pnts) {
1818
coords(index++) = gp_Pnt(it.x, it.y, it.z);
1821
GeomAPI_PointsToBSpline fit(coords, weight1, weight2, weight3,
1822
maxDegree, continuity, tol3d);
1823
const Handle(Geom_BSplineCurve)& spline = fit.Curve();
1824
if (!spline.IsNull()) {
1828
throw Standard_Failure("Failed to approximate B-Spline");
1831
catch (Standard_Failure& e) {
1832
THROWM(Base::CADKernelError, e.GetMessageString())
1836
void GeomBSplineCurve::increaseMultiplicity(int index, int multiplicity)
1839
Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(this->handle());
1840
curve->IncreaseMultiplicity(index, multiplicity);
1842
catch (Standard_Failure& e) {
1843
THROWM(Base::CADKernelError,e.GetMessageString())
1847
void GeomBSplineCurve::insertKnot(double param, int multiplicity)
1850
Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(this->handle());
1851
curve->InsertKnot(param, multiplicity);
1854
catch (Standard_Failure& e) {
1855
THROWM(Base::CADKernelError,e.GetMessageString())
1859
bool GeomBSplineCurve::removeKnot(int index, int multiplicity, double tolerance)
1862
Handle(Geom_BSplineCurve) curve =Handle(Geom_BSplineCurve)::DownCast(myCurve->Copy());
1863
if (curve->RemoveKnot(index, multiplicity, tolerance)) {
1866
TColStd_Array1OfReal weights(1, curve->NbPoles());
1867
curve->Weights(weights);
1868
for (Standard_Integer i = weights.Lower(); i <= weights.Upper(); i++) {
1869
double v = weights(i);
1870
if (v <= gp::Resolution())
1880
catch (Standard_Failure& e) {
1881
THROWM(Base::CADKernelError,e.GetMessageString())
1885
void GeomBSplineCurve::Trim(double u, double v)
1887
auto splitUnwrappedBSpline = [this](double u, double v) {
1889
auto handle = GeomConvert::SplitBSplineCurve ( myCurve,
1892
Precision::Confusion()
1898
if (isPeriodic() && (v < u)) {
1899
v = v + (getLastParameter() - getFirstParameter());
1901
splitUnwrappedBSpline(u, v);
1903
catch (Standard_Failure& e) {
1904
THROWM(Base::CADKernelError,e.GetMessageString())
1908
void GeomBSplineCurve::scaleKnotsToBounds(double u0, double u1)
1911
Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(myCurve->Copy());
1912
Standard_RangeError_Raise_if (u1 <= u0, " ");
1913
TColStd_Array1OfReal k(1,curve->NbKnots());
1915
if ((abs(u0-k.First()) > Precision::Confusion()) || (abs(u1-k.Last()) > Precision::Confusion())) {
1916
BSplCLib::Reparametrize(u0, u1, k);
1922
catch (Standard_Failure& e) {
1923
THROWM(Base::CADKernelError,e.GetMessageString())
1928
unsigned int GeomBSplineCurve::getMemSize () const
1930
return sizeof(Geom_BSplineCurve);
1933
void GeomBSplineCurve::Save(Base::Writer& writer) const
1936
GeomCurve::Save(writer);
1938
std::vector<Base::Vector3d> poles = this->getPoles();
1939
std::vector<double> weights = this->getWeights();
1940
std::vector<double> knots = this->getKnots();
1941
std::vector<int> mults = this->getMultiplicities();
1942
int degree = this->getDegree();
1943
bool isperiodic = this->isPeriodic();
1948
<< "PolesCount=\"" << poles.size() <<
1949
"\" KnotsCount=\"" << knots.size() <<
1950
"\" Degree=\"" << degree <<
1951
"\" IsPeriodic=\"" << (int) isperiodic <<
1956
std::vector<Base::Vector3d>::const_iterator itp;
1957
std::vector<double>::const_iterator itw;
1959
for (itp = poles.begin(), itw = weights.begin(); itp != poles.end() && itw != weights.end(); ++itp, ++itw) {
1963
<< "X=\"" << (*itp).x <<
1964
"\" Y=\"" << (*itp).y <<
1965
"\" Z=\"" << (*itp).z <<
1966
"\" Weight=\"" << (*itw) <<
1967
"\"/>" << std::endl;
1970
std::vector<double>::const_iterator itk;
1971
std::vector<int>::const_iterator itm;
1973
for (itk = knots.begin(), itm = mults.begin(); itk != knots.end() && itm != mults.end(); ++itk, ++itm) {
1977
<< "Value=\"" << (*itk)
1978
<< "\" Mult=\"" << (*itm) <<
1979
"\"/>" << std::endl;
1983
writer.Stream() << writer.ind() << "</BSplineCurve>" << std::endl ;
1986
void GeomBSplineCurve::Restore(Base::XMLReader& reader)
1989
GeomCurve::Restore(reader);
1991
reader.readElement("BSplineCurve");
1993
int polescount = reader.getAttributeAsInteger("PolesCount");
1994
int knotscount = reader.getAttributeAsInteger("KnotsCount");
1995
int degree = reader.getAttributeAsInteger("Degree");
1996
bool isperiodic = (bool) reader.getAttributeAsInteger("IsPeriodic");
2003
TColgp_Array1OfPnt p(1,polescount);
2004
TColStd_Array1OfReal w(1,polescount);
2005
TColStd_Array1OfReal k(1,knotscount);
2006
TColStd_Array1OfInteger m(1,knotscount);
2008
for (int i = 1; i <= polescount; i++) {
2009
reader.readElement("Pole");
2010
double X = reader.getAttributeAsFloat("X");
2011
double Y = reader.getAttributeAsFloat("Y");
2012
double Z = reader.getAttributeAsFloat("Z");
2013
double W = reader.getAttributeAsFloat("Weight");
2014
p.SetValue(i, gp_Pnt(X,Y,Z));
2018
for (int i = 1; i <= knotscount; i++) {
2019
reader.readElement("Knot");
2020
double val = reader.getAttributeAsFloat("Value");
2021
Standard_Integer mult = reader.getAttributeAsInteger("Mult");
2023
m.SetValue(i, mult);
2026
reader.readEndElement("BSplineCurve");
2030
Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(p, w, k, m, degree, isperiodic ? Standard_True : Standard_False, Standard_False);
2032
if (!spline.IsNull())
2033
this->myCurve = spline;
2035
THROWM(Base::CADKernelError,"BSpline restore failed")
2037
catch (Standard_Failure& e) {
2039
THROWM(Base::CADKernelError,e.GetMessageString())
2044
PyObject *GeomBSplineCurve::getPyObject()
2046
return new BSplineCurvePy(dynamic_cast<GeomBSplineCurve*>(this->clone()));
2049
bool GeomBSplineCurve::isSame(const Geometry &_other, double tol, double atol) const
2051
if(_other.getTypeId() != getTypeId()) {
2052
if (isLinear() && _other.isDerivedFrom(GeomCurve::getClassTypeId())) {
2053
std::unique_ptr<Geometry> geo(toLineSegment());
2055
return geo->isSame(_other, tol, atol);
2060
auto &other = dynamic_cast<const GeomBSplineCurve &>(_other);
2063
if(countPoles() != other.countPoles()
2064
|| countKnots() != other.countKnots()
2065
|| getDegree() != other.getDegree()
2066
|| isPeriodic() != other.isPeriodic())
2069
double tol2 = tol*tol;
2070
for(int i=1, c=countPoles(); i<=c; ++i) {
2071
if(myCurve->Pole(i).SquareDistance(other.myCurve->Pole(i)) > tol2
2072
|| fabs(myCurve->Weight(i) - other.myCurve->Weight(i)) > tol)
2077
for(int i=1, c=countKnots(); i<=c; ++i) {
2078
if(fabs(myCurve->Knot(i) - other.myCurve->Knot(i)) > tol)
2087
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomConic, Part::GeomCurve)
2089
GeomConic::GeomConic() = default;
2091
GeomConic::~GeomConic() = default;
2093
Base::Vector3d GeomConic::getLocation() const
2095
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2096
gp_Ax1 axis = conic->Axis();
2097
const gp_Pnt& loc = axis.Location();
2098
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
2101
void GeomConic::setLocation(const Base::Vector3d& Center)
2103
gp_Pnt p1(Center.x,Center.y,Center.z);
2104
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2107
conic->SetLocation(p1);
2109
catch (Standard_Failure& e) {
2111
THROWM(Base::CADKernelError,e.GetMessageString())
2115
Base::Vector3d GeomConic::getCenter() const
2117
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2118
gp_Ax1 axis = conic->Axis();
2119
const gp_Pnt& loc = axis.Location();
2120
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
2123
void GeomConic::setCenter(const Base::Vector3d& Center)
2125
gp_Pnt p1(Center.x,Center.y,Center.z);
2126
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2129
conic->SetLocation(p1);
2131
catch (Standard_Failure& e) {
2133
THROWM(Base::CADKernelError,e.GetMessageString())
2137
Base::Vector3d GeomConic::getAxisDirection() const
2139
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2140
gp_Ax1 axis = conic->Axis();
2141
const gp_Dir& dir = axis.Direction();
2142
return Base::Vector3d( dir.X(),dir.Y(),dir.Z());
2155
double GeomConic::getAngleXU() const
2157
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2159
gp_Pnt center = conic->Axis().Location();
2160
gp_Dir normal = conic->Axis().Direction();
2161
gp_Dir xdir = conic->XAxis().Direction();
2164
gp_Ax2 xdirref(center, normal);
2166
return -xdir.AngleWithRef(xdirref.XDirection(),normal);
2174
void GeomConic::setAngleXU(double angle)
2176
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());;
2179
gp_Pnt center = conic->Axis().Location();
2180
gp_Dir normal = conic->Axis().Direction();
2182
gp_Ax1 normaxis(center, normal);
2183
gp_Ax2 xdirref(center, normal);
2185
xdirref.Rotate(normaxis,angle);
2186
conic->SetPosition(xdirref);
2188
catch (Standard_Failure& e) {
2190
THROWM(Base::CADKernelError,e.GetMessageString())
2200
bool GeomConic::isReversed() const
2202
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2203
assert(!conic.IsNull());
2204
return conic->Axis().Direction().Z() < 0;
2207
GeomBSplineCurve* GeomConic::toNurbs(double first, double last) const
2209
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2210
Handle(Geom_Curve) curve = new Geom_TrimmedCurve(conic, first, last);
2213
Handle(Geom_BSplineCurve) bspline = GeomConvert::CurveToBSplineCurve(curve);
2214
Standard_Real fnew = bspline->FirstParameter(), lnew = bspline->LastParameter(), UTol;
2215
if (!bspline->IsPeriodic()) {
2216
bspline->Resolution(Precision::Confusion(), UTol);
2217
if (Abs(first - fnew) > UTol || Abs(last - lnew) > UTol) {
2218
TColStd_Array1OfReal knots(1,bspline->NbKnots());
2219
bspline->Knots(knots);
2220
BSplCLib::Reparametrize(first, last, knots);
2221
bspline->SetKnots(knots);
2225
return new GeomBSplineCurve(bspline);
2228
bool GeomConic::isSame(const Geometry &_other, double tol, double atol) const
2230
if(!_other.isDerivedFrom(GeomConic::getClassTypeId()))
2233
auto &other = static_cast<const GeomConic &>(_other);
2235
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(handle());
2236
Handle(Geom_Conic) conic2 = Handle(Geom_Conic)::DownCast(other.handle());
2238
return conic->Position().XDirection().Angle(conic2->Position().XDirection()) <= atol
2239
&& conic->Position().YDirection().Angle(conic2->Position().YDirection()) <= atol
2240
&& Base::DistanceP2(getLocation(),other.getLocation()) <= tol*tol;
2245
TYPESYSTEM_SOURCE(Part::GeomTrimmedCurve,Part::GeomBoundedCurve)
2247
GeomTrimmedCurve::GeomTrimmedCurve() = default;
2249
GeomTrimmedCurve::GeomTrimmedCurve(const Handle(Geom_TrimmedCurve)& c)
2254
GeomTrimmedCurve::~GeomTrimmedCurve() = default;
2256
void GeomTrimmedCurve::setHandle(const Handle(Geom_TrimmedCurve)& c)
2258
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
2261
const Handle(Geom_Geometry)& GeomTrimmedCurve::handle() const
2266
Geometry *GeomTrimmedCurve::copy() const
2268
GeomTrimmedCurve *newCurve = new GeomTrimmedCurve(myCurve);
2269
newCurve->copyNonTag(this);
2274
unsigned int GeomTrimmedCurve::getMemSize () const
2276
return sizeof(Geom_TrimmedCurve);
2279
void GeomTrimmedCurve::Save(Base::Writer &) const
2281
throw Base::NotImplementedError("GeomTrimmedCurve::Save");
2284
void GeomTrimmedCurve::Restore(Base::XMLReader &)
2286
throw Base::NotImplementedError("GeomTrimmedCurve::Restore");
2289
PyObject *GeomTrimmedCurve::getPyObject()
2291
return new TrimmedCurvePy(static_cast<GeomTrimmedCurve*>(this->clone()));
2294
bool GeomTrimmedCurve::isSame(const Geometry &_other, double tol, double atol) const
2296
if(_other.getTypeId() != getTypeId())
2299
auto &other = static_cast<const GeomTrimmedCurve &>(_other);
2302
other.getRange(u1,v1);
2303
if(fabs(u-u1)>tol || fabs(v-v1)>tol)
2306
Handle(Geom_Curve) basis = myCurve->BasisCurve();
2307
Handle(Geom_Curve) basis1 = other.myCurve->BasisCurve();
2308
if(basis.IsNull() || basis1.IsNull() || basis->DynamicType() != basis1->DynamicType())
2311
std::unique_ptr<Geometry> b(makeFromCurve(basis));
2312
std::unique_ptr<Geometry> b1(makeFromCurve(basis1));
2313
if (b && b1 && b->isSame(*b1, tol, atol))
2318
bool GeomTrimmedCurve::intersectBasisCurves( const GeomTrimmedCurve * c,
2319
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
2322
Handle(Geom_TrimmedCurve) curve1 = Handle(Geom_TrimmedCurve)::DownCast(handle());
2323
Handle(Geom_TrimmedCurve) curve2 = Handle(Geom_TrimmedCurve)::DownCast(c->handle());
2325
Handle(Geom_Curve) bcurve1 = curve1->BasisCurve();
2326
Handle(Geom_Curve) bcurve2 = curve2->BasisCurve();
2329
if(!bcurve1.IsNull() && !bcurve2.IsNull()) {
2331
return intersect(bcurve1, bcurve2, points, tol);
2338
void GeomTrimmedCurve::getRange(double& u, double& v) const
2340
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2341
u = curve->FirstParameter();
2342
v = curve->LastParameter();
2345
void GeomTrimmedCurve::setRange(double u, double v)
2348
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2350
curve->SetTrim(u, v);
2352
catch (Standard_Failure& e) {
2353
THROWM(Base::CADKernelError,e.GetMessageString())
2358
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomArcOfConic,Part::GeomTrimmedCurve)
2360
GeomArcOfConic::GeomArcOfConic() = default;
2362
GeomArcOfConic::~GeomArcOfConic() = default;
2370
Base::Vector3d GeomArcOfConic::getStartPoint(bool emulateCCWXY) const
2372
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2373
gp_Pnt pnt = curve->StartPoint();
2376
pnt = curve->EndPoint();
2378
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
2387
Base::Vector3d GeomArcOfConic::getEndPoint(bool emulateCCWXY) const
2389
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2390
gp_Pnt pnt = curve->EndPoint();
2393
pnt = curve->StartPoint();
2395
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
2398
Base::Vector3d GeomArcOfConic::getCenter() const
2400
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2401
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2402
gp_Ax1 axis = conic->Axis();
2403
const gp_Pnt& loc = axis.Location();
2404
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
2407
Base::Vector3d GeomArcOfConic::getLocation() const
2409
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2410
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2411
gp_Ax1 axis = conic->Axis();
2412
const gp_Pnt& loc = axis.Location();
2413
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
2416
void GeomArcOfConic::setCenter(const Base::Vector3d& Center)
2418
gp_Pnt p1(Center.x,Center.y,Center.z);
2419
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2420
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2423
conic->SetLocation(p1);
2425
catch (Standard_Failure& e) {
2427
THROWM(Base::CADKernelError,e.GetMessageString())
2431
void GeomArcOfConic::setLocation(const Base::Vector3d& Center)
2433
gp_Pnt p1(Center.x,Center.y,Center.z);
2434
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2435
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2438
conic->SetLocation(p1);
2440
catch (Standard_Failure& e) {
2442
THROWM(Base::CADKernelError,e.GetMessageString())
2446
Base::Vector3d GeomArcOfConic::getAxisDirection() const
2448
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2449
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2450
gp_Ax1 axis = conic->Axis();
2451
const gp_Dir& dir = axis.Direction();
2452
return Base::Vector3d( dir.X(),dir.Y(),dir.Z());
2461
bool GeomArcOfConic::isReversed() const
2463
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2464
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2465
assert(!conic.IsNull());
2466
return conic->Axis().Direction().Z() < 0;
2479
double GeomArcOfConic::getAngleXU() const
2481
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2482
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2484
gp_Pnt center = conic->Axis().Location();
2485
gp_Dir normal = conic->Axis().Direction();
2486
gp_Dir xdir = conic->XAxis().Direction();
2488
gp_Ax2 xdirref(center, normal);
2490
return -xdir.AngleWithRef(xdirref.XDirection(),normal);
2496
void GeomArcOfConic::setAngleXU(double angle)
2498
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2499
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2502
gp_Pnt center = conic->Axis().Location();
2503
gp_Dir normal = conic->Axis().Direction();
2505
gp_Ax1 normaxis(center, normal);
2506
gp_Ax2 xdirref(center, normal);
2508
xdirref.Rotate(normaxis,angle);
2509
conic->SetPosition(xdirref);
2511
catch (Standard_Failure& e) {
2513
THROWM(Base::CADKernelError,e.GetMessageString())
2522
Base::Vector3d GeomArcOfConic::getXAxisDir() const
2524
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2525
Handle(Geom_Conic) c = Handle(Geom_Conic)::DownCast( curve->BasisCurve() );
2526
assert(!c.IsNull());
2527
gp_Dir xdir = c->XAxis().Direction();
2528
return Base::Vector3d(xdir.X(), xdir.Y(), xdir.Z());
2539
void GeomArcOfConic::setXAxisDir(const Base::Vector3d& newdir)
2541
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2542
Handle(Geom_Conic) c = Handle(Geom_Conic)::DownCast( curve->BasisCurve() );
2543
assert(!c.IsNull());
2545
if (newdir.Sqr() < Precision::SquareConfusion())
2549
gp_Ax2 pos = c->Position();
2551
pos.SetXDirection(gp_Dir(newdir.x, newdir.y, newdir.z));
2552
c->SetPosition(pos);
2554
catch (Standard_Failure& e) {
2556
THROWM(Base::CADKernelError,e.GetMessageString())
2562
TYPESYSTEM_SOURCE(Part::GeomCircle,Part::GeomConic)
2564
GeomCircle::GeomCircle()
2566
Handle(Geom_Circle) c = new Geom_Circle(gp_Circ());
2570
GeomCircle::GeomCircle(const Handle(Geom_Circle)& c)
2575
GeomCircle::~GeomCircle() = default;
2577
const Handle(Geom_Geometry)& GeomCircle::handle() const
2583
void GeomCircle::setHandle(const Handle(Geom_Circle)& c)
2585
myCurve = Handle(Geom_Circle)::DownCast(c->Copy());
2588
Geometry *GeomCircle::copy() const
2590
GeomCircle *newCirc = new GeomCircle(myCurve);
2591
newCirc->copyNonTag(this);
2595
GeomBSplineCurve* GeomCircle::toNurbs(double first, double last) const
2598
if (first != 0 || last != 2*M_PI) {
2599
return GeomConic::toNurbs(first, last);
2602
Handle(Geom_Circle) conic = Handle(Geom_Circle)::DownCast(handle());
2603
double radius = conic->Radius();
2605
TColgp_Array1OfPnt poles(1, 7);
2606
poles(1) = gp_Pnt(radius, 0, 0);
2607
poles(2) = gp_Pnt(radius, 2*radius, 0);
2608
poles(3) = gp_Pnt(-radius, 2*radius, 0);
2609
poles(4) = gp_Pnt(-radius, 0, 0);
2610
poles(5) = gp_Pnt(-radius, -2*radius, 0);
2611
poles(6) = gp_Pnt(radius, -2*radius, 0);
2612
poles(7) = gp_Pnt(radius, 0, 0);
2615
trsf.SetTransformation(conic->Position(), gp_Ax3());
2616
TColStd_Array1OfReal weights(1,7);
2617
for (int i=1; i<=7; i++) {
2618
poles(i).Transform(trsf);
2625
TColStd_Array1OfInteger mults(1, 3);
2630
TColStd_Array1OfReal knots(1, 3);
2635
Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles, weights,knots, mults, 3,
2636
Standard_False, Standard_True);
2637
return new GeomBSplineCurve(spline);
2640
double GeomCircle::getRadius() const
2642
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(handle());
2643
return circle->Radius();
2646
void GeomCircle::setRadius(double Radius)
2648
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(handle());
2651
gp_Circ c = circle->Circ();
2652
c.SetRadius(Radius);
2655
catch (Standard_Failure& e) {
2657
THROWM(Base::CADKernelError,e.GetMessageString())
2662
unsigned int GeomCircle::getMemSize () const
2664
return sizeof(Geom_Circle);
2667
void GeomCircle::Save(Base::Writer& writer) const
2670
GeomCurve::Save(writer);
2672
gp_Pnt center = this->myCurve->Axis().Location();
2673
gp_Dir normal = this->myCurve->Axis().Direction();
2674
gp_Dir xdir = this->myCurve->XAxis().Direction();
2676
gp_Ax2 xdirref(center, normal);
2677
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
2682
<< "CenterX=\"" << center.X() <<
2683
"\" CenterY=\"" << center.Y() <<
2684
"\" CenterZ=\"" << center.Z() <<
2685
"\" NormalX=\"" << normal.X() <<
2686
"\" NormalY=\"" << normal.Y() <<
2687
"\" NormalZ=\"" << normal.Z() <<
2688
"\" AngleXU=\"" << AngleXU <<
2689
"\" Radius=\"" << this->myCurve->Radius() <<
2690
"\"/>" << std::endl;
2693
void GeomCircle::Restore(Base::XMLReader& reader)
2696
GeomCurve::Restore(reader);
2698
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Radius;
2701
reader.readElement("Circle");
2703
CenterX = reader.getAttributeAsFloat("CenterX");
2704
CenterY = reader.getAttributeAsFloat("CenterY");
2705
CenterZ = reader.getAttributeAsFloat("CenterZ");
2706
NormalX = reader.getAttributeAsFloat("NormalX");
2707
NormalY = reader.getAttributeAsFloat("NormalY");
2708
NormalZ = reader.getAttributeAsFloat("NormalZ");
2709
if (reader.hasAttribute("AngleXU"))
2710
AngleXU = reader.getAttributeAsFloat("AngleXU");
2711
Radius = reader.getAttributeAsFloat("Radius");
2714
gp_Pnt p1(CenterX,CenterY,CenterZ);
2715
gp_Dir norm(NormalX,NormalY,NormalZ);
2717
gp_Ax1 normaxis(p1,norm);
2718
gp_Ax2 xdir(p1, norm);
2719
xdir.Rotate(normaxis,AngleXU);
2722
GC_MakeCircle mc(xdir, Radius);
2724
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
2726
this->myCurve = mc.Value();
2728
catch (Standard_Failure& e) {
2730
THROWM(Base::CADKernelError,e.GetMessageString())
2734
PyObject *GeomCircle::getPyObject()
2736
return new CirclePy(static_cast<GeomCircle*>(this->clone()));
2739
bool GeomCircle::isSame(const Geometry &_other, double tol, double atol) const
2741
if(_other.getTypeId() != getTypeId())
2745
auto &other = static_cast<const GeomCircle &>(_other);
2746
return GeomConic::isSame(other,tol,atol) && fabs(getRadius() - other.getRadius()) <= tol;
2751
TYPESYSTEM_SOURCE(Part::GeomArcOfCircle,Part::GeomArcOfConic)
2753
GeomArcOfCircle::GeomArcOfCircle()
2755
Handle(Geom_Circle) c = new Geom_Circle(gp_Circ());
2756
this->myCurve = new Geom_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
2759
GeomArcOfCircle::GeomArcOfCircle(const Handle(Geom_Circle)& c)
2764
GeomArcOfCircle::~GeomArcOfCircle() = default;
2766
void GeomArcOfCircle::setHandle(const Handle(Geom_TrimmedCurve)& c)
2768
Handle(Geom_Circle) basis = Handle(Geom_Circle)::DownCast(c->BasisCurve());
2770
Standard_Failure::Raise("Basis curve is not a circle");
2771
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
2774
void GeomArcOfCircle::setHandle(const Handle(Geom_Circle)& c)
2776
this->myCurve = new Geom_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
2780
const Handle(Geom_Geometry)& GeomArcOfCircle::handle() const
2785
Geometry *GeomArcOfCircle::copy() const
2787
GeomArcOfCircle* copy = new GeomArcOfCircle();
2788
copy->setHandle(this->myCurve);
2789
copy->copyNonTag(this);
2793
GeomBSplineCurve* GeomArcOfCircle::toNurbs(double first, double last) const
2795
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2796
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(curve->BasisCurve());
2797
return GeomCircle(circle).toNurbs(first, last);
2800
double GeomArcOfCircle::getRadius() const
2802
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(myCurve->BasisCurve());
2803
return circle->Radius();
2806
void GeomArcOfCircle::setRadius(double Radius)
2808
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(myCurve->BasisCurve());
2811
gp_Circ c = circle->Circ();
2812
c.SetRadius(Radius);
2815
catch (Standard_Failure& e) {
2817
THROWM(Base::CADKernelError,e.GetMessageString())
2826
double GeomArcOfCircle::getAngle(bool emulateCCWXY) const
2828
double startangle, endangle;
2829
getRange(startangle, endangle, emulateCCWXY);
2830
double angle = endangle - startangle;
2843
void GeomArcOfCircle::getRange(double& u, double& v, bool emulateCCWXY) const
2845
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2846
u = curve->FirstParameter();
2847
v = curve->LastParameter();
2849
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2850
double angleXU = -conic->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0));
2851
double u1 = u, v1 = v;
2852
if (conic->Axis().Direction().Z() > 0.0){
2879
void GeomArcOfCircle::setRange(double u, double v, bool emulateCCWXY)
2882
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
2884
Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(curve->BasisCurve());
2885
double angleXU = -conic->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0));
2886
double u1 = u, v1 = v;
2887
if (conic->Axis().Direction().Z() > 0.0){
2899
curve->SetTrim(u, v);
2901
catch (Standard_Failure& e) {
2903
THROWM(Base::CADKernelError,e.GetMessageString())
2908
unsigned int GeomArcOfCircle::getMemSize () const
2910
return sizeof(Geom_Circle) + 2 *sizeof(double);
2913
void GeomArcOfCircle::Save(Base::Writer &writer) const
2916
Geometry::Save(writer);
2918
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(this->myCurve->BasisCurve());
2920
gp_Pnt center = circle->Axis().Location();
2921
gp_Dir normal = circle->Axis().Direction();
2922
gp_Dir xdir = circle->XAxis().Direction();
2924
gp_Ax2 xdirref(center, normal);
2925
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
2930
<< "CenterX=\"" << center.X() <<
2931
"\" CenterY=\"" << center.Y() <<
2932
"\" CenterZ=\"" << center.Z() <<
2933
"\" NormalX=\"" << normal.X() <<
2934
"\" NormalY=\"" << normal.Y() <<
2935
"\" NormalZ=\"" << normal.Z() <<
2936
"\" AngleXU=\"" << AngleXU <<
2937
"\" Radius=\"" << circle->Radius() <<
2938
"\" StartAngle=\"" << this->myCurve->FirstParameter() <<
2939
"\" EndAngle=\"" << this->myCurve->LastParameter() <<
2940
"\"/>" << std::endl;
2943
void GeomArcOfCircle::Restore(Base::XMLReader &reader)
2946
Geometry::Restore(reader);
2948
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Radius,StartAngle,EndAngle;
2951
reader.readElement("ArcOfCircle");
2953
CenterX = reader.getAttributeAsFloat("CenterX");
2954
CenterY = reader.getAttributeAsFloat("CenterY");
2955
CenterZ = reader.getAttributeAsFloat("CenterZ");
2956
NormalX = reader.getAttributeAsFloat("NormalX");
2957
NormalY = reader.getAttributeAsFloat("NormalY");
2958
NormalZ = reader.getAttributeAsFloat("NormalZ");
2959
if (reader.hasAttribute("AngleXU"))
2960
AngleXU = reader.getAttributeAsFloat("AngleXU");
2961
Radius = reader.getAttributeAsFloat("Radius");
2962
StartAngle = reader.getAttributeAsFloat("StartAngle");
2963
EndAngle = reader.getAttributeAsFloat("EndAngle");
2966
gp_Pnt p1(CenterX,CenterY,CenterZ);
2967
gp_Dir norm(NormalX,NormalY,NormalZ);
2969
gp_Ax1 normaxis(p1,norm);
2970
gp_Ax2 xdir(p1, norm);
2971
xdir.Rotate(normaxis,AngleXU);
2974
GC_MakeCircle mc(xdir, Radius);
2976
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
2977
GC_MakeArcOfCircle ma(mc.Value()->Circ(), StartAngle, EndAngle, Standard_True);
2979
THROWM(Base::CADKernelError,gce_ErrorStatusText(ma.Status()))
2981
Handle(Geom_TrimmedCurve) tmpcurve = ma.Value();
2982
Handle(Geom_Circle) tmpcircle = Handle(Geom_Circle)::DownCast(tmpcurve->BasisCurve());
2983
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(this->myCurve->BasisCurve());
2985
circle->SetCirc(tmpcircle->Circ());
2986
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
2988
catch (Standard_Failure& e) {
2990
THROWM(Base::CADKernelError,e.GetMessageString())
2994
PyObject *GeomArcOfCircle::getPyObject()
2996
return new ArcOfCirclePy(static_cast<GeomArcOfCircle*>(this->clone()));
3001
TYPESYSTEM_SOURCE(Part::GeomEllipse,Part::GeomConic)
3003
GeomEllipse::GeomEllipse()
3005
Handle(Geom_Ellipse) e = new Geom_Ellipse(gp_Elips());
3009
GeomEllipse::GeomEllipse(const Handle(Geom_Ellipse)& e)
3014
GeomEllipse::~GeomEllipse() = default;
3016
const Handle(Geom_Geometry)& GeomEllipse::handle() const
3021
void GeomEllipse::setHandle(const Handle(Geom_Ellipse) &e)
3023
this->myCurve = Handle(Geom_Ellipse)::DownCast(e->Copy());
3026
Geometry *GeomEllipse::copy() const
3028
GeomEllipse *newEllipse = new GeomEllipse(myCurve);
3029
newEllipse->copyNonTag(this);
3033
GeomBSplineCurve* GeomEllipse::toNurbs(double first, double last) const
3036
if (first != 0 || last != 2*M_PI) {
3037
return GeomConic::toNurbs(first, last);
3040
Handle(Geom_Ellipse) conic = Handle(Geom_Ellipse)::DownCast(handle());
3041
Standard_Real majorRadius = conic->MajorRadius();
3042
Standard_Real minorRadius = conic->MinorRadius();
3044
TColgp_Array1OfPnt poles(1, 7);
3045
poles(1) = gp_Pnt(majorRadius, 0, 0);
3046
poles(2) = gp_Pnt(majorRadius, 2*minorRadius, 0);
3047
poles(3) = gp_Pnt(-majorRadius, 2*minorRadius, 0);
3048
poles(4) = gp_Pnt(-majorRadius, 0, 0);
3049
poles(5) = gp_Pnt(-majorRadius, -2*minorRadius, 0);
3050
poles(6) = gp_Pnt(majorRadius, -2*minorRadius, 0);
3051
poles(7) = gp_Pnt(majorRadius, 0, 0);
3054
trsf.SetTransformation(conic->Position(), gp_Ax3());
3055
TColStd_Array1OfReal weights(1,7);
3056
for (int i=1; i<=7; i++) {
3057
poles(i).Transform(trsf);
3064
TColStd_Array1OfInteger mults(1, 3);
3069
TColStd_Array1OfReal knots(1, 3);
3074
Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles, weights,knots, mults, 3,
3075
Standard_False, Standard_True);
3076
return new GeomBSplineCurve(spline);
3079
double GeomEllipse::getMajorRadius() const
3081
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(handle());
3082
return ellipse->MajorRadius();
3085
void GeomEllipse::setMajorRadius(double Radius)
3087
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(handle());
3090
ellipse->SetMajorRadius(Radius);
3092
catch (Standard_Failure& e) {
3094
THROWM(Base::CADKernelError,e.GetMessageString())
3098
double GeomEllipse::getMinorRadius() const
3100
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(handle());
3101
return ellipse->MinorRadius();
3104
void GeomEllipse::setMinorRadius(double Radius)
3106
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(handle());
3109
ellipse->SetMinorRadius(Radius);
3111
catch (Standard_Failure& e) {
3113
THROWM(Base::CADKernelError,e.GetMessageString())
3122
Base::Vector3d GeomEllipse::getMajorAxisDir() const
3124
gp_Dir xdir = myCurve->XAxis().Direction();
3125
return Base::Vector3d(xdir.X(), xdir.Y(), xdir.Z());
3132
Base::Vector3d GeomEllipse::getMinorAxisDir() const
3134
gp_Dir ydir = myCurve->YAxis().Direction();
3135
return Base::Vector3d(ydir.X(), ydir.Y(), ydir.Z());
3147
void GeomEllipse::setMajorAxisDir(Base::Vector3d newdir)
3149
if (newdir.Sqr() < Precision::SquareConfusion())
3152
gp_Ax2 pos = myCurve->Position();
3153
pos.SetXDirection(gp_Dir(newdir.x, newdir.y, newdir.z));
3154
myCurve->SetPosition(pos);
3156
catch (Standard_Failure& e) {
3158
THROWM(Base::CADKernelError,e.GetMessageString())
3163
unsigned int GeomEllipse::getMemSize () const
3165
return sizeof(Geom_Ellipse);
3168
void GeomEllipse::Save(Base::Writer& writer) const
3171
GeomCurve::Save(writer);
3173
gp_Pnt center = this->myCurve->Axis().Location();
3174
gp_Dir normal = this->myCurve->Axis().Direction();
3175
gp_Dir xdir = this->myCurve->XAxis().Direction();
3177
gp_Ax2 xdirref(center, normal);
3179
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
3185
<< "CenterX=\"" << center.X() << "\" "
3186
<< "CenterY=\"" << center.Y() << "\" "
3187
<< "CenterZ=\"" << center.Z() << "\" "
3188
<< "NormalX=\"" << normal.X() << "\" "
3189
<< "NormalY=\"" << normal.Y() << "\" "
3190
<< "NormalZ=\"" << normal.Z() << "\" "
3191
<< "MajorRadius=\"" << this->myCurve->MajorRadius() << "\" "
3192
<< "MinorRadius=\"" << this->myCurve->MinorRadius() << "\" "
3193
<< "AngleXU=\"" << AngleXU << "\" "
3194
<< "/>" << std::endl;
3197
void GeomEllipse::Restore(Base::XMLReader& reader)
3200
GeomCurve::Restore(reader);
3202
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU;
3204
reader.readElement("Ellipse");
3206
CenterX = reader.getAttributeAsFloat("CenterX");
3207
CenterY = reader.getAttributeAsFloat("CenterY");
3208
CenterZ = reader.getAttributeAsFloat("CenterZ");
3209
NormalX = reader.getAttributeAsFloat("NormalX");
3210
NormalY = reader.getAttributeAsFloat("NormalY");
3211
NormalZ = reader.getAttributeAsFloat("NormalZ");
3212
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
3213
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
3216
if(reader.hasAttribute("AngleXU"))
3217
AngleXU = reader.getAttributeAsFloat("AngleXU");
3222
gp_Pnt p1(CenterX,CenterY,CenterZ);
3223
gp_Dir norm(NormalX,NormalY,NormalZ);
3225
gp_Ax1 normaxis(p1,norm);
3227
gp_Ax2 xdir(p1, norm);
3229
xdir.Rotate(normaxis,AngleXU);
3232
GC_MakeEllipse mc(xdir, MajorRadius, MinorRadius);
3234
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
3236
this->myCurve = mc.Value();
3238
catch (Standard_Failure& e) {
3240
THROWM(Base::CADKernelError,e.GetMessageString())
3244
PyObject *GeomEllipse::getPyObject()
3246
return new EllipsePy(static_cast<GeomEllipse*>(this->clone()));
3249
bool GeomEllipse::isSame(const Geometry &_other, double tol, double atol) const
3251
if(_other.getTypeId() != getTypeId())
3255
auto &other = static_cast<const GeomEllipse &>(_other);
3256
return GeomConic::isSame(other,tol,atol)
3257
&& fabs(getMajorRadius() - other.getMajorRadius()) <= tol
3258
&& fabs(getMinorRadius() - other.getMinorRadius()) <= tol;
3263
TYPESYSTEM_SOURCE(Part::GeomArcOfEllipse,Part::GeomArcOfConic)
3265
GeomArcOfEllipse::GeomArcOfEllipse()
3267
Handle(Geom_Ellipse) e = new Geom_Ellipse(gp_Elips());
3268
this->myCurve = new Geom_TrimmedCurve(e, e->FirstParameter(),e->LastParameter());
3271
GeomArcOfEllipse::GeomArcOfEllipse(const Handle(Geom_Ellipse)& e)
3276
GeomArcOfEllipse::~GeomArcOfEllipse() = default;
3278
void GeomArcOfEllipse::setHandle(const Handle(Geom_TrimmedCurve)& c)
3280
Handle(Geom_Ellipse) basis = Handle(Geom_Ellipse)::DownCast(c->BasisCurve());
3282
Standard_Failure::Raise("Basis curve is not an ellipse");
3283
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
3286
void GeomArcOfEllipse::setHandle(const Handle(Geom_Ellipse)& e)
3288
this->myCurve = new Geom_TrimmedCurve(e, e->FirstParameter(),e->LastParameter());
3291
const Handle(Geom_Geometry)& GeomArcOfEllipse::handle() const
3296
Geometry *GeomArcOfEllipse::copy() const
3298
GeomArcOfEllipse* copy = new GeomArcOfEllipse();
3299
copy->setHandle(this->myCurve);
3300
copy->copyNonTag(this);
3304
GeomBSplineCurve* GeomArcOfEllipse::toNurbs(double first, double last) const
3306
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
3307
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(curve->BasisCurve());
3308
return GeomEllipse(ellipse).toNurbs(first, last);
3311
double GeomArcOfEllipse::getMajorRadius() const
3313
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(myCurve->BasisCurve());
3314
return ellipse->MajorRadius();
3317
void GeomArcOfEllipse::setMajorRadius(double Radius)
3319
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(myCurve->BasisCurve());
3322
ellipse->SetMajorRadius(Radius);
3324
catch (Standard_Failure& e) {
3326
THROWM(Base::CADKernelError,e.GetMessageString())
3330
double GeomArcOfEllipse::getMinorRadius() const
3332
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(myCurve->BasisCurve());
3333
return ellipse->MinorRadius();
3336
void GeomArcOfEllipse::setMinorRadius(double Radius)
3338
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(myCurve->BasisCurve());
3341
ellipse->SetMinorRadius(Radius);
3343
catch (Standard_Failure& e) {
3345
THROWM(Base::CADKernelError,e.GetMessageString())
3354
Base::Vector3d GeomArcOfEllipse::getMajorAxisDir() const
3356
Handle(Geom_Ellipse) c = Handle(Geom_Ellipse)::DownCast( myCurve->BasisCurve() );
3357
assert(!c.IsNull());
3358
gp_Dir xdir = c->XAxis().Direction();
3359
return Base::Vector3d(xdir.X(), xdir.Y(), xdir.Z());
3366
Base::Vector3d GeomArcOfEllipse::getMinorAxisDir() const
3368
Handle(Geom_Ellipse) c = Handle(Geom_Ellipse)::DownCast(myCurve->BasisCurve());
3369
assert(!c.IsNull());
3370
gp_Dir ydir = c->YAxis().Direction();
3371
return Base::Vector3d(ydir.X(), ydir.Y(), ydir.Z());
3382
void GeomArcOfEllipse::setMajorAxisDir(Base::Vector3d newdir)
3384
Handle(Geom_Ellipse) c = Handle(Geom_Ellipse)::DownCast( myCurve->BasisCurve() );
3385
assert(!c.IsNull());
3386
if (newdir.Sqr() < Precision::SquareConfusion())
3389
gp_Ax2 pos = c->Position();
3390
pos.SetXDirection(gp_Dir(newdir.x, newdir.y, newdir.z));
3391
c->SetPosition(pos);
3393
catch (Standard_Failure& e) {
3395
THROWM(Base::CADKernelError,e.GetMessageString())
3406
void GeomArcOfEllipse::getRange(double& u, double& v, bool emulateCCWXY) const
3408
u = myCurve->FirstParameter();
3409
v = myCurve->LastParameter();
3429
void GeomArcOfEllipse::setRange(double u, double v, bool emulateCCWXY)
3438
myCurve->SetTrim(u, v);
3440
catch (Standard_Failure& e) {
3442
THROWM(Base::CADKernelError,e.GetMessageString())
3447
unsigned int GeomArcOfEllipse::getMemSize () const
3449
return sizeof(Geom_Ellipse) + 2 *sizeof(double);
3452
void GeomArcOfEllipse::Save(Base::Writer &writer) const
3455
GeomCurve::Save(writer);
3457
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(this->myCurve->BasisCurve());
3459
gp_Pnt center = ellipse->Axis().Location();
3460
gp_Dir normal = ellipse->Axis().Direction();
3461
gp_Dir xdir = ellipse->XAxis().Direction();
3463
gp_Ax2 xdirref(center, normal);
3465
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
3471
<< "CenterX=\"" << center.X() << "\" "
3472
<< "CenterY=\"" << center.Y() << "\" "
3473
<< "CenterZ=\"" << center.Z() << "\" "
3474
<< "NormalX=\"" << normal.X() << "\" "
3475
<< "NormalY=\"" << normal.Y() << "\" "
3476
<< "NormalZ=\"" << normal.Z() << "\" "
3477
<< "MajorRadius=\"" << ellipse->MajorRadius() << "\" "
3478
<< "MinorRadius=\"" << ellipse->MinorRadius() << "\" "
3479
<< "AngleXU=\"" << AngleXU << "\" "
3480
<< "StartAngle=\"" << this->myCurve->FirstParameter() << "\" "
3481
<< "EndAngle=\"" << this->myCurve->LastParameter() << "\" "
3482
<< "/>" << std::endl;
3485
void GeomArcOfEllipse::Restore(Base::XMLReader &reader)
3488
GeomCurve::Restore(reader);
3490
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU,StartAngle,EndAngle;
3492
reader.readElement("ArcOfEllipse");
3494
CenterX = reader.getAttributeAsFloat("CenterX");
3495
CenterY = reader.getAttributeAsFloat("CenterY");
3496
CenterZ = reader.getAttributeAsFloat("CenterZ");
3497
NormalX = reader.getAttributeAsFloat("NormalX");
3498
NormalY = reader.getAttributeAsFloat("NormalY");
3499
NormalZ = reader.getAttributeAsFloat("NormalZ");
3500
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
3501
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
3502
AngleXU = reader.getAttributeAsFloat("AngleXU");
3503
StartAngle = reader.getAttributeAsFloat("StartAngle");
3504
EndAngle = reader.getAttributeAsFloat("EndAngle");
3508
gp_Pnt p1(CenterX,CenterY,CenterZ);
3509
gp_Dir norm(NormalX,NormalY,NormalZ);
3511
gp_Ax1 normaxis(p1,norm);
3513
gp_Ax2 xdir(p1, norm);
3515
xdir.Rotate(normaxis,AngleXU);
3518
GC_MakeEllipse mc(xdir, MajorRadius, MinorRadius);
3520
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
3522
GC_MakeArcOfEllipse ma(mc.Value()->Elips(), StartAngle, EndAngle, Standard_True);
3524
THROWM(Base::CADKernelError,gce_ErrorStatusText(ma.Status()))
3526
Handle(Geom_TrimmedCurve) tmpcurve = ma.Value();
3527
Handle(Geom_Ellipse) tmpellipse = Handle(Geom_Ellipse)::DownCast(tmpcurve->BasisCurve());
3528
Handle(Geom_Ellipse) ellipse = Handle(Geom_Ellipse)::DownCast(this->myCurve->BasisCurve());
3530
ellipse->SetElips(tmpellipse->Elips());
3531
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
3533
catch (Standard_Failure& e) {
3535
THROWM(Base::CADKernelError,e.GetMessageString())
3539
PyObject *GeomArcOfEllipse::getPyObject()
3541
return new ArcOfEllipsePy(static_cast<GeomArcOfEllipse*>(this->clone()));
3546
TYPESYSTEM_SOURCE(Part::GeomHyperbola,Part::GeomConic)
3548
GeomHyperbola::GeomHyperbola()
3550
Handle(Geom_Hyperbola) h = new Geom_Hyperbola(gp_Hypr());
3554
GeomHyperbola::GeomHyperbola(const Handle(Geom_Hyperbola)& h)
3559
GeomHyperbola::~GeomHyperbola() = default;
3561
const Handle(Geom_Geometry)& GeomHyperbola::handle() const
3567
void GeomHyperbola::setHandle(const Handle(Geom_Hyperbola)& c)
3569
myCurve = Handle(Geom_Hyperbola)::DownCast(c->Copy());
3572
Geometry *GeomHyperbola::copy() const
3574
GeomHyperbola *newHyp = new GeomHyperbola(myCurve);
3575
newHyp->copyNonTag(this);
3579
GeomBSplineCurve* GeomHyperbola::toNurbs(double first, double last) const
3581
return GeomConic::toNurbs(first, last);
3584
double GeomHyperbola::getMajorRadius() const
3586
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(handle());
3587
return h->MajorRadius();
3590
void GeomHyperbola::setMajorRadius(double Radius)
3592
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(handle());
3595
h->SetMajorRadius(Radius);
3597
catch (Standard_Failure& e) {
3599
THROWM(Base::CADKernelError,e.GetMessageString())
3603
double GeomHyperbola::getMinorRadius() const
3605
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(handle());
3606
return h->MinorRadius();
3609
void GeomHyperbola::setMinorRadius(double Radius)
3611
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(handle());
3614
h->SetMinorRadius(Radius);
3616
catch (Standard_Failure& e) {
3618
THROWM(Base::CADKernelError,e.GetMessageString())
3623
unsigned int GeomHyperbola::getMemSize () const
3625
return sizeof(Geom_Hyperbola);
3628
void GeomHyperbola::Save(Base::Writer& writer) const
3631
GeomCurve::Save(writer);
3633
gp_Pnt center = this->myCurve->Axis().Location();
3634
gp_Dir normal = this->myCurve->Axis().Direction();
3635
gp_Dir xdir = this->myCurve->XAxis().Direction();
3637
gp_Ax2 xdirref(center, normal);
3639
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
3644
<< "CenterX=\"" << center.X() << "\" "
3645
<< "CenterY=\"" << center.Y() << "\" "
3646
<< "CenterZ=\"" << center.Z() << "\" "
3647
<< "NormalX=\"" << normal.X() << "\" "
3648
<< "NormalY=\"" << normal.Y() << "\" "
3649
<< "NormalZ=\"" << normal.Z() << "\" "
3650
<< "MajorRadius=\"" << this->myCurve->MajorRadius() << "\" "
3651
<< "MinorRadius=\"" << this->myCurve->MinorRadius() << "\" "
3652
<< "AngleXU=\"" << AngleXU << "\" "
3653
<< "/>" << std::endl;
3656
void GeomHyperbola::Restore(Base::XMLReader& reader)
3659
GeomCurve::Restore(reader);
3661
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU;
3663
reader.readElement("Hyperbola");
3665
CenterX = reader.getAttributeAsFloat("CenterX");
3666
CenterY = reader.getAttributeAsFloat("CenterY");
3667
CenterZ = reader.getAttributeAsFloat("CenterZ");
3668
NormalX = reader.getAttributeAsFloat("NormalX");
3669
NormalY = reader.getAttributeAsFloat("NormalY");
3670
NormalZ = reader.getAttributeAsFloat("NormalZ");
3671
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
3672
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
3673
AngleXU = reader.getAttributeAsFloat("AngleXU");
3676
gp_Pnt p1(CenterX,CenterY,CenterZ);
3677
gp_Dir norm(NormalX,NormalY,NormalZ);
3679
gp_Ax1 normaxis(p1,norm);
3681
gp_Ax2 xdir(p1, norm);
3683
xdir.Rotate(normaxis,AngleXU);
3686
GC_MakeHyperbola mc(xdir, MajorRadius, MinorRadius);
3688
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
3690
this->myCurve = mc.Value();
3692
catch (Standard_Failure& e) {
3694
THROWM(Base::CADKernelError,e.GetMessageString())
3698
PyObject *GeomHyperbola::getPyObject()
3700
return new HyperbolaPy(static_cast<GeomHyperbola*>(this->clone()));
3703
bool GeomHyperbola::isSame(const Geometry &_other, double tol, double atol) const
3705
if(_other.getTypeId() != getTypeId())
3709
auto &other = static_cast<const GeomHyperbola &>(_other);
3710
return GeomConic::isSame(other,tol,atol)
3711
&& fabs(getMajorRadius() - other.getMajorRadius()) <= tol
3712
&& fabs(getMinorRadius() - other.getMinorRadius()) <= tol;
3717
TYPESYSTEM_SOURCE(Part::GeomArcOfHyperbola,Part::GeomArcOfConic)
3719
GeomArcOfHyperbola::GeomArcOfHyperbola()
3721
gp_Ax2 ax2 = gp_Ax2();
3722
Handle(Geom_Hyperbola) h = new Geom_Hyperbola(gp_Hypr(ax2, 1,1));
3723
this->myCurve = new Geom_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
3726
GeomArcOfHyperbola::GeomArcOfHyperbola(const Handle(Geom_Hyperbola)& h)
3731
GeomArcOfHyperbola::~GeomArcOfHyperbola() = default;
3733
void GeomArcOfHyperbola::setHandle(const Handle(Geom_TrimmedCurve)& c)
3735
Handle(Geom_Hyperbola) basis = Handle(Geom_Hyperbola)::DownCast(c->BasisCurve());
3737
Standard_Failure::Raise("Basis curve is not an hyperbola");
3738
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
3741
void GeomArcOfHyperbola::setHandle(const Handle(Geom_Hyperbola)& h)
3743
this->myCurve = new Geom_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
3746
const Handle(Geom_Geometry)& GeomArcOfHyperbola::handle() const
3751
Geometry *GeomArcOfHyperbola::copy() const
3753
GeomArcOfHyperbola* copy = new GeomArcOfHyperbola();
3754
copy->setHandle(this->myCurve);
3755
copy->copyNonTag(this);
3759
GeomBSplineCurve* GeomArcOfHyperbola::toNurbs(double first, double last) const
3761
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
3762
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(curve->BasisCurve());
3763
return GeomHyperbola(hyperbola).toNurbs(first, last);
3766
double GeomArcOfHyperbola::getMajorRadius() const
3768
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3769
return h->MajorRadius();
3772
void GeomArcOfHyperbola::setMajorRadius(double Radius)
3774
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3777
h->SetMajorRadius(Radius);
3779
catch (Standard_Failure& e) {
3781
THROWM(Base::CADKernelError,e.GetMessageString())
3785
double GeomArcOfHyperbola::getMinorRadius() const
3787
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3788
return h->MinorRadius();
3791
void GeomArcOfHyperbola::setMinorRadius(double Radius)
3793
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3796
h->SetMinorRadius(Radius);
3798
catch (Standard_Failure& e) {
3800
THROWM(Base::CADKernelError,e.GetMessageString())
3809
Base::Vector3d GeomArcOfHyperbola::getMajorAxisDir() const
3811
Handle(Geom_Hyperbola) c = Handle(Geom_Hyperbola)::DownCast( myCurve->BasisCurve() );
3812
assert(!c.IsNull());
3813
gp_Dir xdir = c->XAxis().Direction();
3814
return Base::Vector3d(xdir.X(), xdir.Y(), xdir.Z());
3821
Base::Vector3d GeomArcOfHyperbola::getMinorAxisDir() const
3823
Handle(Geom_Hyperbola) c = Handle(Geom_Hyperbola)::DownCast( myCurve->BasisCurve() );
3824
assert(!c.IsNull());
3825
gp_Dir ydir = c->YAxis().Direction();
3826
return Base::Vector3d(ydir.X(), ydir.Y(), ydir.Z());
3837
void GeomArcOfHyperbola::setMajorAxisDir(Base::Vector3d newdir)
3839
Handle(Geom_Hyperbola) c = Handle(Geom_Hyperbola)::DownCast( myCurve->BasisCurve() );
3840
assert(!c.IsNull());
3841
if (newdir.Sqr() < Precision::SquareConfusion())
3845
gp_Ax2 pos = c->Position();
3846
pos.SetXDirection(gp_Dir(newdir.x, newdir.y, newdir.z));
3847
c->SetPosition(pos);
3849
catch (Standard_Failure& e) {
3851
THROWM(Base::CADKernelError,e.GetMessageString())
3855
void GeomArcOfHyperbola::getRange(double& u, double& v, bool emulateCCWXY) const
3860
Handle(Geom_Hyperbola) c = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3861
assert(!c.IsNull());
3866
catch (Standard_Failure& e) {
3868
THROWM(Base::CADKernelError,e.GetMessageString())
3871
u = myCurve->FirstParameter();
3872
v = myCurve->LastParameter();
3875
void GeomArcOfHyperbola::setRange(double u, double v, bool emulateCCWXY)
3878
myCurve->SetTrim(u, v);
3882
Handle(Geom_Hyperbola) c = Handle(Geom_Hyperbola)::DownCast(myCurve->BasisCurve());
3883
assert(!c.IsNull());
3888
catch (Standard_Failure& e) {
3890
THROWM(Base::CADKernelError,e.GetMessageString())
3895
unsigned int GeomArcOfHyperbola::getMemSize () const
3897
return sizeof(Geom_Hyperbola) + 2 *sizeof(double);
3900
void GeomArcOfHyperbola::Save(Base::Writer &writer) const
3903
GeomCurve::Save(writer);
3905
Handle(Geom_Hyperbola) h = Handle(Geom_Hyperbola)::DownCast(this->myCurve->BasisCurve());
3907
gp_Pnt center = h->Axis().Location();
3908
gp_Dir normal = h->Axis().Direction();
3909
gp_Dir xdir = h->XAxis().Direction();
3911
gp_Ax2 xdirref(center, normal);
3913
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
3917
<< "<ArcOfHyperbola "
3918
<< "CenterX=\"" << center.X() << "\" "
3919
<< "CenterY=\"" << center.Y() << "\" "
3920
<< "CenterZ=\"" << center.Z() << "\" "
3921
<< "NormalX=\"" << normal.X() << "\" "
3922
<< "NormalY=\"" << normal.Y() << "\" "
3923
<< "NormalZ=\"" << normal.Z() << "\" "
3924
<< "MajorRadius=\"" << h->MajorRadius() << "\" "
3925
<< "MinorRadius=\"" << h->MinorRadius() << "\" "
3926
<< "AngleXU=\"" << AngleXU << "\" "
3927
<< "StartAngle=\"" << this->myCurve->FirstParameter() << "\" "
3928
<< "EndAngle=\"" << this->myCurve->LastParameter() << "\" "
3929
<< "/>" << std::endl;
3932
void GeomArcOfHyperbola::Restore(Base::XMLReader &reader)
3935
GeomCurve::Restore(reader);
3937
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU,StartAngle,EndAngle;
3939
reader.readElement("ArcOfHyperbola");
3941
CenterX = reader.getAttributeAsFloat("CenterX");
3942
CenterY = reader.getAttributeAsFloat("CenterY");
3943
CenterZ = reader.getAttributeAsFloat("CenterZ");
3944
NormalX = reader.getAttributeAsFloat("NormalX");
3945
NormalY = reader.getAttributeAsFloat("NormalY");
3946
NormalZ = reader.getAttributeAsFloat("NormalZ");
3947
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
3948
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
3949
AngleXU = reader.getAttributeAsFloat("AngleXU");
3950
StartAngle = reader.getAttributeAsFloat("StartAngle");
3951
EndAngle = reader.getAttributeAsFloat("EndAngle");
3955
gp_Pnt p1(CenterX,CenterY,CenterZ);
3956
gp_Dir norm(NormalX,NormalY,NormalZ);
3958
gp_Ax1 normaxis(p1,norm);
3960
gp_Ax2 xdir(p1, norm);
3962
xdir.Rotate(normaxis,AngleXU);
3965
GC_MakeHyperbola mc(xdir, MajorRadius, MinorRadius);
3967
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
3969
GC_MakeArcOfHyperbola ma(mc.Value()->Hypr(), StartAngle, EndAngle, Standard_True);
3971
THROWM(Base::CADKernelError,gce_ErrorStatusText(ma.Status()))
3973
Handle(Geom_TrimmedCurve) tmpcurve = ma.Value();
3974
Handle(Geom_Hyperbola) tmphyperbola = Handle(Geom_Hyperbola)::DownCast(tmpcurve->BasisCurve());
3975
Handle(Geom_Hyperbola) hyperbola = Handle(Geom_Hyperbola)::DownCast(this->myCurve->BasisCurve());
3977
hyperbola->SetHypr(tmphyperbola->Hypr());
3978
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
3980
catch (Standard_Failure& e) {
3982
THROWM(Base::CADKernelError,e.GetMessageString())
3986
PyObject *GeomArcOfHyperbola::getPyObject()
3988
return new ArcOfHyperbolaPy(static_cast<GeomArcOfHyperbola*>(this->clone()));
3992
TYPESYSTEM_SOURCE(Part::GeomParabola,Part::GeomConic)
3994
GeomParabola::GeomParabola()
3996
Handle(Geom_Parabola) p = new Geom_Parabola(gp_Parab());
4000
GeomParabola::GeomParabola(const Handle(Geom_Parabola)& p)
4005
GeomParabola::~GeomParabola() = default;
4007
const Handle(Geom_Geometry)& GeomParabola::handle() const
4012
void GeomParabola::setHandle(const Handle(Geom_Parabola)& c)
4014
myCurve = Handle(Geom_Parabola)::DownCast(c->Copy());
4017
Geometry *GeomParabola::copy() const
4019
GeomParabola *newPar = new GeomParabola(myCurve);
4020
newPar->copyNonTag(this);
4024
GeomBSplineCurve* GeomParabola::toNurbs(double first, double last) const
4028
return GeomCurve::toNurbs(first, last);
4031
double GeomParabola::getFocal() const
4033
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(handle());
4037
void GeomParabola::setFocal(double length)
4039
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(handle());
4042
p->SetFocal(length);
4044
catch (Standard_Failure& e) {
4046
THROWM(Base::CADKernelError,e.GetMessageString())
4051
unsigned int GeomParabola::getMemSize () const
4053
return sizeof(Geom_Parabola);
4056
void GeomParabola::Save(Base::Writer& writer) const
4059
GeomCurve::Save(writer);
4061
gp_Pnt center = this->myCurve->Axis().Location();
4062
gp_Dir normal = this->myCurve->Axis().Direction();
4063
gp_Dir xdir = this->myCurve->XAxis().Direction();
4065
gp_Ax2 xdirref(center, normal);
4067
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
4072
<< "CenterX=\"" << center.X() << "\" "
4073
<< "CenterY=\"" << center.Y() << "\" "
4074
<< "CenterZ=\"" << center.Z() << "\" "
4075
<< "NormalX=\"" << normal.X() << "\" "
4076
<< "NormalY=\"" << normal.Y() << "\" "
4077
<< "NormalZ=\"" << normal.Z() << "\" "
4078
<< "Focal=\"" << this->myCurve->Focal() << "\" "
4079
<< "AngleXU=\"" << AngleXU << "\" "
4080
<< "/>" << std::endl;
4083
void GeomParabola::Restore(Base::XMLReader& reader)
4086
GeomCurve::Restore(reader);
4088
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Focal,AngleXU;
4090
reader.readElement("Parabola");
4092
CenterX = reader.getAttributeAsFloat("CenterX");
4093
CenterY = reader.getAttributeAsFloat("CenterY");
4094
CenterZ = reader.getAttributeAsFloat("CenterZ");
4095
NormalX = reader.getAttributeAsFloat("NormalX");
4096
NormalY = reader.getAttributeAsFloat("NormalY");
4097
NormalZ = reader.getAttributeAsFloat("NormalZ");
4098
Focal = reader.getAttributeAsFloat("Focal");
4099
AngleXU = reader.getAttributeAsFloat("AngleXU");
4102
gp_Pnt p1(CenterX,CenterY,CenterZ);
4103
gp_Dir norm(NormalX,NormalY,NormalZ);
4105
gp_Ax1 normaxis(p1,norm);
4107
gp_Ax2 xdir(p1, norm);
4109
xdir.Rotate(normaxis,AngleXU);
4112
gce_MakeParab mc(xdir, Focal);
4114
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
4116
this->myCurve = new Geom_Parabola(mc.Value());
4118
catch (Standard_Failure& e) {
4120
THROWM(Base::CADKernelError,e.GetMessageString())
4124
PyObject *GeomParabola::getPyObject()
4126
return new ParabolaPy(static_cast<GeomParabola*>(this->clone()));
4129
bool GeomParabola::isSame(const Geometry &_other, double tol, double atol) const
4131
if(_other.getTypeId() != getTypeId())
4135
auto &other = static_cast<const GeomParabola &>(_other);
4136
return GeomConic::isSame(other,tol,atol) && fabs(getFocal() - other.getFocal()) < tol;
4140
TYPESYSTEM_SOURCE(Part::GeomArcOfParabola,Part::GeomArcOfConic)
4142
GeomArcOfParabola::GeomArcOfParabola()
4144
Handle(Geom_Parabola) p = new Geom_Parabola(gp_Parab());
4145
this->myCurve = new Geom_TrimmedCurve(p, p->FirstParameter(),p->LastParameter());
4148
GeomArcOfParabola::GeomArcOfParabola(const Handle(Geom_Parabola)& h)
4153
GeomArcOfParabola::~GeomArcOfParabola() = default;
4155
void GeomArcOfParabola::setHandle(const Handle(Geom_TrimmedCurve)& c)
4157
Handle(Geom_Parabola) basis = Handle(Geom_Parabola)::DownCast(c->BasisCurve());
4159
Standard_Failure::Raise("Basis curve is not a parabola");
4160
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
4163
void GeomArcOfParabola::setHandle(const Handle(Geom_Parabola)& h)
4165
this->myCurve = new Geom_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
4168
const Handle(Geom_Geometry)& GeomArcOfParabola::handle() const
4173
Geometry *GeomArcOfParabola::copy() const
4175
GeomArcOfParabola* copy = new GeomArcOfParabola();
4176
copy->setHandle(this->myCurve);
4177
copy->copyNonTag(this);
4181
GeomBSplineCurve* GeomArcOfParabola::toNurbs(double first, double last) const
4183
Handle(Geom_TrimmedCurve) curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
4184
Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(curve->BasisCurve());
4185
return GeomParabola(parabola).toNurbs(first, last);
4188
double GeomArcOfParabola::getFocal() const
4190
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(myCurve->BasisCurve());
4194
void GeomArcOfParabola::setFocal(double length)
4196
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(myCurve->BasisCurve());
4199
p->SetFocal(length);
4201
catch (Standard_Failure& e) {
4203
THROWM(Base::CADKernelError,e.GetMessageString())
4207
Base::Vector3d GeomArcOfParabola::getFocus() const
4209
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(myCurve->BasisCurve());
4210
gp_Pnt gp = p->Focus();
4212
return Base::Vector3d(gp.X(),gp.Y(),gp.Z());
4215
void GeomArcOfParabola::getRange(double& u, double& v, bool emulateCCWXY) const
4220
Handle(Geom_Parabola) c = Handle(Geom_Parabola)::DownCast(myCurve->BasisCurve());
4221
assert(!c.IsNull());
4226
catch (Standard_Failure& e) {
4228
THROWM(Base::CADKernelError,e.GetMessageString())
4231
u = myCurve->FirstParameter();
4232
v = myCurve->LastParameter();
4235
void GeomArcOfParabola::setRange(double u, double v, bool emulateCCWXY)
4238
myCurve->SetTrim(u, v);
4241
Handle(Geom_Parabola) c = Handle(Geom_Parabola)::DownCast(myCurve->BasisCurve());
4242
assert(!c.IsNull());
4247
catch (Standard_Failure& e) {
4249
THROWM(Base::CADKernelError,e.GetMessageString())
4254
unsigned int GeomArcOfParabola::getMemSize () const
4256
return sizeof(Geom_Parabola) + 2 *sizeof(double);
4259
void GeomArcOfParabola::Save(Base::Writer &writer) const
4262
GeomCurve::Save(writer);
4264
Handle(Geom_Parabola) p = Handle(Geom_Parabola)::DownCast(this->myCurve->BasisCurve());
4266
gp_Pnt center = p->Axis().Location();
4267
gp_Dir normal = p->Axis().Direction();
4268
gp_Dir xdir = p->XAxis().Direction();
4270
gp_Ax2 xdirref(center, normal);
4272
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
4276
<< "<ArcOfParabola "
4277
<< "CenterX=\"" << center.X() << "\" "
4278
<< "CenterY=\"" << center.Y() << "\" "
4279
<< "CenterZ=\"" << center.Z() << "\" "
4280
<< "NormalX=\"" << normal.X() << "\" "
4281
<< "NormalY=\"" << normal.Y() << "\" "
4282
<< "NormalZ=\"" << normal.Z() << "\" "
4283
<< "Focal=\"" << p->Focal() << "\" "
4284
<< "AngleXU=\"" << AngleXU << "\" "
4285
<< "StartAngle=\"" << this->myCurve->FirstParameter() << "\" "
4286
<< "EndAngle=\"" << this->myCurve->LastParameter() << "\" "
4287
<< "/>" << std::endl;
4290
void GeomArcOfParabola::Restore(Base::XMLReader &reader)
4293
GeomCurve::Restore(reader);
4295
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Focal,AngleXU,StartAngle,EndAngle;
4297
reader.readElement("ArcOfParabola");
4299
CenterX = reader.getAttributeAsFloat("CenterX");
4300
CenterY = reader.getAttributeAsFloat("CenterY");
4301
CenterZ = reader.getAttributeAsFloat("CenterZ");
4302
NormalX = reader.getAttributeAsFloat("NormalX");
4303
NormalY = reader.getAttributeAsFloat("NormalY");
4304
NormalZ = reader.getAttributeAsFloat("NormalZ");
4305
Focal = reader.getAttributeAsFloat("Focal");
4306
AngleXU = reader.getAttributeAsFloat("AngleXU");
4307
StartAngle = reader.getAttributeAsFloat("StartAngle");
4308
EndAngle = reader.getAttributeAsFloat("EndAngle");
4312
gp_Pnt p1(CenterX,CenterY,CenterZ);
4313
gp_Dir norm(NormalX,NormalY,NormalZ);
4315
gp_Ax1 normaxis(p1,norm);
4317
gp_Ax2 xdir(p1, norm);
4319
xdir.Rotate(normaxis,AngleXU);
4322
gce_MakeParab mc(xdir, Focal);
4324
THROWM(Base::CADKernelError,gce_ErrorStatusText(mc.Status()))
4326
GC_MakeArcOfParabola ma(mc.Value(), StartAngle, EndAngle, Standard_True);
4328
THROWM(Base::CADKernelError,gce_ErrorStatusText(ma.Status()))
4330
Handle(Geom_TrimmedCurve) tmpcurve = ma.Value();
4331
Handle(Geom_Parabola) tmpparabola = Handle(Geom_Parabola)::DownCast(tmpcurve->BasisCurve());
4332
Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(this->myCurve->BasisCurve());
4334
parabola->SetParab(tmpparabola->Parab());
4335
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
4337
catch (Standard_Failure& e) {
4339
THROWM(Base::CADKernelError,e.GetMessageString())
4343
PyObject *GeomArcOfParabola::getPyObject()
4345
return new ArcOfParabolaPy(static_cast<GeomArcOfParabola*>(this->clone()));
4350
TYPESYSTEM_SOURCE(Part::GeomLine,Part::GeomCurve)
4354
Handle(Geom_Line) c = new Geom_Line(gp_Lin());
4358
GeomLine::GeomLine(const Handle(Geom_Line)& l)
4363
GeomLine::GeomLine(const Base::Vector3d& Pos, const Base::Vector3d& Dir)
4365
this->myCurve = new Geom_Line(gp_Pnt(Pos.x,Pos.y,Pos.z),gp_Dir(Dir.x,Dir.y,Dir.z));
4369
GeomLine::~GeomLine() = default;
4371
void GeomLine::setLine(const Base::Vector3d& Pos, const Base::Vector3d& Dir)
4373
this->myCurve->SetLocation(gp_Pnt(Pos.x,Pos.y,Pos.z));
4374
this->myCurve->SetDirection(gp_Dir(Dir.x,Dir.y,Dir.z));
4377
Base::Vector3d GeomLine::getPos() const
4379
gp_Pnt Pos = this->myCurve->Lin().Location();
4380
return Base::Vector3d(Pos.X(),Pos.Y(),Pos.Z());
4383
Base::Vector3d GeomLine::getDir() const
4385
gp_Dir Dir = this->myCurve->Lin().Direction();
4386
return Base::Vector3d(Dir.X(),Dir.Y(),Dir.Z());
4389
const Handle(Geom_Geometry)& GeomLine::handle() const
4395
void GeomLine::setHandle(const Handle(Geom_Line)& l)
4397
this->myCurve = Handle(Geom_Line)::DownCast(l->Copy());
4400
Geometry *GeomLine::copy() const
4402
GeomLine *newLine = new GeomLine(myCurve);
4403
newLine->copyNonTag(this);
4408
unsigned int GeomLine::getMemSize () const
4410
return sizeof(Geom_Line);
4413
void GeomLine::Save(Base::Writer &writer) const
4416
Geometry::Save(writer);
4418
Base::Vector3d Pos = getPos();
4419
Base::Vector3d Dir = getDir();
4424
<< "PosX=\"" << Pos.x <<
4425
"\" PosY=\"" << Pos.y <<
4426
"\" PosZ=\"" << Pos.z <<
4427
"\" DirX=\"" << Dir.x <<
4428
"\" DirY=\"" << Dir.y <<
4429
"\" DirZ=\"" << Dir.z <<
4430
"\"/>" << std::endl;
4432
void GeomLine::Restore(Base::XMLReader &reader)
4435
Geometry::Restore(reader);
4437
double PosX,PosY,PosZ,DirX,DirY,DirZ;
4439
reader.readElement("GeomLine");
4441
PosX = reader.getAttributeAsFloat("PosX");
4442
PosY = reader.getAttributeAsFloat("PosY");
4443
PosZ = reader.getAttributeAsFloat("PosZ");
4444
DirX = reader.getAttributeAsFloat("DirX");
4445
DirY = reader.getAttributeAsFloat("DirY");
4446
DirZ = reader.getAttributeAsFloat("DirZ");
4449
setLine(Base::Vector3d(PosX,PosY,PosZ),Base::Vector3d(DirX,DirY,DirZ) );
4452
PyObject *GeomLine::getPyObject()
4454
return new LinePy(static_cast<GeomLine*>(this->clone()));
4457
bool GeomLine::isSame(const Geometry &_other, double tol, double atol) const
4459
if(_other.getTypeId() != getTypeId()) {
4460
if (_other.isDerivedFrom(GeomCurve::getClassTypeId())) {
4461
std::unique_ptr<Geometry> geo(dynamic_cast<const GeomCurve&>(_other).toLine());
4463
return isSame(*geo, tol, atol);
4468
auto &other = dynamic_cast<const GeomLine &>(_other);
4470
return getDir().GetAngle(other.getDir()) <= atol
4471
&& Base::DistanceP2(getPos(), other.getPos()) <= tol*tol;
4475
TYPESYSTEM_SOURCE(Part::GeomLineSegment,Part::GeomTrimmedCurve)
4477
GeomLineSegment::GeomLineSegment()
4480
line.SetLocation(gp_Pnt(0.0,0.0,0.0));
4481
line.SetDirection(gp_Dir(0.0,0.0,1.0));
4482
Handle(Geom_Line) c = new Geom_Line(line);
4483
this->myCurve = new Geom_TrimmedCurve(c, 0.0,1.0);
4486
GeomLineSegment::GeomLineSegment(const Handle(Geom_Line)& l)
4491
GeomLineSegment::~GeomLineSegment() = default;
4493
void GeomLineSegment::setHandle(const Handle(Geom_TrimmedCurve)& c)
4495
Handle(Geom_Line) basis = Handle(Geom_Line)::DownCast(c->BasisCurve());
4497
Standard_Failure::Raise("Basis curve is not a line");
4498
this->myCurve = Handle(Geom_TrimmedCurve)::DownCast(c->Copy());
4501
void GeomLineSegment::setHandle(const Handle(Geom_Line)& l)
4503
this->myCurve = new Geom_TrimmedCurve(l, l->FirstParameter(),l->LastParameter());
4506
const Handle(Geom_Geometry)& GeomLineSegment::handle() const
4511
Geometry *GeomLineSegment::copy()const
4513
auto *tempCurve = new GeomLineSegment();
4514
tempCurve->myCurve = Handle(Geom_TrimmedCurve)::DownCast(myCurve->Copy());
4515
tempCurve->copyNonTag(this);
4519
Base::Vector3d GeomLineSegment::getStartPoint() const
4521
Handle(Geom_TrimmedCurve) this_curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
4522
gp_Pnt pnt = this_curve->StartPoint();
4523
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
4526
Base::Vector3d GeomLineSegment::getEndPoint() const
4528
Handle(Geom_TrimmedCurve) this_curve = Handle(Geom_TrimmedCurve)::DownCast(handle());
4529
gp_Pnt pnt = this_curve->EndPoint();
4530
return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z());
4533
void GeomLineSegment::setPoints(const Base::Vector3d& Start, const Base::Vector3d& End)
4535
gp_Pnt p1(Start.x,Start.y,Start.z), p2(End.x,End.y,End.z);
4536
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast(handle());
4540
if (p1.Distance(p2) < gp::Resolution())
4541
THROWM(Base::ValueError,"Both points are equal");
4543
GC_MakeSegment ms(p1, p2);
4545
THROWM(Base::CADKernelError,gce_ErrorStatusText(ms.Status()))
4549
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
4550
(this_curv->BasisCurve());
4551
Handle(Geom_TrimmedCurve)& that_curv =
4552
const_cast<opencascade::handle<Geom_TrimmedCurve>&>(ms.Value());
4553
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast(that_curv->BasisCurve());
4554
this_line->SetLin(that_line->Lin());
4555
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
4557
catch (Standard_Failure& e) {
4559
THROWM(Base::CADKernelError,e.GetMessageString())
4564
unsigned int GeomLineSegment::getMemSize () const
4566
return sizeof(Geom_TrimmedCurve) + sizeof(Geom_Line);
4569
void GeomLineSegment::Save (Base::Writer &writer) const
4572
Geometry::Save(writer);
4574
Base::Vector3d End = getEndPoint();
4575
Base::Vector3d Start = getStartPoint();
4580
<< "StartX=\"" << Start.x <<
4581
"\" StartY=\"" << Start.y <<
4582
"\" StartZ=\"" << Start.z <<
4583
"\" EndX=\"" << End.x <<
4584
"\" EndY=\"" << End.y <<
4585
"\" EndZ=\"" << End.z <<
4586
"\"/>" << std::endl;
4589
void GeomLineSegment::Restore (Base::XMLReader &reader)
4592
Geometry::Restore(reader);
4594
double StartX,StartY,StartZ,EndX,EndY,EndZ;
4596
reader.readElement("LineSegment");
4598
StartX = reader.getAttributeAsFloat("StartX");
4599
StartY = reader.getAttributeAsFloat("StartY");
4600
StartZ = reader.getAttributeAsFloat("StartZ");
4601
EndX = reader.getAttributeAsFloat("EndX");
4602
EndY = reader.getAttributeAsFloat("EndY");
4603
EndZ = reader.getAttributeAsFloat("EndZ");
4605
Base::Vector3d start(StartX,StartY,StartZ);
4606
Base::Vector3d end(EndX,EndY,EndZ);
4609
setPoints(start, end);
4611
catch(Base::ValueError&) {
4615
reader.setPartialRestore(true);
4618
end = start + Base::Vector3d(DBL_EPSILON,0,0);
4621
end = start + Base::Vector3d(start.x*DBL_EPSILON,0,0);
4624
setPoints(start, end);
4628
PyObject *GeomLineSegment::getPyObject()
4630
return new LineSegmentPy(dynamic_cast<GeomLineSegment*>(this->clone()));
4635
TYPESYSTEM_SOURCE(Part::GeomOffsetCurve,Part::GeomCurve)
4637
GeomOffsetCurve::GeomOffsetCurve() = default;
4639
GeomOffsetCurve::GeomOffsetCurve(const Handle(Geom_Curve)& c, double offset, const gp_Dir& dir)
4641
this->myCurve = new Geom_OffsetCurve(c, offset, dir);
4644
GeomOffsetCurve::GeomOffsetCurve(const Handle(Geom_Curve)& c, double offset, Base::Vector3d& dir):GeomOffsetCurve(c,offset,gp_Dir(dir.x,dir.y,dir.z))
4648
GeomOffsetCurve::GeomOffsetCurve(const Handle(Geom_OffsetCurve)& c)
4653
GeomOffsetCurve::~GeomOffsetCurve() = default;
4655
Geometry *GeomOffsetCurve::copy() const
4657
auto *newCurve = new GeomOffsetCurve(myCurve);
4658
newCurve->copyNonTag(this);
4662
Base::Vector3d GeomOffsetCurve::getDir() const
4664
gp_Dir Dir = this->myCurve->Direction();
4665
return Base::Vector3d(Dir.X(),Dir.Y(),Dir.Z());
4668
double GeomOffsetCurve::getOffset() const
4670
return this->myCurve->Offset();
4673
void GeomOffsetCurve::setHandle(const Handle(Geom_OffsetCurve)& c)
4675
this->myCurve = Handle(Geom_OffsetCurve)::DownCast(c->Copy());
4678
const Handle(Geom_Geometry)& GeomOffsetCurve::handle() const
4680
return this->myCurve;
4684
unsigned int GeomOffsetCurve::getMemSize () const
4686
return sizeof(Geom_OffsetCurve);
4689
void GeomOffsetCurve::Save(Base::Writer &) const
4691
throw Base::NotImplementedError("GeomOffsetCurve::Save");
4694
void GeomOffsetCurve::Restore(Base::XMLReader &)
4696
throw Base::NotImplementedError("GeomOffsetCurve::Restore");
4699
PyObject *GeomOffsetCurve::getPyObject()
4701
return new OffsetCurvePy(dynamic_cast<GeomOffsetCurve*>(this->clone()));
4704
bool GeomOffsetCurve::isSame(const Geometry &_other, double tol, double atol) const
4706
if(_other.getTypeId() != getTypeId())
4709
auto &other = dynamic_cast<const GeomOffsetCurve &>(_other);
4710
if(myCurve->Direction().Angle(other.myCurve->Direction()) > atol || fabs(getOffset() - other.getOffset()) > tol)
4713
Handle(Geom_Curve) basis = myCurve->BasisCurve();
4714
Handle(Geom_Curve) basis1 = other.myCurve->BasisCurve();
4715
if(basis.IsNull() || basis1.IsNull() || basis->DynamicType() != basis1->DynamicType())
4718
std::unique_ptr<Geometry> b(makeFromCurve(basis));
4719
std::unique_ptr<Geometry> b1(makeFromCurve(basis1));
4720
return b && b1 && b->isSame(*b1, tol, atol);
4726
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomSurface,Part::Geometry)
4728
GeomSurface::GeomSurface() = default;
4730
GeomSurface::~GeomSurface() = default;
4732
bool GeomSurface::isPlanar(gp_Pln *pln, double tol) const
4734
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4735
return isPlanar(s, pln, tol);
4738
bool GeomSurface::isPlanar(const Handle(Geom_Surface) &s, gp_Pln *pln, double tol)
4740
GeomLib_IsPlanarSurface check(s, tol);
4741
if (!check.IsPlanar())
4744
*pln = check.Plan();
4748
GeomPlane* GeomSurface::toPlane(bool clone, double tol) const
4750
if (isDerivedFrom(GeomPlane::getClassTypeId())) {
4752
return dynamic_cast<GeomPlane*>(this->clone());
4754
return dynamic_cast<GeomPlane*>(this->copy());
4759
if (!isPlanar(&pln, tol))
4762
auto res = new GeomPlane(pln);
4763
res->copyNonTag(this);
4765
res->tag = this->tag;
4769
TopoDS_Shape GeomSurface::toShape() const
4771
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4772
Standard_Real u1,u2,v1,v2;
4773
s->Bounds(u1,u2,v1,v2);
4774
BRepBuilderAPI_MakeFace mkBuilder(s, u1, u2, v1, v2, Precision::Confusion() );
4775
return mkBuilder.Shape();
4778
bool GeomSurface::tangentU(double u, double v, gp_Dir& dirU) const
4780
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4781
GeomLProp_SLProps prop(s,u,v,2,Precision::Confusion());
4782
if (prop.IsTangentUDefined()) {
4783
prop.TangentU(dirU);
4789
bool GeomSurface::tangentV(double u, double v, gp_Dir& dirV) const
4791
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4792
GeomLProp_SLProps prop(s,u,v,2,Precision::Confusion());
4793
if (prop.IsTangentVDefined()) {
4794
prop.TangentV(dirV);
4801
bool GeomSurface::normal(double u, double v, gp_Dir& dir) const
4803
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4804
Standard_Boolean done;
4806
Tools::getNormal(s, u, v, Precision::Confusion(), dir, done);
4814
gp_Vec GeomSurface::getDN(double u, double v, int Nu, int Nv) const
4816
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4817
return s->DN(u, v, Nu, Nv);
4820
bool GeomSurface::isUmbillic(double u, double v) const
4822
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4823
GeomLProp_SLProps prop(s,u,v,2,Precision::Confusion());
4824
if (prop.IsCurvatureDefined()) {
4825
return prop.IsUmbilic();
4828
THROWM(Base::RuntimeError,"No curvature defined")
4831
double GeomSurface::curvature(double u, double v, Curvature type) const
4833
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4834
GeomLProp_SLProps prop(s,u,v,2,Precision::Confusion());
4835
if (prop.IsCurvatureDefined()) {
4839
value = prop.MaxCurvature();
4842
value = prop.MinCurvature();
4845
value = prop.MeanCurvature();
4848
value = prop.GaussianCurvature();
4855
THROWM(Base::RuntimeError,"No curvature defined")
4858
void GeomSurface::curvatureDirections(double u, double v, gp_Dir& maxD, gp_Dir& minD) const
4860
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(handle());
4861
GeomLProp_SLProps prop(s,u,v,2,Precision::Confusion());
4862
if (prop.IsCurvatureDefined()) {
4863
prop.CurvatureDirections(maxD, minD);
4867
THROWM(Base::RuntimeError,"No curvature defined")
4872
TYPESYSTEM_SOURCE(Part::GeomBezierSurface,Part::GeomSurface)
4874
GeomBezierSurface::GeomBezierSurface()
4876
TColgp_Array2OfPnt poles(1,2,1,2);
4877
poles(1,1) = gp_Pnt(0.0,0.0,0.0);
4878
poles(2,1) = gp_Pnt(1.0,0.0,0.0);
4879
poles(1,2) = gp_Pnt(0.0,1.0,0.0);
4880
poles(2,2) = gp_Pnt(1.0,1.0,0.0);
4881
this->mySurface = new Geom_BezierSurface(poles);
4884
GeomBezierSurface::GeomBezierSurface(const Handle(Geom_BezierSurface)& b)
4889
GeomBezierSurface::~GeomBezierSurface() = default;
4891
const Handle(Geom_Geometry)& GeomBezierSurface::handle() const
4896
void GeomBezierSurface::setHandle(const Handle(Geom_BezierSurface)& b)
4898
this->mySurface = Handle(Geom_BezierSurface)::DownCast(b->Copy());
4901
Geometry *GeomBezierSurface::copy() const
4903
auto *newSurf = new GeomBezierSurface(mySurface);
4904
newSurf->copyNonTag(this);
4909
unsigned int GeomBezierSurface::getMemSize () const
4911
unsigned int size = sizeof(Geom_BezierSurface);
4912
if (!mySurface.IsNull()) {
4913
unsigned int poles = mySurface->NbUPoles();
4914
poles *= mySurface->NbVPoles();
4915
size += poles * sizeof(gp_Pnt);
4916
size += poles * sizeof(Standard_Real);
4921
void GeomBezierSurface::Save(Base::Writer &) const
4923
throw Base::NotImplementedError("GeomBezierSurface::Save");
4926
void GeomBezierSurface::Restore(Base::XMLReader &)
4928
throw Base::NotImplementedError("GeomBezierSurface::Restore");
4931
PyObject *GeomBezierSurface::getPyObject()
4933
return new BezierSurfacePy(static_cast<GeomBezierSurface*>(this->clone()));
4936
bool GeomBezierSurface::isSame(const Geometry &_other, double tol, double atol) const
4938
if(_other.getTypeId() != getTypeId())
4941
auto &other = static_cast<const GeomBezierSurface &>(_other);
4942
Standard_Integer uc = mySurface->NbUPoles();
4943
Standard_Integer vc = mySurface->NbVPoles();
4944
if(uc != other.mySurface->NbUPoles()
4945
|| vc != other.mySurface->NbVPoles()
4946
|| mySurface->UDegree() != other.mySurface->UDegree()
4947
|| mySurface->VDegree() != other.mySurface->VDegree())
4951
double tol2 = tol*tol;
4952
for(Standard_Integer u=1; u<=uc; ++u) {
4953
for(Standard_Integer v=1; v<=vc; ++v) {
4954
if(mySurface->Pole(u,v).SquareDistance(other.mySurface->Pole(u,v)) > tol2
4955
|| fabs(mySurface->Weight(u,v) - other.mySurface->Weight(u,v)) > tol)
4964
TYPESYSTEM_SOURCE(Part::GeomBSplineSurface,Part::GeomSurface)
4966
GeomBSplineSurface::GeomBSplineSurface()
4968
TColgp_Array2OfPnt poles(1,2,1,2);
4969
poles(1,1) = gp_Pnt(0.0,0.0,0.0);
4970
poles(2,1) = gp_Pnt(1.0,0.0,0.0);
4971
poles(1,2) = gp_Pnt(0.0,1.0,0.0);
4972
poles(2,2) = gp_Pnt(1.0,1.0,0.0);
4974
TColStd_Array1OfReal knots(1,2);
4978
TColStd_Array1OfInteger mults(1,2);
4982
this->mySurface = new Geom_BSplineSurface(poles, knots, knots, mults, mults, 1, 1);
4985
GeomBSplineSurface::GeomBSplineSurface(const Handle(Geom_BSplineSurface)& b)
4990
GeomBSplineSurface::~GeomBSplineSurface() = default;
4992
void GeomBSplineSurface::setHandle(const Handle(Geom_BSplineSurface)& s)
4994
mySurface = Handle(Geom_BSplineSurface)::DownCast(s->Copy());
4997
const Handle(Geom_Geometry)& GeomBSplineSurface::handle() const
5002
Geometry *GeomBSplineSurface::copy() const
5004
GeomBSplineSurface *newSurf = new GeomBSplineSurface(mySurface);
5005
newSurf->copyNonTag(this);
5009
void GeomBSplineSurface::scaleKnotsToBounds(double u0, double u1, double v0, double v1)
5012
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast(mySurface->Copy());
5013
Standard_RangeError_Raise_if (u1 <= u0 || v1 <= v0, " ");
5014
Standard_Real bu0,bu1,bv0,bv1;
5015
surf->Bounds(bu0,bu1,bv0,bv1);
5016
if ((abs(u0-bu0) > Precision::Confusion()) || (abs(u1-bu1) > Precision::Confusion())) {
5017
TColStd_Array1OfReal uk(1,surf->NbUKnots());
5019
BSplCLib::Reparametrize(u0, u1, uk);
5020
surf->SetUKnots(uk);
5022
if ((abs(v0-bv0) > Precision::Confusion()) || (abs(v1-bv1) > Precision::Confusion())) {
5023
TColStd_Array1OfReal vk(1,surf->NbVKnots());
5025
BSplCLib::Reparametrize(v0, v1, vk);
5026
surf->SetVKnots(vk);
5031
catch (Standard_Failure& e) {
5032
THROWM(Base::CADKernelError,e.GetMessageString())
5037
unsigned int GeomBSplineSurface::getMemSize () const
5039
unsigned int size = sizeof(Geom_BSplineSurface);
5040
if (!mySurface.IsNull()) {
5041
size += mySurface->NbUKnots() * sizeof(Standard_Real);
5042
size += mySurface->NbUKnots() * sizeof(Standard_Integer);
5043
size += mySurface->NbVKnots() * sizeof(Standard_Real);
5044
size += mySurface->NbVKnots() * sizeof(Standard_Integer);
5045
unsigned int poles = mySurface->NbUPoles();
5046
poles *= mySurface->NbVPoles();
5047
size += poles * sizeof(gp_Pnt);
5048
size += poles * sizeof(Standard_Real);
5053
void GeomBSplineSurface::Save(Base::Writer &) const
5055
throw Base::NotImplementedError("GeomBSplineSurface::Save");
5058
void GeomBSplineSurface::Restore(Base::XMLReader &)
5060
throw Base::NotImplementedError("GeomBSplineSurface::Restore");
5063
PyObject *GeomBSplineSurface::getPyObject()
5065
return new BSplineSurfacePy(static_cast<GeomBSplineSurface*>(this->clone()));
5068
bool GeomBSplineSurface::isSame(const Geometry &_other, double tol, double atol) const
5070
if(_other.getTypeId() != getTypeId()) {
5071
if (_other.isDerivedFrom(GeomSurface::getClassTypeId()) && isPlanar()) {
5072
std::unique_ptr<Geometry> geo(toPlane());
5074
return geo->isSame(_other, tol, atol);
5079
auto &other = static_cast<const GeomBSplineSurface &>(_other);
5080
Standard_Integer uc = mySurface->NbUPoles();
5081
Standard_Integer vc = mySurface->NbVPoles();
5082
Standard_Integer ukc = mySurface->NbUKnots();
5083
Standard_Integer vkc = mySurface->NbVKnots();
5084
if(uc != other.mySurface->NbUPoles()
5085
|| vc != other.mySurface->NbVPoles()
5086
|| ukc != other.mySurface->NbUKnots()
5087
|| vkc != other.mySurface->NbVKnots()
5088
|| mySurface->UDegree() != other.mySurface->UDegree()
5089
|| mySurface->VDegree() != other.mySurface->VDegree()
5090
|| mySurface->IsUPeriodic() != other.mySurface->IsUPeriodic()
5091
|| mySurface->IsVPeriodic() != other.mySurface->IsVPeriodic())
5095
double tol2 = tol*tol;
5096
for(Standard_Integer u=1; u<=uc; ++u) {
5097
for(Standard_Integer v=1; v<=vc; ++v) {
5098
if(mySurface->Pole(u,v).SquareDistance(other.mySurface->Pole(u,v)) > tol2
5099
|| fabs(mySurface->Weight(u,v) - other.mySurface->Weight(u,v)) > tol)
5103
for(Standard_Integer u=1; u<=ukc; ++u) {
5104
if(fabs(mySurface->UKnot(u) - other.mySurface->UKnot(u)) > tol
5105
|| fabs(mySurface->UMultiplicity(u) - other.mySurface->UMultiplicity(u)) > tol)
5108
for(Standard_Integer v=1; v<=ukc; ++v) {
5109
if(fabs(mySurface->VKnot(v) - other.mySurface->VKnot(v)) > tol
5110
|| fabs(mySurface->VMultiplicity(v) - other.mySurface->VMultiplicity(v)) > tol)
5118
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomElementarySurface, Part::GeomSurface)
5120
GeomElementarySurface::GeomElementarySurface()
5124
GeomElementarySurface::~GeomElementarySurface()
5128
Base::Vector3d GeomElementarySurface::getLocation(void) const
5130
Handle(Geom_ElementarySurface) surf = Handle(Geom_ElementarySurface)::DownCast(handle());
5131
gp_Pnt loc = surf->Location();
5132
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
5135
Base::Vector3d GeomElementarySurface::getDir(void) const
5137
Handle(Geom_ElementarySurface) surf = Handle(Geom_ElementarySurface)::DownCast(handle());
5138
const gp_Dir &dir = surf->Position().Direction();
5139
return Base::Vector3d(dir.X(),dir.Y(),dir.Z());
5142
Base::Vector3d GeomElementarySurface::getXDir(void) const
5144
Handle(Geom_ElementarySurface) surf = Handle(Geom_ElementarySurface)::DownCast(handle());
5145
const gp_Dir &dir = surf->Position().XDirection();
5146
return Base::Vector3d(dir.X(),dir.Y(),dir.Z());
5149
Base::Vector3d GeomElementarySurface::getYDir(void) const
5151
Handle(Geom_ElementarySurface) surf = Handle(Geom_ElementarySurface)::DownCast(handle());
5152
const gp_Dir &dir = surf->Position().YDirection();
5153
return Base::Vector3d(dir.X(),dir.Y(),dir.Z());
5156
bool GeomElementarySurface::isSame(const Geometry &_other, double tol, double atol) const
5158
if(!_other.isDerivedFrom(GeomElementarySurface::getClassTypeId()))
5161
auto &other = static_cast<const GeomElementarySurface &>(_other);
5162
return Base::DistanceP2(getLocation(), other.getLocation()) <= tol*tol
5163
&& getDir().GetAngle(other.getDir()) <= atol
5164
&& ((getXDir().GetAngle(other.getXDir()) <= atol
5165
&& getYDir().GetAngle(other.getYDir()) <= atol)
5168
|| (getXDir().GetAngle(other.getYDir()) <= atol
5169
&& getYDir().GetAngle(-other.getXDir()) <= atol)
5170
|| (getYDir().GetAngle(other.getXDir()) <= atol
5171
&& getXDir().GetAngle(-other.getYDir()) <= atol));
5176
TYPESYSTEM_SOURCE(Part::GeomCylinder,Part::GeomSurface)
5178
GeomCylinder::GeomCylinder()
5180
Handle(Geom_CylindricalSurface) s = new Geom_CylindricalSurface(gp_Cylinder());
5181
this->mySurface = s;
5184
GeomCylinder::GeomCylinder(const Handle(Geom_CylindricalSurface)& c)
5189
GeomCylinder::~GeomCylinder() = default;
5191
void GeomCylinder::setHandle(const Handle(Geom_CylindricalSurface)& s)
5193
mySurface = Handle(Geom_CylindricalSurface)::DownCast(s->Copy());
5196
const Handle(Geom_Geometry)& GeomCylinder::handle() const
5201
Geometry *GeomCylinder::copy() const
5203
GeomCylinder *tempCurve = new GeomCylinder();
5204
tempCurve->mySurface = Handle(Geom_CylindricalSurface)::DownCast(mySurface->Copy());
5205
tempCurve->copyNonTag(this);
5210
unsigned int GeomCylinder::getMemSize () const
5212
return sizeof(Geom_CylindricalSurface);
5215
void GeomCylinder::Save(Base::Writer &) const
5217
throw Base::NotImplementedError("GeomCylinder::Save");
5220
void GeomCylinder::Restore(Base::XMLReader &)
5222
throw Base::NotImplementedError("GeomCylinder::Restore");
5225
PyObject *GeomCylinder::getPyObject()
5227
return new CylinderPy(static_cast<GeomCylinder*>(this->clone()));
5230
double GeomCylinder::getRadius() const
5232
return mySurface->Radius();
5235
bool GeomCylinder::isSame(const Geometry &_other, double tol, double atol) const
5237
if(_other.getTypeId() != getTypeId())
5241
auto &other = static_cast<const GeomCylinder &>(_other);
5242
return GeomElementarySurface::isSame(other,tol,atol)
5243
&& fabs(getRadius() - other.getRadius()) <= tol;
5249
TYPESYSTEM_SOURCE(Part::GeomCone,Part::GeomSurface)
5253
Handle(Geom_ConicalSurface) s = new Geom_ConicalSurface(gp_Cone());
5254
this->mySurface = s;
5257
GeomCone::GeomCone(const Handle(Geom_ConicalSurface)& c)
5262
GeomCone::~GeomCone() = default;
5264
void GeomCone::setHandle(const Handle(Geom_ConicalSurface)& s)
5266
mySurface = Handle(Geom_ConicalSurface)::DownCast(s->Copy());
5269
const Handle(Geom_Geometry)& GeomCone::handle() const
5274
Geometry *GeomCone::copy() const
5276
GeomCone *tempCurve = new GeomCone();
5277
tempCurve->mySurface = Handle(Geom_ConicalSurface)::DownCast(mySurface->Copy());
5278
tempCurve->copyNonTag(this);
5283
unsigned int GeomCone::getMemSize () const
5285
return sizeof(Geom_ConicalSurface);
5288
void GeomCone::Save(Base::Writer &) const
5290
throw Base::NotImplementedError("GeomCone::Save");
5293
void GeomCone::Restore(Base::XMLReader &)
5295
throw Base::NotImplementedError("GeomCone::Restore");
5298
PyObject *GeomCone::getPyObject()
5300
return new ConePy(static_cast<GeomCone*>(this->clone()));
5303
gp_Vec GeomCone::getDN(double u, double v, int Nu, int Nv) const
5306
#if OCC_VERSION_HEX >= 0x070700
5307
return GeomSurface::getDN(u, v, Nu, Nv);
5310
auto ElSLib__ConeDN = [](const Standard_Real U,
5311
const Standard_Real V,
5313
const Standard_Real Radius,
5314
const Standard_Real SAngle,
5315
const Standard_Integer Nu,
5316
const Standard_Integer Nv)
5318
gp_XYZ Xdir = Pos.XDirection().XYZ();
5319
gp_XYZ Ydir = Pos.YDirection().XYZ();
5320
Standard_Real Um = U + Nu * M_PI_2;
5321
Xdir.Multiply(cos(Um));
5322
Ydir.Multiply(sin(Um));
5325
Xdir.Multiply(Radius + V * sin(SAngle));
5326
if(Nu == 0) Xdir.Add(Pos.Location().XYZ());
5327
return gp_Vec(Xdir);
5330
Xdir.Multiply(sin(SAngle));
5332
Xdir.Add(Pos.Direction().XYZ() * cos(SAngle));
5333
return gp_Vec(Xdir);
5335
return gp_Vec(0.0,0.0,0.0);
5340
Handle(Geom_ConicalSurface) s = Handle(Geom_ConicalSurface)::DownCast(handle());
5341
Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " ");
5343
return {0.0, 0.0, 0.0};
5346
return ElSLib__ConeDN(u, v, s->Position(), s->RefRadius(), s->SemiAngle(), Nu, Nv);
5351
double GeomCone::getRadius() const
5353
return mySurface->RefRadius();
5356
double GeomCone::getSemiAngle() const
5358
return mySurface->SemiAngle();
5361
bool GeomCone::isSame(const Geometry &_other, double tol, double atol) const
5363
if(_other.getTypeId() != getTypeId())
5366
auto &other = static_cast<const GeomCone &>(_other);
5367
return GeomElementarySurface::isSame(other,tol,atol)
5368
&& fabs(getRadius() - other.getRadius()) <= tol
5369
&& fabs(getSemiAngle() - other.getSemiAngle()) <= atol;
5374
TYPESYSTEM_SOURCE(Part::GeomToroid,Part::GeomSurface)
5376
GeomToroid::GeomToroid()
5378
Handle(Geom_ToroidalSurface) s = new Geom_ToroidalSurface(gp_Torus());
5379
this->mySurface = s;
5382
GeomToroid::GeomToroid(const Handle(Geom_ToroidalSurface)& t)
5387
GeomToroid::~GeomToroid() = default;
5389
void GeomToroid::setHandle(const Handle(Geom_ToroidalSurface)& s)
5391
mySurface = Handle(Geom_ToroidalSurface)::DownCast(s->Copy());
5394
const Handle(Geom_Geometry)& GeomToroid::handle() const
5399
Geometry *GeomToroid::copy() const
5401
GeomToroid *tempCurve = new GeomToroid();
5402
tempCurve->mySurface = Handle(Geom_ToroidalSurface)::DownCast(mySurface->Copy());
5403
tempCurve->copyNonTag(this);
5408
unsigned int GeomToroid::getMemSize () const
5410
return sizeof(Geom_ToroidalSurface);
5413
void GeomToroid::Save(Base::Writer &) const
5415
throw Base::NotImplementedError("GeomToroid::Save");
5418
void GeomToroid::Restore(Base::XMLReader &)
5420
throw Base::NotImplementedError("GeomToroid::Restore");
5423
PyObject *GeomToroid::getPyObject()
5425
return new ToroidPy(static_cast<GeomToroid*>(this->clone()));
5428
double GeomToroid::getMajorRadius() const
5430
return mySurface->MajorRadius();
5433
double GeomToroid::getMinorRadius() const
5435
return mySurface->MinorRadius();
5438
bool GeomToroid::isSame(const Geometry &_other, double tol, double atol) const
5440
if(_other.getTypeId() != getTypeId())
5444
auto &other = static_cast<const GeomToroid &>(_other);
5445
return GeomElementarySurface::isSame(other,tol,atol)
5446
&& fabs(getMajorRadius() - other.getMajorRadius()) <= tol
5447
&& fabs(getMinorRadius() - other.getMinorRadius()) <= tol;
5453
TYPESYSTEM_SOURCE(Part::GeomSphere,Part::GeomSurface)
5455
GeomSphere::GeomSphere()
5457
Handle(Geom_SphericalSurface) s = new Geom_SphericalSurface(gp_Sphere());
5458
this->mySurface = s;
5461
GeomSphere::GeomSphere(const Handle(Geom_SphericalSurface)& s)
5466
GeomSphere::~GeomSphere() = default;
5468
void GeomSphere::setHandle(const Handle(Geom_SphericalSurface)& s)
5470
mySurface = Handle(Geom_SphericalSurface)::DownCast(s->Copy());
5473
const Handle(Geom_Geometry)& GeomSphere::handle() const
5478
Geometry *GeomSphere::copy() const
5480
GeomSphere *tempCurve = new GeomSphere();
5481
tempCurve->mySurface = Handle(Geom_SphericalSurface)::DownCast(mySurface->Copy());
5482
tempCurve->copyNonTag(this);
5487
unsigned int GeomSphere::getMemSize () const
5489
return sizeof(Geom_SphericalSurface);
5492
void GeomSphere::Save(Base::Writer &) const
5494
throw Base::NotImplementedError("GeomSphere::Save");
5497
void GeomSphere::Restore(Base::XMLReader &)
5499
throw Base::NotImplementedError("GeomSphere::Restore");
5502
PyObject *GeomSphere::getPyObject()
5504
return new SpherePy(static_cast<GeomSphere*>(this->clone()));
5507
double GeomSphere::getRadius() const
5509
return mySurface->Radius();
5512
bool GeomSphere::isSame(const Geometry &_other, double tol, double atol) const
5514
if(_other.getTypeId() != getTypeId())
5518
auto &other = static_cast<const GeomSphere &>(_other);
5519
return GeomElementarySurface::isSame(other,tol,atol)
5520
&& fabs(getRadius() - other.getRadius()) <= tol;
5526
TYPESYSTEM_SOURCE(Part::GeomPlane,Part::GeomSurface)
5528
GeomPlane::GeomPlane()
5530
Handle(Geom_Plane) s = new Geom_Plane(gp_Pln());
5531
this->mySurface = s;
5534
GeomPlane::GeomPlane(const gp_Pln &pln)
5536
Handle(Geom_Plane) s = new Geom_Plane(pln);
5537
this->mySurface = s;
5540
GeomPlane::GeomPlane(const Handle(Geom_Plane)& p)
5545
GeomPlane::~GeomPlane() = default;
5547
void GeomPlane::setHandle(const Handle(Geom_Plane)& s)
5549
mySurface = Handle(Geom_Plane)::DownCast(s->Copy());
5552
const Handle(Geom_Geometry)& GeomPlane::handle() const
5557
Geometry *GeomPlane::copy() const
5559
GeomPlane *tempCurve = new GeomPlane();
5560
tempCurve->mySurface = Handle(Geom_Plane)::DownCast(mySurface->Copy());
5561
tempCurve->copyNonTag(this);
5566
unsigned int GeomPlane::getMemSize () const
5568
return sizeof(Geom_Plane);
5571
void GeomPlane::Save(Base::Writer &) const
5573
throw Base::NotImplementedError("GeomPlane::Save");
5576
void GeomPlane::Restore(Base::XMLReader &)
5578
throw Base::NotImplementedError("GeomPlane::Restore");
5581
PyObject *GeomPlane::getPyObject()
5583
return new PlanePy(static_cast<GeomPlane*>(this->clone()));
5586
bool GeomPlane::isSame(const Geometry &_other, double tol, double atol) const
5588
if(_other.getTypeId() != getTypeId()) {
5589
if (_other.isDerivedFrom(GeomSurface::getClassTypeId())) {
5590
std::unique_ptr<Geometry> geo(static_cast<const GeomSurface&>(_other).toPlane());
5592
return isSame(*geo, tol, atol);
5597
auto &other = static_cast<const GeomPlane &>(_other);
5598
return GeomElementarySurface::isSame(other,tol,atol);
5603
TYPESYSTEM_SOURCE(Part::GeomOffsetSurface,Part::GeomSurface)
5605
GeomOffsetSurface::GeomOffsetSurface() = default;
5607
GeomOffsetSurface::GeomOffsetSurface(const Handle(Geom_Surface)& s, double offset)
5609
this->mySurface = new Geom_OffsetSurface(s, offset);
5612
GeomOffsetSurface::GeomOffsetSurface(const Handle(Geom_OffsetSurface)& s)
5617
GeomOffsetSurface::~GeomOffsetSurface() = default;
5619
void GeomOffsetSurface::setHandle(const Handle(Geom_OffsetSurface)& s)
5621
mySurface = Handle(Geom_OffsetSurface)::DownCast(s->Copy());
5624
const Handle(Geom_Geometry)& GeomOffsetSurface::handle() const
5629
Geometry *GeomOffsetSurface::copy() const
5631
GeomOffsetSurface *newSurf = new GeomOffsetSurface(mySurface);
5632
newSurf->copyNonTag(this);
5637
unsigned int GeomOffsetSurface::getMemSize () const
5639
return sizeof(Geom_OffsetSurface);
5642
void GeomOffsetSurface::Save(Base::Writer &) const
5644
throw Base::NotImplementedError("GeomOffsetSurface::Save");
5647
void GeomOffsetSurface::Restore(Base::XMLReader &)
5649
throw Base::NotImplementedError("GeomOffsetSurface::Restore");
5652
PyObject *GeomOffsetSurface::getPyObject()
5654
return new OffsetSurfacePy(static_cast<GeomOffsetSurface*>(this->clone()));
5657
double GeomOffsetSurface::getOffset() const
5659
return mySurface->Offset();
5662
bool GeomOffsetSurface::isSame(const Geometry &_other, double tol, double atol) const
5664
if(_other.getTypeId() != getTypeId())
5667
auto &other = static_cast<const GeomOffsetSurface &>(_other);
5668
if(fabs(getOffset() - other.getOffset()) > tol)
5671
Handle(Geom_Surface) basis = mySurface->BasisSurface();
5672
Handle(Geom_Surface) basis1 = other.mySurface->BasisSurface();
5673
if(basis.IsNull() || basis1.IsNull() || basis->DynamicType() != basis1->DynamicType())
5676
std::unique_ptr<Geometry> b(makeFromSurface(basis));
5677
std::unique_ptr<Geometry> b1(makeFromSurface(basis1));
5678
return b && b1 && b->isSame(*b1,tol,atol);
5683
TYPESYSTEM_SOURCE(Part::GeomPlateSurface,Part::GeomSurface)
5685
GeomPlateSurface::GeomPlateSurface() = default;
5687
GeomPlateSurface::GeomPlateSurface(const Handle(Geom_Surface)& s, const Plate_Plate& plate)
5689
this->mySurface = new GeomPlate_Surface(s, plate);
5692
GeomPlateSurface::GeomPlateSurface(const GeomPlate_BuildPlateSurface& buildPlate)
5694
Handle(GeomPlate_Surface) s = buildPlate.Surface();
5695
this->mySurface = Handle(GeomPlate_Surface)::DownCast(s->Copy());
5698
GeomPlateSurface::GeomPlateSurface(const Handle(GeomPlate_Surface)& s)
5703
GeomPlateSurface::~GeomPlateSurface() = default;
5705
void GeomPlateSurface::setHandle(const Handle(GeomPlate_Surface)& s)
5707
mySurface = Handle(GeomPlate_Surface)::DownCast(s->Copy());
5710
const Handle(Geom_Geometry)& GeomPlateSurface::handle() const
5715
Geometry *GeomPlateSurface::copy() const
5717
GeomPlateSurface *newSurf = new GeomPlateSurface(mySurface);
5718
newSurf->copyNonTag(this);
5723
unsigned int GeomPlateSurface::getMemSize () const
5725
throw Base::NotImplementedError("GeomPlateSurface::getMemSize");
5728
void GeomPlateSurface::Save(Base::Writer &) const
5730
throw Base::NotImplementedError("GeomPlateSurface::Save");
5733
void GeomPlateSurface::Restore(Base::XMLReader &)
5735
throw Base::NotImplementedError("GeomPlateSurface::Restore");
5738
PyObject *GeomPlateSurface::getPyObject()
5740
return new PlateSurfacePy(static_cast<GeomPlateSurface*>(this->clone()));
5743
bool GeomPlateSurface::isSame(const Geometry &, double, double) const
5751
TYPESYSTEM_SOURCE(Part::GeomTrimmedSurface,Part::GeomSurface)
5753
GeomTrimmedSurface::GeomTrimmedSurface() = default;
5755
GeomTrimmedSurface::GeomTrimmedSurface(const Handle(Geom_RectangularTrimmedSurface)& s)
5760
GeomTrimmedSurface::~GeomTrimmedSurface() = default;
5762
void GeomTrimmedSurface::setHandle(const Handle(Geom_RectangularTrimmedSurface)& s)
5764
mySurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(s->Copy());
5767
const Handle(Geom_Geometry)& GeomTrimmedSurface::handle() const
5772
Geometry *GeomTrimmedSurface::copy() const
5774
GeomTrimmedSurface *newSurf = new GeomTrimmedSurface(mySurface);
5775
newSurf->copyNonTag(this);
5780
unsigned int GeomTrimmedSurface::getMemSize () const
5782
return sizeof(Geom_RectangularTrimmedSurface);
5785
void GeomTrimmedSurface::Save(Base::Writer &) const
5787
throw Base::NotImplementedError("GeomTrimmedSurface::Save");
5790
void GeomTrimmedSurface::Restore(Base::XMLReader &)
5792
throw Base::NotImplementedError("GeomTrimmedSurface::Restore");
5795
PyObject *GeomTrimmedSurface::getPyObject()
5797
return new RectangularTrimmedSurfacePy(static_cast<GeomTrimmedSurface*>(this->clone()));
5800
bool GeomTrimmedSurface::isSame(const Geometry &_other, double tol, double atol) const
5802
if(_other.getTypeId() != getTypeId())
5805
auto &other = static_cast<const GeomTrimmedSurface &>(_other);
5807
Standard_Real u1[2],u2[2],v1[2],v2[2];
5808
mySurface->Bounds(u1[0],u2[0],v1[0],v2[0]);
5809
other.mySurface->Bounds(u1[1],u2[1],v1[1],v2[1]);
5811
if(fabs(u1[0]-u1[1])>tol || fabs(u2[0]-u2[1])>tol
5812
|| fabs(v1[0]-v1[1])>tol || fabs(v2[0]-v2[1])>tol)
5815
Handle(Geom_Surface) basis = mySurface->BasisSurface();
5816
Handle(Geom_Surface) basis1 = other.mySurface->BasisSurface();
5817
if(basis.IsNull() || basis1.IsNull() || basis->DynamicType() != basis1->DynamicType())
5820
std::unique_ptr<Geometry> b(makeFromSurface(basis));
5821
std::unique_ptr<Geometry> b1(makeFromSurface(basis1));
5822
return b && b1 && b->isSame(*b1,tol,atol);
5826
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomSweptSurface, Part::GeomSurface)
5828
GeomSweptSurface::GeomSweptSurface()
5832
GeomSweptSurface::~GeomSweptSurface()
5836
Base::Vector3d GeomSweptSurface::getDir(void) const
5838
Handle(Geom_SweptSurface) surf = Handle(Geom_SweptSurface)::DownCast(handle());
5839
const gp_Dir &dir = surf->Direction();
5840
return Base::Vector3d(dir.X(),dir.Y(),dir.Z());
5843
bool GeomSweptSurface::isSame(const Geometry &_other, double tol, double atol) const
5845
if(!_other.isDerivedFrom(GeomSweptSurface::getClassTypeId()))
5848
auto &other = static_cast<const GeomSweptSurface &>(_other);
5849
if(getDir().GetAngle(other.getDir()) > atol)
5852
Handle(Geom_SweptSurface) surf = Handle(Geom_SweptSurface)::DownCast(handle());
5853
Handle(Geom_SweptSurface) surf1 = Handle(Geom_SweptSurface)::DownCast(other.handle());
5855
Handle(Geom_Curve) basis = surf->BasisCurve();
5856
Handle(Geom_Curve) basis1 = surf1->BasisCurve();
5857
if(basis.IsNull() || basis1.IsNull() || basis->DynamicType() != basis1->DynamicType())
5860
std::unique_ptr<Geometry> b(makeFromCurve(basis));
5861
std::unique_ptr<Geometry> b1(makeFromCurve(basis1));
5862
return b && b1 && b->isSame(*b1,tol,atol);
5866
TYPESYSTEM_SOURCE(Part::GeomSurfaceOfRevolution,Part::GeomSurface)
5868
GeomSurfaceOfRevolution::GeomSurfaceOfRevolution() = default;
5870
GeomSurfaceOfRevolution::GeomSurfaceOfRevolution(const Handle(Geom_Curve)& c, const gp_Ax1& a)
5872
this->mySurface = new Geom_SurfaceOfRevolution(c,a);
5875
GeomSurfaceOfRevolution::GeomSurfaceOfRevolution(const Handle(Geom_SurfaceOfRevolution)& s)
5880
GeomSurfaceOfRevolution::~GeomSurfaceOfRevolution() = default;
5882
void GeomSurfaceOfRevolution::setHandle(const Handle(Geom_SurfaceOfRevolution)& c)
5884
mySurface = Handle(Geom_SurfaceOfRevolution)::DownCast(c->Copy());
5887
const Handle(Geom_Geometry)& GeomSurfaceOfRevolution::handle() const
5892
Geometry *GeomSurfaceOfRevolution::copy() const
5894
GeomSurfaceOfRevolution *newSurf = new GeomSurfaceOfRevolution(mySurface);
5895
newSurf->copyNonTag(this);
5900
unsigned int GeomSurfaceOfRevolution::getMemSize () const
5902
return sizeof(Geom_SurfaceOfRevolution);
5905
void GeomSurfaceOfRevolution::Save(Base::Writer &) const
5907
throw Base::NotImplementedError("GeomSurfaceOfRevolution::Save");
5910
void GeomSurfaceOfRevolution::Restore(Base::XMLReader &)
5912
throw Base::NotImplementedError("GeomSurfaceOfRevolution::Restore");
5915
PyObject *GeomSurfaceOfRevolution::getPyObject()
5917
return new SurfaceOfRevolutionPy(static_cast<GeomSurfaceOfRevolution*>(this->clone()));
5922
TYPESYSTEM_SOURCE(Part::GeomSurfaceOfExtrusion,Part::GeomSurface)
5924
GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion() = default;
5926
GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion(const Handle(Geom_Curve)& c, const gp_Dir& d)
5928
this->mySurface = new Geom_SurfaceOfLinearExtrusion(c,d);
5931
GeomSurfaceOfExtrusion::GeomSurfaceOfExtrusion(const Handle(Geom_SurfaceOfLinearExtrusion)& s)
5936
GeomSurfaceOfExtrusion::~GeomSurfaceOfExtrusion() = default;
5938
void GeomSurfaceOfExtrusion::setHandle(const Handle(Geom_SurfaceOfLinearExtrusion)& c)
5940
mySurface = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(c->Copy());
5943
const Handle(Geom_Geometry)& GeomSurfaceOfExtrusion::handle() const
5948
Geometry *GeomSurfaceOfExtrusion::copy() const
5950
GeomSurfaceOfExtrusion *newSurf = new GeomSurfaceOfExtrusion(mySurface);
5951
newSurf->copyNonTag(this);
5956
unsigned int GeomSurfaceOfExtrusion::getMemSize () const
5958
return sizeof(Geom_SurfaceOfLinearExtrusion);
5961
void GeomSurfaceOfExtrusion::Save(Base::Writer &) const
5963
throw Base::NotImplementedError("GeomSurfaceOfExtrusion::Save");
5966
void GeomSurfaceOfExtrusion::Restore(Base::XMLReader &)
5968
throw Base::NotImplementedError("GeomSurfaceOfExtrusion::Restore");
5971
PyObject *GeomSurfaceOfExtrusion::getPyObject()
5973
return new SurfaceOfExtrusionPy(static_cast<GeomSurfaceOfExtrusion*>(this->clone()));
5981
bool find2DLinesIntersection(const Base::Vector3d &orig1, const Base::Vector3d &dir1,
5982
const Base::Vector3d &orig2, const Base::Vector3d &dir2,
5983
Base::Vector3d &point)
5985
double det = dir1.x*dir2.y - dir1.y*dir2.x;
5986
if ((det > 0 ? det : -det) < 1e-10)
5988
double c1 = dir1.y*orig1.x - dir1.x*orig1.y;
5989
double c2 = dir2.y*orig2.x - dir2.x*orig2.y;
5990
double x = (dir1.x*c2 - dir2.x*c1)/det;
5991
double y = (dir1.y*c2 - dir2.y*c1)/det;
5992
point = Base::Vector3d(x,y,0.f);
5996
bool find2DLinesIntersection(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
5997
Base::Vector3d &point)
5999
Base::Vector3d orig1 = lineSeg1->getStartPoint();
6000
Base::Vector3d orig2 = lineSeg2->getStartPoint();
6001
Base::Vector3d dir1 = (lineSeg1->getEndPoint()-lineSeg1->getStartPoint());
6002
Base::Vector3d dir2 = (lineSeg2->getEndPoint()-lineSeg2->getStartPoint());
6003
return find2DLinesIntersection(orig1, dir1, orig2, dir2, point);
6006
bool findFilletCenter(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2, double radius,
6007
Base::Vector3d ¢er)
6009
Base::Vector3d midPoint1 = (lineSeg1->getStartPoint()+lineSeg1->getEndPoint())/2;
6010
Base::Vector3d midPoint2 = (lineSeg2->getStartPoint()+lineSeg2->getEndPoint())/2;
6011
return findFilletCenter(lineSeg1, lineSeg2, radius, midPoint1, midPoint2, center);
6014
bool findFilletCenter(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2, double radius,
6015
const Base::Vector3d &refPnt1, const Base::Vector3d &refPnt2, Base::Vector3d ¢er)
6018
Base::Vector3d l1p1, l1p2, l2p1, l2p2, dir1, dir2, norm1, norm2;
6019
l1p1 = lineSeg1->getStartPoint();
6020
l1p2 = lineSeg1->getEndPoint();
6021
l2p1 = lineSeg2->getStartPoint();
6022
l2p2 = lineSeg2->getEndPoint();
6024
dir1 = (l1p1 - l1p2).Normalize();
6025
dir2 = (l2p1 - l2p2).Normalize();
6027
norm1 = Base::Vector3d(dir1.y, -dir1.x, 0.).Normalize();
6028
norm2 = Base::Vector3d(dir2.y, -dir2.x, 0.).Normalize();
6033
Base::Vector3d corner;
6034
if (!find2DLinesIntersection(lineSeg1,lineSeg2,corner))
6038
Base::Vector3d normPnt1, normPnt2;
6039
normPnt1.ProjectToLine(refPnt1-l1p1, l1p2-l1p1);
6040
normPnt2.ProjectToLine(refPnt2-l2p1, l2p2-l2p1);
6041
normPnt1 += refPnt1;
6042
normPnt2 += refPnt2;
6045
Base::Vector3d bisectDir = ((normPnt1 - corner).Normalize() + (normPnt2-corner).Normalize()).Normalize();
6048
Base::Vector3d normIntersection1, normIntersection2;
6049
if (find2DLinesIntersection(normPnt1, norm1, corner, bisectDir, normIntersection1) &&
6050
find2DLinesIntersection(normPnt2, norm2, corner, bisectDir, normIntersection2)) {
6051
norm1 = (normIntersection1 - normPnt1).Normalize();
6052
norm2 = (normIntersection2 - normPnt2).Normalize();
6058
Base::Vector3d tmpPoint1 = l1p1 + (norm1 * radius);
6059
Base::Vector3d tmpPoint2 = l2p1 + (norm2 * radius);
6062
if (find2DLinesIntersection(tmpPoint1, dir1, tmpPoint2, dir2, center))
6069
double suggestFilletRadius(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
6070
const Base::Vector3d &refPnt1, const Base::Vector3d &refPnt2)
6072
Base::Vector3d corner;
6073
if (!Part::find2DLinesIntersection(lineSeg1, lineSeg2, corner))
6076
Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
6077
Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
6080
if (dir1*(refPnt1-corner) < 0)
6082
if (dir2*(refPnt2-corner) < 0)
6086
Base::Vector3d dirBisect = (dir1.Normalize() + dir2.Normalize()).Normalize();
6088
Base::Vector3d projPnt1, projPnt2;
6089
projPnt1.ProjectToLine(refPnt1-corner, dir1);
6090
projPnt2.ProjectToLine(refPnt2-corner, dir2);
6091
projPnt1 += refPnt1;
6092
projPnt2 += refPnt2;
6094
Base::Vector3d norm1(dir1.y, -dir1.x, 0.f);
6095
Base::Vector3d norm2(dir2.y, -dir2.x, 0.f);
6097
double r1=-1, r2=-1;
6098
Base::Vector3d center1, center2;
6099
if (find2DLinesIntersection(projPnt1, norm1, corner, dirBisect, center1))
6100
r1 = (projPnt1 - center1).Length();
6101
if (find2DLinesIntersection(projPnt2, norm2, corner, dirBisect, center2))
6102
r2 = (projPnt1 - center2).Length();
6104
return r1 < r2 ? r1 : r2;
6107
GeomArcOfCircle *createFilletGeometry(const GeomLineSegment *lineSeg1, const GeomLineSegment *lineSeg2,
6108
const Base::Vector3d ¢er, double radius)
6110
Base::Vector3d corner;
6111
if (!Part::find2DLinesIntersection(lineSeg1, lineSeg2, corner))
6115
Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint();
6116
Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint();
6118
Base::Vector3d radDir1, radDir2;
6119
radDir1.ProjectToLine(center - corner, dir1);
6120
radDir2.ProjectToLine(center - corner, dir2);
6123
double startAngle, endAngle, range;
6125
startAngle = atan2(radDir1.y, radDir1.x);
6126
range = atan2(-radDir1.y*radDir2.x+radDir1.x*radDir2.y,
6127
radDir1.x*radDir2.x+radDir1.y*radDir2.y);
6128
endAngle = startAngle + range;
6130
if (endAngle < startAngle)
6131
std::swap(startAngle, endAngle);
6133
if (endAngle > 2*M_PI )
6136
if (startAngle < 0 )
6140
GeomArcOfCircle *arc = new GeomArcOfCircle();
6141
arc->setRadius(radius);
6142
arc->setCenter(center);
6143
arc->setRange(startAngle, endAngle, true);
6148
std::unique_ptr<GeomSurface> makeFromSurface(const Handle(Geom_Surface)& s, bool silent)
6150
std::unique_ptr<GeomSurface> geoSurf;
6154
throw Base::ValueError("Null surface");
6158
if (s->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) {
6159
Handle(Geom_ToroidalSurface) hSurf = Handle(Geom_ToroidalSurface)::DownCast(s);
6160
geoSurf = std::make_unique<GeomToroid>(hSurf);
6162
else if (s->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
6163
Handle(Geom_BezierSurface) hSurf = Handle(Geom_BezierSurface)::DownCast(s);
6164
geoSurf = std::make_unique<GeomBezierSurface>(hSurf);
6166
else if (s->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
6167
Handle(Geom_BSplineSurface) hSurf = Handle(Geom_BSplineSurface)::DownCast(s);
6168
geoSurf = std::make_unique<GeomBSplineSurface>(hSurf);
6170
else if (s->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
6171
Handle(Geom_CylindricalSurface) hSurf = Handle(Geom_CylindricalSurface)::DownCast(s);
6172
geoSurf = std::make_unique<GeomCylinder>(hSurf);
6174
else if (s->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
6175
Handle(Geom_ConicalSurface) hSurf = Handle(Geom_ConicalSurface)::DownCast(s);
6176
geoSurf = std::make_unique<GeomCone>(hSurf);
6178
else if (s->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
6179
Handle(Geom_SphericalSurface) hSurf = Handle(Geom_SphericalSurface)::DownCast(s);
6180
geoSurf = std::make_unique<GeomSphere>(hSurf);
6182
else if (s->IsKind(STANDARD_TYPE(Geom_Plane))) {
6183
Handle(Geom_Plane) hSurf = Handle(Geom_Plane)::DownCast(s);
6184
geoSurf = std::make_unique<GeomPlane>(hSurf);
6186
else if (s->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
6187
Handle(Geom_OffsetSurface) hSurf = Handle(Geom_OffsetSurface)::DownCast(s);
6188
geoSurf = std::make_unique<GeomOffsetSurface>(hSurf);
6190
else if (s->IsKind(STANDARD_TYPE(GeomPlate_Surface))) {
6191
Handle(GeomPlate_Surface) hSurf = Handle(GeomPlate_Surface)::DownCast(s);
6192
geoSurf = std::make_unique<GeomPlateSurface>(hSurf);
6194
else if (s->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
6195
Handle(Geom_RectangularTrimmedSurface) hSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(s);
6196
geoSurf = std::make_unique<GeomTrimmedSurface>(hSurf);
6198
else if (s->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
6199
Handle(Geom_SurfaceOfRevolution) hSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(s);
6200
geoSurf = std::make_unique<GeomSurfaceOfRevolution>(hSurf);
6202
else if (s->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
6203
Handle(Geom_SurfaceOfLinearExtrusion) hSurf = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(s);
6204
geoSurf = std::make_unique<GeomSurfaceOfExtrusion>(hSurf);
6207
std::string err = "Unhandled surface type ";
6208
err += s->DynamicType()->Name();
6209
throw Base::TypeError(err);
6215
std::unique_ptr<GeomSurface> makeFromSurfaceAdaptor(const BRepAdaptor_Surface& adapt, bool silent)
6217
std::unique_ptr<GeomSurface> geoSurf;
6219
switch(adapt.GetType())
6223
geoSurf.reset(new GeomPlane());
6224
Handle(Geom_Plane) this_surf = Handle(Geom_Plane)::DownCast
6225
(geoSurf->handle());
6226
this_surf->SetPln(adapt.Plane());
6229
case GeomAbs_Cylinder:
6231
geoSurf.reset(new GeomCylinder());
6232
Handle(Geom_CylindricalSurface) this_surf = Handle(Geom_CylindricalSurface)::DownCast
6233
(geoSurf->handle());
6234
this_surf->SetCylinder(adapt.Cylinder());
6239
geoSurf.reset(new GeomCone());
6240
Handle(Geom_ConicalSurface) this_surf = Handle(Geom_ConicalSurface)::DownCast
6241
(geoSurf->handle());
6242
this_surf->SetCone(adapt.Cone());
6245
case GeomAbs_Sphere:
6247
geoSurf.reset(new GeomSphere());
6248
Handle(Geom_SphericalSurface) this_surf = Handle(Geom_SphericalSurface)::DownCast
6249
(geoSurf->handle());
6250
this_surf->SetSphere(adapt.Sphere());
6255
geoSurf.reset(new GeomToroid());
6256
Handle(Geom_ToroidalSurface) this_surf = Handle(Geom_ToroidalSurface)::DownCast
6257
(geoSurf->handle());
6258
this_surf->SetTorus(adapt.Torus());
6261
case GeomAbs_BezierSurface:
6263
geoSurf.reset(new GeomBezierSurface(adapt.Bezier()));
6266
case GeomAbs_BSplineSurface:
6268
geoSurf.reset(new GeomBSplineSurface(adapt.BSpline()));
6271
case GeomAbs_SurfaceOfRevolution:
6273
Handle(Geom_Surface) s = BRep_Tool::Surface(adapt.Face());
6274
Handle(Geom_SurfaceOfRevolution) rev = Handle(Geom_SurfaceOfRevolution)::DownCast(s);
6276
Handle(Geom_RectangularTrimmedSurface) rect = Handle(Geom_RectangularTrimmedSurface)::DownCast(s);
6277
rev = Handle(Geom_SurfaceOfRevolution)::DownCast(rect->BasisSurface());
6280
geoSurf.reset(new GeomSurfaceOfRevolution(rev));
6283
case GeomAbs_SurfaceOfExtrusion:
6285
Handle(Geom_Surface) s = BRep_Tool::Surface(adapt.Face());
6286
Handle(Geom_SurfaceOfLinearExtrusion) ext = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(s);
6288
Handle(Geom_RectangularTrimmedSurface) rect = Handle(Geom_RectangularTrimmedSurface)::DownCast(s);
6289
ext = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(rect->BasisSurface());
6292
geoSurf.reset(new GeomSurfaceOfExtrusion(ext));
6295
case GeomAbs_OffsetSurface:
6297
Handle(Geom_Surface) s = BRep_Tool::Surface(adapt.Face());
6298
Handle(Geom_OffsetSurface) off = Handle(Geom_OffsetSurface)::DownCast(s);
6300
Handle(Geom_RectangularTrimmedSurface) rect = Handle(Geom_RectangularTrimmedSurface)::DownCast(s);
6301
off = Handle(Geom_OffsetSurface)::DownCast(rect->BasisSurface());
6304
geoSurf.reset(new GeomOffsetSurface(off));
6311
if (!geoSurf && !silent) {
6312
std::string err = "Cannot convert surface type ";
6313
Handle(Geom_Surface) s = BRep_Tool::Surface(adapt.Face());
6315
err += s->DynamicType()->Name();
6318
throw Base::TypeError(err);
6325
std::unique_ptr<GeomCurve> makeFromCurve(const Handle(Geom_Curve)& c, bool silent)
6327
std::unique_ptr<GeomCurve> geoCurve;
6331
throw Base::ValueError("Null curve");
6335
if (c->IsKind(STANDARD_TYPE(Geom_Circle))) {
6336
Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast(c);
6337
geoCurve = std::make_unique<GeomCircle>(circ);
6339
else if (c->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
6340
Handle(Geom_Ellipse) ell = Handle(Geom_Ellipse)::DownCast(c);
6341
geoCurve = std::make_unique<GeomEllipse>(ell);
6343
else if (c->IsKind(STANDARD_TYPE(Geom_Hyperbola))) {
6344
Handle(Geom_Hyperbola) hyp = Handle(Geom_Hyperbola)::DownCast(c);
6345
geoCurve = std::make_unique<GeomHyperbola>(hyp);
6347
else if (c->IsKind(STANDARD_TYPE(Geom_Line))) {
6348
Handle(Geom_Line) lin = Handle(Geom_Line)::DownCast(c);
6349
geoCurve = std::make_unique<GeomLine>(lin);
6351
else if (c->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
6352
Handle(Geom_OffsetCurve) oc = Handle(Geom_OffsetCurve)::DownCast(c);
6353
geoCurve = std::make_unique<GeomOffsetCurve>(oc);
6355
else if (c->IsKind(STANDARD_TYPE(Geom_Parabola))) {
6356
Handle(Geom_Parabola) par = Handle(Geom_Parabola)::DownCast(c);
6357
geoCurve = std::make_unique<GeomParabola>(par);
6359
else if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
6360
return makeFromTrimmedCurve(c, c->FirstParameter(), c->LastParameter());
6366
else if (c->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
6367
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(c);
6368
geoCurve = std::make_unique<GeomBezierCurve>(bezier);
6370
else if (c->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
6371
Handle(Geom_BSplineCurve) bspline = Handle(Geom_BSplineCurve)::DownCast(c);
6372
geoCurve = std::make_unique<GeomBSplineCurve>(bspline);
6375
std::string err = "Unhandled curve type ";
6376
err += c->DynamicType()->Name();
6377
throw Base::TypeError(err);
6383
std::unique_ptr<GeomCurve> makeFromTrimmedCurve(const Handle(Geom_Curve)& c, double f, double l, bool silent)
6387
throw Base::ValueError("Null curve");
6388
return std::unique_ptr<GeomCurve>();
6391
if (c->IsKind(STANDARD_TYPE(Geom_Circle))) {
6392
Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast(c);
6393
std::unique_ptr<GeomCurve> arc(new GeomArcOfCircle());
6394
Handle(Geom_TrimmedCurve) this_arc = Handle(Geom_TrimmedCurve)::DownCast
6396
Handle(Geom_Circle) this_circ = Handle(Geom_Circle)::DownCast
6397
(this_arc->BasisCurve());
6398
this_circ->SetCirc(circ->Circ());
6399
this_arc->SetTrim(f, l);
6402
else if (c->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
6403
Handle(Geom_Ellipse) ellp = Handle(Geom_Ellipse)::DownCast(c);
6404
std::unique_ptr<GeomCurve> arc(new GeomArcOfEllipse());
6405
Handle(Geom_TrimmedCurve) this_arc = Handle(Geom_TrimmedCurve)::DownCast
6407
Handle(Geom_Ellipse) this_ellp = Handle(Geom_Ellipse)::DownCast
6408
(this_arc->BasisCurve());
6409
this_ellp->SetElips(ellp->Elips());
6410
this_arc->SetTrim(f, l);
6413
else if (c->IsKind(STANDARD_TYPE(Geom_Hyperbola))) {
6414
Handle(Geom_Hyperbola) hypr = Handle(Geom_Hyperbola)::DownCast(c);
6415
std::unique_ptr<GeomCurve> arc(new GeomArcOfHyperbola());
6416
Handle(Geom_TrimmedCurve) this_arc = Handle(Geom_TrimmedCurve)::DownCast
6418
Handle(Geom_Hyperbola) this_hypr = Handle(Geom_Hyperbola)::DownCast
6419
(this_arc->BasisCurve());
6420
this_hypr->SetHypr(hypr->Hypr());
6421
this_arc->SetTrim(f, l);
6424
else if (c->IsKind(STANDARD_TYPE(Geom_Line))) {
6425
Handle(Geom_Line) line = Handle(Geom_Line)::DownCast(c);
6426
std::unique_ptr<GeomCurve> segm(new GeomLineSegment());
6427
Handle(Geom_TrimmedCurve) this_segm = Handle(Geom_TrimmedCurve)::DownCast
6429
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
6430
(this_segm->BasisCurve());
6431
this_line->SetLin(line->Lin());
6432
this_segm->SetTrim(f, l);
6435
else if (c->IsKind(STANDARD_TYPE(Geom_Parabola))) {
6436
Handle(Geom_Parabola) para = Handle(Geom_Parabola)::DownCast(c);
6437
std::unique_ptr<GeomCurve> arc(new GeomArcOfParabola());
6438
Handle(Geom_TrimmedCurve) this_arc = Handle(Geom_TrimmedCurve)::DownCast
6440
Handle(Geom_Parabola) this_para = Handle(Geom_Parabola)::DownCast
6441
(this_arc->BasisCurve());
6442
this_para->SetParab(para->Parab());
6443
this_arc->SetTrim(f, l);
6446
else if (c->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
6447
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(c->Copy());
6448
bezier->Segment(f, l);
6449
return std::unique_ptr<GeomCurve>(new GeomBezierCurve(bezier));
6451
else if (c->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
6452
Handle(Geom_BSplineCurve) bspline = Handle(Geom_BSplineCurve)::DownCast(c->Copy());
6453
bspline->Segment(f, l);
6454
return std::unique_ptr<GeomCurve>(new GeomBSplineCurve(bspline));
6456
else if (c->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
6457
Handle(Geom_OffsetCurve) oc = Handle(Geom_OffsetCurve)::DownCast(c);
6458
double v = oc->Offset();
6459
gp_Dir dir = oc->Direction();
6460
std::unique_ptr<GeomCurve> bc(makeFromTrimmedCurve(oc->BasisCurve(), f, l));
6461
return std::unique_ptr<GeomCurve>(new GeomOffsetCurve(Handle(Geom_Curve)::DownCast(bc->handle()), v, dir));
6463
else if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
6464
Handle(Geom_TrimmedCurve) trc = Handle(Geom_TrimmedCurve)::DownCast(c);
6465
return makeFromTrimmedCurve(trc->BasisCurve(), f, l);
6472
std::string err = "Unhandled curve type ";
6473
err += c->DynamicType()->Name();
6474
throw Base::TypeError(err);
6477
return std::unique_ptr<GeomCurve>();
6480
std::unique_ptr<GeomCurve> makeFromCurveAdaptor(const Adaptor3d_Curve& adapt, bool silent)
6482
std::unique_ptr<GeomCurve> geoCurve;
6483
switch (adapt.GetType())
6487
geoCurve = std::make_unique<GeomLine>();
6488
Handle(Geom_Line) this_curv = Handle(Geom_Line)::DownCast
6489
(geoCurve->handle());
6490
this_curv->SetLin(adapt.Line());
6493
case GeomAbs_Circle:
6495
geoCurve = std::make_unique<GeomCircle>();
6496
Handle(Geom_Circle) this_curv = Handle(Geom_Circle)::DownCast
6497
(geoCurve->handle());
6498
this_curv->SetCirc(adapt.Circle());
6501
case GeomAbs_Ellipse:
6503
geoCurve = std::make_unique<GeomEllipse>();
6504
Handle(Geom_Ellipse) this_curv = Handle(Geom_Ellipse)::DownCast
6505
(geoCurve->handle());
6506
this_curv->SetElips(adapt.Ellipse());
6509
case GeomAbs_Hyperbola:
6511
geoCurve = std::make_unique<GeomHyperbola>();
6512
Handle(Geom_Hyperbola) this_curv = Handle(Geom_Hyperbola)::DownCast
6513
(geoCurve->handle());
6514
this_curv->SetHypr(adapt.Hyperbola());
6517
case GeomAbs_Parabola:
6519
geoCurve = std::make_unique<GeomParabola>();
6520
Handle(Geom_Parabola) this_curv = Handle(Geom_Parabola)::DownCast
6521
(geoCurve->handle());
6522
this_curv->SetParab(adapt.Parabola());
6525
case GeomAbs_BezierCurve:
6527
geoCurve = std::make_unique<GeomBezierCurve>(adapt.Bezier());
6530
case GeomAbs_BSplineCurve:
6532
geoCurve = std::make_unique<GeomBSplineCurve>(adapt.BSpline());
6535
case GeomAbs_OffsetCurve:
6537
geoCurve = std::make_unique<GeomOffsetCurve>(adapt.OffsetCurve());
6540
case GeomAbs_OtherCurve:
6547
throw Base::TypeError("Unhandled curve type");
6552
Handle(Geom_Curve) curv3d = Handle(Geom_Curve)::DownCast
6553
(geoCurve->handle());
6554
double u = curv3d->FirstParameter();
6555
double v = curv3d->LastParameter();
6556
if (u != adapt.FirstParameter() || v != adapt.LastParameter()) {
6557
geoCurve = makeFromTrimmedCurve(curv3d, adapt.FirstParameter(), adapt.LastParameter());