Salome HOME
42832360d5b81240af08bd81b004b87289cf9d1d
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ExtensionDlg.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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   : TransformationGUI_ExtensionDlg.cxx
25 // Author : Sergey KHROMOV, Open CASCADE S.A.S.
26
27 #include "TransformationGUI_ExtensionDlg.h"
28 #include <GEOMBase.h>
29 #include <GeometryGUI.h>
30 #include <GEOMImpl_Types.hxx>
31
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <TColStd_MapOfInteger.hxx>
39
40 #include <QApplication>
41 #include <QGridLayout>
42 #include <QGroupBox>
43 #include <QLabel>
44 #include <QLineEdit>
45 #include <QPushButton>
46 #include <QRadioButton>
47
48
49 //=================================================================================
50 // class    : TransformationGUI_ExtensionDlg
51 // purpose  :
52 //=================================================================================
53 TransformationGUI_ExtensionDlg::TransformationGUI_ExtensionDlg
54                       (GeometryGUI* theGeometryGUI, QWidget* parent,
55                        bool modal, Qt::WindowFlags fl)
56   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
57     myObjLbl         (0),
58     myUMinLbl        (0),
59     myUMaxLbl        (0),
60     myVMinLbl        (0),
61     myVMaxLbl        (0),
62     mySelButton      (0),
63     myEditObjName    (0),
64     myUMinSpinBox    (0),
65     myUMaxSpinBox    (0),
66     myVMinSpinBox    (0),
67     myVMaxSpinBox    (0)
68 {
69   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
70   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_EXTEND_EDGE")));
71   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_EXTEND_FACE")));
72
73   setWindowTitle(tr("GEOM_EXTENSION_TITLE"));
74
75   /***************************************************************/
76   mainFrame()->GroupConstructors->setTitle(tr ("GEOM_EXTENSION"));
77   mainFrame()->RadioButton1->setIcon(image1);
78   mainFrame()->RadioButton2->setIcon(image2);
79   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
80   mainFrame()->RadioButton3->close();
81
82   QGroupBox *aGrp = new QGroupBox(tr("GEOM_ARGUMENTS"));
83
84   myObjLbl        = new QLabel;
85   myUMinLbl       = new QLabel;
86   myUMaxLbl       = new QLabel;
87   myVMinLbl       = new QLabel;
88   myVMaxLbl       = new QLabel;
89   mySelButton     = new QPushButton;
90   myEditObjName   = new QLineEdit;
91   myUMinSpinBox   = new SalomeApp_DoubleSpinBox;
92   myUMaxSpinBox   = new SalomeApp_DoubleSpinBox;
93   myVMinSpinBox   = new SalomeApp_DoubleSpinBox;
94   myVMaxSpinBox   = new SalomeApp_DoubleSpinBox;
95
96   myVMinLbl->setText(tr("GEOM_EXTENSION_MIN_V"));
97   myVMaxLbl->setText(tr("GEOM_EXTENSION_MAX_V"));
98   mySelButton->setIcon(image0);
99
100   QGridLayout *aGrpLayout = new QGridLayout(aGrp);
101
102   aGrpLayout->setMargin(9);
103   aGrpLayout->setSpacing(6);
104   aGrpLayout->addWidget(myObjLbl,      0, 0);
105   aGrpLayout->addWidget(myUMinLbl,     1, 0);
106   aGrpLayout->addWidget(myUMaxLbl,     2, 0);
107   aGrpLayout->addWidget(myVMinLbl,     3, 0);
108   aGrpLayout->addWidget(myVMaxLbl,     4, 0);
109   aGrpLayout->addWidget(mySelButton,   0, 1);
110   aGrpLayout->addWidget(myEditObjName, 0, 2);
111   aGrpLayout->addWidget(myUMinSpinBox, 1, 1, 1, 2);
112   aGrpLayout->addWidget(myUMaxSpinBox, 2, 1, 1, 2);
113   aGrpLayout->addWidget(myVMinSpinBox, 3, 1, 1, 2);
114   aGrpLayout->addWidget(myVMaxSpinBox, 4, 1, 1, 2);
115
116   myVMinLbl->hide();
117   myVMaxLbl->hide();
118   myVMinSpinBox->hide();
119   myVMaxSpinBox->hide();
120
121   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
122   layout->setMargin(0); layout->setSpacing(6);
123   layout->addWidget(aGrp);
124   /***************************************************************/
125
126   setHelpFileName("extension_operation_page.html");
127
128   /* Initialisations */
129   Init();
130 }
131
132 //=================================================================================
133 // function : ~GenerationGUI_FillingDlg()
134 // purpose  : Destroys the object and frees any allocated resources
135 //=================================================================================
136 TransformationGUI_ExtensionDlg::~TransformationGUI_ExtensionDlg()
137 {
138   // no need to delete child widgets, Qt does it all for us
139 }
140
141 //=================================================================================
142 // function : Init()
143 // purpose  :
144 //=================================================================================
145 void TransformationGUI_ExtensionDlg::Init()
146 {
147   /* init variables */
148   showOnlyPreviewControl();
149   myEditCurrentArgument = myEditObjName;
150
151   double aStep = 0.1;
152   /* min, max, step and decimals for spin boxes & initial values */
153   initSpinBox(myUMinSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
154   initSpinBox(myUMaxSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
155   initSpinBox(myVMinSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
156   initSpinBox(myVMaxSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
157
158   myUMinSpinBox->setValue(0.);
159   myUMaxSpinBox->setValue(1.);
160   myVMinSpinBox->setValue(0.);
161   myVMaxSpinBox->setValue(1.);
162
163   /* signals and slots connections */
164   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
165   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
166
167   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
168
169   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
170   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
171   connect(mySelButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
172
173   connect(myUMinSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174   connect(myUMaxSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175   connect(myVMinSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176   connect(myVMaxSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
177
178   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
179
180   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
181            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
182
183   initName(tr("GEOM_EXTENSION_EDGE_NAME"));
184   resize(100,100);
185
186   ConstructorsClicked(0);
187 }
188
189 //=================================================================================
190 // function : SetDoubleSpinBoxStep()
191 // purpose  : Double spin box management
192 //=================================================================================
193 void TransformationGUI_ExtensionDlg::SetDoubleSpinBoxStep(double step)
194 {
195   myUMinSpinBox->setSingleStep(step);
196   myUMaxSpinBox->setSingleStep(step);
197   myVMinSpinBox->setSingleStep(step);
198   myVMaxSpinBox->setSingleStep(step);
199 }
200
201 //=================================================================================
202 // function : ConstructorsClicked()
203 // purpose  : Radio button management
204 //=================================================================================
205 void TransformationGUI_ExtensionDlg::ConstructorsClicked (int constructorId)
206 {
207   switch (constructorId) {
208   case 0: // Extend edge
209     {
210       TColStd_MapOfInteger aMap;
211
212       aMap.Add(GEOM_EDGE);
213       globalSelection(aMap);
214
215       myObjLbl->setText(tr("GEOM_EDGE"));
216       myUMinLbl->setText(tr("GEOM_EXTENSION_MIN"));
217       myUMaxLbl->setText(tr("GEOM_EXTENSION_MAX"));
218       myVMinLbl->hide();
219       myVMaxLbl->hide();
220       myVMinSpinBox->hide();
221       myVMaxSpinBox->hide();
222
223       initName(tr("GEOM_EXTENSION_EDGE_NAME"));
224
225       break;
226     }
227   case 1: // Extend face
228     {
229       TColStd_MapOfInteger aMap;
230
231       aMap.Add(GEOM_FACE);
232       globalSelection(aMap);
233
234       myObjLbl->setText(tr("GEOM_FACE"));
235       myUMinLbl->setText(tr("GEOM_EXTENSION_MIN_U"));
236       myUMaxLbl->setText(tr("GEOM_EXTENSION_MAX_U"));
237       myVMinLbl->show();
238       myVMaxLbl->show();
239       myVMinSpinBox->show();
240       myVMaxSpinBox->show();
241
242       initName(tr("GEOM_EXTENSION_FACE_NAME"));
243
244       break;
245     }
246   default:
247     break;
248   }
249
250   myBase.nullify();
251   qApp->processEvents();
252   updateGeometry();
253   resize(minimumSizeHint());
254
255   SelectionIntoArgument();
256 }
257
258 //=================================================================================
259 // function : ClickOnOk()
260 // purpose  :
261 //=================================================================================
262 void TransformationGUI_ExtensionDlg::ClickOnOk()
263 {
264   setIsApplyAndClose(true);
265   if (ClickOnApply())
266     ClickOnCancel();
267 }
268
269 //=================================================================================
270 // function : ClickOnApply()
271 // purpose  :
272 //=================================================================================
273 bool TransformationGUI_ExtensionDlg::ClickOnApply()
274 {
275   if (!onAccept())
276     return false;
277
278   initName();
279
280   return true;
281 }
282
283 //=================================================================================
284 // function : SelectionIntoArgument()
285 // purpose  : Called when selection as changed or other case
286 //=================================================================================
287 void TransformationGUI_ExtensionDlg::SelectionIntoArgument()
288 {
289   erasePreview();
290   myEditCurrentArgument->setText("");
291
292   if (myEditCurrentArgument == myEditObjName) {
293     const TopAbs_ShapeEnum aType =
294       getConstructorId() == 0 ? TopAbs_EDGE: TopAbs_FACE;
295     GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
296
297     if (aSelectedObject) {
298       myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
299       myBase = aSelectedObject;
300     } else {
301       myBase.nullify();
302     }
303   }
304
305   processPreview();
306 }
307
308 //=================================================================================
309 // function : SetEditCurrentArgument()
310 // purpose  :
311 //=================================================================================
312 void TransformationGUI_ExtensionDlg::SetEditCurrentArgument()
313 {
314   QPushButton* send = (QPushButton*)sender();
315
316   if (send == mySelButton) {
317     myEditObjName->setFocus();
318     myEditCurrentArgument = myEditObjName;
319     SelectionIntoArgument();
320   }
321 }
322
323 //=================================================================================
324 // function : ActivateThisDialog()
325 // purpose  :
326 //=================================================================================
327 void TransformationGUI_ExtensionDlg::ActivateThisDialog()
328 {
329   GEOMBase_Skeleton::ActivateThisDialog();
330   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
331            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
332
333   ConstructorsClicked(getConstructorId());
334 }
335
336 //=================================================================================
337 // function : enterEvent()
338 // purpose  :
339 //=================================================================================
340 void TransformationGUI_ExtensionDlg::enterEvent(QEvent*)
341 {
342   if (!mainFrame()->GroupConstructors->isEnabled())
343     ActivateThisDialog();
344 }
345
346 //=================================================================================
347 // function : ValueChangedInSpinBox()
348 // purpose  :
349 //=================================================================================
350 void TransformationGUI_ExtensionDlg::ValueChangedInSpinBox(double /*newValue*/)
351 {
352   processPreview();
353 }
354
355 //=================================================================================
356 // function : createOperation
357 // purpose  :
358 //=================================================================================
359 GEOM::GEOM_IOperations_ptr TransformationGUI_ExtensionDlg::createOperation()
360 {
361   return getGeomEngine()->GetIShapesOperations();
362 }
363
364 //=================================================================================
365 // function : isValid
366 // purpose  :
367 //=================================================================================
368 bool TransformationGUI_ExtensionDlg::isValid(QString& msg)
369 {
370   bool ok = (myUMinSpinBox->isValid(msg, !IsPreview()) &&
371              myUMaxSpinBox->isValid(msg, !IsPreview()) &&
372              myVMinSpinBox->isValid(msg, !IsPreview()) &&
373              myVMaxSpinBox->isValid(msg, !IsPreview()) &&
374              myBase);
375   return ok;
376 }
377
378 //=================================================================================
379 // function : execute
380 // purpose  :
381 //=================================================================================
382 bool TransformationGUI_ExtensionDlg::execute(ObjectList& objects)
383 {
384   bool res = false;
385   GEOM::GEOM_IShapesOperations_var anOper =
386     GEOM::GEOM_IShapesOperations::_narrow(getOperation());
387   GEOM::GEOM_Object_var anObj;
388
389   switch (getConstructorId()) {
390   case 0:
391     anObj = anOper->ExtendEdge(myBase.get(), myUMinSpinBox->value(),
392                                myUMaxSpinBox->value());
393     if (!anObj->_is_nil() && !IsPreview())
394     {
395           QStringList aParameters;
396           aParameters << myUMinSpinBox->text();
397           aParameters << myUMaxSpinBox->text();
398           anObj->SetParameters(aParameters.join(":").toUtf8().constData());
399     }
400     res   = true;
401     break;
402   case 1:
403     anObj = anOper->ExtendFace(myBase.get(), myUMinSpinBox->value(),
404                                myUMaxSpinBox->value(),
405                                myVMinSpinBox->value(),
406                                myVMaxSpinBox->value());
407     if (!anObj->_is_nil() && !IsPreview())
408     {
409           QStringList aParameters;
410           aParameters << myUMinSpinBox->text();
411           aParameters << myUMaxSpinBox->text();
412           aParameters << myVMinSpinBox->text();
413           aParameters << myVMaxSpinBox->text();
414           anObj->SetParameters(aParameters.join(":").toUtf8().constData());
415     }
416     res   = true;
417     break;
418   default:
419     break;
420   }
421
422   if (!anObj->_is_nil()) {
423     objects.push_back(anObj._retn());
424   }
425
426   return res;
427 }
428
429 //=================================================================================
430 // function : getSourceObjects
431 // purpose  : virtual method to get source objects
432 //=================================================================================
433 QList<GEOM::GeomObjPtr> TransformationGUI_ExtensionDlg::getSourceObjects()
434 {
435   QList<GEOM::GeomObjPtr> res;
436   res << myBase;
437   return res;
438 }