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_BoxDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "PrimitiveGUI_BoxDlg.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"
45 //=================================================================================
46 // class : PrimitiveGUI_BoxDlg()
47 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setCaption(tr("GEOM_BOX_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_BOX"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
71 GroupPoints->PushButton1->setPixmap(image2);
72 GroupPoints->PushButton2->setPixmap(image2);
74 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
75 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
76 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
77 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
78 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
80 Layout1->addWidget(GroupPoints, 2, 0);
81 Layout1->addWidget(GroupDimensions, 2, 0);
82 /***************************************************************/
88 //=================================================================================
89 // function : ~DialogBox_Box()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
94 // no need to delete child widgets, Qt does it all for us
98 //=================================================================================
101 //=================================================================================
102 void PrimitiveGUI_BoxDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
109 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
111 /* Get setting of step value from file configuration */
112 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
115 /* min, max, step and decimals for spin boxes */
116 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
117 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
118 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
120 double initValue = 200.0;
121 GroupDimensions->SpinBox_DX->SetValue(initValue);
122 GroupDimensions->SpinBox_DY->SetValue(initValue);
123 GroupDimensions->SpinBox_DZ->SetValue(initValue);
125 /* signals and slots connections */
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
137 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
138 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
140 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
141 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
142 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
144 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
145 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
147 initName( tr( "GEOM_BOX" ) );
148 ConstructorsClicked(0);
152 //=================================================================================
153 // function : ConstructorsClicked()
154 // purpose : Radio button management
155 //=================================================================================
156 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
158 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
160 switch (constructorId)
164 globalSelection( GEOM_POINT );
166 GroupDimensions->hide();
170 myEditCurrentArgument = GroupPoints->LineEdit1;
171 GroupPoints->LineEdit1->setText("");
172 GroupPoints->LineEdit2->setText("");
173 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
175 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
176 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
183 GroupDimensions->show();
192 //=================================================================================
193 // function : ClickOnOk()
195 //=================================================================================
196 void PrimitiveGUI_BoxDlg::ClickOnOk()
198 if ( ClickOnApply() )
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool PrimitiveGUI_BoxDlg::ClickOnApply()
213 ConstructorsClicked( getConstructorId() );
218 //=================================================================================
219 // function : ClickOnCancel()
221 //=================================================================================
222 void PrimitiveGUI_BoxDlg::ClickOnCancel()
224 GEOMBase_Skeleton::ClickOnCancel();
228 //=================================================================================
229 // function : SelectionIntoArgument()
230 // purpose : Called when selection as changed
231 //=================================================================================
232 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
234 if ( getConstructorId() != 0 )
237 myEditCurrentArgument->setText("");
239 if (IObjectCount() != 1)
241 if (myEditCurrentArgument == GroupPoints->LineEdit1)
242 myPoint1 = GEOM::GEOM_Object::_nil();
243 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
244 myPoint2 = GEOM::GEOM_Object::_nil();
249 Standard_Boolean testResult = Standard_False;
250 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
252 if(!testResult || CORBA::is_nil( aSelectedObject ))
255 if(myEditCurrentArgument == GroupPoints->LineEdit1)
256 myPoint1 = aSelectedObject;
257 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
258 myPoint2 = aSelectedObject;
260 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
266 //=================================================================================
267 // function : SetEditCurrentArgument()
269 //=================================================================================
270 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
272 QPushButton* send = (QPushButton*)sender();
274 if(send == GroupPoints->PushButton1)
275 myEditCurrentArgument = GroupPoints->LineEdit1;
276 else if(send == GroupPoints->PushButton2)
277 myEditCurrentArgument = GroupPoints->LineEdit2;
279 globalSelection( GEOM_POINT );
281 myEditCurrentArgument->setFocus();
282 SelectionIntoArgument();
286 //=================================================================================
287 // function : LineEditReturnPressed()
289 //=================================================================================
290 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
292 QLineEdit* send = (QLineEdit*)sender();
293 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
295 myEditCurrentArgument = send;
296 GEOMBase_Skeleton::LineEditReturnPressed();
301 //=================================================================================
302 // function : ActivateThisDialog()
304 //=================================================================================
305 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
307 GEOMBase_Skeleton::ActivateThisDialog();
308 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
309 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 ConstructorsClicked( getConstructorId() );
315 //=================================================================================
316 // function : enterEvent [REDEFINED]
318 //=================================================================================
319 void PrimitiveGUI_BoxDlg::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_BoxDlg::DeactivateActiveDialog()
332 GEOMBase_Skeleton::DeactivateActiveDialog();
336 //=================================================================================
337 // function : ValueChangedInSpinBox()
339 //=================================================================================
340 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
346 //=================================================================================
347 // function : createOperation
349 //=================================================================================
350 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
352 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
356 //=================================================================================
357 // function : isValid
359 //=================================================================================
360 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
362 return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true;
366 //=================================================================================
367 // function : execute
369 //=================================================================================
370 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
374 GEOM::GEOM_Object_var anObj;
376 switch ( getConstructorId() )
380 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
381 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
389 double x = GroupDimensions->SpinBox_DX->GetValue();
390 double y = GroupDimensions->SpinBox_DY->GetValue();
391 double z = GroupDimensions->SpinBox_DZ->GetValue();
393 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
399 if ( !anObj->_is_nil() )
400 objects.push_back( anObj._retn() );
405 //=================================================================================
406 // function : closeEvent
408 //=================================================================================
409 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
411 GEOMBase_Skeleton::closeEvent( e );