add class LineSegment
This commit is contained in:
parent
7e8c9a6b1a
commit
e96370f820
|
@ -67,6 +67,7 @@
|
|||
#include "Mod/Part/App/TopoShapeCompSolidPy.h"
|
||||
#include "Mod/Part/App/TopoShapeShellPy.h"
|
||||
#include "Mod/Part/App/LinePy.h"
|
||||
#include "Mod/Part/App/LineSegmentPy.h"
|
||||
#include "Mod/Part/App/PointPy.h"
|
||||
#include "Mod/Part/App/CirclePy.h"
|
||||
#include "Mod/Part/App/EllipsePy.h"
|
||||
|
@ -207,6 +208,7 @@ PyMODINIT_FUNC initPart()
|
|||
Base::Interpreter().addType(&Part::TopoShapeShellPy ::Type,partModule,"Shell");
|
||||
|
||||
Base::Interpreter().addType(&Part::LinePy ::Type,partModule,"Line");
|
||||
Base::Interpreter().addType(&Part::LineSegmentPy ::Type,partModule,"LineSegment");
|
||||
Base::Interpreter().addType(&Part::PointPy ::Type,partModule,"Point");
|
||||
Base::Interpreter().addType(&Part::CirclePy ::Type,partModule,"Circle");
|
||||
Base::Interpreter().addType(&Part::EllipsePy ::Type,partModule,"Ellipse");
|
||||
|
|
|
@ -54,6 +54,7 @@ generate_from_xml(GeometryPy)
|
|||
generate_from_xml(GeometryCurvePy)
|
||||
generate_from_xml(GeometrySurfacePy)
|
||||
generate_from_xml(LinePy)
|
||||
generate_from_xml(LineSegmentPy)
|
||||
generate_from_xml(PointPy)
|
||||
generate_from_xml(BezierCurvePy)
|
||||
generate_from_xml(BSplineCurvePy)
|
||||
|
@ -210,6 +211,8 @@ SET(Python_SRCS
|
|||
GeometrySurfacePyImp.cpp
|
||||
LinePy.xml
|
||||
LinePyImp.cpp
|
||||
LineSegmentPy.xml
|
||||
LineSegmentPyImp.cpp
|
||||
PointPy.xml
|
||||
PointPyImp.cpp
|
||||
BezierCurvePy.xml
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Mod/Part/App/LinePy.h>
|
||||
#include <Mod/Part/App/LineSegmentPy.h>
|
||||
#include <Mod/Part/App/CirclePy.h>
|
||||
#include <Mod/Part/App/EllipsePy.h>
|
||||
#include <Mod/Part/App/ArcPy.h>
|
||||
|
@ -2720,7 +2721,7 @@ PyObject *GeomArcOfParabola::getPyObject(void)
|
|||
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomLine,Part::GeomCurve);
|
||||
TYPESYSTEM_SOURCE(Part::GeomLine,Part::GeomCurve)
|
||||
|
||||
GeomLine::GeomLine()
|
||||
{
|
||||
|
@ -2825,7 +2826,7 @@ PyObject *GeomLine::getPyObject(void)
|
|||
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomLineSegment,Part::GeomCurve);
|
||||
TYPESYSTEM_SOURCE(Part::GeomLineSegment,Part::GeomCurve)
|
||||
|
||||
GeomLineSegment::GeomLineSegment()
|
||||
{
|
||||
|
@ -2951,7 +2952,7 @@ void GeomLineSegment::Restore (Base::XMLReader &reader)
|
|||
|
||||
PyObject *GeomLineSegment::getPyObject(void)
|
||||
{
|
||||
return new LinePy((GeomLineSegment*)this->clone());
|
||||
return new LineSegmentPy(static_cast<GeomLineSegment*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
|
44
src/Mod/Part/App/LineSegmentPy.xml
Normal file
44
src/Mod/Part/App/LineSegmentPy.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="GeometryCurvePy"
|
||||
Name="LineSegmentPy"
|
||||
Twin="GeomLineSegment"
|
||||
TwinPointer="GeomLineSegment"
|
||||
Include="Mod/Part/App/Geometry.h"
|
||||
Namespace="Part"
|
||||
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
|
||||
FatherNamespace="Part"
|
||||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>Describes a line segment
|
||||
To create a line segment there are several ways:
|
||||
Part.LineSegment()
|
||||
Creates a default line segment
|
||||
|
||||
Part.LineSegment(LineSegment)
|
||||
Creates a copy of the given line segment
|
||||
|
||||
Part.LineSegment(Point1,Point2)
|
||||
Creates a line segment that goes through two given points</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="setParameterRange">
|
||||
<Documentation>
|
||||
<UserDocu>Set the parameter range of the underlying line geometry</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="StartPoint" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Returns the start point of this line.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="StartPoint" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="EndPoint" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Returns the end point point of this line.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="EndPoint" Type="Object"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
308
src/Mod/Part/App/LineSegmentPyImp.cpp
Normal file
308
src/Mod/Part/App/LineSegmentPyImp.cpp
Normal file
|
@ -0,0 +1,308 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <gp.hxx>
|
||||
# include <gp_Lin.hxx>
|
||||
# include <Geom_Line.hxx>
|
||||
# include <Geom_TrimmedCurve.hxx>
|
||||
# include <GC_MakeLine.hxx>
|
||||
# include <GC_MakeSegment.hxx>
|
||||
# include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
|
||||
#include "OCCError.h"
|
||||
#include "Geometry.h"
|
||||
#include <Mod/Part/App/LinePy.h>
|
||||
#include <Mod/Part/App/LineSegmentPy.h>
|
||||
#include <Mod/Part/App/LineSegmentPy.cpp>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
extern const char* gce_ErrorStatusText(gce_ErrorType et);
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string LineSegmentPy::representation(void) const
|
||||
{
|
||||
std::stringstream str;
|
||||
Base::Vector3d start = getGeomLineSegmentPtr()->getStartPoint();
|
||||
Base::Vector3d end = getGeomLineSegmentPtr()->getEndPoint();
|
||||
str << "<Line segment ("
|
||||
<< start.x << "," <<start.y << "," <<start.z << ") ("
|
||||
<< end.x << "," <<end.y << "," <<end.z << ") >";
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject *LineSegmentPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of LineSegmentPy and the Twin object
|
||||
return new LineSegmentPy(new GeomLineSegment);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int LineSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
PyObject *pLine;
|
||||
if (PyArg_ParseTuple(args, "O!", &(LineSegmentPy::Type), &pLine)) {
|
||||
// Copy line
|
||||
LineSegmentPy* pcLine = static_cast<LineSegmentPy*>(pLine);
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(pcLine->getGeomLineSegmentPtr()->handle());
|
||||
Handle_Geom_Line that_line = Handle_Geom_Line::DownCast
|
||||
(that_curv->BasisCurve());
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
|
||||
(this_curv->BasisCurve());
|
||||
|
||||
// Assign the lines
|
||||
this_line->SetLin(that_line->Lin());
|
||||
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
double first, last;
|
||||
if (PyArg_ParseTuple(args, "O!dd", &(LineSegmentPy::Type), &pLine, &first, &last)) {
|
||||
// Copy line
|
||||
LineSegmentPy* pcLine = static_cast<LineSegmentPy*>(pLine);
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(pcLine->getGeomLineSegmentPtr()->handle());
|
||||
Handle_Geom_Line that_line = Handle_Geom_Line::DownCast
|
||||
(that_curv->BasisCurve());
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
|
||||
(this_curv->BasisCurve());
|
||||
|
||||
// Assign the lines
|
||||
this_line->SetLin(that_line->Lin());
|
||||
this_curv->SetTrim(first, last);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
PyObject *pV1, *pV2;
|
||||
if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &pV1,
|
||||
&(Base::VectorPy::Type), &pV2)) {
|
||||
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
|
||||
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
|
||||
try {
|
||||
// Create line out of two points
|
||||
double distance = Base::Distance(v1, v2);
|
||||
if (distance < gp::Resolution())
|
||||
Standard_Failure::Raise("Both points are equal");
|
||||
GC_MakeSegment ms(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Pnt(v2.x,v2.y,v2.z));
|
||||
if (!ms.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(ms.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
|
||||
(this_curv->BasisCurve());
|
||||
Handle_Geom_TrimmedCurve that_curv = ms.Value();
|
||||
Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve());
|
||||
this_line->SetLin(that_line->Lin());
|
||||
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(PartExceptionOCCError, "creation of line failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- LineSegment\n"
|
||||
"-- Point, Point");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject* LineSegmentPy::setParameterRange(PyObject *args)
|
||||
{
|
||||
double first, last;
|
||||
if (!PyArg_ParseTuple(args, "dd", &first, &last))
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
this_curve->SetTrim(first, last);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
Py::Object LineSegmentPy::getStartPoint(void) const
|
||||
{
|
||||
Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
gp_Pnt pnt = this_curve->StartPoint();
|
||||
return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
|
||||
}
|
||||
|
||||
void LineSegmentPy::setStartPoint(Py::Object arg)
|
||||
{
|
||||
gp_Pnt p1, p2;
|
||||
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
p2 = this_curv->EndPoint();
|
||||
|
||||
PyObject *p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
|
||||
p1.SetX(v.x);
|
||||
p1.SetY(v.y);
|
||||
p1.SetZ(v.z);
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
Py::Tuple tuple(arg);
|
||||
p1.SetX((double)Py::Float(tuple.getItem(0)));
|
||||
p1.SetY((double)Py::Float(tuple.getItem(1)));
|
||||
p1.SetZ((double)Py::Float(tuple.getItem(2)));
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector' or tuple, not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
try {
|
||||
// Create line out of two points
|
||||
if (p1.Distance(p2) < gp::Resolution())
|
||||
Standard_Failure::Raise("Both points are equal");
|
||||
GC_MakeSegment ms(p1, p2);
|
||||
if (!ms.IsDone()) {
|
||||
throw Py::Exception(gce_ErrorStatusText(ms.Status()));
|
||||
}
|
||||
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
|
||||
(this_curv->BasisCurve());
|
||||
Handle_Geom_TrimmedCurve that_curv = ms.Value();
|
||||
Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve());
|
||||
this_line->SetLin(that_line->Lin());
|
||||
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Py::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object LineSegmentPy::getEndPoint(void) const
|
||||
{
|
||||
Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
gp_Pnt pnt = this_curve->EndPoint();
|
||||
return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
|
||||
}
|
||||
|
||||
void LineSegmentPy::setEndPoint(Py::Object arg)
|
||||
{
|
||||
gp_Pnt p1, p2;
|
||||
Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
|
||||
(this->getGeomLineSegmentPtr()->handle());
|
||||
p1 = this_curv->StartPoint();
|
||||
|
||||
PyObject *p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
|
||||
p2.SetX(v.x);
|
||||
p2.SetY(v.y);
|
||||
p2.SetZ(v.z);
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
Py::Tuple tuple(arg);
|
||||
p2.SetX((double)Py::Float(tuple.getItem(0)));
|
||||
p2.SetY((double)Py::Float(tuple.getItem(1)));
|
||||
p2.SetZ((double)Py::Float(tuple.getItem(2)));
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector' or tuple, not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
try {
|
||||
// Create line out of two points
|
||||
if (p1.Distance(p2) < gp::Resolution())
|
||||
Standard_Failure::Raise("Both points are equal");
|
||||
GC_MakeSegment ms(p1, p2);
|
||||
if (!ms.IsDone()) {
|
||||
throw Py::Exception(gce_ErrorStatusText(ms.Status()));
|
||||
}
|
||||
|
||||
// get Geom_Line of line segment
|
||||
Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
|
||||
(this_curv->BasisCurve());
|
||||
Handle_Geom_TrimmedCurve that_curv = ms.Value();
|
||||
Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve());
|
||||
this_line->SetLin(that_line->Lin());
|
||||
this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter());
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Py::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *LineSegmentPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LineSegmentPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user