RNC: IMP EDF 1542: Added the functionnality MakeVertexOnCurveByLength that allows creating a point at a given curvilinear abscissa on a curve

This commit is contained in:
gdd 2010-12-17 10:15:39 +00:00
parent 2b23fe11ea
commit 9c7d624fdc
15 changed files with 167 additions and 8 deletions

View File

@ -404,6 +404,16 @@ module GEOM
GEOM_Object MakePointOnCurve (in GEOM_Object theRefCurve, GEOM_Object MakePointOnCurve (in GEOM_Object theRefCurve,
in double theParameter); 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 * Create a point on the given curve, projecting given point
* \param theRefCurve The referenced curve. * \param theRefCurve The referenced curve.

View File

@ -57,6 +57,7 @@
#define PARAM_VALUE 0 #define PARAM_VALUE 0
#define COORD_VALUE 1 #define COORD_VALUE 1
#define LENGTH_VALUE 2
#define GEOM_POINT_XYZ 0 #define GEOM_POINT_XYZ 0
#define GEOM_POINT_REF 1 #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 ); QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), myParamGroup );
myParamCoord->addButton( btn, PARAM_VALUE ); myParamCoord->addButton( btn, PARAM_VALUE );
boxLayout->addWidget( btn ); 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 ); btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), myParamGroup );
myParamCoord->addButton( btn, COORD_VALUE ); myParamCoord->addButton( btn, COORD_VALUE );
boxLayout->addWidget( btn ); boxLayout->addWidget( btn );
@ -367,6 +371,8 @@ void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
GroupLineIntersection->hide(); GroupLineIntersection->hide();
GroupOnSurface->hide(); GroupOnSurface->hide();
myParamGroup->show(); myParamGroup->show();
myParamCoord->button( LENGTH_VALUE )->show();
myParamCoord->button( PARAM_VALUE )->setChecked( true );
GroupOnCurve->show(); GroupOnCurve->show();
myCoordGrp->show(); myCoordGrp->show();
updateParamCoord( false ); updateParamCoord( false );
@ -409,6 +415,8 @@ void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
GroupOnCurve->hide(); GroupOnCurve->hide();
GroupLineIntersection->hide(); GroupLineIntersection->hide();
myParamGroup->show(); myParamGroup->show();
myParamCoord->button( LENGTH_VALUE )->hide();
myParamCoord->button( PARAM_VALUE )->setChecked(true);
GroupOnSurface->show(); GroupOnSurface->show();
myCoordGrp->show(); myCoordGrp->show();
updateParamCoord( false ); updateParamCoord( false );
@ -772,7 +780,7 @@ bool BasicGUI_PointDlg::isValid( QString& msg )
} }
else if ( id == GEOM_POINT_EDGE ) { else if ( id == GEOM_POINT_EDGE ) {
bool ok = true; bool ok = true;
if ( myParamCoord->checkedId() == PARAM_VALUE ) if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE )
ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() ); ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
else { else {
ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok; ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
@ -846,7 +854,12 @@ bool BasicGUI_PointDlg::execute( ObjectList& objects )
if ( myParamCoord->checkedId() == PARAM_VALUE ) { if ( myParamCoord->checkedId() == PARAM_VALUE ) {
anObj = anOper->MakePointOnCurve( myEdge, getParameter() ); anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
aParameters<<GroupOnCurve->SpinBox_DX->text(); aParameters<<GroupOnCurve->SpinBox_DX->text();
} else { }
else if ( myParamCoord->checkedId() == LENGTH_VALUE ) {
anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter() );
aParameters<<GroupOnCurve->SpinBox_DX->text();
}
else if ( myParamCoord->checkedId() == COORD_VALUE ) {
double x = GroupXYZ->SpinBox_DX->value(); double x = GroupXYZ->SpinBox_DX->value();
double y = GroupXYZ->SpinBox_DY->value(); double y = GroupXYZ->SpinBox_DY->value();
double z = GroupXYZ->SpinBox_DZ->value(); double z = GroupXYZ->SpinBox_DZ->value();
@ -971,11 +984,25 @@ void BasicGUI_PointDlg::ClickParamCoord( int id )
void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate) void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
{ {
bool isParam = myParamCoord->checkedId() == PARAM_VALUE; 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(); const int id = getConstructorId();
if ( id == GEOM_POINT_EDGE ) { if ( id == GEOM_POINT_EDGE ) {
GroupOnCurve->TextLabel2->setShown( isParam ); GroupOnCurve->TextLabel2->setShown( isParam || isLength );
GroupOnCurve->SpinBox_DX->setShown( isParam ); 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 ) { else if ( id == GEOM_POINT_SURF ) {
GroupOnSurface->TextLabel2->setShown( isParam ); GroupOnSurface->TextLabel2->setShown( isParam );
@ -984,7 +1011,7 @@ void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
GroupOnSurface->SpinBox_DY->setShown( isParam ); GroupOnSurface->SpinBox_DY->setShown( isParam );
} }
GroupXYZ->setShown( !isParam ); GroupXYZ->setShown( !isParam && !isLength );
if ( theIsUpdate ) if ( theIsUpdate )
QTimer::singleShot(50, this, SLOT(updateSize())); QTimer::singleShot(50, this, SLOT(updateSize()));

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>297</width> <width>496</width>
<height>148</height> <height>148</height>
</rect> </rect>
</property> </property>

View File

@ -1102,6 +1102,10 @@ Please, select face, shell or solid and try again</translation>
<source>GEOM_COORD_VALUE</source> <source>GEOM_COORD_VALUE</source>
<translation>By coordinate</translation> <translation>By coordinate</translation>
</message> </message>
<message>
<source>GEOM_LENGTH_VALUE</source>
<translation>By length</translation>
</message>
<message> <message>
<source>GEOM_PARTITION</source> <source>GEOM_PARTITION</source>
<translation>Partition</translation> <translation>Partition</translation>

View File

@ -1100,6 +1100,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau</translation>
<message> <message>
<source>GEOM_COORD_VALUE</source> <source>GEOM_COORD_VALUE</source>
<translation>Par coordonnée</translation> <translation>Par coordonnée</translation>
</message>
<message>
<source>GEOM_LENGTH_VALUE</source>
<translation>Par longueur</translation>
</message> </message>
<message> <message>
<source>GEOM_PARTITION</source> <source>GEOM_PARTITION</source>

View File

@ -205,6 +205,7 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom
switch( theLocation ) switch( theLocation )
{ {
case PointOn_CurveByParam: fType = POINT_CURVE_PAR; break; 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_CurveByCoord: fType = POINT_CURVE_COORD; break;
case PointOn_SurfaceByParam: fType = POINT_SURFACE_PAR; break; case PointOn_SurfaceByParam: fType = POINT_SURFACE_PAR; break;
case PointOn_SurfaceByCoord: fType = POINT_SURFACE_COORD; break; case PointOn_SurfaceByCoord: fType = POINT_SURFACE_COORD; break;
@ -226,6 +227,10 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom
aPI.SetCurve(aRefFunction); aPI.SetCurve(aRefFunction);
aPI.SetParameter(theParam1); aPI.SetParameter(theParam1);
break; break;
case PointOn_CurveByLength:
aPI.SetCurve(aRefFunction);
aPI.SetLength(theParam1);
break;
case PointOn_CurveByCoord: case PointOn_CurveByCoord:
aPI.SetCurve(aRefFunction); aPI.SetCurve(aRefFunction);
aPI.SetX(theParam1); aPI.SetX(theParam1);
@ -268,6 +273,10 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::makePointOnGeom
GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve(" GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
<< theGeomObj << ", " << theParam1 << ")"; << theGeomObj << ", " << theParam1 << ")";
break; break;
case PointOn_CurveByLength:
GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByLength("
<< theGeomObj << ", " << theParam1 << ")";
break;
case PointOn_CurveByCoord: case PointOn_CurveByCoord:
GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByCoord(" GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurveByCoord("
<< theGeomObj << ", " << theParam1 << theGeomObj << ", " << theParam1
@ -314,6 +323,17 @@ Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurveByCoord
return makePointOnGeom(theCurve, theXParam, theYParam, theZParam, PointOn_CurveByCoord); 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 * MakePointOnSurface

View File

@ -43,6 +43,9 @@ class GEOMImpl_IBasicOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakePointOnCurve (Handle(GEOM_Object) theCurve, Standard_EXPORT Handle(GEOM_Object) MakePointOnCurve (Handle(GEOM_Object) theCurve,
double theParameter); double theParameter);
Standard_EXPORT Handle(GEOM_Object) MakePointOnCurveByLength (Handle(GEOM_Object) theCurve,
double theLength);
Standard_EXPORT Handle(GEOM_Object) MakePointOnCurveByCoord (Handle(GEOM_Object) theCurve, Standard_EXPORT Handle(GEOM_Object) MakePointOnCurveByCoord (Handle(GEOM_Object) theCurve,
double theXParam, double theXParam,
double theYParam, double theYParam,
@ -122,6 +125,7 @@ class GEOMImpl_IBasicOperations : public GEOM_IOperations {
{ {
PointOn_CurveByParam, PointOn_CurveByParam,
PointOn_CurveByCoord, PointOn_CurveByCoord,
PointOn_CurveByLength,
PointOn_SurfaceByParam, PointOn_SurfaceByParam,
PointOn_SurfaceByCoord PointOn_SurfaceByCoord
}; };

View File

@ -38,6 +38,8 @@
#define ARG_SURFACE 9 #define ARG_SURFACE 9
#define ARG_PARAM2 10 #define ARG_PARAM2 10
#define ARG_LENGTH 11
class GEOMImpl_IPoint class GEOMImpl_IPoint
{ {
public: public:
@ -72,6 +74,10 @@ class GEOMImpl_IPoint
double GetParameter() { return _func->GetReal(ARG_PARAM); } double GetParameter() { return _func->GetReal(ARG_PARAM); }
double GetParameter2() { return _func->GetReal(ARG_PARAM2); } double GetParameter2() { return _func->GetReal(ARG_PARAM2); }
void SetLength(double theLength) { _func->SetReal(ARG_LENGTH, theLength); }
double GetLength() { return _func->GetReal(ARG_LENGTH); }
private: private:
Handle(GEOM_Function) _func; Handle(GEOM_Function) _func;

View File

@ -45,6 +45,8 @@
#include <TopoDS_Face.hxx> #include <TopoDS_Face.hxx>
#include <ShapeAnalysis.hxx> #include <ShapeAnalysis.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <BRepAdaptor_Curve.hxx>
//======================================================================= //=======================================================================
//function : GetID //function : GetID
@ -150,6 +152,28 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
("Point On Curve creation aborted : cannot project point"); ("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<<std::endl;
if (theLength > 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 = "<<result_length<<std::endl;
aPnt = AdapCurve.Value(aParam);
}
else if (aType == POINT_SURFACE_PAR) { else if (aType == POINT_SURFACE_PAR) {
Handle(GEOM_Function) aRefCurve = aPI.GetSurface(); Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
TopoDS_Shape aRefShape = aRefCurve->GetValue(); TopoDS_Shape aRefShape = aRefCurve->GetValue();

View File

@ -109,6 +109,7 @@
#define POINT_SURFACE_PAR 5 #define POINT_SURFACE_PAR 5
#define POINT_CURVE_COORD 6 #define POINT_CURVE_COORD 6
#define POINT_SURFACE_COORD 7 #define POINT_SURFACE_COORD 7
#define POINT_CURVE_LENGTH 8
#define VECTOR_TWO_PNT 1 #define VECTOR_TWO_PNT 1
#define VECTOR_DX_DY_DZ 2 #define VECTOR_DX_DY_DZ 2

View File

@ -155,6 +155,32 @@ GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurve
return GetObject(anObject); 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 * MakePointOnCurveByCoord

View File

@ -55,6 +55,9 @@ class GEOM_I_EXPORT GEOM_IBasicOperations_i :
GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theCurve,
CORBA::Double theParameter); 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, GEOM::GEOM_Object_ptr MakePointOnCurveByCoord (GEOM::GEOM_Object_ptr theCurve,
CORBA::Double theXParameter, CORBA::Double theXParameter,
CORBA::Double theYParameter, CORBA::Double theYParameter,

View File

@ -587,6 +587,20 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakePointOnCurve (GEOM::GEOM_Object_ptr the
return anObj; 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 // MakePointOnCurveByCoord
//============================================================================= //=============================================================================

View File

@ -150,6 +150,8 @@ public:
CORBA::Double theZ); CORBA::Double theZ);
GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theRefCurve, GEOM::GEOM_Object_ptr MakePointOnCurve (GEOM::GEOM_Object_ptr theRefCurve,
CORBA::Double theParameter); 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, GEOM::GEOM_Object_ptr MakePointOnCurveByCoord (GEOM::GEOM_Object_ptr theRefCurve,
CORBA::Double theXParameter, CORBA::Double theXParameter,
CORBA::Double theYParameter, CORBA::Double theYParameter,

View File

@ -504,6 +504,20 @@ class geompyDC(GEOM._objref_GEOM_Gen):
anObj.SetParameters(Parameters) anObj.SetParameters(Parameters)
return anObj 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 ## Create a point, corresponding to the given parameters on the
# given surface. # given surface.
# @param theRefSurf The referenced surface. # @param theRefSurf The referenced surface.