]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_PlaneDlg.cxx
Salome HOME
SMH: Merged GEOM (NEWGUI, HEAD, POLYWORK)
[modules/geom.git] / src / BasicGUI / BasicGUI_PlaneDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BasicGUI_PlaneDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_PlaneDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 #include "GEOMImpl_Types.hxx"
39
40 using namespace std;
41
42 //=================================================================================
43 // class    : BasicGUI_PlaneDlg()
44 // purpose  : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
51 {
52   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
53   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_3PNTS")));
54   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
55   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_PLANE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_PLANE"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->setPixmap(image1);
63   RadioButton3->setPixmap(image2);
64
65   GroupPntDir = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
66   GroupPntDir->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
67   GroupPntDir->TextLabel1->setText(tr("GEOM_POINT"));
68   GroupPntDir->TextLabel2->setText(tr("GEOM_VECTOR"));
69   GroupPntDir->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
70   GroupPntDir->PushButton1->setPixmap(image3);
71   GroupPntDir->PushButton2->setPixmap(image3);
72   GroupPntDir->LineEdit1->setReadOnly( true );
73   GroupPntDir->LineEdit2->setReadOnly( true );
74
75   Group3Pnts = new DlgRef_3Sel1Spin(this, "Group3Pnts");
76   Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
77   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
78   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
79   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
80   Group3Pnts->TextLabel4->setText(tr("GEOM_PLANE_SIZE"));
81   Group3Pnts->PushButton1->setPixmap(image3);
82   Group3Pnts->PushButton2->setPixmap(image3);
83   Group3Pnts->PushButton3->setPixmap(image3);
84
85   Group3Pnts->LineEdit1->setReadOnly( true );
86   Group3Pnts->LineEdit2->setReadOnly( true );
87   Group3Pnts->LineEdit3->setReadOnly( true );
88
89   GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
90   GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
91   GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
92   GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
93   GroupFace->PushButton1->setPixmap(image3);
94
95   GroupFace->LineEdit1->setReadOnly( true );
96     
97   Layout1->addWidget(GroupPntDir, 2, 0);
98   Layout1->addWidget(Group3Pnts, 2, 0);
99   Layout1->addWidget(GroupFace, 2, 0);
100   /***************************************************************/
101
102   Init();
103 }
104
105
106 //=================================================================================
107 // function : ~BasicGUI_PlaneDlg()
108 // purpose  : Destroys the object and frees any allocated resources
109 //=================================================================================
110 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
111 {  
112 }
113
114
115 //=================================================================================
116 // function : Init()
117 // purpose  :
118 //=================================================================================
119 void BasicGUI_PlaneDlg::Init()
120 {
121   /* init variables */
122   myEditCurrentArgument = GroupPntDir->LineEdit1;
123
124   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
125
126   // myGeometryGUI->SetState( 0 );
127
128   /* Get setting of step value from file configuration */
129   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
130   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
131   
132   double aTrimSize = 2000.0;
133   
134   /* min, max, step and decimals for spin boxes */
135   GroupPntDir->SpinBox_DX->RangeStepAndValidator( 0.001, 10000000.0, aStep, 3 );
136   GroupPntDir->SpinBox_DX->SetValue( aTrimSize );
137   Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
138   Group3Pnts->SpinBox_DX->SetValue( aTrimSize );
139   GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
140   GroupFace->SpinBox_DX->SetValue( aTrimSize );
141
142   /* signals and slots connections */
143   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
144   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
145   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
146
147   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
148   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
149   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
150
151   connect(GroupPntDir->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152   connect(GroupPntDir->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153   connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156   connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157
158   connect(GroupPntDir->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159   connect(GroupPntDir->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160   connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161   connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162   connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163   connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164
165   connect(GroupPntDir->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166   connect(Group3Pnts->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167   connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168
169   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntDir->SpinBox_DX, SLOT(SetStep(double)));
170   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Pnts->SpinBox_DX, SLOT(SetStep(double)));
171   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
172
173   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
174
175   initName( tr( "GEOM_PLANE" ) );
176
177   Group3Pnts->hide();
178   GroupFace->hide();
179   ConstructorsClicked( 0 );
180 }
181
182
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose  : Radio button management
186 //=================================================================================
187 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
188 {
189   disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
190   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
191
192   switch ( constructorId )
193   {
194     case 0: /* plane from a point and a direction (vector, edge...) */
195       { 
196                                 Group3Pnts->hide();
197                                 GroupFace->hide();
198                                 resize(0, 0);
199                                 GroupPntDir->show();
200
201                                 myEditCurrentArgument = GroupPntDir->LineEdit1;
202                                 GroupPntDir->LineEdit1->setText(tr(""));
203                                 GroupPntDir->LineEdit2->setText(tr(""));
204
205                                 /* for the first argument */
206                                 globalSelection( GEOM_POINT );
207                                 break;
208       }
209     case 1: /* plane from 3 points */
210       {
211                                 GroupPntDir->hide();
212                                 GroupFace->hide();
213                                 resize(0, 0);
214                                 Group3Pnts->show();
215
216                                 myEditCurrentArgument = Group3Pnts->LineEdit1;
217                                 Group3Pnts->LineEdit1->setText("");
218                                 Group3Pnts->LineEdit2->setText("");
219                                 Group3Pnts->LineEdit3->setText("");
220
221                                 /* for the first argument */
222                                 globalSelection( GEOM_POINT );
223                                 break;
224       } 
225     case 2: /* plane from a planar face selection */
226       {
227                                 GroupPntDir->hide();
228                                 Group3Pnts->hide();
229                                 resize(0, 0);
230                                 GroupFace->show();
231
232                                 myEditCurrentArgument = GroupFace->LineEdit1;
233                                 GroupFace->LineEdit1->setText(tr(""));
234
235                                 /* for the first argument */
236                                 globalSelection( GEOM_PLANE );
237                                 break;
238       }
239     }
240
241   myEditCurrentArgument->setFocus();
242   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
243           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 }
245
246
247 //=================================================================================
248 // function : ClickOnOk()
249 // purpose  :
250 //=================================================================================
251 void BasicGUI_PlaneDlg::ClickOnOk()
252 {
253   if ( ClickOnApply() )
254     ClickOnCancel();
255 }
256
257
258 //=================================================================================
259 // function : ClickOnApply()
260 // purpose  :
261 //=================================================================================
262 bool BasicGUI_PlaneDlg::ClickOnApply()
263 {
264   if ( !onAccept() )
265     return false;
266
267   initName();
268   ConstructorsClicked( getConstructorId() );
269   return true;
270 }
271
272 //=======================================================================
273 // function : ClickOnCancel()
274 // purpose  :
275 //=======================================================================
276 void BasicGUI_PlaneDlg::ClickOnCancel()
277 {
278   GEOMBase_Skeleton::ClickOnCancel();
279 }
280
281 //=================================================================================
282 // function : SelectionIntoArgument()
283 // purpose  : Called when selection has changed
284 //=================================================================================
285 void BasicGUI_PlaneDlg::SelectionIntoArgument()
286 {
287   myEditCurrentArgument->setText("");
288   
289   if ( IObjectCount() != 1 )  
290   {
291     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = GEOM::GEOM_Object::_nil();
292     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = GEOM::GEOM_Object::_nil();
293     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1 = GEOM::GEOM_Object::_nil();
294     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )  myPoint2 = GEOM::GEOM_Object::_nil();
295     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )  myPoint3 = GEOM::GEOM_Object::_nil();
296     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )   myFace   = GEOM::GEOM_Object::_nil();
297     return;
298   }
299
300   // nbSel == 1
301   Standard_Boolean aRes = Standard_False;
302   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
303   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
304   {  
305     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
306     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = aSelectedObject;
307     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = aSelectedObject;
308     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1 = aSelectedObject;
309     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )  myPoint2 = aSelectedObject;
310     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )  myPoint3 = aSelectedObject;
311     else if ( myEditCurrentArgument == GroupFace->LineEdit1 )   myFace   = aSelectedObject;
312   }
313
314   displayPreview();
315 }
316
317
318 //=================================================================================
319 // function : SetEditCurrentArgument()
320 // purpose  :
321 //=================================================================================
322 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
323 {
324   QPushButton* send = (QPushButton*)sender();  
325
326   if      ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
327   else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
328   else if ( send == Group3Pnts->PushButton1 )  myEditCurrentArgument = Group3Pnts->LineEdit1;
329   else if ( send == Group3Pnts->PushButton2 )  myEditCurrentArgument = Group3Pnts->LineEdit2;
330   else if ( send == Group3Pnts->PushButton3 )  myEditCurrentArgument = Group3Pnts->LineEdit3;
331   else if ( send == GroupFace->PushButton1 )   myEditCurrentArgument = GroupFace->LineEdit1;
332
333   myEditCurrentArgument->setFocus();
334   
335   if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
336     globalSelection( GEOM_LINE );
337   else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
338         globalSelection( GEOM_PLANE );
339   else
340         globalSelection( GEOM_POINT );
341    
342   SelectionIntoArgument();
343 }
344
345
346 //=================================================================================
347 // function : LineEditReturnPressed()
348 // purpose  :
349 //=================================================================================
350 void BasicGUI_PlaneDlg::LineEditReturnPressed()
351 {
352   QLineEdit* send = (QLineEdit*)sender();
353   if ( send == GroupPntDir->LineEdit1 ||
354        send == GroupPntDir->LineEdit2 ||
355        send == Group3Pnts->LineEdit1 ||
356        send == Group3Pnts->LineEdit2 ||
357        send == Group3Pnts->LineEdit3 ||
358        send == GroupFace->LineEdit1 )
359   {
360     myEditCurrentArgument = send;
361     GEOMBase_Skeleton::LineEditReturnPressed();
362   }
363 }
364
365
366 //=================================================================================
367 // function : ActivateThisDialog()
368 // purpose  :
369 //=================================================================================
370 void BasicGUI_PlaneDlg::ActivateThisDialog()
371 {
372   GEOMBase_Skeleton::ActivateThisDialog();
373   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
374           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
375
376   // myGeometryGUI->SetState( 0 );
377
378   ConstructorsClicked( getConstructorId() );
379 }
380
381 //=================================================================================
382 // function : DeactivateActiveDialog()
383 // purpose  : public slot to deactivate if active
384 //=================================================================================
385 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
386 {
387   // myGeometryGUI->SetState( -1 );
388   GEOMBase_Skeleton::DeactivateActiveDialog();
389 }
390
391 //=================================================================================
392 // function : enterEvent()
393 // purpose  :
394 //=================================================================================
395 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
396 {
397   if ( !GroupConstructors->isEnabled() )
398     ActivateThisDialog();
399 }
400
401
402 //=================================================================================
403 // function : ValueChangedInSpinBox()
404 // purpose  :
405 //=================================================================================
406 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
407 {
408   displayPreview();
409 }
410
411 //=================================================================================
412 // function : getSize()
413 // purpose  :
414 //=================================================================================
415 double BasicGUI_PlaneDlg::getSize() const
416 {
417   switch ( getConstructorId() )
418   {
419   case 0 : return GroupPntDir->SpinBox_DX->GetValue();
420   case 1 : return Group3Pnts->SpinBox_DX->GetValue();
421   case 2 : return GroupFace->SpinBox_DX->GetValue();
422   }
423   return 0.;
424 }
425
426 //=================================================================================
427 // function : createOperation
428 // purpose  :
429 //=================================================================================
430 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
431 {
432   return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
433 }
434
435 //=================================================================================
436 // function : isEqual
437 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
438 //=================================================================================
439 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
440 {
441         return thePnt1->_is_equivalent( thePnt2 );
442 }
443
444 //=================================================================================
445 // function : isValid
446 // purpose  :
447 //=================================================================================
448 bool BasicGUI_PlaneDlg::isValid( QString& msg )
449 {
450         const int id = getConstructorId();
451         if ( getSize() <= 0 )
452         {
453                 msg = QString( "Please, enter size greater than 0." );
454                 return false;
455         }
456         if ( id == 0 )
457                 return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
458         else if ( id == 1 )
459                 return !CORBA::is_nil( myPoint1  ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
460                        !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
461         else if ( id == 2 )
462                 return !CORBA::is_nil( myFace );
463         return false;
464 }
465
466 //=================================================================================
467 // function : execute
468 // purpose  :
469 //=================================================================================
470 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
471 {
472   bool res = false;
473
474   GEOM::GEOM_Object_var anObj;
475
476   switch ( getConstructorId() )
477   {
478   case 0 :
479     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
480     res = true;
481     break;
482   case 1 :
483     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
484     res = true;
485     break;
486   case 2 :
487     anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
488     res = true;
489     break;
490   }
491
492   if ( !anObj->_is_nil() )
493     objects.push_back( anObj._retn() );
494
495   return res;
496 }
497
498 //=================================================================================
499 // function : closeEvent
500 // purpose  :
501 //=================================================================================
502 void BasicGUI_PlaneDlg::closeEvent( QCloseEvent* e )
503 {
504   // myGeometryGUI->SetState( -1 );
505   GEOMBase_Skeleton::closeEvent( e );
506 }
507