From: rnv Date: Wed, 4 May 2011 13:32:04 +0000 (+0000) Subject: Start implementation of the "16564: EDF 509 GEOM : 3D line with mathematical equation... X-Git-Tag: V6_3_0b1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5652cf8774ebd0a7f3743d7a70cce8fbd3f6aeac;p=modules%2Fgeom.git Start implementation of the "16564: EDF 509 GEOM : 3D line with mathematical equation in GUI" issue. --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index a63bd51c6..ba85debac 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -135,6 +135,21 @@ module GEOM FOM_AutoCorrect }; + /*! + * Kind of the curves. + * Used in the function GEOM_Gen.MakeCurveParametric() + */ + enum curve_type { + /*! Polyline curve */ + Polyline, + + /*! Bezier curve */ + Bezier, + + /*! Interpolation, curve */ + Interpolation + }; + typedef sequence string_array; typedef sequence short_array; @@ -2595,6 +2610,25 @@ module GEOM in boolean theIsClosed, in boolean theDoReordering); + /*! + * Creates a curve using the parametric definition of the basic points. + * \param thexExpr parametric equation of the coordinates X. + * \param theyExpr parametric equation of the coordinates Y. + * \param thezExpr parametric equation of the coordinates Z. + * \param theParamMin the minimal value of the parameter. + * \param theParamMax the maximum value of the parameter. + * \param theParamStep the step of the parameter. + * \param theCurveType the type of the curve. + * \return New GEOM_Object, containing the created curve. + */ + GEOM_Object MakeCurveParametric(in string thexExpr, + in string theyExpr, + in string thezExpr, + in double theParamMin, + in double theParamMax, + in double theParamStep, + in curve_type theCurveType); + /*! * Create a sketcher (wire or face), following the textual description, * passed through \a theCommand argument. \n diff --git a/src/BasicGUI/BasicGUI_CurveDlg.cxx b/src/BasicGUI/BasicGUI_CurveDlg.cxx index d7af0b9b0..fa10f1030 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.cxx +++ b/src/BasicGUI/BasicGUI_CurveDlg.cxx @@ -24,6 +24,7 @@ // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. #include "BasicGUI_CurveDlg.h" +#include "BasicGUI_ParamCurveWidget.h" #include #include @@ -69,6 +70,20 @@ BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* pare mainFrame()->RadioButton2->setIcon( image3 ); mainFrame()->RadioButton3->setIcon( image2 ); + QGroupBox* creationModeCroup = new QGroupBox(this); + QButtonGroup* bg = new QButtonGroup(this); + + creationModeCroup->setTitle( tr( "GEOM_CURVE_CRMODE" ) ); + QHBoxLayout * creationModeLayout = new QHBoxLayout(creationModeCroup); + myBySelectionBtn = new QRadioButton( tr( "GEOM_CURVE_SELECTION" ) ,creationModeCroup ); + myAnaliticalBtn = new QRadioButton( tr( "GEOM_CURVE_ANALITICAL" ) ,creationModeCroup ); + + bg->addButton(myBySelectionBtn); + bg->addButton(myAnaliticalBtn); + + creationModeLayout->addWidget(myBySelectionBtn); + creationModeLayout->addWidget(myAnaliticalBtn); + GroupPoints = new DlgRef_1Sel3Check( centralWidget() ); GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) ); @@ -88,9 +103,13 @@ BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* pare GroupPoints->CheckButton3->hide(); + myParams = new BasicGUI_ParamCurveWidget( centralWidget() ); + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); layout->setMargin( 0 ); layout->setSpacing( 6 ); + layout->addWidget( creationModeCroup ); layout->addWidget( GroupPoints ); + layout->addWidget( myParams ); /***************************************************************/ setHelpFileName( "create_curve_page.html" ); @@ -123,6 +142,26 @@ void BasicGUI_CurveDlg::Init() localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); showOnlyPreviewControl(); + myBySelectionBtn->setChecked(true); + + /* Get setting of step value from file configuration */ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.; + + double aMax( 100. ), aMin( 0.0 ); + + /* min, max, step and decimals for spin boxes & initial values */ + initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" ); + initSpinBox( myParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" ); + initSpinBox( myParams->myPStep, COORD_MIN, COORD_MAX, step, "length_precision" ); + myParams->myPMin->setValue( aMin ); + myParams->myPMax->setValue( aMax ); + myParams->myPStep->setValue( step ); + myParams->myXExpr->setText("t"); + myParams->myYExpr->setText("t"); + myParams->myZExpr->setText("t"); + + myParams->hide(); /* signals and slots connections */ connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) ); @@ -141,6 +180,17 @@ void BasicGUI_CurveDlg::Init() connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + connect( myBySelectionBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); + connect( myAnaliticalBtn, SIGNAL( clicked() ), this, SLOT( CreationModeChanged() ) ); + + connect(myParams->myPMin, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double))); + connect(myParams->myPMax, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double))); + connect(myParams->myPStep, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double))); + + connect(myParams->myXExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + connect(myParams->myYExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + connect(myParams->myZExpr, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished())); + initName( tr( "GEOM_CURVE" ) ); resize(100,100); ConstructorsClicked( 0 ); @@ -321,7 +371,17 @@ GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation() //================================================================================= bool BasicGUI_CurveDlg::isValid( QString& msg ) { - return myPoints.count() > 1; + if( myBySelectionBtn->isChecked() ) + return myPoints.count() > 1; + else { + bool ok = myParams->myPMin->isValid( msg, !IsPreview() ) && + myParams->myPMax->isValid( msg, !IsPreview() ) && + myParams->myPStep->isValid( msg, !IsPreview() ); + ok &= !myParams->myXExpr->text().isEmpty(); + ok &= !myParams->myYExpr->text().isEmpty(); + ok &= !myParams->myZExpr->text().isEmpty(); + return ok; + } } //================================================================================= @@ -343,23 +403,59 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects ) switch ( getConstructorId() ) { case 0 : - anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() ); + if( myBySelectionBtn->isChecked() ) + anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() ); + else + anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), + qPrintable(myParams->myYExpr->text()), + qPrintable(myParams->myZExpr->text()), + myParams->myPMin->value(), + myParams->myPMax->value(), + myParams->myPStep->value(), + GEOM::Polyline); res = true; break; case 1 : - anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() ); + if( myBySelectionBtn->isChecked() ) + anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() ); + else + anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), + qPrintable(myParams->myYExpr->text()), + qPrintable(myParams->myZExpr->text()), + myParams->myPMin->value(), + myParams->myPMax->value(), + myParams->myPStep->value(), + GEOM::Bezier); + res = true; break; case 2 : - anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(), - GroupPoints->CheckButton2->isChecked() ); + if( myBySelectionBtn->isChecked() ) + anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(), + GroupPoints->CheckButton2->isChecked() ); + else + anObj = anOper->MakeCurveParametric(qPrintable(myParams->myXExpr->text()), + qPrintable(myParams->myYExpr->text()), + qPrintable(myParams->myZExpr->text()), + myParams->myPMin->value(), + myParams->myPMax->value(), + myParams->myPStep->value(), + GEOM::Interpolation); res = true; break; } - if ( !anObj->_is_nil() ) + if ( !anObj->_is_nil() ) { + if(myAnaliticalBtn->isChecked() && !IsPreview()) { + QStringList aParameters; + aParameters<myPMin->text(); + aParameters<myPMax->text(); + aParameters<myPStep->text(); + anObj->SetParameters(aParameters.join(":").toLatin1().constData()); + } objects.push_back( anObj._retn() ); - + } + return res; } @@ -372,3 +468,32 @@ void BasicGUI_CurveDlg::addSubshapesToStudy() for ( int i = 0; i < myPoints.count(); i++ ) GEOMBase::PublishSubObject( myPoints[i].get() ); } + +//================================================================================= +// function : CreationModeChanged +// purpose : +//================================================================================= +void BasicGUI_CurveDlg::CreationModeChanged() { + const QObject* s = sender(); + GroupPoints->setVisible(myBySelectionBtn == s); + myParams->setVisible(myBySelectionBtn != s); + + ConstructorsClicked( getConstructorId() ); +} + +//================================================================================= +// function : ValueChangedInSpinBox() +// purpose : +//================================================================================= +void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/) +{ + processPreview(); +} + +//================================================================================= +// function : ValueChangedInSpinBox() +// purpose : +//================================================================================= +void BasicGUI_CurveDlg::OnEditingFinished() { + processPreview(); +} diff --git a/src/BasicGUI/BasicGUI_CurveDlg.h b/src/BasicGUI/BasicGUI_CurveDlg.h index 982579788..19e48cb08 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.h +++ b/src/BasicGUI/BasicGUI_CurveDlg.h @@ -32,6 +32,8 @@ #include class DlgRef_1Sel3Check; +class QRadioButton; +class BasicGUI_ParamCurveWidget; //================================================================================= // class : BasicGUI_CurveDlg @@ -59,6 +61,9 @@ private: private: DlgRef_1Sel3Check* GroupPoints; QList myPoints; + QRadioButton* myAnaliticalBtn; + QRadioButton* myBySelectionBtn; + BasicGUI_ParamCurveWidget* myParams; private slots: void ClickOnOk(); @@ -71,6 +76,9 @@ private slots: void CheckButtonToggled(); void SelectionIntoArgument(); void SetEditCurrentArgument(); + void CreationModeChanged(); + void ValueChangedInSpinBox(double/*theValue*/); + void OnEditingFinished(); }; #endif // BASICGUI_CURVEDLG_H diff --git a/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx b/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx new file mode 100644 index 000000000..8f7695a65 --- /dev/null +++ b/src/BasicGUI/BasicGUI_ParamCurveWidget.cxx @@ -0,0 +1,97 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +// GEOM GEOMGUI : GUI for Geometry component +// File : BasicGUI_ParamCurveWidget.h +// Author : Roman NIKOLAEV (roman.nikolaev@opencascade.com) + +#include "BasicGUI_ParamCurveWidget.h" + +#include +#include +#include +#include + +#include + + +BasicGUI_ParamCurveWidget::BasicGUI_ParamCurveWidget(QWidget* parent): + QWidget(parent) { + + QGridLayout* l = new QGridLayout( this ); + l->setSpacing( 0 ); + l->setMargin( 0 ); + + QGroupBox* groupBox = new QGroupBox( tr("GEOM_PCURVE_TITLE"), this ); + + QGridLayout* gridLayout = new QGridLayout( groupBox ); + gridLayout->setSpacing( 6 ); + gridLayout->setMargin( 11 ); + + //X Equation + QLabel* textLabel1 = new QLabel( tr("GEOM_PCURVE_X"), groupBox ); + myXExpr = new QLineEdit( groupBox ); + + //Y Equation + QLabel* textLabel2 = new QLabel(tr("GEOM_PCURVE_Y"), groupBox); + myYExpr = new QLineEdit( groupBox ); + + //Z Equation + QLabel* textLabel3 = new QLabel( tr("GEOM_PCURVE_Z"), groupBox ); + myZExpr = new QLineEdit( groupBox ); + + // Min and Max + QLabel* textLabel4 = new QLabel( tr("GEOM_PCURVE_MIN"), groupBox ); + myPMin = new SalomeApp_DoubleSpinBox( groupBox ); + + // Min and Max + QLabel* textLabel5 = new QLabel( tr("GEOM_PCURVE_MAX"), groupBox ); + myPMax = new SalomeApp_DoubleSpinBox( groupBox ); + + // Step + QLabel* textLabel6 = new QLabel( tr("GEOM_PCURVE_STEP"), groupBox ); + myPStep = new SalomeApp_DoubleSpinBox( groupBox ); + + //Layout + gridLayout->addWidget(textLabel1, 0, 0, 1, 1); + gridLayout->addWidget(myXExpr, 0, 1, 1, 1); + + gridLayout->addWidget(textLabel2, 1, 0, 1, 1); + gridLayout->addWidget(myYExpr, 1, 1, 1, 1); + + gridLayout->addWidget(textLabel3, 2, 0, 1, 1); + gridLayout->addWidget(myZExpr, 2, 1, 1, 1); + + gridLayout->addWidget(textLabel4, 3, 0, 1, 1); + gridLayout->addWidget(myPMin, 3, 1, 1, 1); + + gridLayout->addWidget(textLabel5, 4, 0, 1, 1); + gridLayout->addWidget(myPMax, 4, 1, 1, 1); + + gridLayout->addWidget(textLabel6, 5, 0, 1, 1); + gridLayout->addWidget(myPStep, 5, 1, 1, 1); + + l->addWidget(groupBox, 0, 0, 1, 1); +} + + +BasicGUI_ParamCurveWidget::~BasicGUI_ParamCurveWidget(){ +} diff --git a/src/BasicGUI/BasicGUI_ParamCurveWidget.h b/src/BasicGUI/BasicGUI_ParamCurveWidget.h new file mode 100644 index 000000000..8adb8ccdd --- /dev/null +++ b/src/BasicGUI/BasicGUI_ParamCurveWidget.h @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +// GEOM GEOMGUI : GUI for Geometry component +// File : BasicGUI_ParamCurveWidget.h +// Author : Roman NIKOLAEV (roman.nikolaev@opencascade.com) + +#ifndef BASICGUI_PARAM_CURVE_WIDGET_H +#define BASICGUI_PARAM_CURVE_WIDGET_H +#include + +class QLineEdit; +class SalomeApp_DoubleSpinBox; + +class BasicGUI_ParamCurveWidget: public QWidget { + Q_OBJECT + + public: + BasicGUI_ParamCurveWidget(QWidget * parent = 0); + ~BasicGUI_ParamCurveWidget(); + + public: + QLineEdit* myXExpr; + QLineEdit* myYExpr; + QLineEdit* myZExpr; + + SalomeApp_DoubleSpinBox* myPMin; + SalomeApp_DoubleSpinBox* myPMax; + SalomeApp_DoubleSpinBox* myPStep; + +}; + +#endif //BASICGUI_PARAM_CURVE_WIDGET_H diff --git a/src/BasicGUI/Makefile.am b/src/BasicGUI/Makefile.am index 88c19b11d..9f47697a0 100644 --- a/src/BasicGUI/Makefile.am +++ b/src/BasicGUI/Makefile.am @@ -36,7 +36,8 @@ salomeinclude_HEADERS = \ BasicGUI_MarkerDlg.h \ BasicGUI_PlaneDlg.h \ BasicGUI_PointDlg.h \ - BasicGUI_VectorDlg.h + BasicGUI_VectorDlg.h \ + BasicGUI_ParamCurveWidget.h # # OBSOLETE: BasicGUI_WorkingPlaneDlg.h # @@ -56,7 +57,8 @@ dist_libBasicGUI_la_SOURCES = \ BasicGUI_VectorDlg.cxx \ BasicGUI_PlaneDlg.cxx \ BasicGUI_CurveDlg.cxx \ - BasicGUI_MarkerDlg.cxx + BasicGUI_MarkerDlg.cxx \ + BasicGUI_ParamCurveWidget.cxx # # OBSOLETE: BasicGUI_WorkingPlaneDlg.cxx # @@ -70,7 +72,8 @@ MOC_FILES = \ BasicGUI_VectorDlg_moc.cxx \ BasicGUI_PlaneDlg_moc.cxx \ BasicGUI_CurveDlg_moc.cxx \ - BasicGUI_MarkerDlg_moc.cxx + BasicGUI_MarkerDlg_moc.cxx \ + BasicGUI_ParamCurveWidget_moc.cxx # # OBSOLETE: BasicGUI_WorkingPlaneDlg_moc.cxx # diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 5618f5b3a..c89ab8139 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -1166,7 +1166,7 @@ void ReplaceVariables(TCollection_AsciiString& theCommand, else if(i == aTotalNbParams) { aStartPos = aCommand.Location(i-1, COMMA, 1, aCommand.Length()) + 2; - aEndPos = aCommand.Location(C_BRACKET, 1, aCommand.Length()); + aEndPos = aCommand.Location(C_BRACKET, aStartPos , aCommand.Length()); } //Replace other parameters (bettwen two ',' characters) else if(i != aFirstParam && i != aTotalNbParams ) diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 2ee69bbde..fd5aec4c2 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4334,6 +4334,49 @@ Otherwise the dimensions will be kept without modifications. GEOM_IS_REORDER Reorder vertices taking into account distances + + GEOM_CURVE_CRMODE + Creation Mode + + + GEOM_CURVE_SELECTION + By Selection + + + GEOM_CURVE_ANALITICAL + Analitical + + + + BasicGUI_ParamCurveWidget + + GEOM_PCURVE_TITLE + Curve parameters + + + GEOM_PCURVE_X + X(t) equation + + + GEOM_PCURVE_Y + Y(t) equation + + + GEOM_PCURVE_Z + Z(t) equation + + + GEOM_PCURVE_MIN + Min t + + + GEOM_PCURVE_MAX + Max t + + + GEOM_PCURVE_STEP + Step + BasicGUI_EllipseDlg diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index 3d53948c3..54ac51a06 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -19,6 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +#include +#include + #include #include @@ -53,6 +56,111 @@ #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC + +/* ================================== + * =========== PYTHON ============== + * ==================================*/ + +typedef struct { + PyObject_HEAD + int softspace; + std::string *out; + } PyStdOut; + +static void +PyStdOut_dealloc(PyStdOut *self) +{ + PyObject_Del(self); +} + +static PyObject * +PyStdOut_write(PyStdOut *self, PyObject *args) +{ + char *c; + int l; + if (!PyArg_ParseTuple(args, "t#:write",&c, &l)) + return NULL; + + //std::cerr << c ; + *(self->out)=*(self->out)+c; + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef PyStdOut_methods[] = { + {"write", (PyCFunction)PyStdOut_write, METH_VARARGS, + PyDoc_STR("write(string) -> None")}, + {NULL, NULL} /* sentinel */ +}; + +static PyMemberDef PyStdOut_memberlist[] = { + {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0, + (char*)"flag indicating that a space needs to be printed; used by print"}, + {NULL} /* Sentinel */ +}; + +static PyTypeObject PyStdOut_Type = { + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PyOut", /*tp_name*/ + sizeof(PyStdOut), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)PyStdOut_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + /* softspace is writable: we must supply tp_setattro */ + PyObject_GenericSetAttr, /* tp_setattro */ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + PyStdOut_methods, /*tp_methods*/ + PyStdOut_memberlist, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ +}; + +PyObject * newPyStdOut( std::string& out ) +{ + PyStdOut *self; + self = PyObject_New(PyStdOut, &PyStdOut_Type); + if (self == NULL) + return NULL; + self->softspace = 0; + self->out=&out; + return (PyObject*)self; +} + + +////////////////////////END PYTHON/////////////////////////// //============================================================================= /*! * constructor: @@ -549,6 +657,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list::iterator it = thePoints.begin(); @@ -620,6 +729,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier int aLen = thePoints.size(); aCI.SetLength(aLen); + aCI.SetConstructorType(POINT_CONSTRUCTOR); int ind = 1; std::list::iterator it = thePoints.begin(); @@ -690,6 +800,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation GEOMImpl_ISpline aCI (aFunction); int aLen = thePoints.size(); + aCI.SetConstructorType(POINT_CONSTRUCTOR); aCI.SetLength(aLen); int ind = 1; @@ -736,6 +847,221 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation return aSpline; } +//============================================================================= +/*! + * MakeCurveParametric + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, + double theParamMin, double theParamMax, double theParamStep, + CurveType theCurveType) { + TCollection_AsciiString aPyScript; + aPyScript +="from math import * \n"; + aPyScript +="def X(t): \n"; + aPyScript +=" return "; + aPyScript += thexExpr; + aPyScript += "\n"; + aPyScript +="def Y(t): \n"; + aPyScript +=" return "; + aPyScript += theyExpr; + aPyScript += "\n"; + + aPyScript +="def Z(t): \n"; + aPyScript +=" return "; + aPyScript += thezExpr; + aPyScript += "\n"; + + aPyScript +="def coordCalucator(tmin, tmax, tstep): \n"; + aPyScript +=" coords = [] \n"; + aPyScript +=" while tmin <= tmax : \n"; + aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n"; + aPyScript +=" tmin = tmin + tstep \n"; + aPyScript +=" return coords \n"; + + SetErrorCode(KO); + + if(theParamMin >= theParamMax) { + SetErrorCode("The minimum value of the parameter must be less than maximum value !!!"); + return NULL; + } + + if(theParamStep <= 0.0 ) { + SetErrorCode("Value of the step must be positive !!!"); + return NULL; + } + + /* Initialize the Python interpreter */ + if (! Py_IsInitialized()) { + SetErrorCode("Python interpreter is not initialized !!! "); + return NULL; + } + + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject* main_mod = PyImport_AddModule("__main__"); + PyObject* main_dict = PyModule_GetDict(main_mod); + + PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL); + + if (obj == NULL) { + SetErrorCode("Error during run python script !!!"); + PyGILState_Release(gstate); + return NULL; + } else { + Py_DECREF(obj); + } + + PyObject * func = NULL; + func = PyObject_GetAttrString(main_mod, "coordCalucator"); + + if (func == NULL){ + SetErrorCode("Can't get function from python module !!!"); + PyGILState_Release(gstate); + return NULL; + } + + PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep ); + PyObject* new_stderr = NULL; + + if (coords == NULL){ + fflush(stderr); + std::string err_description=""; + new_stderr = newPyStdOut(err_description); + PySys_SetObject((char*)"stderr", new_stderr); + PyErr_Print(); + PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__")); + Py_DECREF(new_stderr); + MESSAGE("Can't evaluate coordCalucator()" << " error is " << err_description); + SetErrorCode("Can't evaluate the expressions, please check them !!!"); + PyGILState_Release(gstate); + return NULL; + } + + Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3); + + if(PyList_Size( coords ) <= 0) { + SetErrorCode("Empty list of the points, please check input parameters !!!"); + return NULL; + } + + int k=1; + for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) { + PyObject* coord = PyList_GetItem( coords, i ); + if (coord != NULL) { + for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) { + PyObject* item = PyList_GetItem(coord, j); + aCoordsArray->SetValue(k, PyFloat_AsDouble(item)); + k++; + } + } + } + + Py_DECREF(coords); + + + + PyGILState_Release(gstate); + + Handle(GEOM_Object) aCurve; + Handle(GEOM_Function) aFunction; + TCollection_AsciiString aCurveType; + + switch(theCurveType) { + case Polyline: { + //Add a new Polyline object + aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE); + + //Add a new Polyline function for creation a polyline relatively to points set + aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS); + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL; + + GEOMImpl_IPolyline aCI (aFunction); + + aCI.SetLength(PyList_Size( coords )); + aCI.SetConstructorType(COORD_CONSTRUCTOR); + aCI.SetIsClosed(false); + aCI.SetCoordinates(aCoordsArray); + aCurveType = "geompy.GEOM.Polyline"; + break; + } + case Bezier: { + //Add a new Spline object + aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE); + //Add a new Spline function for creation a bezier curve relatively to points set + aFunction = + aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER); + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL; + + GEOMImpl_ISpline aCI (aFunction); + + aCI.SetLength(PyList_Size( coords )); + aCI.SetConstructorType(COORD_CONSTRUCTOR); + aCI.SetIsClosed(false); + aCI.SetCoordinates(aCoordsArray); + aCurveType = "geompy.GEOM.Bezier"; + break; + } + case Interpolation: { + //Add a new Spline object + aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE); + + //Add a new Spline function for creation a bezier curve relatively to points set + aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION); + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL; + + GEOMImpl_ISpline aCI (aFunction); + aCI.SetConstructorType(COORD_CONSTRUCTOR); + aCI.SetLength(PyList_Size( coords )); + aCI.SetIsClosed(false); + aCI.SetDoReordering(false); + aCI.SetCoordinates(aCoordsArray); + aCurveType = "geompy.GEOM.Interpolation"; + break; + } + } + + //Compute the Curve value + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Curve driver failed !!!"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + GEOM::TPythonDump pd (aFunction); + pd << aCurve << " = geompy.MakeCurveParametric("; + pd << "\"" << thexExpr << "\", "; + pd << "\"" << theyExpr << "\", "; + pd << "\"" << thezExpr << "\", "; + + pd << theParamMin <<", "; + pd << theParamMax <<", "; + pd << theParamStep <<", "; + pd << aCurveType.ToCString() <<")"; + + SetErrorCode(OK); + return aCurve; +} + //============================================================================= /*! * MakeSketcher @@ -923,3 +1249,4 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane SetErrorCode(OK); return aSketcher; } + diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index d85dcf14d..01acdb7a2 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -32,7 +32,11 @@ class GEOM_Engine; class Handle(GEOM_Object); class GEOMImpl_ICurvesOperations : public GEOM_IOperations { + public: + + enum CurveType { Polyline, Bezier, Interpolation }; + Standard_EXPORT GEOMImpl_ICurvesOperations(GEOM_Engine* theEngine, int theDocID); Standard_EXPORT ~GEOMImpl_ICurvesOperations(); @@ -73,6 +77,10 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations { bool theIsClosed = false, bool theDoReordering = false); + Standard_EXPORT Handle(GEOM_Object) MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, + double theParamMin, double theParamMax, double theParamStep, + CurveType theCurveType); + Standard_EXPORT Handle(GEOM_Object) MakeSketcher (const char* theCommand, std::list theWorkingPlane); Standard_EXPORT Handle(GEOM_Object) Make3DSketcher (std::list theCoordinates); diff --git a/src/GEOMImpl/GEOMImpl_IPolyline.hxx b/src/GEOMImpl/GEOMImpl_IPolyline.hxx index d4b3ae66f..b9794dda1 100644 --- a/src/GEOMImpl/GEOMImpl_IPolyline.hxx +++ b/src/GEOMImpl/GEOMImpl_IPolyline.hxx @@ -22,11 +22,15 @@ //NOTE: This is an interface to a function for the Polyline creation. #include "GEOM_Function.hxx" +#include #define POLY_ARG_LENG 1 #define POLY_ARG_LAST 1 #define POLY_ARG_CLOS 2 +#define POLY_CONSTRUCTOR 3 +#define POLY_ARG_ARRAY 4 + class GEOMImpl_IPolyline { public: @@ -45,6 +49,18 @@ class GEOMImpl_IPolyline bool GetIsClosed() { return (bool)_func->GetInteger(POLY_ARG_CLOS); } + void SetConstructorType(int theConstructor) {_func->SetInteger(POLY_CONSTRUCTOR,theConstructor); } + + int GetConstructorType() { return _func->GetInteger(POLY_CONSTRUCTOR); } + + void SetCoordinates(const Handle(TColStd_HArray1OfReal)& theValue) + { _func->SetRealArray(POLY_ARG_ARRAY, theValue); } + + + Handle(TColStd_HArray1OfReal) GetCoordinates() { return _func->GetRealArray(POLY_ARG_ARRAY); } + + + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_ISpline.hxx b/src/GEOMImpl/GEOMImpl_ISpline.hxx index d3304c162..5b95b58b5 100644 --- a/src/GEOMImpl/GEOMImpl_ISpline.hxx +++ b/src/GEOMImpl/GEOMImpl_ISpline.hxx @@ -22,12 +22,16 @@ // NOTE: This is an interface to a function for the Spline creation. #include "GEOM_Function.hxx" +#include #define SPL_ARG_LENG 1 #define SPL_ARG_CLOS 2 #define SPL_ARG_REOR 3 #define SPL_ARG_LAST 2 +#define SPL_CONSTRUCTOR 4 +#define SPL_ARG_ARRAY 5 + class GEOMImpl_ISpline { public: @@ -50,6 +54,17 @@ class GEOMImpl_ISpline Handle(GEOM_Function) GetPoint(int theId) { return _func->GetReference(SPL_ARG_LAST + theId); } + + void SetConstructorType(int theConstructor) {_func->SetInteger(SPL_CONSTRUCTOR,theConstructor); } + + int GetConstructorType() { return _func->GetInteger(SPL_CONSTRUCTOR); } + + void SetCoordinates(const Handle(TColStd_HArray1OfReal)& theValue) + { _func->SetRealArray(SPL_ARG_ARRAY, theValue); } + + + Handle(TColStd_HArray1OfReal) GetCoordinates() { return _func->GetRealArray(SPL_ARG_ARRAY); } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_PolylineDriver.cxx b/src/GEOMImpl/GEOMImpl_PolylineDriver.cxx index f04e719a6..517f440f0 100644 --- a/src/GEOMImpl/GEOMImpl_PolylineDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_PolylineDriver.cxx @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -68,42 +70,69 @@ Standard_Integer GEOMImpl_PolylineDriver::Execute(TFunction_Logbook& log) const GEOMImpl_IPolyline aCI (aFunction); Standard_Integer aType = aFunction->GetType(); - + TopoDS_Shape aShape; if (aType == POLYLINE_POINTS) { + + bool useCoords = aCI.GetConstructorType() == COORD_CONSTRUCTOR; + TColgp_Array1OfPnt points(1, (useCoords ? aCI.GetLength() : 1) ); + if(useCoords) { + Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates(); + int anArrayLength = aCoordsArray->Length(); + for (int i = 0, j = 1; i <= (anArrayLength-3); i += 3) { + gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3)); + points.SetValue(j,aPnt); + j++; + } + } + int aLen = aCI.GetLength(); int ind = 1; BRepBuilderAPI_MakePolygon aMakePoly; for (; ind <= aLen; ind++) { - Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind); - TopoDS_Shape aShapePnt = aRefPoint->GetValue(); - if (aShapePnt.ShapeType() != TopAbs_VERTEX) { - Standard_TypeMismatch::Raise - ("Polyline creation aborted : arguments are not a vertexes"); - return 0; - } - if (aShapePnt.ShapeType() == TopAbs_VERTEX) { - aMakePoly.Add(TopoDS::Vertex(aShapePnt)); - //if (!aMakePoly.Added()) return 0; + if(useCoords) { + aMakePoly.Add(BRepBuilderAPI_MakeVertex(points.Value(ind))); + } else { + Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind); + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.ShapeType() != TopAbs_VERTEX) { + Standard_TypeMismatch::Raise + ("Polyline creation aborted : arguments are not a vertexes"); + return 0; + } + if (aShapePnt.ShapeType() == TopAbs_VERTEX) { + aMakePoly.Add(TopoDS::Vertex(aShapePnt)); + //if (!aMakePoly.Added()) return 0; + } } } // Compare first and last point coordinates and close polyline if it's the same. if ( aLen > 2 ) { - Handle(GEOM_Function) aFPoint = aCI.GetPoint(1); - TopoDS_Shape aFirstPnt = aFPoint->GetValue(); - TopoDS_Vertex aV1 = TopoDS::Vertex(aFirstPnt); - - Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen); - TopoDS_Shape aLastPnt = aLPoint->GetValue(); - TopoDS_Vertex aV2 = TopoDS::Vertex(aLastPnt); - + TopoDS_Vertex aV1; + if( useCoords ) { + aV1 = BRepBuilderAPI_MakeVertex(points.Value(1)); + } else { + Handle(GEOM_Function) aFPoint = aCI.GetPoint(1); + TopoDS_Shape aFirstPnt = aFPoint->GetValue(); + aV1 = TopoDS::Vertex(aFirstPnt); + } + + TopoDS_Vertex aV2; + if( useCoords ) { + aV2 = BRepBuilderAPI_MakeVertex(points.Value(aLen)); + } else { + Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen); + TopoDS_Shape aLastPnt = aLPoint->GetValue(); + aV2 = TopoDS::Vertex(aLastPnt); + } + if ( (!aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2)) || aCI.GetIsClosed()) aMakePoly.Close(); } - + if (aMakePoly.IsDone()) { aShape = aMakePoly.Wire(); } @@ -112,11 +141,11 @@ Standard_Integer GEOMImpl_PolylineDriver::Execute(TFunction_Logbook& log) const } if (aShape.IsNull()) return 0; - + aFunction->SetValue(aShape); - + log.SetTouched(Label()); - + return 1; } diff --git a/src/GEOMImpl/GEOMImpl_SplineDriver.cxx b/src/GEOMImpl/GEOMImpl_SplineDriver.cxx index c8684cb19..7524942e3 100644 --- a/src/GEOMImpl/GEOMImpl_SplineDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_SplineDriver.cxx @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -81,30 +82,54 @@ Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape aShape; if (aType == SPLINE_BEZIER || aType == SPLINE_INTERPOLATION) { + + bool useCoords = aCI.GetConstructorType() == COORD_CONSTRUCTOR; + TColgp_Array1OfPnt points(1, (useCoords ? aCI.GetLength() : 1) ); + if(useCoords) { + Handle(TColStd_HArray1OfReal) aCoordsArray = aCI.GetCoordinates(); + int anArrayLength = aCoordsArray->Length(); + for (int i = 0, j = 1; i <= (anArrayLength-3); i += 3) { + gp_Pnt aPnt = gp_Pnt(aCoordsArray->Value(i+1), aCoordsArray->Value(i+2), aCoordsArray->Value(i+3)); + points.SetValue(j,aPnt); + j++; + } + } + + int ind, aLen = aCI.GetLength(); if (aLen < 2) return 0; Standard_Boolean isSeveral = Standard_False; gp_Pnt aPrevP; int aRealLen = aLen; if (aType == SPLINE_BEZIER && aCI.GetIsClosed()) { - Handle(GEOM_Function) aFPoint = aCI.GetPoint(1); - TopoDS_Shape aFirstPnt = aFPoint->GetValue(); - TopoDS_Vertex aV1 = TopoDS::Vertex(aFirstPnt); - - Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen); - TopoDS_Shape aLastPnt = aLPoint->GetValue(); - TopoDS_Vertex aV2 = TopoDS::Vertex(aLastPnt); + TopoDS_Vertex aV1; + if(useCoords) { + aV1 = BRepBuilderAPI_MakeVertex(points.Value(1)); + } else { + Handle(GEOM_Function) aFPoint = aCI.GetPoint(1); + TopoDS_Shape aFirstPnt = aFPoint->GetValue(); + aV1 = TopoDS::Vertex(aFirstPnt); + } + TopoDS_Vertex aV2; + if(useCoords) { + aV2 = BRepBuilderAPI_MakeVertex(points.Value(aLen)); + } else { + Handle(GEOM_Function) aLPoint = aCI.GetPoint(aLen); + TopoDS_Shape aLastPnt = aLPoint->GetValue(); + aV2 = TopoDS::Vertex(aLastPnt); + } + if (!aV1.IsNull() && !aV2.IsNull() && !aV1.IsSame(aV2)) { aRealLen++; } } + TColgp_Array1OfPnt CurvePoints (1, aRealLen); for (ind = 1; ind <= aLen; ind++) { - Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind); - TopoDS_Shape aShapePnt = aRefPoint->GetValue(); - if (aShapePnt.ShapeType() == TopAbs_VERTEX) { - gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + gp_Pnt aP; + if( useCoords ) { + aP = points.Value(ind); if (!isSeveral && ind > 1) { if (aP.Distance(aPrevP) > Precision::Confusion()) { isSeveral = Standard_True; @@ -112,6 +137,19 @@ Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const } CurvePoints.SetValue(ind, aP); aPrevP = aP; + } else { + Handle(GEOM_Function) aRefPoint = aCI.GetPoint(ind); + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.ShapeType() == TopAbs_VERTEX) { + aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + if (!isSeveral && ind > 1) { + if (aP.Distance(aPrevP) > Precision::Confusion()) { + isSeveral = Standard_True; + } + } + CurvePoints.SetValue(ind, aP); + aPrevP = aP; + } } } if (aType == SPLINE_BEZIER) { @@ -126,7 +164,7 @@ Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const } else { //GeomAPI_PointsToBSpline GBC (CurvePoints); //aShape = BRepBuilderAPI_MakeEdge(GBC).Edge(); - + Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aLen); if (aCI.GetDoReordering()) { @@ -164,7 +202,7 @@ Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const aHCurvePoints->SetValue(ind, CurvePoints.Value(ind)); } } - + bool isClosed = aCI.GetIsClosed(); GeomAPI_Interpolate GBC (aHCurvePoints, isClosed, gp::Resolution()); GBC.Perform(); @@ -176,13 +214,13 @@ Standard_Integer GEOMImpl_SplineDriver::Execute(TFunction_Logbook& log) const } else { } - + if (aShape.IsNull()) return 0; - + aFunction->SetValue(aShape); - + log.SetTouched(Label()); - + return 1; } diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 1f01c8317..4435dd6d9 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -293,6 +293,10 @@ #define SHAPES_ON_SHAPE 1 +//Curve constructor type +#define POINT_CONSTRUCTOR 0 +#define COORD_CONSTRUCTOR 1 + // Blocks #define BLOCK_FACE_FOUR_PNT 1 #define BLOCK_FACE_FOUR_EDGES 2 diff --git a/src/GEOMImpl/Makefile.am b/src/GEOMImpl/Makefile.am index 94094bca3..9954c8994 100644 --- a/src/GEOMImpl/Makefile.am +++ b/src/GEOMImpl/Makefile.am @@ -227,6 +227,7 @@ libGEOMimpl_la_CPPFLAGS = \ $(CAS_CPPFLAGS) \ $(KERNEL_CXXFLAGS) \ $(BOOST_CPPFLAGS) \ + $(PYTHON_INCLUDES) \ -I$(srcdir)/../ShHealOper \ -I$(srcdir)/../NMTTools \ -I$(srcdir)/../GEOM \ @@ -243,7 +244,8 @@ libGEOMimpl_la_LDFLAGS = \ ../SKETCHER/libGEOMSketcher.la \ $(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics \ $(STDLIB) \ - $(CAS_LDPATH) -lTKCAF -lTKFillet -lTKOffset + $(CAS_LDPATH) -lTKCAF -lTKFillet -lTKOffset \ + $(PYTHON_LIBS) # extra dist files EXTRA_DIST += GUID.txt diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index 831ca9bde..9a56dc824 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -427,6 +427,46 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeSplineInterpolation return GetObject(anObject); } +//============================================================================= +/*! + * MakeCurveParametric + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, + double theParamMin, double theParamMax, double theParamStep, + GEOM::curve_type theCurveType) { + GEOM::GEOM_Object_var aGEOMObject; + //Set a not done flag + GetOperations()->SetNotDone(); + + GEOMImpl_ICurvesOperations::CurveType aType; + switch(theCurveType) { + case GEOM::Polyline: + aType = GEOMImpl_ICurvesOperations::Polyline; + break; + case GEOM::Bezier: + aType = GEOMImpl_ICurvesOperations::Bezier; + break; + case GEOM::Interpolation: + aType = GEOMImpl_ICurvesOperations::Interpolation; + break; + default: + break; + } + + + // Make Polyline + Handle(GEOM_Object) anObject = + GetOperations()->MakeCurveParametric(thexExpr, theyExpr, thezExpr, + theParamMin, theParamMax, + theParamStep, aType); + + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * MakeSketcher diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.hh b/src/GEOM_I/GEOM_ICurvesOperations_i.hh index b629d46ca..15daf32c3 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.hh +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.hh @@ -85,6 +85,10 @@ class GEOM_I_EXPORT GEOM_ICurvesOperations_i : CORBA::Boolean theIsClosed, CORBA::Boolean theDoReordering); + GEOM::GEOM_Object_ptr MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, + double theParamMin, double theParamMax, double theParamStep, + GEOM::curve_type theCurveType); + GEOM::GEOM_Object_ptr MakeSketcher (const char* theCommand, const GEOM::ListOfDouble& theWorkingPlane); GEOM::GEOM_Object_ptr Make3DSketcher (const GEOM::ListOfDouble& theCoordinates); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index af394ff65..2492a8b9a 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -954,6 +954,28 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp) return anObj + + ## Creates a curve using the parametric definition of the basic points. + # @param thexExpr parametric equation of the coordinates X. + # @param theyExpr parametric equation of the coordinates Y. + # @param thezExpr parametric equation of the coordinates Z. + # @param theParamMin the minimal value of the parameter. + # @param theParamMax the maximum value of the parameter. + # @param theParamStep the step of the parameter. + # @param theCurveType the type of the curve. + # @return New GEOM_Object, containing the created curve. + # + # @ref tui_creation_curve "Example" + def MakeCurveParametric(self, thexExpr, theyExpr, thezExpr, + theParamMin, theParamMax, theParamStep, theCurveType): + theParamMin,theParamMax,theParamStep,Parameters = ParseParameters(theParamMin,theParamMax,theParamStep) + anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType) + RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp) + anObj.SetParameters(Parameters) + return anObj + + + # end of l4_curves ## @}