Salome HOME
Added a method to disable waiting cursor in the preview operation
[modules/geom.git] / src / OperationGUI / OperationGUI_ExtrudedFeatureDlg.cxx
1 // Copyright (C) 2007-2011  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
23 //  GEOM GEOMGUI : GUI for Geometry component
24 //  File   : OperationGUI_ExtrudedFeatureDlg.cxx
25 //  Author : Renaud NEDELEC, Open CASCADE S.A.S.
26
27 #include "OperationGUI.h"
28 #include "OperationGUI_ExtrudedFeatureDlg.h"
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <GeometryGUI.h>
36 #include <GEOMBase.h>
37
38 #include <DlgRef.h>
39 #include <GEOM_Object.hxx>
40
41 // OCCT Includes
42 // #include <TopoDS_Shape.hxx>
43 // #include <TopoDS_Edge.hxx>
44 // #include <TopoDS.hxx>
45 // #include <TopExp.hxx>
46 // #include <TColStd_IndexedMapOfInteger.hxx>
47 // #include <TopTools_IndexedMapOfShape.hxx>
48 // #include <Precision.hxx>
49 #include <TColStd_HSequenceOfTransient.hxx>
50
51 #include <GEOMImpl_Types.hxx>
52
53 //=================================================================================
54 // class    : OperationGUI_ExtrudedFeatureDlg()
55 // purpose  : Constructs a OperationGUI_ExtrudedCutDlg which is a child of 'parent',
56 //            with the name 'name' and widget flags set to 'f'.
57 //            The dialog will by default be modeless, unless you set 'modal' to
58 //            TRUE to construct a modal dialog.
59 //=================================================================================
60
61 OperationGUI_ExtrudedFeatureDlg::OperationGUI_ExtrudedFeatureDlg(const int theOperation,
62                                                                  GeometryGUI* theGeometryGUI,
63                                                                  QWidget* parent,bool modal, 
64                                                                  Qt::WindowFlags fl)
65   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
66     myOperation(theOperation)
67 {
68   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69   QPixmap image0;
70   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
71   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICO_DRAFT")));
72   QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHANGE_DIRECTION")));
73   QString aTitle;
74   switch (myOperation) 
75   {
76     case OperationGUI::BOSS:
77       image0 = QPixmap(aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_BOSS")));
78       aTitle = tr("GEOM_EXTRUDED_BOSS");
79       setHelpFileName("extruded_boss_operation_page.html");
80       break;
81     case OperationGUI::CUT:
82       image0 = QPixmap( aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_CUT")));
83       aTitle = tr("GEOM_EXTRUDED_CUT");
84       setHelpFileName("extruded_cut_operation_page.html");
85       break;
86   }
87     
88   setWindowTitle(aTitle);
89   mainFrame()->GroupConstructors->setTitle(aTitle);
90   mainFrame()->RadioButton1->setIcon(image0);
91   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
92   mainFrame()->RadioButton2->close();
93   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
94   mainFrame()->RadioButton3->close();
95   
96   mainFrame()->RadioButton1->setChecked(true);
97   
98   myGroup = new DlgRef_2Sel2Spin2Push(centralWidget());
99   
100   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
101   
102   myGroup->PushButton1->setIcon(image1);
103   myGroup->PushButton2->setIcon(image1);
104   myGroup->PushButton3->setIcon(image2);
105   myGroup->PushButton4->setIcon(image3);
106   myGroup->LineEdit1->setReadOnly(true);
107   myGroup->LineEdit2->setReadOnly(true);
108   myGroup->TextLabel1->setText(tr("GEOM_INIT_SHAPE"));
109   myGroup->TextLabel2->setText(tr("GEOM_PROFILE"));
110   myGroup->TextLabel3->setText(tr("GEOM_HEIGHT"));
111   myGroup->TextLabel4->setText(tr("GEOM_DRAFT_ANGLE"));
112   myGroup->TextLabel5->setText(tr("GEOM_CHANGE_DIRECTION"));
113  
114   
115   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
116   layout->setMargin(0); 
117   layout->setSpacing(6);
118   layout->addWidget(myGroup);
119
120   Init();
121    
122 }
123
124 //=================================================================================
125 // function : ~OperationGUI_ExtrudedFeatureDlg()
126 // purpose  : Destroys the object and frees any allocated resources
127 //=================================================================================
128 OperationGUI_ExtrudedFeatureDlg::~OperationGUI_ExtrudedFeatureDlg()
129 {
130 }
131
132 //=================================================================================
133 // function : Init()
134 // purpose  :
135 //=================================================================================
136 void OperationGUI_ExtrudedFeatureDlg::Init()
137 {
138   // init variables
139   myEditCurrentArgument = myGroup->LineEdit1;
140   
141   // Get setting of step value from file configuration
142   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
143   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
144   
145   initSpinBox(myGroup->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
146   initSpinBox(myGroup->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
147
148   myGroup->LineEdit1->setText("");
149   myGroup->LineEdit2->setText("");
150   myGroup->SpinBox_DX->setValue(10.0);
151   myGroup->SpinBox_DY->setValue(10.0);
152   myGroup->SpinBox_DY->setEnabled(false);
153   myObject1.nullify();
154   myObject2.nullify();
155   
156   // signals and slots connections
157   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
158   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
159
160   connect(myGroup->PushButton1, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
161   connect(myGroup->PushButton2, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
162   connect(myGroup->PushButton3, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
163   connect(myGroup->PushButton4, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
164   connect(myGroup->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
165   connect(myGroup->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
166   
167
168   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
169            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
170   
171   initName(mainFrame()->GroupConstructors->title());
172   
173   mainFrame()->RadioButton1->setFocus();
174   
175   globalSelection(GEOM_ALLSHAPES); //TODO Ã  changer
176   
177   myGroup->PushButton1->click();
178   SelectionIntoArgument();
179   
180   resize(minimumSizeHint());
181 }
182
183 //=================================================================================
184 // function : ClickOnOk()
185 // purpose  :
186 //=================================================================================
187 void OperationGUI_ExtrudedFeatureDlg::ClickOnOk()
188 {
189   setIsApplyAndClose( true );
190   if (ClickOnApply())
191     ClickOnCancel();
192 }
193
194 //=================================================================================
195 // function : ClickOnApply()
196 // purpose  :
197 //=================================================================================
198 bool OperationGUI_ExtrudedFeatureDlg::ClickOnApply()
199 {
200   if (!onAccept())
201     return false;
202
203   initName();
204   // activate selection and connect selection manager
205   myGroup->PushButton1->click();
206   return true;
207 }
208
209 //=================================================================================
210 // function : SetEditCurrentArgument()
211 // purpose  :
212 //=================================================================================
213 void OperationGUI_ExtrudedFeatureDlg::SetEditCurrentArgument()
214 {
215   QPushButton* send = (QPushButton*)sender();
216   
217   if (send == myGroup->PushButton1) {
218     myEditCurrentArgument = myGroup->LineEdit1;
219
220     myGroup->PushButton2->setDown(false);
221     myGroup->LineEdit2->setEnabled(false);
222    
223 //     globalSelection();   // close local selection
224   }
225   else if (send == myGroup->PushButton2) {
226     myEditCurrentArgument = myGroup->LineEdit2;
227
228     myGroup->PushButton1->setDown(false);
229     myGroup->LineEdit1->setEnabled(false);
230     
231 //     globalSelection(); // close local selection to clear it
232     
233 // //     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
234 //     if (myObject1)
235 //     {
236 //       localSelection( myObject1.get(), TopAbs_FACE );
237 // //       localSelection( myObject1.get(), TopAbs_EDGE );
238 //     }
239 //    /* localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE ); */ 
240   }
241   
242   // enable line edit
243   myEditCurrentArgument->setEnabled(true);
244   myEditCurrentArgument->setFocus();
245   // after setFocus(), because it will be setDown(false) when loses focus
246   send->setDown(true);
247 }
248
249
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose  : Called when selection is changed or on dialog initialization or activation
253 //=================================================================================
254 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
255 {
256   myEditCurrentArgument->setText("");
257
258   QList<TopAbs_ShapeEnum> types;
259   types<<TopAbs_SHAPE;
260   
261   if (myEditCurrentArgument == myGroup->LineEdit1)
262   {
263     types.clear();
264     types<<TopAbs_COMPOUND<<TopAbs_SOLID;
265   }
266   if (myEditCurrentArgument == myGroup->LineEdit2)
267   {
268     types.clear();
269     types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE;
270   }
271
272   GEOM::GeomObjPtr aSelectedObject = getSelected( types );
273   TopoDS_Shape aShape;
274   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
275     QString aName = GEOMBase::GetName( aSelectedObject.get() );
276     myEditCurrentArgument->setText( aName );
277
278     // clear selection
279     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
280     myGeomGUI->getApp()->selectionMgr()->clearSelected();
281     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
282             this, SLOT(SelectionIntoArgument()));
283
284     if (myEditCurrentArgument == myGroup->LineEdit1) {
285       myObject1 = aSelectedObject;
286       if (!myObject2)
287         myGroup->PushButton2->click();
288     }
289     else if (myEditCurrentArgument == myGroup->LineEdit2) {
290       myObject2 = aSelectedObject;
291       if (!myObject1)
292         myGroup->PushButton1->click();
293     }
294     
295     displayPreview(true);
296   }
297   else {
298     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
299     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
300   }
301 }
302
303 //=================================================================================
304 // function : ActivateThisDialog()
305 // purpose  :
306 //=================================================================================
307 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
308 {
309   GEOMBase_Skeleton::ActivateThisDialog();
310
311   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
312            this, SLOT( SelectionIntoArgument() ) );
313   processPreview();
314 }
315
316
317 //=================================================================================
318 // function : enterEvent()
319 // purpose  : when mouse enter onto the QWidget
320 //=================================================================================
321 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
322 {
323   if (!mainFrame()->GroupConstructors->isEnabled())
324     ActivateThisDialog();
325 }
326
327 //=================================================================================
328 // function : ValueChangedInSpinBox()
329 // purpose  :
330 //=================================================================================
331 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
332 {
333   displayPreview(true);
334 }
335
336 //=================================================================================
337 // function : ButtonClicked(bool checked)
338 // purpose  :
339 //=================================================================================
340 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
341 {
342   QPushButton* send = (QPushButton*)sender();
343   if (send == myGroup->PushButton3)
344     myGroup->SpinBox_DY->setEnabled(checked);
345  
346   displayPreview(true);
347 }
348
349 //=================================================================================
350 // function : createOperation
351 // purpose  :
352 //=================================================================================
353 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
354 {
355   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
356 }
357
358 //=================================================================================
359 // function : isValid
360 // purpose  :
361 //=================================================================================
362 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
363 {
364   return myObject1 && myObject2; 
365 }
366
367 //=================================================================================
368 // function : execute
369 // purpose  :
370 //=================================================================================
371 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
372 {
373   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
374   
375   double angle=0.0;
376   double aHeight = myGroup->SpinBox_DX->value();
377   
378   if (myGroup->PushButton3->isChecked())
379     angle=myGroup->SpinBox_DY->value();
380   
381   if (myGroup->PushButton4->isChecked())
382   {
383     aHeight = -aHeight;
384     angle   = -angle;
385   }
386     
387   bool isProtrusion = (myOperation == OperationGUI::BOSS);  
388   
389   // Hide the initial shape in order to see the modifications on the preview
390   erase(myObject1.get(),false); 
391   
392   GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(), 
393                                                        aHeight,
394                                                        angle,
395                                                        isProtrusion);
396   if (!anObj->_is_nil())
397     objects.push_back(anObj._retn());
398
399   return true;
400 }
401
402 // //=================================================================================
403 // // function : addSubshapeToStudy
404 // // purpose  : virtual method to add new SubObjects if local selection
405 // //=================================================================================
406 // void OperationGUI_ExtrudedFeatureDlg::addSubshapesToStudy()
407 // {
408 //   GEOMBase::PublishSubObject( myObject2.get() );
409 // }
410
411
412
413
414   
415
416