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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SalomeApp_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, const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
56 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_TORUS_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_TORUS"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
71 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
75 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
76 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
77 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
78 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
80 Layout1->addWidget(GroupPoints, 2, 0);
81 Layout1->addWidget(GroupDimensions, 2, 0);
82 /***************************************************************/
88 //=================================================================================
89 // function : ~PrimitiveGUI_TorusDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
94 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void PrimitiveGUI_TorusDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
109 myPoint = myDir = GEOM::GEOM_Object::_nil();
111 /* Get setting of step value from file configuration */
112 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
115 /* min, max, step and decimals for spin boxes & initial values */
116 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
117 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
118 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
119 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
121 GroupPoints->SpinBox_DX->SetValue(300.0);
122 GroupPoints->SpinBox_DY->SetValue(100.0);
123 GroupDimensions->SpinBox_DX->SetValue(300.0);
124 GroupDimensions->SpinBox_DY->SetValue(100.0);
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
138 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
139 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
140 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
143 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
144 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
145 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
147 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
148 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
150 initName( tr( "GEOM_TORUS" ) );
151 ConstructorsClicked(0);
156 //=================================================================================
157 // function : ConstructorsClicked()
158 // purpose : Radio button management
159 //=================================================================================
160 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
162 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
164 switch(constructorId)
168 globalSelection( GEOM_LINE );
170 GroupDimensions->hide();
174 myEditCurrentArgument = GroupPoints->LineEdit1;
175 GroupPoints->LineEdit1->setText(tr(""));
176 GroupPoints->LineEdit2->setText(tr(""));
177 myPoint = myDir = GEOM::GEOM_Object::_nil();
179 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
180 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
187 GroupDimensions->show();
196 //=================================================================================
197 // function : ClickOnOk()
199 //=================================================================================
200 void PrimitiveGUI_TorusDlg::ClickOnOk()
202 if ( ClickOnApply() )
207 //=================================================================================
208 // function : ClickOnApply()
210 //=================================================================================
211 bool PrimitiveGUI_TorusDlg::ClickOnApply()
217 ConstructorsClicked( getConstructorId() );
222 //=======================================================================
223 // function : ClickOnCancel()
225 //=======================================================================
226 void PrimitiveGUI_TorusDlg::ClickOnCancel()
228 GEOMBase_Skeleton::ClickOnCancel();
232 //=================================================================================
233 // function : SelectionIntoArgument()
234 // purpose : Called when selection as changed or other case
235 //=================================================================================
236 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
238 if ( getConstructorId() != 0 )
241 myEditCurrentArgument->setText("");
243 if(IObjectCount() != 1)
245 if(myEditCurrentArgument == GroupPoints->LineEdit1)
246 myPoint = GEOM::GEOM_Object::_nil();
247 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
248 myDir = GEOM::GEOM_Object::_nil();
254 Standard_Boolean testResult = Standard_False;
255 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
257 if(!testResult || CORBA::is_nil( aSelectedObject ))
260 if(myEditCurrentArgument == GroupPoints->LineEdit1)
261 myPoint = aSelectedObject;
262 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
263 myDir = aSelectedObject;
265 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
270 //=================================================================================
271 // function : SetEditCurrentArgument()
273 //=================================================================================
274 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
276 QPushButton* send = (QPushButton*)sender();
278 if(send == GroupPoints->PushButton1) {
279 myEditCurrentArgument = GroupPoints->LineEdit1;
280 globalSelection( GEOM_POINT );
282 else if(send == GroupPoints->PushButton2) {
283 myEditCurrentArgument = GroupPoints->LineEdit2;
284 globalSelection( GEOM_LINE );
287 myEditCurrentArgument->setFocus();
288 SelectionIntoArgument();
292 //=================================================================================
293 // function : LineEditReturnPressed()
295 //=================================================================================
296 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
298 QLineEdit* send = (QLineEdit*)sender();
299 if(send == GroupPoints->LineEdit1 ||
300 send == GroupPoints->LineEdit2)
302 myEditCurrentArgument = send;
303 GEOMBase_Skeleton::LineEditReturnPressed();
308 //=================================================================================
309 // function : ActivateThisDialog()
311 //=================================================================================
312 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
314 GEOMBase_Skeleton::ActivateThisDialog();
315 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
316 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
318 ConstructorsClicked( getConstructorId() );
322 //=================================================================================
323 // function : enterEvent()
325 //=================================================================================
326 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
328 if ( !GroupConstructors->isEnabled() )
329 ActivateThisDialog();
333 //=================================================================================
334 // function : DeactivateActiveDialog()
335 // purpose : public slot to deactivate if active
336 //=================================================================================
337 void PrimitiveGUI_TorusDlg::DeactivateActiveDialog()
339 GEOMBase_Skeleton::DeactivateActiveDialog();
343 //=================================================================================
344 // function : ValueChangedInSpinBox
346 //=================================================================================
347 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
359 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
363 //=================================================================================
364 // function : isValid
366 //=================================================================================
367 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
369 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
373 //=================================================================================
374 // function : execute
376 //=================================================================================
377 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
381 GEOM::GEOM_Object_var anObj;
383 switch ( getConstructorId() )
387 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
388 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
395 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR(getRadius1(), getRadius2());
401 if ( !anObj->_is_nil() )
402 objects.push_back( anObj._retn() );
408 //=================================================================================
409 // function : closeEvent
411 //=================================================================================
412 void PrimitiveGUI_TorusDlg::closeEvent( QCloseEvent* e )
414 GEOMBase_Skeleton::closeEvent( e );
418 //=================================================================================
419 // function : getRadius1()
421 //=================================================================================
422 double PrimitiveGUI_TorusDlg::getRadius1() const
424 int aConstructorId = getConstructorId();
425 if (aConstructorId == 0)
426 return GroupPoints->SpinBox_DX->GetValue();
427 else if (aConstructorId == 1)
428 return GroupDimensions->SpinBox_DX->GetValue();
433 //=================================================================================
434 // function : getRadius2()
436 //=================================================================================
437 double PrimitiveGUI_TorusDlg::getRadius2() const
439 int aConstructorId = getConstructorId();
440 if (aConstructorId == 0)
441 return GroupPoints->SpinBox_DY->GetValue();
442 else if (aConstructorId == 1)
443 return GroupDimensions->SpinBox_DY->GetValue();