add class GeomArcOfConic to reduce code duplication

This commit is contained in:
wmayer
2016-12-04 14:20:56 +01:00
parent 4ba8b565dc
commit 273f3995c0
18 changed files with 595 additions and 799 deletions

View File

@@ -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();

View File

@@ -1,14 +1,14 @@
<?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"
Father="ArcOfConicPy"
Name="ArcOfCirclePy"
PythonName="Part.ArcOfCircle"
Twin="GeomArcOfCircle"
TwinPointer="GeomArcOfCircle"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
FatherInclude="Mod/Part/App/ArcOfConicPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
@@ -21,18 +21,6 @@
</Documentation>
<Parameter Name="Radius" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the circle.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Circle" ReadOnly="true">
<Documentation>
<UserDocu>The internal circle representation</UserDocu>

View File

@@ -30,10 +30,10 @@
# include <Geom_TrimmedCurve.hxx>
#endif
#include "Mod/Part/App/Geometry.h"
#include "ArcOfCirclePy.h"
#include "ArcOfCirclePy.cpp"
#include "CirclePy.h"
#include "Geometry.h"
#include <Mod/Part/App/ArcOfCirclePy.h>
#include <Mod/Part/App/ArcOfCirclePy.cpp>
#include <Mod/Part/App/CirclePy.h>
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
@@ -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<Base::VectorPy*>(p)->value();
getGeomArcOfCirclePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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

View File

@@ -0,0 +1,55 @@
<?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="ArcOfConicPy"
PythonName="Part.ArcOfConic"
Twin="GeomArcOfConic"
TwinPointer="GeomArcOfConic"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Abdullah Tahiri" EMail="abdullah.tahiri.yo[at]gmail.com" />
<UserDocu>Describes a portion of a conic</UserDocu>
</Documentation>
<Attribute Name="Location" ReadOnly="false">
<Documentation>
<UserDocu>Center of the conic.</UserDocu>
</Documentation>
<Parameter Name="Location" Type="Object"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Deprecated -- use Location.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the conic.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the conic</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="XAxis" ReadOnly="false">
<Documentation>
<UserDocu>The X axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="XAxis" Type="Object"/>
</Attribute>
<Attribute Name="YAxis" ReadOnly="false">
<Documentation>
<UserDocu>The Y axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="YAxis" Type="Object"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,243 @@
/***************************************************************************
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
* *
* 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 <Geom_TrimmedCurve.hxx>
#endif
#include "Geometry.h"
#include <Mod/Part/App/ArcOfConicPy.h>
#include <Mod/Part/App/ArcOfConicPy.cpp>
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string ArcOfConicPy::representation(void) const
{
return "<ArcOfConic object>";
}
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<Base::VectorPy*>(p)->value();
getGeomArcOfConicPtr()->setLocation(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
getGeomArcOfConicPtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@@ -1,14 +1,14 @@
<?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"
Father="ArcOfConicPy"
Name="ArcOfEllipsePy"
PythonName="Part.ArcOfEllipse"
Twin="GeomArcOfEllipse"
TwinPointer="GeomArcOfEllipse"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
FatherInclude="Mod/Part/App/ArcOfConicPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
@@ -27,24 +27,6 @@
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the ellipse</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Ellipse" ReadOnly="true">
<Documentation>
<UserDocu>The internal ellipse representation</UserDocu>

View File

@@ -30,10 +30,10 @@
# include <Geom_TrimmedCurve.hxx>
#endif
#include "Mod/Part/App/Geometry.h"
#include "ArcOfEllipsePy.h"
#include "ArcOfEllipsePy.cpp"
#include "EllipsePy.h"
#include "Geometry.h"
#include <Mod/Part/App/ArcOfEllipsePy.h>
#include <Mod/Part/App/ArcOfEllipsePy.cpp>
#include <Mod/Part/App/EllipsePy.h>
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
@@ -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<Base::VectorPy*>(p)->value();
getGeomArcOfEllipsePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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

View File

@@ -1,14 +1,14 @@
<?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"
Father="ArcOfConicPy"
Name="ArcOfHyperbolaPy"
PythonName="Part.ArcOfHyperbola"
Twin="GeomArcOfHyperbola"
TwinPointer="GeomArcOfHyperbola"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
FatherInclude="Mod/Part/App/ArcOfConicPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
@@ -27,24 +27,6 @@
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the hyperbola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Hyperbola" ReadOnly="true">
<Documentation>
<UserDocu>The internal hyperbola representation</UserDocu>

View File

@@ -30,10 +30,10 @@
# include <Geom_TrimmedCurve.hxx>
#endif
#include "Mod/Part/App/Geometry.h"
#include "ArcOfHyperbolaPy.h"
#include "ArcOfHyperbolaPy.cpp"
#include "HyperbolaPy.h"
#include "Geometry.h"
#include <Mod/Part/App/ArcOfHyperbolaPy.h>
#include <Mod/Part/App/ArcOfHyperbolaPy.cpp>
#include <Mod/Part/App/HyperbolaPy.h>
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
@@ -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<Base::VectorPy*>(p)->value();
getGeomArcOfHyperbolaPtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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

View File

@@ -1,14 +1,14 @@
<?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"
Father="ArcOfConicPy"
Name="ArcOfParabolaPy"
PythonName="Part.ArcOfParabola"
Twin="GeomArcOfParabola"
TwinPointer="GeomArcOfParabola"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
FatherInclude="Mod/Part/App/ArcOfConicPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
@@ -20,24 +20,6 @@
<UserDocu>The focal length of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Focal" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the parabola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the parabola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Parabola" ReadOnly="true">
<Documentation>

View File

@@ -30,10 +30,10 @@
# include <Geom_TrimmedCurve.hxx>
#endif
#include "Mod/Part/App/Geometry.h"
#include "ArcOfParabolaPy.h"
#include "ArcOfParabolaPy.cpp"
#include "ParabolaPy.h"
#include "Geometry.h"
#include <Mod/Part/App/ArcOfParabolaPy.h>
#include <Mod/Part/App/ArcOfParabolaPy.cpp>
#include <Mod/Part/App/ParabolaPy.h>
#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
@@ -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<Base::VectorPy*>(p)->value();
getGeomArcOfParabolaPtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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

View File

@@ -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

View File

@@ -23,7 +23,7 @@
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Deprecated. Use Location.</UserDocu>
<UserDocu>Deprecated -- use Location.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>

View File

@@ -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

View File

@@ -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<GeomArcOfEllipse*>(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();

View File

@@ -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;

View File

@@ -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<const Part::GeomArcOfCircle*>(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)

View File

@@ -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<const Part::GeomArcOfCircle*>(g);
if(segm->isReversedInXY()){
if (segm->isReversed()) {
points.push_back(segm->getStartPoint(/*emulateCCW=*/true));
points.push_back(segm->getEndPoint(/*emulateCCW=*/true));
}