From 273f3995c08effda53defee5ad25aaa63999970a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 4 Dec 2016 14:20:56 +0100 Subject: [PATCH] add class GeomArcOfConic to reduce code duplication --- src/Mod/Part/App/AppPart.cpp | 3 + src/Mod/Part/App/ArcOfCirclePy.xml | 16 +- src/Mod/Part/App/ArcOfCirclePyImp.cpp | 71 +-- src/Mod/Part/App/ArcOfConicPy.xml | 55 ++ src/Mod/Part/App/ArcOfConicPyImp.cpp | 243 ++++++++ src/Mod/Part/App/ArcOfEllipsePy.xml | 22 +- src/Mod/Part/App/ArcOfEllipsePyImp.cpp | 81 +-- src/Mod/Part/App/ArcOfHyperbolaPy.xml | 22 +- src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp | 81 +-- src/Mod/Part/App/ArcOfParabolaPy.xml | 22 +- src/Mod/Part/App/ArcOfParabolaPyImp.cpp | 81 +-- src/Mod/Part/App/CMakeLists.txt | 3 + src/Mod/Part/App/ConicPy.xml | 2 +- src/Mod/Part/App/ConicPyImp.cpp | 22 +- src/Mod/Part/App/Geometry.cpp | 569 +++++++----------- src/Mod/Part/App/Geometry.h | 97 +-- src/Mod/Sketcher/App/SketchObject.cpp | 2 +- .../Sketcher/Gui/TaskSketcherValidation.cpp | 2 +- 18 files changed, 595 insertions(+), 799 deletions(-) create mode 100644 src/Mod/Part/App/ArcOfConicPy.xml create mode 100644 src/Mod/Part/App/ArcOfConicPyImp.cpp diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index f278c754c8..af49edf332 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -70,6 +70,7 @@ #include "Mod/Part/App/LineSegmentPy.h" #include "Mod/Part/App/PointPy.h" #include "Mod/Part/App/ConicPy.h" +#include "Mod/Part/App/ArcOfConicPy.h" #include "Mod/Part/App/CirclePy.h" #include "Mod/Part/App/EllipsePy.h" #include "Mod/Part/App/ArcPy.h" @@ -306,6 +307,7 @@ PyMODINIT_FUNC initPart() Base::Interpreter().addType(&Part::LineSegmentPy ::Type,partModule,"LineSegment"); Base::Interpreter().addType(&Part::PointPy ::Type,partModule,"Point"); Base::Interpreter().addType(&Part::ConicPy ::Type,partModule,"Conic"); + Base::Interpreter().addType(&Part::ArcOfConicPy ::Type,partModule,"ArcOfConic"); Base::Interpreter().addType(&Part::CirclePy ::Type,partModule,"Circle"); Base::Interpreter().addType(&Part::EllipsePy ::Type,partModule,"Ellipse"); Base::Interpreter().addType(&Part::HyperbolaPy ::Type,partModule,"Hyperbola"); @@ -460,6 +462,7 @@ PyMODINIT_FUNC initPart() Part::GeomBezierCurve ::init(); Part::GeomBSplineCurve ::init(); Part::GeomConic ::init(); + Part::GeomArcOfConic ::init(); Part::GeomCircle ::init(); Part::GeomArcOfCircle ::init(); Part::GeomArcOfEllipse ::init(); diff --git a/src/Mod/Part/App/ArcOfCirclePy.xml b/src/Mod/Part/App/ArcOfCirclePy.xml index 53ce15f33d..ff5de20b48 100644 --- a/src/Mod/Part/App/ArcOfCirclePy.xml +++ b/src/Mod/Part/App/ArcOfCirclePy.xml @@ -1,14 +1,14 @@ @@ -21,18 +21,6 @@ - - - Center of the circle. - - - - - - The axis direction of the circle - - - The internal circle representation diff --git a/src/Mod/Part/App/ArcOfCirclePyImp.cpp b/src/Mod/Part/App/ArcOfCirclePyImp.cpp index 760d756964..9143a80900 100644 --- a/src/Mod/Part/App/ArcOfCirclePyImp.cpp +++ b/src/Mod/Part/App/ArcOfCirclePyImp.cpp @@ -30,10 +30,10 @@ # include #endif -#include "Mod/Part/App/Geometry.h" -#include "ArcOfCirclePy.h" -#include "ArcOfCirclePy.cpp" -#include "CirclePy.h" +#include "Geometry.h" +#include +#include +#include #include "OCCError.h" #include @@ -141,69 +141,6 @@ void ArcOfCirclePy::setRadius(Py::Float arg) getGeomArcOfCirclePtr()->setRadius((double)arg); } -Py::Object ArcOfCirclePy::getCenter(void) const -{ - return Py::Vector(getGeomArcOfCirclePtr()->getCenter()); -} - -void ArcOfCirclePy::setCenter(Py::Object arg) -{ - PyObject* p = arg.ptr(); - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - Base::Vector3d loc = static_cast(p)->value(); - getGeomArcOfCirclePtr()->setCenter(loc); - } - else if (PyObject_TypeCheck(p, &PyTuple_Type)) { - Base::Vector3d loc = Base::getVectorFromTuple(p); - getGeomArcOfCirclePtr()->setCenter(loc); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } -} - -Py::Object ArcOfCirclePy::getAxis(void) const -{ - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfCirclePtr()->handle()); - Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); - gp_Ax1 axis = circle->Axis(); - gp_Dir dir = axis.Direction(); - return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); -} - -void ArcOfCirclePy::setAxis(Py::Object arg) -{ - PyObject* p = arg.ptr(); - Base::Vector3d val; - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - val = static_cast(p)->value(); - } - else if (PyTuple_Check(p)) { - val = Base::getVectorFromTuple(p); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfCirclePtr()->handle()); - Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); - try { - gp_Ax1 axis; - axis.SetLocation(circle->Location()); - axis.SetDirection(gp_Dir(val.x, val.y, val.z)); - circle->SetAxis(axis); - } - catch (Standard_Failure) { - throw Py::Exception("cannot set axis"); - } -} - Py::Object ArcOfCirclePy::getCircle(void) const { Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast diff --git a/src/Mod/Part/App/ArcOfConicPy.xml b/src/Mod/Part/App/ArcOfConicPy.xml new file mode 100644 index 0000000000..57450e686a --- /dev/null +++ b/src/Mod/Part/App/ArcOfConicPy.xml @@ -0,0 +1,55 @@ + + + + + + Describes a portion of a conic + + + + Center of the conic. + + + + + + Deprecated -- use Location. + + + + + + The angle between the X axis and the major axis of the conic. + + + + + + The axis direction of the conic + + + + + + The X axis direction of the circle + + + + + + The Y axis direction of the circle + + + + + diff --git a/src/Mod/Part/App/ArcOfConicPyImp.cpp b/src/Mod/Part/App/ArcOfConicPyImp.cpp new file mode 100644 index 0000000000..ef90ab3700 --- /dev/null +++ b/src/Mod/Part/App/ArcOfConicPyImp.cpp @@ -0,0 +1,243 @@ +/*************************************************************************** + * Copyright (c) 2014 Abdullah Tahiri +#endif + +#include "Geometry.h" +#include +#include +#include "OCCError.h" + +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfConicPy::representation(void) const +{ + return ""; +} + +PyObject *ArcOfConicPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // never create such objects with the constructor + PyErr_SetString(PyExc_RuntimeError, + "You cannot create an instance of the abstract class 'ArcOfConic'."); + return 0; +} + +// constructor method +int ArcOfConicPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + return -1; +} + +Py::Object ArcOfConicPy::getLocation(void) const +{ + return Py::Vector(getGeomArcOfConicPtr()->getLocation()); +} + +Py::Object ArcOfConicPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfConicPtr()->getCenter()); +} + +void ArcOfConicPy::setLocation(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfConicPtr()->setLocation(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfConicPtr()->setLocation(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +void ArcOfConicPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfConicPtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfConicPtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Float ArcOfConicPy::getAngleXU(void) const +{ + return Py::Float(getGeomArcOfConicPtr()->getAngleXU()); +} + +void ArcOfConicPy::setAngleXU(Py::Float arg) +{ + getGeomArcOfConicPtr()->setAngleXU((double)arg); +} + +Py::Object ArcOfConicPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + gp_Ax1 axis = conic->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfConicPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(conic->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + conic->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfConicPy::getXAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + gp_Ax1 axis = conic->XAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfConicPy::setXAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + try { + gp_Ax2 pos; + pos = conic->Position(); + pos.SetXDirection(gp_Dir(val.x, val.y, val.z)); + conic->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set X axis"); + } +} + +Py::Object ArcOfConicPy::getYAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + gp_Ax1 axis = conic->YAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfConicPy::setYAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfConicPtr()->handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(trim->BasisCurve()); + try { + gp_Ax2 pos; + pos = conic->Position(); + pos.SetYDirection(gp_Dir(val.x, val.y, val.z)); + conic->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set Y axis"); + } +} + +PyObject *ArcOfConicPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfConicPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/ArcOfEllipsePy.xml b/src/Mod/Part/App/ArcOfEllipsePy.xml index f2c4ca78c8..a7a4a14bc4 100644 --- a/src/Mod/Part/App/ArcOfEllipsePy.xml +++ b/src/Mod/Part/App/ArcOfEllipsePy.xml @@ -1,14 +1,14 @@ @@ -27,24 +27,6 @@ - - - The angle between the X axis and the major axis of the ellipse. - - - - - - Center of the ellipse. - - - - - - The axis direction of the ellipse - - - The internal ellipse representation diff --git a/src/Mod/Part/App/ArcOfEllipsePyImp.cpp b/src/Mod/Part/App/ArcOfEllipsePyImp.cpp index a03242817b..dfb61ca0cf 100644 --- a/src/Mod/Part/App/ArcOfEllipsePyImp.cpp +++ b/src/Mod/Part/App/ArcOfEllipsePyImp.cpp @@ -30,10 +30,10 @@ # include #endif -#include "Mod/Part/App/Geometry.h" -#include "ArcOfEllipsePy.h" -#include "ArcOfEllipsePy.cpp" -#include "EllipsePy.h" +#include "Geometry.h" +#include +#include +#include #include "OCCError.h" #include @@ -141,79 +141,6 @@ void ArcOfEllipsePy::setMinorRadius(Py::Float arg) getGeomArcOfEllipsePtr()->setMinorRadius((double)arg); } -Py::Float ArcOfEllipsePy::getAngleXU(void) const -{ - return Py::Float(getGeomArcOfEllipsePtr()->getAngleXU()); -} - -void ArcOfEllipsePy::setAngleXU(Py::Float arg) -{ - getGeomArcOfEllipsePtr()->setAngleXU((double)arg); -} - -Py::Object ArcOfEllipsePy::getCenter(void) const -{ - return Py::Vector(getGeomArcOfEllipsePtr()->getCenter()); -} - -void ArcOfEllipsePy::setCenter(Py::Object arg) -{ - PyObject* p = arg.ptr(); - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - Base::Vector3d loc = static_cast(p)->value(); - getGeomArcOfEllipsePtr()->setCenter(loc); - } - else if (PyObject_TypeCheck(p, &PyTuple_Type)) { - Base::Vector3d loc = Base::getVectorFromTuple(p); - getGeomArcOfEllipsePtr()->setCenter(loc); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } -} - -Py::Object ArcOfEllipsePy::getAxis(void) const -{ - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfEllipsePtr()->handle()); - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); - gp_Ax1 axis = ellipse->Axis(); - gp_Dir dir = axis.Direction(); - return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); -} - -void ArcOfEllipsePy::setAxis(Py::Object arg) -{ - PyObject* p = arg.ptr(); - Base::Vector3d val; - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - val = static_cast(p)->value(); - } - else if (PyTuple_Check(p)) { - val = Base::getVectorFromTuple(p); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfEllipsePtr()->handle()); - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); - try { - gp_Ax1 axis; - axis.SetLocation(ellipse->Location()); - axis.SetDirection(gp_Dir(val.x, val.y, val.z)); - ellipse->SetAxis(axis); - } - catch (Standard_Failure) { - throw Py::Exception("cannot set axis"); - } -} - Py::Object ArcOfEllipsePy::getEllipse(void) const { Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast diff --git a/src/Mod/Part/App/ArcOfHyperbolaPy.xml b/src/Mod/Part/App/ArcOfHyperbolaPy.xml index da348c76b0..c6bdef44ba 100644 --- a/src/Mod/Part/App/ArcOfHyperbolaPy.xml +++ b/src/Mod/Part/App/ArcOfHyperbolaPy.xml @@ -1,14 +1,14 @@ @@ -27,24 +27,6 @@ - - - The angle between the X axis and the major axis of the hyperbola. - - - - - - Center of the hyperbola. - - - - - - The axis direction of the hyperbola - - - The internal hyperbola representation diff --git a/src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp b/src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp index 71de3b2a70..077890eff3 100644 --- a/src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp +++ b/src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp @@ -30,10 +30,10 @@ # include #endif -#include "Mod/Part/App/Geometry.h" -#include "ArcOfHyperbolaPy.h" -#include "ArcOfHyperbolaPy.cpp" -#include "HyperbolaPy.h" +#include "Geometry.h" +#include +#include +#include #include "OCCError.h" #include @@ -141,79 +141,6 @@ void ArcOfHyperbolaPy::setMinorRadius(Py::Float arg) getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg); } -Py::Float ArcOfHyperbolaPy::getAngleXU(void) const -{ - return Py::Float(getGeomArcOfHyperbolaPtr()->getAngleXU()); -} - -void ArcOfHyperbolaPy::setAngleXU(Py::Float arg) -{ - getGeomArcOfHyperbolaPtr()->setAngleXU((double)arg); -} - -Py::Object ArcOfHyperbolaPy::getCenter(void) const -{ - return Py::Vector(getGeomArcOfHyperbolaPtr()->getCenter()); -} - -void ArcOfHyperbolaPy::setCenter(Py::Object arg) -{ - PyObject* p = arg.ptr(); - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - Base::Vector3d loc = static_cast(p)->value(); - getGeomArcOfHyperbolaPtr()->setCenter(loc); - } - else if (PyObject_TypeCheck(p, &PyTuple_Type)) { - Base::Vector3d loc = Base::getVectorFromTuple(p); - getGeomArcOfHyperbolaPtr()->setCenter(loc); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } -} - -Py::Object ArcOfHyperbolaPy::getAxis(void) const -{ - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfHyperbolaPtr()->handle()); - Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); - gp_Ax1 axis = hyperbola->Axis(); - gp_Dir dir = axis.Direction(); - return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); -} - -void ArcOfHyperbolaPy::setAxis(Py::Object arg) -{ - PyObject* p = arg.ptr(); - Base::Vector3d val; - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - val = static_cast(p)->value(); - } - else if (PyTuple_Check(p)) { - val = Base::getVectorFromTuple(p); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfHyperbolaPtr()->handle()); - Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); - try { - gp_Ax1 axis; - axis.SetLocation(hyperbola->Location()); - axis.SetDirection(gp_Dir(val.x, val.y, val.z)); - hyperbola->SetAxis(axis); - } - catch (Standard_Failure) { - throw Py::Exception("cannot set axis"); - } -} - Py::Object ArcOfHyperbolaPy::getHyperbola(void) const { Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast diff --git a/src/Mod/Part/App/ArcOfParabolaPy.xml b/src/Mod/Part/App/ArcOfParabolaPy.xml index 662986a1be..d7110b4aed 100644 --- a/src/Mod/Part/App/ArcOfParabolaPy.xml +++ b/src/Mod/Part/App/ArcOfParabolaPy.xml @@ -1,14 +1,14 @@ @@ -20,24 +20,6 @@ The focal length of the parabola. - - - - The angle between the X axis and the major axis of the parabola. - - - - - - Center of the parabola. - - - - - - The axis direction of the parabola - - diff --git a/src/Mod/Part/App/ArcOfParabolaPyImp.cpp b/src/Mod/Part/App/ArcOfParabolaPyImp.cpp index 92f6e9b8ea..b946e920ea 100644 --- a/src/Mod/Part/App/ArcOfParabolaPyImp.cpp +++ b/src/Mod/Part/App/ArcOfParabolaPyImp.cpp @@ -30,10 +30,10 @@ # include #endif -#include "Mod/Part/App/Geometry.h" -#include "ArcOfParabolaPy.h" -#include "ArcOfParabolaPy.cpp" -#include "ParabolaPy.h" +#include "Geometry.h" +#include +#include +#include #include "OCCError.h" #include @@ -129,79 +129,6 @@ void ArcOfParabolaPy::setFocal(Py::Float arg) getGeomArcOfParabolaPtr()->setFocal((double)arg); } -Py::Float ArcOfParabolaPy::getAngleXU(void) const -{ - return Py::Float(getGeomArcOfParabolaPtr()->getAngleXU()); -} - -void ArcOfParabolaPy::setAngleXU(Py::Float arg) -{ - getGeomArcOfParabolaPtr()->setAngleXU((double)arg); -} - -Py::Object ArcOfParabolaPy::getCenter(void) const -{ - return Py::Vector(getGeomArcOfParabolaPtr()->getCenter()); -} - -void ArcOfParabolaPy::setCenter(Py::Object arg) -{ - PyObject* p = arg.ptr(); - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - Base::Vector3d loc = static_cast(p)->value(); - getGeomArcOfParabolaPtr()->setCenter(loc); - } - else if (PyObject_TypeCheck(p, &PyTuple_Type)) { - Base::Vector3d loc = Base::getVectorFromTuple(p); - getGeomArcOfParabolaPtr()->setCenter(loc); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } -} - -Py::Object ArcOfParabolaPy::getAxis(void) const -{ - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfParabolaPtr()->handle()); - Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); - gp_Ax1 axis = parabola->Axis(); - gp_Dir dir = axis.Direction(); - return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); -} - -void ArcOfParabolaPy::setAxis(Py::Object arg) -{ - PyObject* p = arg.ptr(); - Base::Vector3d val; - if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { - val = static_cast(p)->value(); - } - else if (PyTuple_Check(p)) { - val = Base::getVectorFromTuple(p); - } - else { - std::string error = std::string("type must be 'Vector', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - - Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast - (getGeomArcOfParabolaPtr()->handle()); - Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); - try { - gp_Ax1 axis; - axis.SetLocation(parabola->Location()); - axis.SetDirection(gp_Dir(val.x, val.y, val.z)); - parabola->SetAxis(axis); - } - catch (Standard_Failure) { - throw Py::Exception("cannot set axis"); - } -} - Py::Object ArcOfParabolaPy::getParabola(void) const { Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index c1c039f1ca..7623c2b918 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -40,6 +40,7 @@ if(FREETYPE_FOUND) endif(FREETYPE_FOUND) generate_from_xml(ArcPy) +generate_from_xml(ArcOfConicPy) generate_from_xml(ArcOfCirclePy) generate_from_xml(ArcOfParabolaPy) generate_from_xml(BodyBasePy) @@ -184,6 +185,8 @@ SOURCE_GROUP("Properties" FILES ${Properties_SRCS}) SET(Python_SRCS ArcPy.xml ArcPyImp.cpp + ArcOfConicPy.xml + ArcOfConicPyImp.cpp ArcOfCirclePy.xml ArcOfCirclePyImp.cpp ArcOfParabolaPy.xml diff --git a/src/Mod/Part/App/ConicPy.xml b/src/Mod/Part/App/ConicPy.xml index 327af0ff7b..4cc015c280 100644 --- a/src/Mod/Part/App/ConicPy.xml +++ b/src/Mod/Part/App/ConicPy.xml @@ -23,7 +23,7 @@ - Deprecated. Use Location. + Deprecated -- use Location. diff --git a/src/Mod/Part/App/ConicPyImp.cpp b/src/Mod/Part/App/ConicPyImp.cpp index 6f29678d94..45d5bb9872 100644 --- a/src/Mod/Part/App/ConicPyImp.cpp +++ b/src/Mod/Part/App/ConicPyImp.cpp @@ -111,30 +111,12 @@ Py::Float ConicPy::getEccentricity(void) const Py::Float ConicPy::getAngleXU(void) const { - Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(getGeomConicPtr()->handle()); - - gp_Pnt center = conic->Axis().Location(); - gp_Dir normal = conic->Axis().Direction(); - gp_Dir xdir = conic->XAxis().Direction(); - - gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method - - return Py::Float(-xdir.AngleWithRef(xdirref.XDirection(),normal)); + return Py::Float(getGeomConicPtr()->getAngleXU()); } void ConicPy::setAngleXU(Py::Float arg) { - Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(getGeomConicPtr()->handle()); - - gp_Pnt center = conic->Axis().Location(); - gp_Dir normal = conic->Axis().Direction(); - - gp_Ax1 normaxis(center, normal); - - gp_Ax2 xdirref(center, normal); - - xdirref.Rotate(normaxis,arg); - conic->SetPosition(xdirref); + getGeomConicPtr()->setAngleXU((double)arg); } Py::Object ConicPy::getAxis(void) const diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index ff3f2e5e06..be7b389743 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -780,6 +780,162 @@ bool GeomConic::isReversed() const // ------------------------------------------------- +TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomArcOfConic,Part::GeomCurve) + +GeomArcOfConic::GeomArcOfConic() +{ +} + +GeomArcOfConic::~GeomArcOfConic() +{ +} + +/*! + * \brief GeomArcOfConic::getStartPoint + * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. + * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). + * \return XYZ of the arc's starting point. + */ +Base::Vector3d GeomArcOfConic::getStartPoint(bool emulateCCWXY) const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + gp_Pnt pnt = curve->StartPoint(); + if (emulateCCWXY) { + if (isReversed()) + pnt = curve->EndPoint(); + } + return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); +} + +/*! + * \brief GeomArcOfConic::getEndPoint + * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. + * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). + * \return + */ +Base::Vector3d GeomArcOfConic::getEndPoint(bool emulateCCWXY) const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + gp_Pnt pnt = curve->EndPoint(); + if (emulateCCWXY) { + if (isReversed()) + pnt = curve->StartPoint(); + } + return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); +} + +Base::Vector3d GeomArcOfConic::getCenter(void) const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + gp_Ax1 axis = conic->Axis(); + const gp_Pnt& loc = axis.Location(); + return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); +} + +Base::Vector3d GeomArcOfConic::getLocation(void) const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + gp_Ax1 axis = conic->Axis(); + const gp_Pnt& loc = axis.Location(); + return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); +} + +void GeomArcOfConic::setCenter(const Base::Vector3d& Center) +{ + gp_Pnt p1(Center.x,Center.y,Center.z); + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + + try { + conic->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +void GeomArcOfConic::setLocation(const Base::Vector3d& Center) +{ + gp_Pnt p1(Center.x,Center.y,Center.z); + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + + try { + conic->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief GeomArcOfConic::isReversed + * \return tests if an arc that lies in XY plane is reversed (i.e. drawn from + * startpoint to endpoint in CW direction instead of CCW.). Returns True if the + * arc is CW and false if CCW. + */ +bool GeomArcOfConic::isReversed() const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + assert(!conic.IsNull()); + return conic->Axis().Direction().Z() < 0; +} + +/*! + * \brief GeomArcOfConic::getAngleXU + * \return The angle between ellipse's major axis (in direction to focus1) and + * X axis of a default axis system in the plane of ellipse. The angle is + * counted CCW as seen when looking at the ellipse so that ellipse's axis is + * pointing at you. Note that this function may give unexpected results when + * the ellipse is in XY, but reversed, because the X axis of the default axis + * system is reversed compared to the global X axis. This angle, in conjunction + * with ellipse's axis, fully defines the orientation of the ellipse. + */ +double GeomArcOfConic::getAngleXU(void) const +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + + gp_Pnt center = conic->Axis().Location(); + gp_Dir normal = conic->Axis().Direction(); + gp_Dir xdir = conic->XAxis().Direction(); + + gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method + + return -xdir.AngleWithRef(xdirref.XDirection(),normal); +} + +/*! + * \brief GeomArcOfConic::setAngleXU complements getAngleXU. + */ +void GeomArcOfConic::setAngleXU(double angle) +{ + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + + try { + gp_Pnt center = conic->Axis().Location(); + gp_Dir normal = conic->Axis().Direction(); + + gp_Ax1 normaxis(center, normal); + gp_Ax2 xdirref(center, normal); + + xdirref.Rotate(normaxis,angle); + conic->SetPosition(xdirref); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +// ------------------------------------------------- + TYPESYSTEM_SOURCE(Part::GeomCircle,Part::GeomConic) GeomCircle::GeomCircle() @@ -897,7 +1053,7 @@ PyObject *GeomCircle::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::GeomArcOfCircle,Part::GeomCurve) +TYPESYSTEM_SOURCE(Part::GeomArcOfCircle,Part::GeomArcOfConic) GeomArcOfCircle::GeomArcOfCircle() { @@ -935,64 +1091,12 @@ Geometry *GeomArcOfCircle::clone(void) const return copy; } -/*! - * \brief GeomArcOfCircle::getStartPoint - * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. - * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). - * \return XYZ of the arc's starting point. - */ -Base::Vector3d GeomArcOfCircle::getStartPoint(bool emulateCCWXY) const -{ - gp_Pnt pnt = this->myCurve->StartPoint(); - if(emulateCCWXY) - if(isReversedInXY()) - pnt = this->myCurve->EndPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -/*! - * \brief GeomArcOfCircle::getEndPoint - * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. - * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). - * \return - */ -Base::Vector3d GeomArcOfCircle::getEndPoint(bool emulateCCWXY) const -{ - gp_Pnt pnt = this->myCurve->EndPoint(); - if(emulateCCWXY) - if(isReversedInXY()) - pnt = this->myCurve->StartPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfCircle::getCenter(void) const -{ - Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); - gp_Ax1 axis = circle->Axis(); - const gp_Pnt& loc = axis.Location(); - return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); -} - double GeomArcOfCircle::getRadius(void) const { Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); return circle->Radius(); } -void GeomArcOfCircle::setCenter(const Base::Vector3d& Center) -{ - gp_Pnt p1(Center.x,Center.y,Center.z); - Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); - - try { - circle->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - void GeomArcOfCircle::setRadius(double Radius) { Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); @@ -1019,17 +1123,19 @@ void GeomArcOfCircle::setRadius(double Radius) */ void GeomArcOfCircle::getRange(double& u, double& v, bool emulateCCWXY) const { - u = myCurve->FirstParameter(); - v = myCurve->LastParameter(); - if(emulateCCWXY){ - Handle_Geom_Circle cir = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); - double angleXU = -cir->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0)); + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + u = curve->FirstParameter(); + v = curve->LastParameter(); + if (emulateCCWXY){ + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + double angleXU = -conic->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0)); double u1 = u, v1 = v;//the true arc curve parameters, cached. u,v will contain the rotation-corrected and swapped angles. - if(cir->Axis().Direction().Z() > 0.0){ + if (conic->Axis().Direction().Z() > 0.0){ //normal CCW arc u = u1 + angleXU; v = v1 + angleXU; - } else { + } + else { //reversed (CW) arc u = angleXU - v1; v = angleXU - u1; @@ -1039,9 +1145,7 @@ void GeomArcOfCircle::getRange(double& u, double& v, bool emulateCCWXY) const v += 2*M_PI; if (v-u > 2*M_PI) v -= 2*M_PI; - } - } /*! @@ -1055,24 +1159,25 @@ void GeomArcOfCircle::getRange(double& u, double& v, bool emulateCCWXY) const */ void GeomArcOfCircle::setRange(double u, double v, bool emulateCCWXY) { - try { - if(emulateCCWXY){ - Handle_Geom_Circle cir = Handle_Geom_Circle::DownCast(myCurve->BasisCurve()); - double angleXU = -cir->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0)); + Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(handle()); + if (emulateCCWXY){ + Handle_Geom_Conic conic = Handle_Geom_Conic::DownCast(curve->BasisCurve()); + double angleXU = -conic->Position().XDirection().AngleWithRef(gp_Dir(1.0,0.0,0.0), gp_Dir(0.0,0.0,1.0)); double u1 = u, v1 = v;//the values that were passed, ccw angles from X axis. u,v will contain the rotation-corrected and swapped angles. - if(cir->Axis().Direction().Z() > 0.0){ + if (conic->Axis().Direction().Z() > 0.0){ //normal CCW arc u = u1 - angleXU; v = v1 - angleXU; - } else { + } + else { //reversed (CW) arc u = angleXU - v1; v = angleXU - u1; } } - myCurve->SetTrim(u, v); + curve->SetTrim(u, v); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); @@ -1080,19 +1185,6 @@ void GeomArcOfCircle::setRange(double u, double v, bool emulateCCWXY) } } -/*! - * \brief GeomArcOfCircle::isReversedInXY - * \return tests if an arc that lies in XY plane is reversed (i.e. drawn from - * startpoint to endpoint in CW direction instead of CCW.). Returns True if the - * arc is CW and false if CCW. - */ -bool GeomArcOfCircle::isReversedInXY() const -{ - Handle_Geom_Circle c = Handle_Geom_Circle::DownCast( myCurve->BasisCurve() ); - assert(!c.IsNull()); - return c->Axis().Direction().Z() < 0; -} - // Persistence implementer unsigned int GeomArcOfCircle::getMemSize (void) const { @@ -1373,7 +1465,7 @@ void GeomEllipse::setHandle(const Handle_Geom_Ellipse &e) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::GeomArcOfEllipse,Part::GeomCurve) +TYPESYSTEM_SOURCE(Part::GeomArcOfEllipse,Part::GeomArcOfConic) GeomArcOfEllipse::GeomArcOfEllipse() { @@ -1411,59 +1503,6 @@ Geometry *GeomArcOfEllipse::clone(void) const return copy; } -/*! - * \brief GeomArcOfEllipse::getStartPoint - * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. - * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). - * \return XYZ of the arc's starting point. - */ -Base::Vector3d GeomArcOfEllipse::getStartPoint(bool emulateCCWXY) const -{ - gp_Pnt pnt = this->myCurve->StartPoint(); - if(emulateCCWXY) - if(isReversedInXY()) - pnt = this->myCurve->EndPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -/*! - * \brief GeomArcOfEllipse::getEndPoint - * \param emulateCCWXY: if true, the arc will pretent to be a CCW arc in XY plane. - * For this to work, the arc must lie in XY plane (i.e. Axis is either +Z or -Z). - * \return XYZ of the arc's starting point. - */ -Base::Vector3d GeomArcOfEllipse::getEndPoint(bool emulateCCWXY) const -{ - gp_Pnt pnt = this->myCurve->EndPoint(); - if(emulateCCWXY) - if(isReversedInXY()) - pnt = this->myCurve->StartPoint(); - - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfEllipse::getCenter(void) const -{ - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(myCurve->BasisCurve()); - gp_Ax1 axis = ellipse->Axis(); - const gp_Pnt& loc = axis.Location(); - return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); -} - -void GeomArcOfEllipse::setCenter(const Base::Vector3d& Center) -{ - gp_Pnt p1(Center.x,Center.y,Center.z); - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(myCurve->BasisCurve()); - - try { - ellipse->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double GeomArcOfEllipse::getMajorRadius(void) const { Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(myCurve->BasisCurve()); @@ -1502,56 +1541,6 @@ void GeomArcOfEllipse::setMinorRadius(double Radius) } } -/*! - * \brief GeomArcOfEllipse::getAngleXU - * \return The angle between ellipse's major axis (in direction to focus1) and - * X axis of a default axis system in the plane of ellipse. The angle is - * counted CCW as seen when looking at the ellipse so that ellipse's axis is - * pointing at you. Note that this function may give unexpected results when - * the ellipse is in XY, but reversed, because the X axis of the default axis - * system is reversed compared to the global X axis. This angle, in conjunction - * with ellipse's axis, fully defines the orientation of the ellipse. - */ -double GeomArcOfEllipse::getAngleXU(void) const -{ - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(myCurve->BasisCurve()); - - gp_Pnt center = ellipse->Axis().Location(); - gp_Dir normal = ellipse->Axis().Direction(); - gp_Dir xdir = ellipse->XAxis().Direction(); - - gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method - - return -xdir.AngleWithRef(xdirref.XDirection(),normal); - -} - -/*! - * \brief GeomArcOfEllipse::setAngleXU complements getAngleXU. - */ -void GeomArcOfEllipse::setAngleXU(double angle) -{ - Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(myCurve->BasisCurve()); - - try { - gp_Pnt center = ellipse->Axis().Location(); - gp_Dir normal = ellipse->Axis().Direction(); - - gp_Ax1 normaxis(center, normal); - - gp_Ax2 xdirref(center, normal); - - xdirref.Rotate(normaxis,angle); - - ellipse->SetPosition(xdirref); - - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - /*! * \brief GeomArcOfEllipse::getMajorAxisDir * \return the direction vector (unit-length) of major axis of the ellipse. The @@ -1594,18 +1583,6 @@ void GeomArcOfEllipse::setMajorAxisDir(Base::Vector3d newdir) } } -/*! - * \brief GeomArcOfEllipse::isReversedInXY tests if an arc that lies in XY plane is reversed - * (i.e. drawn from startpoint to endpoint in CW direction instead of CCW.) - * \return Returns True if the arc is CW and false if CCW. - */ -bool GeomArcOfEllipse::isReversedInXY() const -{ - Handle_Geom_Ellipse c = Handle_Geom_Ellipse::DownCast( myCurve->BasisCurve() ); - assert(!c.IsNull()); - return c->Axis().Direction().Z() < 0; -} - /*! * \brief GeomArcOfEllipse::getRange * \param u [out] start angle of the arc, in radians. @@ -1617,8 +1594,8 @@ void GeomArcOfEllipse::getRange(double& u, double& v, bool emulateCCWXY) const { u = myCurve->FirstParameter(); v = myCurve->LastParameter(); - if(emulateCCWXY){ - if(isReversedInXY()){ + if (emulateCCWXY) { + if (isReversed()) { std::swap(u,v); u = -u; v = -v; if (v < u) @@ -1639,8 +1616,8 @@ void GeomArcOfEllipse::getRange(double& u, double& v, bool emulateCCWXY) const void GeomArcOfEllipse::setRange(double u, double v, bool emulateCCWXY) { try { - if(emulateCCWXY){ - if(isReversedInXY()){ + if (emulateCCWXY) { + if (isReversed()) { std::swap(u,v); u = -u; v = -v; } @@ -1751,7 +1728,6 @@ PyObject *GeomArcOfEllipse::getPyObject(void) return new ArcOfEllipsePy(static_cast(this->clone())); } - // ------------------------------------------------- TYPESYSTEM_SOURCE(Part::GeomHyperbola,Part::GeomConic) @@ -1903,7 +1879,7 @@ PyObject *GeomHyperbola::getPyObject(void) } // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::GeomArcOfHyperbola,Part::GeomCurve) +TYPESYSTEM_SOURCE(Part::GeomArcOfHyperbola,Part::GeomArcOfConic) GeomArcOfHyperbola::GeomArcOfHyperbola() { @@ -1942,40 +1918,6 @@ Geometry *GeomArcOfHyperbola::clone(void) const return copy; } -Base::Vector3d GeomArcOfHyperbola::getStartPoint() const -{ - gp_Pnt pnt = this->myCurve->StartPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfHyperbola::getEndPoint() const -{ - gp_Pnt pnt = this->myCurve->EndPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfHyperbola::getCenter(void) const -{ - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); - gp_Ax1 axis = h->Axis(); - const gp_Pnt& loc = axis.Location(); - return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); -} - -void GeomArcOfHyperbola::setCenter(const Base::Vector3d& Center) -{ - gp_Pnt p1(Center.x,Center.y,Center.z); - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); - - try { - h->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double GeomArcOfHyperbola::getMajorRadius(void) const { Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); @@ -2014,43 +1956,6 @@ void GeomArcOfHyperbola::setMinorRadius(double Radius) } } -double GeomArcOfHyperbola::getAngleXU(void) const -{ - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); - - gp_Pnt center = h->Axis().Location(); - gp_Dir normal = h->Axis().Direction(); - gp_Dir xdir = h->XAxis().Direction(); - - gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method - - return -xdir.AngleWithRef(xdirref.XDirection(),normal); - -} - -void GeomArcOfHyperbola::setAngleXU(double angle) -{ - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); - - try { - gp_Pnt center = h->Axis().Location(); - gp_Dir normal = h->Axis().Direction(); - - gp_Ax1 normaxis(center, normal); - - gp_Ax2 xdirref(center, normal); - - xdirref.Rotate(normaxis,angle); - - h->SetPosition(xdirref); - - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - /*! * \brief GeomArcOfHyperbola::getMajorAxisDir * \return the direction vector (unit-length) of major axis of the hyperbola. The @@ -2094,24 +1999,12 @@ void GeomArcOfHyperbola::setMajorAxisDir(Base::Vector3d newdir) } } -/*! - * \brief GeomArcOfHyperbola::isReversedInXY tests if an arc that lies in XY plane is reversed - * (i.e. drawn from startpoint to endpoint in CW direction instead of CCW.) - * \return Returns True if the arc is CW and false if CCW. - */ -bool GeomArcOfHyperbola::isReversedInXY() const -{ - Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast( myCurve->BasisCurve() ); - assert(!c.IsNull()); - return c->Axis().Direction().Z() < 0; -} - void GeomArcOfHyperbola::getRange(double& u, double& v, bool emulateCCWXY) const { try { - if(emulateCCWXY){ - if(isReversedInXY()){ - Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast( myCurve->BasisCurve() ); + if (emulateCCWXY){ + if (isReversed()) { + Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); assert(!c.IsNull()); c->Reverse(); } @@ -2131,9 +2024,9 @@ void GeomArcOfHyperbola::setRange(double u, double v, bool emulateCCWXY) try { myCurve->SetTrim(u, v); - if(emulateCCWXY){ - if(isReversedInXY()){ - Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast( myCurve->BasisCurve() ); + if (emulateCCWXY) { + if (isReversed()) { + Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); assert(!c.IsNull()); c->Reverse(); } @@ -2145,8 +2038,6 @@ void GeomArcOfHyperbola::setRange(double u, double v, bool emulateCCWXY) } } - - // Persistence implementer unsigned int GeomArcOfHyperbola::getMemSize (void) const { @@ -2374,7 +2265,7 @@ PyObject *GeomParabola::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::GeomArcOfParabola,Part::GeomCurve) +TYPESYSTEM_SOURCE(Part::GeomArcOfParabola,Part::GeomArcOfConic) GeomArcOfParabola::GeomArcOfParabola() { @@ -2412,40 +2303,6 @@ Geometry *GeomArcOfParabola::clone(void) const return copy; } -Base::Vector3d GeomArcOfParabola::getStartPoint() const -{ - gp_Pnt pnt = this->myCurve->StartPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfParabola::getEndPoint() const -{ - gp_Pnt pnt = this->myCurve->EndPoint(); - return Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); -} - -Base::Vector3d GeomArcOfParabola::getCenter(void) const -{ - Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); - gp_Ax1 axis = p->Axis(); - const gp_Pnt& loc = axis.Location(); - return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); -} - -void GeomArcOfParabola::setCenter(const Base::Vector3d& Center) -{ - gp_Pnt p1(Center.x,Center.y,Center.z); - Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); - - try { - p->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double GeomArcOfParabola::getFocal(void) const { Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); @@ -2465,53 +2322,41 @@ void GeomArcOfParabola::setFocal(double length) } } -double GeomArcOfParabola::getAngleXU(void) const +void GeomArcOfParabola::getRange(double& u, double& v, bool /*emulateCCWXY*/) const { - Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); - - gp_Pnt center = p->Axis().Location(); - gp_Dir normal = p->Axis().Direction(); - gp_Dir xdir = p->XAxis().Direction(); - - gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method - - return -xdir.AngleWithRef(xdirref.XDirection(),normal); - -} - -void GeomArcOfParabola::setAngleXU(double angle) -{ - Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); - +#if 0 try { - gp_Pnt center = p->Axis().Location(); - gp_Dir normal = p->Axis().Direction(); - - gp_Ax1 normaxis(center, normal); - - gp_Ax2 xdirref(center, normal); - - xdirref.Rotate(normaxis,angle); - - p->SetPosition(xdirref); - + if (emulateCCWXY) { + if (isReversed()) { + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); + assert(!c.IsNull()); + c->Reverse(); + } + } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); throw Base::Exception(e->GetMessageString()); } -} +#endif -void GeomArcOfParabola::getRange(double& u, double& v) const -{ u = myCurve->FirstParameter(); v = myCurve->LastParameter(); } -void GeomArcOfParabola::setRange(double u, double v) +void GeomArcOfParabola::setRange(double u, double v, bool /*emulateCCWXY*/) { try { myCurve->SetTrim(u, v); +#if 0 + if (emulateCCWXY) { + if (isReversed()) { + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); + assert(!c.IsNull()); + c->Reverse(); + } + } +#endif } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 5ed99d1c1b..7652f324b6 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -212,6 +212,7 @@ private: class PartExport GeomConic : public GeomCurve { TYPESYSTEM_HEADER(); + protected: GeomConic(); @@ -241,6 +242,46 @@ public: const Handle_Geom_Geometry& handle() const = 0; }; +class PartExport GeomArcOfConic : public GeomCurve +{ + TYPESYSTEM_HEADER(); + +protected: + GeomArcOfConic(); + +public: + virtual ~GeomArcOfConic(); + virtual Geometry *clone(void) const = 0; + + Base::Vector3d getStartPoint(bool emulateCCWXY=false) const; + Base::Vector3d getEndPoint(bool emulateCCWXY=false) const; + + /*! + * \deprecated use getLocation + * \brief getCenter + */ + Base::Vector3d getCenter(void) const; + Base::Vector3d getLocation(void) const; + void setLocation(const Base::Vector3d& Center); + /*! + * \deprecated use setLocation + * \brief setCenter + */ + void setCenter(const Base::Vector3d& Center); + + virtual void getRange(double& u, double& v, bool emulateCCWXY) const = 0; + virtual void setRange(double u, double v, bool emulateCCWXY) = 0; + + bool isReversed() const; + double getAngleXU(void) const; + void setAngleXU(double angle); + + virtual unsigned int getMemSize(void) const = 0; + virtual PyObject *getPyObject(void) = 0; + + const Handle_Geom_Geometry& handle() const = 0; +}; + class PartExport GeomCircle : public GeomConic { TYPESYSTEM_HEADER(); @@ -266,7 +307,7 @@ private: Handle_Geom_Circle myCurve; }; -class PartExport GeomArcOfCircle : public GeomCurve +class PartExport GeomArcOfCircle : public GeomArcOfConic { TYPESYSTEM_HEADER(); public: @@ -275,16 +316,11 @@ public: virtual ~GeomArcOfCircle(); virtual Geometry *clone(void) const; - Base::Vector3d getStartPoint(bool emulateCCWXY) const; - Base::Vector3d getEndPoint(bool emulateCCWXY) const; - - Base::Vector3d getCenter(void) const; double getRadius(void) const; - void setCenter(const Base::Vector3d& Center); void setRadius(double Radius); - void getRange(double& u, double& v, bool emulateCCWXY) const; - void setRange(double u, double v, bool emulateCCWXY); - bool isReversedInXY() const; + + virtual void getRange(double& u, double& v, bool emulateCCWXY) const; + virtual void setRange(double u, double v, bool emulateCCWXY); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -330,7 +366,7 @@ private: Handle_Geom_Ellipse myCurve; }; -class PartExport GeomArcOfEllipse : public GeomCurve +class PartExport GeomArcOfEllipse : public GeomArcOfConic { TYPESYSTEM_HEADER(); public: @@ -339,23 +375,15 @@ public: virtual ~GeomArcOfEllipse(); virtual Geometry *clone(void) const; - Base::Vector3d getStartPoint(bool emulateCCWXY) const; - Base::Vector3d getEndPoint(bool emulateCCWXY) const; - - Base::Vector3d getCenter(void) const; - void setCenter(const Base::Vector3d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; void setMinorRadius(double Radius); - double getAngleXU(void) const; - void setAngleXU(double angle); Base::Vector3d getMajorAxisDir() const; void setMajorAxisDir(Base::Vector3d newdir); - bool isReversedInXY() const; - void getRange(double& u, double& v, bool emulateCCWXY) const; - void setRange(double u, double v, bool emulateCCWXY); + virtual void getRange(double& u, double& v, bool emulateCCWXY) const; + virtual void setRange(double u, double v, bool emulateCCWXY); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -399,7 +427,7 @@ private: Handle_Geom_Hyperbola myCurve; }; -class PartExport GeomArcOfHyperbola : public GeomCurve +class PartExport GeomArcOfHyperbola : public GeomArcOfConic { TYPESYSTEM_HEADER(); public: @@ -408,23 +436,15 @@ public: virtual ~GeomArcOfHyperbola(); virtual Geometry *clone(void) const; - Base::Vector3d getStartPoint() const; - Base::Vector3d getEndPoint() const; - - Base::Vector3d getCenter(void) const; - void setCenter(const Base::Vector3d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; void setMinorRadius(double Radius); - double getAngleXU(void) const; - void setAngleXU(double angle); Base::Vector3d getMajorAxisDir() const; void setMajorAxisDir(Base::Vector3d newdir); - bool isReversedInXY() const; - - void getRange(double& u, double& v, bool emulateCCWXY) const; - void setRange(double u, double v, bool emulateCCWXY); + + virtual void getRange(double& u, double& v, bool emulateCCWXY) const; + virtual void setRange(double u, double v, bool emulateCCWXY); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -465,7 +485,7 @@ private: Handle_Geom_Parabola myCurve; }; -class PartExport GeomArcOfParabola : public GeomCurve +class PartExport GeomArcOfParabola : public GeomArcOfConic { TYPESYSTEM_HEADER(); public: @@ -474,18 +494,11 @@ public: virtual ~GeomArcOfParabola(); virtual Geometry *clone(void) const; - Base::Vector3d getStartPoint() const; - Base::Vector3d getEndPoint() const; - - Base::Vector3d getCenter(void) const; - void setCenter(const Base::Vector3d& Center); double getFocal(void) const; void setFocal(double length); - double getAngleXU(void) const; - void setAngleXU(double angle); - void getRange(double& u, double& v) const; - void setRange(double u, double v); + virtual void getRange(double& u, double& v, bool emulateCCWXY) const; + virtual void setRange(double u, double v, bool emulateCCWXY); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 6fd278fbb3..e2b1af8854 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -4454,7 +4454,7 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze) Part::Geometry* g = this->ExternalGeo[-geoId-1]; if (g->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()){ const Part::GeomArcOfCircle *segm = static_cast(g); - if(segm->isReversedInXY()){ + if (segm->isReversed()){ //Gotcha! a link to an endpoint of external arc that is reversed. //create a constraint copy, affect it, replace the pointer if (!affected) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp index 904f1dd72b..b0efa84396 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp @@ -388,7 +388,7 @@ void SketcherValidation::on_findReversed_clicked() //only arcs of circles need to be repaired. Arcs of ellipse were so broken there should be nothing to repair from. if (g->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { const Part::GeomArcOfCircle *segm = static_cast(g); - if(segm->isReversedInXY()){ + if (segm->isReversed()) { points.push_back(segm->getStartPoint(/*emulateCCW=*/true)); points.push_back(segm->getEndPoint(/*emulateCCW=*/true)); }