From: jfa Date: Wed, 13 Aug 2008 13:20:56 +0000 (+0000) Subject: IMP 0016656: EDF531: Default constructor in creation dialog of geometric objects. X-Git-Tag: V5_1_0a1~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a0e96fa432c10a8856c2c5d79bad2db629c18d4a;p=modules%2Fgeom.git IMP 0016656: EDF531: Default constructor in creation dialog of geometric objects. --- diff --git a/doc/salome/gui/GEOM/images/circle1.png b/doc/salome/gui/GEOM/images/circle1.png index 8eae9abbe..c9708f1d7 100755 Binary files a/doc/salome/gui/GEOM/images/circle1.png and b/doc/salome/gui/GEOM/images/circle1.png differ diff --git a/doc/salome/gui/GEOM/images/ellipse.png b/doc/salome/gui/GEOM/images/ellipse.png index 6bce2c247..649303ef2 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_circle.doc b/doc/salome/gui/GEOM/input/creating_circle.doc index 153c61005..7b0442a3a 100644 --- a/doc/salome/gui/GEOM/input/creating_circle.doc +++ b/doc/salome/gui/GEOM/input/creating_circle.doc @@ -15,6 +15,10 @@ Radius) \n Arguments: Name + 1 vertex (for the center) + 1 edge (for the direction) + Radius. +\note Passing None as Center Point means Origin of global +coordinate system, passing None as \b Vector means OZ axis of global +coordinate system. + \image html circle1.png \n Secondly, you can define a \b Circle by three \b Points that lie on it. diff --git a/doc/salome/gui/GEOM/input/creating_ellipse.doc b/doc/salome/gui/GEOM/input/creating_ellipse.doc index 78972181b..8d9fdc6f2 100644 --- a/doc/salome/gui/GEOM/input/creating_ellipse.doc +++ b/doc/salome/gui/GEOM/input/creating_ellipse.doc @@ -12,6 +12,10 @@ Vector giving its normal, and its Major & Minor Radiuses. \n Arguments: Name + 1 vertex (for the center) + 1 edge (for the direction) + 1 X Radius + 1 Y Radius. +\note Passing None as Center Point means Origin of global +coordinate system, passing None as \b Vector means OZ axis of global +coordinate system. + \image html ellipse.png Example: @@ -21,4 +25,4 @@ the direction) + 1 X Radius + 1 Y Radius. Our TUI Scripts provide you with useful examples of creation of \ref tui_creation_ellipse "Basic Geometric Objects". -*/ \ No newline at end of file +*/ diff --git a/src/BasicGUI/BasicGUI_CircleDlg.cxx b/src/BasicGUI/BasicGUI_CircleDlg.cxx index 1a067c6fa..23fc15a4d 100644 --- a/src/BasicGUI/BasicGUI_CircleDlg.cxx +++ b/src/BasicGUI/BasicGUI_CircleDlg.cxx @@ -69,8 +69,8 @@ BasicGUI_CircleDlg::BasicGUI_CircleDlg( GeometryGUI* theGeometryGUI, QWidget* pa GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() ); GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) ); - GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) ); + GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) + " (Origin by default)" ); + GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " (Z axis by default)" ); GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) ); GroupPntVecR->PushButton1->setIcon( image1 ); GroupPntVecR->PushButton2->setIcon( image1 ); @@ -248,6 +248,8 @@ void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId ) connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + displayPreview(); } //================================================================================= @@ -494,12 +496,15 @@ bool BasicGUI_CircleDlg::isValid( QString& msg ) { const int id = getConstructorId(); if ( id == 0 ) - return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0; + //return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0; + //nil point means origin of global CS + //nil vector means Z axis + return getRadius() > 0; else if ( id == 1 ) return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() && !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 ); else if ( id == 2 ) - return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() && + return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() && !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 ); return false; } @@ -548,8 +553,10 @@ void BasicGUI_CircleDlg::addSubshapesToStudy() switch ( getConstructorId() ) { case 0: - objMap[GroupPntVecR->LineEdit1->text()] = myPoint; - objMap[GroupPntVecR->LineEdit2->text()] = myDir; + if (!CORBA::is_nil(myPoint)) + objMap[GroupPntVecR->LineEdit1->text()] = myPoint; + if (!CORBA::is_nil(myDir)) + objMap[GroupPntVecR->LineEdit2->text()] = myDir; break; case 1: objMap[Group3Pnts->LineEdit1->text()] = myPoint1; diff --git a/src/BasicGUI/BasicGUI_EllipseDlg.cxx b/src/BasicGUI/BasicGUI_EllipseDlg.cxx index b0b451569..519e088a3 100644 --- a/src/BasicGUI/BasicGUI_EllipseDlg.cxx +++ b/src/BasicGUI/BasicGUI_EllipseDlg.cxx @@ -69,8 +69,8 @@ BasicGUI_EllipseDlg::BasicGUI_EllipseDlg( GeometryGUI* theGeometryGUI, QWidget* GroupPoints = new DlgRef_2Sel2Spin( centralWidget() ); GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) ); - GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) ); + 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->PushButton1->setIcon( image1 ); @@ -146,6 +146,8 @@ void BasicGUI_EllipseDlg::Init() SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); initName( tr( "GEOM_ELLIPSE" ) ); + + displayPreview(); } //================================================================================= @@ -189,6 +191,7 @@ bool BasicGUI_EllipseDlg::ClickOnApply() //globalSelection(GEOM_POINT); globalSelection(); // close local contexts, if any localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + displayPreview(); return true; } @@ -368,7 +371,10 @@ bool BasicGUI_EllipseDlg::isValid( QString& msg ) msg = tr( "GEOM_ELLIPSE_ERROR_1" ); return false; } - return !myPoint->_is_nil() && !myDir->_is_nil(); + //return !myPoint->_is_nil() && !myDir->_is_nil(); + //nil point means origin of global CS + //nil vector means Z axis + return true; } //================================================================================= @@ -395,8 +401,10 @@ void BasicGUI_EllipseDlg::addSubshapesToStudy() { QMap objMap; - objMap[GroupPoints->LineEdit1->text()] = myPoint; - objMap[GroupPoints->LineEdit2->text()] = myDir; + if (!CORBA::is_nil(myPoint)) + objMap[GroupPoints->LineEdit1->text()] = myPoint; + if (!CORBA::is_nil(myDir)) + objMap[GroupPoints->LineEdit2->text()] = myDir; addSubshapesToFather( objMap ); } diff --git a/src/BasicGUI/BasicGUI_VectorDlg.cxx b/src/BasicGUI/BasicGUI_VectorDlg.cxx index dd6102815..9408a0a39 100644 --- a/src/BasicGUI/BasicGUI_VectorDlg.cxx +++ b/src/BasicGUI/BasicGUI_VectorDlg.cxx @@ -44,7 +44,7 @@ //================================================================================= // class : BasicGUI_VectorDlg() -// purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the +// purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the // name 'name' and widget flags set to 'f'. // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. @@ -91,7 +91,7 @@ BasicGUI_VectorDlg::BasicGUI_VectorDlg( GeometryGUI* theGeometryGUI, QWidget* pa /***************************************************************/ setHelpFileName( "create_vector_page.html" ); - + /* Initialisations */ Init(); } @@ -102,7 +102,7 @@ BasicGUI_VectorDlg::BasicGUI_VectorDlg( GeometryGUI* theGeometryGUI, QWidget* pa // purpose : Destroys the object and frees any allocated resources //================================================================================= BasicGUI_VectorDlg::~BasicGUI_VectorDlg() -{ +{ } @@ -121,7 +121,7 @@ void BasicGUI_VectorDlg::Init() /* Get setting of step value from file configuration */ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 ); - + /* min, max, step and decimals for spin boxes */ initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY @@ -137,7 +137,7 @@ void BasicGUI_VectorDlg::Init() /* signals and slots connections */ connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ); connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); - + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); @@ -157,12 +157,13 @@ void BasicGUI_VectorDlg::Init() connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) ); - connect( myGeomGUI->getApp()->selectionMgr(), + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); initName( tr("GEOM_VECTOR") ); - ConstructorsClicked( 0 ); + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } //================================================================================= @@ -192,14 +193,14 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId ) { GroupDimensions->hide(); GroupPoints->show(); - + myEditCurrentArgument = GroupPoints->LineEdit1; GroupPoints->LineEdit1->setText( "" ); GroupPoints->LineEdit2->setText( "" ); - + globalSelection(); // close local contexts, if any localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - connect( myGeomGUI->getApp()->selectionMgr(), + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); break; } @@ -208,12 +209,12 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId ) GroupPoints->hide(); GroupDimensions->show(); globalSelection(); // close local contexts, if any - - double dx( 0. ), dy( 0. ), dz( 0. ); + + double dx( 0. ), dy( 0. ), dz( 0. ); GroupDimensions->SpinBox_DX->setValue( dx ); GroupDimensions->SpinBox_DY->setValue( dy ); GroupDimensions->SpinBox_DZ->setValue( dz ); - + GroupDimensions->CheckButton1->setChecked( false ); break; } @@ -271,7 +272,7 @@ void BasicGUI_VectorDlg::SelectionIntoArgument() return; } - // nbSel == 1 + // nbSel == 1 Standard_Boolean aRes = Standard_False; GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes ); if ( !CORBA::is_nil( aSelectedObject ) && aRes ) { @@ -334,7 +335,7 @@ void BasicGUI_VectorDlg::SetEditCurrentArgument() // purpose : //================================================================================= void BasicGUI_VectorDlg::LineEditReturnPressed() -{ +{ QLineEdit* send = (QLineEdit*)sender(); if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1; else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2; @@ -397,7 +398,7 @@ void BasicGUI_VectorDlg::ReverseVector( int state ) GroupDimensions->SpinBox_DX->setValue( dx ); GroupDimensions->SpinBox_DY->setValue( dy ); GroupDimensions->SpinBox_DZ->setValue( dz ); - + displayPreview(); } @@ -426,7 +427,7 @@ bool BasicGUI_VectorDlg::isValid( QString& msg ) bool BasicGUI_VectorDlg::execute( ObjectList& objects ) { bool res = false; - + GEOM::GEOM_Object_var anObj; switch ( getConstructorId() ) { diff --git a/src/BasicGUI/BasicGUI_WorkingPlaneDlg.cxx b/src/BasicGUI/BasicGUI_WorkingPlaneDlg.cxx index f5a646c87..55bba2858 100644 --- a/src/BasicGUI/BasicGUI_WorkingPlaneDlg.cxx +++ b/src/BasicGUI/BasicGUI_WorkingPlaneDlg.cxx @@ -102,20 +102,20 @@ BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg( GeometryGUI* theGeometryGUI, /***************************************************************/ QGroupBox* aReverseGroupBox = new QGroupBox( centralWidget() ); QHBoxLayout* aReverseGroupBoxLayout = new QHBoxLayout( aReverseGroupBox ); - aReverseGroupBoxLayout->setMargin( 9 ); + aReverseGroupBoxLayout->setMargin( 9 ); aReverseGroupBoxLayout->setSpacing( 6 ); - + myReverseCB = new QCheckBox( aReverseGroupBox ); myReverseCB->setText( tr( "GEOM_REVERSE_PLANE" ) ); aReverseGroupBoxLayout->addWidget( myReverseCB ); - + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); layout->setMargin( 0 ); layout->setSpacing( 6 ); layout->addWidget( Group1 ); layout->addWidget( Group2 ); layout->addWidget( Group3 ); layout->addWidget( aReverseGroupBox ); - + setHelpFileName( "create_wplane_page.html" ); Init(); @@ -175,7 +175,8 @@ void BasicGUI_WorkingPlaneDlg::Init() initName( tr( "GEOM_WPLANE" ) ); - ConstructorsClicked( 0 ); + setConstructorId( 2 ); // simplest constructor + ConstructorsClicked( 2 ); } //================================================================================= @@ -196,15 +197,15 @@ void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId ) aMap.Add( GEOM_PLANE ); aMap.Add( GEOM_MARKER ); globalSelection( aMap ); - + Group2->hide(); Group3->hide(); Group1->show(); - + myEditCurrentArgument = Group1->LineEdit1; Group1->LineEdit1->setText( "" ); myFace = GEOM::GEOM_Object::_nil(); - + connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); break; } @@ -213,17 +214,17 @@ void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId ) //globalSelection( GEOM_LINE ); GEOM::GEOM_Object_var anObj; localSelection( anObj, TopAbs_EDGE ); - + Group1->hide(); Group3->hide(); Group2->show(); - + myEditCurrentArgument = Group2->LineEdit1; Group2->LineEdit1->setText( "" ); Group2->LineEdit2->setText( "" ); myVectX = GEOM::GEOM_Object::_nil(); myVectZ = GEOM::GEOM_Object::_nil(); - + connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); break; } @@ -232,13 +233,13 @@ void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId ) Group1->hide(); Group2->hide(); Group3->show(); - + Group3->RadioButton1->setChecked( true ); aOriginType = 1; break; } } - + qApp->processEvents(); updateGeometry(); resize( minimumSize() ); @@ -274,12 +275,12 @@ bool BasicGUI_WorkingPlaneDlg::ClickOnApply() { buttonApply()->setFocus(); myGeomGUI->application()->putInfo( "" ); - + if ( updateWPlane( false ) ) { myGeomGUI->SetWorkingPlane( myWPlane ); myGeomGUI->ActiveWorkingPlane(); } - + return true; } @@ -316,7 +317,7 @@ void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument() if ( myEditCurrentArgument == Group1->LineEdit1 ) myFace = aSelectedObject; - else if ( myEditCurrentArgument == Group2->LineEdit1 || + else if ( myEditCurrentArgument == Group2->LineEdit1 || myEditCurrentArgument == Group2->LineEdit2 ) { if ( aRes && !aSelectedObject->_is_nil() ) { TopoDS_Shape aShape; @@ -347,7 +348,7 @@ void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument() } myEditCurrentArgument->setText( aName ); - + updateWPlane(); } @@ -445,7 +446,7 @@ void BasicGUI_WorkingPlaneDlg::enterEvent( QEvent* ) bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview ) { erasePreview(); - + const int id = getConstructorId(); if ( id == 0 ) { // by planar face selection @@ -470,20 +471,20 @@ bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview ) gp_Dir aDirN ( Zx, Zy, Zz ); gp_Dir aDirX ( Xx, Xy, Xz ); myWPlane = gp_Ax3( aPnt, aDirN, aDirX ); - } + } else { if ( !showPreview ) showError( "Wrong shape selected (has to be a planar face)" ); return false; } - } + } else if ( id == 1 ) { // by two vectors (Ox & Oz) if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) { if ( !showPreview ) showError( "Two vectors have to be selected" ); return false; } - + TopoDS_Edge aVectX, aVectZ; TopoDS_Vertex VX1, VX2, VZ1, VZ2; gp_Vec aVX, aVZ; @@ -534,7 +535,7 @@ bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview ) myWPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX ); - } + } else if ( id == 2 ) { // by selection from standard (OXY or OYZ, or OZX) gp_Ax2 anAx2; @@ -544,23 +545,24 @@ bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview ) myWPlane = gp_Ax3( anAx2 ); - } + } else { return false; } - + if ( myReverseCB->isChecked() ) { myWPlane.YReverse(); myWPlane.ZReverse(); } - + if ( showPreview ) { GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() ); - GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(), - myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(), - myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() ); + GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker + ( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(), + myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(), + myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() ); displayPreview( anObj ); } - + return true; } diff --git a/src/GEOMImpl/GEOMImpl_CircleDriver.cxx b/src/GEOMImpl/GEOMImpl_CircleDriver.cxx index 79184422b..3d32b36e9 100644 --- a/src/GEOMImpl/GEOMImpl_CircleDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_CircleDriver.cxx @@ -77,65 +77,87 @@ Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape aShape; if (aType == CIRCLE_PNT_VEC_R) { - Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); + // Center + gp_Pnt aP = gp::Origin(); + Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); + if (!aRefPoint.IsNull()) { + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.ShapeType() != TopAbs_VERTEX) { + Standard_ConstructionError::Raise + ("Circle creation aborted: invalid center argument, must be a point"); + } + aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + } + // Normal + gp_Vec aV = gp::DZ(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); - TopoDS_Shape aShapePnt = aRefPoint->GetValue(); - TopoDS_Shape aShapeVec = aRefVector->GetValue(); - if (aShapePnt.ShapeType() == TopAbs_VERTEX && - aShapeVec.ShapeType() == TopAbs_EDGE) { - gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + if (!aRefVector.IsNull()) { + 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"); + } TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { - gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); - gp_Ax2 anAxes (aP, aV); - gp_Circ aCirc (anAxes, aCI.GetRadius()); - aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); + 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"); + } } } + // Axes + gp_Ax2 anAxes (aP, aV); + // Circle + gp_Circ aCirc (anAxes, aCI.GetRadius()); + aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); } - else if (aType == CIRCLE_CENTER_TWO_PNT) { - Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); - Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); - Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); - TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue(); - TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue(); - TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue(); - if (aShapePnt1.ShapeType() == TopAbs_VERTEX && aShapePnt2.ShapeType() == TopAbs_VERTEX && - aShapePnt3.ShapeType() == TopAbs_VERTEX) - { - gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1)); - gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2)); - gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3)); - - if (aP1.Distance(aP2) < gp::Resolution() || - aP1.Distance(aP3) < gp::Resolution() || - aP2.Distance(aP3) < gp::Resolution()) - Standard_ConstructionError::Raise("Circle creation aborted: coincident points given"); - if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) - Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line"); - double x, y, z, x1, y1, z1, x2, y2, z2, dx, dy, dz, dx2, dy2, dz2, dx3, dy3, dz3, aRadius; - //Calculations for Radius - x = aP1.X(); y = aP1.Y(); z = aP1.Z(); - x1 = aP2.X(); y1 = aP2.Y(); z1 = aP2.Z(); - dx = x1 - x; - dy = y1 - y; - dz = z1 - z; - aRadius = sqrt(dx*dx + dy*dy + dz*dz); - //Calculations for Plane Vector - x2 = aP3.X(); y2 = aP3.Y(); z2 = aP3.Z(); - dx2 = x2 - x; dy2 = y2 - y; dz2 = z2 - z; - dx3 = ((dy*dz2) - (dy2*dz))/100; - dy3 = ((dx2*dz) - (dx*dz2))/100; - dz3 = ((dx*dy2) - (dx2*dy))/100; - //Make Plane Vector - gp_Dir aDir ( dx3, dy3, dz3 ); - //Make Circle - gp_Ax2 anAxes (aP1, aDir); - gp_Circ aCirc (anAxes, aRadius); - aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); - } + else if (aType == CIRCLE_CENTER_TWO_PNT) { + Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); + Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); + Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); + TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue(); + TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue(); + TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue(); + if (aShapePnt1.ShapeType() == TopAbs_VERTEX && + aShapePnt2.ShapeType() == TopAbs_VERTEX && + aShapePnt3.ShapeType() == TopAbs_VERTEX) + { + gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1)); + gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2)); + gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3)); + + if (aP1.Distance(aP2) < gp::Resolution() || + aP1.Distance(aP3) < gp::Resolution() || + aP2.Distance(aP3) < gp::Resolution()) + Standard_ConstructionError::Raise("Circle creation aborted: coincident points given"); + + if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) + Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line"); + + double x, y, z, x1, y1, z1, x2, y2, z2, dx, dy, dz, dx2, dy2, dz2, dx3, dy3, dz3, aRadius; + //Calculations for Radius + x = aP1.X(); y = aP1.Y(); z = aP1.Z(); + x1 = aP2.X(); y1 = aP2.Y(); z1 = aP2.Z(); + dx = x1 - x; + dy = y1 - y; + dz = z1 - z; + aRadius = sqrt(dx*dx + dy*dy + dz*dz); + //Calculations for Plane Vector + x2 = aP3.X(); y2 = aP3.Y(); z2 = aP3.Z(); + dx2 = x2 - x; dy2 = y2 - y; dz2 = z2 - z; + dx3 = ((dy*dz2) - (dy2*dz))/100; + dy3 = ((dx2*dz) - (dx*dz2))/100; + dz3 = ((dx*dy2) - (dx2*dy))/100; + //Make Plane Vector + gp_Dir aDir ( dx3, dy3, dz3 ); + //Make Circle + gp_Ax2 anAxes (aP1, aDir); + gp_Circ aCirc (anAxes, aRadius); + aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); + } } else if (aType == CIRCLE_THREE_PNT) { Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); @@ -160,7 +182,7 @@ Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); } } - else { + else { } if (aShape.IsNull()) return 0; diff --git a/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx b/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx index 03685a46b..a36e92c3a 100644 --- a/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_EllipseDriver.cxx @@ -71,24 +71,44 @@ Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape aShape; if (aType == ELLIPSE_PNT_VEC_RR) { - Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); + // Center + gp_Pnt aP = gp::Origin(); + Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); + if (!aRefPoint.IsNull()) { + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.ShapeType() != TopAbs_VERTEX) { + Standard_ConstructionError::Raise + ("Circle creation aborted: invalid center argument, must be a point"); + } + aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + } + // Normal + gp_Vec aV = gp::DZ(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); - TopoDS_Shape aShapePnt = aRefPoint->GetValue(); - TopoDS_Shape aShapeVec = aRefVector->GetValue(); - if (aShapePnt.ShapeType() == TopAbs_VERTEX && - aShapeVec.ShapeType() == TopAbs_EDGE) { - gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + if (!aRefVector.IsNull()) { + 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"); + } TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { - gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); - gp_Ax2 anAxes (aP, aV); - gp_Elips anEll (anAxes, aCI.GetRMajor(), aCI.GetRMinor()); - aShape = BRepBuilderAPI_MakeEdge(anEll).Edge(); + 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"); + } } } - } else { + // Axes + gp_Ax2 anAxes (aP, aV); + // Ellipse + gp_Elips anEll (anAxes, aCI.GetRMajor(), aCI.GetRMinor()); + aShape = BRepBuilderAPI_MakeEdge(anEll).Edge(); + } + else { } if (aShape.IsNull()) return 0; diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index d6628ca43..9a497b2e9 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -266,7 +266,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR { SetErrorCode(KO); - if (thePnt.IsNull() || theVec.IsNull()) return NULL; + // Not set thePnt means origin of global CS, + // Not set theVec means Z axis of global CS + //if (thePnt.IsNull() || theVec.IsNull()) return NULL; //Add a new Circle object Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE); @@ -281,13 +283,18 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR GEOMImpl_ICircle aCI (aFunction); - Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction(); - Handle(GEOM_Function) aRefVec = theVec->GetLastFunction(); + if (!thePnt.IsNull()) { + Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction(); + if (aRefPnt.IsNull()) return NULL; + aCI.SetCenter(aRefPnt); + } - if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL; + if (!theVec.IsNull()) { + Handle(GEOM_Function) aRefVec = theVec->GetLastFunction(); + if (aRefVec.IsNull()) return NULL; + aCI.SetVector(aRefVec); + } - aCI.SetCenter(aRefPnt); - aCI.SetVector(aRefVec); aCI.SetRadius(theR); //Compute the Circle value @@ -325,7 +332,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse { SetErrorCode(KO); - if (thePnt.IsNull() || theVec.IsNull()) return NULL; + // Not set thePnt means origin of global CS, + // Not set theVec means Z axis of global CS + //if (thePnt.IsNull() || theVec.IsNull()) return NULL; //Add a new Ellipse object Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE); @@ -340,13 +349,18 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse GEOMImpl_IEllipse aCI (aFunction); - Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction(); - Handle(GEOM_Function) aRefVec = theVec->GetLastFunction(); + if (!thePnt.IsNull()) { + Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction(); + if (aRefPnt.IsNull()) return NULL; + aCI.SetCenter(aRefPnt); + } - if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL; + if (!theVec.IsNull()) { + Handle(GEOM_Function) aRefVec = theVec->GetLastFunction(); + if (aRefVec.IsNull()) return NULL; + aCI.SetVector(aRefVec); + } - aCI.SetCenter(aRefPnt); - aCI.SetVector(aRefVec); aCI.SetRMajor(theRMajor); aCI.SetRMinor(theRMinor); diff --git a/src/GEOM_I/GEOM_ICurvesOperations_i.cc b/src/GEOM_I/GEOM_ICurvesOperations_i.cc index 3a15afb1b..3bda04930 100644 --- a/src/GEOM_I/GEOM_ICurvesOperations_i.cc +++ b/src/GEOM_I/GEOM_ICurvesOperations_i.cc @@ -65,15 +65,22 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeCirclePntVecR //Set a not done flag GetOperations()->SetNotDone(); - if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn(); - - //Get the reference points - Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject - (thePnt->GetStudyID(), thePnt->GetEntry()); - Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject - (theVec->GetStudyID(), theVec->GetEntry()); - - if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn(); + // Not set thePnt means origin of global CS, + // Not set theVec means Z axis of global CS + //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn(); + + //Get the arguments + Handle(GEOM_Object) aPnt, aVec; + 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 Circle Handle(GEOM_Object) anObject = @@ -167,15 +174,22 @@ GEOM::GEOM_Object_ptr GEOM_ICurvesOperations_i::MakeEllipse //Set a not done flag GetOperations()->SetNotDone(); - if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn(); + // Not set thePnt means origin of global CS, + // Not set theVec means Z axis of global CS + //if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn(); - //Get the reference points - Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject - (thePnt->GetStudyID(), thePnt->GetEntry()); - Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject - (theVec->GetStudyID(), theVec->GetEntry()); - - if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn(); + //Get the arguments + Handle(GEOM_Object) aPnt, aVec; + 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 = diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index d4f38a78b..2b2f27dc3 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -500,12 +500,22 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the created circle. # # @ref tui_creation_circle "Example" - def MakeCircle(self,thePnt, theVec, theR): + def MakeCircle(self, thePnt, theVec, theR): # Example: see GEOM_TestAll.py anObj = self.CurvesOp.MakeCirclePntVecR(thePnt, theVec, theR) RaiseIfFailed("MakeCirclePntVecR", self.CurvesOp) return anObj + ## Create a circle with given radius. + # Center of the circle will be in the origin of global + # coordinate system and normal vector will be codirected with Z axis + # @param theR Circle radius. + # @return New GEOM_Object, containing the created circle. + def MakeCircleR(self, theR): + anObj = self.CurvesOp.MakeCirclePntVecR(None, None, theR) + RaiseIfFailed("MakeCirclePntVecR", self.CurvesOp) + return anObj + ## Create a circle, passing through three given points # @param thePnt1,thePnt2,thePnt3 Points, defining the circle. # @return New GEOM_Object, containing the created circle. @@ -538,12 +548,23 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @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): # Example: see GEOM_TestAll.py anObj = self.CurvesOp.MakeEllipse(thePnt, theVec, theRMajor, theRMinor) RaiseIfFailed("MakeEllipse", self.CurvesOp) return anObj + ## Create an ellipse with given radiuses. + # Center of the ellipse will be in the origin of global + # coordinate system and normal vector will be codirected with Z axis + # @param theRMajor Major ellipse radius. + # @param theRMinor Minor ellipse radius. + # @return New GEOM_Object, containing the created ellipse. + def MakeEllipseRR(self, theRMajor, theRMinor): + anObj = self.CurvesOp.MakeEllipse(None, None, theRMajor, theRMinor) + RaiseIfFailed("MakeEllipse", self.CurvesOp) + return anObj + ## Create a polyline on the set of points. # @param thePoints Sequence of points for the polyline. # @return New GEOM_Object, containing the created polyline. diff --git a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx index 2dcecd1bd..b6a8dc33f 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx @@ -152,7 +152,8 @@ void PrimitiveGUI_BoxDlg::Init() initName( tr( "GEOM_BOX" ) ); - ConstructorsClicked( 0 ); + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } //================================================================================= diff --git a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx index bdf686812..07bf6b3ee 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx @@ -164,7 +164,8 @@ void PrimitiveGUI_ConeDlg::Init() initName( tr( "GEOM_CONE" ) ); - ConstructorsClicked( 0 ); + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx index 24b8387fa..871596615 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx @@ -159,7 +159,9 @@ void PrimitiveGUI_CylinderDlg::Init() SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); initName( tr( "GEOM_CYLINDER" ) ); - ConstructorsClicked( 0 ); + + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_SphereDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_SphereDlg.cxx index bc7854fb3..13bd12071 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_SphereDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_SphereDlg.cxx @@ -139,7 +139,8 @@ void PrimitiveGUI_SphereDlg::Init() initName( tr( "GEOM_SPHERE" ) ); - ConstructorsClicked( 0 ); + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } //================================================================================= diff --git a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx index 099cf7972..f4dc772a9 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx @@ -156,7 +156,8 @@ void PrimitiveGUI_TorusDlg::Init() initName( tr( "GEOM_TORUS" ) ); - ConstructorsClicked( 0 ); + setConstructorId( 1 ); // simplest constructor + ConstructorsClicked( 1 ); } //=================================================================================