1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "AdvancedGUI_DividedDiskDlg.h"
26 #include <GeometryGUI.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <GEOMImpl_Types.hxx>
49 //=================================================================================
51 //=================================================================================
52 AdvancedGUI_DividedDiskDlg::AdvancedGUI_DividedDiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
53 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
55 // QPixmap imageOp (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDDISK_R_RATIO")));
56 QPixmap imageOp1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
57 QPixmap imageOp2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
58 QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
60 setWindowTitle(tr("GEOM_DIVIDEDDISK_TITLE"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDDISK"));
64 mainFrame()->RadioButton1->setIcon(imageOp1);
65 mainFrame()->RadioButton2->setIcon(imageOp2);
66 // mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
67 // mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
69 mainFrame()->RadioButton3->close();
71 GroupParams = new DlgRef_1Spin(centralWidget());
72 GroupParams->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 GroupParams->TextLabel1->setText(tr("GEOM_RADIUS"));
75 GroupOrientation = new DlgRef_3Radio(centralWidget());
76 GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
77 GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
78 GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
79 GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
81 GroupPattern = new DlgRef_3Radio(centralWidget());
82 GroupPattern->GroupBox1->setTitle(tr("GEOM_PATTERN"));
83 GroupPattern->RadioButton1->setText(tr("GEOM_SQUARE"));
84 GroupPattern->RadioButton2->setText(tr("GEOM_HEXAGON"));
85 GroupPattern->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
86 GroupPattern->RadioButton3->close();
88 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
89 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
90 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
91 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
92 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
93 GroupPntVecR->PushButton1->setIcon(imageSel);
94 GroupPntVecR->PushButton2->setIcon(imageSel);
95 GroupPntVecR->LineEdit1->setReadOnly(true);
96 GroupPntVecR->LineEdit2->setReadOnly(true);
97 //@@ setup dialog box layout here @@//
99 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
100 layout->setMargin(0); layout->setSpacing(6);
101 layout->addWidget(GroupParams);
102 layout->addWidget(GroupOrientation);
103 layout->addWidget(GroupPntVecR);
104 layout->addWidget(GroupPattern);
105 /***************************************************************/
107 setHelpFileName("create_divideddisk_page.html");
112 //=================================================================================
114 //=================================================================================
115 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
117 // no need to delete child widgets, Qt does it all for us
120 //=================================================================================
123 //=================================================================================
124 void AdvancedGUI_DividedDiskDlg::Init()
126 // Get setting of step value from file configuration
127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
130 // min, max, step and decimals for spin boxes & initial values
131 initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
132 initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
133 GroupParams ->SpinBox_DX->setValue(100);
134 GroupPntVecR->SpinBox_DX->setValue(100);
136 GroupOrientation->RadioButton1->setChecked(true);
139 GroupPattern->RadioButton1->setChecked(true);
140 myPattern = GEOM::SQUARE;
142 // Signal/slot connections
143 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
146 this, SLOT(SetDoubleSpinBoxStep(double)));
148 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
150 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
156 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
157 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
158 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
160 connect(GroupPattern->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
161 connect(GroupPattern->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
163 initName(tr("GEOM_DIVIDEDDISK"));
165 ConstructorsClicked(0);
168 //=================================================================================
169 // function : SetDoubleSpinBoxStep()
170 // purpose : Double spin box management
171 //=================================================================================
172 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double /*step*/)
174 //@@ set double spin box step for all spin boxes here @@//
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose : Radio button management
180 //=================================================================================
181 void AdvancedGUI_DividedDiskDlg::ConstructorsClicked (int constructorId)
183 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
185 switch (constructorId) {
188 GroupPntVecR->hide();
190 GroupOrientation->show();
192 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
193 globalSelection(); // close local contexts, if any
199 GroupOrientation->hide();
200 GroupPntVecR->show();
202 GroupPntVecR->PushButton1->click();
207 qApp->processEvents();
209 resize(minimumSizeHint());
210 SelectionIntoArgument();
212 displayPreview(true);
215 //=================================================================================
216 // function : RadioButtonClicked()
217 // purpose : Radio button management
218 //=================================================================================
219 void AdvancedGUI_DividedDiskDlg::RadioButtonClicked()
221 QRadioButton* send = (QRadioButton*)sender();
224 if (send == GroupOrientation->RadioButton1)
226 else if ( send == GroupOrientation->RadioButton2)
228 else if ( send == GroupOrientation->RadioButton3)
232 else if (send == GroupPattern->RadioButton1)
233 myPattern = GEOM::SQUARE;
234 else if (send == GroupPattern->RadioButton2)
235 myPattern = GEOM::HEXAGON;
237 displayPreview(true);
240 //=================================================================================
241 // function : ClickOnOk()
243 //=================================================================================
244 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose : Called when selection is changed or on dialog initialization or activation
267 //=================================================================================
268 void AdvancedGUI_DividedDiskDlg::SelectionIntoArgument()
270 if (getConstructorId() == 0)
274 myEditCurrentArgument->setText("");
276 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
277 SALOME_ListIO aSelList;
278 aSelMgr->selectedObjects(aSelList);
280 if (aSelList.Extent() != 1) {
281 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
282 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
286 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
287 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
289 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ){
290 QString aName = GEOMBase::GetName( aSelectedObject.get() );
292 myEditCurrentArgument->setText(aName);
295 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
296 myGeomGUI->getApp()->selectionMgr()->clearSelected();
297 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
298 this, SLOT(SelectionIntoArgument()));
300 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
301 myPoint = aSelectedObject;
302 if (myPoint && !myDir)
303 GroupPntVecR->PushButton2->click();
305 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
306 myDir = aSelectedObject;
307 if (myDir && !myPoint)
308 GroupPntVecR->PushButton1->click();
311 displayPreview(true);
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void AdvancedGUI_DividedDiskDlg::SetEditCurrentArgument()
320 QPushButton* send = (QPushButton*)sender();
322 if (send == GroupPntVecR->PushButton1) {
323 myEditCurrentArgument = GroupPntVecR->LineEdit1;
325 GroupPntVecR->PushButton2->setDown(false);
326 GroupPntVecR->LineEdit2->setEnabled(false);
328 else if (send == GroupPntVecR->PushButton2) {
329 myEditCurrentArgument = GroupPntVecR->LineEdit2;
331 GroupPntVecR->PushButton1->setDown(false);
332 GroupPntVecR->LineEdit1->setEnabled(false);
335 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
336 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
337 globalSelection(); // close local contexts, if any
338 localSelection(TopAbs_EDGE);
341 globalSelection(); // close local contexts, if any
342 localSelection(TopAbs_VERTEX);
344 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
345 this, SLOT(SelectionIntoArgument()));
348 myEditCurrentArgument->setEnabled(true);
349 myEditCurrentArgument->setFocus();
350 // after setFocus(), because it will be setDown(false) when loses focus
353 // seems we need it only to avoid preview disappearing, caused by selection mode change
354 displayPreview(true);
357 //=================================================================================
358 // function : ActivateThisDialog()
360 //=================================================================================
361 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
363 GEOMBase_Skeleton::ActivateThisDialog();
364 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
365 this, SLOT( SelectionIntoArgument() ) );
367 ConstructorsClicked( getConstructorId() );
370 //=================================================================================
371 // function : enterEvent [REDEFINED]
373 //=================================================================================
374 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
376 if (!mainFrame()->GroupConstructors->isEnabled())
377 ActivateThisDialog();
380 //=================================================================================
381 // function : ValueChangedInSpinBox()
383 //=================================================================================
384 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
386 displayPreview(true);
389 //=================================================================================
390 // function : createOperation
392 //=================================================================================
393 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
395 return getGeomEngine()->GetPluginOperations("AdvancedEngine");
398 //=================================================================================
399 // function : isValid
401 //=================================================================================
402 bool AdvancedGUI_DividedDiskDlg::isValid (QString& /*msg*/)
406 //@@ add custom validation actions here @@//
411 //=================================================================================
412 // function : execute
414 //=================================================================================
415 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
419 GEOM::GEOM_Object_var anObj;
421 GEOM::IAdvancedOperations_var anOper = GEOM::IAdvancedOperations::_narrow(getOperation());
423 CORBA::Double theRatio = 67; // About 2/3
424 CORBA::Double theR = 0;
426 switch (getConstructorId()) {
428 theR = GroupParams->SpinBox_DX->value(); // init parameter value from dialog box ;
430 // call engine function
431 anObj = anOper->MakeDividedDisk(theR, theRatio, myOrientation, myPattern);
432 res = !anObj->_is_nil();
433 if (res && !IsPreview())
435 QStringList aParameters;
436 aParameters << GroupParams->SpinBox_DX->text();
437 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toUtf8().constData());
441 theR = GroupPntVecR->SpinBox_DX->value();
443 // call engine function
444 anObj = anOper->MakeDividedDiskPntVecR(myPoint.get(), myDir.get(), theR, theRatio, myPattern);
445 res = !anObj->_is_nil();
446 if (res && !IsPreview())
448 QStringList aParameters;
449 aParameters << GroupPntVecR->SpinBox_DX->text();
450 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toUtf8().constData());
457 objects.push_back(anObj._retn());
462 //=================================================================================
463 // function : getSourceObjects
464 // purpose : virtual method to get source objects
465 //=================================================================================
466 QList<GEOM::GeomObjPtr> AdvancedGUI_DividedDiskDlg::getSourceObjects()
468 QList<GEOM::GeomObjPtr> res;
469 res << myPoint << myDir;