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"
44 //=================================================================================
45 // class : PrimitiveGUI_TorusDlg()
46 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_TORUS_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_TORUS"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
71 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
72 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
73 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
74 GroupPoints->PushButton1->setPixmap(image2);
75 GroupPoints->PushButton2->setPixmap(image2);
77 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
78 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
79 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
80 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 Layout1->addWidget(GroupDimensions, 2, 0);
84 /***************************************************************/
86 setHelpFileName("turus.htm");
92 //=================================================================================
93 // function : ~PrimitiveGUI_TorusDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
98 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void PrimitiveGUI_TorusDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 GroupPoints->LineEdit1->setReadOnly( true );
111 GroupPoints->LineEdit2->setReadOnly( true );
113 myPoint = myDir = GEOM::GEOM_Object::_nil();
115 /* Get setting of step value from file configuration */
116 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
117 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
119 /* min, max, step and decimals for spin boxes & initial values */
120 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
121 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
122 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
123 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
125 GroupPoints->SpinBox_DX->SetValue(300.0);
126 GroupPoints->SpinBox_DY->SetValue(100.0);
127 GroupDimensions->SpinBox_DX->SetValue(300.0);
128 GroupDimensions->SpinBox_DY->SetValue(100.0);
130 /* signals and slots connections */
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 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)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
151 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
154 initName( tr( "GEOM_TORUS" ) );
155 ConstructorsClicked(0);
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose : Radio button management
162 //=================================================================================
163 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
165 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
167 switch(constructorId)
171 globalSelection( GEOM_LINE );
173 GroupDimensions->hide();
177 myEditCurrentArgument = GroupPoints->LineEdit1;
178 GroupPoints->LineEdit1->setText(tr(""));
179 GroupPoints->LineEdit2->setText(tr(""));
180 myPoint = myDir = GEOM::GEOM_Object::_nil();
182 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 GroupDimensions->show();
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void PrimitiveGUI_TorusDlg::ClickOnOk()
205 if ( ClickOnApply() )
210 //=================================================================================
211 // function : ClickOnApply()
213 //=================================================================================
214 bool PrimitiveGUI_TorusDlg::ClickOnApply()
220 ConstructorsClicked( getConstructorId() );
225 //=======================================================================
226 // function : ClickOnCancel()
228 //=======================================================================
229 void PrimitiveGUI_TorusDlg::ClickOnCancel()
231 GEOMBase_Skeleton::ClickOnCancel();
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose : Called when selection as changed or other case
238 //=================================================================================
239 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
241 if ( getConstructorId() != 0 )
244 myEditCurrentArgument->setText("");
246 if(IObjectCount() != 1)
248 if(myEditCurrentArgument == GroupPoints->LineEdit1)
249 myPoint = GEOM::GEOM_Object::_nil();
250 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
251 myDir = GEOM::GEOM_Object::_nil();
257 Standard_Boolean testResult = Standard_False;
258 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
260 if(!testResult || CORBA::is_nil( aSelectedObject ))
263 if(myEditCurrentArgument == GroupPoints->LineEdit1)
264 myPoint = aSelectedObject;
265 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
266 myDir = aSelectedObject;
268 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
279 QPushButton* send = (QPushButton*)sender();
281 if(send == GroupPoints->PushButton1) {
282 myEditCurrentArgument = GroupPoints->LineEdit1;
283 globalSelection( GEOM_POINT );
285 else if(send == GroupPoints->PushButton2) {
286 myEditCurrentArgument = GroupPoints->LineEdit2;
287 globalSelection( GEOM_LINE );
290 myEditCurrentArgument->setFocus();
291 SelectionIntoArgument();
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if(send == GroupPoints->LineEdit1 ||
303 send == GroupPoints->LineEdit2)
305 myEditCurrentArgument = send;
306 GEOMBase_Skeleton::LineEditReturnPressed();
311 //=================================================================================
312 // function : ActivateThisDialog()
314 //=================================================================================
315 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
317 GEOMBase_Skeleton::ActivateThisDialog();
318 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
319 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
321 ConstructorsClicked( getConstructorId() );
325 //=================================================================================
326 // function : enterEvent()
328 //=================================================================================
329 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
331 if ( !GroupConstructors->isEnabled() )
332 ActivateThisDialog();
336 //=================================================================================
337 // function : DeactivateActiveDialog()
338 // purpose : public slot to deactivate if active
339 //=================================================================================
340 void PrimitiveGUI_TorusDlg::DeactivateActiveDialog()
342 GEOMBase_Skeleton::DeactivateActiveDialog();
346 //=================================================================================
347 // function : ValueChangedInSpinBox
349 //=================================================================================
350 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
356 //=================================================================================
357 // function : createOperation
359 //=================================================================================
360 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
362 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
366 //=================================================================================
367 // function : isValid
369 //=================================================================================
370 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
372 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
376 //=================================================================================
377 // function : execute
379 //=================================================================================
380 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
384 GEOM::GEOM_Object_var anObj;
386 switch ( getConstructorId() )
390 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
391 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
398 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR(getRadius1(), getRadius2());
404 if ( !anObj->_is_nil() )
405 objects.push_back( anObj._retn() );
411 //=================================================================================
412 // function : closeEvent
414 //=================================================================================
415 void PrimitiveGUI_TorusDlg::closeEvent( QCloseEvent* e )
417 GEOMBase_Skeleton::closeEvent( e );
421 //=================================================================================
422 // function : getRadius1()
424 //=================================================================================
425 double PrimitiveGUI_TorusDlg::getRadius1() const
427 int aConstructorId = getConstructorId();
428 if (aConstructorId == 0)
429 return GroupPoints->SpinBox_DX->GetValue();
430 else if (aConstructorId == 1)
431 return GroupDimensions->SpinBox_DX->GetValue();
436 //=================================================================================
437 // function : getRadius2()
439 //=================================================================================
440 double PrimitiveGUI_TorusDlg::getRadius2() const
442 int aConstructorId = getConstructorId();
443 if (aConstructorId == 0)
444 return GroupPoints->SpinBox_DY->GetValue();
445 else if (aConstructorId == 1)
446 return GroupDimensions->SpinBox_DY->GetValue();