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 "QAD_Config.h"
32 #include "QAD_Desktop.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "utilities.h"
40 //=================================================================================
41 // class : PrimitiveGUI_TorusDlg()
42 // purpose : Constructs a PrimitiveGUI_TorusDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 PrimitiveGUI_TorusDlg::PrimitiveGUI_TorusDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TORUS_DXYZ")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_TORUS_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_TORUS"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_POINT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
66 GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_I").arg("1"));
67 GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_I").arg("2"));
68 GroupPoints->PushButton1->setPixmap(image2);
69 GroupPoints->PushButton2->setPixmap(image2);
71 GroupDimensions = new DlgRef_2Spin(this, "GroupDimensions");
72 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
73 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
74 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
76 Layout1->addWidget(GroupPoints, 2, 0);
77 Layout1->addWidget(GroupDimensions, 2, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~PrimitiveGUI_TorusDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 PrimitiveGUI_TorusDlg::~PrimitiveGUI_TorusDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void PrimitiveGUI_TorusDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
102 GroupPoints->LineEdit1->setReadOnly( true );
103 GroupPoints->LineEdit2->setReadOnly( true );
105 myPoint = myDir = GEOM::GEOM_Object::_nil();
107 /* Get setting of step value from file configuration */
108 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
109 double step = St.toDouble();
111 /* min, max, step and decimals for spin boxes & initial values */
112 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
113 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
114 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
115 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, step, 3);
117 GroupPoints->SpinBox_DX->SetValue(300.0);
118 GroupPoints->SpinBox_DY->SetValue(100.0);
119 GroupDimensions->SpinBox_DX->SetValue(300.0);
120 GroupDimensions->SpinBox_DY->SetValue(100.0);
122 /* signals and slots connections */
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
134 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
135 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
136 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
138 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
139 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
140 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
141 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
143 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
145 initName( tr( "GEOM_TORUS" ) );
146 ConstructorsClicked(0);
151 //=================================================================================
152 // function : ConstructorsClicked()
153 // purpose : Radio button management
154 //=================================================================================
155 void PrimitiveGUI_TorusDlg::ConstructorsClicked(int constructorId)
157 disconnect(mySelection, 0, this, 0);
159 switch(constructorId)
163 globalSelection( GEOM_LINE );
165 GroupDimensions->hide();
169 myEditCurrentArgument = GroupPoints->LineEdit1;
170 GroupPoints->LineEdit1->setText(tr(""));
171 GroupPoints->LineEdit2->setText(tr(""));
172 myPoint = myDir = GEOM::GEOM_Object::_nil();
174 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
181 GroupDimensions->show();
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void PrimitiveGUI_TorusDlg::ClickOnOk()
196 if ( ClickOnApply() )
201 //=================================================================================
202 // function : ClickOnApply()
204 //=================================================================================
205 bool PrimitiveGUI_TorusDlg::ClickOnApply()
211 ConstructorsClicked( getConstructorId() );
216 //=======================================================================
217 // function : ClickOnCancel()
219 //=======================================================================
220 void PrimitiveGUI_TorusDlg::ClickOnCancel()
222 GEOMBase_Skeleton::ClickOnCancel();
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection as changed or other case
229 //=================================================================================
230 void PrimitiveGUI_TorusDlg::SelectionIntoArgument()
232 if ( getConstructorId() != 0 )
235 myEditCurrentArgument->setText("");
237 if(mySelection->IObjectCount() != 1)
239 if(myEditCurrentArgument == GroupPoints->LineEdit1)
240 myPoint = GEOM::GEOM_Object::_nil();
241 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
242 myDir = GEOM::GEOM_Object::_nil();
248 Standard_Boolean testResult = Standard_False;
249 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
251 if(!testResult || CORBA::is_nil( aSelectedObject ))
254 if(myEditCurrentArgument == GroupPoints->LineEdit1)
255 myPoint = aSelectedObject;
256 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
257 myDir = aSelectedObject;
259 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
264 //=================================================================================
265 // function : SetEditCurrentArgument()
267 //=================================================================================
268 void PrimitiveGUI_TorusDlg::SetEditCurrentArgument()
270 QPushButton* send = (QPushButton*)sender();
272 if(send == GroupPoints->PushButton1) {
273 myEditCurrentArgument = GroupPoints->LineEdit1;
274 globalSelection( GEOM_POINT );
276 else if(send == GroupPoints->PushButton2) {
277 myEditCurrentArgument = GroupPoints->LineEdit2;
278 globalSelection( GEOM_LINE );
281 myEditCurrentArgument->setFocus();
282 SelectionIntoArgument();
286 //=================================================================================
287 // function : LineEditReturnPressed()
289 //=================================================================================
290 void PrimitiveGUI_TorusDlg::LineEditReturnPressed()
292 QLineEdit* send = (QLineEdit*)sender();
293 if(send == GroupPoints->LineEdit1 ||
294 send == GroupPoints->LineEdit2)
296 myEditCurrentArgument = send;
297 GEOMBase_Skeleton::LineEditReturnPressed();
302 //=================================================================================
303 // function : ActivateThisDialog()
305 //=================================================================================
306 void PrimitiveGUI_TorusDlg::ActivateThisDialog()
308 GEOMBase_Skeleton::ActivateThisDialog();
309 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 ConstructorsClicked( getConstructorId() );
315 //=================================================================================
316 // function : enterEvent()
318 //=================================================================================
319 void PrimitiveGUI_TorusDlg::enterEvent(QEvent* e)
321 if ( !GroupConstructors->isEnabled() )
322 ActivateThisDialog();
326 //=================================================================================
327 // function : DeactivateActiveDialog()
328 // purpose : public slot to deactivate if active
329 //=================================================================================
330 void PrimitiveGUI_TorusDlg::DeactivateActiveDialog()
332 GEOMBase_Skeleton::DeactivateActiveDialog();
336 //=================================================================================
337 // function : ValueChangedInSpinBox
339 //=================================================================================
340 void PrimitiveGUI_TorusDlg::ValueChangedInSpinBox()
346 //=================================================================================
347 // function : createOperation
349 //=================================================================================
350 GEOM::GEOM_IOperations_ptr PrimitiveGUI_TorusDlg::createOperation()
352 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
356 //=================================================================================
357 // function : isValid
359 //=================================================================================
360 bool PrimitiveGUI_TorusDlg::isValid( QString& msg )
362 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
366 //=================================================================================
367 // function : execute
369 //=================================================================================
370 bool PrimitiveGUI_TorusDlg::execute( ObjectList& objects )
374 GEOM::GEOM_Object_var anObj;
376 switch ( getConstructorId() )
380 if (!CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir )){
381 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusPntVecRR(myPoint, myDir, getRadius1(), getRadius2());
388 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeTorusRR(getRadius1(), getRadius2());
394 if ( !anObj->_is_nil() )
395 objects.push_back( anObj._retn() );
401 //=================================================================================
402 // function : closeEvent
404 //=================================================================================
405 void PrimitiveGUI_TorusDlg::closeEvent( QCloseEvent* e )
407 GEOMBase_Skeleton::closeEvent( e );
411 //=================================================================================
412 // function : getRadius1()
414 //=================================================================================
415 double PrimitiveGUI_TorusDlg::getRadius1() const
417 int aConstructorId = getConstructorId();
418 if (aConstructorId == 0)
419 return GroupPoints->SpinBox_DX->GetValue();
420 else if (aConstructorId == 1)
421 return GroupDimensions->SpinBox_DX->GetValue();
426 //=================================================================================
427 // function : getRadius2()
429 //=================================================================================
430 double PrimitiveGUI_TorusDlg::getRadius2() const
432 int aConstructorId = getConstructorId();
433 if (aConstructorId == 0)
434 return GroupPoints->SpinBox_DY->GetValue();
435 else if (aConstructorId == 1)
436 return GroupDimensions->SpinBox_DY->GetValue();