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"
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
44 #include "GEOMImpl_Types.hxx"
46 #include "utilities.h"
51 //=================================================================================
52 // class : PrimitiveGUI_BoxDlg()
53 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
65 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setCaption(tr("GEOM_BOX_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_BOX"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->setPixmap(image1);
73 RadioButton3->close(TRUE);
75 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
79 GroupPoints->PushButton1->setPixmap(image2);
80 GroupPoints->PushButton2->setPixmap(image2);
82 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
83 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
84 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
85 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
86 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
88 Layout1->addWidget(GroupPoints, 2, 0);
89 Layout1->addWidget(GroupDimensions, 2, 0);
90 /***************************************************************/
92 setHelpFileName("box.htm");
98 //=================================================================================
99 // function : ~DialogBox_Box()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
104 // no need to delete child widgets, Qt does it all for us
108 //=================================================================================
111 //=================================================================================
112 void PrimitiveGUI_BoxDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
116 GroupPoints->LineEdit1->setReadOnly( true );
117 GroupPoints->LineEdit2->setReadOnly( true );
119 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
121 /* Get setting of step value from file configuration */
122 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
123 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
125 /* min, max, step and decimals for spin boxes */
126 GroupDimensions->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
127 GroupDimensions->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
128 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
130 double initValue = 200.0;
131 GroupDimensions->SpinBox_DX->SetValue(initValue);
132 GroupDimensions->SpinBox_DY->SetValue(initValue);
133 GroupDimensions->SpinBox_DZ->SetValue(initValue);
135 /* signals and slots connections */
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
141 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
148 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
149 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
151 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
152 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
153 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
155 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
158 initName( tr( "GEOM_BOX" ) );
159 ConstructorsClicked(0);
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
169 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
171 switch (constructorId)
175 // globalSelection( GEOM_POINT );
176 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
178 GroupDimensions->hide();
182 myEditCurrentArgument = GroupPoints->LineEdit1;
183 GroupPoints->LineEdit1->setText("");
184 GroupPoints->LineEdit2->setText("");
185 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
187 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
188 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195 GroupDimensions->show();
204 //=================================================================================
205 // function : ClickOnOk()
207 //=================================================================================
208 void PrimitiveGUI_BoxDlg::ClickOnOk()
210 if ( ClickOnApply() )
215 //=================================================================================
216 // function : ClickOnApply()
218 //=================================================================================
219 bool PrimitiveGUI_BoxDlg::ClickOnApply()
225 ConstructorsClicked( getConstructorId() );
230 //=================================================================================
231 // function : SelectionIntoArgument()
232 // purpose : Called when selection as changed
233 //=================================================================================
234 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
236 if ( getConstructorId() != 0 )
239 myEditCurrentArgument->setText("");
241 if (IObjectCount() != 1)
243 if (myEditCurrentArgument == GroupPoints->LineEdit1)
244 myPoint1 = GEOM::GEOM_Object::_nil();
245 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
246 myPoint2 = GEOM::GEOM_Object::_nil();
251 Standard_Boolean testResult = Standard_False;
252 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
254 if(!testResult || CORBA::is_nil( aSelectedObject ))
258 QString aName = GEOMBase::GetName( aSelectedObject );
259 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
261 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
262 TColStd_IndexedMapOfInteger aMap;
263 aSelMgr->GetIndexes( firstIObject(), aMap );
264 if ( aMap.Extent() == 1 )
266 GEOM::GEOM_IShapesOperations_var aShapesOp =
267 getGeomEngine()->GetIShapesOperations( getStudyId() );
268 int anIndex = aMap( 1 );
269 aName.append( ":vertex_" + QString::number( anIndex ) );
270 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
271 aSelMgr->clearSelected();
275 myEditCurrentArgument->setText( aName );
277 if(myEditCurrentArgument == GroupPoints->LineEdit1)
278 myPoint1 = aSelectedObject;
279 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
280 myPoint2 = aSelectedObject;
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
292 QPushButton* send = (QPushButton*)sender();
294 if(send == GroupPoints->PushButton1)
295 myEditCurrentArgument = GroupPoints->LineEdit1;
296 else if(send == GroupPoints->PushButton2)
297 myEditCurrentArgument = GroupPoints->LineEdit2;
299 // globalSelection( GEOM_POINT );
300 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
302 myEditCurrentArgument->setFocus();
303 SelectionIntoArgument();
307 //=================================================================================
308 // function : LineEditReturnPressed()
310 //=================================================================================
311 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
313 QLineEdit* send = (QLineEdit*)sender();
314 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
316 myEditCurrentArgument = send;
317 GEOMBase_Skeleton::LineEditReturnPressed();
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
328 GEOMBase_Skeleton::ActivateThisDialog();
329 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
330 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
332 ConstructorsClicked( getConstructorId() );
336 //=================================================================================
337 // function : enterEvent [REDEFINED]
339 //=================================================================================
340 void PrimitiveGUI_BoxDlg::enterEvent(QEvent* e)
342 if ( !GroupConstructors->isEnabled() )
343 ActivateThisDialog();
347 //=================================================================================
348 // function : ValueChangedInSpinBox()
350 //=================================================================================
351 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox()
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation()
363 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
367 //=================================================================================
368 // function : isValid
370 //=================================================================================
371 bool PrimitiveGUI_BoxDlg::isValid( QString& msg )
373 return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : true;
377 //=================================================================================
378 // function : execute
380 //=================================================================================
381 bool PrimitiveGUI_BoxDlg::execute( ObjectList& objects )
385 GEOM::GEOM_Object_var anObj;
387 switch ( getConstructorId() )
391 if ( !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) ) {
392 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxTwoPnt( myPoint1, myPoint2 );
400 double x = GroupDimensions->SpinBox_DX->GetValue();
401 double y = GroupDimensions->SpinBox_DY->GetValue();
402 double z = GroupDimensions->SpinBox_DZ->GetValue();
404 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->MakeBoxDXDYDZ( x, y, z );
410 if ( !anObj->_is_nil() )
411 objects.push_back( anObj._retn() );
416 //=================================================================================
417 // function : closeEvent
419 //=================================================================================
420 void PrimitiveGUI_BoxDlg::closeEvent( QCloseEvent* e )
422 GEOMBase_Skeleton::closeEvent( e );