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"
38 #include "GEOMImpl_Types.hxx"
40 #include "utilities.h"
42 //=================================================================================
43 // class : PrimitiveGUI_TorusDlg()
44 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50 const char* name, bool modal, WFlags fl)
51 : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
55 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_PV")));
56 QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TORUS_DXYZ")));
57 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setCaption(tr("GEOM_TORUS_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_TORUS"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
72 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
73 GroupPoints->PushButton1->setPixmap(image2);
74 GroupPoints->PushButton2->setPixmap(image2);
76 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
77 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
78 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
79 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
81 Layout1->addWidget(GroupPoints, 2, 0);
82 Layout1->addWidget(GroupDimensions, 2, 0);
83 /***************************************************************/
85 setHelpFileName("turus.htm");
91 //=================================================================================
92 // function : ~PrimitiveGUI_TorusDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
97 // no need to delete child widgets, Qt does it all for us
101 //=================================================================================
104 //=================================================================================
105 void PrimitiveGUI_TorusDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
110 GroupPoints->LineEdit2->setReadOnly( true );
112 myPoint = myDir = GEOM::GEOM_Object::_nil();
114 /* Get setting of step value from file configuration */
115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
118 /* min, max, step and decimals for spin boxes & initial values */
119 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
120 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
121 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
122 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY);
124 GroupPoints->SpinBox_DX->SetValue(300.0);
125 GroupPoints->SpinBox_DY->SetValue(100.0);
126 GroupDimensions->SpinBox_DX->SetValue(300.0);
127 GroupDimensions->SpinBox_DY->SetValue(100.0);
129 /* signals and slots connections */
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
135 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
144 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
147 GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
149 GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
151 GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
153 GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
155 connect(myGeomGUI->getApp()->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
158 initName( tr( "GEOM_TORUS" ) );
159 ConstructorsClicked(0);
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
169 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
171 switch (constructorId)
175 globalSelection( GEOM_POINT );
177 GroupDimensions->hide();
181 myEditCurrentArgument = GroupPoints->LineEdit1;
182 GroupPoints->LineEdit1->setText(tr(""));
183 GroupPoints->LineEdit2->setText(tr(""));
184 myPoint = myDir = GEOM::GEOM_Object::_nil();
186 connect(myGeomGUI->getApp()->selectionMgr(),
187 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188 SelectionIntoArgument();
196 GroupDimensions->show();
206 //=================================================================================
207 // function : ClickOnOk()
209 //=================================================================================
210 void PrimitiveGUI_TorusDlg::ClickOnOk()
212 if ( ClickOnApply() )
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 bool PrimitiveGUI_TorusDlg::ClickOnApply()
231 //=================================================================================
232 // function : SelectionIntoArgument()
233 // purpose : Called when selection as changed or other case
234 //=================================================================================
235 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
237 if ( getConstructorId() != 0 )
240 myEditCurrentArgument->setText("");
242 if (IObjectCount() != 1)
244 if (myEditCurrentArgument == GroupPoints->LineEdit1)
245 myPoint = GEOM::GEOM_Object::_nil();
246 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
247 myDir = GEOM::GEOM_Object::_nil();
252 Standard_Boolean testResult = Standard_False;
253 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
255 if (!testResult || CORBA::is_nil( aSelectedObject ))
258 if (myEditCurrentArgument == GroupPoints->LineEdit1)
259 myPoint = aSelectedObject;
260 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
261 myDir = aSelectedObject;
263 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
268 //=================================================================================
269 // function : LineEditReturnPressed()
271 //=================================================================================
272 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
274 QLineEdit* send = (QLineEdit*)sender();
275 if (send == GroupPoints->LineEdit1 ||
276 send == GroupPoints->LineEdit2)
278 myEditCurrentArgument = send;
279 GEOMBase_Skeleton::LineEditReturnPressed();
284 //=================================================================================
285 // function : SetEditCurrentArgument()
287 //=================================================================================
288 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
290 QPushButton* send = (QPushButton*)sender();
292 if (send == GroupPoints->PushButton1) {
293 myEditCurrentArgument = GroupPoints->LineEdit1;
294 globalSelection( GEOM_POINT );
296 else if (send == GroupPoints->PushButton2) {
297 myEditCurrentArgument = GroupPoints->LineEdit2;
298 globalSelection( GEOM_LINE );
301 myEditCurrentArgument->setFocus();
302 SelectionIntoArgument();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
314 connect(myGeomGUI->getApp()->selectionMgr(),
315 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
317 ConstructorsClicked( getConstructorId() );
321 //=================================================================================
322 // function : enterEvent()
324 //=================================================================================
325 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
327 if ( !GroupConstructors->isEnabled() )
328 ActivateThisDialog();
332 //=================================================================================
333 // function : ValueChangedInSpinBox
335 //=================================================================================
336 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
342 //=================================================================================
343 // function : createOperation
345 //=================================================================================
346 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
348 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
352 //=================================================================================
353 // function : isValid
355 //=================================================================================
356 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
358 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
362 //=================================================================================
363 // function : execute
365 //=================================================================================
366 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
370 GEOM::GEOM_Object_var anObj;
372 switch ( getConstructorId() )
376 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ))
378 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
379 MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
386 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
387 MakeTorusRR(getRadius1(), getRadius2());
393 if ( !anObj->_is_nil() )
394 objects.push_back( anObj._retn() );
400 //=================================================================================
401 // function : getRadius1()
403 //=================================================================================
404 double PrimitiveGUI_TorusDlg::getRadius1() const
406 int aConstructorId = getConstructorId();
407 if (aConstructorId == 0)
408 return GroupPoints->SpinBox_DX->GetValue();
409 else if (aConstructorId == 1)
410 return GroupDimensions->SpinBox_DX->GetValue();
415 //=================================================================================
416 // function : getRadius2()
418 //=================================================================================
419 double PrimitiveGUI_TorusDlg::getRadius2() const
421 int aConstructorId = getConstructorId();
422 if (aConstructorId == 0)
423 return GroupPoints->SpinBox_DY->GetValue();
424 else if (aConstructorId == 1)
425 return GroupDimensions->SpinBox_DY->GetValue();