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->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
83 GroupPattern->RadioButton3->close();
86 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
87 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
88 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
89 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
90 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
91 GroupPntVecR->PushButton1->setIcon(imageSel);
92 GroupPntVecR->PushButton2->setIcon(imageSel);
93 GroupPntVecR->LineEdit1->setReadOnly(true);
94 GroupPntVecR->LineEdit2->setReadOnly(true);
95 //@@ setup dialog box layout here @@//
97 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
98 layout->setMargin(0); layout->setSpacing(6);
99 layout->addWidget(GroupParams);
100 layout->addWidget(GroupOrientation);
101 layout->addWidget(GroupPntVecR);
102 layout->addWidget(GroupPattern);
103 /***************************************************************/
105 setHelpFileName("create_divideddisk_page.html");
110 //=================================================================================
112 //=================================================================================
113 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
115 // no need to delete child widgets, Qt does it all for us
118 //=================================================================================
121 //=================================================================================
122 void AdvancedGUI_DividedDiskDlg::Init()
124 // Get setting of step value from file configuration
125 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
126 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
128 // min, max, step and decimals for spin boxes & initial values
129 initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
130 initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
131 GroupParams ->SpinBox_DX->setValue(100);
132 GroupPntVecR->SpinBox_DX->setValue(100);
134 GroupOrientation->RadioButton1->setChecked(true);
137 GroupPattern->RadioButton1->setChecked(true);
138 myPattern = GEOM::SQUARE;
140 // Signal/slot connections
141 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
144 this, SLOT(SetDoubleSpinBoxStep(double)));
146 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
148 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
155 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
156 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
158 connect(GroupPattern->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
159 connect(GroupPattern->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
161 initName(tr("GEOM_DIVIDEDDISK"));
163 ConstructorsClicked(0);
166 //=================================================================================
167 // function : SetDoubleSpinBoxStep()
168 // purpose : Double spin box management
169 //=================================================================================
170 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double step)
172 //@@ set double spin box step for all spin boxes here @@//
175 //=================================================================================
176 // function : ConstructorsClicked()
177 // purpose : Radio button management
178 //=================================================================================
179 void AdvancedGUI_DividedDiskDlg::ConstructorsClicked (int constructorId)
181 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
183 switch (constructorId) {
186 GroupPntVecR->hide();
188 GroupOrientation->show();
190 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
191 globalSelection(); // close local contexts, if any
197 GroupOrientation->hide();
198 GroupPntVecR->show();
200 GroupPntVecR->PushButton1->click();
205 qApp->processEvents();
207 resize(minimumSizeHint());
208 SelectionIntoArgument();
210 displayPreview(true);
213 //=================================================================================
214 // function : RadioButtonClicked()
215 // purpose : Radio button management
216 //=================================================================================
217 void AdvancedGUI_DividedDiskDlg::RadioButtonClicked()
219 QRadioButton* send = (QRadioButton*)sender();
222 if (send == GroupOrientation->RadioButton1)
224 else if ( send == GroupOrientation->RadioButton2)
226 else if ( send == GroupOrientation->RadioButton3)
230 else if (send == GroupPattern->RadioButton1)
231 myPattern = GEOM::SQUARE;
232 else if (send == GroupPattern->RadioButton2)
233 myPattern = GEOM::HEXAGON;
235 displayPreview(true);
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
262 //=================================================================================
263 // function : SelectionIntoArgument()
264 // purpose : Called when selection is changed or on dialog initialization or activation
265 //=================================================================================
266 void AdvancedGUI_DividedDiskDlg::SelectionIntoArgument()
268 if (getConstructorId() == 0)
272 myEditCurrentArgument->setText("");
274 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
275 SALOME_ListIO aSelList;
276 aSelMgr->selectedObjects(aSelList);
278 if (aSelList.Extent() != 1) {
279 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
280 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
284 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
285 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
287 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ){
288 QString aName = GEOMBase::GetName( aSelectedObject.get() );
290 myEditCurrentArgument->setText(aName);
293 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
294 myGeomGUI->getApp()->selectionMgr()->clearSelected();
295 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
296 this, SLOT(SelectionIntoArgument()));
298 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
299 myPoint = aSelectedObject;
300 if (myPoint && !myDir)
301 GroupPntVecR->PushButton2->click();
303 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
304 myDir = aSelectedObject;
305 if (myDir && !myPoint)
306 GroupPntVecR->PushButton1->click();
309 displayPreview(true);
312 //=================================================================================
313 // function : SetEditCurrentArgument()
315 //=================================================================================
316 void AdvancedGUI_DividedDiskDlg::SetEditCurrentArgument()
318 QPushButton* send = (QPushButton*)sender();
320 if (send == GroupPntVecR->PushButton1) {
321 myEditCurrentArgument = GroupPntVecR->LineEdit1;
323 GroupPntVecR->PushButton2->setDown(false);
324 GroupPntVecR->LineEdit2->setEnabled(false);
326 else if (send == GroupPntVecR->PushButton2) {
327 myEditCurrentArgument = GroupPntVecR->LineEdit2;
329 GroupPntVecR->PushButton1->setDown(false);
330 GroupPntVecR->LineEdit1->setEnabled(false);
333 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
334 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
335 globalSelection(); // close local contexts, if any
336 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
339 globalSelection(); // close local contexts, if any
340 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
342 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
343 this, SLOT(SelectionIntoArgument()));
346 myEditCurrentArgument->setEnabled(true);
347 myEditCurrentArgument->setFocus();
348 // after setFocus(), because it will be setDown(false) when loses focus
351 // seems we need it only to avoid preview disappearing, caused by selection mode change
352 displayPreview(true);
355 //=================================================================================
356 // function : ActivateThisDialog()
358 //=================================================================================
359 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
361 GEOMBase_Skeleton::ActivateThisDialog();
362 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
363 this, SLOT( SelectionIntoArgument() ) );
365 ConstructorsClicked( getConstructorId() );
368 //=================================================================================
369 // function : enterEvent [REDEFINED]
371 //=================================================================================
372 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
374 if (!mainFrame()->GroupConstructors->isEnabled())
375 ActivateThisDialog();
378 //=================================================================================
379 // function : ValueChangedInSpinBox()
381 //=================================================================================
382 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
384 displayPreview(true);
387 //=================================================================================
388 // function : createOperation
390 //=================================================================================
391 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
393 return getGeomEngine()->GetIAdvancedOperations(getStudyId());
396 //=================================================================================
397 // function : isValid
399 //=================================================================================
400 bool AdvancedGUI_DividedDiskDlg::isValid (QString& msg)
404 //@@ add custom validation actions here @@//
409 //=================================================================================
410 // function : execute
412 //=================================================================================
413 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
417 GEOM::GEOM_Object_var anObj;
419 GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
420 CORBA::Double theRatio = 67; // About 2/3
421 CORBA::Double theR = 0;
423 switch (getConstructorId()) {
425 theR = GroupParams->SpinBox_DX->value(); // init parameter value from dialog box ;
427 // call engine function
428 anObj = anOper->MakeDividedDisk(theR, theRatio, myOrientation, myPattern);
429 res = !anObj->_is_nil();
430 if (res && !IsPreview())
432 QStringList aParameters;
433 aParameters << GroupParams->SpinBox_DX->text();
434 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
438 theR = GroupPntVecR->SpinBox_DX->value();
440 // call engine function
441 anObj = anOper->MakeDividedDiskPntVecR(myPoint.get(), myDir.get(), theR, theRatio, myPattern);
442 res = !anObj->_is_nil();
443 if (res && !IsPreview())
445 QStringList aParameters;
446 aParameters << GroupPntVecR->SpinBox_DX->text();
447 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
454 objects.push_back(anObj._retn());