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"
30 #include "DlgRef_2Sel3Spin.h"
31 #include "DlgRef_3Spin.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_ConeDlg()
48 // purpose : Constructs a PrimitiveGUI_ConeDlg 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_ConeDlg::PrimitiveGUI_ConeDlg(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_CONE_PV")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_CONE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_CONE"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel3Spin(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->TextLabel5->setText(tr("GEOM_HEIGHT"));
77 GroupPoints->PushButton1->setIcon(image2);
78 GroupPoints->PushButton2->setIcon(image2);
80 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
81 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
82 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
83 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
84 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
86 gridLayout1->addWidget(GroupPoints, 2, 0);
87 gridLayout1->addWidget(GroupDimensions, 2, 0);
88 /***************************************************************/
90 setHelpFileName( "cone.htm" );
96 //=================================================================================
97 // function : ~PrimitiveGUI_ConeDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
102 // no need to delete child widgets, Qt does it all for us
106 //=================================================================================
109 //=================================================================================
110 void PrimitiveGUI_ConeDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
114 GroupPoints->LineEdit1->setReadOnly( true );
115 GroupPoints->LineEdit2->setReadOnly( true );
117 myPoint = myDir = GEOM::GEOM_Object::_nil();
119 /* Get setting of step value from file configuration */
120 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
121 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
123 /* min, max, step and decimals for spin boxes & initial values */
124 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
125 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
126 GroupPoints->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
127 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
128 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
129 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
131 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
132 GroupPoints->SpinBox_DX->SetValue(aRadius1);
133 GroupPoints->SpinBox_DY->SetValue(aRadius2);
134 GroupPoints->SpinBox_DZ->SetValue(aHeight);
135 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
136 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
137 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
139 /* signals and slots connections */
140 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
141 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
144 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
153 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
155 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
159 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
160 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
161 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
162 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
164 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
165 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
167 initName( tr( "GEOM_CONE" ).toStdString().c_str() );
168 ConstructorsClicked(0);
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
178 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
180 switch(constructorId)
184 globalSelection( GEOM_POINT );
185 GroupDimensions->hide();
189 myEditCurrentArgument = GroupPoints->LineEdit1;
190 GroupPoints->LineEdit1->setText(tr(""));
191 GroupPoints->LineEdit2->setText(tr(""));
192 myPoint = myDir = GEOM::GEOM_Object::_nil();
194 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
195 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202 GroupDimensions->show();
211 //=================================================================================
212 // function : ClickOnOk()
214 //=================================================================================
215 void PrimitiveGUI_ConeDlg::ClickOnOk()
217 if ( ClickOnApply() )
222 //=================================================================================
223 // function : ClickOnApply()
225 //=================================================================================
226 bool PrimitiveGUI_ConeDlg::ClickOnApply()
232 ConstructorsClicked( getConstructorId() );
237 //=======================================================================
238 // function : ClickOnCancel()
240 //=======================================================================
241 void PrimitiveGUI_ConeDlg::ClickOnCancel()
243 GEOMBase_Skeleton::ClickOnCancel();
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
253 if ( getConstructorId() != 0 )
256 if(IObjectCount() != 1)
258 if(myEditCurrentArgument == GroupPoints->LineEdit1)
259 myPoint = GEOM::GEOM_Object::_nil();
260 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
261 myDir = GEOM::GEOM_Object::_nil();
266 Standard_Boolean testResult = Standard_False;
267 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
269 if(!testResult || CORBA::is_nil( aSelectedObject ))
272 if (myEditCurrentArgument == GroupPoints->LineEdit1)
273 myPoint = aSelectedObject;
274 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
275 myDir = aSelectedObject;
278 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
283 //=================================================================================
284 // function : SetEditCurrentArgument()
286 //=================================================================================
287 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
289 QPushButton* send = (QPushButton*)sender();
291 if(send == GroupPoints->PushButton1) {
292 myEditCurrentArgument = GroupPoints->LineEdit1;
293 globalSelection( GEOM_POINT );
295 else if(send == GroupPoints->PushButton2) {
296 myEditCurrentArgument = GroupPoints->LineEdit2;
297 globalSelection( GEOM_LINE );
300 myEditCurrentArgument->setFocus();
301 SelectionIntoArgument();
305 //=================================================================================
306 // function : LineEditReturnPressed()
308 //=================================================================================
309 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
311 QLineEdit* send = (QLineEdit*)sender();
312 if(send == GroupPoints->LineEdit1 ||
313 send == GroupPoints->LineEdit2)
315 myEditCurrentArgument = send;
316 GEOMBase_Skeleton::LineEditReturnPressed();
321 //=================================================================================
322 // function : ActivateThisDialog()
324 //=================================================================================
325 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
327 GEOMBase_Skeleton::ActivateThisDialog();
328 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
329 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
331 ConstructorsClicked( getConstructorId() );
335 //=================================================================================
336 // function : DeactivateActiveDialog()
337 // purpose : public slot to deactivate if active
338 //=================================================================================
339 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
341 GEOMBase_Skeleton::DeactivateActiveDialog();
345 //=================================================================================
346 // function : enterEvent()
348 //=================================================================================
349 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
351 if ( !GroupConstructors->isEnabled() )
352 ActivateThisDialog();
356 //=================================================================================
357 // function : ValueChangedInSpinBox()
359 //=================================================================================
360 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
366 //=================================================================================
367 // function : createOperation
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
372 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
375 //=================================================================================
376 // function : isValid
378 //=================================================================================
379 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
381 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
384 //=================================================================================
385 // function : execute
387 //=================================================================================
388 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
392 GEOM::GEOM_Object_var anObj;
394 switch ( getConstructorId() )
398 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
399 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
410 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
418 if ( !anObj->_is_nil() )
419 objects.push_back( anObj._retn() );
424 //=================================================================================
425 // function : closeEvent
427 //=================================================================================
428 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
430 // myGeomGUI->SetState( -1 );
431 GEOMBase_Skeleton::closeEvent( e );
435 //=================================================================================
436 // function : getRadius1()
438 //=================================================================================
439 double PrimitiveGUI_ConeDlg::getRadius1() const
441 int aConstructorId = getConstructorId();
442 if (aConstructorId == 0)
443 return GroupPoints->SpinBox_DX->GetValue();
444 else if (aConstructorId == 1)
445 return GroupDimensions->SpinBox_DX->GetValue();
450 //=================================================================================
451 // function : getRadius2()
453 //=================================================================================
454 double PrimitiveGUI_ConeDlg::getRadius2() const
456 int aConstructorId = getConstructorId();
457 if (aConstructorId == 0)
458 return GroupPoints->SpinBox_DY->GetValue();
459 else if (aConstructorId == 1)
460 return GroupDimensions->SpinBox_DY->GetValue();
465 //=================================================================================
466 // function : getRadius2()
468 //=================================================================================
469 double PrimitiveGUI_ConeDlg::getHeight() const
471 int aConstructorId = getConstructorId();
472 if (aConstructorId == 0)
473 return GroupPoints->SpinBox_DZ->GetValue();
474 else if (aConstructorId == 1)
475 return GroupDimensions->SpinBox_DZ->GetValue();