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 "QAD_Config.h"
32 #include "QAD_Desktop.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "utilities.h"
41 //=================================================================================
42 // class : PrimitiveGUI_BoxDlg()
43 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
53 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_SELECT")));
55 setCaption(tr("GEOM_BOX_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_BOX"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->setPixmap(image1);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
67 GroupPoints->PushButton1->setPixmap(image2);
68 GroupPoints->PushButton2->setPixmap(image2);
70 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
71 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
72 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
73 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
74 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
76 Layout1->addWidget(GroupPoints, 2, 0);
77 Layout1->addWidget(GroupDimensions, 2, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~DialogBox_Box()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void PrimitiveGUI_BoxDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
102 GroupPoints->LineEdit1->setReadOnly( true );
103 GroupPoints->LineEdit2->setReadOnly( true );
105 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
107 /* Get setting of step value from file configuration */
108 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
109 double step = St.toDouble();
111 /* min, max, step and decimals for spin boxes */
112 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
113 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
114 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
116 double initValue = 200.0;
117 GroupDimensions->SpinBox_DX->SetValue(initValue);
118 GroupDimensions->SpinBox_DY->SetValue(initValue);
119 GroupDimensions->SpinBox_DZ->SetValue(initValue);
121 /* signals and slots connections */
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
126 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
133 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
134 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
136 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
137 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
138 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
140 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
142 initName( tr( "GEOM_BOX" ) );
143 ConstructorsClicked(0);
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose : Radio button management
150 //=================================================================================
151 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
153 disconnect(mySelection, 0, this, 0);
155 switch (constructorId)
159 globalSelection( GEOM_POINT );
161 GroupDimensions->hide();
165 myEditCurrentArgument = GroupPoints->LineEdit1;
166 GroupPoints->LineEdit1->setText("");
167 GroupPoints->LineEdit2->setText("");
168 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
170 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
177 GroupDimensions->show();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void PrimitiveGUI_BoxDlg::ClickOnOk()
192 if ( ClickOnApply() )
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool PrimitiveGUI_BoxDlg::ClickOnApply()
207 ConstructorsClicked( getConstructorId() );
212 //=================================================================================
213 // function : ClickOnCancel()
215 //=================================================================================
216 void PrimitiveGUI_BoxDlg::ClickOnCancel()
218 GEOMBase_Skeleton::ClickOnCancel();
222 //=================================================================================
223 // function : SelectionIntoArgument()
224 // purpose : Called when selection as changed
225 //=================================================================================
226 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
228 if ( getConstructorId() != 0 )
231 myEditCurrentArgument->setText("");
233 if (mySelection->IObjectCount() != 1)
235 if (myEditCurrentArgument == GroupPoints->LineEdit1)
236 myPoint1 = GEOM::GEOM_Object::_nil();
237 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
238 myPoint2 = GEOM::GEOM_Object::_nil();
243 Standard_Boolean testResult = Standard_False;
244 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
246 if(!testResult || CORBA::is_nil( aSelectedObject ))
249 if(myEditCurrentArgument == GroupPoints->LineEdit1)
250 myPoint1 = aSelectedObject;
251 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
252 myPoint2 = aSelectedObject;
254 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
260 //=================================================================================
261 // function : SetEditCurrentArgument()
263 //=================================================================================
264 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
266 QPushButton* send = (QPushButton*)sender();
268 if(send == GroupPoints->PushButton1)
269 myEditCurrentArgument = GroupPoints->LineEdit1;
270 else if(send == GroupPoints->PushButton2)
271 myEditCurrentArgument = GroupPoints->LineEdit2;
273 globalSelection( GEOM_POINT );
275 myEditCurrentArgument->setFocus();
276 SelectionIntoArgument();
280 //=================================================================================
281 // function : LineEditReturnPressed()
283 //=================================================================================
284 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
286 QLineEdit* send = (QLineEdit*)sender();
287 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
289 myEditCurrentArgument = send;
290 GEOMBase_Skeleton::LineEditReturnPressed();
295 //=================================================================================
296 // function : ActivateThisDialog()
298 //=================================================================================
299 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
301 GEOMBase_Skeleton::ActivateThisDialog();
302 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
304 ConstructorsClicked( getConstructorId() );
308 //=================================================================================
309 // function : enterEvent [REDEFINED]
311 //=================================================================================
312 void PrimitiveGUI_BoxDlg::enterEvent(QEvent* e)
314 if ( !GroupConstructors->isEnabled() )
315 ActivateThisDialog();
319 //=================================================================================
320 // function : DeactivateActiveDialog()
321 // purpose : public slot to deactivate if active
322 //=================================================================================
323 void PrimitiveGUI_BoxDlg::DeactivateActiveDialog()
325 GEOMBase_Skeleton::DeactivateActiveDialog();
329 //=================================================================================
330 // function : ValueChangedInSpinBox()
332 //=================================================================================
333 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
339 //=================================================================================
340 // function : createOperation
342 //=================================================================================
343 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
345 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
349 //=================================================================================
350 // function : isValid
352 //=================================================================================
353 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
355 return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true;
359 //=================================================================================
360 // function : execute
362 //=================================================================================
363 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
367 GEOM::GEOM_Object_var anObj;
369 switch ( getConstructorId() )
373 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
374 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
382 double x = GroupDimensions->SpinBox_DX->GetValue();
383 double y = GroupDimensions->SpinBox_DY->GetValue();
384 double z = GroupDimensions->SpinBox_DZ->GetValue();
386 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
393 if ( !anObj->_is_nil() )
394 objects.push_back( anObj._retn() );
399 //=================================================================================
400 // function : closeEvent
402 //=================================================================================
403 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
405 GEOMBase_Skeleton::closeEvent( e );