1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PrimitiveGUI_DiskDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "PrimitiveGUI_DiskDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
45 //=================================================================================
46 // class : PrimitiveGUI_DiskDlg()
47 // purpose : Constructs a PrimitiveGUI_DiskDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_PNT_VEC_R" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DISK_THREE_POINTS" ) ) );
60 setWindowTitle( tr( "GEOM_DISK_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_DISK" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image2 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPntVecR = new DlgRef_2Sel1Spin( centralWidget() );
71 GroupPntVecR->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPntVecR->TextLabel1->setText( tr( "GEOM_CENTER_POINT" ) );
73 GroupPntVecR->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
74 GroupPntVecR->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
75 GroupPntVecR->PushButton1->setIcon( image1 );
76 GroupPntVecR->PushButton2->setIcon( image1 );
78 GroupPntVecR->LineEdit1->setReadOnly( true );
79 GroupPntVecR->LineEdit2->setReadOnly( true );
81 Group3Pnts = new DlgRef_3Sel( centralWidget() );
83 Group3Pnts->GroupBox1->setTitle( tr( "GEOM_3_POINTS" ) );
84 Group3Pnts->TextLabel1->setText( tr( "GEOM_POINT1" ) );
85 Group3Pnts->TextLabel2->setText( tr( "GEOM_POINT2" ) );
86 Group3Pnts->TextLabel3->setText( tr( "GEOM_POINT3" ) );
87 Group3Pnts->PushButton1->setIcon( image1 );
88 Group3Pnts->PushButton2->setIcon( image1 );
89 Group3Pnts->PushButton3->setIcon( image1 );
91 Group3Pnts->LineEdit1->setReadOnly( true );
92 Group3Pnts->LineEdit2->setReadOnly( true );
93 Group3Pnts->LineEdit3->setReadOnly( true );
95 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
96 layout->setMargin( 0 ); layout->setSpacing( 6 );
97 layout->addWidget( GroupPntVecR );
98 layout->addWidget( Group3Pnts );
99 /***************************************************************/
101 setHelpFileName( "create_disk_page.html" );
107 //=================================================================================
108 // function : ~PrimitiveGUI_DiskDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 PrimitiveGUI_DiskDlg::~PrimitiveGUI_DiskDlg()
116 //=================================================================================
119 //=================================================================================
120 void PrimitiveGUI_DiskDlg::Init()
123 myEditCurrentArgument = GroupPntVecR->LineEdit1;
125 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
127 /* Get setting of step value from file configuration */
128 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
129 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
131 /* min, max, step and decimals for spin boxes & initial values */
132 initSpinBox( GroupPntVecR->SpinBox_DX, 0.001, COORD_MAX, aStep, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
133 GroupPntVecR->SpinBox_DX->setValue( 100 );
135 /* signals and slots connections */
136 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
137 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
139 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
140 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
142 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
144 connect( GroupPntVecR->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
145 connect( GroupPntVecR->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPntVecR->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
147 connect( GroupPntVecR->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149 connect( Group3Pnts->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
150 connect( Group3Pnts->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151 connect( Group3Pnts->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152 connect( Group3Pnts->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
153 connect( Group3Pnts->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
154 connect( Group3Pnts->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
156 connect( GroupPntVecR->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT(ValueChangedInSpinBox() ) );
157 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
159 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
160 this, SLOT( SelectionIntoArgument() ) );
162 initName( tr( "GEOM_DISK" ) );
164 ConstructorsClicked( 0 );
167 //=================================================================================
168 // function : SetDoubleSpinBoxStep()
169 // purpose : Double spin box management
170 //=================================================================================
171 void PrimitiveGUI_DiskDlg::SetDoubleSpinBoxStep( double step )
173 GroupPntVecR->SpinBox_DX->setSingleStep(step);
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void PrimitiveGUI_DiskDlg::ConstructorsClicked( int constructorId )
182 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
184 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
186 switch ( constructorId ) {
190 GroupPntVecR->show();
192 myEditCurrentArgument = GroupPntVecR->LineEdit1;
193 GroupPntVecR->LineEdit1->setText( "" );
194 GroupPntVecR->LineEdit2->setText( "" );
199 GroupPntVecR->hide();
202 myEditCurrentArgument = Group3Pnts->LineEdit1;
203 Group3Pnts->LineEdit1->setText( "" );
204 Group3Pnts->LineEdit2->setText( "" );
205 Group3Pnts->LineEdit3->setText( "" );
210 qApp->processEvents();
212 resize( minimumSize() );
214 myEditCurrentArgument->setFocus();
215 globalSelection(); // close local contexts, if any
216 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
218 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
219 this, SLOT( SelectionIntoArgument() ) );
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void PrimitiveGUI_DiskDlg::ClickOnOk()
228 if ( ClickOnApply() )
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 bool PrimitiveGUI_DiskDlg::ClickOnApply()
242 ConstructorsClicked( getConstructorId() );
246 //=================================================================================
247 // function : SelectionIntoArgument()
248 // purpose : Called when selection as changed or other case
249 //=================================================================================
250 void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
252 myEditCurrentArgument->setText( "" );
254 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
256 aSelMgr->selectedObjects( aList );
258 if ( aList.Extent() != 1 ) {
259 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
260 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
261 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
262 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
263 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
268 Handle(SALOME_InteractiveObject) anIO = aList.First();
270 Standard_Boolean aRes = Standard_False;
271 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
272 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
273 QString aName = GEOMBase::GetName( aSelectedObject );
275 // If selected Vertex or Edge on the some Shape Get selection Subshape
277 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
278 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
279 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
280 aNeedType = TopAbs_EDGE;
282 TColStd_IndexedMapOfInteger aMap;
283 aSelMgr->GetIndexes(anIO, aMap);
284 if ( aMap.Extent() == 1 ) { // Local Selection
285 int anIndex = aMap(1);
286 if ( aNeedType == TopAbs_EDGE )
287 aName += QString( ":edge_%1" ).arg( anIndex );
289 aName += QString( ":vertex_%1" ).arg( anIndex );
291 //Find SubShape Object in Father
292 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
294 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
295 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
296 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
299 aSelectedObject = aFindedObject; // get Object from study
302 else { // Global Selection
303 if ( aShape.ShapeType() != aNeedType ) {
304 aSelectedObject = GEOM::GEOM_Object::_nil();
310 myEditCurrentArgument->setText( aName );
312 if ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint = aSelectedObject;
313 else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
314 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
315 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
316 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
323 //=================================================================================
324 // function : SetEditCurrentArgument()
326 //=================================================================================
327 void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
329 QPushButton* send = (QPushButton*)sender();
331 if ( send == GroupPntVecR->PushButton1 ) myEditCurrentArgument = GroupPntVecR->LineEdit1;
332 else if ( send == GroupPntVecR->PushButton2 ) myEditCurrentArgument = GroupPntVecR->LineEdit2;
333 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
334 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
335 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
337 myEditCurrentArgument->setFocus();
339 if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) {
340 globalSelection(); // close local contexts, if any
341 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
344 globalSelection(); // close local contexts, if any
345 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
348 SelectionIntoArgument();
351 //=================================================================================
352 // function : LineEditReturnPressed()
354 //=================================================================================
355 void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
357 QLineEdit* send = (QLineEdit*)sender();
358 if ( send == GroupPntVecR->LineEdit1 ||
359 send == GroupPntVecR->LineEdit2 ||
360 send == Group3Pnts->LineEdit1 ||
361 send == Group3Pnts->LineEdit2 ||
362 send == Group3Pnts->LineEdit3 ) {
363 myEditCurrentArgument = send;
364 GEOMBase_Skeleton::LineEditReturnPressed();
369 //=================================================================================
370 // function : ActivateThisDialog()
372 //=================================================================================
373 void PrimitiveGUI_DiskDlg::ActivateThisDialog()
375 GEOMBase_Skeleton::ActivateThisDialog();
377 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
378 this, SLOT( SelectionIntoArgument() ) );
380 ConstructorsClicked( getConstructorId() );
384 //=================================================================================
385 // function : enterEvent()
387 //=================================================================================
388 void PrimitiveGUI_DiskDlg::enterEvent( QEvent* )
390 if ( !mainFrame()->GroupConstructors->isEnabled() )
391 ActivateThisDialog();
394 //=================================================================================
395 // function : DeactivateActiveDialog()
396 // purpose : public slot to deactivate if active
397 //=================================================================================
398 void PrimitiveGUI_DiskDlg::DeactivateActiveDialog()
400 // myGeomGUI->SetState( -1 );
401 GEOMBase_Skeleton::DeactivateActiveDialog();
404 //=================================================================================
405 // function : ValueChangedInSpinBox()
407 //=================================================================================
408 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
413 //=================================================================================
414 // function : getRadius()
416 //=================================================================================
417 double PrimitiveGUI_DiskDlg::getRadius() const
420 switch ( getConstructorId() ) {
422 r = GroupPntVecR->SpinBox_DX->value(); break;
427 //=================================================================================
428 // function : createOperation
430 //=================================================================================
431 GEOM::GEOM_IOperations_ptr PrimitiveGUI_DiskDlg::createOperation()
433 return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
436 //=================================================================================
437 // function : isEqual
438 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
439 //=================================================================================
440 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
442 return thePnt1->_is_equivalent( thePnt2 );
445 //=================================================================================
446 // function : isValid
448 //=================================================================================
449 bool PrimitiveGUI_DiskDlg::isValid( QString& msg )
451 const int id = getConstructorId();
453 return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0;
455 return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
456 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
460 //=================================================================================
461 // function : execute
463 //=================================================================================
464 bool PrimitiveGUI_DiskDlg::execute( ObjectList& objects )
468 GEOM::GEOM_Object_var anObj;
470 switch ( getConstructorId() ) {
472 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskPntVecR( myPoint, myDir, getRadius() );
476 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeDiskThreePnt( myPoint1, myPoint2, myPoint3 );
481 if ( !anObj->_is_nil() )
482 objects.push_back( anObj._retn() );
484 MESSAGE( "Execute Object is NULL!" );
490 //=================================================================================
491 // function : addSubshapeToStudy
492 // purpose : virtual method to add new SubObjects if local selection
493 //=================================================================================
494 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
496 QMap<QString, GEOM::GEOM_Object_var> objMap;
498 switch ( getConstructorId() ) {
500 objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
501 objMap[GroupPntVecR->LineEdit2->text()] = myDir;
504 objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
505 objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
506 objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
509 addSubshapesToFather( objMap );