From: jfa Date: Wed, 24 Sep 2008 11:38:20 +0000 (+0000) Subject: Bugs 16640, 19050: Improve selection mechanism in GEOM dialog boxes. X-Git-Tag: V5_1_0a2~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e545a24c53862b3de91f20771d7dd3143acc22a;p=modules%2Fgeom.git Bugs 16640, 19050: Improve selection mechanism in GEOM dialog boxes. --- diff --git a/src/BlocksGUI/BlocksGUI_BlockDlg.cxx b/src/BlocksGUI/BlocksGUI_BlockDlg.cxx index ba0e54b1f..9a755c357 100644 --- a/src/BlocksGUI/BlocksGUI_BlockDlg.cxx +++ b/src/BlocksGUI/BlocksGUI_BlockDlg.cxx @@ -233,7 +233,7 @@ void BlocksGUI_BlockDlg::SelectionIntoArgument() aSelMgr->selectedObjects(aSelList); if (aSelList.Extent() != 1) { - if (myEditCurrentArgument == Group2F->LineEdit1) myFace1 = GEOM::GEOM_Object::_nil(); + if (myEditCurrentArgument == Group2F->LineEdit1) myFace1 = GEOM::GEOM_Object::_nil(); else if (myEditCurrentArgument == Group2F->LineEdit2) myFace2 = GEOM::GEOM_Object::_nil(); else if (myEditCurrentArgument == Group6F->LineEdit1) myFace1 = GEOM::GEOM_Object::_nil(); else if (myEditCurrentArgument == Group6F->LineEdit2) myFace2 = GEOM::GEOM_Object::_nil(); @@ -271,8 +271,9 @@ void BlocksGUI_BlockDlg::SelectionIntoArgument() GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); } - else + else { aSelectedObject = aFindedObject; // get Object from study + } } else // Global Selection { @@ -372,9 +373,6 @@ void BlocksGUI_BlockDlg::SetEditCurrentArgument() break; } - // enable push button - aSender->setDown(true); - // set line edit as current argument if (aSender == Group2F->PushButton1) { myEditCurrentArgument = Group2F->LineEdit1; @@ -401,9 +399,11 @@ void BlocksGUI_BlockDlg::SetEditCurrentArgument() myEditCurrentArgument = Group6F->LineEdit6; } - // enable line edit + // enable push button and line edit myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) then loses focus + aSender->setDown(true); globalSelection(); // close local contexts, if any localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes @@ -422,6 +422,7 @@ void BlocksGUI_BlockDlg::ActivateThisDialog() localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); //Select Faces on All Shapes connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + displayPreview(); } //================================================================================= @@ -501,7 +502,7 @@ bool BlocksGUI_BlockDlg::execute (ObjectList& objects) } //================================================================================= -// function : addSubshapeToStudy +// function : addSubshapesToStudy // purpose : virtual method to add new SubObjects if local selection //================================================================================= void BlocksGUI_BlockDlg::addSubshapesToStudy() diff --git a/src/BlocksGUI/BlocksGUI_QuadFaceDlg.cxx b/src/BlocksGUI/BlocksGUI_QuadFaceDlg.cxx index ebb593f74..7cb6b6370 100644 --- a/src/BlocksGUI/BlocksGUI_QuadFaceDlg.cxx +++ b/src/BlocksGUI/BlocksGUI_QuadFaceDlg.cxx @@ -33,13 +33,14 @@ #include #include -#include - +// QT Includes #include // OCCT Includes -#include #include +#include + +#include //================================================================================= // class : BlocksGUI_QuadFaceDlg() @@ -392,9 +393,6 @@ void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument() break; } - // enable push button - aSender->setDown(true); - // set line edit as current argument QMap::iterator anIter; for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) { @@ -408,6 +406,10 @@ void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument() myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); + // enable push button + // after setFocus(), because it will be setDown(false) then loses focus + aSender->setDown(true); + activateSelection(); } diff --git a/src/BlocksGUI/BlocksGUI_TrsfDlg.cxx b/src/BlocksGUI/BlocksGUI_TrsfDlg.cxx index 1977fccf3..5a8dcb084 100644 --- a/src/BlocksGUI/BlocksGUI_TrsfDlg.cxx +++ b/src/BlocksGUI/BlocksGUI_TrsfDlg.cxx @@ -359,9 +359,6 @@ void BlocksGUI_TrsfDlg::SetEditCurrentArgument() break; } - // enable push button - aSender->setDown(true); - // set line edit as current argument QMap::iterator anIter; for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) { @@ -375,6 +372,10 @@ void BlocksGUI_TrsfDlg::SetEditCurrentArgument() myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); + // enable push button + // after setFocus(), because it will be setDown(false) then loses focus + aSender->setDown(true); + activateSelection(); } diff --git a/src/GEOMBase/GEOMBase_Skeleton.cxx b/src/GEOMBase/GEOMBase_Skeleton.cxx index 6bcb99393..0b21530b4 100644 --- a/src/GEOMBase/GEOMBase_Skeleton.cxx +++ b/src/GEOMBase/GEOMBase_Skeleton.cxx @@ -191,6 +191,7 @@ void GEOMBase_Skeleton::DeactivateActiveDialog() myGeomGUI->SetActiveDialogBox( 0 ); disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 ); } + erasePreview(); } //================================================================================= diff --git a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx index 05441ed86..d7c9f0d10 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx @@ -1,22 +1,22 @@ // GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : PrimitiveGUI_BoxDlg.cxx @@ -29,11 +29,12 @@ #include #include -#include #include +#include #include #include +// OCCT Includes #include #include #include @@ -41,57 +42,57 @@ #include #include -#include +//#include //================================================================================= // class : PrimitiveGUI_BoxDlg() -// purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the +// purpose : Constructs a PrimitiveGUI_BoxDlg 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. //================================================================================= -PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg( GeometryGUI* theGeometryGUI, QWidget* parent, - bool modal, Qt::WindowFlags fl ) - : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myInitial(true) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_2P" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BOX_DXYZ" ) )); - QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ"))); + QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_BOX_TITLE" ) ); + setWindowTitle(tr("GEOM_BOX_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BOX" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - mainFrame()->RadioButton2->setIcon( image1 ); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_BOX")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setIcon(image1); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->close(); - GroupPoints = new DlgRef_2Sel( centralWidget() ); - GroupPoints->GroupBox1->setTitle( tr( "GEOM_DIAGONAL_POINTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) ); - GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) ); - GroupPoints->PushButton1->setIcon( image2 ); - GroupPoints->PushButton2->setIcon( image2 ); - - GroupDimensions = new DlgRef_3Spin( centralWidget() ); - GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) ); - GroupDimensions->TextLabel1->setText( tr( "GEOM_DX" ) ); - GroupDimensions->TextLabel2->setText( tr( "GEOM_DY" ) ); - GroupDimensions->TextLabel3->setText( tr( "GEOM_DZ" ) ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupPoints ); - layout->addWidget( GroupDimensions ); + GroupPoints = new DlgRef_2Sel(centralWidget()); + GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS")); + GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg(1)); + GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(2)); + GroupPoints->PushButton1->setIcon(image2); + GroupPoints->PushButton2->setIcon(image2); + + GroupDimensions = new DlgRef_3Spin(centralWidget()); + GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ")); + GroupDimensions->TextLabel1->setText(tr("GEOM_DX")); + GroupDimensions->TextLabel2->setText(tr("GEOM_DY")); + GroupDimensions->TextLabel3->setText(tr("GEOM_DZ")); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPoints); + layout->addWidget(GroupDimensions); /***************************************************************/ - setHelpFileName( "create_box_page.html" ); - + setHelpFileName("create_box_page.html"); + Init(); } - //================================================================================= // function : ~DialogBox_Box() // purpose : Destroys the object and frees any allocated resources @@ -101,213 +102,220 @@ PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg() // no need to delete child widgets, Qt does it all for us } - //================================================================================= // function : Init() // purpose : //================================================================================= void PrimitiveGUI_BoxDlg::Init() { - /* init variables */ - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setReadOnly( true ); - GroupPoints->LineEdit2->setReadOnly( true ); - - myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); - - /* Get setting of step value from file configuration */ + // 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 - initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY + 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 + initSpinBox(GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + + // init variables + GroupPoints->LineEdit1->setReadOnly(true); + GroupPoints->LineEdit2->setReadOnly(true); + + GroupPoints->LineEdit1->setText(""); + GroupPoints->LineEdit2->setText(""); + myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); double initValue = 200.0; - GroupDimensions->SpinBox_DX->setValue( initValue ); - GroupDimensions->SpinBox_DY->setValue( initValue ); - GroupDimensions->SpinBox_DZ->setValue( initValue ); + GroupDimensions->SpinBox_DX->setValue(initValue); + GroupDimensions->SpinBox_DY->setValue(initValue); + GroupDimensions->SpinBox_DZ->setValue(initValue); - /* signals and slots connections */ - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); + connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); - connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - - connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) ); + connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double))); - initName( tr( "GEOM_BOX" ) ); + initName(tr("GEOM_BOX")); - setConstructorId( 1 ); // simplest constructor - ConstructorsClicked( 1 ); + setConstructorId(1); // simplest constructor + ConstructorsClicked(1); } //================================================================================= // function : SetDoubleSpinBoxStep() // purpose : Double spin box management //================================================================================= -void PrimitiveGUI_BoxDlg::SetDoubleSpinBoxStep( double step ) +void PrimitiveGUI_BoxDlg::SetDoubleSpinBoxStep (double step) { GroupDimensions->SpinBox_DX->setSingleStep(step); GroupDimensions->SpinBox_DY->setSingleStep(step); GroupDimensions->SpinBox_DZ->setSingleStep(step); } - //================================================================================= // function : ConstructorsClicked() // purpose : Radio button management //================================================================================= -void PrimitiveGUI_BoxDlg::ConstructorsClicked( int constructorId ) +void PrimitiveGUI_BoxDlg::ConstructorsClicked (int constructorId) { - disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 ); - - switch ( constructorId ) { + switch (constructorId) { case 0: { - //globalSelection( GEOM_POINT ); - globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - GroupDimensions->hide(); GroupPoints->show(); - - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setText( "" ); - GroupPoints->LineEdit2->setText( "" ); - myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + GroupPoints->PushButton1->click(); break; } case 1: { GroupPoints->hide(); GroupDimensions->show(); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); globalSelection(); // close local contexts, if any + + displayPreview(); break; } } - + qApp->processEvents(); updateGeometry(); - resize( minimumSize() ); + resize(minimumSize()); - displayPreview(); + if (myInitial) { + // on dialog initialization we init the first field with a selected object (if any) + SelectionIntoArgument(); + myInitial = false; + } + else { + displayPreview(); + } } - //================================================================================= // function : ClickOnOk() // purpose : //================================================================================= void PrimitiveGUI_BoxDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } - //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= bool PrimitiveGUI_BoxDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; - + initName(); - ConstructorsClicked( getConstructorId() ); + // activate selection and connect selection manager + ConstructorsClicked(getConstructorId()); return true; } - //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void PrimitiveGUI_BoxDlg::SelectionIntoArgument() { - if ( getConstructorId() != 0 ) + if (getConstructorId() != 0) return; - - myEditCurrentArgument->setText( "" ); - + + erasePreview(); + myEditCurrentArgument->setText(""); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); SALOME_ListIO aSelList; aSelMgr->selectedObjects(aSelList); - if ( aSelList.Extent() != 1 ) { - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) - myPoint1 = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) - myPoint2 = GEOM::GEOM_Object::_nil(); + if (aSelList.Extent() != 1) { + if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil(); return; } // nbSel == 1 Standard_Boolean testResult = Standard_False; - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult ); - - if ( !testResult || CORBA::is_nil( aSelectedObject ) ) + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); + + if (!testResult || CORBA::is_nil(aSelectedObject)) return; - + + QString aName = GEOMBase::GetName(aSelectedObject); + + // Get Selected object if selected subshape TopoDS_Shape aShape; - QString aName = GEOMBase::GetName( aSelectedObject ); - if (GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { TColStd_IndexedMapOfInteger aMap; - aSelMgr->GetIndexes( aSelList.First(), aMap ); - if ( aMap.Extent() == 1) { // Local Selection - int anIndex = aMap( 1 ); - aName.append( ":vertex_" + QString::number( anIndex ) ); + aSelMgr->GetIndexes(aSelList.First(), aMap); + if (aMap.Extent() == 1) // Local Selection + { + int anIndex = aMap(1); + aName.append(":vertex_" + QString::number(anIndex)); //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName ); - - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = - getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); + GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); + + if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = + getGeomEngine()->GetIShapesOperations(getStudyId()); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); } else { - aSelectedObject = aFindedObject; // get Object from study + aSelectedObject = aFindedObject; // get Object from study } } - else { // Global Selection - if ( aShape.ShapeType() != TopAbs_VERTEX ) { + else // Global Selection + { + if (aShape.ShapeType() != TopAbs_VERTEX) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; } } } - myEditCurrentArgument->setText( aName ); + myEditCurrentArgument->setText(aName); + + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) + if (myEditCurrentArgument == GroupPoints->LineEdit1) { myPoint1 = aSelectedObject; - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (!myPoint1->_is_nil() && myPoint2->_is_nil()) + GroupPoints->PushButton2->click(); + } + else if (myEditCurrentArgument == GroupPoints->LineEdit2) { myPoint2 = aSelectedObject; - + if (!myPoint2->_is_nil() && myPoint1->_is_nil()) + GroupPoints->PushButton1->click(); + } + displayPreview(); } - //================================================================================= // function : SetEditCurrentArgument() // purpose : @@ -315,20 +323,41 @@ void PrimitiveGUI_BoxDlg::SelectionIntoArgument() void PrimitiveGUI_BoxDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - - if ( send == GroupPoints->PushButton1 ) + + // ?? Commented, because we need this flag in ConstructorsClicked, because + // SelectionIntoArgument must be called only on dialog creation, and must not be called on + // simple switch between constructors (as we need to keep old values in fields in this case) + + // clear selection + //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + //if (myInitial) + // myInitial = false; + //else + // myGeomGUI->getApp()->selectionMgr()->clearSelected(); + + if (send == GroupPoints->PushButton1) { myEditCurrentArgument = GroupPoints->LineEdit1; - else if ( send == GroupPoints->PushButton2 ) + GroupPoints->PushButton2->setDown(false); + GroupPoints->LineEdit2->setEnabled(false); + } + else if (send == GroupPoints->PushButton2) { myEditCurrentArgument = GroupPoints->LineEdit2; - - // globalSelection( GEOM_POINT ); - globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - + GroupPoints->PushButton1->setDown(false); + GroupPoints->LineEdit1->setEnabled(false); + } + + // enable line edit + myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); - SelectionIntoArgument(); -} + // after setFocus(), because it will be setDown(false) then loses focus + send->setDown(true); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(); // close local contexts, if any + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); +} //================================================================================= // function : LineEditReturnPressed() @@ -337,13 +366,12 @@ void PrimitiveGUI_BoxDlg::SetEditCurrentArgument() void PrimitiveGUI_BoxDlg::LineEditReturnPressed() { QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) { + if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -351,24 +379,27 @@ void PrimitiveGUI_BoxDlg::LineEditReturnPressed() void PrimitiveGUI_BoxDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - - ConstructorsClicked( getConstructorId() ); + //if (getConstructorId() == 0) { + // localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); + // connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + // this, SLOT(SelectionIntoArgument())); + //} + //displayPreview(); + + // reinit, because some selected objects could be removed + Init(); } - //================================================================================= // function : enterEvent [REDEFINED] // purpose : //================================================================================= -void PrimitiveGUI_BoxDlg::enterEvent( QEvent* ) +void PrimitiveGUI_BoxDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } - //================================================================================= // function : ValueChangedInSpinBox() // purpose : @@ -378,75 +409,71 @@ void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox() displayPreview(); } - //================================================================================= // function : createOperation // purpose : //================================================================================= GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation() { - return getGeomEngine()->GetI3DPrimOperations( getStudyId() ); + return getGeomEngine()->GetI3DPrimOperations(getStudyId()); } - //================================================================================= // function : isValid // purpose : //================================================================================= -bool PrimitiveGUI_BoxDlg::isValid( QString& msg ) +bool PrimitiveGUI_BoxDlg::isValid (QString&) { - return getConstructorId() == 0 ? !( myPoint1->_is_nil() || myPoint2->_is_nil() ) : true; + return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true; } - //================================================================================= // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_BoxDlg::execute (ObjectList& objects) { bool res = false; - + GEOM::GEOM_Object_var anObj; - - switch ( getConstructorId() ) { - case 0 : - { - if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) { - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 ); - res = true; + + switch (getConstructorId()) { + case 0: + { + if (!CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2)) { + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakeBoxTwoPnt(myPoint1, myPoint2); + res = true; } - - break; } - case 1 : + break; + case 1: { double x = GroupDimensions->SpinBox_DX->value(); double y = GroupDimensions->SpinBox_DY->value(); double z = GroupDimensions->SpinBox_DZ->value(); - - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z ); + + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakeBoxDXDYDZ(x, y, z); res = true; - break; } + break; } - - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); - + + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + return res; } //================================================================================= -// function : addSubshapeToStudy +// function : addSubshapesToStudy // purpose : virtual method to add new SubObjects if local selection //================================================================================= void PrimitiveGUI_BoxDlg::addSubshapesToStudy() { - QMap objMap; - if ( getConstructorId() == 0 ) { + if (getConstructorId() == 0) { + QMap objMap; objMap[GroupPoints->LineEdit1->text()] = myPoint1; objMap[GroupPoints->LineEdit2->text()] = myPoint2; - addSubshapesToFather( objMap ); + addSubshapesToFather(objMap); } } diff --git a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.h b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.h index cb6ab13ef..d89955596 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.h @@ -38,11 +38,11 @@ class DlgRef_3Spin; class PrimitiveGUI_BoxDlg : public GEOMBase_Skeleton { Q_OBJECT - + public: PrimitiveGUI_BoxDlg( GeometryGUI*, QWidget* = 0, bool modal = false, Qt::WindowFlags = 0 ); ~PrimitiveGUI_BoxDlg(); - + protected: // redefined from GEOMBase_Helper virtual GEOM::GEOM_IOperations_ptr createOperation(); @@ -55,8 +55,11 @@ private: void enterEvent( QEvent* ); private: - GEOM::GEOM_Object_var myPoint1, myPoint2; /* Points containing the vector */ - + GEOM::GEOM_Object_var myPoint1, myPoint2; /* Points containing the vector */ + + // to initialize the first selection field with a selected object on the dialog creation + bool myInitial; + DlgRef_2Sel* GroupPoints; DlgRef_3Spin* GroupDimensions; diff --git a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx index 1fe9e0fe3..8055391de 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.cxx @@ -1,22 +1,22 @@ // GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : PrimitiveGUI_ConeDlg.cxx @@ -29,11 +29,12 @@ #include #include -#include #include +#include #include #include +// OCCT Includes #include #include #include @@ -45,56 +46,56 @@ //================================================================================= // class : PrimitiveGUI_ConeDlg() -// purpose : Constructs a PrimitiveGUI_ConeDlg which is a child of 'parent', with the +// purpose : Constructs a PrimitiveGUI_ConeDlg 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. //================================================================================= -PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg( GeometryGUI* theGeometryGUI, QWidget* parent, - bool modal, Qt::WindowFlags fl ) - : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +PrimitiveGUI_ConeDlg::PrimitiveGUI_ConeDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myInitial(true) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_PV" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CONE_DXYZ" ) ) ); - QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CONE_PV"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CONE_DXYZ"))); + QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_CONE_TITLE" ) ); + setWindowTitle(tr("GEOM_CONE_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CONE" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - mainFrame()->RadioButton2->setIcon( image1 ); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_CONE")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setIcon(image1); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->close(); - GroupPoints = new DlgRef_2Sel3Spin( centralWidget() ); - GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) ); - GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) ); - GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) ); - GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) ); - GroupPoints->TextLabel5->setText( tr( "GEOM_HEIGHT" ) ); - GroupPoints->PushButton1->setIcon( image2 ); - GroupPoints->PushButton2->setIcon( image2 ); - - GroupDimensions = new DlgRef_3Spin( centralWidget() ); - GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) ); - GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) ); - GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) ); - GroupDimensions->TextLabel3->setText( tr( "GEOM_HEIGHT" ) ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupPoints ); - layout->addWidget( GroupDimensions ); + GroupPoints = new DlgRef_2Sel3Spin(centralWidget()); + GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT")); + GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR")); + GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg(1)); + GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg(2)); + GroupPoints->TextLabel5->setText(tr("GEOM_HEIGHT")); + GroupPoints->PushButton1->setIcon(image2); + GroupPoints->PushButton2->setIcon(image2); + + GroupDimensions = new DlgRef_3Spin(centralWidget()); + GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ")); + GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg(1)); + GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg(2)); + GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT")); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPoints); + layout->addWidget(GroupDimensions); /***************************************************************/ - setHelpFileName( "create_cone_page.html" ); - + setHelpFileName("create_cone_page.html"); + Init(); } - //================================================================================= // function : ~PrimitiveGUI_ConeDlg() // purpose : Destroys the object and frees any allocated resources @@ -104,76 +105,72 @@ PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg() // no need to delete child widgets, Qt does it all for us } - //================================================================================= // function : Init() // purpose : //================================================================================= void PrimitiveGUI_ConeDlg::Init() { - /* init variables */ - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setReadOnly( true ); - GroupPoints->LineEdit2->setReadOnly( true ); - - myPoint = myDir = GEOM::GEOM_Object::_nil(); - - /* Get setting of step value from file configuration */ + // 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 & initial values */ - initSpinBox( GroupPoints->SpinBox_DX, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupPoints->SpinBox_DY, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupPoints->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupDimensions->SpinBox_DX, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupDimensions->SpinBox_DY, 0.000, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - - double aRadius1( 100.0 ), aRadius2( 0.0 ), aHeight( 300.0 ); - GroupPoints->SpinBox_DX->setValue( aRadius1 ); - GroupPoints->SpinBox_DY->setValue( aRadius2 ); - GroupPoints->SpinBox_DZ->setValue( aHeight ); - GroupDimensions->SpinBox_DX->setValue( aRadius1 ); - GroupDimensions->SpinBox_DY->setValue( aRadius2 ); - GroupDimensions->SpinBox_DZ->setValue( aHeight ); - - /* signals and slots connections */ - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); - - connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); - - connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - - connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - - connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupPoints->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - - connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) ); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - - initName( tr( "GEOM_CONE" ) ); - - setConstructorId( 1 ); // simplest constructor - ConstructorsClicked( 1 ); -} + double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100); + + // min, max, step and decimals for spin boxes & initial values + initSpinBox(GroupPoints->SpinBox_DX, 0.000, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupPoints->SpinBox_DY, 0.000, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupPoints->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DX, 0.000, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DY, 0.000, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + + // init variables + GroupPoints->LineEdit1->setReadOnly(true); + GroupPoints->LineEdit2->setReadOnly(true); + + GroupPoints->LineEdit1->setText(""); + GroupPoints->LineEdit2->setText(""); + myPoint = myDir = GEOM::GEOM_Object::_nil(); + + double aRadius1(100.0), aRadius2(0.0), aHeight(300.0); + GroupPoints->SpinBox_DX->setValue(aRadius1); + GroupPoints->SpinBox_DY->setValue(aRadius2); + GroupPoints->SpinBox_DZ->setValue(aHeight); + GroupDimensions->SpinBox_DX->setValue(aRadius1); + GroupDimensions->SpinBox_DY->setValue(aRadius2); + GroupDimensions->SpinBox_DZ->setValue(aHeight); + + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); + + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + + connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double))); + + initName(tr("GEOM_CONE")); + + setConstructorId(1); // simplest constructor + ConstructorsClicked(1); +} //================================================================================= // function : SetDoubleSpinBoxStep() // purpose : Double spin box management //================================================================================= -void PrimitiveGUI_ConeDlg::SetDoubleSpinBoxStep( double step ) +void PrimitiveGUI_ConeDlg::SetDoubleSpinBoxStep (double step) { GroupPoints->SpinBox_DX->setSingleStep(step); GroupPoints->SpinBox_DY->setSingleStep(step); @@ -187,145 +184,157 @@ void PrimitiveGUI_ConeDlg::SetDoubleSpinBoxStep( double step ) // function : ConstructorsClicked() // purpose : Radio button management //================================================================================= -void PrimitiveGUI_ConeDlg::ConstructorsClicked( int constructorId ) +void PrimitiveGUI_ConeDlg::ConstructorsClicked (int constructorId) { - disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 ); - - switch( constructorId ) { - case 0 : + switch (constructorId) { + case 0: { - //globalSelection( GEOM_POINT ); - globalSelection(); // to break prvious local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - GroupDimensions->hide(); GroupPoints->show(); - - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setText( "" ); - GroupPoints->LineEdit2->setText( "" ); - myPoint = myDir = GEOM::GEOM_Object::_nil(); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + GroupPoints->PushButton1->click(); break; } - case 1 : - { - globalSelection(); // close local contexts, if any - + case 1: + { GroupPoints->hide(); GroupDimensions->show(); - + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(); // close local contexts, if any + + displayPreview(); break; } } qApp->processEvents(); updateGeometry(); - resize( minimumSize() ); + resize(minimumSize()); - displayPreview(); + if (myInitial) { + // on dialog initialization we init the first field with a selected object (if any) + SelectionIntoArgument(); + myInitial = false; + } + else { + displayPreview(); + } } - //================================================================================= // function : ClickOnOk() // purpose : //================================================================================= void PrimitiveGUI_ConeDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } - //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= bool PrimitiveGUI_ConeDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; initName(); - ConstructorsClicked( getConstructorId() ); + // activate selection and connect selection manager + ConstructorsClicked(getConstructorId()); return true; } //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void PrimitiveGUI_ConeDlg::SelectionIntoArgument() { if (getConstructorId() != 0) return; + erasePreview(); + myEditCurrentArgument->setText(""); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); SALOME_ListIO aSelList; aSelMgr->selectedObjects(aSelList); if (aSelList.Extent() != 1) { - if (myEditCurrentArgument == GroupPoints->LineEdit1) - myPoint = GEOM::GEOM_Object::_nil(); - else if (myEditCurrentArgument == GroupPoints->LineEdit2) - myDir = GEOM::GEOM_Object::_nil(); + if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == GroupPoints->LineEdit2) myDir = GEOM::GEOM_Object::_nil(); return; } - /* nbSel == 1 */ + // nbSel == 1 Standard_Boolean testResult = Standard_False; GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); - - if ( !testResult || CORBA::is_nil( aSelectedObject ) ) + + if (!testResult || CORBA::is_nil(aSelectedObject)) return; - TopoDS_Shape aShape; - QString aName = GEOMBase::GetName( aSelectedObject ); + QString aName = GEOMBase::GetName(aSelectedObject); - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { + // Get Selected object if selected subshape + TopoDS_Shape aShape; + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (myEditCurrentArgument == GroupPoints->LineEdit2) aNeedType = TopAbs_EDGE; TColStd_IndexedMapOfInteger aMap; aSelMgr->GetIndexes(aSelList.First(), aMap); - if ( aMap.Extent() == 1 ) { + if (aMap.Extent() == 1) // Local Selection + { int anIndex = aMap(1); - if ( aNeedType == TopAbs_EDGE ) - aName.append( ":edge_" + QString::number( anIndex ) ); + if (aNeedType == TopAbs_EDGE) + aName.append(":edge_" + QString::number(anIndex)); else - aName.append( ":vertex_" + QString::number( anIndex ) ); + aName.append(":vertex_" + QString::number(anIndex)); //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName ); + GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = - getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); + if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = + getGeomEngine()->GetIShapesOperations(getStudyId()); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); } else { - aSelectedObject = aFindedObject; // get Object from study + aSelectedObject = aFindedObject; // get Object from study } } - else { - if ( aShape.ShapeType() != aNeedType ) { + else // Global Selection + { + if (aShape.ShapeType() != aNeedType) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; } } } - myEditCurrentArgument->setText( aName ); + myEditCurrentArgument->setText(aName); + + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) + if (myEditCurrentArgument == GroupPoints->LineEdit1) { myPoint = aSelectedObject; - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (!myPoint->_is_nil() && myDir->_is_nil()) + GroupPoints->PushButton2->click(); + } + else if (myEditCurrentArgument == GroupPoints->LineEdit2) { myDir = aSelectedObject; - + if (!myDir->_is_nil() && myPoint->_is_nil()) + GroupPoints->PushButton1->click(); + } + displayPreview(); } @@ -336,23 +345,36 @@ void PrimitiveGUI_ConeDlg::SelectionIntoArgument() void PrimitiveGUI_ConeDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - - if ( send == GroupPoints->PushButton1 ) { + + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + if (send == GroupPoints->PushButton1) { myEditCurrentArgument = GroupPoints->LineEdit1; - globalSelection( GEOM_POINT ); // to break prvious local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + + GroupPoints->PushButton2->setDown(false); + GroupPoints->LineEdit2->setEnabled(false); + + globalSelection(GEOM_POINT); // to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } - else if ( send == GroupPoints->PushButton2 ) { + else if (send == GroupPoints->PushButton2) { myEditCurrentArgument = GroupPoints->LineEdit2; - globalSelection( GEOM_LINE );// to break prvious local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE ); + + GroupPoints->PushButton1->setDown(false); + GroupPoints->LineEdit1->setEnabled(false); + + globalSelection(GEOM_LINE);// to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); } - + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); - SelectionIntoArgument(); + // after setFocus(), because it will be setDown(false) then loses focus + send->setDown(true); } - //================================================================================= // function : LineEditReturnPressed() // purpose : @@ -360,14 +382,13 @@ void PrimitiveGUI_ConeDlg::SetEditCurrentArgument() void PrimitiveGUI_ConeDlg::LineEditReturnPressed() { QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupPoints->LineEdit1 || - send == GroupPoints->LineEdit2 ) { + if (send == GroupPoints->LineEdit1 || + send == GroupPoints->LineEdit2) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -375,34 +396,21 @@ void PrimitiveGUI_ConeDlg::LineEditReturnPressed() void PrimitiveGUI_ConeDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - - ConstructorsClicked( getConstructorId() ); -} - -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : public slot to deactivate if active -//================================================================================= -void PrimitiveGUI_ConeDlg::DeactivateActiveDialog() -{ - GEOMBase_Skeleton::DeactivateActiveDialog(); + // reinit, because some selected objects could be removed + Init(); } - //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void PrimitiveGUI_ConeDlg::enterEvent( QEvent* ) +void PrimitiveGUI_ConeDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } - //================================================================================= // function : ValueChangedInSpinBox() // purpose : @@ -412,21 +420,20 @@ void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox() displayPreview(); } - //================================================================================= // function : createOperation // purpose : //================================================================================= GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation() { - return getGeomEngine()->GetI3DPrimOperations( getStudyId() ); + return getGeomEngine()->GetI3DPrimOperations(getStudyId()); } //================================================================================= // function : isValid // purpose : //================================================================================= -bool PrimitiveGUI_ConeDlg::isValid( QString& msg ) +bool PrimitiveGUI_ConeDlg::isValid (QString&) { return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true; } @@ -435,38 +442,33 @@ bool PrimitiveGUI_ConeDlg::isValid( QString& msg ) // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_ConeDlg::execute (ObjectList& objects) { bool res = false; - + GEOM::GEOM_Object_var anObj; - switch ( getConstructorId() ) { - case 0 : - if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) { - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint, - myDir, - getRadius1(), - getRadius2(), - getHeight() ); + switch (getConstructorId()) { + case 0: + if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) { + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeConePntVecR1R2H(myPoint, myDir, getRadius1(), getRadius2(), getHeight()); res = true; } break; - case 1 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(), - getRadius2(), - getHeight() ); + case 1: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeConeR1R2H(getRadius1(), getRadius2(), getHeight()); res = true; break; } - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); return res; } - //================================================================================= // function : getRadius1() // purpose : @@ -474,14 +476,13 @@ bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects ) double PrimitiveGUI_ConeDlg::getRadius1() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DX->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DX->value(); return 0; } - //================================================================================= // function : getRadius2() // purpose : @@ -489,24 +490,23 @@ double PrimitiveGUI_ConeDlg::getRadius1() const double PrimitiveGUI_ConeDlg::getRadius2() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DY->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DY->value(); return 0; } - //================================================================================= -// function : getRadius2() +// function : getHeight() // purpose : //================================================================================= double PrimitiveGUI_ConeDlg::getHeight() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DZ->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DZ->value(); return 0; } @@ -518,8 +518,8 @@ double PrimitiveGUI_ConeDlg::getHeight() const void PrimitiveGUI_ConeDlg::addSubshapesToStudy() { QMap objMap; - - switch ( getConstructorId() ) { + + switch (getConstructorId()) { case 0: objMap[GroupPoints->LineEdit1->text()] = myPoint; objMap[GroupPoints->LineEdit2->text()] = myDir; @@ -527,5 +527,5 @@ void PrimitiveGUI_ConeDlg::addSubshapesToStudy() case 1: return; } - addSubshapesToFather( objMap ); + addSubshapesToFather(objMap); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.h b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.h index 0cf79ec17..196ec5ee4 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_ConeDlg.h @@ -59,6 +59,9 @@ private: private: GEOM::GEOM_Object_var myPoint, myDir; + + // to initialize the first selection field with a selected object on the dialog creation + bool myInitial; DlgRef_2Sel3Spin* GroupPoints; DlgRef_3Spin* GroupDimensions; @@ -67,7 +70,6 @@ private slots: void ClickOnOk(); bool ClickOnApply(); void ActivateThisDialog(); - void DeactivateActiveDialog(); void LineEditReturnPressed(); void SelectionIntoArgument(); void SetEditCurrentArgument(); diff --git a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx index aa01161fc..67b6842e2 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.cxx @@ -1,22 +1,22 @@ // GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : PrimitiveGUI_CylinderDlg.cxx @@ -26,15 +26,15 @@ #include "PrimitiveGUI_CylinderDlg.h" #include - #include #include -#include #include +#include #include #include +// OCCT Includes #include #include #include @@ -46,54 +46,54 @@ //================================================================================= // class : PrimitiveGUI_CylinderDlg() -// purpose : Constructs a PrimitiveGUI_CylinderDlg which is a child of 'parent', with the +// purpose : Constructs a PrimitiveGUI_CylinderDlg 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. //================================================================================= -PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg( GeometryGUI* theGeometryGUI, QWidget* parent, - bool modal, Qt::WindowFlags fl ) - : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +PrimitiveGUI_CylinderDlg::PrimitiveGUI_CylinderDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myInitial(true) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_PV" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CYLINDER_DXYZ" ) ) ); - QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CYLINDER_PV"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CYLINDER_DXYZ"))); + QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_CYLINDER_TITLE" ) ); + setWindowTitle(tr("GEOM_CYLINDER_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CYLINDER" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - mainFrame()->RadioButton2->setIcon( image1 ); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_CYLINDER")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setIcon(image1); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->close(); - GroupPoints = new DlgRef_2Sel2Spin( centralWidget() ); - GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) ); - GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) ); - GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS" ) ); - GroupPoints->TextLabel4->setText( tr( "GEOM_HEIGHT" ) ); - GroupPoints->PushButton1->setIcon( image2 ); - GroupPoints->PushButton2->setIcon( image2 ); - - GroupDimensions = new DlgRef_2Spin( centralWidget() ); - GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) ); - GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) ); - GroupDimensions->TextLabel2->setText( tr( "GEOM_HEIGHT" ) ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupPoints ); - layout->addWidget( GroupDimensions ); + GroupPoints = new DlgRef_2Sel2Spin(centralWidget()); + GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT")); + GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR")); + GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS")); + GroupPoints->TextLabel4->setText(tr("GEOM_HEIGHT")); + GroupPoints->PushButton1->setIcon(image2); + GroupPoints->PushButton2->setIcon(image2); + + GroupDimensions = new DlgRef_2Spin(centralWidget()); + GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ")); + GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS")); + GroupDimensions->TextLabel2->setText(tr("GEOM_HEIGHT")); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPoints); + layout->addWidget(GroupDimensions); /***************************************************************/ - setHelpFileName( "create_cylinder_page.html" ); + setHelpFileName("create_cylinder_page.html"); Init(); } - //================================================================================= // function : ~PrimitiveGUI_CylinderDlg() // purpose : Destroys the object and frees any allocated resources @@ -103,73 +103,67 @@ PrimitiveGUI_CylinderDlg::~PrimitiveGUI_CylinderDlg() // no need to delete child widgets, Qt does it all for us } - //================================================================================= // function : Init() // purpose : //================================================================================= void PrimitiveGUI_CylinderDlg::Init() { - /* init variables */ + // 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 & initial values + initSpinBox(GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupPoints->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + + // init variables myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setReadOnly( true ); - GroupPoints->LineEdit2->setReadOnly( true ); + GroupPoints->LineEdit1->setReadOnly(true); + GroupPoints->LineEdit2->setReadOnly(true); + GroupPoints->LineEdit1->setText(""); + GroupPoints->LineEdit2->setText(""); myPoint = myDir = GEOM::GEOM_Object::_nil(); - - /* 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 & initial values */ - /* First constructor : radius */ - initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - /* First constructor : algebric height */ - initSpinBox( GroupPoints->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - /* Second constructor : radius */ - initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - /* Second constructor : algebric height */ - initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - - GroupPoints->SpinBox_DX->setValue( 100.0 ); - GroupPoints->SpinBox_DY->setValue( 300.0 ); - GroupDimensions->SpinBox_DX->setValue( 100.0 ); - GroupDimensions->SpinBox_DY->setValue( 300.0 ); - - /* signals and slots connections */ - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); - - connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); - - connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - - connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - - connect( GroupPoints->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupPoints->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DX, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DY, SIGNAL(valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - - connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) ); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - - initName( tr( "GEOM_CYLINDER" ) ); - - setConstructorId( 1 ); // simplest constructor - ConstructorsClicked( 1 ); -} + double aRadius(100.0), aHeight(300.0); + GroupPoints->SpinBox_DX->setValue(aRadius); + GroupPoints->SpinBox_DY->setValue(aHeight); + GroupDimensions->SpinBox_DX->setValue(aRadius); + GroupDimensions->SpinBox_DY->setValue(aHeight); + + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); + + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + + connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double))); + + initName(tr("GEOM_CYLINDER")); + + setConstructorId(1); // simplest constructor + ConstructorsClicked(1); +} //================================================================================= // function : SetDoubleSpinBoxStep() // purpose : Double spin box management //================================================================================= -void PrimitiveGUI_CylinderDlg::SetDoubleSpinBoxStep( double step ) +void PrimitiveGUI_CylinderDlg::SetDoubleSpinBoxStep (double step) { GroupPoints->SpinBox_DX->setSingleStep(step); GroupPoints->SpinBox_DY->setSingleStep(step); @@ -177,88 +171,89 @@ void PrimitiveGUI_CylinderDlg::SetDoubleSpinBoxStep( double step ) GroupDimensions->SpinBox_DY->setSingleStep(step); } - //================================================================================= // function : ConstructorsClicked() // purpose : Radio button management //================================================================================= -void PrimitiveGUI_CylinderDlg::ConstructorsClicked( int constructorId ) +void PrimitiveGUI_CylinderDlg::ConstructorsClicked (int constructorId) { - disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 ); - - switch( constructorId ) { - case 0 : + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + + switch (constructorId) { + case 0: { - globalSelection( GEOM_POINT ); // to break previous local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - GroupDimensions->hide(); GroupPoints->show(); - - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setText( "" ); - GroupPoints->LineEdit2->setText( "" ); - myPoint = myDir = GEOM::GEOM_Object::_nil(); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + GroupPoints->PushButton1->click(); break; } - case 1 : - { - globalSelection(); // close local contexts, if any - + case 1: + { GroupPoints->hide(); GroupDimensions->show(); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(); // close local contexts, if any break; } } qApp->processEvents(); updateGeometry(); - resize( minimumSize() ); + resize(minimumSize()); - displayPreview(); + if (myInitial) { + myInitial = false; + if (constructorId == 0) { + // on dialog initialization we init the first field with a selected object (if any) + SelectionIntoArgument(); + } + else { + displayPreview(); + } + } + else { + displayPreview(); + } } - //================================================================================= // function : ClickOnOk() // purpose : //================================================================================= void PrimitiveGUI_CylinderDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } - //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= bool PrimitiveGUI_CylinderDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; initName(); - ConstructorsClicked( getConstructorId() ); + // activate selection and connect selection manager + ConstructorsClicked(getConstructorId()); return true; } - //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void PrimitiveGUI_CylinderDlg::SelectionIntoArgument() { - if ( getConstructorId() != 0 ) + if (getConstructorId() != 0) return; - myEditCurrentArgument->setText( "" ); - + erasePreview(); + myEditCurrentArgument->setText(""); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); SALOME_ListIO aSelList; aSelMgr->selectedObjects(aSelList); @@ -270,44 +265,47 @@ void PrimitiveGUI_CylinderDlg::SelectionIntoArgument() myDir = GEOM::GEOM_Object::_nil(); return; } - - /* nbSel == 1 */ + + // nbSel == 1 Standard_Boolean testResult = Standard_False; GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); - + if (!testResult || CORBA::is_nil(aSelectedObject)) return; QString aName = GEOMBase::GetName(aSelectedObject); + + // Get Selected object if selected subshape TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (myEditCurrentArgument == GroupPoints->LineEdit2) aNeedType = TopAbs_EDGE; TColStd_IndexedMapOfInteger aMap; aSelMgr->GetIndexes(aSelList.First(), aMap); - if ( aMap.Extent() == 1 ) { // Local Selection - int anIndex = aMap( 1 ); - if ( aNeedType == TopAbs_EDGE ) - aName.append( ":edge_" + QString::number( anIndex ) ); + if (aMap.Extent() == 1) { // Local Selection + int anIndex = aMap(1); + if (aNeedType == TopAbs_EDGE) + aName.append(":edge_" + QString::number(anIndex)); else - aName.append( ":vertex_" + QString::number( anIndex ) ); + aName.append(":vertex_" + QString::number(anIndex)); //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName ); + GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = - getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); + if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = + getGeomEngine()->GetIShapesOperations(getStudyId()); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); } else { - aSelectedObject = aFindedObject; // get Object from study + aSelectedObject = aFindedObject; // get Object from study } } else { // Global Selection - if ( aShape.ShapeType() != aNeedType ) { + if (aShape.ShapeType() != aNeedType) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; } @@ -316,15 +314,26 @@ void PrimitiveGUI_CylinderDlg::SelectionIntoArgument() myEditCurrentArgument->setText(aName); - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == GroupPoints->LineEdit1) { myPoint = aSelectedObject; - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (!myPoint->_is_nil() && myDir->_is_nil()) + GroupPoints->PushButton2->click(); + } + else if (myEditCurrentArgument == GroupPoints->LineEdit2) { myDir = aSelectedObject; - + if (!myDir->_is_nil() && myPoint->_is_nil()) + GroupPoints->PushButton1->click(); + } + displayPreview(); } - //================================================================================= // function : SetEditCurrentArgument() // purpose : @@ -332,38 +341,50 @@ void PrimitiveGUI_CylinderDlg::SelectionIntoArgument() void PrimitiveGUI_CylinderDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - - if ( send == GroupPoints->PushButton1 ) { + + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + if (send == GroupPoints->PushButton1) { myEditCurrentArgument = GroupPoints->LineEdit1; - globalSelection( GEOM_POINT ); // to break previous local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + + GroupPoints->PushButton2->setDown(false); + GroupPoints->LineEdit2->setEnabled(false); + + globalSelection(GEOM_POINT); // to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } - else if ( send == GroupPoints->PushButton2 ) { + else if (send == GroupPoints->PushButton2) { myEditCurrentArgument = GroupPoints->LineEdit2; - globalSelection( GEOM_LINE ); // to break previous local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE ); + + GroupPoints->PushButton1->setDown(false); + GroupPoints->LineEdit1->setEnabled(false); + + globalSelection(GEOM_LINE); // to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); } - + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); - SelectionIntoArgument(); + // after setFocus(), because it will be setDown(false) then loses focus + send->setDown(true); } - //================================================================================= // function : LineEditReturnPressed() // purpose : //================================================================================= void PrimitiveGUI_CylinderDlg::LineEditReturnPressed() -{ +{ QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupPoints->LineEdit1 || - send == GroupPoints->LineEdit2 ) { + if (send == GroupPoints->LineEdit1 || + send == GroupPoints->LineEdit2) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -371,94 +392,79 @@ void PrimitiveGUI_CylinderDlg::LineEditReturnPressed() void PrimitiveGUI_CylinderDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - - ConstructorsClicked( getConstructorId() ); -} + // reinit, because some selected objects could be removed + Init(); +} //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void PrimitiveGUI_CylinderDlg::enterEvent( QEvent* ) +void PrimitiveGUI_CylinderDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } - -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : public slot to deactivate if active -//================================================================================= -void PrimitiveGUI_CylinderDlg::DeactivateActiveDialog() -{ - GEOMBase_Skeleton::DeactivateActiveDialog(); -} - - //================================================================================= -// function : ValueChangedInSpinBox +// function : ValueChangedInSpinBox() // purpose : //================================================================================= -void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox( ) -{ +void PrimitiveGUI_CylinderDlg::ValueChangedInSpinBox() +{ displayPreview(); } - //================================================================================= // function : createOperation // purpose : //================================================================================= GEOM::GEOM_IOperations_ptr PrimitiveGUI_CylinderDlg::createOperation() { - return getGeomEngine()->GetI3DPrimOperations( getStudyId() ); + return getGeomEngine()->GetI3DPrimOperations(getStudyId()); } - //================================================================================= // function : isValid // purpose : //================================================================================= -bool PrimitiveGUI_CylinderDlg::isValid( QString& msg ) +bool PrimitiveGUI_CylinderDlg::isValid (QString&) { - return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil() ) : true; + return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true; } //================================================================================= // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_CylinderDlg::execute (ObjectList& objects) { bool res = false; - + GEOM::GEOM_Object_var anObj; - - switch ( getConstructorId() ) { - case 0 : - if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ) { - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderPntVecRH( myPoint, myDir, getRadius(), getHeight() ); + + switch (getConstructorId()) { + case 0: + if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) { + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeCylinderPntVecRH(myPoint, myDir, getRadius(), getHeight()); res = true; } break; - case 1 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeCylinderRH( getRadius(), getHeight() ); + case 1: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeCylinderRH(getRadius(), getHeight()); res = true; - break; } - - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); - + + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + return res; } - //================================================================================= // function : getRadius() // purpose : @@ -466,14 +472,13 @@ bool PrimitiveGUI_CylinderDlg::execute( ObjectList& objects ) double PrimitiveGUI_CylinderDlg::getRadius() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DX->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DX->value(); return 0; } - //================================================================================= // function : getHeight() // purpose : @@ -481,9 +486,9 @@ double PrimitiveGUI_CylinderDlg::getRadius() const double PrimitiveGUI_CylinderDlg::getHeight() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DY->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DY->value(); return 0; } @@ -496,7 +501,7 @@ void PrimitiveGUI_CylinderDlg::addSubshapesToStudy() { QMap objMap; - switch ( getConstructorId() ) { + switch (getConstructorId()) { case 0: objMap[GroupPoints->LineEdit1->text()] = myPoint; objMap[GroupPoints->LineEdit2->text()] = myDir; @@ -504,5 +509,5 @@ void PrimitiveGUI_CylinderDlg::addSubshapesToStudy() case 1: return; } - addSubshapesToFather( objMap ); + addSubshapesToFather(objMap); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.h b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.h index 8a64be473..a10ece58f 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_CylinderDlg.h @@ -58,6 +58,9 @@ private: private: GEOM::GEOM_Object_var myPoint, myDir; + + // to initialize the first selection field with a selected object on the dialog creation + bool myInitial; DlgRef_2Sel2Spin* GroupPoints; DlgRef_2Spin* GroupDimensions; @@ -66,7 +69,6 @@ private slots: void ClickOnOk(); bool ClickOnApply(); void ActivateThisDialog(); - void DeactivateActiveDialog(); void LineEditReturnPressed(); void SelectionIntoArgument(); void SetEditCurrentArgument(); diff --git a/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.cxx index 20f9ef21a..c562f5960 100755 --- a/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.cxx @@ -1,22 +1,22 @@ // GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : PrimitiveGUI_DiskDlg.cxx @@ -26,92 +26,93 @@ #include "PrimitiveGUI_DiskDlg.h" #include - #include #include -#include #include +#include #include #include -#include -#include +// OCCT Includes #include #include #include #include +#include +#include //================================================================================= // class : PrimitiveGUI_DiskDlg() -// purpose : Constructs a PrimitiveGUI_DiskDlg which is a child of 'parent', with the +// purpose : Constructs a PrimitiveGUI_DiskDlg 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. //================================================================================= -PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg( GeometryGUI* theGeometryGUI, QWidget* parent, - bool modal, Qt::WindowFlags fl ) - : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myInitial(true) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_PNT_VEC_R" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_THREE_POINTS" ) ) ); - QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_R" ) ) ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_THREE_POINTS"))); + QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_R"))); - setWindowTitle( tr( "GEOM_DISK_TITLE" ) ); + setWindowTitle(tr("GEOM_DISK_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_DISK" ) ); - mainFrame()->RadioButton1->setIcon( image3 ); - mainFrame()->RadioButton2->setIcon( image0 ); - mainFrame()->RadioButton3->setIcon( image2 ); - - 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->TextLabel3->setText( tr( "GEOM_RADIUS" ) ); - GroupPntVecR->PushButton1->setIcon( image1 ); - GroupPntVecR->PushButton2->setIcon( image1 ); - GroupPntVecR->LineEdit1->setReadOnly( true ); - GroupPntVecR->LineEdit2->setReadOnly( true ); - - Group3Pnts = new DlgRef_3Sel( centralWidget() ); - Group3Pnts->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) ); - Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) ); - Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) ); - Group3Pnts->PushButton1->setIcon( image1 ); - Group3Pnts->PushButton2->setIcon( image1 ); - Group3Pnts->PushButton3->setIcon( image1 ); - Group3Pnts->LineEdit1->setReadOnly( true ); - Group3Pnts->LineEdit2->setReadOnly( true ); - Group3Pnts->LineEdit3->setReadOnly( true ); - - GroupDimensions = new DlgRef_1Spin( centralWidget() ); - GroupDimensions->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS" ) ); - - GroupOrientation = new DlgRef_3Radio( centralWidget() ); - GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) ); - GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) ); - GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) ); - GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupPntVecR ); - layout->addWidget( Group3Pnts ); - layout->addWidget( GroupDimensions ); - layout->addWidget( GroupOrientation ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISK")); + mainFrame()->RadioButton1->setIcon(image3); + mainFrame()->RadioButton2->setIcon(image0); + mainFrame()->RadioButton3->setIcon(image2); + + 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->TextLabel3->setText(tr("GEOM_RADIUS")); + GroupPntVecR->PushButton1->setIcon(image1); + GroupPntVecR->PushButton2->setIcon(image1); + GroupPntVecR->LineEdit1->setReadOnly(true); + GroupPntVecR->LineEdit2->setReadOnly(true); + + Group3Pnts = new DlgRef_3Sel(centralWidget()); + Group3Pnts->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1")); + Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2")); + Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3")); + Group3Pnts->PushButton1->setIcon(image1); + Group3Pnts->PushButton2->setIcon(image1); + Group3Pnts->PushButton3->setIcon(image1); + Group3Pnts->LineEdit1->setReadOnly(true); + Group3Pnts->LineEdit2->setReadOnly(true); + Group3Pnts->LineEdit3->setReadOnly(true); + + GroupDimensions = new DlgRef_1Spin(centralWidget()); + GroupDimensions->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS")); + + GroupOrientation = new DlgRef_3Radio(centralWidget()); + GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION")); + GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY")); + GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ")); + GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX")); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPntVecR); + layout->addWidget(Group3Pnts); + layout->addWidget(GroupDimensions); + layout->addWidget(GroupOrientation); /***************************************************************/ - setHelpFileName( "create_disk_page.html" ); + setHelpFileName("create_disk_page.html"); Init(); } - //================================================================================= // function : ~PrimitiveGUI_DiskDlg() // purpose : Destroys the object and frees any allocated resources @@ -120,72 +121,77 @@ PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg() { } - //================================================================================= // function : Init() // purpose : //================================================================================= void PrimitiveGUI_DiskDlg::Init() { - /* init variables */ + // Get setting of step value from file configuration + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100); + + // min, max, step and decimals for spin boxes & initial values + initSpinBox(GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3); // VSR:TODO : DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3); // VSR:TODO : DBL_DIGITS_DISPLAY + + // init variables myEditCurrentArgument = GroupPntVecR->LineEdit1; myOrientationType = 1; + GroupOrientation->RadioButton1->setChecked(true); + GroupPntVecR->LineEdit1->setText(""); + GroupPntVecR->LineEdit2->setText(""); + Group3Pnts->LineEdit1->setText(""); + Group3Pnts->LineEdit2->setText(""); + Group3Pnts->LineEdit3->setText(""); myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil(); - /* Get setting of step value from file configuration */ - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 ); + GroupPntVecR->SpinBox_DX->setValue(100); + GroupDimensions->SpinBox_DX->setValue(100); - /* min, max, step and decimals for spin boxes & initial values */ - initSpinBox( GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY - GroupPntVecR->SpinBox_DX->setValue( 100 ); - initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY - GroupDimensions->SpinBox_DX->setValue( 100 ); + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - /* 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() ) ); + connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); - connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); + connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); + connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); + connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) ); - connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) ); + connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) ); - connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) ); - connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) ); + connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); + connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked())); + connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked())); + connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked())); - initName( tr( "GEOM_DISK" ) ); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double))); + connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); - ConstructorsClicked( 0 ); + initName(tr("GEOM_DISK")); + + ConstructorsClicked(0); } //================================================================================= // function : SetDoubleSpinBoxStep() // purpose : Double spin box management //================================================================================= -void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep( double step ) +void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep (double step) { + GroupDimensions->SpinBox_DX->setSingleStep(step); GroupPntVecR->SpinBox_DX->setSingleStep(step); } @@ -195,11 +201,11 @@ void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep( double step ) //================================================================================= void PrimitiveGUI_DiskDlg::RadioButtonClicked() { - if ( GroupOrientation->RadioButton1->isChecked() ) + if (GroupOrientation->RadioButton1->isChecked()) myOrientationType = 1; - else if ( GroupOrientation->RadioButton2->isChecked() ) + else if (GroupOrientation->RadioButton2->isChecked()) myOrientationType = 2; - else if ( GroupOrientation->RadioButton3->isChecked() ) + else if (GroupOrientation->RadioButton3->isChecked()) myOrientationType = 3; displayPreview(); } @@ -208,59 +214,61 @@ void PrimitiveGUI_DiskDlg::RadioButtonClicked() // function : ConstructorsClicked() // purpose : Radio button management //================================================================================= -void PrimitiveGUI_DiskDlg::ConstructorsClicked( int constructorId ) +void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId) { - disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0); - - myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil(); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); - switch ( constructorId ) { + switch (constructorId) { case 0: { GroupPntVecR->hide(); Group3Pnts->hide(); GroupDimensions->show(); GroupOrientation->show(); - GroupOrientation->RadioButton1->setChecked( true ); - myOrientationType = 1; + + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(); // close local contexts, if any break; } case 1: { - Group3Pnts->hide(); - GroupPntVecR->show(); GroupDimensions->hide(); GroupOrientation->hide(); - myEditCurrentArgument = GroupPntVecR->LineEdit1; - GroupPntVecR->LineEdit1->setText( "" ); - GroupPntVecR->LineEdit2->setText( "" ); + GroupPntVecR->show(); + Group3Pnts->hide(); + + GroupPntVecR->PushButton1->click(); break; } case 2: { - GroupPntVecR->hide(); - Group3Pnts->show(); GroupDimensions->hide(); GroupOrientation->hide(); - myEditCurrentArgument = Group3Pnts->LineEdit1; - Group3Pnts->LineEdit1->setText( "" ); - Group3Pnts->LineEdit2->setText( "" ); - Group3Pnts->LineEdit3->setText( "" ); + GroupPntVecR->hide(); + Group3Pnts->show(); + + Group3Pnts->PushButton1->click(); break; } } - + qApp->processEvents(); updateGeometry(); - resize( minimumSize() ); - - myEditCurrentArgument->setFocus(); - globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + resize(minimumSize()); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - displayPreview(); + if (myInitial) { + myInitial = false; + if (constructorId == 1 || constructorId == 2) { + // on dialog initialization we init the first field with a selected object (if any) + SelectionIntoArgument(); + } + else { + displayPreview(); + } + } + else { + displayPreview(); + } } //================================================================================= @@ -269,7 +277,7 @@ void PrimitiveGUI_DiskDlg::ConstructorsClicked( int constructorId ) //================================================================================= void PrimitiveGUI_DiskDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } @@ -279,96 +287,123 @@ void PrimitiveGUI_DiskDlg::ClickOnOk() //================================================================================= bool PrimitiveGUI_DiskDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; initName(); - ConstructorsClicked( getConstructorId() ); + // activate selection and connect selection manager + ConstructorsClicked(getConstructorId()); return true; } //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void PrimitiveGUI_DiskDlg::SelectionIntoArgument() { - if (getConstructorId() == 0) { - displayPreview(); + if (getConstructorId() == 0) return; - } - myEditCurrentArgument->setText( "" ); - + erasePreview(); + myEditCurrentArgument->setText(""); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); - SALOME_ListIO aList; - aSelMgr->selectedObjects( aList ); - - if ( aList.Extent() != 1 ) { - if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() != 1) { + if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == Group3Pnts->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == Group3Pnts->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil(); + else if (myEditCurrentArgument == Group3Pnts->LineEdit3) myPoint3 = GEOM::GEOM_Object::_nil(); return; } // nbSel == 1 - Handle(SALOME_InteractiveObject) anIO = aList.First(); - - Standard_Boolean aRes = Standard_False; - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes); - if ( !CORBA::is_nil( aSelectedObject ) && aRes ) { - QString aName = GEOMBase::GetName( aSelectedObject ); - - // If selected Vertex or Edge on the some Shape Get selection Subshape - TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { - TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) - aNeedType = TopAbs_EDGE; - - TColStd_IndexedMapOfInteger aMap; - aSelMgr->GetIndexes(anIO, aMap); - if ( aMap.Extent() == 1 ) { // Local Selection - int anIndex = aMap(1); - if ( aNeedType == TopAbs_EDGE ) - aName += QString( ":edge_%1" ).arg( anIndex ); - else - aName += QString( ":vertex_%1" ).arg( anIndex ); - - //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName ); - - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); - } - else { - aSelectedObject = aFindedObject; // get Object from study - } + Handle(SALOME_InteractiveObject) anIO = aSelList.First(); + Standard_Boolean testResult = Standard_False; + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult); + + if (!testResult || CORBA::is_nil(aSelectedObject)) + return; + + QString aName = GEOMBase::GetName(aSelectedObject); + + // If selected Vertex or Edge on the some Shape Get selection Subshape + TopoDS_Shape aShape; + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { + TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; + if (myEditCurrentArgument == GroupPntVecR->LineEdit2) + aNeedType = TopAbs_EDGE; + + TColStd_IndexedMapOfInteger aMap; + aSelMgr->GetIndexes(anIO, aMap); + if (aMap.Extent() == 1) { // Local Selection + int anIndex = aMap(1); + if (aNeedType == TopAbs_EDGE) + aName += QString(":edge_%1").arg(anIndex); + else + aName += QString(":vertex_%1").arg(anIndex); + + //Find SubShape Object in Father + GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); + + if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); } - else { // Global Selection - if ( aShape.ShapeType() != aNeedType ) { - aSelectedObject = GEOM::GEOM_Object::_nil(); - aName = ""; - } + else { + aSelectedObject = aFindedObject; // get Object from study + } + } + else { // Global Selection + if (aShape.ShapeType() != aNeedType) { + aSelectedObject = GEOM::GEOM_Object::_nil(); + aName = ""; } } - - myEditCurrentArgument->setText( aName ); - - if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject; - else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject; - else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject; - else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject; - else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject; + } + + myEditCurrentArgument->setText(aName); + + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == GroupPntVecR->LineEdit1) { + myPoint = aSelectedObject; + if (!myPoint->_is_nil() && myDir->_is_nil()) + GroupPntVecR->PushButton2->click(); + } + else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) { + myDir = aSelectedObject; + if (!myDir->_is_nil() && myPoint->_is_nil()) + GroupPntVecR->PushButton1->click(); + } + else if (myEditCurrentArgument == Group3Pnts->LineEdit1) { + myPoint1 = aSelectedObject; + if (!myPoint1->_is_nil() && myPoint2->_is_nil()) + Group3Pnts->PushButton2->click(); + } + else if (myEditCurrentArgument == Group3Pnts->LineEdit2) { + myPoint2 = aSelectedObject; + if (!myPoint2->_is_nil() && myPoint3->_is_nil()) + Group3Pnts->PushButton3->click(); + } + else if (myEditCurrentArgument == Group3Pnts->LineEdit3) { + myPoint3 = aSelectedObject; + if (!myPoint3->_is_nil() && myPoint1->_is_nil()) + Group3Pnts->PushButton1->click(); } displayPreview(); } - //================================================================================= // function : SetEditCurrentArgument() // purpose : @@ -377,24 +412,63 @@ void PrimitiveGUI_DiskDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1; - else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2; - else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1; - else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2; - else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3; - - myEditCurrentArgument->setFocus(); + if (send == GroupPntVecR->PushButton1) { + myEditCurrentArgument = GroupPntVecR->LineEdit1; + + GroupPntVecR->PushButton2->setDown(false); + GroupPntVecR->LineEdit2->setEnabled(false); + } + else if (send == GroupPntVecR->PushButton2) { + myEditCurrentArgument = GroupPntVecR->LineEdit2; + + GroupPntVecR->PushButton1->setDown(false); + GroupPntVecR->LineEdit1->setEnabled(false); + } + else if (send == Group3Pnts->PushButton1) { + myEditCurrentArgument = Group3Pnts->LineEdit1; + + Group3Pnts->PushButton2->setDown(false); + Group3Pnts->PushButton3->setDown(false); + Group3Pnts->LineEdit2->setEnabled(false); + Group3Pnts->LineEdit3->setEnabled(false); + } + else if (send == Group3Pnts->PushButton2) { + myEditCurrentArgument = Group3Pnts->LineEdit2; + + Group3Pnts->PushButton1->setDown(false); + Group3Pnts->PushButton3->setDown(false); + Group3Pnts->LineEdit1->setEnabled(false); + Group3Pnts->LineEdit3->setEnabled(false); + } + else if (send == Group3Pnts->PushButton3) { + myEditCurrentArgument = Group3Pnts->LineEdit3; - if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) { + Group3Pnts->PushButton1->setDown(false); + Group3Pnts->PushButton2->setDown(false); + Group3Pnts->LineEdit1->setEnabled(false); + Group3Pnts->LineEdit2->setEnabled(false); + } + + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + if (myEditCurrentArgument == GroupPntVecR->LineEdit2) { globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE ); + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); } else { globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) then loses focus + send->setDown(true); - SelectionIntoArgument(); + // seems we need it only to avoid preview disappearing, caused by selection mode change + displayPreview(); } //================================================================================= @@ -403,18 +477,17 @@ void PrimitiveGUI_DiskDlg::SetEditCurrentArgument() //================================================================================= void PrimitiveGUI_DiskDlg::LineEditReturnPressed() { - QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupPntVecR->LineEdit1 || - send == GroupPntVecR->LineEdit2 || - send == Group3Pnts->LineEdit1 || - send == Group3Pnts->LineEdit2 || - send == Group3Pnts->LineEdit3 ) { +QLineEdit* send = (QLineEdit*)sender(); + if (send == GroupPntVecR->LineEdit1 || + send == GroupPntVecR->LineEdit2 || + send == Group3Pnts->LineEdit1 || + send == Group3Pnts->LineEdit2 || + send == Group3Pnts->LineEdit3) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -423,33 +496,20 @@ void PrimitiveGUI_DiskDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - - ConstructorsClicked( getConstructorId() ); + // reinit, because some selected objects could be removed + Init(); } - //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void PrimitiveGUI_DiskDlg::enterEvent( QEvent* ) +void PrimitiveGUI_DiskDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : public slot to deactivate if active -//================================================================================= -void PrimitiveGUI_DiskDlg::DeactivateActiveDialog() -{ - // myGeomGUI->SetState( -1 ); - GEOMBase_Skeleton::DeactivateActiveDialog(); -} - //================================================================================= // function : ValueChangedInSpinBox() // purpose : @@ -459,54 +519,38 @@ void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox() displayPreview(); } -//================================================================================= -// function : getRadius() -// purpose : -//================================================================================= -double PrimitiveGUI_DiskDlg::getRadius() const -{ - double r = 0.; - switch ( getConstructorId() ) { - case 0: - r = GroupDimensions->SpinBox_DX->value(); break; - case 1: - r = GroupPntVecR->SpinBox_DX->value(); break; - } - return r; -} - //================================================================================= // function : createOperation // purpose : //================================================================================= GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation() { - return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() ); + return getGeomEngine()->GetI3DPrimOperations(getStudyId()); } //================================================================================= // function : isEqual // purpose : it may also be needed to check for min distance between gp_Pnt-s... //================================================================================= -static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 ) +static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2) { - return thePnt1->_is_equivalent( thePnt2 ); + return thePnt1->_is_equivalent(thePnt2); } //================================================================================= // function : isValid // purpose : //================================================================================= -bool PrimitiveGUI_DiskDlg::isValid( QString& msg ) +bool PrimitiveGUI_DiskDlg::isValid (QString&) { const int id = getConstructorId(); - if ( id == 0 ) + if (id == 0) return true; - else if ( id == 1 ) + else if (id == 1) return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0; - else if ( id == 2 ) + else if (id == 2) return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() && - !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 ); + !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3); return false; } @@ -514,36 +558,52 @@ bool PrimitiveGUI_DiskDlg::isValid( QString& msg ) // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_DiskDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects) { bool res = false; - + GEOM::GEOM_Object_var anObj; - - switch ( getConstructorId() ) { - case 0 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskR( getRadius(), myOrientationType ); + + switch (getConstructorId()) { + case 0: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeDiskR(getRadius(), myOrientationType); res = true; break; - case 1 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskPntVecR( myPoint, myDir, getRadius() ); + case 1: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeDiskPntVecR(myPoint, myDir, getRadius()); res = true; break; - case 2 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskThreePnt( myPoint1, myPoint2, myPoint3 ); + case 2: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeDiskThreePnt(myPoint1, myPoint2, myPoint3); res = true; break; } - - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); - else { - MESSAGE( "Execute Object is NULL!" ); - } - + + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + return res; } +//================================================================================= +// function : getRadius() +// purpose : +//================================================================================= +double PrimitiveGUI_DiskDlg::getRadius() const +{ + double r = 0.; + switch (getConstructorId()) { + case 0: + r = GroupDimensions->SpinBox_DX->value(); break; + case 1: + r = GroupPntVecR->SpinBox_DX->value(); break; + } + return r; +} + //================================================================================= // function : addSubshapeToStudy // purpose : virtual method to add new SubObjects if local selection @@ -552,7 +612,7 @@ void PrimitiveGUI_DiskDlg::addSubshapesToStudy() { QMap objMap; - switch ( getConstructorId() ) { + switch (getConstructorId()) { case 1: objMap[GroupPntVecR->LineEdit1->text()] = myPoint; objMap[GroupPntVecR->LineEdit2->text()] = myDir; @@ -563,5 +623,5 @@ void PrimitiveGUI_DiskDlg::addSubshapesToStudy() objMap[Group3Pnts->LineEdit3->text()] = myPoint3; break; } - addSubshapesToFather( objMap ); + addSubshapesToFather(objMap); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.h b/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.h index da2630b31..14de268ed 100755 --- a/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_DiskDlg.h @@ -62,6 +62,9 @@ private: private: GEOM::GEOM_Object_var myPoint, myDir, myPoint1, myPoint2, myPoint3; + // to initialize the first selection field with a selected object on the dialog creation + bool myInitial; + DlgRef_2Sel1Spin* GroupPntVecR; DlgRef_3Sel* Group3Pnts; DlgRef_1Spin* GroupDimensions; @@ -72,7 +75,6 @@ private slots: bool ClickOnApply(); void ActivateThisDialog(); - void DeactivateActiveDialog(); void SelectionIntoArgument(); diff --git a/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.cxx index 452b1d804..601dbb37d 100755 --- a/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.cxx @@ -53,9 +53,9 @@ PrimitiveGUI_FaceDlg::PrimitiveGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget bool modal, Qt::WindowFlags fl ) : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FACE_OBJ_HW" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FACE_HW" ) ) ); + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_OBJ_HW"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); + QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_HW"))); setWindowTitle( tr( "GEOM_FACE_TITLE" ) ); @@ -268,6 +268,7 @@ bool PrimitiveGUI_FaceDlg::ClickOnApply() //================================================================================= void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId ) { + erasePreview(); switch ( constructorId ) { case 0: { @@ -302,7 +303,7 @@ void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId ) updateGeometry(); resize( minimumSize() ); SelectionIntoArgument(); - displayPreview(); + //displayPreview(); } //================================================================================= @@ -474,26 +475,30 @@ bool PrimitiveGUI_FaceDlg::isValid( QString& msg ) // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_FaceDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects) { bool res = false; GEOM::GEOM_Object_var anObj; - switch ( getConstructorId() ) { - case 0 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceHW( GroupDimensions->SpinBox_DX->value(), GroupDimensions->SpinBox_DY->value(), myOrientationType ); + switch (getConstructorId()) { + case 0: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeFaceHW(GroupDimensions->SpinBox_DX->value(), + GroupDimensions->SpinBox_DY->value(), myOrientationType); res = true; break; - case 1 : - if ( GroupType->RadioButton1->isChecked() ) - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceObjHW( myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value() ); + case 1: + if (GroupType->RadioButton1->isChecked()) + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()); else if (GroupType->RadioButton2->isChecked()) - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeFaceObjHW( myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value() ); + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()); res = true; break; } - - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); return res; } diff --git a/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.h b/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.h index c9e59f7ae..4160281dd 100755 --- a/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_FaceDlg.h @@ -56,9 +56,6 @@ private: void enterEvent( QEvent* ); private: - GEOM::GEOM_Object_var myPoint1; - GEOM::GEOM_Object_var myPoint2; - GEOM::GEOM_Object_var myVector; GEOM::GEOM_Object_var myEdge; GEOM::GEOM_Object_var myFace; diff --git a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx index acea052ab..984294b16 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.cxx @@ -1,22 +1,22 @@ // GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : PrimitiveGUI_TorusDlg.cxx @@ -29,11 +29,12 @@ #include #include -#include #include +#include #include #include +// OCCT Includes #include #include #include @@ -45,55 +46,55 @@ //================================================================================= // class : PrimitiveGUI_TorusDlg() -// purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the +// purpose : Constructs a PrimitiveGUI_TorusDlg 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. //================================================================================= -PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg( GeometryGUI* theGeometryGUI, QWidget* parent, - bool modal, Qt::WindowFlags fl ) - : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myInitial(true) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TORUS_PV" ) ) ); - QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_TORUS_DXYZ" ) ) ); - QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ"))); + QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_TORUS_TITLE" ) ); + setWindowTitle(tr("GEOM_TORUS_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TORUS" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - mainFrame()->RadioButton2->setIcon( image1 ); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_TORUS")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setIcon(image1); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->close(); - GroupPoints = new DlgRef_2Sel2Spin( centralWidget() ); - GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_POINT" ) ); - GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) ); - GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) ); - GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) ); - GroupPoints->PushButton1->setIcon( image2 ); - GroupPoints->PushButton2->setIcon( image2 ); - - GroupDimensions = new DlgRef_2Spin( centralWidget() ); - GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) ); - GroupDimensions->TextLabel1->setText( tr( "GEOM_RADIUS_I" ).arg( 1 ) ); - GroupDimensions->TextLabel2->setText( tr( "GEOM_RADIUS_I" ).arg( 2 ) ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupPoints ); - layout->addWidget( GroupDimensions ); + GroupPoints = new DlgRef_2Sel2Spin(centralWidget()); + GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT")); + GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR")); + GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg(1)); + GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg(2)); + GroupPoints->PushButton1->setIcon(image2); + GroupPoints->PushButton2->setIcon(image2); + + GroupDimensions = new DlgRef_2Spin(centralWidget()); + GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ")); + GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg(1)); + GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg(2)); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPoints); + layout->addWidget(GroupDimensions); /***************************************************************/ - setHelpFileName( "create_torus_page.html" ); - + setHelpFileName("create_torus_page.html"); + Init(); } - //================================================================================= // function : ~PrimitiveGUI_TorusDlg() // purpose : Destroys the object and frees any allocated resources @@ -103,68 +104,66 @@ PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg() // no need to delete child widgets, Qt does it all for us } - //================================================================================= // function : Init() // purpose : //================================================================================= void PrimitiveGUI_TorusDlg::Init() { - /* init variables */ + // 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 & initial values + initSpinBox(GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY + + // init variables myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setReadOnly( true ); - GroupPoints->LineEdit2->setReadOnly( true ); - - myPoint = myDir = GEOM::GEOM_Object::_nil(); + GroupPoints->LineEdit1->setReadOnly(true); + GroupPoints->LineEdit2->setReadOnly(true); - /* Get setting of step value from file configuration */ - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 ); + GroupPoints->LineEdit1->setText(""); + GroupPoints->LineEdit2->setText(""); + myPoint = myDir = GEOM::GEOM_Object::_nil(); - /* min, max, step and decimals for spin boxes & initial values */ - initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupDimensions->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox( GroupDimensions->SpinBox_DY, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY + GroupPoints->SpinBox_DX->setValue(300.0); + GroupPoints->SpinBox_DY->setValue(100.0); + GroupDimensions->SpinBox_DX->setValue(300.0); + GroupDimensions->SpinBox_DY->setValue(100.0); - GroupPoints->SpinBox_DX->setValue( 300.0 ); - GroupPoints->SpinBox_DY->setValue( 100.0 ); - GroupDimensions->SpinBox_DX->setValue( 300.0 ); - GroupDimensions->SpinBox_DY->setValue( 100.0 ); + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - /* signals and slots connections */ - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); - connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); + connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); - connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); - connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) ); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double))); - connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) ); - - connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), - this, SLOT( SelectionIntoArgument() ) ); - - initName( tr( "GEOM_TORUS" ) ); + initName(tr("GEOM_TORUS")); - setConstructorId( 1 ); // simplest constructor - ConstructorsClicked( 1 ); + setConstructorId(1); // simplest constructor + ConstructorsClicked(1); } //================================================================================= // function : SetDoubleSpinBoxStep() // purpose : Double spin box management //================================================================================= -void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep( double step ) +void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep (double step) { GroupPoints->SpinBox_DX->setSingleStep(step); GroupPoints->SpinBox_DY->setSingleStep(step); @@ -172,138 +171,141 @@ void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep( double step ) GroupDimensions->SpinBox_DY->setSingleStep(step); } - //================================================================================= // function : ConstructorsClicked() // purpose : Radio button management //================================================================================= -void PrimitiveGUI_TorusDlg::ConstructorsClicked( int constructorId ) +void PrimitiveGUI_TorusDlg::ConstructorsClicked (int constructorId) { - disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 ); - - switch( constructorId ) { - case 0 : + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + + switch (constructorId) { + case 0: { - globalSelection(); // close local contexts, if any - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - GroupDimensions->hide(); GroupPoints->show(); - - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit1->setText( "" ); - GroupPoints->LineEdit2->setText( "" ); - myPoint = myDir = GEOM::GEOM_Object::_nil(); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - SelectionIntoArgument(); + + GroupPoints->PushButton1->click(); break; } case 1: { GroupPoints->hide(); GroupDimensions->show(); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); globalSelection(); // close local contexts, if any - - break ; + break; } } - + qApp->processEvents(); updateGeometry(); - resize( minimumSize() ); + resize(minimumSize()); - displayPreview(); + if (myInitial) { + myInitial = false; + if (constructorId == 0) { + // on dialog initialization we init the first field with a selected object (if any) + SelectionIntoArgument(); + } + else { + displayPreview(); + } + } + else { + displayPreview(); + } } - //================================================================================= // function : ClickOnOk() // purpose : //================================================================================= void PrimitiveGUI_TorusDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } - //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= bool PrimitiveGUI_TorusDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; initName(); - + // activate selection and connect selection manager + ConstructorsClicked(getConstructorId()); return true; } - //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void PrimitiveGUI_TorusDlg::SelectionIntoArgument() { - if ( getConstructorId() != 0 ) + if (getConstructorId() != 0) return; - - myEditCurrentArgument->setText( "" ); - + + erasePreview(); + myEditCurrentArgument->setText(""); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); SALOME_ListIO aSelList; aSelMgr->selectedObjects(aSelList); - if ( aSelList.Extent() != 1 ) { - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) + if (aSelList.Extent() != 1) { + if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint = GEOM::GEOM_Object::_nil(); - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + else if (myEditCurrentArgument == GroupPoints->LineEdit2) myDir = GEOM::GEOM_Object::_nil(); return; } - - /* nbSel == 1 */ + + // nbSel == 1 Standard_Boolean testResult = Standard_False; - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), testResult ); - - if ( !testResult || CORBA::is_nil( aSelectedObject ) ) + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); + + if (!testResult || CORBA::is_nil(aSelectedObject)) return; - QString aName = GEOMBase::GetName(aSelectedObject); + + // Get Selected object if selected subshape TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) { + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX; - if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (myEditCurrentArgument == GroupPoints->LineEdit2) aNeedType = TopAbs_EDGE; TColStd_IndexedMapOfInteger aMap; - aSelMgr->GetIndexes( aSelList.First(), aMap ); - if ( aMap.Extent() == 1 ) { // Local Selection - int anIndex = aMap( 1 ); - if ( aNeedType == TopAbs_EDGE ) - aName.append( ":edge_" + QString::number( anIndex ) ); + aSelMgr->GetIndexes(aSelList.First(), aMap); + if (aMap.Extent() == 1) { // Local Selection + int anIndex = aMap(1); + if (aNeedType == TopAbs_EDGE) + aName.append(":edge_" + QString::number(anIndex)); else - aName.append( ":vertex_" + QString::number( anIndex ) ); + aName.append(":vertex_" + QString::number(anIndex)); //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName ); + GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = - getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); + if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = + getGeomEngine()->GetIShapesOperations(getStudyId()); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); + } + else { + aSelectedObject = aFindedObject; // get Object from study } - else - aSelectedObject = aFindedObject; // get Object from study } else { // Global Selection - if ( aShape.ShapeType() != aNeedType ) { + if (aShape.ShapeType() != aNeedType) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; } @@ -312,15 +314,26 @@ void PrimitiveGUI_TorusDlg::SelectionIntoArgument() myEditCurrentArgument->setText(aName); - if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == GroupPoints->LineEdit1) { myPoint = aSelectedObject; - else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) + if (!myPoint->_is_nil() && myDir->_is_nil()) + GroupPoints->PushButton2->click(); + } + else if (myEditCurrentArgument == GroupPoints->LineEdit2) { myDir = aSelectedObject; - + if (!myDir->_is_nil() && myPoint->_is_nil()) + GroupPoints->PushButton1->click(); + } + displayPreview(); } - //================================================================================= // function : SetEditCurrentArgument() // purpose : @@ -328,38 +341,53 @@ void PrimitiveGUI_TorusDlg::SelectionIntoArgument() void PrimitiveGUI_TorusDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - globalSelection( GEOM_POINT ); // to break previous local selection - - if ( send == GroupPoints->PushButton1 ) { + + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + if (send == GroupPoints->PushButton1) { myEditCurrentArgument = GroupPoints->LineEdit1; - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + + GroupPoints->PushButton2->setDown(false); + GroupPoints->LineEdit2->setEnabled(false); + + globalSelection(GEOM_POINT); // to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } - else if ( send == GroupPoints->PushButton2 ) { + else if (send == GroupPoints->PushButton2) { myEditCurrentArgument = GroupPoints->LineEdit2; - GEOM::GEOM_Object_var anObj; - localSelection( anObj, TopAbs_EDGE ); + + GroupPoints->PushButton1->setDown(false); + GroupPoints->LineEdit1->setEnabled(false); + + globalSelection(GEOM_LINE); // to break previous local selection + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); } - + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); - SelectionIntoArgument(); -} + // after setFocus(), because it will be setDown(false) then loses focus + send->setDown(true); + // seems we need it only to avoid preview disappearing, caused by selection mode change + displayPreview(); +} //================================================================================= // function : LineEditReturnPressed() // purpose : //================================================================================= void PrimitiveGUI_TorusDlg::LineEditReturnPressed() -{ +{ QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupPoints->LineEdit1 || - send == GroupPoints->LineEdit2 ) { + if (send == GroupPoints->LineEdit1 || + send == GroupPoints->LineEdit2) { myEditCurrentArgument = send; GEOMBase_Skeleton::LineEditReturnPressed(); } } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -367,26 +395,23 @@ void PrimitiveGUI_TorusDlg::LineEditReturnPressed() void PrimitiveGUI_TorusDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - - ConstructorsClicked( getConstructorId() ); -} + // reinit, because some selected objects could be removed + Init(); +} //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void PrimitiveGUI_TorusDlg::enterEvent( QEvent* ) +void PrimitiveGUI_TorusDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } - //================================================================================= -// function : ValueChangedInSpinBox +// function : ValueChangedInSpinBox() // purpose : //================================================================================= void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox() @@ -394,57 +419,55 @@ void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox() displayPreview(); } - //================================================================================= // function : createOperation // purpose : //================================================================================= GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation() { - return getGeomEngine()->GetI3DPrimOperations( getStudyId() ); + return getGeomEngine()->GetI3DPrimOperations(getStudyId()); } - //================================================================================= // function : isValid // purpose : //================================================================================= -bool PrimitiveGUI_TorusDlg::isValid( QString& msg ) +bool PrimitiveGUI_TorusDlg::isValid (QString&) { return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true; } - //================================================================================= // function : execute // purpose : //================================================================================= -bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects ) +bool PrimitiveGUI_TorusDlg::execute (ObjectList& objects) { bool res = false; - + GEOM::GEOM_Object_var anObj; - switch ( getConstructorId() ) { - case 0 : - if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){ - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR( myPoint, myDir, getRadius1(), getRadius2() ); + switch (getConstructorId()) { + case 0: + if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) { + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2()); res = true; } break; - case 1 : - anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR( getRadius1(), getRadius2() ); + case 1: + anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())-> + MakeTorusRR(getRadius1(), getRadius2()); res = true; break; } - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); return res; } - //================================================================================= // function : getRadius1() // purpose : @@ -452,14 +475,13 @@ bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects ) double PrimitiveGUI_TorusDlg::getRadius1() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DX->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DX->value(); return 0; } - //================================================================================= // function : getRadius2() // purpose : @@ -467,9 +489,9 @@ double PrimitiveGUI_TorusDlg::getRadius1() const double PrimitiveGUI_TorusDlg::getRadius2() const { int aConstructorId = getConstructorId(); - if ( aConstructorId == 0 ) + if (aConstructorId == 0) return GroupPoints->SpinBox_DY->value(); - else if ( aConstructorId == 1 ) + else if (aConstructorId == 1) return GroupDimensions->SpinBox_DY->value(); return 0; } @@ -482,7 +504,7 @@ void PrimitiveGUI_TorusDlg::addSubshapesToStudy() { QMap objMap; - switch ( getConstructorId() ) { + switch (getConstructorId()) { case 0: objMap[GroupPoints->LineEdit1->text()] = myPoint; objMap[GroupPoints->LineEdit2->text()] = myDir; @@ -490,5 +512,5 @@ void PrimitiveGUI_TorusDlg::addSubshapesToStudy() case 1: return; } - addSubshapesToFather( objMap ); + addSubshapesToFather(objMap); } diff --git a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.h b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.h index 2408106c1..46d7843b4 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.h +++ b/src/PrimitiveGUI/PrimitiveGUI_TorusDlg.h @@ -56,7 +56,11 @@ private: double getRadius1() const; double getRadius2() const; +private: GEOM::GEOM_Object_var myPoint, myDir; + + // to initialize the first selection field with a selected object on the dialog creation + bool myInitial; DlgRef_2Sel2Spin* GroupPoints; DlgRef_2Spin* GroupDimensions;