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_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 "SalomeApp_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, 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_CONE_PV")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
56 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_CONE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_CONE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel3Spin(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->TextLabel5->setText(tr("GEOM_HEIGHT"));
73 GroupPoints->PushButton1->setPixmap(image2);
74 GroupPoints->PushButton2->setPixmap(image2);
76 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
77 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
78 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
79 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
80 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 Layout1->addWidget(GroupDimensions, 2, 0);
84 /***************************************************************/
90 //=================================================================================
91 // function : ~PrimitiveGUI_ConeDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void PrimitiveGUI_ConeDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly( true );
109 GroupPoints->LineEdit2->setReadOnly( true );
111 myPoint = myDir = GEOM::GEOM_Object::_nil();
113 /* Get setting of step value from file configuration */
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
117 /* min, max, step and decimals for spin boxes & initial values */
118 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
119 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
120 GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
121 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, 999.999, step, 3);
122 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, 999.999, step, 3);
123 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
126 GroupPoints->SpinBox_DX->SetValue(aRadius1);
127 GroupPoints->SpinBox_DY->SetValue(aRadius2);
128 GroupPoints->SpinBox_DZ->SetValue(aHeight);
129 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
130 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
131 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
133 /* signals and slots connections */
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
138 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
146 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
152 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
153 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
154 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
155 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
156 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
158 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
159 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
161 initName( tr( "GEOM_CONE" ) );
162 ConstructorsClicked(0);
166 //=================================================================================
167 // function : ConstructorsClicked()
168 // purpose : Radio button management
169 //=================================================================================
170 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
172 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
174 switch(constructorId)
178 globalSelection( GEOM_POINT );
179 GroupDimensions->hide();
183 myEditCurrentArgument = GroupPoints->LineEdit1;
184 GroupPoints->LineEdit1->setText(tr(""));
185 GroupPoints->LineEdit2->setText(tr(""));
186 myPoint = myDir = GEOM::GEOM_Object::_nil();
188 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
189 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 GroupDimensions->show();
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void PrimitiveGUI_ConeDlg::ClickOnOk()
211 if ( ClickOnApply() )
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 bool PrimitiveGUI_ConeDlg::ClickOnApply()
226 ConstructorsClicked( getConstructorId() );
231 //=======================================================================
232 // function : ClickOnCancel()
234 //=======================================================================
235 void PrimitiveGUI_ConeDlg::ClickOnCancel()
237 GEOMBase_Skeleton::ClickOnCancel();
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection as changed or other case
244 //=================================================================================
245 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
247 if ( getConstructorId() != 0 )
250 if(IObjectCount() != 1)
252 if(myEditCurrentArgument == GroupPoints->LineEdit1)
253 myPoint = GEOM::GEOM_Object::_nil();
254 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
255 myDir = GEOM::GEOM_Object::_nil();
260 Standard_Boolean testResult = Standard_False;
261 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
263 if(!testResult || CORBA::is_nil( aSelectedObject ))
266 if (myEditCurrentArgument == GroupPoints->LineEdit1)
267 myPoint = aSelectedObject;
268 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
269 myDir = aSelectedObject;
272 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
277 //=================================================================================
278 // function : SetEditCurrentArgument()
280 //=================================================================================
281 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
283 QPushButton* send = (QPushButton*)sender();
285 if(send == GroupPoints->PushButton1) {
286 myEditCurrentArgument = GroupPoints->LineEdit1;
287 globalSelection( GEOM_POINT );
289 else if(send == GroupPoints->PushButton2) {
290 myEditCurrentArgument = GroupPoints->LineEdit2;
291 globalSelection( GEOM_LINE );
294 myEditCurrentArgument->setFocus();
295 SelectionIntoArgument();
299 //=================================================================================
300 // function : LineEditReturnPressed()
302 //=================================================================================
303 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
305 QLineEdit* send = (QLineEdit*)sender();
306 if(send == GroupPoints->LineEdit1 ||
307 send == GroupPoints->LineEdit2)
309 myEditCurrentArgument = send;
310 GEOMBase_Skeleton::LineEditReturnPressed();
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
321 GEOMBase_Skeleton::ActivateThisDialog();
322 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
323 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
325 ConstructorsClicked( getConstructorId() );
329 //=================================================================================
330 // function : DeactivateActiveDialog()
331 // purpose : public slot to deactivate if active
332 //=================================================================================
333 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
335 GEOMBase_Skeleton::DeactivateActiveDialog();
339 //=================================================================================
340 // function : enterEvent()
342 //=================================================================================
343 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
345 if ( !GroupConstructors->isEnabled() )
346 ActivateThisDialog();
350 //=================================================================================
351 // function : ValueChangedInSpinBox()
353 //=================================================================================
354 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
360 //=================================================================================
361 // function : createOperation
363 //=================================================================================
364 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
366 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
369 //=================================================================================
370 // function : isValid
372 //=================================================================================
373 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
375 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
378 //=================================================================================
379 // function : execute
381 //=================================================================================
382 bool PrimitiveGUI_ConeDlg::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() )->MakeConePntVecR1R2H( myPoint,
404 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
412 if ( !anObj->_is_nil() )
413 objects.push_back( anObj._retn() );
418 //=================================================================================
419 // function : closeEvent
421 //=================================================================================
422 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
424 // myGeomGUI->SetState( -1 );
425 GEOMBase_Skeleton::closeEvent( e );
429 //=================================================================================
430 // function : getRadius1()
432 //=================================================================================
433 double PrimitiveGUI_ConeDlg::getRadius1() const
435 int aConstructorId = getConstructorId();
436 if (aConstructorId == 0)
437 return GroupPoints->SpinBox_DX->GetValue();
438 else if (aConstructorId == 1)
439 return GroupDimensions->SpinBox_DX->GetValue();
444 //=================================================================================
445 // function : getRadius2()
447 //=================================================================================
448 double PrimitiveGUI_ConeDlg::getRadius2() const
450 int aConstructorId = getConstructorId();
451 if (aConstructorId == 0)
452 return GroupPoints->SpinBox_DY->GetValue();
453 else if (aConstructorId == 1)
454 return GroupDimensions->SpinBox_DY->GetValue();
459 //=================================================================================
460 // function : getRadius2()
462 //=================================================================================
463 double PrimitiveGUI_ConeDlg::getHeight() const
465 int aConstructorId = getConstructorId();
466 if (aConstructorId == 0)
467 return GroupPoints->SpinBox_DZ->GetValue();
468 else if (aConstructorId == 1)
469 return GroupDimensions->SpinBox_DZ->GetValue();