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>
42 //=================================================================================
44 //=================================================================================
45 AdvancedGUI_DividedDiskDlg::AdvancedGUI_DividedDiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
48 // QPixmap imageOp (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDDISK_R_RATIO")));
49 QPixmap imageOp1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
50 QPixmap imageOp2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
51 QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setWindowTitle(tr("GEOM_DIVIDEDDISK_TITLE"));
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDDISK"));
57 mainFrame()->RadioButton1->setIcon(imageOp1);
58 mainFrame()->RadioButton2->setIcon(imageOp2);
59 // mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
60 // mainFrame()->RadioButton2->close();
61 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
62 mainFrame()->RadioButton3->close();
64 GroupParams = new DlgRef_1Spin(centralWidget());
65 GroupParams->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupParams->TextLabel1->setText(tr("GEOM_RADIUS"));
68 GroupOrientation = new DlgRef_3Radio(centralWidget());
69 GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
70 GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
71 GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
72 GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
74 GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
75 GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
77 GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
78 GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
79 GroupPntVecR->PushButton1->setIcon(imageSel);
80 GroupPntVecR->PushButton2->setIcon(imageSel);
81 GroupPntVecR->LineEdit1->setReadOnly(true);
82 GroupPntVecR->LineEdit2->setReadOnly(true);
83 //@@ setup dialog box layout here @@//
85 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86 layout->setMargin(0); layout->setSpacing(6);
87 layout->addWidget(GroupParams);
88 layout->addWidget(GroupOrientation);
89 layout->addWidget(GroupPntVecR);
90 /***************************************************************/
92 setHelpFileName("create_divideddisk_page.html");
97 //=================================================================================
99 //=================================================================================
100 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
102 // no need to delete child widgets, Qt does it all for us
105 //=================================================================================
108 //=================================================================================
109 void AdvancedGUI_DividedDiskDlg::Init()
111 // Get setting of step value from file configuration
112 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
115 // min, max, step and decimals for spin boxes & initial values
116 initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
117 GroupParams ->SpinBox_DX->setValue(100);
118 GroupPntVecR->SpinBox_DX->setValue(100);
120 GroupOrientation->RadioButton1->setChecked(true);
123 // Signal/slot connections
124 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
127 this, SLOT(SetDoubleSpinBoxStep(double)));
129 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
131 connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
135 connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
137 connect(GroupOrientation->RadioButton1, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
138 connect(GroupOrientation->RadioButton2, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
139 connect(GroupOrientation->RadioButton3, SIGNAL(clicked()), this, SLOT(RadioButtonClicked()));
141 initName(tr("GEOM_DIVIDEDDISK"));
143 ConstructorsClicked(0);
146 //=================================================================================
147 // function : SetDoubleSpinBoxStep()
148 // purpose : Double spin box management
149 //=================================================================================
150 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double step)
152 //@@ set double spin box step for all spin boxes here @@//
155 //=================================================================================
156 // function : ConstructorsClicked()
157 // purpose : Radio button management
158 //=================================================================================
159 void AdvancedGUI_DividedDiskDlg::ConstructorsClicked (int constructorId)
161 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
163 switch (constructorId) {
166 GroupPntVecR->hide();
168 GroupOrientation->show();
170 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
171 globalSelection(); // close local contexts, if any
177 GroupOrientation->hide();
178 GroupPntVecR->show();
180 GroupPntVecR->PushButton1->click();
185 qApp->processEvents();
187 resize(minimumSizeHint());
188 SelectionIntoArgument();
190 displayPreview(true);
193 //=================================================================================
194 // function : RadioButtonClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void AdvancedGUI_DividedDiskDlg::RadioButtonClicked()
199 if (GroupOrientation->RadioButton1->isChecked())
201 else if (GroupOrientation->RadioButton2->isChecked())
203 else if (GroupOrientation->RadioButton3->isChecked())
206 displayPreview(true);
209 //=================================================================================
210 // function : ClickOnOk()
212 //=================================================================================
213 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection is changed or on dialog initialization or activation
236 //=================================================================================
237 void AdvancedGUI_DividedDiskDlg::SelectionIntoArgument()
239 if (getConstructorId() == 0)
243 myEditCurrentArgument->setText("");
245 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
246 SALOME_ListIO aSelList;
247 aSelMgr->selectedObjects(aSelList);
249 if (aSelList.Extent() != 1) {
250 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
251 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
255 TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
256 GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
258 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ){
259 QString aName = GEOMBase::GetName( aSelectedObject.get() );
261 myEditCurrentArgument->setText(aName);
264 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
265 myGeomGUI->getApp()->selectionMgr()->clearSelected();
266 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
267 this, SLOT(SelectionIntoArgument()));
269 if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
270 myPoint = aSelectedObject;
271 if (myPoint && !myDir)
272 GroupPntVecR->PushButton2->click();
274 else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
275 myDir = aSelectedObject;
276 if (myDir && !myPoint)
277 GroupPntVecR->PushButton1->click();
280 displayPreview(true);
283 //=================================================================================
284 // function : SetEditCurrentArgument()
286 //=================================================================================
287 void AdvancedGUI_DividedDiskDlg::SetEditCurrentArgument()
289 QPushButton* send = (QPushButton*)sender();
291 if (send == GroupPntVecR->PushButton1) {
292 myEditCurrentArgument = GroupPntVecR->LineEdit1;
294 GroupPntVecR->PushButton2->setDown(false);
295 GroupPntVecR->LineEdit2->setEnabled(false);
297 else if (send == GroupPntVecR->PushButton2) {
298 myEditCurrentArgument = GroupPntVecR->LineEdit2;
300 GroupPntVecR->PushButton1->setDown(false);
301 GroupPntVecR->LineEdit1->setEnabled(false);
304 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
305 if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
306 globalSelection(); // close local contexts, if any
307 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
310 globalSelection(); // close local contexts, if any
311 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
313 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
314 this, SLOT(SelectionIntoArgument()));
317 myEditCurrentArgument->setEnabled(true);
318 myEditCurrentArgument->setFocus();
319 // after setFocus(), because it will be setDown(false) when loses focus
322 // seems we need it only to avoid preview disappearing, caused by selection mode change
323 displayPreview(true);
326 //=================================================================================
327 // function : ActivateThisDialog()
329 //=================================================================================
330 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
332 GEOMBase_Skeleton::ActivateThisDialog();
333 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
334 this, SLOT( SelectionIntoArgument() ) );
336 ConstructorsClicked( getConstructorId() );
339 //=================================================================================
340 // function : enterEvent [REDEFINED]
342 //=================================================================================
343 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
345 if (!mainFrame()->GroupConstructors->isEnabled())
346 ActivateThisDialog();
349 //=================================================================================
350 // function : ValueChangedInSpinBox()
352 //=================================================================================
353 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
355 displayPreview(true);
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
364 return getGeomEngine()->GetIAdvancedOperations(getStudyId());
367 //=================================================================================
368 // function : isValid
370 //=================================================================================
371 bool AdvancedGUI_DividedDiskDlg::isValid (QString& msg)
375 //@@ add custom validation actions here @@//
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
388 GEOM::GEOM_Object_var anObj;
390 GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
391 CORBA::Double theRatio = 50;
392 CORBA::Double theR = 0;
394 switch (getConstructorId()) {
396 theR = GroupParams->SpinBox_DX->value(); // init parameter value from dialog box ;
398 // call engine function
399 anObj = anOper->MakeDividedDisk(theR, theRatio, myOrientation);
400 res = !anObj->_is_nil();
401 if (res && !IsPreview())
403 QStringList aParameters;
404 aParameters << GroupParams->SpinBox_DX->text();
405 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
409 theR = GroupPntVecR->SpinBox_DX->value();
411 // call engine function
412 anObj = anOper->MakeDividedDiskPntVecR(myPoint.get(), myDir.get(), theR, theRatio);
413 res = !anObj->_is_nil();
414 if (res && !IsPreview())
416 QStringList aParameters;
417 aParameters << GroupPntVecR->SpinBox_DX->text();
418 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
425 objects.push_back(anObj._retn());