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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : PrimitiveGUI_TorusDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "PrimitiveGUI_TorusDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
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 const char* name, bool modal, WFlags fl)
57 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
58 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV")));
62 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ")));
63 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setCaption(tr("GEOM_TORUS_TITLE"));
67 /***************************************************************/
68 GroupConstructors->setTitle(tr("GEOM_TORUS"));
69 RadioButton1->setPixmap(image0);
70 RadioButton2->setPixmap(image1);
71 RadioButton3->close(TRUE);
73 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
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->setPixmap(image2);
80 GroupPoints->PushButton2->setPixmap(image2);
82 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
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 Layout1->addWidget(GroupPoints, 2, 0);
88 Layout1->addWidget(GroupDimensions, 2, 0);
89 /***************************************************************/
91 setHelpFileName("create_torus_page.html");
97 //=================================================================================
98 // function : ~PrimitiveGUI_TorusDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_TorusDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
115 GroupPoints->LineEdit1->setReadOnly( true );
116 GroupPoints->LineEdit2->setReadOnly( true );
118 myPoint = myDir = GEOM::GEOM_Object::_nil();
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
124 /* min, max, step and decimals for spin boxes & initial values */
125 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
126 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
127 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
128 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
130 GroupPoints->SpinBox_DX->SetValue(300.0);
131 GroupPoints->SpinBox_DY->SetValue(100.0);
132 GroupDimensions->SpinBox_DX->SetValue(300.0);
133 GroupDimensions->SpinBox_DY->SetValue(100.0);
135 /* signals and slots connections */
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
141 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
153 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
154 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
155 GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
157 GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
159 GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
161 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
162 this, SLOT(SelectionIntoArgument()));
164 initName( tr( "GEOM_TORUS" ) );
165 ConstructorsClicked(0);
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose : Radio button management
171 //=================================================================================
172 void PrimitiveGUI_TorusDlg::ConstructorsClicked (int constructorId)
174 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
176 switch (constructorId)
180 globalSelection(); // close local contexts, if any
181 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
183 GroupDimensions->hide();
187 myEditCurrentArgument = GroupPoints->LineEdit1;
188 GroupPoints->LineEdit1->setText(tr(""));
189 GroupPoints->LineEdit2->setText(tr(""));
190 myPoint = myDir = GEOM::GEOM_Object::_nil();
192 connect(myGeomGUI->getApp()->selectionMgr(),
193 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 SelectionIntoArgument();
201 globalSelection(); // close local contexts, if any
203 GroupDimensions->show();
213 //=================================================================================
214 // function : ClickOnOk()
216 //=================================================================================
217 void PrimitiveGUI_TorusDlg::ClickOnOk()
224 //=================================================================================
225 // function : ClickOnApply()
227 //=================================================================================
228 bool PrimitiveGUI_TorusDlg::ClickOnApply()
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
244 if (getConstructorId() != 0)
247 myEditCurrentArgument->setText("");
249 if (IObjectCount() != 1)
251 if (myEditCurrentArgument == GroupPoints->LineEdit1)
252 myPoint = GEOM::GEOM_Object::_nil();
253 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
254 myDir = GEOM::GEOM_Object::_nil();
259 Standard_Boolean testResult = Standard_False;
260 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult);
262 if (!testResult || CORBA::is_nil(aSelectedObject))
265 QString aName = GEOMBase::GetName(aSelectedObject);
267 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
269 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
270 if (myEditCurrentArgument == GroupPoints->LineEdit2)
271 aNeedType = TopAbs_EDGE;
273 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
274 TColStd_IndexedMapOfInteger aMap;
275 aSelMgr->GetIndexes(firstIObject(), aMap);
276 if (aMap.Extent() == 1) // Local Selection
278 int anIndex = aMap(1);
279 if (aNeedType == TopAbs_EDGE)
280 aName.append(":edge_" + QString::number(anIndex));
282 aName.append(":vertex_" + QString::number(anIndex));
284 //Find SubShape Object in Father
285 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
287 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
288 GEOM::GEOM_IShapesOperations_var aShapesOp =
289 getGeomEngine()->GetIShapesOperations( getStudyId() );
290 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
293 aSelectedObject = aFindedObject; // get Object from study
295 else // Global Selection
297 if (aShape.ShapeType() != aNeedType) {
298 aSelectedObject = GEOM::GEOM_Object::_nil();
304 myEditCurrentArgument->setText(aName);
306 if (myEditCurrentArgument == GroupPoints->LineEdit1)
307 myPoint = aSelectedObject;
308 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
309 myDir = aSelectedObject;
314 //=================================================================================
315 // function : LineEditReturnPressed()
317 //=================================================================================
318 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
320 QLineEdit* send = (QLineEdit*)sender();
321 if (send == GroupPoints->LineEdit1 ||
322 send == GroupPoints->LineEdit2)
324 myEditCurrentArgument = send;
325 GEOMBase_Skeleton::LineEditReturnPressed();
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
337 globalSelection( GEOM_POINT ); // to break previous local selection
339 if (send == GroupPoints->PushButton1) {
340 myEditCurrentArgument = GroupPoints->LineEdit1;
341 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
343 else if (send == GroupPoints->PushButton2) {
344 myEditCurrentArgument = GroupPoints->LineEdit2;
345 GEOM::GEOM_Object_var anObj;
346 localSelection( anObj, TopAbs_EDGE );
349 myEditCurrentArgument->setFocus();
350 SelectionIntoArgument();
354 //=================================================================================
355 // function : ActivateThisDialog()
357 //=================================================================================
358 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
360 GEOMBase_Skeleton::ActivateThisDialog();
362 connect(myGeomGUI->getApp()->selectionMgr(),
363 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
365 ConstructorsClicked( getConstructorId() );
369 //=================================================================================
370 // function : enterEvent()
372 //=================================================================================
373 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
375 if ( !GroupConstructors->isEnabled() )
376 ActivateThisDialog();
380 //=================================================================================
381 // function : ValueChangedInSpinBox
383 //=================================================================================
384 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
390 //=================================================================================
391 // function : createOperation
393 //=================================================================================
394 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
396 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
399 //=================================================================================
400 // function : isValid
402 //=================================================================================
403 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
405 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
408 //=================================================================================
409 // function : execute
411 //=================================================================================
412 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
416 GEOM::GEOM_Object_var anObj;
418 switch ( getConstructorId() )
422 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ))
424 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
425 MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
432 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
433 MakeTorusRR(getRadius1(), getRadius2());
439 if ( !anObj->_is_nil() )
440 objects.push_back( anObj._retn() );
445 //=================================================================================
446 // function : getRadius1()
448 //=================================================================================
449 double PrimitiveGUI_TorusDlg::getRadius1() const
451 int aConstructorId = getConstructorId();
452 if (aConstructorId == 0)
453 return GroupPoints->SpinBox_DX->GetValue();
454 else if (aConstructorId == 1)
455 return GroupDimensions->SpinBox_DX->GetValue();
459 //=================================================================================
460 // function : getRadius2()
462 //=================================================================================
463 double PrimitiveGUI_TorusDlg::getRadius2() const
465 int aConstructorId = getConstructorId();
466 if (aConstructorId == 0)
467 return GroupPoints->SpinBox_DY->GetValue();
468 else if (aConstructorId == 1)
469 return GroupDimensions->SpinBox_DY->GetValue();
473 //=================================================================================
474 // function : addSubshapeToStudy
475 // purpose : virtual method to add new SubObjects if local selection
476 //=================================================================================
477 void PrimitiveGUI_TorusDlg::addSubshapesToStudy()
479 QMap<QString, GEOM::GEOM_Object_var> objMap;
481 switch (getConstructorId())
484 objMap[GroupPoints->LineEdit1->text()] = myPoint;
485 objMap[GroupPoints->LineEdit2->text()] = myDir;
490 addSubshapesToFather( objMap );