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