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