Salome HOME
Fix for bug PAL12858(EDF210 GEOM Preferences menu of GEOM: color of the wireframe?)
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PrismDlg.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   : GenerationGUI_PrismDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GenerationGUI_PrismDlg.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 <BRepPrimAPI_MakePrism.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <gp_Lin.hxx>
39 #include "GEOMImpl_Types.hxx"
40
41 #include <qlabel.h>
42 #include <qcheckbox.h>
43
44 #include "utilities.h"
45
46 //=================================================================================
47 // class    : GenerationGUI_PrismDlg()
48 // purpose  : Constructs a GenerationGUI_PrismDlg 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 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
54                                                const char* name, bool modal, WFlags fl)
55   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 {
58   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PRISM")));
59   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PRISM_2P")));
61
62   setCaption(tr("GEOM_EXTRUSION_TITLE"));
63
64   /***************************************************************/
65   GroupConstructors->setTitle(tr("GEOM_EXTRUSION"));
66   RadioButton1->setPixmap(image0);
67   RadioButton2->setPixmap(image2);
68   //RadioButton2->close(TRUE);
69   RadioButton3->close(TRUE);
70
71   GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
72   GroupPoints->CheckButton1->hide();
73   GroupPoints->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV"));
74   GroupPoints->TextLabel1->setText(tr("GEOM_BASE"));
75   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
76   GroupPoints->TextLabel3->setText(tr("GEOM_HEIGHT"));
77   GroupPoints->PushButton1->setPixmap(image1);
78   GroupPoints->PushButton2->setPixmap(image1);
79   GroupPoints->LineEdit1->setReadOnly( true );
80   GroupPoints->LineEdit2->setReadOnly( true );
81   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
82
83   GroupPoints2 = new DlgRef_3Sel_QTD(this, "GroupPoints2");
84   GroupPoints2->GroupBox1->setTitle(tr("GEOM_EXTRUSION_BSV_2P"));
85   GroupPoints2->TextLabel1->setText(tr("GEOM_BASE"));
86   GroupPoints2->TextLabel2->setText(tr("GEOM_POINT_I").arg("1"));
87   GroupPoints2->TextLabel3->setText(tr("GEOM_POINT_I").arg("2"));
88   GroupPoints2->PushButton1->setPixmap(image1);
89   GroupPoints2->PushButton2->setPixmap(image1);
90   GroupPoints2->PushButton3->setPixmap(image1);
91
92   Layout1->addWidget(GroupPoints, 2, 0);
93   Layout1->addWidget(GroupPoints2, 2, 0);
94   /***************************************************************/
95
96   setHelpFileName("extrusion.htm");
97
98   /* Initialisations */
99   Init();
100 }
101
102
103 //=================================================================================
104 // function : ~GenerationGUI_PrismDlg()
105 // purpose  : Destroys the object and frees any allocated resources
106 //=================================================================================
107 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
108 {  
109   /* no need to delete child widgets, Qt does it all for us */
110 }
111
112
113 //=================================================================================
114 // function : Init()
115 // purpose  :
116 //=================================================================================
117 void GenerationGUI_PrismDlg::Init()
118 {
119   /* init variables */
120   myEditCurrentArgument = GroupPoints->LineEdit1;
121   GroupPoints->LineEdit1->setReadOnly( true );
122   GroupPoints->LineEdit2->setReadOnly( true );
123
124   GroupPoints2->LineEdit1->setReadOnly( true );
125   GroupPoints2->LineEdit2->setReadOnly( true );
126   GroupPoints2->LineEdit3->setReadOnly( true );
127
128   //myOkBase = myOkVec = false;
129   myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
130   
131   /* Get setting of step value from file configuration */
132   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
133   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
134
135   /* min, max, step and decimals for spin boxes & initial values */
136   GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
137   GroupPoints->SpinBox_DX->SetValue(100.0);
138
139   /* signals and slots connections */
140   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142
143   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144
145   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147
148   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150
151   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
153
154   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)),      this, SLOT(onReverse()));
155
156
157   connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158   connect(GroupPoints2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159   connect(GroupPoints2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160
161   connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162   connect(GroupPoints2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163   connect(GroupPoints2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164
165
166   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
167           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
168
169   initName(tr("GEOM_EXTRUSION"));
170
171   globalSelection( GEOM_ALLSHAPES );
172   ConstructorsClicked(0);
173 }
174
175
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose  : Radio button management
179 //=================================================================================
180 void GenerationGUI_PrismDlg::ConstructorsClicked(int constructorId)
181 {
182   disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
183   
184   switch (constructorId)
185     {
186     case 0:
187       {
188         globalSelection( GEOM_POINT );
189
190         GroupPoints2->hide();
191         resize(0, 0);
192         GroupPoints->show();
193         
194         //GroupPoints->LineEdit1->setFocus();
195         //myEditCurrentArgument = GroupPoints->LineEdit1;
196         //displayPreview();
197
198         myEditCurrentArgument = GroupPoints->LineEdit1;
199         GroupPoints->LineEdit1->setText("");
200         GroupPoints->LineEdit2->setText("");
201         GroupPoints2->LineEdit1->setText("");
202         GroupPoints2->LineEdit2->setText("");
203         GroupPoints2->LineEdit3->setText("");
204         myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
205         myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
206
207         break;
208       }
209     case 1:
210       {
211         GroupPoints->hide();
212         resize(0, 0);
213         GroupPoints2->show();
214         
215         myEditCurrentArgument = GroupPoints2->LineEdit1;
216         GroupPoints2->LineEdit1->setText("");
217         GroupPoints2->LineEdit2->setText("");
218         GroupPoints2->LineEdit3->setText("");
219         myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
220         myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
221         GroupPoints->LineEdit1->setText("");
222         GroupPoints->LineEdit2->setText("");
223         
224         break;
225       }
226     }
227   displayPreview();
228 }
229
230
231 //=================================================================================
232 // function : ClickOnOk()
233 // purpose  :
234 //=================================================================================
235 void GenerationGUI_PrismDlg::ClickOnOk()
236 {
237   if ( ClickOnApply() )
238     ClickOnCancel();
239 }
240
241
242 //=================================================================================
243 // function : ClickOnApply()
244 // purpose  :
245 //=================================================================================
246 bool GenerationGUI_PrismDlg::ClickOnApply()
247 {
248   if ( !onAccept() )
249     return false;
250
251   initName();
252   return true;
253 }
254
255
256 //=================================================================================
257 // function : SelectionIntoArgument()
258 // purpose  : Called when selection has changed
259 //=================================================================================
260 void GenerationGUI_PrismDlg::SelectionIntoArgument()
261 {
262   erasePreview();
263   myEditCurrentArgument->setText("");
264
265   if ( getConstructorId()==0 ) {
266
267     if (IObjectCount() != 1) {
268       if (myEditCurrentArgument == GroupPoints->LineEdit1)
269         myOkBase = false;
270       else if (myEditCurrentArgument == GroupPoints->LineEdit2)
271         myOkVec = false;
272       return;
273     }
274
275     // nbSel == 1
276     Standard_Boolean testResult = Standard_False;
277     GEOM::GEOM_Object_ptr aSelectedObject =
278       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
279
280     if (!testResult)
281       return;
282
283     if (myEditCurrentArgument == GroupPoints->LineEdit1) {
284       myBase = aSelectedObject;
285       myOkBase = true;
286     }
287     else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
288       myVec = aSelectedObject;
289       myOkVec = true;
290     }
291     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
292
293     displayPreview();
294   }
295
296   else { // getConstructorId()==1 - extrusion using 2 points
297
298     if (IObjectCount() != 1) {
299       if (myEditCurrentArgument == GroupPoints2->LineEdit1)
300         myOkBase = false;
301       else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
302         myPoint1 = GEOM::GEOM_Object::_nil();
303         myOkPnt1 = false;
304       }
305       else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
306         myPoint2 = GEOM::GEOM_Object::_nil();
307         myOkPnt2 = false;
308       }
309       return;
310     }
311
312     // nbSel == 1
313     Standard_Boolean testResult = Standard_False;
314     GEOM::GEOM_Object_var aSelectedObject =
315       GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
316
317     if (!testResult || CORBA::is_nil( aSelectedObject ))
318       return;
319
320     if (myEditCurrentArgument == GroupPoints2->LineEdit1) {
321       myBase = aSelectedObject;
322       myOkBase = true;
323     }
324     else if (myEditCurrentArgument == GroupPoints2->LineEdit2) {
325       myPoint1 = aSelectedObject;
326       myOkPnt1 = true;
327     }
328     else if (myEditCurrentArgument == GroupPoints2->LineEdit3) {
329       myPoint2 = aSelectedObject;
330       myOkPnt2 = true;
331     }
332
333     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
334
335     displayPreview();
336   }
337 }
338
339
340 //=================================================================================
341 // function : SetEditCurrentArgument()
342 // purpose  :
343 //=================================================================================
344 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
345 {
346   QPushButton* send = (QPushButton*)sender();
347   globalSelection( GEOM_ALLSHAPES );
348
349   if(send == GroupPoints->PushButton1) {
350     GroupPoints->LineEdit1->setFocus();
351     myEditCurrentArgument = GroupPoints->LineEdit1;
352   }
353   else if(send == GroupPoints->PushButton2) {
354     GroupPoints->LineEdit2->setFocus();
355     myEditCurrentArgument = GroupPoints->LineEdit2;
356     globalSelection( GEOM_LINE );
357   }
358   else if(send == GroupPoints2->PushButton1) {
359     GroupPoints2->LineEdit1->setFocus();
360     myEditCurrentArgument = GroupPoints2->LineEdit1;
361   }
362   else if(send == GroupPoints2->PushButton2) {
363     GroupPoints2->LineEdit2->setFocus();
364     myEditCurrentArgument = GroupPoints2->LineEdit2;
365     globalSelection( GEOM_POINT );
366   }
367   else if(send == GroupPoints2->PushButton3) {
368     GroupPoints2->LineEdit3->setFocus();
369     myEditCurrentArgument = GroupPoints2->LineEdit3;
370     globalSelection( GEOM_POINT );
371   }
372   SelectionIntoArgument();
373 }
374
375
376 //=================================================================================
377 // function : LineEditReturnPressed()
378 // purpose  :
379 //=================================================================================
380 void GenerationGUI_PrismDlg::LineEditReturnPressed()
381 {
382   QLineEdit* send = (QLineEdit*)sender();
383   if(send == GroupPoints->LineEdit1 ||
384      send == GroupPoints->LineEdit2 ||
385      send == GroupPoints2->LineEdit1 ||
386      send == GroupPoints2->LineEdit2 ||
387      send == GroupPoints2->LineEdit3 )
388     {
389       myEditCurrentArgument = send;
390       GEOMBase_Skeleton::LineEditReturnPressed();
391     }
392 }
393
394 //=================================================================================
395 // function : enterEvent()
396 // purpose  : when mouse enter onto the QWidget
397 //=================================================================================
398 void GenerationGUI_PrismDlg::enterEvent(QEvent * e)
399 {
400   if ( !GroupConstructors->isEnabled() )
401     ActivateThisDialog();
402 }
403
404
405 //=================================================================================
406 // function : ActivateThisDialog()
407 // purpose  :
408 //=================================================================================
409 void GenerationGUI_PrismDlg::ActivateThisDialog()
410 {
411   GEOMBase_Skeleton::ActivateThisDialog();
412   globalSelection( GEOM_ALLSHAPES );
413   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
414           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
415   //GroupPoints->LineEdit1->setFocus();
416   //myEditCurrentArgument = GroupPoints->LineEdit1;
417   //displayPreview();
418   ConstructorsClicked( getConstructorId() );
419 }
420
421
422 //=================================================================================
423 // function : ValueChangedInSpinBox()
424 // purpose  :
425 //=================================================================================
426 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
427 {
428   displayPreview();
429 }
430
431
432 //=================================================================================
433 // function : getHeight()
434 // purpose  :
435 //=================================================================================
436 double GenerationGUI_PrismDlg::getHeight() const
437 {
438   return GroupPoints->SpinBox_DX->GetValue();
439 }
440
441 //=================================================================================
442 // function : createOperation
443 // purpose  :
444 //=================================================================================
445 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
446 {
447   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
448 }
449
450 //=================================================================================
451 // function : isValid
452 // purpose  :
453 //=================================================================================
454 bool GenerationGUI_PrismDlg::isValid( QString& )
455 {
456   return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
457 }
458
459 //=================================================================================
460 // function : execute
461 // purpose  :
462 //=================================================================================
463 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
464 {
465   GEOM::GEOM_Object_var anObj;
466
467   switch ( getConstructorId() ) 
468   {
469   case 0 :
470     { 
471       anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
472         MakePrismVecH(myBase, myVec, getHeight());
473       break;
474     }
475   case 1 :
476     {
477       anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
478         MakePrismTwoPnt(myBase, myPoint1, myPoint2);
479       break;
480     }
481   }
482   if ( !anObj->_is_nil() )
483     objects.push_back( anObj._retn() );
484
485   return true;
486 }
487
488
489 //=================================================================================
490 // function :  onReverse()
491 // purpose  :
492 //=================================================================================
493 void GenerationGUI_PrismDlg::onReverse()
494 {
495   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
496   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
497 }