From: vsr Date: Wed, 25 Feb 2009 13:31:16 +0000 (+0000) Subject: Issue 0020154 : improve ellipse creeation function X-Git-Tag: V5_1_1a2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=46fd079b60d3e5c54bd6a4a77bfd99f75806eead;p=modules%2Fgeom.git Issue 0020154 : improve ellipse creeation function --- diff --git a/doc/salome/gui/GEOM/images/ellipse.png b/doc/salome/gui/GEOM/images/ellipse.png index 8eea6cae6..9b3150115 100755 Binary files a/doc/salome/gui/GEOM/images/ellipse.png and b/doc/salome/gui/GEOM/images/ellipse.png differ diff --git a/doc/salome/gui/GEOM/input/creating_ellipse.doc b/doc/salome/gui/GEOM/input/creating_ellipse.doc index 2beaa9086..b2dace591 100644 --- a/doc/salome/gui/GEOM/input/creating_ellipse.doc +++ b/doc/salome/gui/GEOM/input/creating_ellipse.doc @@ -4,17 +4,30 @@ To create an \b Ellipse in the Main Menu select New Entity - > Basic - > Ellipse -\n You can define an \b Ellipse by its Center Point, a \b -Vector giving its normal, and its Major & Minor Radiuses. +\n You can define an \b Ellipse by its Center point, a \b +Vector giving its normal, another vector specifying the direction of +ellipse's Major Axis and its Major & Minor Radiuses. \n The \b Result of the operation will be a GEOM_Object (edge). -\n TUI Command: geompy.MakeEllipse(Point, Vector, RadiusMajor, RadiusMinor) +\note The parameters Center, Vector and Major Axis +are optional. By default it is presumed that the Center point +is located at the origin of the global coordinate system, the \b Vector +corresponds to the OZ axis of the global coordinate system and Major Axis +corresponds to the OX axis of the global coordinate system. + + +\note Actual direction of the major axis vector is defined as + Vmaj' = (Vn * Vmaj) * Vn where \em Vn is a normal vector and +\em Vmaj is an original vector of the major axis. + +\n TUI Command (no major axis): geompy.MakeEllipse(Point, Vector, RadiusMajor, RadiusMinor) \n Arguments: Name + 1 vertex (for the center) + 1 edge (for the direction) + 1 X Radius + 1 Y Radius. -\note By default it is presumed that the Center Point is located at the Origin of the global -coordinate system, and the \b Vector corresponds to OZ axis of the global -coordinate system. +\n TUI Command (use major axis):geompy.MakeEllipseVec(Point, Vector, RadiusMajor, RadiusMinor, VectorMajor) +\n Arguments: Name + 1 vertex (for the center) + 1 edge (for +the normal direction) + 1 X Radius + 1 Y Radius + 1 edge (for the +major axis direction) \image html ellipse.png diff --git a/doc/salome/gui/GEOM/input/tui_basic_geom_objs.doc b/doc/salome/gui/GEOM/input/tui_basic_geom_objs.doc index 89baf140d..51da40037 100644 --- a/doc/salome/gui/GEOM/input/tui_basic_geom_objs.doc +++ b/doc/salome/gui/GEOM/input/tui_basic_geom_objs.doc @@ -116,21 +116,32 @@ gg = salome.ImportComponentGUI("GEOM") # create vertices p0 = geompy.MakeVertex(0., 0., 0.) -p50 = geompy.MakeVertex(50., 50., 50.) +p1 = geompy.MakeVertex(50., 50., 50.) +p2 = geompy.MakeVertex(0., 50., 0.) -# create a vector from two points -vector = geompy.MakeVector(p0, p50) +# create a normal vector from two points +normal = geompy.MakeVector(p0, p1) + +# create a major axis vector from two points +major = geompy.MakeVector(p0, p2) # create an ellipse from a point, a vector and radiuses -ellipse = geompy.MakeEllipse(p50, vector, 50, 25) +ellipse1 = geompy.MakeEllipse(p1, normal, 50, 25) + +# create an ellipse from a point, a normal vector, radiuses and a major axis vector +ellipse2 = geompy.MakeEllipse(p1, normal, 50, 25, major) # add objects in the study -id_vector = geompy.addToStudy(vector, "Vector") -id_ellipse = geompy.addToStudy(ellipse,"Ellipse") +id_normal = geompy.addToStudy(normal, "Normal") +id_major = geompy.addToStudy(major, "Major Axis") +id_ellipse1 = geompy.addToStudy(ellipse1, "Ellipse 1") +id_ellipse2 = geompy.addToStudy(ellipse2, "Ellipse 2") # display the ellipse and its normal vector -gg.createAndDisplayGO(id_vector) -gg.createAndDisplayGO(id_ellipse) +gg.createAndDisplayGO(id_normal) +gg.createAndDisplayGO(id_major) +gg.createAndDisplayGO(id_ellipse1) +gg.createAndDisplayGO(id_ellipse2) \endcode \anchor tui_creation_arc @@ -302,4 +313,4 @@ gg.setDisplayMode(id_plane3,1) gg.setTransparency(id_plane3,0.5) \endcode -*/ \ No newline at end of file +*/ diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 7a64111e2..2be25f963 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -2102,6 +2102,21 @@ module GEOM in double theRMajor, in double theRMinor); + /*! + * Create an ellipse with given center, normal vector, main axis vector and radiuses. + * \param thePnt Ellipse center. + * \param theVec Vector, normal to the plane of the ellipse. + * \param theRMajor Major ellipse radius. + * \param theRMinor Minor ellipse radius. + * \param theVecMaj Vector, direction of the ellipse's main axis. + * \return New GEOM_Object, containing the created ellipse. + */ + GEOM_Object MakeEllipseVec (in GEOM_Object thePnt, + in GEOM_Object theVec, + in double theRMajor, + in double theRMinor, + in GEOM_Object theVecMaj); + /*! * Create an arc of circle, passing through three given points. * \param thePnt1 Start point of the arc. diff --git a/idl/GEOM_Superv.idl b/idl/GEOM_Superv.idl index 4690e7e7e..1ee41d642 100644 --- a/idl/GEOM_Superv.idl +++ b/idl/GEOM_Superv.idl @@ -478,6 +478,11 @@ module GEOM in GEOM_Object theVec, in double theRMajor, in double theRMinor) ; + GEOM_Object MakeEllipseVec (in GEOM_Object thePnt, + in GEOM_Object theVec, + in double theRMajor, + in double theRMinor, + in GEOM_Object theVecMaj) ; GEOM_Object MakeArc (in GEOM_Object thePnt1, in GEOM_Object thePnt2, in GEOM_Object thePnt3) ; diff --git a/src/BasicGUI/BasicGUI_EllipseDlg.cxx b/src/BasicGUI/BasicGUI_EllipseDlg.cxx index 9b9eb6c07..dee60ede9 100644 --- a/src/BasicGUI/BasicGUI_EllipseDlg.cxx +++ b/src/BasicGUI/BasicGUI_EllipseDlg.cxx @@ -68,19 +68,23 @@ BasicGUI_EllipseDlg::BasicGUI_EllipseDlg( GeometryGUI* theGeometryGUI, QWidget* mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); mainFrame()->RadioButton3->close(); - GroupPoints = new DlgRef_2Sel2Spin( centralWidget() ); + GroupPoints = new DlgRef_3Sel2Spin( centralWidget() ); GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) + " (Origin by default)" ); - GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " (Z axis by default)" ); - GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_MAJOR" ) ); - GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_MINOR" ) ); + GroupPoints->TextLabel1->setText( tr( "%1 (%2)" ).arg( tr( "GEOM_CENTER" ), tr( "ORIGIN_DEFAULT" ) ) ); + GroupPoints->TextLabel2->setText( tr( "%1 (%2)" ).arg( tr( "GEOM_VECTOR" ), tr( "Z_AXIS_DEFAULT" ) ) ); + GroupPoints->TextLabel3->setText( tr( "%1 (%2)" ).arg( tr( "GEOM_VECTOR_MAJOR" ), tr( "X_AXIS_DEFAULT" ) ) ); + GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_MAJOR" ) ); + GroupPoints->TextLabel5->setText( tr( "GEOM_RADIUS_MINOR" ) ); GroupPoints->PushButton1->setIcon( image1 ); GroupPoints->PushButton2->setIcon( image1 ); + GroupPoints->PushButton3->setIcon( image1 ); GroupPoints->LineEdit1->setReadOnly( true ); GroupPoints->LineEdit2->setReadOnly( true ); + GroupPoints->LineEdit3->setReadOnly( true ); GroupPoints->LineEdit1->setEnabled( true ); GroupPoints->LineEdit2->setEnabled( false ); + GroupPoints->LineEdit3->setEnabled( false ); QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); layout->setMargin( 0 ); layout->setSpacing( 6 ); @@ -114,7 +118,7 @@ void BasicGUI_EllipseDlg::Init() localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); GroupPoints->PushButton1->setDown(true); - myPoint = myDir = GEOM::GEOM_Object::_nil(); + myPoint = myDir = myMajor = GEOM::GEOM_Object::_nil(); /* Get setting of step value from file configuration */ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); @@ -137,9 +141,11 @@ void BasicGUI_EllipseDlg::Init() connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect( GroupPoints->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); + connect( GroupPoints->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) ); connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) ); @@ -188,13 +194,16 @@ bool BasicGUI_EllipseDlg::ClickOnApply() initName(); // reset - myPoint = myDir = GEOM::GEOM_Object::_nil(); + myPoint = myDir = myMajor = GEOM::GEOM_Object::_nil(); GroupPoints->LineEdit1->setText( "" ); GroupPoints->LineEdit2->setText( "" ); + GroupPoints->LineEdit3->setText( "" ); GroupPoints->PushButton1->setDown(true); GroupPoints->PushButton2->setDown(false); + GroupPoints->PushButton3->setDown(false); GroupPoints->LineEdit1->setEnabled( true ); GroupPoints->LineEdit2->setEnabled( false ); + GroupPoints->LineEdit3->setEnabled( false ); myEditCurrentArgument = GroupPoints->LineEdit1; globalSelection(); // close local contexts, if any @@ -219,6 +228,7 @@ void BasicGUI_EllipseDlg::SelectionIntoArgument() if (aSelList.Extent() != 1) { if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint = GEOM::GEOM_Object::_nil(); else if (myEditCurrentArgument == GroupPoints->LineEdit2) myDir = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == GroupPoints->LineEdit3) myMajor = GEOM::GEOM_Object::_nil(); return; } @@ -232,7 +242,7 @@ void BasicGUI_EllipseDlg::SelectionIntoArgument() TopoDS_Shape aShape; TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if ( myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupPoints->LineEdit3 ) aNeedType = TopAbs_EDGE; if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { @@ -278,7 +288,12 @@ void BasicGUI_EllipseDlg::SelectionIntoArgument() } else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) { myDir = aSelectedObject; - if ( !myDir->_is_nil() && myPoint->_is_nil() ) + if ( !myDir->_is_nil() && myMajor->_is_nil() ) + GroupPoints->PushButton3->click(); + } + else if ( myEditCurrentArgument == GroupPoints->LineEdit3 ) { + myMajor = aSelectedObject; + if ( !myMajor->_is_nil() && myPoint->_is_nil() ) GroupPoints->PushButton1->click(); } } @@ -298,19 +313,31 @@ void BasicGUI_EllipseDlg::SetEditCurrentArgument() if ( send == GroupPoints->PushButton1 ) { myEditCurrentArgument = GroupPoints->LineEdit1; GroupPoints->PushButton2->setDown(false); + GroupPoints->PushButton3->setDown(false); GroupPoints->LineEdit1->setEnabled( true ); GroupPoints->LineEdit2->setEnabled( false ); + GroupPoints->LineEdit3->setEnabled( false ); } else if ( send == GroupPoints->PushButton2 ) { myEditCurrentArgument = GroupPoints->LineEdit2; GroupPoints->PushButton1->setDown(false); + GroupPoints->PushButton3->setDown(false); GroupPoints->LineEdit1->setEnabled( false ); GroupPoints->LineEdit2->setEnabled( true ); + GroupPoints->LineEdit3->setEnabled( false ); + } + else if ( send == GroupPoints->PushButton3 ) { + myEditCurrentArgument = GroupPoints->LineEdit3; + GroupPoints->PushButton1->setDown(false); + GroupPoints->PushButton2->setDown(false); + GroupPoints->LineEdit1->setEnabled( false ); + GroupPoints->LineEdit2->setEnabled( false ); + GroupPoints->LineEdit3->setEnabled( true ); } globalSelection(); // close local contexts, if any TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if ( myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupPoints->LineEdit3 ) aNeedType = TopAbs_EDGE; localSelection( GEOM::GEOM_Object::_nil(), aNeedType ); @@ -328,7 +355,8 @@ void BasicGUI_EllipseDlg::LineEditReturnPressed() { QLineEdit* send = (QLineEdit*)sender(); if ( send == GroupPoints->LineEdit1 || - send == GroupPoints->LineEdit2 ) { + send == GroupPoints->LineEdit2 || + send == GroupPoints->LineEdit3 ) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } @@ -350,6 +378,7 @@ void BasicGUI_EllipseDlg::ActivateThisDialog() GroupPoints->LineEdit1->setText( "" ); GroupPoints->LineEdit2->setText( "" ); + GroupPoints->LineEdit3->setText( "" ); myPoint = myDir = GEOM::GEOM_Object::_nil(); //globalSelection( GEOM_POINT ); @@ -429,7 +458,9 @@ bool BasicGUI_EllipseDlg::execute( ObjectList& objects ) aParameters<SpinBox_DX->text(); aParameters<SpinBox_DY->text(); - GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR ); + GEOM::GEOM_Object_var anObj = myMajor->_is_nil() ? + GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse ( myPoint, myDir, aMajorR, aMinorR ) : + GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipseVec( myPoint, myDir, aMajorR, aMinorR, myMajor ); if ( !anObj->_is_nil() ) { if ( !IsPreview() ) anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters)); @@ -450,6 +481,8 @@ void BasicGUI_EllipseDlg::addSubshapesToStudy() objMap[GroupPoints->LineEdit1->text()] = myPoint; if (!CORBA::is_nil(myDir)) objMap[GroupPoints->LineEdit2->text()] = myDir; + if (!CORBA::is_nil(myMajor)) + objMap[GroupPoints->LineEdit3->text()] = myMajor; addSubshapesToFather( objMap ); } diff --git a/src/BasicGUI/BasicGUI_EllipseDlg.h b/src/BasicGUI/BasicGUI_EllipseDlg.h index ab6ef7cb4..c80bce197 100644 --- a/src/BasicGUI/BasicGUI_EllipseDlg.h +++ b/src/BasicGUI/BasicGUI_EllipseDlg.h @@ -28,7 +28,7 @@ #include -class DlgRef_2Sel2Spin; +class DlgRef_3Sel2Spin; //================================================================================= // class : BasicGUI_EllipseDlg @@ -54,9 +54,9 @@ private: void enterEvent( QEvent* ); private: - GEOM::GEOM_Object_var myPoint, myDir; + GEOM::GEOM_Object_var myPoint, myDir, myMajor; - DlgRef_2Sel2Spin* GroupPoints; + DlgRef_3Sel2Spin* GroupPoints; private slots: void ClickOnOk(); diff --git a/src/DlgRef/DlgRef.cxx b/src/DlgRef/DlgRef.cxx index 0b0f48585..2d876aed2 100644 --- a/src/DlgRef/DlgRef.cxx +++ b/src/DlgRef/DlgRef.cxx @@ -542,6 +542,20 @@ DlgRef_3Sel1Spin::~DlgRef_3Sel1Spin() { } +////////////////////////////////////////// +// DlgRef_3Sel2Spin +////////////////////////////////////////// + +DlgRef_3Sel2Spin::DlgRef_3Sel2Spin( QWidget* parent, Qt::WindowFlags f ) +: QWidget( parent, f ) +{ + setupUi( this ); +} + +DlgRef_3Sel2Spin::~DlgRef_3Sel2Spin() +{ +} + ////////////////////////////////////////// // DlgRef_3Sel3Spin1Check ////////////////////////////////////////// @@ -766,7 +780,7 @@ QString DlgRef::PrintDoubleValue( double theValue, int thePrecision ) { const double prec = 1e-12; - if ( abs(theValue) < thePrecision) + if ( qAbs(theValue) < prec ) return "0"; QString aRes; diff --git a/src/DlgRef/DlgRef.h b/src/DlgRef/DlgRef.h index 69b58ca64..3ef90cceb 100644 --- a/src/DlgRef/DlgRef.h +++ b/src/DlgRef/DlgRef.h @@ -629,6 +629,22 @@ public: ~DlgRef_3Sel1Spin(); }; +////////////////////////////////////////// +// DlgRef_3Sel2Spin +////////////////////////////////////////// + +#include "ui_DlgRef_3Sel2Spin_QTD.h" + +class DLGREF_EXPORT DlgRef_3Sel2Spin : public QWidget, + public Ui::DlgRef_3Sel2Spin_QTD +{ + Q_OBJECT + +public: + DlgRef_3Sel2Spin( QWidget* = 0, Qt::WindowFlags = 0 ); + ~DlgRef_3Sel2Spin(); +}; + ////////////////////////////////////////// // DlgRef_3Sel3Spin1Check ////////////////////////////////////////// diff --git a/src/DlgRef/DlgRef_3Sel2Spin_QTD.ui b/src/DlgRef/DlgRef_3Sel2Spin_QTD.ui new file mode 100644 index 000000000..509282969 --- /dev/null +++ b/src/DlgRef/DlgRef_3Sel2Spin_QTD.ui @@ -0,0 +1,199 @@ + + DlgRef_3Sel2Spin_QTD + + + + 0 + 0 + 120 + 177 + + + + + 0 + 0 + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + TL1 + + + false + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + TL2 + + + false + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + TL3 + + + false + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + TL4 + + + false + + + + + + + + + + + 0 + 0 + + + + TL5 + + + false + + + + + + + + + + + + + qPixmapFromMimeSource + + + SalomeApp_DoubleSpinBox + QDoubleSpinBox +
SalomeApp_DoubleSpinBox.h
+
+
+ + PushButton1 + LineEdit1 + PushButton2 + LineEdit2 + PushButton3 + LineEdit3 + SpinBox_DX + + + +
diff --git a/src/DlgRef/Makefile.am b/src/DlgRef/Makefile.am index cbd156bb1..54cb1abe7 100644 --- a/src/DlgRef/Makefile.am +++ b/src/DlgRef/Makefile.am @@ -75,6 +75,7 @@ UIC_FILES = \ ui_DlgRef_3Radio1Sel1Spin_QTD.h \ ui_DlgRef_3Sel1Check_QTD.h \ ui_DlgRef_3Sel1Spin_QTD.h \ + ui_DlgRef_3Sel2Spin_QTD.h \ ui_DlgRef_3Sel3Spin1Check_QTD.h \ ui_DlgRef_3Sel3Spin2Check_QTD.h \ ui_DlgRef_3Sel4Spin2Check_QTD.h \ diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 15ac7e838..13210b537 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -3760,6 +3760,25 @@ Please, select face, shell or solid and try again Import operation has finished with errors: + + BasicGUI_EllipseDlg + + GEOM_VECTOR_MAJOR + Major Axis + + + ORIGIN_DEFAULT + Origin by default + + + X_AXIS_DEFAULT + X axis by default + + + Z_AXIS_DEFAULT + Z axis by default + + BasicGUI_MarkerDlg diff --git a/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx b/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx index 24ac23eb6..176ba05df 100644 --- a/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx @@ -79,7 +79,7 @@ Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) { Standard_ConstructionError::Raise - ("Circle creation aborted: invalid center argument, must be a point"); + ("Ellipse creation aborted: invalid center argument, must be a point"); } aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); } @@ -90,7 +90,7 @@ Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapeVec.ShapeType() != TopAbs_EDGE) { Standard_ConstructionError::Raise - ("Circle creation aborted: invalid vector argument, must be a vector or an edge"); + ("Ellipse creation aborted: invalid normal vector argument, must be a vector or an edge"); } TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; @@ -99,12 +99,37 @@ Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (aV.Magnitude() < gp::Resolution()) { Standard_ConstructionError::Raise - ("Circle creation aborted: vector of zero length is given"); + ("Ellipse creation aborted: normal vector of zero length is given"); } } } + // Main Axis vector + gp_Vec aVM = gp::DX(); + Handle(GEOM_Function) aRefVectorMaj = aCI.GetVectorMajor(); + if (!aRefVectorMaj.IsNull()) { + TopoDS_Shape aShapeVec = aRefVectorMaj->GetValue(); + if (aShapeVec.ShapeType() != TopAbs_EDGE) { + Standard_ConstructionError::Raise + ("Ellipse creation aborted: invalid major axis vector argument, must be a vector or an edge"); + } + TopoDS_Edge anE = TopoDS::Edge(aShapeVec); + TopoDS_Vertex V1, V2; + TopExp::Vertices(anE, V1, V2, Standard_True); + if (!V1.IsNull() && !V2.IsNull()) { + aVM = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); + if (aVM.Magnitude() < gp::Resolution()) { + Standard_ConstructionError::Raise + ("Ellipse creation aborted: major axis vector of zero length is given"); + } + if (aV.IsParallel(aVM, Precision::Angular())) { + Standard_ConstructionError::Raise + ("Ellipse creation aborted: normal and major axis vectors are parallel"); + } + } + } + // Axes - gp_Ax2 anAxes (aP, aV); + gp_Ax2 anAxes (aP, aV, aVM); // Ellipse gp_Elips anEll (anAxes, aCI.GetRMajor(), aCI.GetRMinor()); aShape = BRepBuilderAPI_MakeEdge(anEll).Edge(); diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index 6a6b8f9ef..72fb49c63 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -334,12 +334,14 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR //============================================================================= Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, - double theRMajor, double theRMinor) + double theRMajor, double theRMinor, + Handle(GEOM_Object) theVecMaj) { SetErrorCode(KO); // Not set thePnt means origin of global CS, // Not set theVec means Z axis of global CS + // Not set theVecMaj means X axis of global CS //if (thePnt.IsNull() || theVec.IsNull()) return NULL; //Add a new Ellipse object @@ -370,6 +372,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse aCI.SetRMajor(theRMajor); aCI.SetRMinor(theRMinor); + if (!theVecMaj.IsNull()) { + Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction(); + if (aRefVecMaj.IsNull()) return NULL; + aCI.SetVectorMajor(aRefVecMaj); + } + //Compute the Ellipse value try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 @@ -387,8 +395,15 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse } //Make a Python command - GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse(" - << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")"; + if (!theVecMaj.IsNull()) { + GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse(" + << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor + << ", " << theVecMaj << ")"; + } + else { + GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse(" + << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")"; + } SetErrorCode(OK); return anEll; diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index 7380a0977..dbf5ecee0 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -51,7 +51,8 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) MakeEllipse (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, - double theRMajor, double theRMinor); + double theRMajor, double theRMinor, + Handle(GEOM_Object) theVecMaj); Standard_EXPORT Handle(GEOM_Object) MakeArc (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2, diff --git a/src/GEOMImpl/GEOMImpl_IEllipse.hxx b/src/GEOMImpl/GEOMImpl_IEllipse.hxx index 8a199e760..8fe39a5f3 100644 --- a/src/GEOMImpl/GEOMImpl_IEllipse.hxx +++ b/src/GEOMImpl/GEOMImpl_IEllipse.hxx @@ -23,10 +23,11 @@ // #include "GEOM_Function.hxx" -#define ELLIPS_ARG_CC 1 -#define ELLIPS_ARG_VV 2 -#define ELLIPS_ARG_RMAJ 3 -#define ELLIPS_ARG_RMIN 4 +#define ELLIPS_ARG_CC 1 +#define ELLIPS_ARG_VV 2 +#define ELLIPS_ARG_RMAJ 3 +#define ELLIPS_ARG_RMIN 4 +#define ELLIPS_ARG_VVMAJ 5 class GEOMImpl_IEllipse { @@ -40,12 +41,16 @@ class GEOMImpl_IEllipse void SetRMajor(double theR) { _func->SetReal(ELLIPS_ARG_RMAJ, theR); } void SetRMinor(double theR) { _func->SetReal(ELLIPS_ARG_RMIN, theR); } + void SetVectorMajor(Handle(GEOM_Function) theV) { _func->SetReference(ELLIPS_ARG_VVMAJ, theV); } + Handle(GEOM_Function) GetCenter() { return _func->GetReference(ELLIPS_ARG_CC); } Handle(GEOM_Function) GetVector() { return _func->GetReference(ELLIPS_ARG_VV); } double GetRMajor() { return _func->GetReal(ELLIPS_ARG_RMAJ); } double GetRMinor() { return _func->GetReal(ELLIPS_ARG_RMIN); } + Handle(GEOM_Function) GetVectorMajor() { return _func->GetReference(ELLIPS_ARG_VVMAJ); } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index 2b15af49f..572a2918b 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -181,7 +181,49 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn(); //Get the arguments - Handle(GEOM_Object) aPnt, aVec; + Handle(GEOM_Object) aPnt, aVec, aVecMaj; + if (!CORBA::is_nil(thePnt)) { + aPnt = GetOperations()->GetEngine()->GetObject + (thePnt->GetStudyID(), thePnt->GetEntry()); + if (aPnt.IsNull()) return aGEOMObject._retn(); + } + if (!CORBA::is_nil(theVec)) { + aVec = GetOperations()->GetEngine()->GetObject + (theVec->GetStudyID(), theVec->GetEntry()); + if (aVec.IsNull()) return aGEOMObject._retn(); + } + + // Make Ellipse + Handle(GEOM_Object) anObject = + GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor, aVecMaj); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + +//============================================================================= +/*! + * MakeEllipseVec + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipseVec + (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec, + CORBA::Double theRMajor, double theRMinor, + GEOM::GEOM_Object_ptr theVecMaj) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + // Not set thePnt means origin of global CS, + // Not set theVec means Z axis of global CS + // Not set theVecMaj means X axis of global CS + //if (thePnt == NULL || theVec == NULL || theVecMaj == NULL) return aGEOMObject._retn(); + + //Get the arguments + Handle(GEOM_Object) aPnt, aVec, aVecMaj; if (!CORBA::is_nil(thePnt)) { aPnt = GetOperations()->GetEngine()->GetObject (thePnt->GetStudyID(), thePnt->GetEntry()); @@ -192,10 +234,15 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse (theVec->GetStudyID(), theVec->GetEntry()); if (aVec.IsNull()) return aGEOMObject._retn(); } + if (!CORBA::is_nil(theVecMaj)) { + aVecMaj = GetOperations()->GetEngine()->GetObject + (theVecMaj->GetStudyID(), theVecMaj->GetEntry()); + if (aVecMaj.IsNull()) return aGEOMObject._retn(); + } // Make Ellipse Handle(GEOM_Object) anObject = - GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor); + GetOperations()->MakeEllipse(aPnt, aVec, theRMajor, theRMinor, aVecMaj); if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn(); diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.hh b/src/GEOM_I/GEOM_ICurvesOperations_i.hh index 24179fc1f..728f567e0 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.hh +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.hh @@ -57,6 +57,11 @@ class GEOM_I_EXPORT GEOM_ICurvesOperations_i : GEOM::GEOM_Object_ptr theVector, double theRMajor, double theRMinor); + GEOM::GEOM_Object_ptr MakeEllipseVec (GEOM::GEOM_Object_ptr theCenter, + GEOM::GEOM_Object_ptr theVector, + double theRMajor, double theRMinor, + GEOM::GEOM_Object_ptr theVectorMajor); + GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt3); diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 159bb6f49..094b6e99f 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -2532,6 +2532,23 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeEllipse (GEOM::GEOM_Object_ptr theCente return anObj; } +//============================================================================= +// MakeEllipseVec: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeEllipseVec (GEOM::GEOM_Object_ptr theCenter, + GEOM::GEOM_Object_ptr theVector, + CORBA::Double theRMajor, + CORBA::Double theRMinor, + GEOM::GEOM_Object_ptr theVectorMajor) +{ + beginService( " GEOM_Superv_i::MakeEllipseVec" ); + MESSAGE("GEOM_Superv_i::MakeEllipseVec"); + getCurvesOp(); + GEOM::GEOM_Object_ptr anObj = myCurvesOp->MakeEllipseVec(theCenter, theVector, theRMajor, theRMinor, theVectorMajor); + endService( " GEOM_Superv_i::MakeEllipseVec" ); + return anObj; +} + //============================================================================= // MakeArc: //============================================================================= diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index b34c13214..e9e2dd242 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -557,6 +557,10 @@ public: GEOM::GEOM_Object_ptr MakeEllipse (GEOM::GEOM_Object_ptr theCenter, GEOM::GEOM_Object_ptr theVector, CORBA::Double theRMajor, CORBA::Double theRMinor); + GEOM::GEOM_Object_ptr MakeEllipseVec (GEOM::GEOM_Object_ptr theCenter, + GEOM::GEOM_Object_ptr theVector, + CORBA::Double theRMajor, CORBA::Double theRMinor, + GEOM::GEOM_Object_ptr theVectorMajor); GEOM::GEOM_Object_ptr MakeArc (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2, GEOM::GEOM_Object_ptr thePnt3); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 56e0ba3fb..61f6380c3 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -652,13 +652,18 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @param theVec Vector, normal to the plane of the ellipse. # @param theRMajor Major ellipse radius. # @param theRMinor Minor ellipse radius. + # @param theVecMaj Vector, direction by the main exis. # @return New GEOM_Object, containing the created ellipse. # # @ref tui_creation_ellipse "Example" - def MakeEllipse(self, thePnt, theVec, theRMajor, theRMinor): + def MakeEllipse(self, thePnt, theVec, theRMajor, theRMinor, theVecMaj=None): # Example: see GEOM_TestAll.py theRMajor, theRMinor, Parameters = ParseParameters(theRMajor, theRMinor) - anObj = self.CurvesOp.MakeEllipse(thePnt, theVec, theRMajor, theRMinor) + if theVecMaj is not None: + anObj = self.CurvesOp.MakeEllipseVec(thePnt, theVec, theRMajor, theRMinor, theVecMaj) + else: + anObj = self.CurvesOp.MakeEllipse(thePnt, theVec, theRMajor, theRMinor) + pass RaiseIfFailed("MakeEllipse", self.CurvesOp) anObj.SetParameters(Parameters) return anObj