]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ExtrudedFeatureDlg.cxx
Salome HOME
Added 2 new operations:
[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   else if (send == myGroup->PushButton2) {
214     myEditCurrentArgument = myGroup->LineEdit2;
215
216     myGroup->PushButton1->setDown(false);
217     myGroup->LineEdit1->setEnabled(false);
218   }
219
220   // enable line edit
221   myEditCurrentArgument->setEnabled(true);
222   myEditCurrentArgument->setFocus();
223   // after setFocus(), because it will be setDown(false) when loses focus
224   send->setDown(true);
225 }
226
227
228 //=================================================================================
229 // function : SelectionIntoArgument()
230 // purpose  : Called when selection is changed or on dialog initialization or activation
231 //=================================================================================
232 void OperationGUI_ExtrudedFeatureDlg::SelectionIntoArgument()
233 {
234   myEditCurrentArgument->setText("");
235
236   QList<TopAbs_ShapeEnum> types;
237   types<<TopAbs_SHAPE;
238   
239   if (myEditCurrentArgument == myGroup->LineEdit1)
240   {
241     types.clear();
242     types<<TopAbs_COMPOUND<<TopAbs_SOLID;
243   }
244   if (myEditCurrentArgument == myGroup->LineEdit2)
245   {
246     types.clear();
247     types << TopAbs_EDGE << TopAbs_WIRE;
248   }
249
250   GEOM::GeomObjPtr aSelectedObject = getSelected( types );
251   TopoDS_Shape aShape;
252   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
253     QString aName = GEOMBase::GetName( aSelectedObject.get() );
254     myEditCurrentArgument->setText( aName );
255
256     // clear selection
257     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
258     myGeomGUI->getApp()->selectionMgr()->clearSelected();
259     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
260             this, SLOT(SelectionIntoArgument()));
261
262     if (myEditCurrentArgument == myGroup->LineEdit1) {
263       myObject1 = aSelectedObject;
264       if (!myObject2)
265         myGroup->PushButton2->click();
266     }
267     else if (myEditCurrentArgument == myGroup->LineEdit2) {
268       myObject2 = aSelectedObject;
269       if (!myObject1)
270         myGroup->PushButton1->click();
271     }
272     
273     displayPreview(true);
274   }
275   else {
276     if      (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
277     else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
278   }
279 }
280
281 //=================================================================================
282 // function : ActivateThisDialog()
283 // purpose  :
284 //=================================================================================
285 void OperationGUI_ExtrudedFeatureDlg::ActivateThisDialog()
286 {
287   GEOMBase_Skeleton::ActivateThisDialog();
288
289   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
290            this, SLOT( SelectionIntoArgument() ) );
291   processPreview();
292 }
293
294
295 //=================================================================================
296 // function : enterEvent()
297 // purpose  : when mouse enter onto the QWidget
298 //=================================================================================
299 void OperationGUI_ExtrudedFeatureDlg::enterEvent (QEvent*)
300 {
301   if (!mainFrame()->GroupConstructors->isEnabled())
302     ActivateThisDialog();
303 }
304
305 //=================================================================================
306 // function : ValueChangedInSpinBox()
307 // purpose  :
308 //=================================================================================
309 void OperationGUI_ExtrudedFeatureDlg::ValueChangedInSpinBox()
310 {
311   displayPreview(true);
312 }
313
314 //=================================================================================
315 // function : ButtonClicked(bool checked)
316 // purpose  :
317 //=================================================================================
318 void OperationGUI_ExtrudedFeatureDlg::ButtonClicked(bool checked)
319 {
320   myGroup->SpinBox_DY->setEnabled(checked);
321   displayPreview(true);
322 }
323
324 //=================================================================================
325 // function : createOperation
326 // purpose  :
327 //=================================================================================
328 GEOM::GEOM_IOperations_ptr OperationGUI_ExtrudedFeatureDlg::createOperation()
329 {
330   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
331 }
332
333 //=================================================================================
334 // function : isValid
335 // purpose  :
336 //=================================================================================
337 bool OperationGUI_ExtrudedFeatureDlg::isValid (QString&)
338 {
339   return myObject1 && myObject2; 
340 }
341
342 //=================================================================================
343 // function : execute
344 // purpose  :
345 //=================================================================================
346 bool OperationGUI_ExtrudedFeatureDlg::execute (ObjectList& objects)
347 {
348 //   GEOM::GEOM_Object_var anObj;
349
350   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
351   
352   double angle=0.0;
353   if (myGroup->PushButton3->isChecked())
354     angle=myGroup->SpinBox_DY->value();
355     
356   bool isProtrusion = (myOperation == OperationGUI::BOSS);  
357   
358   GEOM::GEOM_Object_var anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(), 
359                                                        myGroup->SpinBox_DX->value(),
360                                                        angle,
361                                                        isProtrusion);
362 //    switch (myOperation) 
363 //   {
364 //     case OperationGUI::BOSS:
365 //       anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),myGroup->SpinBox_DX->value(),angle, true);
366 //       break;
367 //     case OperationGUI::CUT:
368 //       anObj = anOper->MakeDraftPrism(myObject1.get(), myObject2.get(),myGroup->SpinBox_DX->value(),angle, false);
369 //       break;
370 //   }
371   if (!anObj->_is_nil())
372     objects.push_back(anObj._retn());
373
374   return true;
375 }
376
377
378
379
380   
381
382