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"
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"
42 //=================================================================================
43 // class : BasicGUI_PlaneDlg()
44 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
52 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
53 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_3PNTS")));
54 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
55 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_PLANE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_PLANE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->setPixmap(image1);
63 RadioButton3->setPixmap(image2);
65 GroupPntDir = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
66 GroupPntDir->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
67 GroupPntDir->TextLabel1->setText(tr("GEOM_POINT"));
68 GroupPntDir->TextLabel2->setText(tr("GEOM_VECTOR"));
69 GroupPntDir->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
70 GroupPntDir->PushButton1->setPixmap(image3);
71 GroupPntDir->PushButton2->setPixmap(image3);
72 GroupPntDir->LineEdit1->setReadOnly( true );
73 GroupPntDir->LineEdit2->setReadOnly( true );
75 Group3Pnts = new DlgRef_3Sel1Spin(this, "Group3Pnts");
76 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
77 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
78 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
79 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
80 Group3Pnts->TextLabel4->setText(tr("GEOM_PLANE_SIZE"));
81 Group3Pnts->PushButton1->setPixmap(image3);
82 Group3Pnts->PushButton2->setPixmap(image3);
83 Group3Pnts->PushButton3->setPixmap(image3);
85 Group3Pnts->LineEdit1->setReadOnly( true );
86 Group3Pnts->LineEdit2->setReadOnly( true );
87 Group3Pnts->LineEdit3->setReadOnly( true );
89 GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
90 GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
91 GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
92 GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
93 GroupFace->PushButton1->setPixmap(image3);
95 GroupFace->LineEdit1->setReadOnly( true );
97 Layout1->addWidget(GroupPntDir, 2, 0);
98 Layout1->addWidget(Group3Pnts, 2, 0);
99 Layout1->addWidget(GroupFace, 2, 0);
100 /***************************************************************/
106 //=================================================================================
107 // function : ~BasicGUI_PlaneDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
115 //=================================================================================
118 //=================================================================================
119 void BasicGUI_PlaneDlg::Init()
122 myEditCurrentArgument = GroupPntDir->LineEdit1;
124 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
126 // myGeometryGUI->SetState( 0 );
128 /* Get setting of step value from file configuration */
129 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
130 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
132 double aTrimSize = 2000.0;
134 /* min, max, step and decimals for spin boxes */
135 GroupPntDir->SpinBox_DX->RangeStepAndValidator( 0.001, 10000000.0, aStep, 3 );
136 GroupPntDir->SpinBox_DX->SetValue( aTrimSize );
137 Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
138 Group3Pnts->SpinBox_DX->SetValue( aTrimSize );
139 GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
140 GroupFace->SpinBox_DX->SetValue( aTrimSize );
142 /* signals and slots connections */
143 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
144 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
145 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
147 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
148 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
149 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
151 connect(GroupPntDir->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupPntDir->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPntDir->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPntDir->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupPntDir->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(Group3Pnts->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntDir->SpinBox_DX, SLOT(SetStep(double)));
170 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Pnts->SpinBox_DX, SLOT(SetStep(double)));
171 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
173 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 initName( tr( "GEOM_PLANE" ) );
179 ConstructorsClicked( 0 );
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose : Radio button management
186 //=================================================================================
187 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
189 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
190 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
192 switch ( constructorId )
194 case 0: /* plane from a point and a direction (vector, edge...) */
201 myEditCurrentArgument = GroupPntDir->LineEdit1;
202 GroupPntDir->LineEdit1->setText(tr(""));
203 GroupPntDir->LineEdit2->setText(tr(""));
205 /* for the first argument */
206 globalSelection( GEOM_POINT );
209 case 1: /* plane from 3 points */
216 myEditCurrentArgument = Group3Pnts->LineEdit1;
217 Group3Pnts->LineEdit1->setText("");
218 Group3Pnts->LineEdit2->setText("");
219 Group3Pnts->LineEdit3->setText("");
221 /* for the first argument */
222 globalSelection( GEOM_POINT );
225 case 2: /* plane from a planar face selection */
232 myEditCurrentArgument = GroupFace->LineEdit1;
233 GroupFace->LineEdit1->setText(tr(""));
235 /* for the first argument */
236 globalSelection( GEOM_PLANE );
241 myEditCurrentArgument->setFocus();
242 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
243 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
247 //=================================================================================
248 // function : ClickOnOk()
250 //=================================================================================
251 void BasicGUI_PlaneDlg::ClickOnOk()
253 if ( ClickOnApply() )
258 //=================================================================================
259 // function : ClickOnApply()
261 //=================================================================================
262 bool BasicGUI_PlaneDlg::ClickOnApply()
268 ConstructorsClicked( getConstructorId() );
272 //=======================================================================
273 // function : ClickOnCancel()
275 //=======================================================================
276 void BasicGUI_PlaneDlg::ClickOnCancel()
278 GEOMBase_Skeleton::ClickOnCancel();
281 //=================================================================================
282 // function : SelectionIntoArgument()
283 // purpose : Called when selection has changed
284 //=================================================================================
285 void BasicGUI_PlaneDlg::SelectionIntoArgument()
287 myEditCurrentArgument->setText("");
289 if ( IObjectCount() != 1 )
291 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
292 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
293 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
294 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
295 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
296 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = GEOM::GEOM_Object::_nil();
301 Standard_Boolean aRes = Standard_False;
302 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
303 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
305 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
306 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = aSelectedObject;
307 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = aSelectedObject;
308 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
309 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
310 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
311 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = aSelectedObject;
318 //=================================================================================
319 // function : SetEditCurrentArgument()
321 //=================================================================================
322 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
324 QPushButton* send = (QPushButton*)sender();
326 if ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
327 else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
328 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
329 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
330 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
331 else if ( send == GroupFace->PushButton1 ) myEditCurrentArgument = GroupFace->LineEdit1;
333 myEditCurrentArgument->setFocus();
335 if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
336 globalSelection( GEOM_LINE );
337 else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
338 globalSelection( GEOM_PLANE );
340 globalSelection( GEOM_POINT );
342 SelectionIntoArgument();
346 //=================================================================================
347 // function : LineEditReturnPressed()
349 //=================================================================================
350 void BasicGUI_PlaneDlg::LineEditReturnPressed()
352 QLineEdit* send = (QLineEdit*)sender();
353 if ( send == GroupPntDir->LineEdit1 ||
354 send == GroupPntDir->LineEdit2 ||
355 send == Group3Pnts->LineEdit1 ||
356 send == Group3Pnts->LineEdit2 ||
357 send == Group3Pnts->LineEdit3 ||
358 send == GroupFace->LineEdit1 )
360 myEditCurrentArgument = send;
361 GEOMBase_Skeleton::LineEditReturnPressed();
366 //=================================================================================
367 // function : ActivateThisDialog()
369 //=================================================================================
370 void BasicGUI_PlaneDlg::ActivateThisDialog()
372 GEOMBase_Skeleton::ActivateThisDialog();
373 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
374 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
376 // myGeometryGUI->SetState( 0 );
378 ConstructorsClicked( getConstructorId() );
381 //=================================================================================
382 // function : DeactivateActiveDialog()
383 // purpose : public slot to deactivate if active
384 //=================================================================================
385 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
387 // myGeometryGUI->SetState( -1 );
388 GEOMBase_Skeleton::DeactivateActiveDialog();
391 //=================================================================================
392 // function : enterEvent()
394 //=================================================================================
395 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
397 if ( !GroupConstructors->isEnabled() )
398 ActivateThisDialog();
402 //=================================================================================
403 // function : ValueChangedInSpinBox()
405 //=================================================================================
406 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
411 //=================================================================================
412 // function : getSize()
414 //=================================================================================
415 double BasicGUI_PlaneDlg::getSize() const
417 switch ( getConstructorId() )
419 case 0 : return GroupPntDir->SpinBox_DX->GetValue();
420 case 1 : return Group3Pnts->SpinBox_DX->GetValue();
421 case 2 : return GroupFace->SpinBox_DX->GetValue();
426 //=================================================================================
427 // function : createOperation
429 //=================================================================================
430 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
432 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
435 //=================================================================================
436 // function : isEqual
437 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
438 //=================================================================================
439 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
441 return thePnt1->_is_equivalent( thePnt2 );
444 //=================================================================================
445 // function : isValid
447 //=================================================================================
448 bool BasicGUI_PlaneDlg::isValid( QString& msg )
450 const int id = getConstructorId();
451 if ( getSize() <= 0 )
453 msg = QString( "Please, enter size greater than 0." );
457 return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
459 return !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
460 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
462 return !CORBA::is_nil( myFace );
466 //=================================================================================
467 // function : execute
469 //=================================================================================
470 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
474 GEOM::GEOM_Object_var anObj;
476 switch ( getConstructorId() )
479 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
483 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
487 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
492 if ( !anObj->_is_nil() )
493 objects.push_back( anObj._retn() );
498 //=================================================================================
499 // function : closeEvent
501 //=================================================================================
502 void BasicGUI_PlaneDlg::closeEvent( QCloseEvent* e )
504 // myGeometryGUI->SetState( -1 );
505 GEOMBase_Skeleton::closeEvent( e );