Part Module New Feature: Hyperbola & ArcOfHyperbola
- Completed Hyperbola c++ implementation and python wrapper - Created ArOfHyperbola c++ and python wrapper implementation
This commit is contained in:
committed by
Sebastian Hoogen
parent
6997cc9991
commit
75377ebfd3
@@ -68,6 +68,7 @@
|
||||
#include "ArcOfCirclePy.h"
|
||||
#include "ArcOfEllipsePy.h"
|
||||
#include "ArcOfParabolaPy.h"
|
||||
#include "ArcOfHyperbolaPy.h"
|
||||
#include "BezierCurvePy.h"
|
||||
#include "BSplineCurvePy.h"
|
||||
#include "HyperbolaPy.h"
|
||||
@@ -176,6 +177,7 @@ void PartExport initPart()
|
||||
Base::Interpreter().addType(&Part::ArcOfCirclePy ::Type,partModule,"ArcOfCircle");
|
||||
Base::Interpreter().addType(&Part::ArcOfEllipsePy ::Type,partModule,"ArcOfEllipse");
|
||||
Base::Interpreter().addType(&Part::ArcOfParabolaPy ::Type,partModule,"ArcOfParabola");
|
||||
Base::Interpreter().addType(&Part::ArcOfHyperbolaPy ::Type,partModule,"ArcOfHyperbola");
|
||||
Base::Interpreter().addType(&Part::BezierCurvePy ::Type,partModule,"BezierCurve");
|
||||
Base::Interpreter().addType(&Part::BSplineCurvePy ::Type,partModule,"BSplineCurve");
|
||||
Base::Interpreter().addType(&Part::OffsetCurvePy ::Type,partModule,"OffsetCurve");
|
||||
@@ -267,6 +269,7 @@ void PartExport initPart()
|
||||
Part::GeomArcOfCircle ::init();
|
||||
Part::GeomArcOfEllipse ::init();
|
||||
Part::GeomArcOfParabola ::init();
|
||||
Part::GeomArcOfHyperbola ::init();
|
||||
Part::GeomEllipse ::init();
|
||||
Part::GeomHyperbola ::init();
|
||||
Part::GeomParabola ::init();
|
||||
|
||||
54
src/Mod/Part/App/ArcOfHyperbolaPy.xml
Normal file
54
src/Mod/Part/App/ArcOfHyperbolaPy.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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="ArcOfHyperbolaPy"
|
||||
Twin="GeomArcOfHyperbola"
|
||||
TwinPointer="GeomArcOfHyperbola"
|
||||
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 an hyperbola</UserDocu>
|
||||
</Documentation>
|
||||
<Attribute Name="MajorRadius" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The major radius of the hyperbola.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="MajorRadius" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="MinorRadius" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The minor radius of the hyperbola.</UserDocu>
|
||||
</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>
|
||||
</Documentation>
|
||||
<Parameter Name="Hyperbola" Type="Object"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
233
src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp
Normal file
233
src/Mod/Part/App/ArcOfHyperbolaPyImp.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
/***************************************************************************
|
||||
* 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 <gp_Hypr.hxx>
|
||||
# include <Geom_Hyperbola.hxx>
|
||||
# include <GC_MakeArcOfHyperbola.hxx>
|
||||
# include <GC_MakeHyperbola.hxx>
|
||||
# include <Geom_TrimmedCurve.hxx>
|
||||
#endif
|
||||
|
||||
#include "Mod/Part/App/Geometry.h"
|
||||
#include "ArcOfHyperbolaPy.h"
|
||||
#include "ArcOfHyperbolaPy.cpp"
|
||||
#include "HyperbolaPy.h"
|
||||
#include "OCCError.h"
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
extern const char* gce_ErrorStatusText(gce_ErrorType et);
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ArcOfHyperbolaPy::representation(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();
|
||||
gp_Pnt loc = axis.Location();
|
||||
Standard_Real fMajRad = hyperbola->MajorRadius();
|
||||
Standard_Real fMinRad = hyperbola->MinorRadius();
|
||||
Standard_Real u1 = trim->FirstParameter();
|
||||
Standard_Real u2 = trim->LastParameter();
|
||||
|
||||
gp_Dir normal = hyperbola->Axis().Direction();
|
||||
gp_Dir xdir = hyperbola->XAxis().Direction();
|
||||
|
||||
gp_Ax2 xdirref(loc, normal); // this is a reference XY for the hyperbola
|
||||
|
||||
Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
|
||||
|
||||
|
||||
std::stringstream str;
|
||||
str << "ArcOfHyperbola (";
|
||||
str << "MajorRadius : " << fMajRad << ", ";
|
||||
str << "MinorRadius : " << fMinRad << ", ";
|
||||
str << "AngleXU : " << fAngleXU << ", ";
|
||||
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
|
||||
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
|
||||
str << "Parameter : (" << u1 << ", " << u2 << ")";
|
||||
str << ")";
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject *ArcOfHyperbolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of ArcOfHyperbolaPy and the Twin object
|
||||
return new ArcOfHyperbolaPy(new GeomArcOfHyperbola);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int ArcOfHyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
PyObject* o;
|
||||
double u1, u2;
|
||||
PyObject *sense=Py_True;
|
||||
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
|
||||
try {
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast
|
||||
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
|
||||
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
|
||||
if (!arc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
getGeomArcOfHyperbolaPtr()->setHandle(arc.Value());
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// All checks failed
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"ArcOfHyperbola constructor expects an hyperbola curve and a parameter range");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py::Float ArcOfHyperbolaPy::getMajorRadius(void) const
|
||||
{
|
||||
return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius());
|
||||
}
|
||||
|
||||
void ArcOfHyperbolaPy::setMajorRadius(Py::Float arg)
|
||||
{
|
||||
getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float ArcOfHyperbolaPy::getMinorRadius(void) const
|
||||
{
|
||||
return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius());
|
||||
}
|
||||
|
||||
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
|
||||
(getGeomArcOfHyperbolaPtr()->handle());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve());
|
||||
return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true);
|
||||
}
|
||||
|
||||
PyObject *ArcOfHyperbolaPy::getCustomAttributes(const char* attr) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ArcOfHyperbolaPy::setCustomAttributes(const char* attr, PyObject *obj)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -33,6 +33,11 @@
|
||||
# include <GC_MakeArcOfCircle.hxx>
|
||||
# include <GC_MakeArcOfEllipse.hxx>
|
||||
# include <GC_MakeArcOfParabola.hxx>
|
||||
# include <gp_Hypr.hxx>
|
||||
# include <Geom_Hyperbola.hxx>
|
||||
# include <Geom_TrimmedCurve.hxx>
|
||||
# include <GC_MakeArcOfCircle.hxx>
|
||||
# include <GC_MakeArcOfHyperbola.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -41,6 +46,7 @@
|
||||
#include "CirclePy.h"
|
||||
#include "EllipsePy.h"
|
||||
#include "ParabolaPy.h"
|
||||
#include "HyperbolaPy.h"
|
||||
#include "OCCError.h"
|
||||
|
||||
#include <Base/VectorPy.h>
|
||||
@@ -164,6 +170,32 @@ int ArcPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
|
||||
try {
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast
|
||||
(static_cast<HyperbolaPy*>(o)->getGeomHyperbolaPtr()->handle());
|
||||
GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
|
||||
if (!arc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
getGeomTrimmedCurvePtr()->setHandle(arc.Value());
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(PartExceptionOCCError, "creation of arc failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// All checks failed
|
||||
PyErr_SetString(PyExc_TypeError, "Arc constructor expects a conic curve and a parameter range");
|
||||
return -1;
|
||||
|
||||
@@ -44,6 +44,7 @@ generate_from_xml(CirclePy)
|
||||
generate_from_xml(ArcOfEllipsePy)
|
||||
generate_from_xml(EllipsePy)
|
||||
generate_from_xml(HyperbolaPy)
|
||||
generate_from_xml(ArcOfHyperbolaPy)
|
||||
generate_from_xml(ParabolaPy)
|
||||
generate_from_xml(OffsetCurvePy)
|
||||
generate_from_xml(GeometryPy)
|
||||
@@ -158,6 +159,8 @@ SET(Python_SRCS
|
||||
EllipsePyImp.cpp
|
||||
HyperbolaPy.xml
|
||||
HyperbolaPyImp.cpp
|
||||
ArcOfHyperbolaPy.xml
|
||||
ArcOfHyperbolaPyImp.cpp
|
||||
ParabolaPy.xml
|
||||
ParabolaPyImp.cpp
|
||||
OffsetCurvePy.xml
|
||||
|
||||
@@ -82,6 +82,8 @@
|
||||
# include <GC_MakeEllipse.hxx>
|
||||
# include <gce_MakeParab.hxx>
|
||||
# include <GC_MakeArcOfParabola.hxx>
|
||||
# include <GC_MakeHyperbola.hxx>
|
||||
# include <GC_MakeArcOfHyperbola.hxx>
|
||||
# include <GC_MakeLine.hxx>
|
||||
# include <GC_MakeSegment.hxx>
|
||||
# include <Precision.hxx>
|
||||
@@ -98,6 +100,7 @@
|
||||
#include "BezierCurvePy.h"
|
||||
#include "BSplineCurvePy.h"
|
||||
#include "HyperbolaPy.h"
|
||||
#include "ArcOfHyperbolaPy.h"
|
||||
#include "OffsetCurvePy.h"
|
||||
#include "ParabolaPy.h"
|
||||
#include "BezierSurfacePy.h"
|
||||
@@ -1313,16 +1316,441 @@ Geometry *GeomHyperbola::clone(void) const
|
||||
return newHyp;
|
||||
}
|
||||
|
||||
Base::Vector3d GeomHyperbola::getCenter(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
gp_Ax1 axis = h->Axis();
|
||||
const gp_Pnt& loc = axis.Location();
|
||||
return Base::Vector3d(loc.X(),loc.Y(),loc.Z());
|
||||
}
|
||||
|
||||
void GeomHyperbola::setCenter(const Base::Vector3d& Center)
|
||||
{
|
||||
gp_Pnt p1(Center.x,Center.y,Center.z);
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
|
||||
try {
|
||||
h->SetLocation(p1);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
double GeomHyperbola::getMajorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
return h->MajorRadius();
|
||||
}
|
||||
|
||||
void GeomHyperbola::setMajorRadius(double Radius)
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
|
||||
try {
|
||||
h->SetMajorRadius(Radius);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
double GeomHyperbola::getMinorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
return h->MinorRadius();
|
||||
}
|
||||
|
||||
void GeomHyperbola::setMinorRadius(double Radius)
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(handle());
|
||||
|
||||
try {
|
||||
h->SetMinorRadius(Radius);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
double GeomHyperbola::getAngleXU(void) const
|
||||
{
|
||||
gp_Pnt center = this->myCurve->Axis().Location();
|
||||
gp_Dir normal = this->myCurve->Axis().Direction();
|
||||
gp_Dir xdir = this->myCurve->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 GeomHyperbola::setAngleXU(double angle)
|
||||
{
|
||||
try {
|
||||
gp_Pnt center = this->myCurve->Axis().Location();
|
||||
gp_Dir normal = this->myCurve->Axis().Direction();
|
||||
|
||||
gp_Ax1 normaxis(center, normal);
|
||||
|
||||
gp_Ax2 xdirref(center, normal);
|
||||
|
||||
xdirref.Rotate(normaxis,angle);
|
||||
|
||||
this->myCurve->SetPosition(xdirref);
|
||||
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
// Persistence implementer
|
||||
unsigned int GeomHyperbola::getMemSize (void) const {assert(0); return 0;/* not implemented yet */}
|
||||
void GeomHyperbola::Save (Base::Writer &/*writer*/) const {assert(0); /* not implemented yet */}
|
||||
void GeomHyperbola::Restore (Base::XMLReader &/*reader*/) {assert(0); /* not implemented yet */}
|
||||
unsigned int GeomHyperbola::getMemSize (void) const
|
||||
{
|
||||
return sizeof(Geom_Hyperbola);
|
||||
}
|
||||
|
||||
void GeomHyperbola::Save(Base::Writer& writer) const
|
||||
{
|
||||
// save the attributes of the father class
|
||||
GeomCurve::Save(writer);
|
||||
|
||||
gp_Pnt center = this->myCurve->Axis().Location();
|
||||
gp_Dir normal = this->myCurve->Axis().Direction();
|
||||
gp_Dir xdir = this->myCurve->XAxis().Direction();
|
||||
|
||||
gp_Ax2 xdirref(center, normal); // this is a reference XY for the ellipse
|
||||
|
||||
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
|
||||
|
||||
writer.Stream()
|
||||
<< writer.ind()
|
||||
<< "<Hyperbola "
|
||||
<< "CenterX=\"" << center.X() << "\" "
|
||||
<< "CenterY=\"" << center.Y() << "\" "
|
||||
<< "CenterZ=\"" << center.Z() << "\" "
|
||||
<< "NormalX=\"" << normal.X() << "\" "
|
||||
<< "NormalY=\"" << normal.Y() << "\" "
|
||||
<< "NormalZ=\"" << normal.Z() << "\" "
|
||||
<< "MajorRadius=\"" << this->myCurve->MajorRadius() << "\" "
|
||||
<< "MinorRadius=\"" << this->myCurve->MinorRadius() << "\" "
|
||||
<< "AngleXU=\"" << AngleXU << "\" "
|
||||
<< "/>" << endl;
|
||||
}
|
||||
|
||||
void GeomHyperbola::Restore(Base::XMLReader& reader)
|
||||
{
|
||||
// read the attributes of the father class
|
||||
GeomCurve::Restore(reader);
|
||||
|
||||
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU;
|
||||
// read my Element
|
||||
reader.readElement("Hyperbola");
|
||||
// get the value of my Attribute
|
||||
CenterX = reader.getAttributeAsFloat("CenterX");
|
||||
CenterY = reader.getAttributeAsFloat("CenterY");
|
||||
CenterZ = reader.getAttributeAsFloat("CenterZ");
|
||||
NormalX = reader.getAttributeAsFloat("NormalX");
|
||||
NormalY = reader.getAttributeAsFloat("NormalY");
|
||||
NormalZ = reader.getAttributeAsFloat("NormalZ");
|
||||
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
|
||||
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
|
||||
AngleXU = reader.getAttributeAsFloat("AngleXU");
|
||||
|
||||
// set the read geometry
|
||||
gp_Pnt p1(CenterX,CenterY,CenterZ);
|
||||
gp_Dir norm(NormalX,NormalY,NormalZ);
|
||||
|
||||
gp_Ax1 normaxis(p1,norm);
|
||||
|
||||
gp_Ax2 xdir(p1, norm);
|
||||
|
||||
xdir.Rotate(normaxis,AngleXU);
|
||||
|
||||
try {
|
||||
GC_MakeHyperbola mc(xdir, MajorRadius, MinorRadius);
|
||||
if (!mc.IsDone())
|
||||
throw Base::Exception(gce_ErrorStatusText(mc.Status()));
|
||||
|
||||
this->myCurve = mc.Value();
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *GeomHyperbola::getPyObject(void)
|
||||
{
|
||||
return new HyperbolaPy((GeomHyperbola*)this->clone());
|
||||
}
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomArcOfHyperbola,Part::GeomCurve);
|
||||
|
||||
GeomArcOfHyperbola::GeomArcOfHyperbola()
|
||||
{
|
||||
gp_Ax2 ax2 = gp_Ax2();
|
||||
Handle_Geom_Hyperbola h = new Geom_Hyperbola(gp_Hypr(ax2, 1,1));
|
||||
this->myCurve = new Geom_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
|
||||
}
|
||||
|
||||
GeomArcOfHyperbola::GeomArcOfHyperbola(const Handle_Geom_Hyperbola& h)
|
||||
{
|
||||
this->myCurve = new Geom_TrimmedCurve(h, h->FirstParameter(),h->LastParameter());
|
||||
}
|
||||
|
||||
GeomArcOfHyperbola::~GeomArcOfHyperbola()
|
||||
{
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::setHandle(const Handle_Geom_TrimmedCurve& c)
|
||||
{
|
||||
Handle_Geom_Hyperbola basis = Handle_Geom_Hyperbola::DownCast(c->BasisCurve());
|
||||
if (basis.IsNull())
|
||||
Standard_Failure::Raise("Basis curve is not an hyperbola");
|
||||
this->myCurve = Handle_Geom_TrimmedCurve::DownCast(c->Copy());
|
||||
}
|
||||
|
||||
const Handle_Geom_Geometry& GeomArcOfHyperbola::handle() const
|
||||
{
|
||||
return myCurve;
|
||||
}
|
||||
|
||||
Geometry *GeomArcOfHyperbola::clone(void) const
|
||||
{
|
||||
GeomArcOfHyperbola* copy = new GeomArcOfHyperbola();
|
||||
copy->setHandle(this->myCurve);
|
||||
copy->Construction = this->Construction;
|
||||
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());
|
||||
return h->MajorRadius();
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::setMajorRadius(double Radius)
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve());
|
||||
|
||||
try {
|
||||
h->SetMajorRadius(Radius);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
double GeomArcOfHyperbola::getMinorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve());
|
||||
return h->MinorRadius();
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::setMinorRadius(double Radius)
|
||||
{
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve());
|
||||
|
||||
try {
|
||||
h->SetMinorRadius(Radius);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::getRange(double& u, double& v) const
|
||||
{
|
||||
u = myCurve->FirstParameter();
|
||||
v = myCurve->LastParameter();
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::setRange(double u, double v)
|
||||
{
|
||||
try {
|
||||
myCurve->SetTrim(u, v);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
// Persistence implementer
|
||||
unsigned int GeomArcOfHyperbola::getMemSize (void) const
|
||||
{
|
||||
return sizeof(Geom_Hyperbola) + 2 *sizeof(double);
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::Save(Base::Writer &writer) const
|
||||
{
|
||||
// save the attributes of the father class
|
||||
GeomCurve::Save(writer);
|
||||
|
||||
Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(this->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 XY for the ellipse
|
||||
|
||||
double AngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
|
||||
|
||||
writer.Stream()
|
||||
<< writer.ind()
|
||||
<< "<ArcOfHyperbola "
|
||||
<< "CenterX=\"" << center.X() << "\" "
|
||||
<< "CenterY=\"" << center.Y() << "\" "
|
||||
<< "CenterZ=\"" << center.Z() << "\" "
|
||||
<< "NormalX=\"" << normal.X() << "\" "
|
||||
<< "NormalY=\"" << normal.Y() << "\" "
|
||||
<< "NormalZ=\"" << normal.Z() << "\" "
|
||||
<< "MajorRadius=\"" << h->MajorRadius() << "\" "
|
||||
<< "MinorRadius=\"" << h->MinorRadius() << "\" "
|
||||
<< "AngleXU=\"" << AngleXU << "\" "
|
||||
<< "StartAngle=\"" << this->myCurve->FirstParameter() << "\" "
|
||||
<< "EndAngle=\"" << this->myCurve->LastParameter() << "\" "
|
||||
<< "/>" << endl;
|
||||
}
|
||||
|
||||
void GeomArcOfHyperbola::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
// read the attributes of the father class
|
||||
GeomCurve::Restore(reader);
|
||||
|
||||
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius,AngleXU,StartAngle,EndAngle;
|
||||
// read my Element
|
||||
reader.readElement("ArcOfHyperbola");
|
||||
// get the value of my Attribute
|
||||
CenterX = reader.getAttributeAsFloat("CenterX");
|
||||
CenterY = reader.getAttributeAsFloat("CenterY");
|
||||
CenterZ = reader.getAttributeAsFloat("CenterZ");
|
||||
NormalX = reader.getAttributeAsFloat("NormalX");
|
||||
NormalY = reader.getAttributeAsFloat("NormalY");
|
||||
NormalZ = reader.getAttributeAsFloat("NormalZ");
|
||||
MajorRadius = reader.getAttributeAsFloat("MajorRadius");
|
||||
MinorRadius = reader.getAttributeAsFloat("MinorRadius");
|
||||
AngleXU = reader.getAttributeAsFloat("AngleXU");
|
||||
StartAngle = reader.getAttributeAsFloat("StartAngle");
|
||||
EndAngle = reader.getAttributeAsFloat("EndAngle");
|
||||
|
||||
|
||||
// set the read geometry
|
||||
gp_Pnt p1(CenterX,CenterY,CenterZ);
|
||||
gp_Dir norm(NormalX,NormalY,NormalZ);
|
||||
|
||||
gp_Ax1 normaxis(p1,norm);
|
||||
|
||||
gp_Ax2 xdir(p1, norm);
|
||||
|
||||
xdir.Rotate(normaxis,AngleXU);
|
||||
|
||||
try {
|
||||
GC_MakeHyperbola mc(xdir, MajorRadius, MinorRadius);
|
||||
if (!mc.IsDone())
|
||||
throw Base::Exception(gce_ErrorStatusText(mc.Status()));
|
||||
|
||||
GC_MakeArcOfHyperbola ma(mc.Value()->Hypr(), StartAngle, EndAngle, 1);
|
||||
if (!ma.IsDone())
|
||||
throw Base::Exception(gce_ErrorStatusText(ma.Status()));
|
||||
|
||||
Handle_Geom_TrimmedCurve tmpcurve = ma.Value();
|
||||
Handle_Geom_Hyperbola tmphyperbola = Handle_Geom_Hyperbola::DownCast(tmpcurve->BasisCurve());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(this->myCurve->BasisCurve());
|
||||
|
||||
hyperbola->SetHypr(tmphyperbola->Hypr());
|
||||
this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter());
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
throw Base::Exception(e->GetMessageString());
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *GeomArcOfHyperbola::getPyObject(void)
|
||||
{
|
||||
return new ArcOfHyperbolaPy(static_cast<GeomArcOfHyperbola*>(this->clone()));
|
||||
}
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomParabola,Part::GeomCurve);
|
||||
|
||||
@@ -307,6 +307,15 @@ public:
|
||||
GeomHyperbola(const Handle_Geom_Hyperbola&);
|
||||
virtual ~GeomHyperbola();
|
||||
virtual Geometry *clone(void) 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);
|
||||
|
||||
// Persistence implementer ---------------------
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
@@ -321,6 +330,44 @@ private:
|
||||
Handle_Geom_Hyperbola myCurve;
|
||||
};
|
||||
|
||||
class PartExport GeomArcOfHyperbola : public GeomCurve
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
public:
|
||||
GeomArcOfHyperbola();
|
||||
GeomArcOfHyperbola(const Handle_Geom_Hyperbola&);
|
||||
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);
|
||||
|
||||
void getRange(double& u, double& v) const;
|
||||
void setRange(double u, double v);
|
||||
|
||||
// Persistence implementer ---------------------
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
virtual void Save(Base::Writer &/*writer*/) const;
|
||||
virtual void Restore(Base::XMLReader &/*reader*/);
|
||||
// Base implementer ----------------------------
|
||||
virtual PyObject *getPyObject(void);
|
||||
|
||||
void setHandle(const Handle_Geom_TrimmedCurve&);
|
||||
const Handle_Geom_Geometry& handle() const;
|
||||
|
||||
private:
|
||||
Handle_Geom_TrimmedCurve myCurve;
|
||||
};
|
||||
|
||||
class PartExport GeomParabola : public GeomCurve
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
|
||||
@@ -1,80 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?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="HyperbolaPy"
|
||||
Twin="GeomHyperbola"
|
||||
TwinPointer="GeomHyperbola"
|
||||
Include="Mod/Part/App/Geometry.h"
|
||||
Namespace="Part"
|
||||
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
|
||||
<PythonExport
|
||||
Father="GeometryCurvePy"
|
||||
Name="HyperbolaPy"
|
||||
Twin="GeomHyperbola"
|
||||
TwinPointer="GeomHyperbola"
|
||||
Include="Mod/Part/App/Geometry.h"
|
||||
Namespace="Part"
|
||||
FatherInclude="Mod/Part/App/GeometryCurvePy.h"
|
||||
FatherNamespace="Part"
|
||||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>Describes a hyperbola in 3D space
|
||||
To create a hyperbola there are several ways:
|
||||
<UserDocu>Describes an hyperbola in 3D space
|
||||
To create an hyperbola there are several ways:
|
||||
Part.Hyperbola()
|
||||
Creates a hyperbola with major radius 2 and minor radius 1 with the
|
||||
Creates an hyperbola with major radius 2 and minor radius 1 with the
|
||||
center in (0,0,0)
|
||||
|
||||
Part.Hyperbola(Hyperbola)
|
||||
Create a copy of the given hyperbola
|
||||
|
||||
Part.Hyperbola(S1,S2,Center)
|
||||
Creates a hyperbola centered on the point Center, where
|
||||
Creates an hyperbola centered on the point Center, where
|
||||
the plane of the hyperbola is defined by Center, S1 and S2,
|
||||
its major axis is defined by Center and S1,
|
||||
its major radius is the distance between Center and S1, and
|
||||
its minor radius is the distance between S2 and the major axis.
|
||||
|
||||
Part.Hyperbola(Center,MajorRadius,MinorRadius)
|
||||
Creates a hyperbola with major and minor radii MajorRadius and
|
||||
Creates an hyperbola with major and minor radii MajorRadius and
|
||||
MinorRadius, and located in the plane defined by Center and
|
||||
the normal (0,0,1)
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<Attribute Name="Eccentricity" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Computes the eccentricity of this hyperbola, which is a value greater than 1.
|
||||
The eccentricity is:
|
||||
e = f / MajorRadius
|
||||
where f is the focal distance of this hyperbola.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Eccentricity" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focal" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The focal distance is the distance between
|
||||
the center and a focus of the hyperbola</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focal" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focus1" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The first focus is on the positive side of the
|
||||
'X Axis' (major axis) of the hyperbola;
|
||||
the second focus is on the negative side.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focus1" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focus2" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The first focus is on the positive side of the
|
||||
'X Axis' (major axis) of the hyperbola;
|
||||
the second focus is on the negative side.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focus2" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Parameter" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Compute the parameter of this hyperbola
|
||||
which is the distance between its focus
|
||||
and its directrix. This distance is twice the focal length.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Parameter" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="MajorRadius" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The major radius of the hyperbola.</UserDocu>
|
||||
@@ -87,11 +46,46 @@ and its directrix. This distance is twice the focal length.
|
||||
</Documentation>
|
||||
<Parameter Name="MinorRadius" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Location" ReadOnly="false">
|
||||
<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="Eccentricity" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Location of the hyperbola</UserDocu>
|
||||
<UserDocu>The eccentricity of the hyperbola.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Location" Type="Object"/>
|
||||
<Parameter Name="Eccentricity" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focal" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The focal distance of the hyperbola.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focal" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focus1" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The first focus is on the positive side of the major axis of the hyperbola;
|
||||
the second focus is on the negative side.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focus1" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focus2" ReadOnly="true">
|
||||
<Documentation>
|
||||
<Documentation>
|
||||
<UserDocu>The first focus is on the positive side of the major axis of the hyperbola;
|
||||
the second focus is on the negative side.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Documentation>
|
||||
<Parameter Name="Focus2" Type="Object"/>
|
||||
</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>
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <gp_Hypr.hxx>
|
||||
# include <Geom_Hyperbola.hxx>
|
||||
# include <GC_MakeHyperbola.hxx>
|
||||
# include <gp_Hypr.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
#include "OCCError.h"
|
||||
#include "Geometry.h"
|
||||
@@ -57,9 +57,9 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
char* keywords_n[] = {NULL};
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
|
||||
Handle_Geom_Hyperbola hypr = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
hypr->SetMajorRadius(2.0);
|
||||
hypr->SetMinorRadius(1.0);
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetMajorRadius(2.0);
|
||||
hyperbola->SetMinorRadius(1.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
PyErr_Clear();
|
||||
PyObject *pHypr;
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(HyperbolaPy::Type), &pHypr)) {
|
||||
HyperbolaPy* pH = static_cast<HyperbolaPy*>(pHypr);
|
||||
HyperbolaPy* pHyperbola = static_cast<HyperbolaPy*>(pHypr);
|
||||
Handle_Geom_Hyperbola Hypr1 = Handle_Geom_Hyperbola::DownCast
|
||||
(pH->getGeometryPtr()->handle());
|
||||
(pHyperbola->getGeomHyperbolaPtr()->handle());
|
||||
Handle_Geom_Hyperbola Hypr2 = Handle_Geom_Hyperbola::DownCast
|
||||
(this->getGeometryPtr()->handle());
|
||||
(this->getGeomHyperbolaPtr()->handle());
|
||||
Hypr2->SetHypr(Hypr1->Hypr());
|
||||
return 0;
|
||||
}
|
||||
@@ -86,16 +86,16 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
|
||||
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
|
||||
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
|
||||
GC_MakeHyperbola mh(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Pnt(v2.x,v2.y,v2.z),
|
||||
gp_Pnt(v3.x,v3.y,v3.z));
|
||||
if (!mh.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mh.Status()));
|
||||
GC_MakeHyperbola me(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Pnt(v2.x,v2.y,v2.z),
|
||||
gp_Pnt(v3.x,v3.y,v3.z));
|
||||
if (!me.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
hyperb->SetHypr(mh.Value()->Hypr());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetHypr(me.Value()->Hypr());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,15 +107,15 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
&(Base::VectorPy::Type), &pV,
|
||||
&major, &minor)) {
|
||||
Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value();
|
||||
GC_MakeHyperbola mh(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
|
||||
GC_MakeHyperbola me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
|
||||
major, minor);
|
||||
if (!mh.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mh.Status()));
|
||||
if (!me.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Hyperbola hyperb = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
hyperb->SetHypr(mh.Value()->Hypr());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetHypr(me.Value()->Hypr());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -127,90 +127,111 @@ int HyperbolaPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getMajorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
return Py::Float(hyperbola->MajorRadius());
|
||||
}
|
||||
|
||||
void HyperbolaPy::setMajorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetMajorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getMinorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
return Py::Float(hyperbola->MinorRadius());
|
||||
}
|
||||
|
||||
void HyperbolaPy::setMinorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetMinorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getAngleXU(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
|
||||
gp_Pnt center = hyperbola->Axis().Location();
|
||||
gp_Dir normal = hyperbola->Axis().Direction();
|
||||
gp_Dir xdir = hyperbola->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));
|
||||
|
||||
}
|
||||
|
||||
void HyperbolaPy::setAngleXU(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
|
||||
|
||||
gp_Pnt center = hyperbola->Axis().Location();
|
||||
gp_Dir normal = hyperbola->Axis().Direction();
|
||||
|
||||
gp_Ax1 normaxis(center, normal);
|
||||
|
||||
gp_Ax2 xdirref(center, normal);
|
||||
|
||||
xdirref.Rotate(normaxis,arg);
|
||||
|
||||
hyperbola->SetPosition(xdirref);
|
||||
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getEccentricity(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->Eccentricity());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
return Py::Float(hyperbola->Eccentricity());
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getFocal(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->Focal());
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
return Py::Float(hyperbola->Focal());
|
||||
}
|
||||
|
||||
Py::Object HyperbolaPy::getFocus1(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Pnt loc = c->Focus1();
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
gp_Pnt loc = hyperbola->Focus1();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
}
|
||||
|
||||
Py::Object HyperbolaPy::getFocus2(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Pnt loc = c->Focus2();
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
gp_Pnt loc = hyperbola->Focus2();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getParameter(void) const
|
||||
Py::Object HyperbolaPy::getCenter(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->Parameter());
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getMajorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->MajorRadius());
|
||||
}
|
||||
|
||||
void HyperbolaPy::setMajorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
curve->SetMajorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float HyperbolaPy::getMinorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->MinorRadius());
|
||||
}
|
||||
|
||||
void HyperbolaPy::setMinorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Hyperbola curve = Handle_Geom_Hyperbola::DownCast(getGeometryPtr()->handle());
|
||||
curve->SetMinorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Object HyperbolaPy::getLocation(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Pnt loc = c->Location();
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
gp_Pnt loc = hyperbola->Location();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
}
|
||||
|
||||
void HyperbolaPy::setLocation(Py::Object arg)
|
||||
void HyperbolaPy::setCenter(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
gp_Pnt loc;
|
||||
Py::Tuple tuple(arg);
|
||||
gp_Pnt loc;
|
||||
loc.SetX((double)Py::Float(tuple.getItem(0)));
|
||||
loc.SetY((double)Py::Float(tuple.getItem(1)));
|
||||
loc.SetZ((double)Py::Float(tuple.getItem(2)));
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
c->SetLocation(loc);
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
hyperbola->SetLocation(loc);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
@@ -221,41 +242,34 @@ void HyperbolaPy::setLocation(Py::Object arg)
|
||||
|
||||
Py::Object HyperbolaPy::getAxis(void) const
|
||||
{
|
||||
Handle_Geom_Hyperbola c = Handle_Geom_Hyperbola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Dir dir = c->Axis().Direction();
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
gp_Ax1 axis = hyperbola->Axis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void HyperbolaPy::setAxis(Py::Object arg)
|
||||
{
|
||||
Standard_Real dir_x, dir_y, dir_z;
|
||||
PyObject *p = arg.ptr();
|
||||
PyObject* p = arg.ptr();
|
||||
Base::Vector3d val;
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
|
||||
dir_x = v.x;
|
||||
dir_y = v.y;
|
||||
dir_z = v.z;
|
||||
val = static_cast<Base::VectorPy*>(p)->value();
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
Py::Tuple tuple(arg);
|
||||
dir_x = (double)Py::Float(tuple.getItem(0));
|
||||
dir_y = (double)Py::Float(tuple.getItem(1));
|
||||
dir_z = (double)Py::Float(tuple.getItem(2));
|
||||
val = Base::getVectorFromTuple<double>(p);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector' or tuple, not ");
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle());
|
||||
try {
|
||||
Handle_Geom_Hyperbola this_curv = Handle_Geom_Hyperbola::DownCast
|
||||
(this->getGeometryPtr()->handle());
|
||||
gp_Ax1 axis;
|
||||
axis.SetLocation(this_curv->Location());
|
||||
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
|
||||
this_curv->SetAxis(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");
|
||||
@@ -271,5 +285,3 @@ int HyperbolaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@
|
||||
#include <GC_MakeArcOfCircle.hxx>
|
||||
#include <GC_MakeArcOfEllipse.hxx>
|
||||
#include <GC_MakeArcOfParabola.hxx>
|
||||
#include <GC_MakeArcOfHyperbola.hxx>
|
||||
#include <GC_MakeCircle.hxx>
|
||||
#include <GC_MakeConicalSurface.hxx>
|
||||
#include <GC_MakeCylindricalSurface.hxx>
|
||||
|
||||
Reference in New Issue
Block a user