1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_VectorDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "BasicGUI_VectorDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
43 #include "GEOMImpl_Types.hxx"
45 #include "utilities.h"
49 //=================================================================================
50 // class : BasicGUI_VectorDlg()
51 // purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_VectorDlg::BasicGUI_VectorDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57 const char* name, bool modal, WFlags fl)
58 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl)
60 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_2P")));
61 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_DXYZ")));
62 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setCaption(tr("GEOM_VECTOR_TITLE"));
66 /***************************************************************/
67 GroupConstructors->setTitle(tr("GEOM_VECTOR"));
68 RadioButton1->setPixmap(image0);
69 RadioButton2->setPixmap(image1);
70 RadioButton3->close(TRUE);
72 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
76 GroupPoints->PushButton1->setPixmap(image2);
77 GroupPoints->PushButton2->setPixmap(image2);
79 GroupPoints->LineEdit1->setReadOnly( true );
80 GroupPoints->LineEdit2->setReadOnly( true );
82 GroupDimensions = new DlgRef_3Spin1Check(this, "GroupDimensions");
83 GroupDimensions->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
84 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
85 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
86 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
87 GroupDimensions->CheckBox1->setText(tr("GEOM_REVERSE_VECTOR"));
89 Layout1->addWidget(GroupPoints, 2, 0);
90 Layout1->addWidget(GroupDimensions, 2, 0);
91 /***************************************************************/
93 setHelpFileName("create_vector_page.html");
100 //=================================================================================
101 // function : ~BasicGUI_VectorDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
109 //=================================================================================
112 //=================================================================================
113 void BasicGUI_VectorDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
118 myPoint1 = GEOM::GEOM_Object::_nil();
119 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 dx( 0. ), dy( 0. ), dz( 200. );
131 GroupDimensions->SpinBox_DX->SetValue( dx );
132 GroupDimensions->SpinBox_DY->SetValue( dy );
133 GroupDimensions->SpinBox_DZ->SetValue( dz );
135 GroupDimensions->CheckBox1->setChecked(FALSE);
137 /* signals and slots connections */
138 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
139 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
140 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
146 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
153 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
154 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
156 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
157 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
158 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
160 connect(GroupDimensions->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
162 connect(myGeomGUI->getApp()->selectionMgr(),
163 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
165 initName( tr("GEOM_VECTOR") );
167 GroupDimensions->hide();
168 ConstructorsClicked( 0 );
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
178 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
179 myPoint1 = GEOM::GEOM_Object::_nil();
180 myPoint2 = GEOM::GEOM_Object::_nil();
182 switch (constructorId)
186 GroupDimensions->hide();
190 myEditCurrentArgument = GroupPoints->LineEdit1;
191 GroupPoints->LineEdit1->setText("");
192 GroupPoints->LineEdit2->setText("");
194 globalSelection(); // close local contexts, if any
195 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
196 connect(myGeomGUI->getApp()->selectionMgr(),
197 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 GroupDimensions->show();
205 globalSelection(); // close local contexts, if any
207 double dx( 0. ), dy( 0. ), dz( 0. );
208 GroupDimensions->SpinBox_DX->SetValue( dx );
209 GroupDimensions->SpinBox_DY->SetValue( dy );
210 GroupDimensions->SpinBox_DZ->SetValue( dz );
212 GroupDimensions->CheckBox1->setChecked( FALSE );
221 //=================================================================================
222 // function : ClickOnOk()
224 //=================================================================================
225 void BasicGUI_VectorDlg::ClickOnOk()
227 if ( ClickOnApply() )
231 //=======================================================================
232 // function : ClickOnCancel()
234 //=======================================================================
235 void BasicGUI_VectorDlg::ClickOnCancel()
237 GEOMBase_Skeleton::ClickOnCancel();
240 //=================================================================================
241 // function : ClickOnApply()
243 //=================================================================================
244 bool BasicGUI_VectorDlg::ClickOnApply()
246 buttonApply->setFocus();
252 if ( getConstructorId() != 1 )
253 ConstructorsClicked( getConstructorId() );
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void BasicGUI_VectorDlg::SelectionIntoArgument()
264 myEditCurrentArgument->setText("");
266 if (IObjectCount() != 1)
268 if (myEditCurrentArgument == GroupPoints->LineEdit1)
269 myPoint1 = GEOM::GEOM_Object::_nil();
270 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
271 myPoint2 = GEOM::GEOM_Object::_nil();
276 Standard_Boolean aRes = Standard_False;
277 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
278 if (!CORBA::is_nil(aSelectedObject) && aRes)
280 QString aName = GEOMBase::GetName(aSelectedObject);
283 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
285 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
286 TColStd_IndexedMapOfInteger aMap;
287 aSelMgr->GetIndexes(firstIObject(), aMap);
288 if (aMap.Extent() == 1) // Local Selection
291 int anIndex = aMap(1);
292 aName += QString(":vertex_%1").arg(anIndex);
294 //Find SubShape Object in Father
295 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
297 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
298 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
299 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
302 aSelectedObject = aFindedObject; // get Object from study
304 else // Global Selection
306 if (aShape.ShapeType() != TopAbs_VERTEX) {
307 aSelectedObject = GEOM::GEOM_Object::_nil();
313 myEditCurrentArgument->setText(aName);
315 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
316 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
322 //=================================================================================
323 // function : SetEditCurrentArgument()
325 //=================================================================================
326 void BasicGUI_VectorDlg::SetEditCurrentArgument()
328 QPushButton* send = (QPushButton*)sender();
329 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
330 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
331 myEditCurrentArgument->setFocus();
332 SelectionIntoArgument();
336 //=================================================================================
337 // function : LineEditReturnPressed()
339 //=================================================================================
340 void BasicGUI_VectorDlg::LineEditReturnPressed()
342 QLineEdit* send = (QLineEdit*)sender();
343 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
344 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
346 GEOMBase_Skeleton::LineEditReturnPressed();
349 //=================================================================================
350 // function : ActivateThisDialog()
352 //=================================================================================
353 void BasicGUI_VectorDlg::ActivateThisDialog()
355 GEOMBase_Skeleton::ActivateThisDialog();
356 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
357 this, SLOT(SelectionIntoArgument()));
359 ConstructorsClicked(getConstructorId());
362 //=================================================================================
363 // function : DeactivateActiveDialog()
364 // purpose : public slot to deactivate if active
365 //=================================================================================
366 void BasicGUI_VectorDlg::DeactivateActiveDialog()
368 GEOMBase_Skeleton::DeactivateActiveDialog();
371 //=================================================================================
372 // function : enterEvent()
374 //=================================================================================
375 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
377 if ( !GroupConstructors->isEnabled() )
378 ActivateThisDialog();
381 //=================================================================================
382 // function : ValueChangedInSpinBox()
384 //=================================================================================
385 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
390 //=================================================================================
391 // function : ReverseVector()
392 // purpose : 'state' not used here
393 //=================================================================================
394 void BasicGUI_VectorDlg::ReverseVector(int state)
396 double dx = -GroupDimensions->SpinBox_DX->GetValue();
397 double dy = -GroupDimensions->SpinBox_DY->GetValue();
398 double dz = -GroupDimensions->SpinBox_DZ->GetValue();
400 GroupDimensions->SpinBox_DX->SetValue( dx );
401 GroupDimensions->SpinBox_DY->SetValue( dy );
402 GroupDimensions->SpinBox_DZ->SetValue( dz );
407 //=================================================================================
408 // function : createOperation
410 //=================================================================================
411 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
413 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
416 //=================================================================================
417 // function : isValid
419 //=================================================================================
420 bool BasicGUI_VectorDlg::isValid( QString& msg )
422 return getConstructorId() == 0 ? !myPoint1->_is_nil() && !myPoint2->_is_nil(): true;
425 //=================================================================================
426 // function : execute
428 //=================================================================================
429 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
433 GEOM::GEOM_Object_var anObj;
435 switch ( getConstructorId() ) {
437 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
443 double dx = GroupDimensions->SpinBox_DX->GetValue();
444 double dy = GroupDimensions->SpinBox_DY->GetValue();
445 double dz = GroupDimensions->SpinBox_DZ->GetValue();
446 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx,dy,dz );
452 if ( !anObj->_is_nil() )
453 objects.push_back( anObj._retn() );
458 //=================================================================================
459 // function : addSubshapeToStudy
460 // purpose : virtual method to add new SubObjects if local selection
461 //=================================================================================
462 void BasicGUI_VectorDlg::addSubshapesToStudy()
464 QMap<QString, GEOM::GEOM_Object_var> objMap;
466 switch (getConstructorId())
469 objMap[GroupPoints->LineEdit1->text()] = myPoint1;
470 objMap[GroupPoints->LineEdit2->text()] = myPoint2;
475 addSubshapesToFather( objMap );