Salome HOME
removed comment
[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   QString aTitle;
73   switch (myOperation) 
74   {
75     case OperationGUI::BOSS:
76       image0 = QPixmap(aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_BOSS")));
77       aTitle = tr("GEOM_EXTRUDED_BOSS");
78       break;
79     case OperationGUI::CUT:
80       image0 = QPixmap( aResMgr->loadPixmap("GEOM", tr("ICO_EXTRUDED_CUT")));
81       aTitle = tr("GEOM_EXTRUDED_CUT");
82       break;
83   }
84     
85   setWindowTitle(aTitle);
86   mainFrame()->GroupConstructors->setTitle(aTitle);
87   mainFrame()->RadioButton1->setIcon(image0);
88   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
89   mainFrame()->RadioButton2->close();
90   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
91   mainFrame()->RadioButton3->close();
92   
93   mainFrame()->RadioButton1->setChecked(true);
94   
95   myGroup = new DlgRef_2Sel2Spin1Push(centralWidget());
96   myGroup->PushButton1->setIcon(image1);
97   myGroup->PushButton2->setIcon(image1);
98   myGroup->PushButton3->setIcon(image2);
99   myGroup->LineEdit1->setReadOnly(true);
100   myGroup->LineEdit2->setReadOnly(true);
101   myGroup->TextLabel1->setText(tr("GEOM_INIT_SHAPE"));
102   myGroup->TextLabel2->setText(tr("GEOM_SKETCH"));
103   myGroup->TextLabel3->setText(tr("GEOM_HEIGHT"));
104  
105   
106   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
107   layout->setMargin(0); 
108   layout->setSpacing(6);
109   layout->addWidget(myGroup);
110
111   Init();
112    
113 }
114
115 //=================================================================================
116 // function : ~OperationGUI_ExtrudedFeatureDlg()
117 // purpose  : Destroys the object and frees any allocated resources
118 //=================================================================================
119 OperationGUI_ExtrudedFeatureDlg::~OperationGUI_ExtrudedFeatureDlg()
120 {
121 }
122
123 //=================================================================================
124 // function : Init()
125 // purpose  :
126 //=================================================================================
127 void OperationGUI_ExtrudedFeatureDlg::Init()
128 {
129   // init variables
130   myEditCurrentArgument = myGroup->LineEdit1;
131   
132   // Get setting of step value from file configuration
133   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
134   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
135   
136   initSpinBox(myGroup->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
137   initSpinBox(myGroup->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
138
139   myGroup->LineEdit1->setText("");
140   myGroup->LineEdit2->setText("");
141   myGroup->SpinBox_DX->setValue(10.0);
142   myGroup->SpinBox_DY->setValue(10.0);
143   myGroup->SpinBox_DY->setEnabled(false);
144   myObject1.nullify();
145   myObject2.nullify();
146   
147   // signals and slots connections
148   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
150
151   connect(myGroup->PushButton1, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
152   connect(myGroup->PushButton2, SIGNAL(clicked()),     this, SLOT(SetEditCurrentArgument()));
153   connect(myGroup->PushButton3, SIGNAL(clicked(bool)), this, SLOT(ButtonClicked(bool)));
154   connect(myGroup->SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155   connect(myGroup->SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156   
157
158   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
159            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
160   
161   initName(mainFrame()->GroupConstructors->title());
162   
163   mainFrame()->RadioButton1->setFocus();
164   
165   globalSelection(GEOM_ALLSHAPES); //TODO à changer
166   
167   myGroup->PushButton1->click();
168   SelectionIntoArgument();
169   
170   resize(minimumSizeHint());
171 }
172
173 //=================================================================================
174 // function : ClickOnOk()
175 // purpose  :
176 //=================================================================================
177 void OperationGUI_ExtrudedFeatureDlg::ClickOnOk()
178 {
179   setIsApplyAndClose( true );
180   if (ClickOnApply())
181     ClickOnCancel();
182 }
183
184 //=================================================================================
185 // function : ClickOnApply()
186 // purpose  :
187 //=================================================================================
188 bool OperationGUI_ExtrudedFeatureDlg::ClickOnApply()
189 {
190   if (!onAccept())
191     return false;
192
193   initName();
194   // activate selection and connect selection manager
195   myGroup->PushButton1->click();
196   return true;
197 }
198
199 //=================================================================================
200 // function : SetEditCurrentArgument()
201 // purpose  :
202 //=================================================================================
203 void OperationGUI_ExtrudedFeatureDlg::SetEditCurrentArgument()
204 {
205   QPushButton* send = (QPushButton*)sender();
206   
207   if (send == myGroup->PushButton1) {
208     myEditCurrentArgument = myGroup->LineEdit1;
209
210     myGroup->PushButton2->setDown(false);
211     myGroup->LineEdit2->setEnabled(false);
212     
213     globalSelection();   // close local selection
214   }
215   else if (send == myGroup->PushButton2) {
216     myEditCurrentArgument = myGroup->LineEdit2;
217
218     myGroup->PushButton1->setDown(false);
219     myGroup->LineEdit1->setEnabled(false);
220     
221     globalSelection(); // close local selection to clear it
222 //     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
223     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
224   }
225   
226   // enable line edit
227   myEditCurrentArgument->setEnabled(true);
228   myEditCurrentArgument->setFocus();
229   // after setFocus(), because it will be setDown(false) when loses focus
230   send->setDown(true);
231 }
232
233
234 //=================================================================================
235 // function : SelectionIntoArgument()
236 // purpose  : Called when selection is changed or on dialog initialization or activation
237 //=================================================================================
238 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
239 {
240   myEditCurrentArgument->setText("");
241
242   QList<TopAbs_ShapeEnum> types;
243   types<<TopAbs_SHAPE;
244   
245   if (myEditCurrentArgument == myGroup->LineEdit1)
246   {
247     types.clear();
248     types<<TopAbs_COMPOUND<<TopAbs_SOLID;
249   }
250   if (myEditCurrentArgument == myGroup->LineEdit2)
251   {
252     types.clear();
253     types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE;
254   }
255
256   GEOM::GeomObjPtr aSelectedObject = getSelected( types );
257   TopoDS_Shape aShape;
258   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
259     QString aName = GEOMBase::GetName( aSelectedObject.get() );
260     myEditCurrentArgument->setText( aName );
261
262     // clear selection
263     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
264     myGeomGUI->getApp()->selectionMgr()->clearSelected();
265     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
266             this, SLOT(SelectionIntoArgument()));
267
268     if (myEditCurrentArgument == myGroup->LineEdit1) {
269       myObject1 = aSelectedObject;
270       if (!myObject2)
271         myGroup->PushButton2->click();
272     }
273     else if (myEditCurrentArgument == myGroup->LineEdit2) {
274       myObject2 = aSelectedObject;
275       if (!myObject1)
276         myGroup->PushButton1->click();
277     }
278     
279     displayPreview(true);
280   }
281   else {
282     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
283     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
284   }
285 }
286
287 //=================================================================================
288 // function : ActivateThisDialog()
289 // purpose  :
290 //=================================================================================
291 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
292 {
293   GEOMBase_Skeleton::ActivateThisDialog();
294
295   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
296            this, SLOT( SelectionIntoArgument() ) );
297   processPreview();
298 }
299
300
301 //=================================================================================
302 // function : enterEvent()
303 // purpose  : when mouse enter onto the QWidget
304 //=================================================================================
305 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
306 {
307   if (!mainFrame()->GroupConstructors->isEnabled())
308     ActivateThisDialog();
309 }
310
311 //=================================================================================
312 // function : ValueChangedInSpinBox()
313 // purpose  :
314 //=================================================================================
315 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
316 {
317   displayPreview(true);
318 }
319
320 //=================================================================================
321 // function : ButtonClicked(bool checked)
322 // purpose  :
323 //=================================================================================
324 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
325 {
326   myGroup->SpinBox_DY->setEnabled(checked);
327   displayPreview(true);
328 }
329
330 //=================================================================================
331 // function : createOperation
332 // purpose  :
333 //=================================================================================
334 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
335 {
336   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
337 }
338
339 //=================================================================================
340 // function : isValid
341 // purpose  :
342 //=================================================================================
343 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
344 {
345   return myObject1 && myObject2; 
346 }
347
348 //=================================================================================
349 // function : execute
350 // purpose  :
351 //=================================================================================
352 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
353 {
354   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
355   
356   double angle=0.0;
357   if (myGroup->PushButton3->isChecked())
358     angle=myGroup->SpinBox_DY->value();
359     
360   bool isProtrusion = (myOperation == OperationGUI::BOSS);  
361   
362   // Hide the initial shape in order to see the modifications on the preview
363   getDisplayer()->Erase(myObject1.get(),false,false);   
364   
365   GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(), 
366                                                        myGroup->SpinBox_DX->value(),
367                                                        angle,
368                                                        isProtrusion);
369   if (!anObj->_is_nil())
370     objects.push_back(anObj._retn());
371
372   return true;
373 }
374
375 //=================================================================================
376 // function : addSubshapeToStudy
377 // purpose  : virtual method to add new SubObjects if local selection
378 //=================================================================================
379 void OperationGUI_ExtrudedFeatureDlg::addSubshapesToStudy()
380 {
381   GEOMBase::PublishSubObject( myObject2.get() );
382 }
383
384
385
386
387   
388
389