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
30 #include "BasicGUI_VectorDlg.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
43 //=================================================================================
44 // class : BasicGUI_VectorDlg()
45 // purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BasicGUI_VectorDlg::BasicGUI_VectorDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, fl ), myGeometryGUI(theGeometryGUI)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_2P")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_DXYZ")));
55 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_VECTOR_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_VECTOR"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->setPixmap(image1);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
66 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
67 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
68 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
69 GroupPoints->PushButton1->setPixmap(image2);
70 GroupPoints->PushButton2->setPixmap(image2);
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
75 GroupDimensions = new DlgRef_3Spin1Check(this, "GroupDimensions");
76 GroupDimensions->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
77 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
78 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
79 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
80 GroupDimensions->CheckBox1->setText(tr("GEOM_REVERSE_VECTOR"));
82 Layout1->addWidget(GroupPoints, 2, 0);
83 Layout1->addWidget(GroupDimensions, 2, 0);
84 /***************************************************************/
91 //=================================================================================
92 // function : ~BasicGUI_VectorDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
100 //=================================================================================
103 //=================================================================================
104 void BasicGUI_VectorDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
109 myPoint1 = GEOM::GEOM_Object::_nil();
110 myPoint2 = GEOM::GEOM_Object::_nil();
112 /* Get setting of step value from file configuration */
113 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
114 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
116 /* min, max, step and decimals for spin boxes */
117 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
118 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
119 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
121 double dx( 0. ), dy( 0. ), dz( 200. );
122 GroupDimensions->SpinBox_DX->SetValue( dx );
123 GroupDimensions->SpinBox_DY->SetValue( dy );
124 GroupDimensions->SpinBox_DZ->SetValue( dz );
126 GroupDimensions->CheckBox1->setChecked(FALSE);
128 /* signals and slots connections */
129 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
130 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
131 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
133 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
147 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
148 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
149 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
151 connect(GroupDimensions->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
153 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
154 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
156 initName( tr("GEOM_VECTOR") );
158 GroupDimensions->hide();
159 ConstructorsClicked( 0 );
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
169 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
170 myPoint1 = GEOM::GEOM_Object::_nil();
171 myPoint2 = GEOM::GEOM_Object::_nil();
173 switch (constructorId)
177 GroupDimensions->hide();
181 myEditCurrentArgument = GroupPoints->LineEdit1;
182 GroupPoints->LineEdit1->setText("");
183 GroupPoints->LineEdit2->setText("");
185 globalSelection( GEOM_POINT );
186 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
187 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 GroupDimensions->show();
196 double dx( 0. ), dy( 0. ), dz( 0. );
197 GroupDimensions->SpinBox_DX->SetValue( dx );
198 GroupDimensions->SpinBox_DY->SetValue( dy );
199 GroupDimensions->SpinBox_DZ->SetValue( dz );
201 GroupDimensions->CheckBox1->setChecked( FALSE );
210 //=================================================================================
211 // function : ClickOnOk()
213 //=================================================================================
214 void BasicGUI_VectorDlg::ClickOnOk()
216 if ( ClickOnApply() )
220 //=======================================================================
221 // function : ClickOnCancel()
223 //=======================================================================
224 void BasicGUI_VectorDlg::ClickOnCancel()
226 GEOMBase_Skeleton::ClickOnCancel();
229 //=================================================================================
230 // function : ClickOnApply()
232 //=================================================================================
233 bool BasicGUI_VectorDlg::ClickOnApply()
235 buttonApply->setFocus();
241 if ( getConstructorId() != 1 )
242 ConstructorsClicked( getConstructorId() );
247 //=================================================================================
248 // function : SelectionIntoArgument()
249 // purpose : Called when selection as changed or other case
250 //=================================================================================
251 void BasicGUI_VectorDlg::SelectionIntoArgument()
253 myEditCurrentArgument->setText("");
255 if ( IObjectCount() != 1 )
257 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
258 myPoint1 = GEOM::GEOM_Object::_nil();
259 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
260 myPoint2 = GEOM::GEOM_Object::_nil();
265 Standard_Boolean aRes = Standard_False;
266 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
267 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
269 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
270 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
271 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
278 //=================================================================================
279 // function : SetEditCurrentArgument()
281 //=================================================================================
282 void BasicGUI_VectorDlg::SetEditCurrentArgument()
284 QPushButton* send = (QPushButton*)sender();
285 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
286 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
287 myEditCurrentArgument->setFocus();
288 SelectionIntoArgument();
292 //=================================================================================
293 // function : LineEditReturnPressed()
295 //=================================================================================
296 void BasicGUI_VectorDlg::LineEditReturnPressed()
298 QLineEdit* send = (QLineEdit*)sender();
299 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
300 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
302 GEOMBase_Skeleton::LineEditReturnPressed();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void BasicGUI_VectorDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
313 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
314 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
316 ConstructorsClicked( getConstructorId() );
319 //=================================================================================
320 // function : DeactivateActiveDialog()
321 // purpose : public slot to deactivate if active
322 //=================================================================================
323 void BasicGUI_VectorDlg::DeactivateActiveDialog()
325 // myGeometryGUI->SetState( -1 );
326 GEOMBase_Skeleton::DeactivateActiveDialog();
329 //=================================================================================
330 // function : enterEvent()
332 //=================================================================================
333 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
335 if ( !GroupConstructors->isEnabled() )
336 ActivateThisDialog();
339 //=================================================================================
340 // function : ValueChangedInSpinBox()
342 //=================================================================================
343 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
348 //=================================================================================
349 // function : ReverseVector()
350 // purpose : 'state' not used here
351 //=================================================================================
352 void BasicGUI_VectorDlg::ReverseVector(int state)
354 double dx = -GroupDimensions->SpinBox_DX->GetValue();
355 double dy = -GroupDimensions->SpinBox_DY->GetValue();
356 double dz = -GroupDimensions->SpinBox_DZ->GetValue();
358 GroupDimensions->SpinBox_DX->SetValue( dx );
359 GroupDimensions->SpinBox_DY->SetValue( dy );
360 GroupDimensions->SpinBox_DZ->SetValue( dz );
365 //=================================================================================
366 // function : createOperation
368 //=================================================================================
369 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
371 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
374 //=================================================================================
375 // function : isValid
377 //=================================================================================
378 bool BasicGUI_VectorDlg::isValid( QString& msg )
380 return getConstructorId() == 0 ? !myPoint1->_is_nil() && !myPoint2->_is_nil(): true;
383 //=================================================================================
384 // function : execute
386 //=================================================================================
387 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
391 GEOM::GEOM_Object_var anObj;
393 switch ( getConstructorId() ) {
395 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
401 double dx = GroupDimensions->SpinBox_DX->GetValue();
402 double dy = GroupDimensions->SpinBox_DY->GetValue();
403 double dz = GroupDimensions->SpinBox_DZ->GetValue();
404 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx,dy,dz );
410 if ( !anObj->_is_nil() )
411 objects.push_back( anObj._retn() );