]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_RevolDlg.cxx
Salome HOME
Correct make file for shared modules script
[modules/geom.git] / src / GenerationGUI / GenerationGUI_RevolDlg.cxx
1 //  Copyright (C) 2007-2008  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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : GenerationGUI_RevolDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "GenerationGUI_RevolDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41
42 #include <gp_Lin.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepPrimAPI_MakeRevol.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include "GEOMImpl_Types.hxx"
47
48 #include <qlabel.h>
49 #include <qcheckbox.h>
50
51 #include "utilities.h"
52
53 //=================================================================================
54 // class    : GenerationGUI_RevolDlg()
55 // purpose  : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the 
56 //            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 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
61                                                const char* name, bool modal, WFlags fl)
62   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
63                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 {
65   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REVOL")));
66   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67
68   setCaption(tr("GEOM_REVOLUTION_TITLE"));
69
70   /***************************************************************/
71   GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
72   RadioButton1->setPixmap(image0);
73   RadioButton2->close(TRUE);
74   RadioButton3->close(TRUE);
75   myBothway = false;
76
77   GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
78   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
80   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
81   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
82   GroupPoints->PushButton1->setPixmap(image1);
83   GroupPoints->PushButton2->setPixmap(image1);
84   GroupPoints->LineEdit1->setReadOnly( true );
85   GroupPoints->LineEdit2->setReadOnly( true );
86   GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
87   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
88
89   Layout1->addWidget(GroupPoints, 2, 0);
90   /***************************************************************/
91
92   setHelpFileName("create_revolution_page.html");
93
94   /* Initialisations */
95   Init();
96 }
97
98
99 //=================================================================================
100 // function : ~GenerationGUI_RevolDlg()
101 // purpose  : Destroys the object and frees any allocated resources
102 //=================================================================================
103 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
104 {
105   // no need to delete child widgets, Qt does it all for us
106 }
107
108
109 //=================================================================================
110 // function : Init()
111 // purpose  :
112 //=================================================================================
113 void GenerationGUI_RevolDlg::Init()
114 {
115   /* init variables */
116   myEditCurrentArgument = GroupPoints->LineEdit1;
117   GroupPoints->LineEdit1->setReadOnly( true );
118   GroupPoints->LineEdit2->setReadOnly( true );
119
120   myOkBase = myOkAxis = false;
121
122   double SpecificStep = 5;
123   /* min, max, step and decimals for spin boxes & initial values */
124   //GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX,
125   //                                               SpecificStep, DBL_DIGITS_DISPLAY);
126   // 05.06.2008 skl for IPAL12958
127   GroupPoints->SpinBox_DX->RangeStepAndValidator(-360.0, 360.0, SpecificStep, DBL_DIGITS_DISPLAY);
128   GroupPoints->SpinBox_DX->SetValue(45.0);
129
130   /* signals and slots connections */
131   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133
134   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136
137   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139
140   connect(GroupPoints->SpinBox_DX,   SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
141   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)),        this, SLOT(onBothway()));
142   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)),        this, SLOT(onReverse()));
143
144   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
145
146   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
147           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
148
149   initName(tr("GEOM_REVOLUTION"));
150
151   globalSelection( GEOM_ALLSHAPES );
152 }
153
154
155 //=================================================================================
156 // function : ClickOnOk()
157 // purpose  :
158 //=================================================================================
159 void GenerationGUI_RevolDlg::ClickOnOk()
160 {
161   if ( ClickOnApply() )
162     ClickOnCancel();
163 }
164
165
166 //=================================================================================
167 // function : ClickOnApply()
168 // purpose  :
169 //=================================================================================
170 bool GenerationGUI_RevolDlg::ClickOnApply()
171 {
172   if ( !onAccept() )
173     return false;
174
175   initName();
176   return true;
177 }
178
179 //=======================================================================
180 //function : isAcceptableBase
181 //purpose  : return true if theBase can be used as algo argument
182 //=======================================================================
183
184 static bool isAcceptableBase(const TopoDS_Shape& theBase)
185 {
186   switch ( theBase.ShapeType() ) {
187   case TopAbs_VERTEX:
188   case TopAbs_EDGE:
189   case TopAbs_WIRE:
190   case TopAbs_FACE:
191   case TopAbs_SHELL:
192     return true;
193   case TopAbs_SOLID:
194   case TopAbs_COMPSOLID:
195     return false;
196   case TopAbs_COMPOUND: {
197     TopExp_Explorer exp( theBase, TopAbs_SOLID);
198     return !exp.More();
199   }
200   default:
201     return false;
202   }
203   return false;
204 }
205
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose  : Called when selection as changed or other case
209 //=================================================================================
210 void GenerationGUI_RevolDlg::SelectionIntoArgument()
211 {
212   erasePreview();
213   myEditCurrentArgument->setText("");
214   
215   if(IObjectCount() != 1) {
216     if(myEditCurrentArgument == GroupPoints->LineEdit1)
217       myOkBase = false;        
218     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
219       myOkAxis = false;
220     return;
221   }
222   
223   // nbSel == 1
224   Standard_Boolean testResult = Standard_False;
225   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
226   QString aName = GEOMBase::GetName( aSelectedObject );
227   
228   if (!testResult)
229     return;
230
231   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
232     TopoDS_Shape S;
233     myOkBase = false;
234     
235     if ( !GEOMBase::GetShape(aSelectedObject, S) || !isAcceptableBase( S ) )
236       return;
237     
238     myBase = aSelectedObject;
239     myOkBase = true;
240   }
241   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
242     if ( testResult && !aSelectedObject->_is_nil() )
243       {
244         TopoDS_Shape aShape;
245         
246         if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
247           {
248             LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
249               TColStd_IndexedMapOfInteger aMap;
250               aSelMgr->GetIndexes( firstIObject(), aMap );
251               if ( aMap.Extent() == 1 )
252                 {
253
254                   int anIndex = aMap( 1 );
255                   aName.append( ":edge_" + QString::number( anIndex ) );
256
257                   //Find SubShape Object in Father
258                   GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
259                   
260                   if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
261                     GEOM::GEOM_IShapesOperations_var aShapesOp =
262                       getGeomEngine()->GetIShapesOperations( getStudyId() );
263                     myAxis = aShapesOp->GetSubShape(aSelectedObject, anIndex);
264                     myOkAxis = true;
265                   }
266                   else {
267                     myAxis = aFindedObject;
268                     myOkAxis = true;
269                   }
270                 }
271               else {
272                 myOkAxis = true;
273                 if (aShape.ShapeType() != TopAbs_EDGE) {
274                   aSelectedObject = GEOM::GEOM_Object::_nil();
275                   aName = "";
276                   myOkAxis = false;
277                 }
278                 myAxis = aSelectedObject;
279               }
280           }
281       }
282   }
283   myEditCurrentArgument->setText( aName );
284
285   displayPreview();
286 }
287
288
289 //=================================================================================
290 // function : SetEditCurrentArgument()
291 // purpose  :
292 //=================================================================================
293 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
294 {
295   QPushButton* send = (QPushButton*)sender();
296   globalSelection( GEOM_ALLSHAPES );
297
298   if(send == GroupPoints->PushButton1) {
299     GroupPoints->LineEdit1->setFocus();
300     myEditCurrentArgument = GroupPoints->LineEdit1;
301   }
302   else if(send == GroupPoints->PushButton2) {
303     GroupPoints->LineEdit2->setFocus();
304     myEditCurrentArgument = GroupPoints->LineEdit2;
305     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
306   }
307   SelectionIntoArgument();
308 }
309
310
311 //=================================================================================
312 // function : LineEditReturnPressed()
313 // purpose  :
314 //=================================================================================
315 void GenerationGUI_RevolDlg::LineEditReturnPressed()
316 {  
317   QLineEdit* send = (QLineEdit*)sender();
318   if(send == GroupPoints->LineEdit1 ||
319      send == GroupPoints->LineEdit2)
320     {
321       myEditCurrentArgument = send;
322       GEOMBase_Skeleton::LineEditReturnPressed();
323     }
324 }
325
326
327 //=================================================================================
328 // function : ActivateThisDialog()
329 // purpose  :
330 //=================================================================================
331 void GenerationGUI_RevolDlg::ActivateThisDialog()
332 {
333   GEOMBase_Skeleton::ActivateThisDialog();
334   globalSelection( GEOM_ALLSHAPES );
335   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
336   GroupPoints->LineEdit1->setFocus();
337   myEditCurrentArgument = GroupPoints->LineEdit1;
338   displayPreview();
339 }
340
341
342 //=================================================================================
343 // function : enterEvent()
344 // purpose  :
345 //=================================================================================
346 void GenerationGUI_RevolDlg::enterEvent(QEvent* e)
347 {
348   if ( !GroupConstructors->isEnabled() )
349     ActivateThisDialog();
350 }
351
352
353 //=================================================================================
354 // function : ValueChangedInSpinBox()
355 // purpose  :
356 //=================================================================================
357 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
358 {
359   displayPreview();
360 }
361
362
363 //=================================================================================
364 // function : getAngle()
365 // purpose  :
366 //=================================================================================
367 double GenerationGUI_RevolDlg::getAngle() const
368 {
369   return GroupPoints->SpinBox_DX->GetValue();
370 }
371
372 //=================================================================================
373 // function : createOperation
374 // purpose  :
375 //=================================================================================
376 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
377 {
378   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
379 }
380
381 //=================================================================================
382 // function : isValid
383 // purpose  :
384 //=================================================================================
385 bool GenerationGUI_RevolDlg::isValid( QString& )
386 {
387   return myOkBase && myOkAxis;
388 }
389
390 //=================================================================================
391 // function : execute
392 // purpose  :
393 //=================================================================================
394 bool GenerationGUI_RevolDlg::execute( ObjectList& objects )
395 {
396   GEOM::GEOM_Object_var anObj;
397
398   if (!myBothway)
399     anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
400       getOperation() )->MakeRevolutionAxisAngle( myBase, myAxis, getAngle() * PI180 );
401   else
402     anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
403       getOperation() )->MakeRevolutionAxisAngle2Ways( myBase, myAxis, getAngle() * PI180 );
404
405   if ( !anObj->_is_nil() )
406     objects.push_back( anObj._retn() );
407
408   return true;
409 }
410
411
412 //=================================================================================
413 // function :  onReverse()
414 // purpose  :
415 //=================================================================================
416 void GenerationGUI_RevolDlg::onReverse()
417 {
418   double anOldValue = GroupPoints->SpinBox_DX->GetValue();
419   GroupPoints->SpinBox_DX->SetValue( -anOldValue );
420 }
421
422 //=================================================================================
423 // function :  onBothway()
424 // purpose  :
425 //=================================================================================
426 void GenerationGUI_RevolDlg::onBothway()
427 {
428   bool anOldValue = myBothway;
429   myBothway = !anOldValue;
430   GroupPoints->CheckButton2->setEnabled(!myBothway);  
431   displayPreview();
432 }
433
434 //=================================================================================
435 // function : addSubshapeToStudy
436 // purpose  : virtual method to add new SubObjects if local selection
437 //=================================================================================
438 void GenerationGUI_RevolDlg::addSubshapesToStudy()
439 {
440   QMap<QString, GEOM::GEOM_Object_var> objMap;
441
442   objMap[GroupPoints->LineEdit2->text()] = myAxis;
443
444   addSubshapesToFather( objMap );
445 }