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"
30 #include "DlgRef_3Spin.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 #include "GEOMImpl_Types.hxx"
46 //=================================================================================
47 // class : PrimitiveGUI_BoxDlg()
48 // purpose : Constructs a PrimitiveGUI_BoxDlg 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_BoxDlg::PrimitiveGUI_BoxDlg(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_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 setWindowTitle(tr("GEOM_BOX_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_BOX"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 RadioButton3->close();
70 GroupPoints = new Ui::DlgRef_2Sel_QTD();
71 QWidget* aGroupPointsWidget = new QWidget(this);
72 GroupPoints->setupUi(aGroupPointsWidget);
73 aGroupPointsWidget->setObjectName("GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
78 GroupPoints->PushButton1->setIcon(image2);
79 GroupPoints->PushButton2->setIcon(image2);
81 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
82 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
83 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
84 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
85 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
87 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
88 gridLayout1->addWidget(GroupDimensions, 2, 0);
89 /***************************************************************/
91 setHelpFileName("box.htm");
97 //=================================================================================
98 // function : ~DialogBox_Box()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void PrimitiveGUI_BoxDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
115 GroupPoints->LineEdit1->setReadOnly( true );
116 GroupPoints->LineEdit2->setReadOnly( true );
118 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
120 /* Get setting of step value from file configuration */
121 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
122 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
124 /* min, max, step and decimals for spin boxes */
125 GroupDimensions->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
126 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
127 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
129 double initValue = 200.0;
130 GroupDimensions->SpinBox_DX->SetValue(initValue);
131 GroupDimensions->SpinBox_DY->SetValue(initValue);
132 GroupDimensions->SpinBox_DZ->SetValue(initValue);
134 /* signals and slots connections */
135 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
140 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
147 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
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(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
155 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
157 initName( tr( "GEOM_BOX" ).toStdString().c_str() );
158 ConstructorsClicked(0);
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
168 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
170 switch (constructorId)
174 globalSelection( GEOM_POINT );
176 GroupDimensions->hide();
178 ::qobject_cast<QWidget*>( GroupPoints->gridLayout->parent() )->show();
180 myEditCurrentArgument = GroupPoints->LineEdit1;
181 GroupPoints->LineEdit1->setText("");
182 GroupPoints->LineEdit2->setText("");
183 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
185 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
186 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 ::qobject_cast<QWidget*>( GroupPoints->gridLayout->parent() )->hide();
193 GroupDimensions->show();
202 //=================================================================================
203 // function : ClickOnOk()
205 //=================================================================================
206 void PrimitiveGUI_BoxDlg::ClickOnOk()
208 if ( ClickOnApply() )
213 //=================================================================================
214 // function : ClickOnApply()
216 //=================================================================================
217 bool PrimitiveGUI_BoxDlg::ClickOnApply()
223 ConstructorsClicked( getConstructorId() );
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 : ValueChangedInSpinBox()
329 //=================================================================================
330 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
336 //=================================================================================
337 // function : createOperation
339 //=================================================================================
340 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
342 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
346 //=================================================================================
347 // function : isValid
349 //=================================================================================
350 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
352 return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true;
356 //=================================================================================
357 // function : execute
359 //=================================================================================
360 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
364 GEOM::GEOM_Object_var anObj;
366 switch ( getConstructorId() )
370 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
371 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
379 double x = GroupDimensions->SpinBox_DX->GetValue();
380 double y = GroupDimensions->SpinBox_DY->GetValue();
381 double z = GroupDimensions->SpinBox_DZ->GetValue();
383 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
389 if ( !anObj->_is_nil() )
390 objects.push_back( anObj._retn() );
395 //=================================================================================
396 // function : closeEvent
398 //=================================================================================
399 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
401 GEOMBase_Skeleton::closeEvent( e );