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_ConeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_ConeDlg.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_ConeDlg()
46 // purpose : Constructs a PrimitiveGUI_ConeDlg 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_ConeDlg::PrimitiveGUI_ConeDlg(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_CONE_PV")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_CONE_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_CONE"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel3Spin(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->TextLabel5->setText(tr("GEOM_HEIGHT"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
78 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
79 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
80 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
81 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
82 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
84 Layout1->addWidget(GroupPoints, 2, 0);
85 Layout1->addWidget(GroupDimensions, 2, 0);
86 /***************************************************************/
88 setHelpFileName( "cone.htm" );
94 //=================================================================================
95 // function : ~PrimitiveGUI_ConeDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
100 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void PrimitiveGUI_ConeDlg::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.000, COORD_MAX, step, 3);
123 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
124 GroupPoints->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
125 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
126 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
127 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
129 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
130 GroupPoints->SpinBox_DX->SetValue(aRadius1);
131 GroupPoints->SpinBox_DY->SetValue(aRadius2);
132 GroupPoints->SpinBox_DZ->SetValue(aHeight);
133 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
134 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
135 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
137 /* signals and slots connections */
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
142 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
150 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
162 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
163 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
165 initName( tr( "GEOM_CONE" ) );
166 ConstructorsClicked(0);
170 //=================================================================================
171 // function : ConstructorsClicked()
172 // purpose : Radio button management
173 //=================================================================================
174 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
176 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
178 switch(constructorId)
182 globalSelection( GEOM_POINT );
183 GroupDimensions->hide();
187 myEditCurrentArgument = GroupPoints->LineEdit1;
188 GroupPoints->LineEdit1->setText(tr(""));
189 GroupPoints->LineEdit2->setText(tr(""));
190 myPoint = myDir = GEOM::GEOM_Object::_nil();
192 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
193 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
200 GroupDimensions->show();
209 //=================================================================================
210 // function : ClickOnOk()
212 //=================================================================================
213 void PrimitiveGUI_ConeDlg::ClickOnOk()
215 if ( ClickOnApply() )
220 //=================================================================================
221 // function : ClickOnApply()
223 //=================================================================================
224 bool PrimitiveGUI_ConeDlg::ClickOnApply()
230 ConstructorsClicked( getConstructorId() );
235 //=======================================================================
236 // function : ClickOnCancel()
238 //=======================================================================
239 void PrimitiveGUI_ConeDlg::ClickOnCancel()
241 GEOMBase_Skeleton::ClickOnCancel();
245 //=================================================================================
246 // function : SelectionIntoArgument()
247 // purpose : Called when selection as changed or other case
248 //=================================================================================
249 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
251 if ( getConstructorId() != 0 )
254 if(IObjectCount() != 1)
256 if(myEditCurrentArgument == GroupPoints->LineEdit1)
257 myPoint = GEOM::GEOM_Object::_nil();
258 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
259 myDir = GEOM::GEOM_Object::_nil();
264 Standard_Boolean testResult = Standard_False;
265 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
267 if(!testResult || CORBA::is_nil( aSelectedObject ))
270 if (myEditCurrentArgument == GroupPoints->LineEdit1)
271 myPoint = aSelectedObject;
272 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
273 myDir = aSelectedObject;
276 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
281 //=================================================================================
282 // function : SetEditCurrentArgument()
284 //=================================================================================
285 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
287 QPushButton* send = (QPushButton*)sender();
289 if(send == GroupPoints->PushButton1) {
290 myEditCurrentArgument = GroupPoints->LineEdit1;
291 globalSelection( GEOM_POINT );
293 else if(send == GroupPoints->PushButton2) {
294 myEditCurrentArgument = GroupPoints->LineEdit2;
295 globalSelection( GEOM_LINE );
298 myEditCurrentArgument->setFocus();
299 SelectionIntoArgument();
303 //=================================================================================
304 // function : LineEditReturnPressed()
306 //=================================================================================
307 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
309 QLineEdit* send = (QLineEdit*)sender();
310 if(send == GroupPoints->LineEdit1 ||
311 send == GroupPoints->LineEdit2)
313 myEditCurrentArgument = send;
314 GEOMBase_Skeleton::LineEditReturnPressed();
319 //=================================================================================
320 // function : ActivateThisDialog()
322 //=================================================================================
323 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
325 GEOMBase_Skeleton::ActivateThisDialog();
326 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
327 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
329 ConstructorsClicked( getConstructorId() );
333 //=================================================================================
334 // function : DeactivateActiveDialog()
335 // purpose : public slot to deactivate if active
336 //=================================================================================
337 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
339 GEOMBase_Skeleton::DeactivateActiveDialog();
343 //=================================================================================
344 // function : enterEvent()
346 //=================================================================================
347 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
349 if ( !GroupConstructors->isEnabled() )
350 ActivateThisDialog();
354 //=================================================================================
355 // function : ValueChangedInSpinBox()
357 //=================================================================================
358 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
364 //=================================================================================
365 // function : createOperation
367 //=================================================================================
368 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
370 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
373 //=================================================================================
374 // function : isValid
376 //=================================================================================
377 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
379 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
382 //=================================================================================
383 // function : execute
385 //=================================================================================
386 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
390 GEOM::GEOM_Object_var anObj;
392 switch ( getConstructorId() )
396 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
397 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
408 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
416 if ( !anObj->_is_nil() )
417 objects.push_back( anObj._retn() );
422 //=================================================================================
423 // function : closeEvent
425 //=================================================================================
426 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
428 // myGeomGUI->SetState( -1 );
429 GEOMBase_Skeleton::closeEvent( e );
433 //=================================================================================
434 // function : getRadius1()
436 //=================================================================================
437 double PrimitiveGUI_ConeDlg::getRadius1() const
439 int aConstructorId = getConstructorId();
440 if (aConstructorId == 0)
441 return GroupPoints->SpinBox_DX->GetValue();
442 else if (aConstructorId == 1)
443 return GroupDimensions->SpinBox_DX->GetValue();
448 //=================================================================================
449 // function : getRadius2()
451 //=================================================================================
452 double PrimitiveGUI_ConeDlg::getRadius2() const
454 int aConstructorId = getConstructorId();
455 if (aConstructorId == 0)
456 return GroupPoints->SpinBox_DY->GetValue();
457 else if (aConstructorId == 1)
458 return GroupDimensions->SpinBox_DY->GetValue();
463 //=================================================================================
464 // function : getRadius2()
466 //=================================================================================
467 double PrimitiveGUI_ConeDlg::getHeight() const
469 int aConstructorId = getConstructorId();
470 if (aConstructorId == 0)
471 return GroupPoints->SpinBox_DZ->GetValue();
472 else if (aConstructorId == 1)
473 return GroupDimensions->SpinBox_DZ->GetValue();