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 "QAD_Config.h"
32 #include "QAD_Desktop.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "utilities.h"
40 //=================================================================================
41 // class : PrimitiveGUI_ConeDlg()
42 // purpose : Constructs a PrimitiveGUI_ConeDlg 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_ConeDlg::PrimitiveGUI_ConeDlg(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_CONE_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CONE_DXYZ")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_CONE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_CONE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel3Spin(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->TextLabel5->setText(tr("GEOM_HEIGHT"));
69 GroupPoints->PushButton1->setPixmap(image2);
70 GroupPoints->PushButton2->setPixmap(image2);
72 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
73 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
74 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS_I").arg("1"));
75 GroupDimensions->TextLabel2->setText(tr("GEOM_RADIUS_I").arg("2"));
76 GroupDimensions->TextLabel3->setText(tr("GEOM_HEIGHT"));
78 Layout1->addWidget(GroupPoints, 2, 0);
79 Layout1->addWidget(GroupDimensions, 2, 0);
80 /***************************************************************/
86 //=================================================================================
87 // function : ~PrimitiveGUI_ConeDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 PrimitiveGUI_ConeDlg::~PrimitiveGUI_ConeDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void PrimitiveGUI_ConeDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->LineEdit1->setReadOnly( true );
105 GroupPoints->LineEdit2->setReadOnly( true );
107 myPoint = myDir = GEOM::GEOM_Object::_nil();
109 /* Get setting of step value from file configuration */
110 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
111 double step = St.toDouble();
113 /* min, max, step and decimals for spin boxes & initial values */
114 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
115 GroupPoints->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
116 GroupPoints->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
117 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
118 GroupDimensions->SpinBox_DY->RangeStepAndValidator(0.000, COORD_MAX, step, 3);
119 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
121 double aRadius1(100.0), aRadius2(0.0), aHeight(300.0);
122 GroupPoints->SpinBox_DX->SetValue(aRadius1);
123 GroupPoints->SpinBox_DY->SetValue(aRadius2);
124 GroupPoints->SpinBox_DZ->SetValue(aHeight);
125 GroupDimensions->SpinBox_DX->SetValue(aRadius1);
126 GroupDimensions->SpinBox_DY->SetValue(aRadius2);
127 GroupDimensions->SpinBox_DZ->SetValue(aHeight);
129 /* signals and slots connections */
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
141 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
144 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
149 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, 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)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
154 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
156 initName( tr( "GEOM_CONE" ) );
157 ConstructorsClicked(0);
161 //=================================================================================
162 // function : ConstructorsClicked()
163 // purpose : Radio button management
164 //=================================================================================
165 void PrimitiveGUI_ConeDlg::ConstructorsClicked(int constructorId)
167 disconnect(mySelection, 0, this, 0);
169 switch(constructorId)
173 globalSelection( GEOM_POINT );
174 GroupDimensions->hide();
178 myEditCurrentArgument = GroupPoints->LineEdit1;
179 GroupPoints->LineEdit1->setText(tr(""));
180 GroupPoints->LineEdit2->setText(tr(""));
181 myPoint = myDir = GEOM::GEOM_Object::_nil();
183 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 GroupDimensions->show();
199 //=================================================================================
200 // function : ClickOnOk()
202 //=================================================================================
203 void PrimitiveGUI_ConeDlg::ClickOnOk()
205 if ( ClickOnApply() )
210 //=================================================================================
211 // function : ClickOnApply()
213 //=================================================================================
214 bool PrimitiveGUI_ConeDlg::ClickOnApply()
220 ConstructorsClicked( getConstructorId() );
225 //=======================================================================
226 // function : ClickOnCancel()
228 //=======================================================================
229 void PrimitiveGUI_ConeDlg::ClickOnCancel()
231 GEOMBase_Skeleton::ClickOnCancel();
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose : Called when selection as changed or other case
238 //=================================================================================
239 void PrimitiveGUI_ConeDlg::SelectionIntoArgument()
241 if ( getConstructorId() != 0 )
244 if(mySelection->IObjectCount() != 1)
246 if(myEditCurrentArgument == GroupPoints->LineEdit1)
247 myPoint = GEOM::GEOM_Object::_nil();
248 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
249 myDir = GEOM::GEOM_Object::_nil();
254 Standard_Boolean testResult = Standard_False;
255 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
257 if(!testResult || CORBA::is_nil( aSelectedObject ))
260 if (myEditCurrentArgument == GroupPoints->LineEdit1)
261 myPoint = aSelectedObject;
262 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
263 myDir = aSelectedObject;
266 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
271 //=================================================================================
272 // function : SetEditCurrentArgument()
274 //=================================================================================
275 void PrimitiveGUI_ConeDlg::SetEditCurrentArgument()
277 QPushButton* send = (QPushButton*)sender();
279 if(send == GroupPoints->PushButton1) {
280 myEditCurrentArgument = GroupPoints->LineEdit1;
281 globalSelection( GEOM_POINT );
283 else if(send == GroupPoints->PushButton2) {
284 myEditCurrentArgument = GroupPoints->LineEdit2;
285 globalSelection( GEOM_LINE );
288 myEditCurrentArgument->setFocus();
289 SelectionIntoArgument();
293 //=================================================================================
294 // function : LineEditReturnPressed()
296 //=================================================================================
297 void PrimitiveGUI_ConeDlg::LineEditReturnPressed()
299 QLineEdit* send = (QLineEdit*)sender();
300 if(send == GroupPoints->LineEdit1 ||
301 send == GroupPoints->LineEdit2)
303 myEditCurrentArgument = send;
304 GEOMBase_Skeleton::LineEditReturnPressed();
309 //=================================================================================
310 // function : ActivateThisDialog()
312 //=================================================================================
313 void PrimitiveGUI_ConeDlg::ActivateThisDialog()
315 GEOMBase_Skeleton::ActivateThisDialog();
316 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
318 ConstructorsClicked( getConstructorId() );
322 //=================================================================================
323 // function : DeactivateActiveDialog()
324 // purpose : public slot to deactivate if active
325 //=================================================================================
326 void PrimitiveGUI_ConeDlg::DeactivateActiveDialog()
328 GEOMBase_Skeleton::DeactivateActiveDialog();
332 //=================================================================================
333 // function : enterEvent()
335 //=================================================================================
336 void PrimitiveGUI_ConeDlg::enterEvent(QEvent* e)
338 if ( !GroupConstructors->isEnabled() )
339 ActivateThisDialog();
343 //=================================================================================
344 // function : ValueChangedInSpinBox()
346 //=================================================================================
347 void PrimitiveGUI_ConeDlg::ValueChangedInSpinBox()
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr PrimitiveGUI_ConeDlg::createOperation()
359 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
362 //=================================================================================
363 // function : isValid
365 //=================================================================================
366 bool PrimitiveGUI_ConeDlg::isValid( QString& msg )
368 return getConstructorId() == 0 ? !(myPoint->_is_nil() || myDir->_is_nil()) : true;
371 //=================================================================================
372 // function : execute
374 //=================================================================================
375 bool PrimitiveGUI_ConeDlg::execute( ObjectList& objects )
379 GEOM::GEOM_Object_var anObj;
381 switch ( getConstructorId() )
385 if ( !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir ) ){
386 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConePntVecR1R2H( myPoint,
397 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeConeR1R2H( getRadius1(),
405 if ( !anObj->_is_nil() )
406 objects.push_back( anObj._retn() );
411 //=================================================================================
412 // function : closeEvent
414 //=================================================================================
415 void PrimitiveGUI_ConeDlg::closeEvent( QCloseEvent* e )
417 myGeomGUI->SetState( -1 );
418 GEOMBase_Skeleton::closeEvent( e );
422 //=================================================================================
423 // function : getRadius1()
425 //=================================================================================
426 double PrimitiveGUI_ConeDlg::getRadius1() const
428 int aConstructorId = getConstructorId();
429 if (aConstructorId == 0)
430 return GroupPoints->SpinBox_DX->GetValue();
431 else if (aConstructorId == 1)
432 return GroupDimensions->SpinBox_DX->GetValue();
437 //=================================================================================
438 // function : getRadius2()
440 //=================================================================================
441 double PrimitiveGUI_ConeDlg::getRadius2() const
443 int aConstructorId = getConstructorId();
444 if (aConstructorId == 0)
445 return GroupPoints->SpinBox_DY->GetValue();
446 else if (aConstructorId == 1)
447 return GroupDimensions->SpinBox_DY->GetValue();
452 //=================================================================================
453 // function : getRadius2()
455 //=================================================================================
456 double PrimitiveGUI_ConeDlg::getHeight() const
458 int aConstructorId = getConstructorId();
459 if (aConstructorId == 0)
460 return GroupPoints->SpinBox_DZ->GetValue();
461 else if (aConstructorId == 1)
462 return GroupDimensions->SpinBox_DZ->GetValue();