1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : PrimitiveGUI_TorusDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_TorusDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
49 //=================================================================================
50 // class : PrimitiveGUI_TorusDlg()
51 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57 const char* name, bool modal, WFlags fl)
58 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
59 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
62 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV")));
63 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ")));
64 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
66 setCaption(tr("GEOM_TORUS_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_TORUS"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->setPixmap(image1);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
78 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
79 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
80 GroupPoints->PushButton1->setPixmap(image2);
81 GroupPoints->PushButton2->setPixmap(image2);
83 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
84 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
85 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
86 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
88 Layout1->addWidget(GroupPoints, 2, 0);
89 Layout1->addWidget(GroupDimensions, 2, 0);
90 /***************************************************************/
92 setHelpFileName("turus.htm");
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
108 //=================================================================================
111 //=================================================================================
112 void PrimitiveGUI_TorusDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
116 GroupPoints->LineEdit1->setReadOnly( true );
117 GroupPoints->LineEdit2->setReadOnly( true );
119 myPoint = myDir = GEOM::GEOM_Object::_nil();
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
125 /* min, max, step and decimals for spin boxes & initial values */
126 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
127 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
128 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
129 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
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(GroupConstructors, SIGNAL(clicked(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)),
154 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
156 GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
158 GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
160 GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
162 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
163 this, SLOT(SelectionIntoArgument()));
165 initName( tr( "GEOM_TORUS" ) );
166 ConstructorsClicked(0);
169 //=================================================================================
170 // function : ConstructorsClicked()
171 // purpose : Radio button management
172 //=================================================================================
173 void PrimitiveGUI_TorusDlg::ConstructorsClicked (int constructorId)
175 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
177 switch (constructorId)
181 globalSelection(); // close local contexts, if any
182 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
184 GroupDimensions->hide();
188 myEditCurrentArgument = GroupPoints->LineEdit1;
189 GroupPoints->LineEdit1->setText(tr(""));
190 GroupPoints->LineEdit2->setText(tr(""));
191 myPoint = myDir = GEOM::GEOM_Object::_nil();
193 connect(myGeomGUI->getApp()->selectionMgr(),
194 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195 SelectionIntoArgument();
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 GEOM::GEOM_IShapesOperations_var aShapesOp =
279 getGeomEngine()->GetIShapesOperations( getStudyId() );
280 int anIndex = aMap(1);
282 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
283 aSelMgr->clearSelected();
285 if (aNeedType == TopAbs_EDGE)
286 aName.append(":edge_" + QString::number(anIndex));
288 aName.append(":vertex_" + QString::number(anIndex));
290 else // Global Selection
292 if (aShape.ShapeType() != aNeedType) {
293 aSelectedObject = GEOM::GEOM_Object::_nil();
299 myEditCurrentArgument->setText(aName);
301 if (myEditCurrentArgument == GroupPoints->LineEdit1)
302 myPoint = aSelectedObject;
303 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
304 myDir = aSelectedObject;
309 //=================================================================================
310 // function : LineEditReturnPressed()
312 //=================================================================================
313 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
315 QLineEdit* send = (QLineEdit*)sender();
316 if (send == GroupPoints->LineEdit1 ||
317 send == GroupPoints->LineEdit2)
319 myEditCurrentArgument = send;
320 GEOMBase_Skeleton::LineEditReturnPressed();
325 //=================================================================================
326 // function : SetEditCurrentArgument()
328 //=================================================================================
329 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
331 QPushButton* send = (QPushButton*)sender();
332 globalSelection( GEOM_POINT ); // to break previous local selection
334 if (send == GroupPoints->PushButton1) {
335 myEditCurrentArgument = GroupPoints->LineEdit1;
336 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
338 else if (send == GroupPoints->PushButton2) {
339 myEditCurrentArgument = GroupPoints->LineEdit2;
340 GEOM::GEOM_Object_var anObj;
341 localSelection( anObj, TopAbs_EDGE );
344 myEditCurrentArgument->setFocus();
345 SelectionIntoArgument();
349 //=================================================================================
350 // function : ActivateThisDialog()
352 //=================================================================================
353 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
355 GEOMBase_Skeleton::ActivateThisDialog();
357 connect(myGeomGUI->getApp()->selectionMgr(),
358 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
360 ConstructorsClicked( getConstructorId() );
364 //=================================================================================
365 // function : enterEvent()
367 //=================================================================================
368 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
370 if ( !GroupConstructors->isEnabled() )
371 ActivateThisDialog();
375 //=================================================================================
376 // function : ValueChangedInSpinBox
378 //=================================================================================
379 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
385 //=================================================================================
386 // function : createOperation
388 //=================================================================================
389 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
391 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
394 //=================================================================================
395 // function : isValid
397 //=================================================================================
398 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
400 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
403 //=================================================================================
404 // function : execute
406 //=================================================================================
407 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
411 GEOM::GEOM_Object_var anObj;
413 switch ( getConstructorId() )
417 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ))
419 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
420 MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
427 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
428 MakeTorusRR(getRadius1(), getRadius2());
434 if ( !anObj->_is_nil() )
435 objects.push_back( anObj._retn() );
440 //=================================================================================
441 // function : getRadius1()
443 //=================================================================================
444 double PrimitiveGUI_TorusDlg::getRadius1() const
446 int aConstructorId = getConstructorId();
447 if (aConstructorId == 0)
448 return GroupPoints->SpinBox_DX->GetValue();
449 else if (aConstructorId == 1)
450 return GroupDimensions->SpinBox_DX->GetValue();
454 //=================================================================================
455 // function : getRadius2()
457 //=================================================================================
458 double PrimitiveGUI_TorusDlg::getRadius2() const
460 int aConstructorId = getConstructorId();
461 if (aConstructorId == 0)
462 return GroupPoints->SpinBox_DY->GetValue();
463 else if (aConstructorId == 1)
464 return GroupDimensions->SpinBox_DY->GetValue();