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"
30 #include "DlgRef_2Sel2Spin.h"
31 #include "DlgRef_2Spin.h"
32 #include "DlgRef_SpinBox.h"
34 #include "GeometryGUI.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SUIT_Session.h"
39 #include "SalomeApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
42 #include "GEOMImpl_Types.hxx"
46 //=================================================================================
47 // class : PrimitiveGUI_TorusDlg()
48 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, Qt::WindowFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_TORUS_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_TORUS"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
75 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
76 GroupPoints->PushButton1->setIcon(image2);
77 GroupPoints->PushButton2->setIcon(image2);
79 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
80 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
81 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
82 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
84 gridLayout1->addWidget(GroupPoints, 2, 0);
85 gridLayout1->addWidget(GroupDimensions, 2, 0);
86 /***************************************************************/
88 setHelpFileName("turus.htm");
94 //=================================================================================
95 // function : ~PrimitiveGUI_TorusDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
100 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_TorusDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
112 GroupPoints->LineEdit1->setReadOnly( true );
113 GroupPoints->LineEdit2->setReadOnly( true );
115 myPoint = myDir = GEOM::GEOM_Object::_nil();
117 /* Get setting of step value from file configuration */
118 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
119 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
121 /* min, max, step and decimals for spin boxes & initial values */
122 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
123 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
124 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
125 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, step, 3);
127 GroupPoints->SpinBox_DX->SetValue(300.0);
128 GroupPoints->SpinBox_DY->SetValue(100.0);
129 GroupDimensions->SpinBox_DX->SetValue(300.0);
130 GroupDimensions->SpinBox_DY->SetValue(100.0);
132 /* signals and slots connections */
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
144 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
150 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
153 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
154 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
156 initName( tr( "GEOM_TORUS" ).toStdString().c_str() );
157 ConstructorsClicked(0);
161 //=================================================================================
162 // function : ConstructorsClicked()
163 // purpose : Radio button management
164 //=================================================================================
165 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
167 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
169 switch(constructorId)
173 globalSelection( GEOM_LINE );
175 GroupDimensions->hide();
179 myEditCurrentArgument = GroupPoints->LineEdit1;
180 GroupPoints->LineEdit1->setText(tr(""));
181 GroupPoints->LineEdit2->setText(tr(""));
182 myPoint = myDir = GEOM::GEOM_Object::_nil();
184 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
185 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
192 GroupDimensions->show();
201 //=================================================================================
202 // function : ClickOnOk()
204 //=================================================================================
205 void PrimitiveGUI_TorusDlg::ClickOnOk()
207 if ( ClickOnApply() )
212 //=================================================================================
213 // function : ClickOnApply()
215 //=================================================================================
216 bool PrimitiveGUI_TorusDlg::ClickOnApply()
222 ConstructorsClicked( getConstructorId() );
227 //=======================================================================
228 // function : ClickOnCancel()
230 //=======================================================================
231 void PrimitiveGUI_TorusDlg::ClickOnCancel()
233 GEOMBase_Skeleton::ClickOnCancel();
237 //=================================================================================
238 // function : SelectionIntoArgument()
239 // purpose : Called when selection as changed or other case
240 //=================================================================================
241 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
243 if ( getConstructorId() != 0 )
246 myEditCurrentArgument->setText("");
248 if(IObjectCount() != 1)
250 if(myEditCurrentArgument == GroupPoints->LineEdit1)
251 myPoint = GEOM::GEOM_Object::_nil();
252 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
253 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 if(myEditCurrentArgument == GroupPoints->LineEdit1)
266 myPoint = aSelectedObject;
267 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
268 myDir = aSelectedObject;
270 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
275 //=================================================================================
276 // function : SetEditCurrentArgument()
278 //=================================================================================
279 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
281 QPushButton* send = (QPushButton*)sender();
283 if(send == GroupPoints->PushButton1) {
284 myEditCurrentArgument = GroupPoints->LineEdit1;
285 globalSelection( GEOM_POINT );
287 else if(send == GroupPoints->PushButton2) {
288 myEditCurrentArgument = GroupPoints->LineEdit2;
289 globalSelection( GEOM_LINE );
292 myEditCurrentArgument->setFocus();
293 SelectionIntoArgument();
297 //=================================================================================
298 // function : LineEditReturnPressed()
300 //=================================================================================
301 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
303 QLineEdit* send = (QLineEdit*)sender();
304 if(send == GroupPoints->LineEdit1 ||
305 send == GroupPoints->LineEdit2)
307 myEditCurrentArgument = send;
308 GEOMBase_Skeleton::LineEditReturnPressed();
313 //=================================================================================
314 // function : ActivateThisDialog()
316 //=================================================================================
317 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
319 GEOMBase_Skeleton::ActivateThisDialog();
320 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
321 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
323 ConstructorsClicked( getConstructorId() );
327 //=================================================================================
328 // function : enterEvent()
330 //=================================================================================
331 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
333 if ( !GroupConstructors->isEnabled() )
334 ActivateThisDialog();
338 //=================================================================================
339 // function : DeactivateActiveDialog()
340 // purpose : public slot to deactivate if active
341 //=================================================================================
342 void PrimitiveGUI_TorusDlg::DeactivateActiveDialog()
344 GEOMBase_Skeleton::DeactivateActiveDialog();
348 //=================================================================================
349 // function : ValueChangedInSpinBox
351 //=================================================================================
352 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
364 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
368 //=================================================================================
369 // function : isValid
371 //=================================================================================
372 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
374 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
378 //=================================================================================
379 // function : execute
381 //=================================================================================
382 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
386 GEOM::GEOM_Object_var anObj;
388 switch ( getConstructorId() )
392 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
393 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
400 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR(getRadius1(), getRadius2());
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
413 //=================================================================================
414 // function : closeEvent
416 //=================================================================================
417 void PrimitiveGUI_TorusDlg::closeEvent( QCloseEvent* e )
419 GEOMBase_Skeleton::closeEvent( e );
423 //=================================================================================
424 // function : getRadius1()
426 //=================================================================================
427 double PrimitiveGUI_TorusDlg::getRadius1() const
429 int aConstructorId = getConstructorId();
430 if (aConstructorId == 0)
431 return GroupPoints->SpinBox_DX->GetValue();
432 else if (aConstructorId == 1)
433 return GroupDimensions->SpinBox_DX->GetValue();
438 //=================================================================================
439 // function : getRadius2()
441 //=================================================================================
442 double PrimitiveGUI_TorusDlg::getRadius2() const
444 int aConstructorId = getConstructorId();
445 if (aConstructorId == 0)
446 return GroupPoints->SpinBox_DY->GetValue();
447 else if (aConstructorId == 1)
448 return GroupDimensions->SpinBox_DY->GetValue();