]> SALOME platform Git repositories - modules/geom.git/blob - src/PrimitiveGUI/PrimitiveGUI_FaceDlg.cxx
Salome HOME
Notebook: automatic variable definition.
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_FaceDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : PrimitiveGUI_FaceDlg.cxx
24 // Author : Dmitry Matveitchev, OCN.
25 //
26 #include "PrimitiveGUI_FaceDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Notebook.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS.hxx>
40 #include <TopExp.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43
44 #include <GEOMImpl_Types.hxx>
45
46 //=================================================================================
47 // class    : PrimitiveGUI_FaceDlg()
48 // purpose  : Constructs a PrimitiveGUI_FaceDlg which is a child of 'parent', with the 
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 PrimitiveGUI_FaceDlg::PrimitiveGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54                                     bool modal, Qt::WindowFlags fl )
55   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 {
57   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_OBJ_HW")));
58   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FACE_HW")));
60
61   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
62  
63   /***************************************************************/
64   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
65   mainFrame()->RadioButton1->setIcon( image2 );
66   mainFrame()->RadioButton2->setIcon( image0 );
67   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68   mainFrame()->RadioButton3->close();
69
70   GroupPlane = new DlgRef_1Sel2Spin( centralWidget() );
71   GroupPlane->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72   GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
73   GroupPlane->TextLabel2->setText( tr( "GEOM_HEIGHT" ) );
74   GroupPlane->TextLabel3->setText( tr( "GEOM_WIDTH" ) );
75   GroupPlane->PushButton1->setIcon( image1 );
76   GroupPlane->LineEdit1->setReadOnly( true );
77
78   GroupType = new DlgRef_3Radio( centralWidget() );
79   GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
80   GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
81   GroupType->RadioButton2->setText( tr( "GEOM_FACE" ) );
82   GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
83   GroupType->RadioButton3->close();
84
85   GroupDimensions = new DlgRef_2Spin( centralWidget() );
86   GroupDimensions->GroupBox1->setTitle( tr( "GEOM_BOX_OBJ" ) );
87   GroupDimensions->TextLabel1->setText( tr( "GEOM_HEIGHT" ) );
88   GroupDimensions->TextLabel2->setText( tr( "GEOM_WIDTH" ) );
89
90   GroupOrientation = new DlgRef_3Radio( centralWidget() );
91
92   GroupOrientation->GroupBox1->setTitle( tr( "GEOM_ORIENTATION" ) );
93   GroupOrientation->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
94   GroupOrientation->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
95   GroupOrientation->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
96
97   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
98   layout->setMargin( 0 ); layout->setSpacing( 6 );
99   layout->addWidget( GroupType );
100   layout->addWidget( GroupPlane );
101   layout->addWidget( GroupDimensions );
102   layout->addWidget( GroupOrientation );
103
104   /***************************************************************/
105
106   setHelpFileName( "create_squareface_page.html" );
107
108   Init();
109 }
110
111
112 //=================================================================================
113 // function : ~PrimitiveGUI_FaceDlg()
114 // purpose  : Destroys the object and frees any allocated resources
115 //=================================================================================
116 PrimitiveGUI_FaceDlg::~PrimitiveGUI_FaceDlg()
117 {  
118 }
119
120
121 //=================================================================================
122 // function : Init()
123 // purpose  :
124 //=================================================================================
125 void PrimitiveGUI_FaceDlg::Init()
126 {
127   /* init variables */
128   myEditCurrentArgument = GroupPlane->LineEdit1;
129   GroupType->RadioButton1->setChecked(true);
130   myEdge = GEOM::GEOM_Object::_nil();
131   myFace = GEOM::GEOM_Object::_nil();
132   globalSelection(); // close local contexts, if any
133   //  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
134
135   myOrientationType = 1;
136
137   /* Get setting of step value from file configuration */
138   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
139   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
140
141   double aDefaultSize = 100.0;
142   /* min, max, step and decimals for spin boxes */
143   initSpinBox( GroupPlane->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
144   GroupPlane->SpinBox_DX->setValue( aDefaultSize );
145   initSpinBox( GroupPlane->SpinBox_DY, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
146   GroupPlane->SpinBox_DY->setValue( aDefaultSize );
147
148   initSpinBox( GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
149   GroupDimensions->SpinBox_DX->setValue( aDefaultSize );
150   initSpinBox( GroupDimensions->SpinBox_DY, 0.00001, COORD_MAX, aStep, 5 ); // VSR: TODO: DBL_DIGITS_DISPLAY
151   GroupDimensions->SpinBox_DY->setValue( aDefaultSize );
152
153         
154   /* signals and slots connections */
155   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
156   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
157   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
158
159   connect( this,           SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
160
161   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
162   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
163
164   connect( GroupPlane->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
165   connect( GroupPlane->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
166   connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
167   connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168
169   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
170   connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
171
172   connect( GroupOrientation->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173   connect( GroupOrientation->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
174   connect( GroupOrientation->RadioButton3, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
175
176   connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
177   connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
178
179   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
180            this, SLOT( SelectionIntoArgument() ) );
181   
182   initName( tr( "GEOM_FACE" ) );
183
184   ConstructorsClicked( 0 );
185 }
186
187 //=================================================================================
188 // function : SetDoubleSpinBoxStep()
189 // purpose  : Double spin box management
190 //=================================================================================
191 void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
192 {
193   GroupPlane->SpinBox_DX->setSingleStep(step);
194   GroupPlane->SpinBox_DY->setSingleStep(step);
195 }
196
197 //=================================================================================
198 // function : ValueChangedInSpinBox()
199 // purpose  :
200 //=================================================================================
201 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
202 {
203   displayPreview();
204 }
205
206 //=================================================================================
207 // function : RadioBittonClicked()
208 // purpose  : Radio button management
209 //=================================================================================
210 void PrimitiveGUI_FaceDlg::RadioButtonClicked()
211 {
212   if ( GroupOrientation->RadioButton1->isChecked() )
213     myOrientationType = 1;
214   else if ( GroupOrientation->RadioButton2->isChecked() )
215     myOrientationType = 2;
216   else if ( GroupOrientation->RadioButton3->isChecked() )
217     myOrientationType = 3;
218   displayPreview();
219 }
220
221 //=================================================================================
222 // function : TypeBittonClicked()
223 // purpose  : Radio button management
224 //=================================================================================
225 void PrimitiveGUI_FaceDlg::TypeButtonClicked()
226 {
227   if ( GroupType->RadioButton1->isChecked() ) {
228     globalSelection(); // close local contexts, if any
229     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
230     GroupPlane->TextLabel1->setText( tr( "GEOM_EDGE" ) );
231   }
232   else if ( GroupType->RadioButton2->isChecked() ) {
233     globalSelection(); // close local contexts, if any
234     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
235     GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
236   }
237 }
238
239 //=================================================================================
240 // function : ClickOnOk()
241 // purpose  :
242 //=================================================================================
243 void PrimitiveGUI_FaceDlg::ClickOnOk()
244 {
245   if ( ClickOnApply() )
246     ClickOnCancel();
247 }
248
249 //=================================================================================
250 // function : ClickOnApply()
251 // purpose  :
252 //=================================================================================
253 bool PrimitiveGUI_FaceDlg::ClickOnApply()
254 {
255   if ( !onAccept() )
256     return false;
257   
258   initName();
259
260   myEditCurrentArgument->setText( "" );
261   ConstructorsClicked( getConstructorId() );
262
263   return true;
264 }
265
266 //=================================================================================
267 // function : ConstructorsClicked()
268 // purpose  : Radio button management
269 //=================================================================================
270 void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
271 {  
272   erasePreview();
273   switch ( constructorId ) {
274   case 0:
275     {
276       globalSelection(); // close local contexts, if any
277       GroupPlane->hide();
278       GroupDimensions->show();
279       GroupOrientation->show();
280       GroupType->hide();
281       GroupOrientation->RadioButton1->setChecked( true );
282       myOrientationType = 1;
283       break;
284     }
285   case 1:
286     {
287       globalSelection(); // close local contexts, if any
288       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
289       myEditCurrentArgument = GroupPlane->LineEdit1;
290       myEditCurrentArgument->setText("");
291       myEdge = GEOM::GEOM_Object::_nil();
292       myFace = GEOM::GEOM_Object::_nil();
293       GroupType->RadioButton1->setChecked( true );
294       TypeButtonClicked();
295       GroupDimensions->hide();
296       GroupOrientation->hide();
297       GroupType->show();
298       GroupPlane->show();
299       break;
300     }
301   }
302
303   qApp->processEvents();
304   updateGeometry();
305   resize( minimumSizeHint() );
306   SelectionIntoArgument();
307   //displayPreview();
308 }
309
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose  : Called when selection as changed or other case
313 //=================================================================================
314 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
315 {
316   if (getConstructorId() == 0) {
317     displayPreview();
318     return;
319   }
320
321   myEditCurrentArgument->setText( "" );
322
323   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
324   SALOME_ListIO aSelList;
325   aSelMgr->selectedObjects(aSelList);
326
327   if ( aSelList.Extent() != 1 ) {
328     if ( myEditCurrentArgument == GroupPlane->LineEdit1 )  myEdge = GEOM::GEOM_Object::_nil();
329     return;
330   }
331
332   // nbSel == 1 
333   Standard_Boolean aRes = Standard_False;
334   TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
335   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First(), aRes );
336   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
337     QString aName = GEOMBase::GetName( aSelectedObject );
338     
339     TopoDS_Shape aShape;
340     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
341       if (GroupType->RadioButton2->isChecked())
342         aNeedType = TopAbs_FACE;
343
344       TColStd_IndexedMapOfInteger aMap;
345       aSelMgr->GetIndexes( aSelList.First(), aMap );
346       if ( aMap.Extent() == 1 ) { // Local Selection
347         int anIndex = aMap( 1 );
348         if ( aNeedType == TopAbs_EDGE )
349           aName += QString( ":edge_%1" ).arg( anIndex );
350         else
351           aName += QString( ":face_%1" ).arg( anIndex );
352
353         //Find SubShape Object in Father
354         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
355
356         if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
357           GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
358           aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
359         }
360         else
361           aSelectedObject = aFindedObject; // get Object from study
362       }
363       else { // Global Selection
364         if ( aShape.ShapeType() != aNeedType ) {
365           aSelectedObject = GEOM::GEOM_Object::_nil();
366           aName = "";
367         }
368       }
369     }
370
371     myEditCurrentArgument->setText( aName );
372     if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
373       myEdge = aSelectedObject;
374     else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
375       myFace = aSelectedObject;
376   }
377   displayPreview();
378 }
379
380
381 //=================================================================================
382 // function : SetEditCurrentArgument()
383 // purpose  :
384 //=================================================================================
385 void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
386 {
387   QPushButton* send = (QPushButton*)sender();
388
389   globalSelection(); // close previous local contexts
390   if ( send == GroupPlane->PushButton1 ) {
391     myEditCurrentArgument = GroupPlane->LineEdit1;
392     if (GroupType->RadioButton1->isChecked())
393       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
394     else if (GroupType->RadioButton1->isChecked())
395       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
396   }
397
398   myEditCurrentArgument->setFocus();
399   SelectionIntoArgument();
400 }
401
402
403 //=================================================================================
404 // function : LineEditReturnPressed()
405 // purpose  :
406 //=================================================================================
407 void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
408 {
409   QLineEdit* send = (QLineEdit*)sender();
410   if ( send == GroupPlane->LineEdit1 )  myEditCurrentArgument = GroupPlane->LineEdit1;
411   else return;
412   GEOMBase_Skeleton::LineEditReturnPressed();
413 }
414
415
416 //=================================================================================
417 // function : ActivateThisDialog()
418 // purpose  :
419 //=================================================================================
420 void PrimitiveGUI_FaceDlg::ActivateThisDialog()
421 {
422   GEOMBase_Skeleton::ActivateThisDialog();
423   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
424            this, SLOT( SelectionIntoArgument() ) );
425
426   ConstructorsClicked( getConstructorId() );
427 }
428
429 //=================================================================================
430 // function : DeactivateActiveDialog()
431 // purpose  : public slot to deactivate if active
432 //=================================================================================
433 void PrimitiveGUI_FaceDlg::DeactivateActiveDialog()
434 {
435   GEOMBase_Skeleton::DeactivateActiveDialog();
436 }
437
438 //=================================================================================
439 // function : enterEvent()
440 // purpose  :
441 //=================================================================================
442 void PrimitiveGUI_FaceDlg::enterEvent( QEvent* )
443 {
444   if ( !mainFrame()->GroupConstructors->isEnabled() )
445     ActivateThisDialog();
446 }
447
448 //=================================================================================
449 // function : createOperation
450 // purpose  :
451 //=================================================================================
452 GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
453 {
454   return myGeomGUI->GetGeomGen()->GetI3DPrimOperations( getStudyId() );
455 }
456
457 //=================================================================================
458 // function : isValid
459 // purpose  :
460 //=================================================================================
461 bool PrimitiveGUI_FaceDlg::isValid( QString& msg, QStringList& absentParams )
462 {
463   bool ok = true;
464   if( getConstructorId() == 0 )
465   {
466     ok = GroupDimensions->SpinBox_DX->isValid( msg, absentParams, !IsPreview() ) && ok;
467     ok = GroupDimensions->SpinBox_DY->isValid( msg, absentParams, !IsPreview() ) && ok;
468   }
469   else if( getConstructorId() == 1 )
470   {
471     ok = GroupPlane->SpinBox_DX->isValid( msg, absentParams, !IsPreview() ) && ok;
472     ok = GroupPlane->SpinBox_DY->isValid( msg, absentParams, !IsPreview() ) && ok;
473   }
474
475   const int id = getConstructorId();
476   if ( id == 0 )
477     return ok;
478   else if ( id == 1 ) {
479     if (GroupType->RadioButton1->isChecked())
480       return !myEdge->_is_nil() && ok;
481     else if (GroupType->RadioButton2->isChecked())
482       return !myFace->_is_nil() && ok;
483   }
484   return false;
485 }
486
487 //=================================================================================
488 // function : execute
489 // purpose  :
490 //=================================================================================
491 bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
492 {
493   bool res = false;
494   GEOM::GEOM_Object_var anObj;
495
496   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
497
498   switch (getConstructorId()) {
499   case 0:
500     anObj = anOper->MakeFaceHW(GroupDimensions->SpinBox_DX->value(),
501                                GroupDimensions->SpinBox_DY->value(), myOrientationType);
502     if (!anObj->_is_nil() && !IsPreview())
503       myNoteBook->setParameters(anObj, 2, GroupDimensions->SpinBox_DX, GroupDimensions->SpinBox_DY);
504     res = true;
505     break;
506   case 1:
507     anObj = GroupType->RadioButton1->isChecked() ? 
508       anOper->MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) : 
509       anOper->MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
510     if (!anObj->_is_nil() && !IsPreview())
511       myNoteBook->setParameters(anObj, 2, GroupPlane->SpinBox_DX, GroupPlane->SpinBox_DY);
512     res = true;
513     break;
514   }
515
516   if (!anObj->_is_nil())
517     objects.push_back(anObj._retn());
518
519   return res;
520 }
521
522 //=================================================================================
523 // function : addSubshapeToStudy
524 // purpose  : virtual method to add new SubObjects if local selection
525 //=================================================================================
526 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
527 {
528   QMap<QString, GEOM::GEOM_Object_var> objMap;
529   switch ( getConstructorId() ) {
530   case 1 :
531     if ( GroupType->RadioButton1->isChecked() )
532       objMap[GroupPlane->LineEdit1->text()] = myEdge;
533     if ( GroupType->RadioButton2->isChecked() )
534       objMap[GroupPlane->LineEdit1->text()] = myFace;
535     break;
536   }
537   addSubshapesToFather( objMap );
538 }