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_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 "LightApp_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,
53 const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setCaption(tr("GEOM_BOX_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_BOX"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->setPixmap(image1);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
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_DX"));
79 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
80 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 Layout1->addWidget(GroupDimensions, 2, 0);
84 /***************************************************************/
86 setHelpFileName("box.htm");
92 //=================================================================================
93 // function : ~DialogBox_Box()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
98 // no need to delete child widgets, Qt does it all for us
102 //=================================================================================
105 //=================================================================================
106 void PrimitiveGUI_BoxDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 GroupPoints->LineEdit1->setReadOnly( true );
111 GroupPoints->LineEdit2->setReadOnly( true );
113 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
115 /* Get setting of step value from file configuration */
116 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
117 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
119 /* min, max, step and decimals for spin boxes */
120 GroupDimensions->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
121 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
122 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
124 double initValue = 200.0;
125 GroupDimensions->SpinBox_DX->SetValue(initValue);
126 GroupDimensions->SpinBox_DY->SetValue(initValue);
127 GroupDimensions->SpinBox_DZ->SetValue(initValue);
129 /* signals and slots connections */
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
135 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
142 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
143 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
149 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
150 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
152 initName( tr( "GEOM_BOX" ) );
153 ConstructorsClicked(0);
157 //=================================================================================
158 // function : ConstructorsClicked()
159 // purpose : Radio button management
160 //=================================================================================
161 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
163 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
165 switch (constructorId)
169 globalSelection( GEOM_POINT );
171 GroupDimensions->hide();
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 GroupPoints->LineEdit1->setText("");
177 GroupPoints->LineEdit2->setText("");
178 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
180 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
181 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188 GroupDimensions->show();
197 //=================================================================================
198 // function : ClickOnOk()
200 //=================================================================================
201 void PrimitiveGUI_BoxDlg::ClickOnOk()
203 if ( ClickOnApply() )
208 //=================================================================================
209 // function : ClickOnApply()
211 //=================================================================================
212 bool PrimitiveGUI_BoxDlg::ClickOnApply()
218 ConstructorsClicked( getConstructorId() );
223 //=================================================================================
224 // function : SelectionIntoArgument()
225 // purpose : Called when selection as changed
226 //=================================================================================
227 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
229 if ( getConstructorId() != 0 )
232 myEditCurrentArgument->setText("");
234 if (IObjectCount() != 1)
236 if (myEditCurrentArgument == GroupPoints->LineEdit1)
237 myPoint1 = GEOM::GEOM_Object::_nil();
238 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
239 myPoint2 = GEOM::GEOM_Object::_nil();
244 Standard_Boolean testResult = Standard_False;
245 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
247 if(!testResult || CORBA::is_nil( aSelectedObject ))
250 if(myEditCurrentArgument == GroupPoints->LineEdit1)
251 myPoint1 = aSelectedObject;
252 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
253 myPoint2 = aSelectedObject;
255 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
261 //=================================================================================
262 // function : SetEditCurrentArgument()
264 //=================================================================================
265 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
267 QPushButton* send = (QPushButton*)sender();
269 if(send == GroupPoints->PushButton1)
270 myEditCurrentArgument = GroupPoints->LineEdit1;
271 else if(send == GroupPoints->PushButton2)
272 myEditCurrentArgument = GroupPoints->LineEdit2;
274 globalSelection( GEOM_POINT );
276 myEditCurrentArgument->setFocus();
277 SelectionIntoArgument();
281 //=================================================================================
282 // function : LineEditReturnPressed()
284 //=================================================================================
285 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
287 QLineEdit* send = (QLineEdit*)sender();
288 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
290 myEditCurrentArgument = send;
291 GEOMBase_Skeleton::LineEditReturnPressed();
296 //=================================================================================
297 // function : ActivateThisDialog()
299 //=================================================================================
300 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
302 GEOMBase_Skeleton::ActivateThisDialog();
303 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
304 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
306 ConstructorsClicked( getConstructorId() );
310 //=================================================================================
311 // function : enterEvent [REDEFINED]
313 //=================================================================================
314 void PrimitiveGUI_BoxDlg::enterEvent(QEvent* e)
316 if ( !GroupConstructors->isEnabled() )
317 ActivateThisDialog();
321 //=================================================================================
322 // function : ValueChangedInSpinBox()
324 //=================================================================================
325 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
331 //=================================================================================
332 // function : createOperation
334 //=================================================================================
335 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
337 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
341 //=================================================================================
342 // function : isValid
344 //=================================================================================
345 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
347 return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true;
351 //=================================================================================
352 // function : execute
354 //=================================================================================
355 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
359 GEOM::GEOM_Object_var anObj;
361 switch ( getConstructorId() )
365 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
366 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
374 double x = GroupDimensions->SpinBox_DX->GetValue();
375 double y = GroupDimensions->SpinBox_DY->GetValue();
376 double z = GroupDimensions->SpinBox_DZ->GetValue();
378 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
384 if ( !anObj->_is_nil() )
385 objects.push_back( anObj._retn() );
390 //=================================================================================
391 // function : closeEvent
393 //=================================================================================
394 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
396 GEOMBase_Skeleton::closeEvent( e );