1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : PrimitiveGUI_TorusDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "PrimitiveGUI_TorusDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
48 //=================================================================================
49 // class : PrimitiveGUI_TorusDlg()
50 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56 bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_TORUS_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_TORUS"));
68 mainFrame()->RadioButton1->setIcon(image0);
69 mainFrame()->RadioButton2->setIcon(image1);
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
73 GroupPoints = new DlgRef_2Sel2Spin(centralWidget());
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
77 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg(1));
78 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg(2));
79 GroupPoints->PushButton1->setIcon(image2);
80 GroupPoints->PushButton2->setIcon(image2);
82 GroupDimensions = new DlgRef_2Spin(centralWidget());
83 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
84 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg(1));
85 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg(2));
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(GroupPoints);
90 layout->addWidget(GroupDimensions);
91 /***************************************************************/
93 setHelpFileName("create_torus_page.html");
98 //=================================================================================
99 // function : ~PrimitiveGUI_TorusDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
104 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_TorusDlg::Init()
113 // Get setting of step value from file configuration
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
117 // min, max, step and decimals for spin boxes & initial values
118 initSpinBox(GroupPoints->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
119 initSpinBox(GroupPoints->SpinBox_DY, 0.000001, COORD_MAX, step, "length_precision" );
120 initSpinBox(GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
121 initSpinBox(GroupDimensions->SpinBox_DY, 0.000001, COORD_MAX, step, "length_precision" );
124 GroupPoints->LineEdit1->setReadOnly(true);
125 GroupPoints->LineEdit2->setReadOnly(true);
127 GroupPoints->LineEdit1->setText("");
128 GroupPoints->LineEdit2->setText("");
129 myPoint = myDir = GEOM::GEOM_Object::_nil();
131 GroupPoints->SpinBox_DX->setValue(300.0);
132 GroupPoints->SpinBox_DY->setValue(100.0);
133 GroupDimensions->SpinBox_DX->setValue(300.0);
134 GroupDimensions->SpinBox_DY->setValue(100.0);
136 // signals and slots connections
137 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
142 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
155 initName(tr("GEOM_TORUS"));
157 setConstructorId(1); // simplest constructor
158 ConstructorsClicked(1);
161 //=================================================================================
162 // function : SetDoubleSpinBoxStep()
163 // purpose : Double spin box management
164 //=================================================================================
165 void PrimitiveGUI_TorusDlg::SetDoubleSpinBoxStep (double step)
167 GroupPoints->SpinBox_DX->setSingleStep(step);
168 GroupPoints->SpinBox_DY->setSingleStep(step);
169 GroupDimensions->SpinBox_DX->setSingleStep(step);
170 GroupDimensions->SpinBox_DY->setSingleStep(step);
173 //=================================================================================
174 // function : ConstructorsClicked()
175 // purpose : Radio button management
176 //=================================================================================
177 void PrimitiveGUI_TorusDlg::ConstructorsClicked (int constructorId)
179 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
181 switch (constructorId) {
184 GroupDimensions->hide();
187 GroupPoints->PushButton1->click();
193 GroupDimensions->show();
194 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
195 globalSelection(); // close local contexts, if any
200 qApp->processEvents();
202 resize(minimumSizeHint());
203 SelectionIntoArgument();
208 //=================================================================================
209 // function : ClickOnOk()
211 //=================================================================================
212 void PrimitiveGUI_TorusDlg::ClickOnOk()
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 bool PrimitiveGUI_TorusDlg::ClickOnApply()
228 // activate selection and connect selection manager
229 ConstructorsClicked(getConstructorId());
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection is changed or on dialog initialization or activation
236 //=================================================================================
237 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
239 if (getConstructorId() != 0)
243 myEditCurrentArgument->setText("");
245 if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint = GEOM::GEOM_Object::_nil();
246 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myDir = GEOM::GEOM_Object::_nil();
248 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
249 SALOME_ListIO aSelList;
250 aSelMgr->selectedObjects(aSelList);
252 if (aSelList.Extent() != 1)
256 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
258 if ( CORBA::is_nil(aSelectedObject) )
261 QString aName = GEOMBase::GetName(aSelectedObject);
263 // Get Selected object if selected subshape
265 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
267 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
268 if (myEditCurrentArgument == GroupPoints->LineEdit2)
269 aNeedType = TopAbs_EDGE;
271 TColStd_IndexedMapOfInteger aMap;
272 aSelMgr->GetIndexes(aSelList.First(), aMap);
273 if (aMap.Extent() == 1) { // Local Selection
274 int anIndex = aMap(1);
275 if (aNeedType == TopAbs_EDGE)
276 aName.append(":edge_" + QString::number(anIndex));
278 aName.append(":vertex_" + QString::number(anIndex));
280 //Find SubShape Object in Father
281 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
283 if (aFindedObject->_is_nil()) { // Object not found in study
284 GEOM::GEOM_IShapesOperations_var aShapesOp =
285 getGeomEngine()->GetIShapesOperations(getStudyId());
286 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
289 aSelectedObject = aFindedObject; // get Object from study
292 else { // Global Selection
293 if (aShape.ShapeType() != aNeedType) {
294 aSelectedObject = GEOM::GEOM_Object::_nil();
300 myEditCurrentArgument->setText(aName);
303 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
304 myGeomGUI->getApp()->selectionMgr()->clearSelected();
305 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
306 this, SLOT(SelectionIntoArgument()));
308 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
309 myPoint = aSelectedObject;
310 if (!myPoint->_is_nil() && myDir->_is_nil())
311 GroupPoints->PushButton2->click();
313 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
314 myDir = aSelectedObject;
315 if (!myDir->_is_nil() && myPoint->_is_nil())
316 GroupPoints->PushButton1->click();
322 //=================================================================================
323 // function : SetEditCurrentArgument()
325 //=================================================================================
326 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
328 QPushButton* send = (QPushButton*)sender();
330 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
331 if (send == GroupPoints->PushButton1) {
332 myEditCurrentArgument = GroupPoints->LineEdit1;
334 GroupPoints->PushButton2->setDown(false);
335 GroupPoints->LineEdit2->setEnabled(false);
337 globalSelection(GEOM_POINT); // to break previous local selection
338 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
340 else if (send == GroupPoints->PushButton2) {
341 myEditCurrentArgument = GroupPoints->LineEdit2;
343 GroupPoints->PushButton1->setDown(false);
344 GroupPoints->LineEdit1->setEnabled(false);
346 globalSelection(GEOM_LINE); // to break previous local selection
347 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
349 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
350 this, SLOT(SelectionIntoArgument()));
353 myEditCurrentArgument->setEnabled(true);
354 myEditCurrentArgument->setFocus();
355 // after setFocus(), because it will be setDown(false) when loses focus
358 // seems we need it only to avoid preview disappearing, caused by selection mode change
362 //=================================================================================
363 // function : LineEditReturnPressed()
365 //=================================================================================
366 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
368 QLineEdit* send = (QLineEdit*)sender();
369 if (send == GroupPoints->LineEdit1 ||
370 send == GroupPoints->LineEdit2) {
371 myEditCurrentArgument = send;
372 GEOMBase_Skeleton::LineEditReturnPressed();
376 //=================================================================================
377 // function : ActivateThisDialog()
379 //=================================================================================
380 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
382 GEOMBase_Skeleton::ActivateThisDialog();
384 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
385 this, SLOT( SelectionIntoArgument() ) );
387 ConstructorsClicked( getConstructorId() );
390 //=================================================================================
391 // function : enterEvent()
393 //=================================================================================
394 void PrimitiveGUI_TorusDlg::enterEvent (QEvent*)
396 if (!mainFrame()->GroupConstructors->isEnabled())
397 ActivateThisDialog();
400 //=================================================================================
401 // function : ValueChangedInSpinBox()
403 //=================================================================================
404 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
409 //=================================================================================
410 // function : createOperation
412 //=================================================================================
413 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
415 return getGeomEngine()->GetI3DPrimOperations(getStudyId());
418 //=================================================================================
419 // function : isValid
421 //=================================================================================
422 bool PrimitiveGUI_TorusDlg::isValid (QString& msg)
425 if( getConstructorId() == 0 )
427 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
428 ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
430 else if( getConstructorId() == 1 )
432 ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
433 ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
435 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) && ok : ok;
438 //=================================================================================
439 // function : execute
441 //=================================================================================
442 bool PrimitiveGUI_TorusDlg::execute (ObjectList& objects)
446 GEOM::GEOM_Object_var anObj;
448 GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
450 switch (getConstructorId()) {
452 if (!CORBA::is_nil(myPoint) && !CORBA::is_nil(myDir)) {
453 anObj = anOper->MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
454 if (!anObj->_is_nil() && !IsPreview())
456 QStringList aParameters;
457 aParameters << GroupPoints->SpinBox_DX->text();
458 aParameters << GroupPoints->SpinBox_DY->text();
459 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
465 anObj = anOper->MakeTorusRR(getRadius1(), getRadius2());
466 if (!anObj->_is_nil() && !IsPreview())
468 QStringList aParameters;
469 aParameters << GroupDimensions->SpinBox_DX->text();
470 aParameters << GroupDimensions->SpinBox_DY->text();
471 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
477 if (!anObj->_is_nil())
478 objects.push_back(anObj._retn());
483 //=================================================================================
484 // function : getRadius1()
486 //=================================================================================
487 double PrimitiveGUI_TorusDlg::getRadius1() const
489 int aConstructorId = getConstructorId();
490 if (aConstructorId == 0)
491 return GroupPoints->SpinBox_DX->value();
492 else if (aConstructorId == 1)
493 return GroupDimensions->SpinBox_DX->value();
497 //=================================================================================
498 // function : getRadius2()
500 //=================================================================================
501 double PrimitiveGUI_TorusDlg::getRadius2() const
503 int aConstructorId = getConstructorId();
504 if (aConstructorId == 0)
505 return GroupPoints->SpinBox_DY->value();
506 else if (aConstructorId == 1)
507 return GroupDimensions->SpinBox_DY->value();
511 //=================================================================================
512 // function : addSubshapeToStudy
513 // purpose : virtual method to add new SubObjects if local selection
514 //=================================================================================
515 void PrimitiveGUI_TorusDlg::addSubshapesToStudy()
517 QMap<QString, GEOM::GEOM_Object_var> objMap;
519 switch (getConstructorId()) {
521 objMap[GroupPoints->LineEdit1->text()] = myPoint;
522 objMap[GroupPoints->LineEdit2->text()] = myDir;
527 addSubshapesToFather(objMap);