1 // Copyright (C) 2007-2008 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.
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
22 #include "AdvancedGUI_DividedDiskDlg.h"
25 #include <GeometryGUI.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
34 #include <TopoDS_Shape.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
50 //=================================================================================
51 AdvancedGUI_DividedDiskDlg::AdvancedGUI_DividedDiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
52 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
54 // QPixmap imageOp (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDDISK_R_RATIO")));
55 QPixmap imageOp1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
56 QPixmap imageOp2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
57 QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setWindowTitle(tr("GEOM_DIVIDEDDISK_TITLE"));
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDDISK"));
63 mainFrame()->RadioButton1->setIcon(imageOp1);
64 mainFrame()->RadioButton2->setIcon(imageOp2);
65 // mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
66 // mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton3->close();
70 GroupParams = new DlgRef_1Spin(centralWidget());
71 GroupParams->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupParams->TextLabel1->setText(tr("GEOM_RADIUS"));
74 GroupOrientation = new DlgRef_3Radio(centralWidget());
75 GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
76 GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
77 GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
78 GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
80 GroupPattern = new DlgRef_3Radio(centralWidget());
81 GroupPattern->GroupBox1->setTitle(tr("GEOM_PATTERN"));
82 GroupPattern->RadioButton1->setText(tr("GEOM_SQUARE"));
83 GroupPattern->RadioButton2->setText(tr("GEOM_HEXAGON"));
84 GroupPattern->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
85 GroupPattern->RadioButton3->close();
87 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
88 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
89 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
90 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
91 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
92 GroupPntVecR->PushButton1->setIcon(imageSel);
93 GroupPntVecR->PushButton2->setIcon(imageSel);
94 GroupPntVecR->LineEdit1->setReadOnly(true);
95 GroupPntVecR->LineEdit2->setReadOnly(true);
96 //@@ setup dialog box layout here @@//
98 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
99 layout->setMargin(0); layout->setSpacing(6);
100 layout->addWidget(GroupParams);
101 layout->addWidget(GroupOrientation);
102 layout->addWidget(GroupPntVecR);
103 layout->addWidget(GroupPattern);
104 /***************************************************************/
106 setHelpFileName("create_divideddisk_page.html");
111 //=================================================================================
113 //=================================================================================
114 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
116 // no need to delete child widgets, Qt does it all for us
119 //=================================================================================
122 //=================================================================================
123 void AdvancedGUI_DividedDiskDlg::Init()
125 // Get setting of step value from file configuration
126 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
127 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
129 // min, max, step and decimals for spin boxes & initial values
130 initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
131 initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
132 GroupParams ->SpinBox_DX->setValue(100);
133 GroupPntVecR->SpinBox_DX->setValue(100);
135 GroupOrientation->RadioButton1->setChecked(true);
138 GroupPattern->RadioButton1->setChecked(true);
139 myPattern = GEOM::SQUARE;
141 // Signal/slot connections
142 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
145 this, SLOT(SetDoubleSpinBoxStep(double)));
147 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
156 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
157 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
159 connect(GroupPattern->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
160 connect(GroupPattern->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
162 initName(tr("GEOM_DIVIDEDDISK"));
164 ConstructorsClicked(0);
167 //=================================================================================
168 // function : SetDoubleSpinBoxStep()
169 // purpose : Double spin box management
170 //=================================================================================
171 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double step)
173 //@@ set double spin box step for all spin boxes here @@//
176 //=================================================================================
177 // function : ConstructorsClicked()
178 // purpose : Radio button management
179 //=================================================================================
180 void AdvancedGUI_DividedDiskDlg::ConstructorsClicked (int constructorId)
182 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
184 switch (constructorId) {
187 GroupPntVecR->hide();
189 GroupOrientation->show();
191 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
192 globalSelection(); // close local contexts, if any
198 GroupOrientation->hide();
199 GroupPntVecR->show();
201 GroupPntVecR->PushButton1->click();
206 qApp->processEvents();
208 resize(minimumSizeHint());
209 SelectionIntoArgument();
211 displayPreview(true);
214 //=================================================================================
215 // function : RadioButtonClicked()
216 // purpose : Radio button management
217 //=================================================================================
218 void AdvancedGUI_DividedDiskDlg::RadioButtonClicked()
220 QRadioButton* send = (QRadioButton*)sender();
223 if (send == GroupOrientation->RadioButton1)
225 else if ( send == GroupOrientation->RadioButton2)
227 else if ( send == GroupOrientation->RadioButton3)
231 else if (send == GroupPattern->RadioButton1)
232 myPattern = GEOM::SQUARE;
233 else if (send == GroupPattern->RadioButton2)
234 myPattern = GEOM::HEXAGON;
236 displayPreview(true);
239 //=================================================================================
240 // function : ClickOnOk()
242 //=================================================================================
243 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
263 //=================================================================================
264 // function : SelectionIntoArgument()
265 // purpose : Called when selection is changed or on dialog initialization or activation
266 //=================================================================================
267 void AdvancedGUI_DividedDiskDlg::SelectionIntoArgument()
269 if (getConstructorId() == 0)
273 myEditCurrentArgument->setText("");
275 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
276 SALOME_ListIO aSelList;
277 aSelMgr->selectedObjects(aSelList);
279 if (aSelList.Extent() != 1) {
280 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
281 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
285 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
286 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
288 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ){
289 QString aName = GEOMBase::GetName( aSelectedObject.get() );
291 myEditCurrentArgument->setText(aName);
294 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
295 myGeomGUI->getApp()->selectionMgr()->clearSelected();
296 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
297 this, SLOT(SelectionIntoArgument()));
299 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
300 myPoint = aSelectedObject;
301 if (myPoint && !myDir)
302 GroupPntVecR->PushButton2->click();
304 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
305 myDir = aSelectedObject;
306 if (myDir && !myPoint)
307 GroupPntVecR->PushButton1->click();
310 displayPreview(true);
313 //=================================================================================
314 // function : SetEditCurrentArgument()
316 //=================================================================================
317 void AdvancedGUI_DividedDiskDlg::SetEditCurrentArgument()
319 QPushButton* send = (QPushButton*)sender();
321 if (send == GroupPntVecR->PushButton1) {
322 myEditCurrentArgument = GroupPntVecR->LineEdit1;
324 GroupPntVecR->PushButton2->setDown(false);
325 GroupPntVecR->LineEdit2->setEnabled(false);
327 else if (send == GroupPntVecR->PushButton2) {
328 myEditCurrentArgument = GroupPntVecR->LineEdit2;
330 GroupPntVecR->PushButton1->setDown(false);
331 GroupPntVecR->LineEdit1->setEnabled(false);
334 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
335 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
336 globalSelection(); // close local contexts, if any
337 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
340 globalSelection(); // close local contexts, if any
341 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
343 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
344 this, SLOT(SelectionIntoArgument()));
347 myEditCurrentArgument->setEnabled(true);
348 myEditCurrentArgument->setFocus();
349 // after setFocus(), because it will be setDown(false) when loses focus
352 // seems we need it only to avoid preview disappearing, caused by selection mode change
353 displayPreview(true);
356 //=================================================================================
357 // function : ActivateThisDialog()
359 //=================================================================================
360 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
362 GEOMBase_Skeleton::ActivateThisDialog();
363 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
364 this, SLOT( SelectionIntoArgument() ) );
366 ConstructorsClicked( getConstructorId() );
369 //=================================================================================
370 // function : enterEvent [REDEFINED]
372 //=================================================================================
373 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
375 if (!mainFrame()->GroupConstructors->isEnabled())
376 ActivateThisDialog();
379 //=================================================================================
380 // function : ValueChangedInSpinBox()
382 //=================================================================================
383 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
385 displayPreview(true);
388 //=================================================================================
389 // function : createOperation
391 //=================================================================================
392 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
394 return getGeomEngine()->GetIAdvancedOperations(getStudyId());
397 //=================================================================================
398 // function : isValid
400 //=================================================================================
401 bool AdvancedGUI_DividedDiskDlg::isValid (QString& msg)
405 //@@ add custom validation actions here @@//
410 //=================================================================================
411 // function : execute
413 //=================================================================================
414 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
418 GEOM::GEOM_Object_var anObj;
420 GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
421 CORBA::Double theRatio = 67; // About 2/3
422 CORBA::Double theR = 0;
424 switch (getConstructorId()) {
426 theR = GroupParams->SpinBox_DX->value(); // init parameter value from dialog box ;
428 // call engine function
429 anObj = anOper->MakeDividedDisk(theR, theRatio, myOrientation, myPattern);
430 res = !anObj->_is_nil();
431 if (res && !IsPreview())
433 QStringList aParameters;
434 aParameters << GroupParams->SpinBox_DX->text();
435 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
439 theR = GroupPntVecR->SpinBox_DX->value();
441 // call engine function
442 anObj = anOper->MakeDividedDiskPntVecR(myPoint.get(), myDir.get(), theR, theRatio, myPattern);
443 res = !anObj->_is_nil();
444 if (res && !IsPreview())
446 QStringList aParameters;
447 aParameters << GroupPntVecR->SpinBox_DX->text();
448 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
455 objects.push_back(anObj._retn());