From 9c7d624fdc08c44e52f1567b80501351b93d8a14 Mon Sep 17 00:00:00 2001 From: gdd Date: Fri, 17 Dec 2010 10:15:39 +0000 Subject: [PATCH] RNC: IMP EDF 1542: Added the functionnality MakeVertexOnCurveByLength that allows creating a point at a given curvilinear abscissa on a curve --- idl/GEOM_Gen.idl | 10 ++++++ src/BasicGUI/BasicGUI_PointDlg.cxx | 41 ++++++++++++++++++---- src/EntityGUI/EntityGUI_3Spin1Check_QTD.ui | 2 +- src/GEOMGUI/GEOM_msg_en.ts | 4 +++ src/GEOMGUI/GEOM_msg_fr.ts | 4 +++ src/GEOMImpl/GEOMImpl_IBasicOperations.cxx | 20 +++++++++++ src/GEOMImpl/GEOMImpl_IBasicOperations.hxx | 4 +++ src/GEOMImpl/GEOMImpl_IPoint.hxx | 6 ++++ src/GEOMImpl/GEOMImpl_PointDriver.cxx | 24 +++++++++++++ src/GEOMImpl/GEOMImpl_Types.hxx | 1 + src/GEOM_I/GEOM_IBasicOperations_i.cc | 26 ++++++++++++++ src/GEOM_I/GEOM_IBasicOperations_i.hh | 3 ++ src/GEOM_I_Superv/GEOM_Superv_i.cc | 14 ++++++++ src/GEOM_I_Superv/GEOM_Superv_i.hh | 2 ++ src/GEOM_SWIG/geompyDC.py | 14 ++++++++ 15 files changed, 167 insertions(+), 8 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 179ecf35a..868dc7f92 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -404,6 +404,16 @@ module GEOM GEOM_Object MakePointOnCurve (in GEOM_Object theRefCurve, in double theParameter); + /*! + * Create a point, corresponding to the given length on the given curve. + * \param theRefCurve The referenced curve. + * \param theLength Length on the referenced curve. + * \return New GEOM_Object, containing the created point. + */ + GEOM_Object MakePointOnCurveByLength (in GEOM_Object theRefCurve, + in double theLength); + + /*! * Create a point on the given curve, projecting given point * \param theRefCurve The referenced curve. diff --git a/src/BasicGUI/BasicGUI_PointDlg.cxx b/src/BasicGUI/BasicGUI_PointDlg.cxx index 90af070cd..8042083ed 100644 --- a/src/BasicGUI/BasicGUI_PointDlg.cxx +++ b/src/BasicGUI/BasicGUI_PointDlg.cxx @@ -57,6 +57,7 @@ #define PARAM_VALUE 0 #define COORD_VALUE 1 +#define LENGTH_VALUE 2 #define GEOM_POINT_XYZ 0 #define GEOM_POINT_REF 1 @@ -107,6 +108,9 @@ BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* pare QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), myParamGroup ); myParamCoord->addButton( btn, PARAM_VALUE ); boxLayout->addWidget( btn ); + btn = new QRadioButton( tr( "GEOM_LENGTH_VALUE" ), myParamGroup ); + myParamCoord->addButton( btn, LENGTH_VALUE ); + boxLayout->addWidget( btn ); btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), myParamGroup ); myParamCoord->addButton( btn, COORD_VALUE ); boxLayout->addWidget( btn ); @@ -367,6 +371,8 @@ void BasicGUI_PointDlg::ConstructorsClicked(int constructorId) GroupLineIntersection->hide(); GroupOnSurface->hide(); myParamGroup->show(); + myParamCoord->button( LENGTH_VALUE )->show(); + myParamCoord->button( PARAM_VALUE )->setChecked( true ); GroupOnCurve->show(); myCoordGrp->show(); updateParamCoord( false ); @@ -409,6 +415,8 @@ void BasicGUI_PointDlg::ConstructorsClicked(int constructorId) GroupOnCurve->hide(); GroupLineIntersection->hide(); myParamGroup->show(); + myParamCoord->button( LENGTH_VALUE )->hide(); + myParamCoord->button( PARAM_VALUE )->setChecked(true); GroupOnSurface->show(); myCoordGrp->show(); updateParamCoord( false ); @@ -772,7 +780,7 @@ bool BasicGUI_PointDlg::isValid( QString& msg ) } else if ( id == GEOM_POINT_EDGE ) { bool ok = true; - if ( myParamCoord->checkedId() == PARAM_VALUE ) + if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE ) ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() ); else { ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok; @@ -846,7 +854,12 @@ bool BasicGUI_PointDlg::execute( ObjectList& objects ) if ( myParamCoord->checkedId() == PARAM_VALUE ) { anObj = anOper->MakePointOnCurve( myEdge, getParameter() ); aParameters<SpinBox_DX->text(); - } else { + } + else if ( myParamCoord->checkedId() == LENGTH_VALUE ) { + anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter() ); + aParameters<SpinBox_DX->text(); + } + else if ( myParamCoord->checkedId() == COORD_VALUE ) { double x = GroupXYZ->SpinBox_DX->value(); double y = GroupXYZ->SpinBox_DY->value(); double z = GroupXYZ->SpinBox_DZ->value(); @@ -971,20 +984,34 @@ void BasicGUI_PointDlg::ClickParamCoord( int id ) void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate) { bool isParam = myParamCoord->checkedId() == PARAM_VALUE; + bool isLength = myParamCoord->checkedId() == LENGTH_VALUE; + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 ); const int id = getConstructorId(); if ( id == GEOM_POINT_EDGE ) { - GroupOnCurve->TextLabel2->setShown( isParam ); - GroupOnCurve->SpinBox_DX->setShown( isParam ); - } + GroupOnCurve->TextLabel2->setShown( isParam || isLength ); + GroupOnCurve->SpinBox_DX->setShown( isParam || isLength ); + if ( isParam ){ + initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision" ); + GroupOnCurve->SpinBox_DX->setValue( 0.5 ); + GroupOnCurve->TextLabel2->setText(tr( "GEOM_PARAMETER" )); + } + else if ( isLength ){ + initSpinBox( GroupOnCurve->SpinBox_DX, 0.0, COORD_MAX, 0.1 * step, "length_precision" ); + GroupOnCurve->SpinBox_DX->setValue( 0.0 ); + GroupOnCurve->TextLabel2->setText(tr( "GEOM_LENGTH" )); + } + } else if ( id == GEOM_POINT_SURF ) { GroupOnSurface->TextLabel2->setShown( isParam ); GroupOnSurface->TextLabel3->setShown( isParam ); GroupOnSurface->SpinBox_DX->setShown( isParam ); GroupOnSurface->SpinBox_DY->setShown( isParam ); } - - GroupXYZ->setShown( !isParam ); + + GroupXYZ->setShown( !isParam && !isLength ); if ( theIsUpdate ) QTimer::singleShot(50, this, SLOT(updateSize())); diff --git a/src/EntityGUI/EntityGUI_3Spin1Check_QTD.ui b/src/EntityGUI/EntityGUI_3Spin1Check_QTD.ui index f68dc1c1f..fa331f785 100644 --- a/src/EntityGUI/EntityGUI_3Spin1Check_QTD.ui +++ b/src/EntityGUI/EntityGUI_3Spin1Check_QTD.ui @@ -6,7 +6,7 @@ 0 0 - 297 + 496 148 diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index b0ea88ed1..5a4e70bde 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -1102,6 +1102,10 @@ Please, select face, shell or solid and try again GEOM_COORD_VALUE By coordinate + + GEOM_LENGTH_VALUE + By length + GEOM_PARTITION Partition diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 3564fc070..42e44bc1f 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -1100,6 +1100,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau GEOM_COORD_VALUE Par coordonnée + + + GEOM_LENGTH_VALUE + Par longueur GEOM_PARTITION diff --git a/src/GEOMImpl/GEOMImpl_IBasicOperations.cxx b/src/GEOMImpl/GEOMImpl_IBasicOperations.cxx index 9d8bbea1b..ee4899f8e 100644 --- a/src/GEOMImpl/GEOMImpl_IBasicOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IBasicOperations.cxx @@ -205,6 +205,7 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom switch( theLocation ) { case PointOn_CurveByParam: fType = POINT_CURVE_PAR; break; + case PointOn_CurveByLength: fType = POINT_CURVE_LENGTH; break; case PointOn_CurveByCoord: fType = POINT_CURVE_COORD; break; case PointOn_SurfaceByParam: fType = POINT_SURFACE_PAR; break; case PointOn_SurfaceByCoord: fType = POINT_SURFACE_COORD; break; @@ -226,6 +227,10 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom aPI.SetCurve(aRefFunction); aPI.SetParameter(theParam1); break; + case PointOn_CurveByLength: + aPI.SetCurve(aRefFunction); + aPI.SetLength(theParam1); + break; case PointOn_CurveByCoord: aPI.SetCurve(aRefFunction); aPI.SetX(theParam1); @@ -268,6 +273,10 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve(" << theGeomObj << ", " << theParam1 << ")"; break; + case PointOn_CurveByLength: + GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByLength(" + << theGeomObj << ", " << theParam1 << ")"; + break; case PointOn_CurveByCoord: GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByCoord(" << theGeomObj << ", " << theParam1 @@ -314,6 +323,17 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurveByCoord return makePointOnGeom(theCurve, theXParam, theYParam, theZParam, PointOn_CurveByCoord); } +//============================================================================= +/*! + * MakePointOnCurveByLength + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurveByLength + (Handle(GEOM_Object) theCurve, double theLength) +{ + return makePointOnGeom(theCurve, theLength, 0.0, 0.0, PointOn_CurveByLength); +} + //============================================================================= /*! * MakePointOnSurface diff --git a/src/GEOMImpl/GEOMImpl_IBasicOperations.hxx b/src/GEOMImpl/GEOMImpl_IBasicOperations.hxx index c851656a1..6a42fdf95 100644 --- a/src/GEOMImpl/GEOMImpl_IBasicOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IBasicOperations.hxx @@ -43,6 +43,9 @@ class GEOMImpl_IBasicOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) MakePointOnCurve (Handle(GEOM_Object) theCurve, double theParameter); + Standard_EXPORT Handle(GEOM_Object) MakePointOnCurveByLength (Handle(GEOM_Object) theCurve, + double theLength); + Standard_EXPORT Handle(GEOM_Object) MakePointOnCurveByCoord (Handle(GEOM_Object) theCurve, double theXParam, double theYParam, @@ -122,6 +125,7 @@ class GEOMImpl_IBasicOperations : public GEOM_IOperations { { PointOn_CurveByParam, PointOn_CurveByCoord, + PointOn_CurveByLength, PointOn_SurfaceByParam, PointOn_SurfaceByCoord }; diff --git a/src/GEOMImpl/GEOMImpl_IPoint.hxx b/src/GEOMImpl/GEOMImpl_IPoint.hxx index 7ee94ea6e..5c65005d0 100755 --- a/src/GEOMImpl/GEOMImpl_IPoint.hxx +++ b/src/GEOMImpl/GEOMImpl_IPoint.hxx @@ -38,6 +38,8 @@ #define ARG_SURFACE 9 #define ARG_PARAM2 10 +#define ARG_LENGTH 11 + class GEOMImpl_IPoint { public: @@ -72,6 +74,10 @@ class GEOMImpl_IPoint double GetParameter() { return _func->GetReal(ARG_PARAM); } double GetParameter2() { return _func->GetReal(ARG_PARAM2); } + void SetLength(double theLength) { _func->SetReal(ARG_LENGTH, theLength); } + + double GetLength() { return _func->GetReal(ARG_LENGTH); } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_PointDriver.cxx b/src/GEOMImpl/GEOMImpl_PointDriver.cxx index 8af5452e6..38411ee68 100644 --- a/src/GEOMImpl/GEOMImpl_PointDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_PointDriver.cxx @@ -45,6 +45,8 @@ #include #include +#include +#include //======================================================================= //function : GetID @@ -150,6 +152,28 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const ("Point On Curve creation aborted : cannot project point"); } } + else if (aType == POINT_CURVE_LENGTH) { + Handle(GEOM_Function) aRefCurve = aPI.GetCurve(); + Standard_Real theLength = aPI.GetLength(); + TopoDS_Shape aRefShape = aRefCurve->GetValue(); + if (aRefShape.ShapeType() != TopAbs_EDGE) { + Standard_TypeMismatch::Raise + ("Point On Curve creation aborted : curve shape is not an edge"); + } + BRepAdaptor_Curve AdapCurve = BRepAdaptor_Curve(TopoDS::Edge(aRefShape)); + Standard_Real theCurveLength = GCPnts_AbscissaPoint::Length(AdapCurve); + //std::cout<<"theCurveLength = "< theCurveLength) { + Standard_ConstructionError::Raise + ("Point On Curve creation aborted : given length is greater than edges length"); + } + + GCPnts_AbscissaPoint anAbsPnt(AdapCurve, aPI.GetLength(), 0); + Standard_Real aParam = anAbsPnt.Parameter(); + Standard_Real result_length = GCPnts_AbscissaPoint::Length(AdapCurve, 0, aParam); + std::cout<<"calculated Length of the result = "<GetValue(); diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index b954ec438..6b98bf77b 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -109,6 +109,7 @@ #define POINT_SURFACE_PAR 5 #define POINT_CURVE_COORD 6 #define POINT_SURFACE_COORD 7 +#define POINT_CURVE_LENGTH 8 #define VECTOR_TWO_PNT 1 #define VECTOR_DX_DY_DZ 2 diff --git a/src/GEOM_I/GEOM_IBasicOperations_i.cc b/src/GEOM_I/GEOM_IBasicOperations_i.cc index 1e7fbc247..00399592c 100644 --- a/src/GEOM_I/GEOM_IBasicOperations_i.cc +++ b/src/GEOM_I/GEOM_IBasicOperations_i.cc @@ -155,6 +155,32 @@ GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurve return GetObject(anObject); } +//============================================================================= +/*! + * MakePointOnCurveByLength + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurveByLength + (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theLength) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference curve + Handle(GEOM_Object) aReference = GetObjectImpl(theCurve); + if (aReference.IsNull()) return aGEOMObject._retn(); + + //Create the point + Handle(GEOM_Object) anObject = + GetOperations()->MakePointOnCurveByLength(aReference, theLength); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * MakePointOnCurveByCoord diff --git a/src/GEOM_I/GEOM_IBasicOperations_i.hh b/src/GEOM_I/GEOM_IBasicOperations_i.hh index a54cc4417..6f26cee6c 100644 --- a/src/GEOM_I/GEOM_IBasicOperations_i.hh +++ b/src/GEOM_I/GEOM_IBasicOperations_i.hh @@ -55,6 +55,9 @@ class GEOM_I_EXPORT GEOM_IBasicOperations_i : GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParameter); + GEOM::GEOM_Object_ptr MakePointOnCurveByLength (GEOM::GEOM_Object_ptr theCurve, + CORBA::Double theLength); + GEOM::GEOM_Object_ptr MakePointOnCurveByCoord (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theXParameter, CORBA::Double theYParameter, diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index aa842150a..3ca3c9e48 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -587,6 +587,20 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakePointOnCurve (GEOM::GEOM_Object_ptr the return anObj; } +//============================================================================= +// MakePointOnCurveByLength: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::MakePointOnCurveByLength (GEOM::GEOM_Object_ptr theRefCurve, + CORBA::Double theLength) +{ + beginService( " GEOM_Superv_i::MakePointOnCurveByLength" ); + MESSAGE("GEOM_Superv_i::MakePointOnCurveByLength"); + getBasicOp(); + GEOM::GEOM_Object_ptr anObj = myBasicOp->MakePointOnCurveByLength(theRefCurve, theLength); + endService( " GEOM_Superv_i::MakePointOnCurveByLength" ); + return anObj; +} + //============================================================================= // MakePointOnCurveByCoord //============================================================================= diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index c713705ed..c3608f0a1 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -150,6 +150,8 @@ public: CORBA::Double theZ); GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theRefCurve, CORBA::Double theParameter); + GEOM::GEOM_Object_ptr MakePointOnCurveByLength (GEOM::GEOM_Object_ptr theRefCurve, + CORBA::Double theLength); GEOM::GEOM_Object_ptr MakePointOnCurveByCoord (GEOM::GEOM_Object_ptr theRefCurve, CORBA::Double theXParameter, CORBA::Double theYParameter, diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 4c7c7919a..e99f710aa 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -503,6 +503,20 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("MakeVertexOnCurveByCoord", self.BasicOp) anObj.SetParameters(Parameters) return anObj + + ## Create a point, corresponding to the given length on the given curve. + # @param theRefCurve The referenced curve. + # @param theLength length on the referenced curve. + # @return New GEOM_Object, containing the created point. + # + # @ref tui_creation_point "Example" + def MakeVertexOnCurveByLength(self,theRefCurve, theLength): + # Example: see GEOM_TestAll.py + theLength, Parameters = ParseParameters(theLength) + anObj = self.BasicOp.MakePointOnCurveByLength(theRefCurve, theLength) + RaiseIfFailed("MakePointOnCurveByLength", self.BasicOp) + anObj.SetParameters(Parameters) + return anObj ## Create a point, corresponding to the given parameters on the # given surface. -- 2.39.2