1
/***************************************************************************
2
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <BRepBuilderAPI_MakeEdge2d.hxx>
26
# include <BRepBuilderAPI_MakeVertex.hxx>
27
# include <Geom2dAPI_Interpolate.hxx>
28
# include <Geom2dAPI_ProjectPointOnCurve.hxx>
29
# include <Geom2dConvert.hxx>
30
# include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
31
# include <Geom2dLProp_CLProps2d.hxx>
32
# include <gce_ErrorType.hxx>
33
# include <gp_Ax22d.hxx>
34
# include <gp_Circ2d.hxx>
35
# include <gp_Elips2d.hxx>
36
# include <gp_Hypr2d.hxx>
37
# include <gp_Lin2d.hxx>
38
# include <gp_Parab2d.hxx>
39
# include <Standard_ConstructionError.hxx>
40
# include <Standard_Version.hxx>
41
# include <TColgp_Array1OfPnt2d.hxx>
42
# include <TColgp_Array1OfVec2d.hxx>
43
# include <TColgp_HArray1OfPnt2d.hxx>
44
# include <TColStd_Array1OfInteger.hxx>
45
# include <TColStd_Array1OfReal.hxx>
46
# include <TColStd_HArray1OfBoolean.hxx>
47
# include <GCE2d_MakeArcOfCircle.hxx>
48
# include <GCE2d_MakeArcOfEllipse.hxx>
49
# include <GCE2d_MakeArcOfHyperbola.hxx>
50
# include <GCE2d_MakeArcOfParabola.hxx>
51
# include <GCE2d_MakeCircle.hxx>
52
# include <GCE2d_MakeEllipse.hxx>
53
# include <GCE2d_MakeHyperbola.hxx>
54
# include <GCE2d_MakeLine.hxx>
55
# include <GCE2d_MakeParabola.hxx>
56
# include <GCE2d_MakeSegment.hxx>
57
# include <Precision.hxx>
60
#include <Base/Exception.h>
61
#include <Base/Reader.h>
62
#include <Base/Writer.h>
64
#include "Geometry2d.h"
66
#include <Geom2d/ArcOfCircle2dPy.h>
67
#include <Geom2d/ArcOfEllipse2dPy.h>
68
#include <Geom2d/ArcOfHyperbola2dPy.h>
69
#include <Geom2d/ArcOfParabola2dPy.h>
70
#include <Geom2d/BezierCurve2dPy.h>
71
#include <Geom2d/BSplineCurve2dPy.h>
72
#include <Geom2d/Circle2dPy.h>
73
#include <Geom2d/Ellipse2dPy.h>
74
#include <Geom2d/Hyperbola2dPy.h>
75
#include <Geom2d/Line2dSegmentPy.h>
76
#include <Geom2d/Line2dPy.h>
77
#include <Geom2d/OffsetCurve2dPy.h>
78
#include <Geom2d/Parabola2dPy.h>
84
extern const char* gce_ErrorStatusText(gce_ErrorType et);
87
TYPESYSTEM_SOURCE_ABSTRACT(Part::Geometry2d, Base::Persistence)
89
Geometry2d::Geometry2d() = default;
91
Geometry2d::~Geometry2d() = default;
93
unsigned int Geometry2d::getMemSize () const
95
return sizeof(Geometry2d);
98
void Geometry2d::Save(Base::Writer & /*writer*/) const
100
throw Base::NotImplementedError("Save");
103
void Geometry2d::Restore(Base::XMLReader & /*reader*/)
105
throw Base::NotImplementedError("Restore");
108
// -------------------------------------------------
110
TYPESYSTEM_SOURCE(Part::Geom2dPoint, Part::Geometry2d)
112
Geom2dPoint::Geom2dPoint()
114
this->myPoint = new Geom2d_CartesianPoint(0,0);
117
Geom2dPoint::Geom2dPoint(const Handle(Geom2d_CartesianPoint)& p)
119
this->myPoint = Handle(Geom2d_CartesianPoint)::DownCast(p->Copy());
122
Geom2dPoint::Geom2dPoint(const Base::Vector2d& p)
124
this->myPoint = new Geom2d_CartesianPoint(p.x,p.y);
127
Geom2dPoint::~Geom2dPoint() = default;
129
TopoDS_Shape Geom2dPoint::toShape() const
131
Handle(Geom2d_CartesianPoint) c = Handle(Geom2d_CartesianPoint)::DownCast(handle());
132
gp_Pnt2d xy = c->Pnt2d();
136
BRepBuilderAPI_MakeVertex mkBuilder(pnt);
137
return mkBuilder.Shape();
140
const Handle(Geom2d_Geometry)& Geom2dPoint::handle() const
145
Geometry2d *Geom2dPoint::clone() const
147
Geom2dPoint *newPoint = new Geom2dPoint(myPoint);
151
Base::Vector2d Geom2dPoint::getPoint()const
153
return {myPoint->X(),myPoint->Y()};
156
void Geom2dPoint::setPoint(const Base::Vector2d& p)
158
this->myPoint->SetCoord(p.x,p.y);
161
unsigned int Geom2dPoint::getMemSize () const
163
return sizeof(Geom2d_CartesianPoint);
166
void Geom2dPoint::Save(Base::Writer &writer) const
168
// save the attributes of the father class
169
Geometry2d::Save(writer);
171
Base::Vector2d Point = getPoint();
175
<< "X=\"" << Point.x << "\" "
176
<< "Y=\"" << Point.y << "\" "
177
<< "/>" << std::endl;
180
void Geom2dPoint::Restore(Base::XMLReader &reader)
182
// read the attributes of the father class
183
Geometry2d::Restore(reader);
187
reader.readElement("Geom2dPoint");
188
// get the value of my Attribute
189
X = reader.getAttributeAsFloat("X");
190
Y = reader.getAttributeAsFloat("Y");
192
// set the read geometry
193
setPoint(Base::Vector2d(X,Y));
196
PyObject *Geom2dPoint::getPyObject()
198
Handle(Geom2d_CartesianPoint) c = Handle(Geom2d_CartesianPoint)::DownCast(handle());
199
gp_Pnt2d xy = c->Pnt2d();
202
tuple.setItem(0, Py::Float(xy.X()));
203
tuple.setItem(1, Py::Float(xy.Y()));
204
return Py::new_reference_to(tuple);
207
// -------------------------------------------------
209
TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dCurve, Part::Geometry2d)
211
Geom2dCurve::Geom2dCurve() = default;
213
Geom2dCurve::~Geom2dCurve() = default;
215
TopoDS_Shape Geom2dCurve::toShape() const
217
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
218
BRepBuilderAPI_MakeEdge2d mkBuilder(c);
219
return mkBuilder.Shape();
222
bool Geom2dCurve::tangent(double u, gp_Dir2d& dir) const
224
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
225
Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion());
226
if (prop.IsTangentDefined()) {
234
Base::Vector2d Geom2dCurve::pointAtParameter(double u) const
236
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
237
Geom2dLProp_CLProps2d prop(c,u,0,Precision::Confusion());
239
const gp_Pnt2d &point=prop.Value();
240
return {point.X(),point.Y()};
243
Base::Vector2d Geom2dCurve::firstDerivativeAtParameter(double u) const
245
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
246
Geom2dLProp_CLProps2d prop(c,u,1,Precision::Confusion());
248
const gp_Vec2d &vec=prop.D1();
249
return {vec.X(),vec.Y()};
252
Base::Vector2d Geom2dCurve::secondDerivativeAtParameter(double u) const
254
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
255
Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion());
257
const gp_Vec2d &vec=prop.D2();
258
return {vec.X(),vec.Y()};
261
bool Geom2dCurve::normal(double u, gp_Dir2d& dir) const
263
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
264
Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion());
265
if (prop.IsTangentDefined()) {
273
bool Geom2dCurve::closestParameter(const Base::Vector2d& point, double &u) const
275
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
278
gp_Pnt2d pnt(point.x,point.y);
279
Geom2dAPI_ProjectPointOnCurve ppc(pnt, c);
280
u = ppc.LowerDistanceParameter();
284
catch (Standard_Failure& e) {
286
std::cout << e.GetMessageString() << std::endl;
293
bool Geom2dCurve::closestParameterToBasicCurve(const Base::Vector2d& point, double &u) const
295
Handle(Geom2d_Curve) c = Handle(Geom2d_Curve)::DownCast(handle());
297
if (c->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))){
298
Handle(Geom2d_TrimmedCurve) tc = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
299
Handle(Geom2d_Curve) bc = tc->BasisCurve();
302
gp_Pnt2d pnt(point.x,point.y);
303
Geom2dAPI_ProjectPointOnCurve ppc(pnt, bc);
304
u = ppc.LowerDistanceParameter();
308
catch (Standard_Failure& e) {
310
std::cout << e.GetMessageString() << std::endl;
318
return this->closestParameter(point, u);
322
// -------------------------------------------------
324
TYPESYSTEM_SOURCE(Part::Geom2dBezierCurve, Part::Geom2dCurve)
326
Geom2dBezierCurve::Geom2dBezierCurve()
328
TColgp_Array1OfPnt2d poles(1,2);
329
poles(1) = gp_Pnt2d(0.0,0.0);
330
poles(2) = gp_Pnt2d(0.0,1.0);
331
Handle(Geom2d_BezierCurve) b = new Geom2d_BezierCurve(poles);
335
Geom2dBezierCurve::Geom2dBezierCurve(const Handle(Geom2d_BezierCurve)& b)
337
this->myCurve = Handle(Geom2d_BezierCurve)::DownCast(b->Copy());
340
Geom2dBezierCurve::~Geom2dBezierCurve() = default;
342
void Geom2dBezierCurve::setHandle(const Handle(Geom2d_BezierCurve)& c)
344
myCurve = Handle(Geom2d_BezierCurve)::DownCast(c->Copy());
347
const Handle(Geom2d_Geometry)& Geom2dBezierCurve::handle() const
352
Geometry2d *Geom2dBezierCurve::clone() const
354
Geom2dBezierCurve *newCurve = new Geom2dBezierCurve(myCurve);
358
unsigned int Geom2dBezierCurve::getMemSize () const
360
throw Base::NotImplementedError("Geom2dBezierCurve::getMemSize");
363
void Geom2dBezierCurve::Save(Base::Writer &/*writer*/) const
365
throw Base::NotImplementedError("Geom2dBezierCurve::Save");
368
void Geom2dBezierCurve::Restore(Base::XMLReader &/*reader*/)
370
throw Base::NotImplementedError("Geom2dBezierCurve::Restore");
373
PyObject *Geom2dBezierCurve::getPyObject()
375
return new BezierCurve2dPy(static_cast<Geom2dBezierCurve*>(this->clone()));
378
// -------------------------------------------------
380
TYPESYSTEM_SOURCE(Part::Geom2dBSplineCurve, Part::Geom2dCurve)
382
Geom2dBSplineCurve::Geom2dBSplineCurve()
384
TColgp_Array1OfPnt2d poles(1,2);
385
poles(1) = gp_Pnt2d(0.0,0.0);
386
poles(2) = gp_Pnt2d(1.0,0.0);
388
TColStd_Array1OfReal knots(1,2);
392
TColStd_Array1OfInteger mults(1,2);
396
this->myCurve = new Geom2d_BSplineCurve(poles, knots, mults, 1);
399
Geom2dBSplineCurve::Geom2dBSplineCurve(const Handle(Geom2d_BSplineCurve)& b)
401
this->myCurve = Handle(Geom2d_BSplineCurve)::DownCast(b->Copy());
404
Geom2dBSplineCurve::~Geom2dBSplineCurve() = default;
406
void Geom2dBSplineCurve::setHandle(const Handle(Geom2d_BSplineCurve)& c)
408
myCurve = Handle(Geom2d_BSplineCurve)::DownCast(c->Copy());
411
const Handle(Geom2d_Geometry)& Geom2dBSplineCurve::handle() const
416
Geometry2d *Geom2dBSplineCurve::clone() const
418
Geom2dBSplineCurve *newCurve = new Geom2dBSplineCurve(myCurve);
422
int Geom2dBSplineCurve::countPoles() const
424
return myCurve->NbPoles();
427
void Geom2dBSplineCurve::setPole(int index, const Base::Vector2d& pole, double weight)
430
gp_Pnt2d pnt(pole.x,pole.y);
432
myCurve->SetPole(index+1,pnt);
434
myCurve->SetPole(index+1,pnt,weight);
436
catch (Standard_Failure& e) {
438
std::cout << e.GetMessageString() << std::endl;
442
std::vector<Base::Vector2d> Geom2dBSplineCurve::getPoles() const
444
std::vector<Base::Vector2d> poles;
445
poles.reserve(myCurve->NbPoles());
446
TColgp_Array1OfPnt2d p(1,myCurve->NbPoles());
449
for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
450
const gp_Pnt2d& pnt = p(i);
451
poles.emplace_back(pnt.X(), pnt.Y());
456
bool Geom2dBSplineCurve::join(const Handle(Geom2d_BSplineCurve)& spline)
458
Geom2dConvert_CompCurveToBSplineCurve ccbc(this->myCurve);
459
if (!ccbc.Add(spline, Precision::Approximation()))
461
this->myCurve = ccbc.BSplineCurve();
465
void Geom2dBSplineCurve::interpolate(const std::vector<gp_Pnt2d>& p,
466
const std::vector<gp_Vec2d>& t)
469
Standard_ConstructionError::Raise();
470
if (p.size() != t.size())
471
Standard_ConstructionError::Raise();
473
double tol3d = Precision::Approximation();
474
Handle(TColgp_HArray1OfPnt2d) pts = new TColgp_HArray1OfPnt2d(1, p.size());
475
for (std::size_t i=0; i<p.size(); i++) {
476
pts->SetValue(i+1, p[i]);
479
TColgp_Array1OfVec2d tgs(1, t.size());
480
Handle(TColStd_HArray1OfBoolean) fgs = new TColStd_HArray1OfBoolean(1, t.size());
481
for (std::size_t i=0; i<p.size(); i++) {
482
tgs.SetValue(i+1, t[i]);
483
fgs->SetValue(i+1, Standard_True);
486
Geom2dAPI_Interpolate interpolate(pts, Standard_False, tol3d);
487
interpolate.Load(tgs, fgs);
488
interpolate.Perform();
489
this->myCurve = interpolate.Curve();
492
void Geom2dBSplineCurve::getCardinalSplineTangents(const std::vector<gp_Pnt2d>& p,
493
const std::vector<double>& c,
494
std::vector<gp_Vec2d>& t) const
496
// https://de.wikipedia.org/wiki/Kubisch_Hermitescher_Spline#Cardinal_Spline
498
Standard_ConstructionError::Raise();
499
if (p.size() != c.size())
500
Standard_ConstructionError::Raise();
504
t[0] = gp_Vec2d(p[0], p[1]);
505
t[1] = gp_Vec2d(p[0], p[1]);
508
std::size_t e = p.size() - 1;
510
for (std::size_t i = 1; i < e; i++) {
511
gp_Vec2d v = gp_Vec2d(p[i-1], p[i+1]);
512
double f = 0.5 * (1-c[i]);
518
t[t.size()-1] = t[t.size()-2];
522
void Geom2dBSplineCurve::getCardinalSplineTangents(const std::vector<gp_Pnt2d>& p, double c,
523
std::vector<gp_Vec2d>& t) const
525
// https://de.wikipedia.org/wiki/Kubisch_Hermitescher_Spline#Cardinal_Spline
527
Standard_ConstructionError::Raise();
531
t[0] = gp_Vec2d(p[0], p[1]);
532
t[1] = gp_Vec2d(p[0], p[1]);
535
std::size_t e = p.size() - 1;
536
double f = 0.5 * (1-c);
538
for (std::size_t i = 1; i < e; i++) {
539
gp_Vec2d v = gp_Vec2d(p[i-1], p[i+1]);
545
t[t.size()-1] = t[t.size()-2];
549
void Geom2dBSplineCurve::makeC1Continuous(double tol)
551
Geom2dConvert::C0BSplineToC1BSplineCurve(this->myCurve, tol);
554
std::list<Geometry2d*> Geom2dBSplineCurve::toBiArcs(double /*tolerance*/) const
556
Standard_Failure::Raise("Not yet implemented");
560
unsigned int Geom2dBSplineCurve::getMemSize() const
562
throw Base::NotImplementedError("Geom2dBSplineCurve::getMemSize");
565
void Geom2dBSplineCurve::Save(Base::Writer &/*writer*/) const
567
throw Base::NotImplementedError("Geom2dBSplineCurve::Save");
570
void Geom2dBSplineCurve::Restore(Base::XMLReader &/*reader*/)
572
throw Base::NotImplementedError("Geom2dBSplineCurve::Restore");
575
PyObject *Geom2dBSplineCurve::getPyObject()
577
return new BSplineCurve2dPy(static_cast<Geom2dBSplineCurve*>(this->clone()));
580
// -------------------------------------------------
582
TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dConic, Part::Geom2dCurve)
584
Geom2dConic::Geom2dConic() = default;
586
Geom2dConic::~Geom2dConic() = default;
588
Base::Vector2d Geom2dConic::getLocation() const
590
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(handle());
591
const gp_Pnt2d& loc = conic->Location();
592
return {loc.X(),loc.Y()};
595
void Geom2dConic::setLocation(const Base::Vector2d& Center)
597
gp_Pnt2d p1(Center.x,Center.y);
598
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(handle());
601
conic->SetLocation(p1);
603
catch (Standard_Failure& e) {
604
throw Base::CADKernelError(e.GetMessageString());
608
bool Geom2dConic::isReversed() const
610
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(handle());
611
gp_Dir2d xdir = conic->XAxis().Direction();
612
gp_Dir2d ydir = conic->YAxis().Direction();
614
Base::Vector3d xd(xdir.X(), xdir.Y(), 0);
615
Base::Vector3d yd(ydir.X(), ydir.Y(), 0);
616
Base::Vector3d zd = xd.Cross(yd);
620
void Geom2dConic::SaveAxis(Base::Writer& writer, const gp_Ax22d& axis) const
622
gp_Pnt2d center = axis.Location();
623
gp_Dir2d xdir = axis.XDirection();
624
gp_Dir2d ydir = axis.YDirection();
626
<< "CenterX=\"" << center.X() << "\" "
627
<< "CenterY=\"" << center.Y() << "\" "
628
<< "XAxisX=\"" << xdir.X() << "\" "
629
<< "XAxisY=\"" << xdir.Y() << "\" "
630
<< "YAxisX=\"" << ydir.X() << "\" "
631
<< "YAxisY=\"" << ydir.Y() << "\" ";
634
void Geom2dConic::RestoreAxis(Base::XMLReader& reader, gp_Ax22d& axis)
636
double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY;
637
CenterX = reader.getAttributeAsFloat("CenterX");
638
CenterY = reader.getAttributeAsFloat("CenterY");
639
XdirX = reader.getAttributeAsFloat("XAxisX");
640
XdirY = reader.getAttributeAsFloat("XAxisY");
641
YdirX = reader.getAttributeAsFloat("YAxisX");
642
YdirY = reader.getAttributeAsFloat("YAxisY");
644
// set the read geometry
645
gp_Pnt2d p1(CenterX,CenterY);
646
gp_Dir2d xdir(XdirX,XdirY);
647
gp_Dir2d ydir(YdirX,YdirY);
648
axis.SetLocation(p1);
649
axis.SetXDirection(xdir);
650
axis.SetYDirection(ydir);
653
// -------------------------------------------------
655
TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dArcOfConic, Part::Geom2dCurve)
657
Geom2dArcOfConic::Geom2dArcOfConic() = default;
659
Geom2dArcOfConic::~Geom2dArcOfConic() = default;
661
Base::Vector2d Geom2dArcOfConic::getLocation() const
663
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
664
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
665
const gp_Pnt2d& loc = conic->Location();
666
return {loc.X(),loc.Y()};
669
void Geom2dArcOfConic::setLocation(const Base::Vector2d& Center)
671
gp_Pnt2d p1(Center.x,Center.y);
672
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
673
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
676
conic->SetLocation(p1);
678
catch (Standard_Failure& e) {
679
throw Base::CADKernelError(e.GetMessageString());
683
bool Geom2dArcOfConic::isReversed() const
685
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
686
Handle(Geom2d_Conic) conic = Handle(Geom2d_Conic)::DownCast(curve->BasisCurve());
687
gp_Dir2d xdir = conic->XAxis().Direction();
688
gp_Dir2d ydir = conic->YAxis().Direction();
690
Base::Vector3d xd(xdir.X(), xdir.Y(), 0);
691
Base::Vector3d yd(ydir.X(), ydir.Y(), 0);
692
Base::Vector3d zd = xd.Cross(yd);
697
* \brief Geom2dArcOfConic::getStartPoint
698
* \return XY of the arc's starting point.
700
Base::Vector2d Geom2dArcOfConic::getStartPoint() const
702
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
703
gp_Pnt2d pnt = curve->StartPoint();
704
return {pnt.X(), pnt.Y()};
708
* \brief Geom2dArcOfConic::getEndPoint
709
* \return XY of the arc's ending point.
711
Base::Vector2d Geom2dArcOfConic::getEndPoint() const
713
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
714
gp_Pnt2d pnt = curve->EndPoint();
715
return {pnt.X(), pnt.Y()};
719
* \brief Geom2dArcOfConic::getRange
720
* \param u [out] start angle of the arc, in radians.
721
* \param v [out] end angle of the arc, in radians.
723
void Geom2dArcOfConic::getRange(double& u, double& v) const
725
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
726
u = curve->FirstParameter();
727
v = curve->LastParameter();
731
* \brief Geom2dArcOfConic::setRange
732
* \param u [in] start angle of the arc, in radians.
733
* \param v [in] end angle of the arc, in radians.
735
void Geom2dArcOfConic::setRange(double u, double v)
738
Handle(Geom2d_TrimmedCurve) curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
739
curve->SetTrim(u, v);
741
catch (Standard_Failure& e) {
742
throw Base::CADKernelError(e.GetMessageString());
746
void Geom2dArcOfConic::SaveAxis(Base::Writer& writer, const gp_Ax22d& axis, double u, double v) const
748
gp_Pnt2d center = axis.Location();
749
gp_Dir2d xdir = axis.XDirection();
750
gp_Dir2d ydir = axis.YDirection();
752
<< "CenterX=\"" << center.X() << "\" "
753
<< "CenterY=\"" << center.Y() << "\" "
754
<< "XAxisX=\"" << xdir.X() << "\" "
755
<< "XAxisY=\"" << xdir.Y() << "\" "
756
<< "YAxisX=\"" << ydir.X() << "\" "
757
<< "YAxisY=\"" << ydir.Y() << "\" "
758
<< "FirstParameter=\"" << u << "\" "
759
<< "LastParameter=\"" << v << "\" ";
762
void Geom2dArcOfConic::RestoreAxis(Base::XMLReader& reader, gp_Ax22d& axis, double& u, double &v)
764
double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY;
765
CenterX = reader.getAttributeAsFloat("CenterX");
766
CenterY = reader.getAttributeAsFloat("CenterY");
767
XdirX = reader.getAttributeAsFloat("XAxisX");
768
XdirY = reader.getAttributeAsFloat("XAxisY");
769
YdirX = reader.getAttributeAsFloat("YAxisX");
770
YdirY = reader.getAttributeAsFloat("YAxisY");
771
u = reader.getAttributeAsFloat("FirstParameter");
772
v = reader.getAttributeAsFloat("LastParameter");
774
// set the read geometry
775
gp_Pnt2d p1(CenterX,CenterY);
776
gp_Dir2d xdir(XdirX,XdirY);
777
gp_Dir2d ydir(YdirX,YdirY);
778
axis.SetLocation(p1);
779
axis.SetXDirection(xdir);
780
axis.SetYDirection(ydir);
783
// -------------------------------------------------
785
TYPESYSTEM_SOURCE(Part::Geom2dCircle, Part::Geom2dConic)
787
Geom2dCircle::Geom2dCircle()
789
Handle(Geom2d_Circle) c = new Geom2d_Circle(gp_Circ2d());
793
Geom2dCircle::Geom2dCircle(const Handle(Geom2d_Circle)& c)
795
this->myCurve = Handle(Geom2d_Circle)::DownCast(c->Copy());
798
Geom2dCircle::~Geom2dCircle() = default;
800
const Handle(Geom2d_Geometry)& Geom2dCircle::handle() const
805
Geometry2d *Geom2dCircle::clone() const
807
Geom2dCircle *newCirc = new Geom2dCircle(myCurve);
811
double Geom2dCircle::getRadius() const
813
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(handle());
814
return circle->Radius();
817
void Geom2dCircle::setRadius(double Radius)
819
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(handle());
822
gp_Circ2d c = circle->Circ2d();
824
circle->SetCirc2d(c);
826
catch (Standard_Failure& e) {
827
throw Base::CADKernelError(e.GetMessageString());
831
unsigned int Geom2dCircle::getMemSize () const
833
return sizeof(Geom2d_Circle);
836
void Geom2dCircle::Save(Base::Writer& writer) const
838
// save the attributes of the father class
839
Geom2dCurve::Save(writer);
841
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(handle());
842
gp_Circ2d c = circle->Circ2d();
843
gp_Ax22d axis = c.Axis();
848
SaveAxis(writer, axis);
850
<< "Radius=\"" << c.Radius() << "\" "
851
<< "/>" << std::endl;
854
void Geom2dCircle::Restore(Base::XMLReader& reader)
856
// read the attributes of the father class
857
Geom2dCurve::Restore(reader);
862
reader.readElement("Geom2dCircle");
863
// get the value of my Attribute
864
RestoreAxis(reader, axis);
865
Radius = reader.getAttributeAsFloat("Radius");
868
GCE2d_MakeCircle mc(axis, Radius);
870
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
872
this->myCurve = mc.Value();
874
catch (Standard_Failure& e) {
875
throw Base::CADKernelError(e.GetMessageString());
879
PyObject *Geom2dCircle::getPyObject()
881
return new Circle2dPy(static_cast<Geom2dCircle*>(this->clone()));
885
Find the centerpoint of a circle drawn through any 3 points:
887
Given points p1-3, draw 2 lines: S12 and S23 which each connect two points. From the
888
midpoint of each line, draw a perpendicular line (S12p/S23p) across the circle. These
889
lines will cross at the centerpoint.
891
Mathematically, line S12 will have a slope of m12 which can be determined. Therefore,
892
the slope m12p is -1/m12. Line S12p will have an equation of y = m12p*x + b12p. b12p can
893
be solved for using the midpoint of the line. This can be done for both lines. Since
894
both S12p and S23p cross at the centerpoint, solving the two equations together will give
895
the location of the centerpoint.
897
Base::Vector2d Geom2dCircle::getCircleCenter (const Base::Vector2d &p1, const Base::Vector2d &p2, const Base::Vector2d &p3)
899
Base::Vector2d u = p2-p1;
900
Base::Vector2d v = p3-p2;
901
Base::Vector2d w = p1-p3;
907
double eps2 = Precision::SquareConfusion();
908
if (uu < eps2 || vv < eps2 || ww < eps2)
909
THROWM(Base::ValueError,"Two points are coincident");
915
double w0 = (2 * sqrt(abs(uu * ww - uw * uw)) * uw / (uu * ww));
916
double w1 = (2 * sqrt(abs(uu * vv - uv * uv)) * uv / (uu * vv));
917
double w2 = (2 * sqrt(abs(vv * ww - vw * vw)) * vw / (vv * ww));
919
double wx = w0 + w1 + w2;
921
if (abs(wx) < Precision::Confusion())
922
THROWM(Base::ValueError,"Points are collinear");
924
double x = (w0*p1.x + w1*p2.x + w2*p3.x)/wx;
925
double y = (w0*p1.y + w1*p2.y + w2*p3.y)/wx;
930
// -------------------------------------------------
932
TYPESYSTEM_SOURCE(Part::Geom2dArcOfCircle, Part::Geom2dArcOfConic)
934
Geom2dArcOfCircle::Geom2dArcOfCircle()
936
Handle(Geom2d_Circle) c = new Geom2d_Circle(gp_Circ2d());
937
this->myCurve = new Geom2d_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
940
Geom2dArcOfCircle::Geom2dArcOfCircle(const Handle(Geom2d_Circle)& c)
942
this->myCurve = new Geom2d_TrimmedCurve(c, c->FirstParameter(),c->LastParameter());
945
Geom2dArcOfCircle::~Geom2dArcOfCircle() = default;
947
void Geom2dArcOfCircle::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
949
Handle(Geom2d_Circle) basis = Handle(Geom2d_Circle)::DownCast(c->BasisCurve());
951
Standard_Failure::Raise("Basis curve is not a circle");
952
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
955
const Handle(Geom2d_Geometry)& Geom2dArcOfCircle::handle() const
960
Geometry2d *Geom2dArcOfCircle::clone() const
962
Geom2dArcOfCircle* copy = new Geom2dArcOfCircle();
963
copy->setHandle(this->myCurve);
967
double Geom2dArcOfCircle::getRadius() const
969
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(myCurve->BasisCurve());
970
return circle->Radius();
973
void Geom2dArcOfCircle::setRadius(double Radius)
975
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(myCurve->BasisCurve());
978
gp_Circ2d c = circle->Circ2d();
980
circle->SetCirc2d(c);
982
catch (Standard_Failure& e) {
983
throw Base::CADKernelError(e.GetMessageString());
987
unsigned int Geom2dArcOfCircle::getMemSize () const
989
return sizeof(Geom2d_Circle) + 2 *sizeof(double);
992
void Geom2dArcOfCircle::Save(Base::Writer &writer) const
994
// save the attributes of the father class
995
Geom2dCurve::Save(writer);
997
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(this->myCurve->BasisCurve());
999
gp_Circ2d c = circle->Circ2d();
1000
gp_Ax22d axis = c.Axis();
1001
double u = this->myCurve->FirstParameter();
1002
double v = this->myCurve->LastParameter();
1006
<< "<Geom2dArcOfCircle ";
1007
SaveAxis(writer, axis, u, v);
1009
<< "Radius=\"" << c.Radius() << "\" "
1010
<< "/>" << std::endl;
1013
void Geom2dArcOfCircle::Restore(Base::XMLReader &reader)
1015
// read the attributes of the father class
1016
Geom2dCurve::Restore(reader);
1021
reader.readElement("Geom2dArcOfCircle");
1022
// get the value of my Attribute
1023
RestoreAxis(reader, axis, u, v);
1024
Radius = reader.getAttributeAsFloat("Radius");
1027
GCE2d_MakeCircle mc(axis, Radius);
1029
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1030
GCE2d_MakeArcOfCircle ma(mc.Value()->Circ2d(), u, v);
1032
throw Base::CADKernelError(gce_ErrorStatusText(ma.Status()));
1034
Handle(Geom2d_TrimmedCurve) tmpcurve = ma.Value();
1035
Handle(Geom2d_Circle) tmpcircle = Handle(Geom2d_Circle)::DownCast(tmpcurve->BasisCurve());
1036
Handle(Geom2d_Circle) circle = Handle(Geom2d_Circle)::DownCast(this->myCurve->BasisCurve());
1038
circle->SetCirc2d(tmpcircle->Circ2d());
1039
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
1041
catch (Standard_Failure& e) {
1042
throw Base::CADKernelError(e.GetMessageString());
1046
PyObject *Geom2dArcOfCircle::getPyObject()
1048
return new ArcOfCircle2dPy(static_cast<Geom2dArcOfCircle*>(this->clone()));
1051
// -------------------------------------------------
1053
TYPESYSTEM_SOURCE(Part::Geom2dEllipse, Part::Geom2dConic)
1055
Geom2dEllipse::Geom2dEllipse()
1057
Handle(Geom2d_Ellipse) e = new Geom2d_Ellipse(gp_Elips2d());
1061
Geom2dEllipse::Geom2dEllipse(const Handle(Geom2d_Ellipse)& e)
1063
this->myCurve = Handle(Geom2d_Ellipse)::DownCast(e->Copy());
1066
Geom2dEllipse::~Geom2dEllipse() = default;
1068
const Handle(Geom2d_Geometry)& Geom2dEllipse::handle() const
1073
Geometry2d *Geom2dEllipse::clone() const
1075
Geom2dEllipse *newEllipse = new Geom2dEllipse(myCurve);
1079
double Geom2dEllipse::getMajorRadius() const
1081
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(handle());
1082
return ellipse->MajorRadius();
1085
void Geom2dEllipse::setMajorRadius(double Radius)
1087
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(handle());
1090
ellipse->SetMajorRadius(Radius);
1092
catch (Standard_Failure& e) {
1093
throw Base::CADKernelError(e.GetMessageString());
1097
double Geom2dEllipse::getMinorRadius() const
1099
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(handle());
1100
return ellipse->MinorRadius();
1103
void Geom2dEllipse::setMinorRadius(double Radius)
1105
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(handle());
1108
ellipse->SetMinorRadius(Radius);
1110
catch (Standard_Failure& e) {
1111
throw Base::CADKernelError(e.GetMessageString());
1116
* \brief Geom2dEllipse::getMajorAxisDir
1117
* \return the direction vector (unit-length) of major axis of the ellipse. The
1118
* direction also points to the first focus.
1120
Base::Vector2d Geom2dEllipse::getMajorAxisDir() const
1122
gp_Dir2d xdir = myCurve->XAxis().Direction();
1123
return {xdir.X(), xdir.Y()};
1127
* \brief Geom2dEllipse::setMajorAxisDir Rotates the ellipse in its plane, so
1128
* that its major axis is as close as possible to the provided direction.
1129
* \param newdir [in] is the new direction. If the vector is small, the
1130
* orientation of the ellipse will be preserved. If the vector is not small,
1131
* but its projection onto plane of the ellipse is small, an exception will be
1134
void Geom2dEllipse::setMajorAxisDir(Base::Vector2d newdir)
1136
if (newdir.Length() < Precision::Confusion())
1137
return;//zero vector was passed. Keep the old orientation.
1139
gp_Elips2d e = myCurve->Elips2d();
1140
gp_Ax22d pos = e.Axis();
1141
pos.SetXDirection(gp_Dir2d(newdir.x, newdir.y));
1143
myCurve->SetElips2d(e);
1145
catch (Standard_Failure& e) {
1146
throw Base::CADKernelError(e.GetMessageString());
1150
unsigned int Geom2dEllipse::getMemSize () const
1152
return sizeof(Geom2d_Ellipse);
1155
void Geom2dEllipse::Save(Base::Writer& writer) const
1157
// save the attributes of the father class
1158
Geom2dCurve::Save(writer);
1160
gp_Elips2d e = this->myCurve->Elips2d();
1161
gp_Ax22d axis = e.Axis();
1165
<< "<Geom2dEllipse ";
1166
SaveAxis(writer, axis);
1168
<< "MajorRadius=\"" << e.MajorRadius() << "\" "
1169
<< "MinorRadius=\"" << e.MinorRadius() << "\" "
1170
<< "/>" << std::endl;
1173
void Geom2dEllipse::Restore(Base::XMLReader& reader)
1175
// read the attributes of the father class
1176
Geom2dCurve::Restore(reader);
1178
double MajorRadius,MinorRadius;
1181
reader.readElement("Geom2dEllipse");
1182
// get the value of my Attribute
1183
RestoreAxis(reader, axis);
1184
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
1185
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
1188
GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius);
1190
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1192
this->myCurve = mc.Value();
1194
catch (Standard_Failure& e) {
1195
throw Base::CADKernelError(e.GetMessageString());
1199
PyObject *Geom2dEllipse::getPyObject()
1201
return new Ellipse2dPy(static_cast<Geom2dEllipse*>(this->clone()));
1204
void Geom2dEllipse::setHandle(const Handle(Geom2d_Ellipse) &e)
1206
this->myCurve = Handle(Geom2d_Ellipse)::DownCast(e->Copy());
1209
// -------------------------------------------------
1211
TYPESYSTEM_SOURCE(Part::Geom2dArcOfEllipse, Part::Geom2dArcOfConic)
1213
Geom2dArcOfEllipse::Geom2dArcOfEllipse()
1215
Handle(Geom2d_Ellipse) e = new Geom2d_Ellipse(gp_Elips2d());
1216
this->myCurve = new Geom2d_TrimmedCurve(e, e->FirstParameter(),e->LastParameter());
1219
Geom2dArcOfEllipse::Geom2dArcOfEllipse(const Handle(Geom2d_Ellipse)& e)
1221
this->myCurve = new Geom2d_TrimmedCurve(e, e->FirstParameter(),e->LastParameter());
1224
Geom2dArcOfEllipse::~Geom2dArcOfEllipse() = default;
1226
void Geom2dArcOfEllipse::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
1228
Handle(Geom2d_Ellipse) basis = Handle(Geom2d_Ellipse)::DownCast(c->BasisCurve());
1230
Standard_Failure::Raise("Basis curve is not an ellipse");
1231
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
1234
const Handle(Geom2d_Geometry)& Geom2dArcOfEllipse::handle() const
1239
Geometry2d *Geom2dArcOfEllipse::clone() const
1241
Geom2dArcOfEllipse* copy = new Geom2dArcOfEllipse();
1242
copy->setHandle(this->myCurve);
1246
double Geom2dArcOfEllipse::getMajorRadius() const
1248
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1249
return ellipse->MajorRadius();
1252
void Geom2dArcOfEllipse::setMajorRadius(double Radius)
1254
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1257
ellipse->SetMajorRadius(Radius);
1259
catch (Standard_Failure& e) {
1260
throw Base::CADKernelError(e.GetMessageString());
1264
double Geom2dArcOfEllipse::getMinorRadius() const
1266
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1267
return ellipse->MinorRadius();
1270
void Geom2dArcOfEllipse::setMinorRadius(double Radius)
1272
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1275
ellipse->SetMinorRadius(Radius);
1277
catch (Standard_Failure& e) {
1278
throw Base::CADKernelError(e.GetMessageString());
1283
* \brief Geom2dArcOfEllipse::getMajorAxisDir
1284
* \return the direction vector (unit-length) of major axis of the ellipse. The
1285
* direction also points to the first focus.
1287
Base::Vector2d Geom2dArcOfEllipse::getMajorAxisDir() const
1289
Handle(Geom2d_Ellipse) c = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1290
assert(!c.IsNull());
1291
gp_Dir2d xdir = c->XAxis().Direction();
1292
return {xdir.X(), xdir.Y()};
1296
* \brief Geom2dArcOfEllipse::setMajorAxisDir Rotates the ellipse in its plane, so
1297
* that its major axis is as close as possible to the provided direction.
1298
* \param newdir [in] is the new direction. If the vector is small, the
1299
* orientation of the ellipse will be preserved. If the vector is not small,
1300
* but its projection onto plane of the ellipse is small, an exception will be
1303
void Geom2dArcOfEllipse::setMajorAxisDir(Base::Vector2d newdir)
1305
Handle(Geom2d_Ellipse) c = Handle(Geom2d_Ellipse)::DownCast(myCurve->BasisCurve());
1306
assert(!c.IsNull());
1307
if (newdir.Length() < Precision::Confusion())
1308
return;//zero vector was passed. Keep the old orientation.
1310
gp_Elips2d e = c->Elips2d();
1311
gp_Ax22d pos = e.Axis();
1312
pos.SetXDirection(gp_Dir2d(newdir.x, newdir.y));
1316
catch (Standard_Failure& e) {
1317
throw Base::CADKernelError(e.GetMessageString());
1321
unsigned int Geom2dArcOfEllipse::getMemSize () const
1323
return sizeof(Geom2d_Ellipse) + 2 *sizeof(double);
1326
void Geom2dArcOfEllipse::Save(Base::Writer &writer) const
1328
// save the attributes of the father class
1329
Geom2dCurve::Save(writer);
1331
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(this->myCurve->BasisCurve());
1333
gp_Elips2d e = ellipse->Elips2d();
1334
gp_Ax22d axis = e.Axis();
1335
double u = this->myCurve->FirstParameter();
1336
double v = this->myCurve->LastParameter();
1340
<< "<Geom2dArcOfEllipse ";
1341
SaveAxis(writer, axis, u, v);
1343
<< "MajorRadius=\"" << e.MajorRadius() << "\" "
1344
<< "MinorRadius=\"" << e.MinorRadius() << "\" "
1345
<< "/>" << std::endl;
1348
void Geom2dArcOfEllipse::Restore(Base::XMLReader &reader)
1350
// read the attributes of the father class
1351
Geom2dCurve::Restore(reader);
1353
double MajorRadius,MinorRadius,u,v;
1356
reader.readElement("Geom2dArcOfEllipse");
1357
// get the value of my Attribute
1358
RestoreAxis(reader, axis, u, v);
1359
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
1360
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
1363
GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius);
1365
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1367
GCE2d_MakeArcOfEllipse ma(mc.Value()->Elips2d(), u, v);
1369
throw Base::CADKernelError(gce_ErrorStatusText(ma.Status()));
1371
Handle(Geom2d_TrimmedCurve) tmpcurve = ma.Value();
1372
Handle(Geom2d_Ellipse) tmpellipse = Handle(Geom2d_Ellipse)::DownCast(tmpcurve->BasisCurve());
1373
Handle(Geom2d_Ellipse) ellipse = Handle(Geom2d_Ellipse)::DownCast(this->myCurve->BasisCurve());
1375
ellipse->SetElips2d(tmpellipse->Elips2d());
1376
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
1378
catch (Standard_Failure& e) {
1379
throw Base::CADKernelError(e.GetMessageString());
1383
PyObject *Geom2dArcOfEllipse::getPyObject()
1385
return new ArcOfEllipse2dPy(static_cast<Geom2dArcOfEllipse*>(this->clone()));
1388
// -------------------------------------------------
1390
TYPESYSTEM_SOURCE(Part::Geom2dHyperbola, Part::Geom2dConic)
1392
Geom2dHyperbola::Geom2dHyperbola()
1394
Handle(Geom2d_Hyperbola) h = new Geom2d_Hyperbola(gp_Hypr2d());
1398
Geom2dHyperbola::Geom2dHyperbola(const Handle(Geom2d_Hyperbola)& h)
1400
this->myCurve = Handle(Geom2d_Hyperbola)::DownCast(h->Copy());
1403
Geom2dHyperbola::~Geom2dHyperbola() = default;
1405
const Handle(Geom2d_Geometry)& Geom2dHyperbola::handle() const
1410
Geometry2d *Geom2dHyperbola::clone() const
1412
Geom2dHyperbola *newHyp = new Geom2dHyperbola(myCurve);
1416
double Geom2dHyperbola::getMajorRadius() const
1418
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(handle());
1419
return h->MajorRadius();
1422
void Geom2dHyperbola::setMajorRadius(double Radius)
1424
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(handle());
1427
h->SetMajorRadius(Radius);
1429
catch (Standard_Failure& e) {
1430
throw Base::CADKernelError(e.GetMessageString());
1434
double Geom2dHyperbola::getMinorRadius() const
1436
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(handle());
1437
return h->MinorRadius();
1440
void Geom2dHyperbola::setMinorRadius(double Radius)
1442
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(handle());
1445
h->SetMinorRadius(Radius);
1447
catch (Standard_Failure& e) {
1448
throw Base::CADKernelError(e.GetMessageString());
1452
unsigned int Geom2dHyperbola::getMemSize () const
1454
return sizeof(Geom2d_Hyperbola);
1457
void Geom2dHyperbola::Save(Base::Writer& writer) const
1459
// save the attributes of the father class
1460
Geom2dCurve::Save(writer);
1462
gp_Hypr2d h = this->myCurve->Hypr2d();
1463
gp_Ax22d axis = h.Axis();
1467
<< "<Geom2dHyperbola ";
1468
SaveAxis(writer, axis);
1470
<< "MajorRadius=\"" << h.MajorRadius() << "\" "
1471
<< "MinorRadius=\"" << h.MinorRadius() << "\" "
1472
<< "/>" << std::endl;
1475
void Geom2dHyperbola::Restore(Base::XMLReader& reader)
1477
// read the attributes of the father class
1478
Geom2dCurve::Restore(reader);
1480
double MajorRadius,MinorRadius;
1483
reader.readElement("Geom2dHyperbola");
1484
// get the value of my Attribute
1485
RestoreAxis(reader, axis);
1486
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
1487
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
1490
GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius);
1492
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1494
this->myCurve = mc.Value();
1496
catch (Standard_Failure& e) {
1497
throw Base::CADKernelError(e.GetMessageString());
1501
PyObject *Geom2dHyperbola::getPyObject()
1503
return new Hyperbola2dPy(static_cast<Geom2dHyperbola*>(this->clone()));
1506
// -------------------------------------------------
1508
TYPESYSTEM_SOURCE(Part::Geom2dArcOfHyperbola, Part::Geom2dArcOfConic)
1510
Geom2dArcOfHyperbola::Geom2dArcOfHyperbola()
1512
Handle(Geom2d_Hyperbola) h = new Geom2d_Hyperbola(gp_Hypr2d());
1513
this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
1516
Geom2dArcOfHyperbola::Geom2dArcOfHyperbola(const Handle(Geom2d_Hyperbola)& h)
1518
this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
1521
Geom2dArcOfHyperbola::~Geom2dArcOfHyperbola() = default;
1523
void Geom2dArcOfHyperbola::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
1525
Handle(Geom2d_Hyperbola) basis = Handle(Geom2d_Hyperbola)::DownCast(c->BasisCurve());
1527
Standard_Failure::Raise("Basis curve is not an hyperbola");
1528
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
1531
const Handle(Geom2d_Geometry)& Geom2dArcOfHyperbola::handle() const
1536
Geometry2d *Geom2dArcOfHyperbola::clone() const
1538
Geom2dArcOfHyperbola* copy = new Geom2dArcOfHyperbola();
1539
copy->setHandle(this->myCurve);
1543
double Geom2dArcOfHyperbola::getMajorRadius() const
1545
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(myCurve->BasisCurve());
1546
return h->MajorRadius();
1549
void Geom2dArcOfHyperbola::setMajorRadius(double Radius)
1551
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(myCurve->BasisCurve());
1554
h->SetMajorRadius(Radius);
1556
catch (Standard_Failure& e) {
1557
throw Base::CADKernelError(e.GetMessageString());
1561
double Geom2dArcOfHyperbola::getMinorRadius() const
1563
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(myCurve->BasisCurve());
1564
return h->MinorRadius();
1567
void Geom2dArcOfHyperbola::setMinorRadius(double Radius)
1569
Handle(Geom2d_Hyperbola) h = Handle(Geom2d_Hyperbola)::DownCast(myCurve->BasisCurve());
1572
h->SetMinorRadius(Radius);
1574
catch (Standard_Failure& e) {
1575
throw Base::CADKernelError(e.GetMessageString());
1579
unsigned int Geom2dArcOfHyperbola::getMemSize () const
1581
return sizeof(Geom2d_Hyperbola) + 2 *sizeof(double);
1584
void Geom2dArcOfHyperbola::Save(Base::Writer &writer) const
1586
// save the attributes of the father class
1587
Geom2dCurve::Save(writer);
1589
Handle(Geom2d_Hyperbola) hh = Handle(Geom2d_Hyperbola)::DownCast(this->myCurve->BasisCurve());
1591
gp_Hypr2d h = hh->Hypr2d();
1592
gp_Ax22d axis = h.Axis();
1593
double u = this->myCurve->FirstParameter();
1594
double v = this->myCurve->LastParameter();
1598
<< "<Geom2dHyperbola ";
1599
SaveAxis(writer, axis, u, v);
1601
<< "MajorRadius=\"" << h.MajorRadius() << "\" "
1602
<< "MinorRadius=\"" << h.MinorRadius() << "\" "
1603
<< "/>" << std::endl;
1606
void Geom2dArcOfHyperbola::Restore(Base::XMLReader &reader)
1608
// read the attributes of the father class
1609
Geom2dCurve::Restore(reader);
1611
double MajorRadius,MinorRadius,u,v;
1614
reader.readElement("Geom2dHyperbola");
1615
// get the value of my Attribute
1616
RestoreAxis(reader, axis, u, v);
1617
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
1618
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
1621
GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius);
1623
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1625
GCE2d_MakeArcOfHyperbola ma(mc.Value()->Hypr2d(), u, v);
1627
throw Base::CADKernelError(gce_ErrorStatusText(ma.Status()));
1629
Handle(Geom2d_TrimmedCurve) tmpcurve = ma.Value();
1630
Handle(Geom2d_Hyperbola) tmphyperbola = Handle(Geom2d_Hyperbola)::DownCast(tmpcurve->BasisCurve());
1631
Handle(Geom2d_Hyperbola) hyperbola = Handle(Geom2d_Hyperbola)::DownCast(this->myCurve->BasisCurve());
1633
hyperbola->SetHypr2d(tmphyperbola->Hypr2d());
1634
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
1636
catch (Standard_Failure& e) {
1637
throw Base::CADKernelError(e.GetMessageString());
1641
PyObject *Geom2dArcOfHyperbola::getPyObject()
1643
return new ArcOfHyperbola2dPy(static_cast<Geom2dArcOfHyperbola*>(this->clone()));
1646
// -------------------------------------------------
1648
TYPESYSTEM_SOURCE(Part::Geom2dParabola, Part::Geom2dConic)
1650
Geom2dParabola::Geom2dParabola()
1652
Handle(Geom2d_Parabola) p = new Geom2d_Parabola(gp_Parab2d());
1656
Geom2dParabola::Geom2dParabola(const Handle(Geom2d_Parabola)& p)
1658
this->myCurve = Handle(Geom2d_Parabola)::DownCast(p->Copy());
1661
Geom2dParabola::~Geom2dParabola() = default;
1663
const Handle(Geom2d_Geometry)& Geom2dParabola::handle() const
1668
Geometry2d *Geom2dParabola::clone() const
1670
Geom2dParabola *newPar = new Geom2dParabola(myCurve);
1674
double Geom2dParabola::getFocal() const
1676
Handle(Geom2d_Parabola) p = Handle(Geom2d_Parabola)::DownCast(handle());
1680
void Geom2dParabola::setFocal(double length)
1682
Handle(Geom2d_Parabola) p = Handle(Geom2d_Parabola)::DownCast(handle());
1685
p->SetFocal(length);
1687
catch (Standard_Failure& e) {
1688
throw Base::CADKernelError(e.GetMessageString());
1692
unsigned int Geom2dParabola::getMemSize () const
1694
return sizeof(Geom2d_Parabola);
1697
void Geom2dParabola::Save(Base::Writer& writer) const
1699
// save the attributes of the father class
1700
Geom2dCurve::Save(writer);
1702
gp_Parab2d p = this->myCurve->Parab2d();
1703
gp_Ax22d axis = p.Axis();
1704
double focal = p.Focal();
1708
<< "<Geom2dParabola ";
1709
SaveAxis(writer, axis);
1711
<< "Focal=\"" << focal << "\" "
1712
<< "/>" << std::endl;
1715
void Geom2dParabola::Restore(Base::XMLReader& reader)
1717
// read the attributes of the father class
1718
Geom2dCurve::Restore(reader);
1722
reader.readElement("Geom2dParabola");
1724
// get the value of my Attribute
1725
RestoreAxis(reader, axis);
1726
Focal = reader.getAttributeAsFloat("Focal");
1729
GCE2d_MakeParabola mc(axis, Focal);
1731
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1733
this->myCurve = mc.Value();
1735
catch (Standard_Failure& e) {
1736
throw Base::CADKernelError(e.GetMessageString());
1740
PyObject *Geom2dParabola::getPyObject()
1742
return new Parabola2dPy(static_cast<Geom2dParabola*>(this->clone()));
1745
// -------------------------------------------------
1747
TYPESYSTEM_SOURCE(Part::Geom2dArcOfParabola, Part::Geom2dArcOfConic)
1749
Geom2dArcOfParabola::Geom2dArcOfParabola()
1751
Handle(Geom2d_Parabola) p = new Geom2d_Parabola(gp_Parab2d());
1752
this->myCurve = new Geom2d_TrimmedCurve(p, p->FirstParameter(),p->LastParameter());
1755
Geom2dArcOfParabola::Geom2dArcOfParabola(const Handle(Geom2d_Parabola)& h)
1757
this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
1760
Geom2dArcOfParabola::~Geom2dArcOfParabola() = default;
1762
void Geom2dArcOfParabola::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
1764
Handle(Geom2d_Parabola) basis = Handle(Geom2d_Parabola)::DownCast(c->BasisCurve());
1766
Standard_Failure::Raise("Basis curve is not a parabola");
1767
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
1770
const Handle(Geom2d_Geometry)& Geom2dArcOfParabola::handle() const
1775
Geometry2d *Geom2dArcOfParabola::clone() const
1777
Geom2dArcOfParabola* copy = new Geom2dArcOfParabola();
1778
copy->setHandle(this->myCurve);
1782
double Geom2dArcOfParabola::getFocal() const
1784
Handle(Geom2d_Parabola) p = Handle(Geom2d_Parabola)::DownCast(myCurve->BasisCurve());
1788
void Geom2dArcOfParabola::setFocal(double length)
1790
Handle(Geom2d_Parabola) p = Handle(Geom2d_Parabola)::DownCast(myCurve->BasisCurve());
1793
p->SetFocal(length);
1795
catch (Standard_Failure& e) {
1796
throw Base::CADKernelError(e.GetMessageString());
1800
unsigned int Geom2dArcOfParabola::getMemSize () const
1802
return sizeof(Geom2d_Parabola) + 2 *sizeof(double);
1805
void Geom2dArcOfParabola::Save(Base::Writer &writer) const
1807
// save the attributes of the father class
1808
Geom2dCurve::Save(writer);
1810
Handle(Geom2d_Parabola) hp = Handle(Geom2d_Parabola)::DownCast(this->myCurve->BasisCurve());
1811
gp_Parab2d p = hp->Parab2d();
1812
gp_Ax22d axis = p.Axis();
1813
double u = this->myCurve->FirstParameter();
1814
double v = this->myCurve->LastParameter();
1815
double focal = p.Focal();
1819
<< "<Geom2dArcOfParabola ";
1820
SaveAxis(writer, axis, u, v);
1822
<< "Focal=\"" << focal << "\" "
1823
<< "/>" << std::endl;
1826
void Geom2dArcOfParabola::Restore(Base::XMLReader &reader)
1828
// read the attributes of the father class
1829
Geom2dCurve::Restore(reader);
1834
reader.readElement("Geom2dParabola");
1835
// get the value of my Attribute
1836
RestoreAxis(reader, axis, u, v);
1837
Focal = reader.getAttributeAsFloat("Focal");
1840
GCE2d_MakeParabola mc(axis, Focal);
1842
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1844
GCE2d_MakeArcOfParabola ma(mc.Value()->Parab2d(), u, v);
1846
throw Base::CADKernelError(gce_ErrorStatusText(ma.Status()));
1848
Handle(Geom2d_TrimmedCurve) tmpcurve = ma.Value();
1849
Handle(Geom2d_Parabola) tmpparabola = Handle(Geom2d_Parabola)::DownCast(tmpcurve->BasisCurve());
1850
Handle(Geom2d_Parabola) parabola = Handle(Geom2d_Parabola)::DownCast(this->myCurve->BasisCurve());
1852
parabola->SetParab2d(tmpparabola->Parab2d());
1853
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
1855
catch (Standard_Failure& e) {
1856
throw Base::CADKernelError(e.GetMessageString());
1860
PyObject *Geom2dArcOfParabola::getPyObject()
1862
return new ArcOfParabola2dPy(static_cast<Geom2dArcOfParabola*>(this->clone()));
1865
// -------------------------------------------------
1867
TYPESYSTEM_SOURCE(Part::Geom2dLine, Part::Geom2dCurve)
1869
Geom2dLine::Geom2dLine()
1871
Handle(Geom2d_Line) c = new Geom2d_Line(gp_Lin2d());
1875
Geom2dLine::Geom2dLine(const Handle(Geom2d_Line)& l)
1877
this->myCurve = Handle(Geom2d_Line)::DownCast(l->Copy());
1880
Geom2dLine::Geom2dLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir)
1882
this->myCurve = new Geom2d_Line(gp_Pnt2d(Pos.x,Pos.y),gp_Dir2d(Dir.x,Dir.y));
1885
Geom2dLine::~Geom2dLine() = default;
1887
void Geom2dLine::setLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir)
1889
this->myCurve->SetLocation(gp_Pnt2d(Pos.x,Pos.y));
1890
this->myCurve->SetDirection(gp_Dir2d(Dir.x,Dir.y));
1893
Base::Vector2d Geom2dLine::getPos() const
1895
gp_Pnt2d Pos = this->myCurve->Lin2d().Location();
1896
return {Pos.X(),Pos.Y()};
1899
Base::Vector2d Geom2dLine::getDir() const
1901
gp_Dir2d Dir = this->myCurve->Lin2d().Direction();
1902
return {Dir.X(),Dir.Y()};
1905
const Handle(Geom2d_Geometry)& Geom2dLine::handle() const
1910
Geometry2d *Geom2dLine::clone() const
1912
Geom2dLine *newLine = new Geom2dLine(myCurve);
1916
unsigned int Geom2dLine::getMemSize () const
1918
return sizeof(Geom2d_Line);
1921
void Geom2dLine::Save(Base::Writer &writer) const
1923
// save the attributes of the father class
1924
Geometry2d::Save(writer);
1926
Base::Vector2d Pos = getPos();
1927
Base::Vector2d Dir = getDir();
1932
<< "PosX=\"" << Pos.x << "\" "
1933
<< "PosY=\"" << Pos.y << "\" "
1934
<< "DirX=\"" << Dir.x << "\" "
1935
<< "DirY=\"" << Dir.y << "\" "
1936
<< "/>" << std::endl;
1939
void Geom2dLine::Restore(Base::XMLReader &reader)
1941
// read the attributes of the father class
1942
Geom2dCurve::Restore(reader);
1944
double PosX,PosY,DirX,DirY;
1946
reader.readElement("Geom2dLine");
1947
// get the value of my Attribute
1948
PosX = reader.getAttributeAsFloat("PosX");
1949
PosY = reader.getAttributeAsFloat("PosY");
1950
DirX = reader.getAttributeAsFloat("DirX");
1951
DirY = reader.getAttributeAsFloat("DirY");
1952
gp_Pnt2d pnt(PosX, PosY);
1953
gp_Dir2d dir(DirX, DirY);
1956
GCE2d_MakeLine mc(pnt, dir);
1958
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
1960
this->myCurve = mc.Value();
1962
catch (Standard_Failure& e) {
1963
throw Base::CADKernelError(e.GetMessageString());
1967
PyObject *Geom2dLine::getPyObject()
1969
return new Line2dPy(static_cast<Geom2dLine*>(this->clone()));
1972
// -------------------------------------------------
1974
TYPESYSTEM_SOURCE(Part::Geom2dLineSegment, Part::Geom2dCurve)
1976
Geom2dLineSegment::Geom2dLineSegment()
1979
line.SetLocation(gp_Pnt2d(0.0,0.0));
1980
line.SetDirection(gp_Dir2d(0.0,1.0));
1981
Handle(Geom2d_Line) c = new Geom2d_Line(line);
1982
this->myCurve = new Geom2d_TrimmedCurve(c, 0.0,1.0);
1985
Geom2dLineSegment::~Geom2dLineSegment() = default;
1987
void Geom2dLineSegment::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
1989
Handle(Geom2d_Line) basis = Handle(Geom2d_Line)::DownCast(c->BasisCurve());
1991
Standard_Failure::Raise("Basis curve is not a line");
1992
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
1995
const Handle(Geom2d_Geometry)& Geom2dLineSegment::handle() const
2000
Geometry2d *Geom2dLineSegment::clone()const
2002
Geom2dLineSegment *tempCurve = new Geom2dLineSegment();
2003
tempCurve->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(myCurve->Copy());
2007
Base::Vector2d Geom2dLineSegment::getStartPoint() const
2009
Handle(Geom2d_TrimmedCurve) this_curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
2010
gp_Pnt2d pnt = this_curve->StartPoint();
2011
return {pnt.X(), pnt.Y()};
2014
Base::Vector2d Geom2dLineSegment::getEndPoint() const
2016
Handle(Geom2d_TrimmedCurve) this_curve = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
2017
gp_Pnt2d pnt = this_curve->EndPoint();
2018
return {pnt.X(), pnt.Y()};
2021
void Geom2dLineSegment::setPoints(const Base::Vector2d& Start, const Base::Vector2d& End)
2023
gp_Pnt2d p1(Start.x,Start.y), p2(End.x,End.y);
2024
Handle(Geom2d_TrimmedCurve) this_curv = Handle(Geom2d_TrimmedCurve)::DownCast(handle());
2027
// Create line out of two points
2028
if (p1.Distance(p2) < gp::Resolution())
2029
Standard_Failure::Raise("Both points are equal");
2030
GCE2d_MakeSegment ms(p1, p2);
2032
throw Base::CADKernelError(gce_ErrorStatusText(ms.Status()));
2035
// get Geom_Line of line segment
2036
Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast
2037
(this_curv->BasisCurve());
2038
Handle(Geom2d_TrimmedCurve) that_curv = ms.Value();
2039
Handle(Geom2d_Line) that_line = Handle(Geom2d_Line)::DownCast(that_curv->BasisCurve());
2040
this_line->SetLin2d(that_line->Lin2d());
2041
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
2043
catch (Standard_Failure& e) {
2044
throw Base::CADKernelError(e.GetMessageString());
2048
unsigned int Geom2dLineSegment::getMemSize () const
2050
return sizeof(Geom2d_TrimmedCurve) + sizeof(Geom2d_Line);
2053
void Geom2dLineSegment::Save(Base::Writer &writer) const
2055
// save the attributes of the father class
2056
Geom2dCurve::Save(writer);
2058
Base::Vector2d End = getEndPoint();
2059
Base::Vector2d Start = getStartPoint();
2063
<< "<Geom2dLineSegment "
2064
<< "StartX=\"" << Start.x << "\" "
2065
<< "StartY=\"" << Start.y << "\" "
2066
<< "EndX=\"" << End.x << "\" "
2067
<< "EndY=\"" << End.y << "\" "
2068
<< "/>" << std::endl;
2071
void Geom2dLineSegment::Restore(Base::XMLReader &reader)
2073
// read the attributes of the father class
2074
Geom2dCurve::Restore(reader);
2076
double StartX,StartY,EndX,EndY;
2078
reader.readElement("Geom2dLineSegment");
2079
// get the value of my Attribute
2080
StartX = reader.getAttributeAsFloat("StartX");
2081
StartY = reader.getAttributeAsFloat("StartY");
2082
EndX = reader.getAttributeAsFloat("EndX");
2083
EndY = reader.getAttributeAsFloat("EndY");
2085
gp_Pnt2d p1(StartX, StartY);
2086
gp_Pnt2d p2(EndX, EndY);
2089
GCE2d_MakeSegment mc(p1, p2);
2091
throw Base::CADKernelError(gce_ErrorStatusText(mc.Status()));
2093
this->myCurve = mc.Value();
2095
catch (Standard_Failure& e) {
2096
throw Base::CADKernelError(e.GetMessageString());
2100
PyObject *Geom2dLineSegment::getPyObject()
2102
return new Line2dSegmentPy(static_cast<Geom2dLineSegment*>(this->clone()));
2105
// -------------------------------------------------
2107
TYPESYSTEM_SOURCE(Part::Geom2dOffsetCurve, Part::Geom2dCurve)
2109
Geom2dOffsetCurve::Geom2dOffsetCurve() = default;
2111
Geom2dOffsetCurve::Geom2dOffsetCurve(const Handle(Geom2d_Curve)& c, double offset)
2113
this->myCurve = new Geom2d_OffsetCurve(c, offset);
2116
Geom2dOffsetCurve::Geom2dOffsetCurve(const Handle(Geom2d_OffsetCurve)& c)
2118
this->myCurve = Handle(Geom2d_OffsetCurve)::DownCast(c->Copy());
2121
Geom2dOffsetCurve::~Geom2dOffsetCurve() = default;
2123
Geometry2d *Geom2dOffsetCurve::clone() const
2125
Geom2dOffsetCurve *newCurve = new Geom2dOffsetCurve(myCurve);
2129
void Geom2dOffsetCurve::setHandle(const Handle(Geom2d_OffsetCurve)& c)
2131
this->myCurve = Handle(Geom2d_OffsetCurve)::DownCast(c->Copy());
2134
const Handle(Geom2d_Geometry)& Geom2dOffsetCurve::handle() const
2136
return this->myCurve;
2139
unsigned int Geom2dOffsetCurve::getMemSize () const
2141
throw Base::NotImplementedError("Geom2dOffsetCurve::getMemSize");
2144
void Geom2dOffsetCurve::Save(Base::Writer &/*writer*/) const
2146
throw Base::NotImplementedError("Geom2dOffsetCurve::Save");
2149
void Geom2dOffsetCurve::Restore(Base::XMLReader &/*reader*/)
2151
throw Base::NotImplementedError("Geom2dOffsetCurve::Restore");
2154
PyObject *Geom2dOffsetCurve::getPyObject()
2156
return new OffsetCurve2dPy(static_cast<Geom2dOffsetCurve*>(this->clone()));
2159
// -------------------------------------------------
2161
TYPESYSTEM_SOURCE(Part::Geom2dTrimmedCurve, Part::Geom2dCurve)
2163
Geom2dTrimmedCurve::Geom2dTrimmedCurve() = default;
2165
Geom2dTrimmedCurve::Geom2dTrimmedCurve(const Handle(Geom2d_TrimmedCurve)& c)
2167
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
2170
Geom2dTrimmedCurve::~Geom2dTrimmedCurve() = default;
2172
void Geom2dTrimmedCurve::setHandle(const Handle(Geom2d_TrimmedCurve)& c)
2174
this->myCurve = Handle(Geom2d_TrimmedCurve)::DownCast(c->Copy());
2177
const Handle(Geom2d_Geometry)& Geom2dTrimmedCurve::handle() const
2182
Geometry2d *Geom2dTrimmedCurve::clone() const
2184
Geom2dTrimmedCurve *newCurve = new Geom2dTrimmedCurve(myCurve);
2188
unsigned int Geom2dTrimmedCurve::getMemSize () const
2190
throw Base::NotImplementedError("Geom2dTrimmedCurve::getMemSize");
2193
void Geom2dTrimmedCurve::Save(Base::Writer &/*writer*/) const
2195
throw Base::NotImplementedError("Geom2dTrimmedCurve::Save");
2198
void Geom2dTrimmedCurve::Restore(Base::XMLReader &/*reader*/)
2200
throw Base::NotImplementedError("Geom2dTrimmedCurve::Restore");
2203
PyObject *Geom2dTrimmedCurve::getPyObject()
2205
Handle(Geom2d_Curve) basis = this->myCurve->BasisCurve();
2208
if (basis->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
2209
Geom2dArcOfParabola c;
2210
c.setHandle(this->myCurve);
2211
return c.getPyObject();
2213
if (basis->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
2214
Geom2dArcOfHyperbola c;
2215
c.setHandle(this->myCurve);
2216
return c.getPyObject();
2218
if (basis->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
2219
Geom2dArcOfEllipse c;
2220
c.setHandle(this->myCurve);
2221
return c.getPyObject();
2223
if (basis->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
2224
Geom2dArcOfCircle c;
2225
c.setHandle(this->myCurve);
2226
return c.getPyObject();
2228
if (basis->IsKind(STANDARD_TYPE (Geom2d_Line))) {
2229
Geom2dLineSegment c;
2230
c.setHandle(this->myCurve);
2231
return c.getPyObject();
2233
if (basis->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
2234
Geom2dBSplineCurve c;
2235
c.setHandle(Handle(Geom2d_BSplineCurve)::DownCast(basis));
2236
return c.getPyObject();
2238
if (basis->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
2239
Geom2dBezierCurve c;
2240
c.setHandle(Handle(Geom2d_BezierCurve)::DownCast(basis));
2241
return c.getPyObject();
2244
PyErr_SetString(PyExc_RuntimeError, "Unknown curve type");
2248
// ------------------------------------------------------------------
2251
std::unique_ptr<Geom2dCurve> makeFromCurve2d(Handle(Geom2d_Curve) curve)
2253
std::unique_ptr<Geom2dCurve> geo2d;
2256
if (curve->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
2257
geo2d = std::make_unique<Geom2dParabola>(Handle(Geom2d_Parabola)::DownCast(curve));
2259
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
2260
geo2d = std::make_unique<Geom2dHyperbola>(Handle(Geom2d_Hyperbola)::DownCast(curve));
2262
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
2263
geo2d = std::make_unique<Geom2dEllipse>(Handle(Geom2d_Ellipse)::DownCast(curve));
2265
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
2266
geo2d = std::make_unique<Geom2dCircle>(Handle(Geom2d_Circle)::DownCast(curve));
2268
else if (curve->IsKind(STANDARD_TYPE (Geom2d_Line))) {
2269
geo2d = std::make_unique<Geom2dLine>(Handle(Geom2d_Line)::DownCast(curve));
2271
else if (curve->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
2272
geo2d = std::make_unique<Geom2dBSplineCurve>(Handle(Geom2d_BSplineCurve)::DownCast(curve));
2274
else if (curve->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
2275
geo2d = std::make_unique<Geom2dBezierCurve>(Handle(Geom2d_BezierCurve)::DownCast(curve));
2277
else if (curve->IsKind(STANDARD_TYPE (Geom2d_TrimmedCurve))) {
2278
geo2d = std::make_unique<Geom2dTrimmedCurve>(Handle(Geom2d_TrimmedCurve)::DownCast(curve));
2284
std::unique_ptr<Geom2dCurve> makeFromTrimmedCurve2d(const Handle(Geom2d_Curve)& c, double f, double l)
2286
if (c->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
2287
Handle(Geom2d_Circle) circ = Handle(Geom2d_Circle)::DownCast(c);
2288
std::unique_ptr<Geom2dCurve> arc(new Geom2dArcOfCircle());
2290
Handle(Geom2d_TrimmedCurve) this_arc = Handle(Geom2d_TrimmedCurve)::DownCast
2292
Handle(Geom2d_Circle) this_circ = Handle(Geom2d_Circle)::DownCast
2293
(this_arc->BasisCurve());
2294
this_circ->SetCirc2d(circ->Circ2d());
2295
this_arc->SetTrim(f, l);
2298
else if (c->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
2299
Handle(Geom2d_Ellipse) ellp = Handle(Geom2d_Ellipse)::DownCast(c);
2300
std::unique_ptr<Geom2dCurve> arc(new Geom2dArcOfEllipse());
2302
Handle(Geom2d_TrimmedCurve) this_arc = Handle(Geom2d_TrimmedCurve)::DownCast
2304
Handle(Geom2d_Ellipse) this_ellp = Handle(Geom2d_Ellipse)::DownCast
2305
(this_arc->BasisCurve());
2306
this_ellp->SetElips2d(ellp->Elips2d());
2307
this_arc->SetTrim(f, l);
2310
else if (c->IsKind(STANDARD_TYPE(Geom2d_Hyperbola))) {
2311
Handle(Geom2d_Hyperbola) hypr = Handle(Geom2d_Hyperbola)::DownCast(c);
2312
std::unique_ptr<Geom2dCurve> arc(new Geom2dArcOfHyperbola());
2314
Handle(Geom2d_TrimmedCurve) this_arc = Handle(Geom2d_TrimmedCurve)::DownCast
2316
Handle(Geom2d_Hyperbola) this_hypr = Handle(Geom2d_Hyperbola)::DownCast
2317
(this_arc->BasisCurve());
2318
this_hypr->SetHypr2d(hypr->Hypr2d());
2319
this_arc->SetTrim(f, l);
2322
else if (c->IsKind(STANDARD_TYPE(Geom2d_Line))) {
2323
Handle(Geom2d_Line) line = Handle(Geom2d_Line)::DownCast(c);
2324
std::unique_ptr<Geom2dCurve> segm(new Geom2dLineSegment());
2326
Handle(Geom2d_TrimmedCurve) this_segm = Handle(Geom2d_TrimmedCurve)::DownCast
2328
Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast
2329
(this_segm->BasisCurve());
2330
this_line->SetLin2d(line->Lin2d());
2331
this_segm->SetTrim(f, l);
2334
else if (c->IsKind(STANDARD_TYPE(Geom2d_Parabola))) {
2335
Handle(Geom2d_Parabola) para = Handle(Geom2d_Parabola)::DownCast(c);
2336
std::unique_ptr<Geom2dCurve> arc(new Geom2dArcOfParabola());
2338
Handle(Geom2d_TrimmedCurve) this_arc = Handle(Geom2d_TrimmedCurve)::DownCast
2340
Handle(Geom2d_Parabola) this_para = Handle(Geom2d_Parabola)::DownCast
2341
(this_arc->BasisCurve());
2342
this_para->SetParab2d(para->Parab2d());
2343
this_arc->SetTrim(f, l);
2346
else if (c->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
2347
Handle(Geom2d_BezierCurve) bezier = Handle(Geom2d_BezierCurve)::DownCast(c->Copy());
2348
bezier->Segment(f, l);
2349
return std::unique_ptr<Geom2dCurve>(new Geom2dBezierCurve(bezier));
2351
else if (c->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
2352
Handle(Geom2d_BSplineCurve) bspline = Handle(Geom2d_BSplineCurve)::DownCast(c->Copy());
2353
bspline->Segment(f, l);
2354
return std::unique_ptr<Geom2dCurve>(new Geom2dBSplineCurve(bspline));
2356
else if (c->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) {
2357
Handle(Geom2d_OffsetCurve) oc = Handle(Geom2d_OffsetCurve)::DownCast(c);
2358
double v = oc->Offset();
2359
std::unique_ptr<Geom2dCurve> bc(makeFromTrimmedCurve2d(oc->BasisCurve(), f, l));
2360
return std::unique_ptr<Geom2dCurve>(new Geom2dOffsetCurve(Handle(Geom2d_Curve)::DownCast(bc->handle()), v));
2362
else if (c->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
2363
Handle(Geom2d_TrimmedCurve) trc = Handle(Geom2d_TrimmedCurve)::DownCast(c);
2364
return makeFromTrimmedCurve2d(trc->BasisCurve(), f, l);
2367
std::string err = "Unhandled curve type ";
2368
err += c->DynamicType()->Name();
2369
throw Base::TypeError(err);
2372
std::unique_ptr<Geom2dCurve> makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& adapt)
2374
std::unique_ptr<Geom2dCurve> geoCurve;
2375
switch (adapt.GetType())
2379
geoCurve = std::make_unique<Geom2dLine>();
2380
Handle(Geom2d_Line) this_curv = Handle(Geom2d_Line)::DownCast
2381
(geoCurve->handle());
2382
this_curv->SetLin2d(adapt.Line());
2385
case GeomAbs_Circle:
2387
geoCurve = std::make_unique<Geom2dCircle>();
2388
Handle(Geom2d_Circle) this_curv = Handle(Geom2d_Circle)::DownCast
2389
(geoCurve->handle());
2390
this_curv->SetCirc2d(adapt.Circle());
2393
case GeomAbs_Ellipse:
2395
geoCurve = std::make_unique<Geom2dEllipse>();
2396
Handle(Geom2d_Ellipse) this_curv = Handle(Geom2d_Ellipse)::DownCast
2397
(geoCurve->handle());
2398
this_curv->SetElips2d(adapt.Ellipse());
2401
case GeomAbs_Hyperbola:
2403
geoCurve = std::make_unique<Geom2dHyperbola>();
2404
Handle(Geom2d_Hyperbola) this_curv = Handle(Geom2d_Hyperbola)::DownCast
2405
(geoCurve->handle());
2406
this_curv->SetHypr2d(adapt.Hyperbola());
2409
case GeomAbs_Parabola:
2411
geoCurve = std::make_unique<Geom2dParabola>();
2412
Handle(Geom2d_Parabola) this_curv = Handle(Geom2d_Parabola)::DownCast
2413
(geoCurve->handle());
2414
this_curv->SetParab2d(adapt.Parabola());
2417
case GeomAbs_BezierCurve:
2419
geoCurve = std::make_unique<Geom2dBezierCurve>(adapt.Bezier());
2422
case GeomAbs_BSplineCurve:
2424
geoCurve = std::make_unique<Geom2dBSplineCurve>(adapt.BSpline());
2427
case GeomAbs_OtherCurve:
2433
throw Base::TypeError("Unhandled curve type");
2435
// Check if the curve must be trimmed
2436
Handle(Geom2d_Curve) curv2d = Handle(Geom2d_Curve)::DownCast
2437
(geoCurve->handle());
2438
double u = curv2d->FirstParameter();
2439
double v = curv2d->LastParameter();
2440
if (u != adapt.FirstParameter() || v != adapt.LastParameter()) {
2441
geoCurve = makeFromTrimmedCurve2d(curv2d, adapt.FirstParameter(), adapt.LastParameter());