Salome HOME
Added help page and revert some changes for a better ergonomy
[modules/geom.git] / src / OperationGUI / OperationGUI_Fillet1d2dDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
19 // GEOM GEOMGUI : GUI for Geometry component
20 // File   : OperationGUI_Fillet1d2dDlg.cxx
21 // Author : DMV, OCN.
22
23 #include "OperationGUI_Fillet1d2dDlg.h"
24
25 #include <DlgRef.h>
26 #include <GeometryGUI.h>
27 #include <GEOMBase.h>
28
29 #include <SUIT_Desktop.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_ViewWindow.h>
33 #include <SUIT_ViewManager.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <OCCViewer_ViewModel.h>
37
38 // OCCT Includes
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41
42 #include <GEOMImpl_Types.hxx>
43
44 //=================================================================================
45 // class    : OperationGUI_Fillet1d2dDlg()
46 // purpose  : Constructs a OperationGUI_Fillet1d2dDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_Fillet1d2dDlg::OperationGUI_Fillet1d2dDlg (GeometryGUI* theGeometryGUI,
52                                                         QWidget* parent,
53                                                         bool is1D)
54   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
55     myIs1D( is1D )
56 {
57   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
58   QPixmap image0 (aResMgr->loadPixmap("GEOM", myIs1D ? tr("ICON_DLG_FILLET_1D") 
59                                                      : tr("ICON_DLG_FILLET_2D")));
60   QPixmap iconSelect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61
62   setWindowTitle(myIs1D ? tr("GEOM_FILLET_1D_TITLE") : tr("GEOM_FILLET_2D_TITLE"));
63
64   /***************************************************************/
65   mainFrame()->GroupConstructors->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
66   mainFrame()->RadioButton1->setIcon(image0);
67   mainFrame()->RadioButton2->close();
68   mainFrame()->RadioButton3->close();
69
70   GroupVertexes = new DlgRef_2Sel1Spin(centralWidget());
71   GroupVertexes->GroupBox1->setTitle(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
72   GroupVertexes->TextLabel1->setText(myIs1D ? tr("GEOM_PLANAR_EDGE_WIRE") : tr("GEOM_PLANAR_FACE"));
73   GroupVertexes->TextLabel2->setText(tr("GEOM_VERTEXES"));
74   GroupVertexes->TextLabel3->setText(tr("GEOM_RADIUS"));
75   GroupVertexes->PushButton1->setIcon(iconSelect);
76   GroupVertexes->PushButton2->setIcon(iconSelect);
77   GroupVertexes->LineEdit1->setReadOnly(true);
78   GroupVertexes->LineEdit2->setReadOnly(true);
79
80   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
81   layout->setMargin(0); layout->setSpacing(6);
82   layout->addWidget(GroupVertexes);
83
84   /***************************************************************/
85
86   // Set range of spinboxes
87   double SpecificStep = 10.0;
88   initSpinBox(GroupVertexes->SpinBox_DX, 0.00001, COORD_MAX, SpecificStep, "length_precision" );
89
90   setHelpFileName(myIs1D ? "fillet1d_operation_page.html" : "fillet2d_operation_page.html");
91
92   // Initialisation
93   Init();
94   resize(100,100);
95 }
96
97 //=================================================================================
98 // function : ~OperationGUI_Fillet1d2dDlg()
99 // purpose  : Destroys the object and frees any allocated resources
100 //=================================================================================
101 OperationGUI_Fillet1d2dDlg::~OperationGUI_Fillet1d2dDlg()
102 {
103 }
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void OperationGUI_Fillet1d2dDlg::Init()
110 {
111   // Set Initial values of spinboxes
112   GroupVertexes->SpinBox_DX->setValue(5);
113
114   // Clear line edits
115   GroupVertexes->LineEdit1->setText("");
116   GroupVertexes->LineEdit2->setText("");
117
118   myShape = GEOM::GEOM_Object::_nil();
119
120   myVertexes.Clear();
121
122   showOnlyPreviewControl();
123
124   // signals and slots connections
125
126   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()   ));
127   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128
129   //  connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
130
131   connect(GroupVertexes->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132   connect(GroupVertexes->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133
134   connect(GroupVertexes->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135   connect(GroupVertexes->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136
137   connect(GroupVertexes->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
138
139   initName(myIs1D ? tr("GEOM_FILLET_1D") : tr("GEOM_FILLET_2D"));
140   GroupVertexes->PushButton1->click();
141
142   SelectionIntoArgument();
143 }
144
145 //=================================================================================
146 // function : ClickOnOk()
147 // purpose  :
148 //=================================================================================
149 void OperationGUI_Fillet1d2dDlg::ClickOnOk()
150 {
151   setIsApplyAndClose( true );
152   if (ClickOnApply())
153     ClickOnCancel();
154 }
155
156 //=================================================================================
157 // function : ClickOnApply()
158 // purpose  :
159 //=================================================================================
160 bool OperationGUI_Fillet1d2dDlg::ClickOnApply()
161 {
162   if (!onAccept())
163     return false;
164
165   initName();
166   // Reset dialog state
167   GroupVertexes->LineEdit1->setText("");
168   GroupVertexes->LineEdit2->setText("");
169   myShape = GEOM::GEOM_Object::_nil();
170   myVertexes.Clear();
171   GroupVertexes->PushButton1->click();
172
173   return true;
174 }
175
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose  : Called when selection is changed or on dialog initialization or activation
179 //=================================================================================
180 void OperationGUI_Fillet1d2dDlg::SelectionIntoArgument()
181 {
182   erasePreview();
183   myEditCurrentArgument->setText("");
184
185   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
186   SALOME_ListIO aSelList;
187   aSelMgr->selectedObjects(aSelList);
188
189   // If selection of main object is activated
190   if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
191     myShape = GEOM::GEOM_Object::_nil();
192     if (aSelList.Extent() == 1) {
193       GEOM::GEOM_Object_var anObj =
194         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
195       
196       if ( !anObj->_is_nil() ) {
197         QString aName = GEOMBase::GetName( anObj );
198         TopoDS_Shape aShape;
199         if ( GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
200           TColStd_IndexedMapOfInteger aMap;
201           aSelMgr->GetIndexes(aSelList.First(), aMap);
202           if ( aMap.Extent() == 1 ) { // Local Selection
203             int anIndex = aMap( 1 );
204             aName += QString( myIs1D ? ":wire_%1" : ":face_%1" ).arg( anIndex );
205    
206             //Find SubShape Object in Father
207             GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( anObj, aName );
208             
209             if ( aFindedObject->_is_nil()) { // Object not found in study
210               GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
211               anObj = aShapesOp->GetSubShape( anObj, anIndex );
212             }
213             else
214               anObj = aFindedObject; // get Object from study
215           }
216           else { // Global Selection
217             if ((myIs1D && aShape.ShapeType() != TopAbs_WIRE) ||
218                 (!myIs1D && aShape.ShapeType() != TopAbs_FACE && aShape.ShapeType() != TopAbs_SHELL)) {
219               anObj = GEOM::GEOM_Object::_nil();
220               aName = "";
221             }
222           }
223         }
224         myShape = anObj;
225         myEditCurrentArgument->setText(aName
226 );
227         processPreview();
228       }
229     }
230   } else if (myEditCurrentArgument == GroupVertexes->LineEdit2) {
231     myVertexes.Clear();
232     bool isPreview = myIs1D;
233     if (aSelList.Extent() == 1) {
234       GEOM::GEOM_Object_var anObj =
235         GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
236
237       if ( !anObj->_is_nil() ) {
238         TColStd_IndexedMapOfInteger anIndexes;
239         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
240
241         if (anIndexes.Extent() > 0) {
242           QString aName;
243           if (anIndexes.Extent() == 1) {
244             int anIndex = anIndexes(1);
245             aName = QString(GEOMBase::GetName(anObj)) + QString(":vertex_%1").arg(anIndex);
246           }
247           else
248             aName = tr("GEOM_MEN_POPUP_NAME").arg(anIndexes.Extent());
249
250           isPreview = true;
251           myEditCurrentArgument->setText(aName);
252           myVertexes = anIndexes;
253         }
254       }
255     }
256     if ( isPreview )
257       processPreview();
258   }
259
260   if (myEditCurrentArgument == GroupVertexes->LineEdit1) {
261     if (!myShape->_is_nil() && myVertexes.Extent() == 0)
262       GroupVertexes->PushButton2->click();
263   }
264 }
265
266 //=================================================================================
267 // function : SetEditCurrentArgument()
268 // purpose  :
269 //=================================================================================
270 void OperationGUI_Fillet1d2dDlg::SetEditCurrentArgument()
271 {
272   QPushButton* send = (QPushButton*)sender();
273
274   if (send == GroupVertexes->PushButton1) {
275     myEditCurrentArgument = GroupVertexes->LineEdit1;
276     GroupVertexes->PushButton2->setDown(false);
277     GroupVertexes->LineEdit2->setEnabled(false);
278   }
279   else if (send == GroupVertexes->PushButton2) {
280     myEditCurrentArgument = GroupVertexes->LineEdit2;
281     GroupVertexes->PushButton1->setDown(false);
282     GroupVertexes->LineEdit1->setEnabled(false);
283   }
284
285   // enable line edit
286   myEditCurrentArgument->setEnabled(true);
287   myEditCurrentArgument->setFocus();
288   // after setFocus(), because it will be setDown(false) when loses focus
289   send->setDown(true);
290
291   activateSelection();
292
293   // seems we need it only to avoid preview disappearing, caused by selection mode change
294   processPreview();
295 }
296
297 //=================================================================================
298 // function : LineEditReturnPressed()
299 // purpose  :
300 //=================================================================================
301 void OperationGUI_Fillet1d2dDlg::LineEditReturnPressed()
302 {
303   QLineEdit* send = (QLineEdit*)sender();
304
305   if (send == GroupVertexes->LineEdit1)
306     myEditCurrentArgument = GroupVertexes->LineEdit1;
307   else if (send == GroupVertexes->LineEdit2)
308     myEditCurrentArgument = GroupVertexes->LineEdit2;
309   else
310     return;
311
312   GEOMBase_Skeleton::LineEditReturnPressed();
313 }
314
315 //=================================================================================
316 // function : ActivateThisDialog()
317 // purpose  :
318 //=================================================================================
319 void OperationGUI_Fillet1d2dDlg::ActivateThisDialog()
320 {
321   GEOMBase_Skeleton::ActivateThisDialog();
322 }
323
324 //=================================================================================
325 // function : enterEvent()
326 // purpose  :
327 //=================================================================================
328 void OperationGUI_Fillet1d2dDlg::enterEvent (QEvent*)
329 {
330   if (!mainFrame()->GroupConstructors->isEnabled())
331     this->ActivateThisDialog();
332 }
333
334 //=================================================================================
335 // function : ValueChangedInSpinBox()
336 // purpose  :
337 //=================================================================================
338 void OperationGUI_Fillet1d2dDlg::ValueChangedInSpinBox (double)
339 {
340   processPreview();
341 }
342
343 //=================================================================================
344 // function : activateSelection
345 // purpose  : Activate selection in accordance with myEditCurrentArgument
346 //=================================================================================
347 void OperationGUI_Fillet1d2dDlg::activateSelection()
348 {
349   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
350   globalSelection();
351   if (myEditCurrentArgument == GroupVertexes->LineEdit1)
352     //localSelection(myShape, myIs1D ? TopAbs_WIRE : TopAbs_FACE);
353     if (myIs1D)
354       globalSelection(GEOM_WIRE);
355     else {
356       TColStd_MapOfInteger aMap;
357       aMap.Add(GEOM_FACE);
358       aMap.Add(GEOM_SHELL);
359       globalSelection(aMap);
360     }
361   else if (!myShape->_is_nil() && myEditCurrentArgument == GroupVertexes->LineEdit2)
362     localSelection(myShape, TopAbs_VERTEX);
363
364   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
365           this, SLOT(SelectionIntoArgument()));
366 }
367
368 //=================================================================================
369 // function : createOperation
370 // purpose  :
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr OperationGUI_Fillet1d2dDlg::createOperation()
373 {
374   return getGeomEngine()->GetILocalOperations(getStudyId());
375 }
376
377 //=================================================================================
378 // function : isValid()
379 // purpose  : Verify validity of input data
380 //=================================================================================
381 bool OperationGUI_Fillet1d2dDlg::isValid (QString& msg)
382 {
383   bool ok = !myShape->_is_nil();
384   ok = GroupVertexes->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
385   ok = (myIs1D || myVertexes.Extent() > 0) && ok;
386   return ok;
387 }
388
389 //=================================================================================
390 // function : execute
391 // purpose  :
392 //=================================================================================
393 bool OperationGUI_Fillet1d2dDlg::execute (ObjectList& objects)
394 {
395   GEOM::ListOfLong_var aListOfIndexes = new GEOM::ListOfLong;
396   aListOfIndexes->length(myVertexes.Extent());
397
398   for (int i = 1, n = myVertexes.Extent(); i <= n; i++)
399     aListOfIndexes[ i - 1 ] = myVertexes(i);
400
401   GEOM::GEOM_ILocalOperations_var anOper = GEOM::GEOM_ILocalOperations::_narrow(getOperation());
402   GEOM::GEOM_Object_var anObj = myIs1D ?
403     anOper->MakeFillet1D(myShape, getRadius(), aListOfIndexes) : 
404     anOper->MakeFillet2D(myShape, getRadius(), aListOfIndexes);
405
406   if (!anObj->_is_nil())
407     objects.push_back(anObj._retn());
408
409   return true;
410 }
411
412 //=================================================================================
413 // function : getRadius
414 // purpose  : Get radius
415 //=================================================================================
416 double OperationGUI_Fillet1d2dDlg::getRadius() const
417 {
418   return GroupVertexes ->SpinBox_DX->value();
419 }