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_PlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_PlaneDlg.h"
30 #include "QAD_Config.h"
31 #include "QAD_Desktop.h"
33 #include "GEOMImpl_Types.hxx"
37 //=================================================================================
38 // class : BasicGUI_PlaneDlg()
39 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_3PNTS")));
49 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
50 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_PLANE_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_PLANE"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->setPixmap(image1);
58 RadioButton3->setPixmap(image2);
60 GroupPntDir = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
61 GroupPntDir->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
62 GroupPntDir->TextLabel1->setText(tr("GEOM_POINT"));
63 GroupPntDir->TextLabel2->setText(tr("GEOM_VECTOR"));
64 GroupPntDir->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
65 GroupPntDir->PushButton1->setPixmap(image3);
66 GroupPntDir->PushButton2->setPixmap(image3);
67 GroupPntDir->LineEdit1->setReadOnly( true );
68 GroupPntDir->LineEdit2->setReadOnly( true );
70 Group3Pnts = new DlgRef_3Sel1Spin(this, "Group3Pnts");
71 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
72 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
73 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
74 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
75 Group3Pnts->TextLabel4->setText(tr("GEOM_PLANE_SIZE"));
76 Group3Pnts->PushButton1->setPixmap(image3);
77 Group3Pnts->PushButton2->setPixmap(image3);
78 Group3Pnts->PushButton3->setPixmap(image3);
80 Group3Pnts->LineEdit1->setReadOnly( true );
81 Group3Pnts->LineEdit2->setReadOnly( true );
82 Group3Pnts->LineEdit3->setReadOnly( true );
84 GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
85 GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
86 GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
87 GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
88 GroupFace->PushButton1->setPixmap(image3);
90 GroupFace->LineEdit1->setReadOnly( true );
92 Layout1->addWidget(GroupPntDir, 2, 0);
93 Layout1->addWidget(Group3Pnts, 2, 0);
94 Layout1->addWidget(GroupFace, 2, 0);
95 /***************************************************************/
101 //=================================================================================
102 // function : ~BasicGUI_PlaneDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
110 //=================================================================================
113 //=================================================================================
114 void BasicGUI_PlaneDlg::Init()
117 myEditCurrentArgument = GroupPntDir->LineEdit1;
119 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
121 myGeomGUI->SetState( 0 );
123 /* Get setting of step value from file configuration */
124 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
125 double aStep = St.toDouble();
126 double aTrimSize = 2000.0;
128 /* min, max, step and decimals for spin boxes */
129 GroupPntDir->SpinBox_DX->RangeStepAndValidator( 0.001, 10000000.0, aStep, 3 );
130 GroupPntDir->SpinBox_DX->SetValue( aTrimSize );
131 Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
132 Group3Pnts->SpinBox_DX->SetValue( aTrimSize );
133 GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
134 GroupFace->SpinBox_DX->SetValue( aTrimSize );
136 /* signals and slots connections */
137 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
138 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
139 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
143 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
145 connect(GroupPntDir->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(GroupPntDir->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPntDir->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(GroupPntDir->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
154 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPntDir->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(Group3Pnts->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntDir->SpinBox_DX, SLOT(SetStep(double)));
164 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Pnts->SpinBox_DX, SLOT(SetStep(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
167 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
169 initName( tr( "GEOM_PLANE" ) );
173 ConstructorsClicked( 0 );
177 //=================================================================================
178 // function : ConstructorsClicked()
179 // purpose : Radio button management
180 //=================================================================================
181 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
183 disconnect(mySelection, 0, this, 0);
184 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
186 switch ( constructorId )
188 case 0: /* plane from a point and a direction (vector, edge...) */
195 myEditCurrentArgument = GroupPntDir->LineEdit1;
196 GroupPntDir->LineEdit1->setText(tr(""));
197 GroupPntDir->LineEdit2->setText(tr(""));
199 /* for the first argument */
200 globalSelection( GEOM_POINT );
203 case 1: /* plane from 3 points */
210 myEditCurrentArgument = Group3Pnts->LineEdit1;
211 Group3Pnts->LineEdit1->setText("");
212 Group3Pnts->LineEdit2->setText("");
213 Group3Pnts->LineEdit3->setText("");
215 /* for the first argument */
216 globalSelection( GEOM_POINT );
219 case 2: /* plane from a planar face selection */
226 myEditCurrentArgument = GroupFace->LineEdit1;
227 GroupFace->LineEdit1->setText(tr(""));
229 /* for the first argument */
230 globalSelection( GEOM_PLANE );
235 myEditCurrentArgument->setFocus();
236 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240 //=================================================================================
241 // function : ClickOnOk()
243 //=================================================================================
244 void BasicGUI_PlaneDlg::ClickOnOk()
246 if ( ClickOnApply() )
251 //=================================================================================
252 // function : ClickOnApply()
254 //=================================================================================
255 bool BasicGUI_PlaneDlg::ClickOnApply()
261 ConstructorsClicked( getConstructorId() );
265 //=======================================================================
266 // function : ClickOnCancel()
268 //=======================================================================
269 void BasicGUI_PlaneDlg::ClickOnCancel()
271 GEOMBase_Skeleton::ClickOnCancel();
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose : Called when selection has changed
277 //=================================================================================
278 void BasicGUI_PlaneDlg::SelectionIntoArgument()
280 myEditCurrentArgument->setText("");
282 if ( mySelection->IObjectCount() != 1 )
284 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
285 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
286 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
287 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
288 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
289 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = GEOM::GEOM_Object::_nil();
294 Standard_Boolean aRes = Standard_False;
295 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
296 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
298 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
299 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = aSelectedObject;
300 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = aSelectedObject;
301 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
302 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
303 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
304 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = aSelectedObject;
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
319 if ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
320 else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
321 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
322 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
323 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
324 else if ( send == GroupFace->PushButton1 ) myEditCurrentArgument = GroupFace->LineEdit1;
326 myEditCurrentArgument->setFocus();
328 if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
329 globalSelection( GEOM_LINE );
330 else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
331 globalSelection( GEOM_PLANE );
333 globalSelection( GEOM_POINT );
335 SelectionIntoArgument();
339 //=================================================================================
340 // function : LineEditReturnPressed()
342 //=================================================================================
343 void BasicGUI_PlaneDlg::LineEditReturnPressed()
345 QLineEdit* send = (QLineEdit*)sender();
346 if ( send == GroupPntDir->LineEdit1 ||
347 send == GroupPntDir->LineEdit2 ||
348 send == Group3Pnts->LineEdit1 ||
349 send == Group3Pnts->LineEdit2 ||
350 send == Group3Pnts->LineEdit3 ||
351 send == GroupFace->LineEdit1 )
353 myEditCurrentArgument = send;
354 GEOMBase_Skeleton::LineEditReturnPressed();
359 //=================================================================================
360 // function : ActivateThisDialog()
362 //=================================================================================
363 void BasicGUI_PlaneDlg::ActivateThisDialog()
365 GEOMBase_Skeleton::ActivateThisDialog();
366 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
368 myGeomGUI->SetState( 0 );
370 ConstructorsClicked( getConstructorId() );
373 //=================================================================================
374 // function : DeactivateActiveDialog()
375 // purpose : public slot to deactivate if active
376 //=================================================================================
377 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
379 myGeomGUI->SetState( -1 );
380 GEOMBase_Skeleton::DeactivateActiveDialog();
383 //=================================================================================
384 // function : enterEvent()
386 //=================================================================================
387 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
389 if ( !GroupConstructors->isEnabled() )
390 ActivateThisDialog();
394 //=================================================================================
395 // function : ValueChangedInSpinBox()
397 //=================================================================================
398 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
403 //=================================================================================
404 // function : getSize()
406 //=================================================================================
407 double BasicGUI_PlaneDlg::getSize() const
409 switch ( getConstructorId() )
411 case 0 : return GroupPntDir->SpinBox_DX->GetValue();
412 case 1 : return Group3Pnts->SpinBox_DX->GetValue();
413 case 2 : return GroupFace->SpinBox_DX->GetValue();
418 //=================================================================================
419 // function : createOperation
421 //=================================================================================
422 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
424 return getGeomEngine()->GetIBasicOperations( getStudyId() );
427 //=================================================================================
428 // function : isEqual
429 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
430 //=================================================================================
431 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
433 return thePnt1->_is_equivalent( thePnt2 );
436 //=================================================================================
437 // function : isValid
439 //=================================================================================
440 bool BasicGUI_PlaneDlg::isValid( QString& msg )
442 const int id = getConstructorId();
443 if ( getSize() <= 0 )
445 msg = QString( "Please, enter size greater than 0." );
449 return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
451 return !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
452 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
454 return !CORBA::is_nil( myFace );
458 //=================================================================================
459 // function : execute
461 //=================================================================================
462 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
466 GEOM::GEOM_Object_var anObj;
468 switch ( getConstructorId() )
471 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
475 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
479 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
484 if ( !anObj->_is_nil() )
485 objects.push_back( anObj._retn() );
490 //=================================================================================
491 // function : closeEvent
493 //=================================================================================
494 void BasicGUI_PlaneDlg::closeEvent( QCloseEvent* e )
496 myGeomGUI->SetState( -1 );
497 GEOMBase_Skeleton::closeEvent( e );