Salome HOME
updated copyright message
[modules/geom.git] / src / MeasureGUI / MeasureGUI_GetNonBlocksDlg.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   : MeasureGUI_GetNonBlocksDlg.cxx
25
26 #include "MeasureGUI_GetNonBlocksDlg.h"
27
28 #include <GEOMBase.h>
29
30 #include <GeometryGUI.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_DoubleSpinBox.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <SalomeApp_Tools.h>
38
39 #include <QCheckBox>
40 #include <QGridLayout>
41 #include <QGroupBox>
42 #include <QLineEdit>
43 #include <QPushButton>
44 #include <QRadioButton>
45 #include <QVBoxLayout>
46
47 //=================================================================================
48 // class    : MeasureGUI_GetNonBlocksDlg()
49 // purpose  : Constructs a MeasureGUI_GetNonBlocksDlg which is a child of 'parent',
50 //            with the 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 MeasureGUI_GetNonBlocksDlg::MeasureGUI_GetNonBlocksDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
55   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
56     myObjectName     (0),
57     mySelButton      (0),
58     myUseC1Check     (0),
59     myTolLbl         (0),
60     mySpinTol        (0)
61 {
62   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GETNONBLOCKS")));
63   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
64
65   setWindowTitle(tr("GEOM_GETNONBLOCKS_TITLE"));
66
67   /***************************************************************/
68   mainFrame()->GroupConstructors->setTitle(tr("GEOM_GETNONBLOCKS"));
69   mainFrame()->RadioButton1->setIcon(image0);
70   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
71   mainFrame()->RadioButton2->close();
72   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
73   mainFrame()->RadioButton3->close();
74   
75   QGroupBox   *aGrpParams    =
76     new QGroupBox(tr("GEOM_GETNONBLOCKS"), centralWidget());
77   QGridLayout *aParamsLayout = new QGridLayout(aGrpParams);
78   QLabel      *anObjLbl      = new QLabel(tr("GEOM_OBJECT"), aGrpParams);
79
80   myObjectName = new QLineEdit(aGrpParams);
81   mySelButton  = new QPushButton(aGrpParams);
82   myUseC1Check = new QCheckBox(tr("GEOM_USE_C1_CRITERION"), aGrpParams);
83   myTolLbl     = new QLabel(tr("GEOM_ANGULAR_TOLERANCE"), aGrpParams);
84   mySpinTol    = new SalomeApp_DoubleSpinBox(aGrpParams);
85
86   myObjectName->setReadOnly(true);
87   mySelButton->setIcon(image1);
88   mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
89   myUseC1Check->setText(tr("GEOM_USE_C1_CRITERION"));
90   myUseC1Check->setChecked(true);
91
92   aParamsLayout->setMargin(9);
93   aParamsLayout->setSpacing(6);
94   aParamsLayout->addWidget(anObjLbl,     0, 0);
95   aParamsLayout->addWidget(mySelButton,  0, 1);
96   aParamsLayout->addWidget(myObjectName, 0, 2);
97   aParamsLayout->addWidget(myUseC1Check, 1, 0, 1, 3);
98   aParamsLayout->addWidget(myTolLbl,     2, 0);
99   aParamsLayout->addWidget(mySpinTol,    2, 1, 1, 2);
100
101   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
102   layout->setMargin(0); layout->setSpacing(6);
103   layout->addWidget(aGrpParams);
104
105   /***************************************************************/
106
107   myHelpFileName = "get_non_blocks_page.html";
108
109   /* Initialisation */
110   Init();
111 }
112
113 //=================================================================================
114 // function : ~MeasureGUI_GetNonBlocksDlg()
115 // purpose  : Destroys the object and frees any allocated resources
116 //=================================================================================
117 MeasureGUI_GetNonBlocksDlg::~MeasureGUI_GetNonBlocksDlg()
118 {
119 }
120
121 //=================================================================================
122 // function : Init()
123 // purpose  :
124 //=================================================================================
125 void MeasureGUI_GetNonBlocksDlg::Init()
126 {
127   showOnlyPreviewControl();
128
129   /* init variables */
130   double SpecificStep = 0.0001;
131   double aDefaultTol  = Precision::Angular();
132
133   initSpinBox(mySpinTol, aDefaultTol, MAX_NUMBER, SpecificStep, "ang_tol_precision");
134   mySpinTol->setValue(aDefaultTol);
135   myEditCurrentArgument = myObjectName;
136
137    /* signals and slots connections */
138   connect(buttonOk(),    SIGNAL(clicked()),            this, SLOT(ClickOnOk()));
139   connect(buttonApply(), SIGNAL(clicked()),            this, SLOT(ClickOnApply()));
140   connect(myUseC1Check,  SIGNAL(clicked()),            this, SLOT(SetUseC1Tolerance()));
141   connect(mySpinTol,     SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
142   connect(myObjectName,  SIGNAL(returnPressed()),      this, SLOT(LineEditReturnPressed()));
143   connect(mySelButton,   SIGNAL(clicked()),            this, SLOT(SetEditCurrentArgument()));
144
145   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
146            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
147
148   //initName(tr("GEOM_NONBLOCKS"));
149   mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
150   globalSelection();
151   SelectionIntoArgument();
152 }
153
154 //=================================================================================
155 // function : ClickOnOk()
156 // purpose  :
157 //=================================================================================
158 void MeasureGUI_GetNonBlocksDlg::ClickOnOk()
159 {
160   if (ClickOnApply())
161     ClickOnCancel();
162 }
163
164 //=================================================================================
165 // function : ClickOnApply()
166 // purpose  :
167 //=================================================================================
168 bool MeasureGUI_GetNonBlocksDlg::ClickOnApply()
169 {
170   if (!onAccept())
171     return false;
172
173   //initName();
174   return true;
175 }
176
177 //=================================================================================
178 // function : SelectionIntoArgument()
179 // purpose  : Called when selection as changed or other case
180 //=================================================================================
181 void MeasureGUI_GetNonBlocksDlg::SelectionIntoArgument()
182 {
183   erasePreview();
184   myObj = GEOM::GEOM_Object::_nil();
185
186   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
187   SALOME_ListIO aSelList;
188   aSelMgr->selectedObjects(aSelList);
189
190   if (aSelList.Extent() != 1) {
191     processObject();
192     return;
193   }
194
195   GEOM::GEOM_Object_var aSelectedObject =
196     GEOMBase::ConvertIOinGEOMObject(aSelList.First());
197
198   if (aSelectedObject->_is_nil()) {
199     processObject();
200     return;
201   }
202
203   myObj = aSelectedObject;
204   processObject();
205 }
206
207 //=================================================================================
208 // function : SetEditCurrentArgument()
209 // purpose  :
210 //=================================================================================
211 void MeasureGUI_GetNonBlocksDlg::SetEditCurrentArgument()
212 {
213   myObjectName->setFocus();
214   myEditCurrentArgument = myObjectName;
215   SelectionIntoArgument();
216 }
217
218 //=================================================================================
219 // function : SetUseC1Tolerance()
220 // purpose  :
221 //=================================================================================
222 void MeasureGUI_GetNonBlocksDlg::SetUseC1Tolerance()
223 {
224   myTolLbl->setEnabled(myUseC1Check->isChecked());
225   mySpinTol->setEnabled(myUseC1Check->isChecked());
226   processPreview();
227 }
228
229 //=================================================================================
230 // function : LineEditReturnPressed()
231 // purpose  :
232 //=================================================================================
233 void MeasureGUI_GetNonBlocksDlg::LineEditReturnPressed()
234 {
235   QLineEdit* send = (QLineEdit*)sender();
236   if (send == myObjectName) {
237     myEditCurrentArgument = myObjectName;
238     GEOMBase_Skeleton::LineEditReturnPressed();
239   }
240 }
241
242 //=================================================================================
243 // function : ActivateThisDialog()
244 // purpose  :
245 //=================================================================================
246 void MeasureGUI_GetNonBlocksDlg::ActivateThisDialog()
247 {
248   GEOMBase_Skeleton::ActivateThisDialog();
249
250   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
251            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
252
253   globalSelection();
254   processPreview();
255 }
256
257 //=================================================================================
258 // function : processObject()
259 // purpose  : Fill dialog fields in accordance with myObj
260 //=================================================================================
261 void MeasureGUI_GetNonBlocksDlg::processObject()
262 {
263   if (myObj->_is_nil()) {
264     myObjectName->setText("");
265     erasePreview();
266   }
267   else {
268     myObjectName->setText(GEOMBase::GetName(myObj));
269
270     processPreview();
271   }
272 }
273
274 //=================================================================================
275 // function : enterEvent()
276 // purpose  :
277 //=================================================================================
278 void MeasureGUI_GetNonBlocksDlg::enterEvent (QEvent*)
279 {
280   if (!mainFrame()->GroupConstructors->isEnabled())
281     ActivateThisDialog();
282 }
283
284 //=================================================================================
285 // function : createOperation
286 // purpose  :
287 //=================================================================================
288 GEOM::GEOM_IOperations_ptr MeasureGUI_GetNonBlocksDlg::createOperation()
289 {
290   return getGeomEngine()->GetIBlocksOperations();
291 }
292
293 //=================================================================================
294 // function : isValid
295 // purpose  :
296 //=================================================================================
297 bool MeasureGUI_GetNonBlocksDlg::isValid (QString &msg)
298 {
299   return !myObj->_is_nil() && mySpinTol->isValid(msg, !IsPreview());
300 }
301
302 //=================================================================================
303 // function : execute
304 // purpose  :
305 //=================================================================================
306 bool MeasureGUI_GetNonBlocksDlg::execute (ObjectList& objects)
307 {
308   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
309   GEOM::GEOM_Object_var aNonQuads;
310   double aC1Tol = -1.;
311
312   if (myUseC1Check->isChecked()) {
313     aC1Tol = mySpinTol->value();
314   }
315
316   GEOM::GEOM_Object_var anObj = anOper->GetNonBlocks(myObj, aC1Tol, aNonQuads);
317   //mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
318
319   if (!anObj->_is_nil())
320     objects.push_back(anObj._retn());
321   if (!aNonQuads->_is_nil())
322     objects.push_back(aNonQuads._retn());
323
324   return true;
325 }
326
327 //================================================================
328 // Function : getFather
329 // Purpose  : Get father object for object to be added in study
330 //            ( called with addInStudy method )
331 //================================================================
332 GEOM::GEOM_Object_ptr MeasureGUI_GetNonBlocksDlg::getFather (GEOM::GEOM_Object_ptr)
333 {
334   return myObj;
335 }
336
337 //=================================================================================
338 // function : getSourceObjects
339 // purpose  : virtual method to get source objects
340 //=================================================================================
341 QList<GEOM::GeomObjPtr> MeasureGUI_GetNonBlocksDlg::getSourceObjects()
342 {
343   QList<GEOM::GeomObjPtr> res;
344   GEOM::GeomObjPtr aGeomObjPtr(myObj);
345   res << aGeomObjPtr;
346   return res;
347 }