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 "QAD_Desktop.h"
33 #include "QAD_Config.h"
35 #include "GEOMImpl_Types.hxx"
37 #include "utilities.h"
39 //=================================================================================
40 // class : BasicGUI_VectorDlg()
41 // purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BasicGUI_VectorDlg::BasicGUI_VectorDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
47 :GEOMBase_Skeleton(parent, name, Sel, modal, fl )
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_2P")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_DXYZ")));
51 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_VECTOR_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_VECTOR"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->setPixmap(image1);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
65 GroupPoints->PushButton1->setPixmap(image2);
66 GroupPoints->PushButton2->setPixmap(image2);
68 GroupPoints->LineEdit1->setReadOnly( true );
69 GroupPoints->LineEdit2->setReadOnly( true );
71 GroupDimensions = new DlgRef_3Spin1Check(this, "GroupDimensions");
72 GroupDimensions->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
73 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
74 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
75 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
76 GroupDimensions->CheckBox1->setText(tr("GEOM_REVERSE_VECTOR"));
78 Layout1->addWidget(GroupPoints, 2, 0);
79 Layout1->addWidget(GroupDimensions, 2, 0);
80 /***************************************************************/
87 //=================================================================================
88 // function : ~BasicGUI_VectorDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
96 //=================================================================================
99 //=================================================================================
100 void BasicGUI_VectorDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
105 myPoint1 = GEOM::GEOM_Object::_nil();
106 myPoint2 = GEOM::GEOM_Object::_nil();
108 /* Get setting of step value from file configuration */
109 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
110 double step = St.toDouble();
112 /* min, max, step and decimals for spin boxes */
113 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
114 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
115 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
117 double dx( 0. ), dy( 0. ), dz( 200. );
118 GroupDimensions->SpinBox_DX->SetValue( dx );
119 GroupDimensions->SpinBox_DY->SetValue( dy );
120 GroupDimensions->SpinBox_DZ->SetValue( dz );
122 GroupDimensions->CheckBox1->setChecked(FALSE);
124 /* signals and slots connections */
125 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
126 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
127 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
129 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
130 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
131 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
133 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
141 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
144 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
145 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
147 connect(GroupDimensions->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
149 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
151 initName( tr("GEOM_VECTOR") );
153 GroupDimensions->hide();
154 ConstructorsClicked( 0 );
158 //=================================================================================
159 // function : ConstructorsClicked()
160 // purpose : Radio button management
161 //=================================================================================
162 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
164 disconnect(mySelection, 0, this, 0);
165 myPoint1 = GEOM::GEOM_Object::_nil();
166 myPoint2 = GEOM::GEOM_Object::_nil();
168 switch (constructorId)
172 GroupDimensions->hide();
176 myEditCurrentArgument = GroupPoints->LineEdit1;
177 GroupPoints->LineEdit1->setText("");
178 GroupPoints->LineEdit2->setText("");
180 globalSelection( GEOM_POINT );
181 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188 GroupDimensions->show();
190 double dx( 0. ), dy( 0. ), dz( 0. );
191 GroupDimensions->SpinBox_DX->SetValue( dx );
192 GroupDimensions->SpinBox_DY->SetValue( dy );
193 GroupDimensions->SpinBox_DZ->SetValue( dz );
195 GroupDimensions->CheckBox1->setChecked( FALSE );
204 //=================================================================================
205 // function : ClickOnOk()
207 //=================================================================================
208 void BasicGUI_VectorDlg::ClickOnOk()
210 if ( ClickOnApply() )
214 //=======================================================================
215 // function : ClickOnCancel()
217 //=======================================================================
218 void BasicGUI_VectorDlg::ClickOnCancel()
220 GEOMBase_Skeleton::ClickOnCancel();
223 //=================================================================================
224 // function : ClickOnApply()
226 //=================================================================================
227 bool BasicGUI_VectorDlg::ClickOnApply()
229 buttonApply->setFocus();
235 if ( getConstructorId() != 1 )
236 ConstructorsClicked( getConstructorId() );
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose : Called when selection as changed or other case
244 //=================================================================================
245 void BasicGUI_VectorDlg::SelectionIntoArgument()
247 myEditCurrentArgument->setText("");
249 if ( mySelection->IObjectCount() != 1 )
251 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
252 myPoint1 = GEOM::GEOM_Object::_nil();
253 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
254 myPoint2 = GEOM::GEOM_Object::_nil();
259 Standard_Boolean aRes = Standard_False;
260 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
261 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
263 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
264 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
265 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void BasicGUI_VectorDlg::SetEditCurrentArgument()
278 QPushButton* send = (QPushButton*)sender();
279 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
280 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
281 myEditCurrentArgument->setFocus();
282 SelectionIntoArgument();
286 //=================================================================================
287 // function : LineEditReturnPressed()
289 //=================================================================================
290 void BasicGUI_VectorDlg::LineEditReturnPressed()
292 QLineEdit* send = (QLineEdit*)sender();
293 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
294 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
296 GEOMBase_Skeleton::LineEditReturnPressed();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void BasicGUI_VectorDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 ConstructorsClicked( getConstructorId() );
312 //=================================================================================
313 // function : DeactivateActiveDialog()
314 // purpose : public slot to deactivate if active
315 //=================================================================================
316 void BasicGUI_VectorDlg::DeactivateActiveDialog()
318 myGeomGUI->SetState( -1 );
319 GEOMBase_Skeleton::DeactivateActiveDialog();
322 //=================================================================================
323 // function : enterEvent()
325 //=================================================================================
326 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
328 if ( !GroupConstructors->isEnabled() )
329 ActivateThisDialog();
332 //=================================================================================
333 // function : ValueChangedInSpinBox()
335 //=================================================================================
336 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
341 //=================================================================================
342 // function : ReverseVector()
343 // purpose : 'state' not used here
344 //=================================================================================
345 void BasicGUI_VectorDlg::ReverseVector(int state)
347 double dx = -GroupDimensions->SpinBox_DX->GetValue();
348 double dy = -GroupDimensions->SpinBox_DY->GetValue();
349 double dz = -GroupDimensions->SpinBox_DZ->GetValue();
351 GroupDimensions->SpinBox_DX->SetValue( dx );
352 GroupDimensions->SpinBox_DY->SetValue( dy );
353 GroupDimensions->SpinBox_DZ->SetValue( dz );
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
364 return getGeomEngine()->GetIBasicOperations( getStudyId() );
367 //=================================================================================
368 // function : isValid
370 //=================================================================================
371 bool BasicGUI_VectorDlg::isValid( QString& msg )
373 return getConstructorId() == 0 ? !myPoint1->_is_nil() && !myPoint2->_is_nil(): true;
376 //=================================================================================
377 // function : execute
379 //=================================================================================
380 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
384 GEOM::GEOM_Object_var anObj;
386 switch ( getConstructorId() ) {
388 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
394 double dx = GroupDimensions->SpinBox_DX->GetValue();
395 double dy = GroupDimensions->SpinBox_DY->GetValue();
396 double dz = GroupDimensions->SpinBox_DZ->GetValue();
397 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx,dy,dz );
403 if ( !anObj->_is_nil() )
404 objects.push_back( anObj._retn() );