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 : BasicGUI_VectorDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_VectorDlg.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"
44 //=================================================================================
45 // class : BasicGUI_VectorDlg()
46 // purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 BasicGUI_VectorDlg::BasicGUI_VectorDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, modal, fl ), myGeometryGUI(theGeometryGUI)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_2P")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_DXYZ")));
56 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_VECTOR_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_VECTOR"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
70 GroupPoints->PushButton1->setPixmap(image2);
71 GroupPoints->PushButton2->setPixmap(image2);
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 GroupDimensions = new DlgRef_3Spin1Check(this, "GroupDimensions");
77 GroupDimensions->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
78 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
79 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
80 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
81 GroupDimensions->CheckBox1->setText(tr("GEOM_REVERSE_VECTOR"));
83 Layout1->addWidget(GroupPoints, 2, 0);
84 Layout1->addWidget(GroupDimensions, 2, 0);
85 /***************************************************************/
92 //=================================================================================
93 // function : ~BasicGUI_VectorDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
101 //=================================================================================
104 //=================================================================================
105 void BasicGUI_VectorDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
110 myPoint1 = GEOM::GEOM_Object::_nil();
111 myPoint2 = GEOM::GEOM_Object::_nil();
113 /* Get setting of step value from file configuration */
114 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
115 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
117 /* min, max, step and decimals for spin boxes */
118 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
119 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
120 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
122 double dx( 0. ), dy( 0. ), dz( 200. );
123 GroupDimensions->SpinBox_DX->SetValue( dx );
124 GroupDimensions->SpinBox_DY->SetValue( dy );
125 GroupDimensions->SpinBox_DZ->SetValue( dz );
127 GroupDimensions->CheckBox1->setChecked(FALSE);
129 /* signals and slots connections */
130 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
131 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
132 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
138 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
148 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
149 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
150 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
152 connect(GroupDimensions->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
154 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
155 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
157 initName( tr("GEOM_VECTOR") );
159 GroupDimensions->hide();
160 ConstructorsClicked( 0 );
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
170 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
171 myPoint1 = GEOM::GEOM_Object::_nil();
172 myPoint2 = GEOM::GEOM_Object::_nil();
174 switch (constructorId)
178 GroupDimensions->hide();
182 myEditCurrentArgument = GroupPoints->LineEdit1;
183 GroupPoints->LineEdit1->setText("");
184 GroupPoints->LineEdit2->setText("");
186 globalSelection( GEOM_POINT );
187 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
188 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195 GroupDimensions->show();
197 double dx( 0. ), dy( 0. ), dz( 0. );
198 GroupDimensions->SpinBox_DX->SetValue( dx );
199 GroupDimensions->SpinBox_DY->SetValue( dy );
200 GroupDimensions->SpinBox_DZ->SetValue( dz );
202 GroupDimensions->CheckBox1->setChecked( FALSE );
211 //=================================================================================
212 // function : ClickOnOk()
214 //=================================================================================
215 void BasicGUI_VectorDlg::ClickOnOk()
217 if ( ClickOnApply() )
221 //=======================================================================
222 // function : ClickOnCancel()
224 //=======================================================================
225 void BasicGUI_VectorDlg::ClickOnCancel()
227 GEOMBase_Skeleton::ClickOnCancel();
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 bool BasicGUI_VectorDlg::ClickOnApply()
236 buttonApply->setFocus();
242 if ( getConstructorId() != 1 )
243 ConstructorsClicked( getConstructorId() );
248 //=================================================================================
249 // function : SelectionIntoArgument()
250 // purpose : Called when selection as changed or other case
251 //=================================================================================
252 void BasicGUI_VectorDlg::SelectionIntoArgument()
254 myEditCurrentArgument->setText("");
256 if ( IObjectCount() != 1 )
258 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
259 myPoint1 = GEOM::GEOM_Object::_nil();
260 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
261 myPoint2 = GEOM::GEOM_Object::_nil();
266 Standard_Boolean aRes = Standard_False;
267 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
268 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
270 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
271 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
272 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
279 //=================================================================================
280 // function : SetEditCurrentArgument()
282 //=================================================================================
283 void BasicGUI_VectorDlg::SetEditCurrentArgument()
285 QPushButton* send = (QPushButton*)sender();
286 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
287 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
288 myEditCurrentArgument->setFocus();
289 SelectionIntoArgument();
293 //=================================================================================
294 // function : LineEditReturnPressed()
296 //=================================================================================
297 void BasicGUI_VectorDlg::LineEditReturnPressed()
299 QLineEdit* send = (QLineEdit*)sender();
300 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
301 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
303 GEOMBase_Skeleton::LineEditReturnPressed();
307 //=================================================================================
308 // function : ActivateThisDialog()
310 //=================================================================================
311 void BasicGUI_VectorDlg::ActivateThisDialog()
313 GEOMBase_Skeleton::ActivateThisDialog();
314 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
315 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
317 ConstructorsClicked( getConstructorId() );
320 //=================================================================================
321 // function : DeactivateActiveDialog()
322 // purpose : public slot to deactivate if active
323 //=================================================================================
324 void BasicGUI_VectorDlg::DeactivateActiveDialog()
326 // myGeometryGUI->SetState( -1 );
327 GEOMBase_Skeleton::DeactivateActiveDialog();
330 //=================================================================================
331 // function : enterEvent()
333 //=================================================================================
334 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
336 if ( !GroupConstructors->isEnabled() )
337 ActivateThisDialog();
340 //=================================================================================
341 // function : ValueChangedInSpinBox()
343 //=================================================================================
344 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
349 //=================================================================================
350 // function : ReverseVector()
351 // purpose : 'state' not used here
352 //=================================================================================
353 void BasicGUI_VectorDlg::ReverseVector(int state)
355 double dx = -GroupDimensions->SpinBox_DX->GetValue();
356 double dy = -GroupDimensions->SpinBox_DY->GetValue();
357 double dz = -GroupDimensions->SpinBox_DZ->GetValue();
359 GroupDimensions->SpinBox_DX->SetValue( dx );
360 GroupDimensions->SpinBox_DY->SetValue( dy );
361 GroupDimensions->SpinBox_DZ->SetValue( dz );
366 //=================================================================================
367 // function : createOperation
369 //=================================================================================
370 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
372 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
375 //=================================================================================
376 // function : isValid
378 //=================================================================================
379 bool BasicGUI_VectorDlg::isValid( QString& msg )
381 return getConstructorId() == 0 ? !myPoint1->_is_nil() && !myPoint2->_is_nil(): true;
384 //=================================================================================
385 // function : execute
387 //=================================================================================
388 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
392 GEOM::GEOM_Object_var anObj;
394 switch ( getConstructorId() ) {
396 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
402 double dx = GroupDimensions->SpinBox_DX->GetValue();
403 double dy = GroupDimensions->SpinBox_DY->GetValue();
404 double dz = GroupDimensions->SpinBox_DZ->GetValue();
405 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx,dy,dz );
411 if ( !anObj->_is_nil() )
412 objects.push_back( anObj._retn() );