23
#include "PreCompiled.h"
25
# include <GC_MakeSegment.hxx>
26
# include <Geom_Line.hxx>
27
# include <Geom_TrimmedCurve.hxx>
30
#include <Base/GeometryPyCXX.h>
31
#include <Base/VectorPy.h>
33
#include "LineSegmentPy.h"
34
#include "LineSegmentPy.cpp"
41
extern const char* gce_ErrorStatusText(gce_ErrorType et);
44
std::string LineSegmentPy::representation() const
46
std::stringstream str;
47
Base::Vector3d start = getGeomLineSegmentPtr()->getStartPoint();
48
Base::Vector3d end = getGeomLineSegmentPtr()->getEndPoint();
49
str << "<Line segment ("
50
<< start.x << "," <<start.y << "," <<start.z << ") ("
51
<< end.x << "," <<end.y << "," <<end.z << ") >";
56
PyObject *LineSegmentPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
59
return new LineSegmentPy(new GeomLineSegment);
63
int LineSegmentPy::PyInit(PyObject* args, PyObject* )
65
if (PyArg_ParseTuple(args, "")) {
71
if (PyArg_ParseTuple(args, "O!", &(LineSegmentPy::Type), &pLine)) {
73
LineSegmentPy* pcLine = static_cast<LineSegmentPy*>(pLine);
75
Handle(Geom_TrimmedCurve) that_curv = Handle(Geom_TrimmedCurve)::DownCast
76
(pcLine->getGeomLineSegmentPtr()->handle());
77
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast
78
(that_curv->BasisCurve());
80
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
81
(this->getGeomLineSegmentPtr()->handle());
82
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
83
(this_curv->BasisCurve());
86
this_line->SetLin(that_line->Lin());
87
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
93
if (PyArg_ParseTuple(args, "O!dd", &(LineSegmentPy::Type), &pLine, &first, &last)) {
95
LineSegmentPy* pcLine = static_cast<LineSegmentPy*>(pLine);
97
Handle(Geom_TrimmedCurve) that_curv = Handle(Geom_TrimmedCurve)::DownCast
98
(pcLine->getGeomLineSegmentPtr()->handle());
99
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast
100
(that_curv->BasisCurve());
102
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
103
(this->getGeomLineSegmentPtr()->handle());
104
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
105
(this_curv->BasisCurve());
108
this_line->SetLin(that_line->Lin());
109
this_curv->SetTrim(first, last);
114
if (PyArg_ParseTuple(args, "O!dd", &(LinePy::Type), &pLine, &first, &last)) {
116
LinePy* pcLine = static_cast<LinePy*>(pLine);
118
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast
119
(pcLine->getGeomLinePtr()->handle());
121
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
122
(this->getGeomLineSegmentPtr()->handle());
123
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
124
(this_curv->BasisCurve());
127
this_line->SetLin(that_line->Lin());
128
this_curv->SetTrim(first, last);
134
if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &pV1,
135
&(Base::VectorPy::Type), &pV2)) {
136
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
137
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
140
double distance = Base::Distance(v1, v2);
141
if (distance < gp::Resolution())
142
Standard_Failure::Raise("Both points are equal");
143
GC_MakeSegment ms(gp_Pnt(v1.x,v1.y,v1.z),
144
gp_Pnt(v2.x,v2.y,v2.z));
146
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(ms.Status()));
151
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
152
(this->getGeomLineSegmentPtr()->handle());
153
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
154
(this_curv->BasisCurve());
155
Handle(Geom_TrimmedCurve) that_curv = ms.Value();
156
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast(that_curv->BasisCurve());
157
this_line->SetLin(that_line->Lin());
158
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
162
catch (Standard_Failure& e) {
164
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
168
PyErr_SetString(PartExceptionOCCError, "creation of line failed");
173
PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n"
174
"-- empty parameter list\n"
176
"-- LineSegment,double,double\n"
177
"-- Line,double,double\n"
182
PyObject* LineSegmentPy::setParameterRange(PyObject *args)
185
if (!PyArg_ParseTuple(args, "dd", &first, &last))
189
Handle(Geom_TrimmedCurve) this_curve = Handle(Geom_TrimmedCurve)::DownCast
190
(this->getGeomLineSegmentPtr()->handle());
191
this_curve->SetTrim(first, last);
193
catch (Standard_Failure& e) {
194
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
201
Py::Object LineSegmentPy::getStartPoint() const
203
Handle(Geom_TrimmedCurve) this_curve = Handle(Geom_TrimmedCurve)::DownCast
204
(this->getGeomLineSegmentPtr()->handle());
205
gp_Pnt pnt = this_curve->StartPoint();
206
return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
209
void LineSegmentPy::setStartPoint(Py::Object arg)
212
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
213
(this->getGeomLineSegmentPtr()->handle());
214
p2 = this_curv->EndPoint();
216
PyObject *p = arg.ptr();
217
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
218
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
223
else if (PyTuple_Check(p)) {
224
Py::Tuple tuple(arg);
225
p1.SetX((double)Py::Float(tuple.getItem(0)));
226
p1.SetY((double)Py::Float(tuple.getItem(1)));
227
p1.SetZ((double)Py::Float(tuple.getItem(2)));
230
std::string error = std::string("type must be 'Vector' or tuple, not ");
231
error += p->ob_type->tp_name;
232
throw Py::TypeError(error);
237
if (p1.Distance(p2) < gp::Resolution())
238
Standard_Failure::Raise("Both points are equal");
239
GC_MakeSegment ms(p1, p2);
241
throw Py::RuntimeError(gce_ErrorStatusText(ms.Status()));
245
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
246
(this_curv->BasisCurve());
247
Handle(Geom_TrimmedCurve) that_curv = ms.Value();
248
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast(that_curv->BasisCurve());
249
this_line->SetLin(that_line->Lin());
250
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
252
catch (Standard_Failure& e) {
253
throw Py::RuntimeError(e.GetMessageString());
257
Py::Object LineSegmentPy::getEndPoint() const
259
Handle(Geom_TrimmedCurve) this_curve = Handle(Geom_TrimmedCurve)::DownCast
260
(this->getGeomLineSegmentPtr()->handle());
261
gp_Pnt pnt = this_curve->EndPoint();
262
return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
265
void LineSegmentPy::setEndPoint(Py::Object arg)
268
Handle(Geom_TrimmedCurve) this_curv = Handle(Geom_TrimmedCurve)::DownCast
269
(this->getGeomLineSegmentPtr()->handle());
270
p1 = this_curv->StartPoint();
272
PyObject *p = arg.ptr();
273
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
274
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
279
else if (PyTuple_Check(p)) {
280
Py::Tuple tuple(arg);
281
p2.SetX((double)Py::Float(tuple.getItem(0)));
282
p2.SetY((double)Py::Float(tuple.getItem(1)));
283
p2.SetZ((double)Py::Float(tuple.getItem(2)));
286
std::string error = std::string("type must be 'Vector' or tuple, not ");
287
error += p->ob_type->tp_name;
288
throw Py::TypeError(error);
293
if (p1.Distance(p2) < gp::Resolution())
294
Standard_Failure::Raise("Both points are equal");
295
GC_MakeSegment ms(p1, p2);
297
throw Py::RuntimeError(gce_ErrorStatusText(ms.Status()));
301
Handle(Geom_Line) this_line = Handle(Geom_Line)::DownCast
302
(this_curv->BasisCurve());
303
Handle(Geom_TrimmedCurve) that_curv = ms.Value();
304
Handle(Geom_Line) that_line = Handle(Geom_Line)::DownCast(that_curv->BasisCurve());
305
this_line->SetLin(that_line->Lin());
306
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
308
catch (Standard_Failure& e) {
309
throw Py::RuntimeError(e.GetMessageString());
313
PyObject *LineSegmentPy::getCustomAttributes(const char* ) const
318
int LineSegmentPy::setCustomAttributes(const char* , PyObject* )