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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : BasicGUI_PlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_PlaneDlg.h"
30 #include "DlgRef_1Sel1Spin.h"
31 #include "DlgRef_2Sel1Spin.h"
32 #include "DlgRef_3Sel1Spin.h"
33 #include "DlgRef_SpinBox.h"
35 #include "GeometryGUI.h"
38 #include "SUIT_ResourceMgr.h"
39 #include "SUIT_Session.h"
40 #include "SalomeApp_Application.h"
41 #include "LightApp_SelectionMgr.h"
43 #include <TColStd_MapOfInteger.hxx>
45 #include "GEOMImpl_Types.hxx"
49 //=================================================================================
50 // class : BasicGUI_PlaneDlg()
51 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57 const char* name, bool modal, Qt::WindowFlags fl)
58 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
60 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
61 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_3PNTS")));
62 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
63 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65 setWindowTitle(tr("GEOM_PLANE_TITLE"));
67 /***************************************************************/
68 GroupConstructors->setTitle(tr("GEOM_PLANE"));
69 RadioButton1->setIcon(image0);
70 RadioButton2->setIcon(image1);
71 RadioButton3->setIcon(image2);
73 GroupPntDir = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
74 GroupPntDir->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
75 GroupPntDir->TextLabel1->setText(tr("GEOM_POINT"));
76 GroupPntDir->TextLabel2->setText(tr("GEOM_VECTOR"));
77 GroupPntDir->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
78 GroupPntDir->PushButton1->setIcon(image3);
79 GroupPntDir->PushButton2->setIcon(image3);
80 GroupPntDir->LineEdit1->setReadOnly( true );
81 GroupPntDir->LineEdit2->setReadOnly( true );
83 Group3Pnts = new DlgRef_3Sel1Spin(this, "Group3Pnts");
84 Group3Pnts->GroupBox1->setTitle(tr("GEOM_3_POINTS"));
85 Group3Pnts->TextLabel1->setText(tr("GEOM_POINT1"));
86 Group3Pnts->TextLabel2->setText(tr("GEOM_POINT2"));
87 Group3Pnts->TextLabel3->setText(tr("GEOM_POINT3"));
88 Group3Pnts->TextLabel4->setText(tr("GEOM_PLANE_SIZE"));
89 Group3Pnts->PushButton1->setIcon(image3);
90 Group3Pnts->PushButton2->setIcon(image3);
91 Group3Pnts->PushButton3->setIcon(image3);
93 Group3Pnts->LineEdit1->setReadOnly( true );
94 Group3Pnts->LineEdit2->setReadOnly( true );
95 Group3Pnts->LineEdit3->setReadOnly( true );
97 GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
98 GroupFace->GroupBox1->setTitle(tr("GEOM_FACE_OR_LCS"));
99 GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
100 GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
101 GroupFace->PushButton1->setIcon(image3);
103 GroupFace->LineEdit1->setReadOnly( true );
105 gridLayout1->addWidget(GroupPntDir, 2, 0);
106 gridLayout1->addWidget(Group3Pnts, 2, 0);
107 gridLayout1->addWidget(GroupFace, 2, 0);
108 /***************************************************************/
110 setHelpFileName("plane.htm");
116 //=================================================================================
117 // function : ~BasicGUI_PlaneDlg()
118 // purpose : Destroys the object and frees any allocated resources
119 //=================================================================================
120 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
125 //=================================================================================
128 //=================================================================================
129 void BasicGUI_PlaneDlg::Init()
132 myEditCurrentArgument = GroupPntDir->LineEdit1;
134 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
136 // myGeomGUI->SetState( 0 );
138 /* Get setting of step value from file configuration */
139 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
140 double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
142 double aTrimSize = 2000.0;
144 /* min, max, step and decimals for spin boxes */
145 GroupPntDir->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, aStep, 3 );
146 GroupPntDir->SpinBox_DX->SetValue( aTrimSize );
147 Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, 3);
148 Group3Pnts->SpinBox_DX->SetValue( aTrimSize );
149 GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, 3);
150 GroupFace->SpinBox_DX->SetValue( aTrimSize );
152 /* signals and slots connections */
153 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
154 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
155 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
157 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
158 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
159 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
161 connect(GroupPntDir->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(GroupPntDir->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166 connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168 connect(GroupPntDir->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
169 connect(GroupPntDir->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
170 connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
171 connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
172 connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
173 connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
175 connect(GroupPntDir->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176 connect(Group3Pnts->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
177 connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
179 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntDir->SpinBox_DX, SLOT(SetStep(double)));
180 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Pnts->SpinBox_DX, SLOT(SetStep(double)));
181 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
183 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 initName( tr( "GEOM_PLANE" ).toStdString().c_str() );
189 ConstructorsClicked( 0 );
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
199 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
200 myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
202 switch ( constructorId )
204 case 0: /* plane from a point and a direction (vector, edge...) */
211 myEditCurrentArgument = GroupPntDir->LineEdit1;
212 GroupPntDir->LineEdit1->setText(tr(""));
213 GroupPntDir->LineEdit2->setText(tr(""));
215 /* for the first argument */
216 globalSelection( GEOM_POINT );
219 case 1: /* plane from 3 points */
226 myEditCurrentArgument = Group3Pnts->LineEdit1;
227 Group3Pnts->LineEdit1->setText("");
228 Group3Pnts->LineEdit2->setText("");
229 Group3Pnts->LineEdit3->setText("");
231 /* for the first argument */
232 globalSelection( GEOM_POINT );
235 case 2: /* plane from a planar face selection */
242 myEditCurrentArgument = GroupFace->LineEdit1;
243 GroupFace->LineEdit1->setText(tr(""));
245 /* for the first argument */
246 //globalSelection( GEOM_PLANE );
247 TColStd_MapOfInteger aMap;
248 aMap.Add( GEOM_PLANE );
249 aMap.Add( GEOM_MARKER );
250 globalSelection( aMap );
255 myEditCurrentArgument->setFocus();
256 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
257 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 //=================================================================================
262 // function : ClickOnOk()
264 //=================================================================================
265 void BasicGUI_PlaneDlg::ClickOnOk()
267 if ( ClickOnApply() )
272 //=================================================================================
273 // function : ClickOnApply()
275 //=================================================================================
276 bool BasicGUI_PlaneDlg::ClickOnApply()
282 ConstructorsClicked( getConstructorId() );
286 //=======================================================================
287 // function : ClickOnCancel()
289 //=======================================================================
290 void BasicGUI_PlaneDlg::ClickOnCancel()
292 GEOMBase_Skeleton::ClickOnCancel();
295 //=================================================================================
296 // function : SelectionIntoArgument()
297 // purpose : Called when selection has changed
298 //=================================================================================
299 void BasicGUI_PlaneDlg::SelectionIntoArgument()
301 myEditCurrentArgument->setText("");
303 if ( IObjectCount() != 1 )
305 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
306 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
307 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
308 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
309 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = GEOM::GEOM_Object::_nil();
310 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = GEOM::GEOM_Object::_nil();
315 Standard_Boolean aRes = Standard_False;
316 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
317 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
319 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
320 if ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint = aSelectedObject;
321 else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir = aSelectedObject;
322 else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 ) myPoint1 = aSelectedObject;
323 else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 ) myPoint2 = aSelectedObject;
324 else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 ) myPoint3 = aSelectedObject;
325 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) myFace = aSelectedObject;
332 //=================================================================================
333 // function : SetEditCurrentArgument()
335 //=================================================================================
336 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
338 QPushButton* send = (QPushButton*)sender();
340 if ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
341 else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
342 else if ( send == Group3Pnts->PushButton1 ) myEditCurrentArgument = Group3Pnts->LineEdit1;
343 else if ( send == Group3Pnts->PushButton2 ) myEditCurrentArgument = Group3Pnts->LineEdit2;
344 else if ( send == Group3Pnts->PushButton3 ) myEditCurrentArgument = Group3Pnts->LineEdit3;
345 else if ( send == GroupFace->PushButton1 ) myEditCurrentArgument = GroupFace->LineEdit1;
347 myEditCurrentArgument->setFocus();
349 if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
350 globalSelection( GEOM_LINE );
351 else if ( myEditCurrentArgument == GroupFace->LineEdit1 ) {
352 //globalSelection( GEOM_PLANE );
353 TColStd_MapOfInteger aMap;
354 aMap.Add( GEOM_PLANE );
355 aMap.Add( GEOM_MARKER );
356 globalSelection( aMap );
359 globalSelection( GEOM_POINT );
361 SelectionIntoArgument();
365 //=================================================================================
366 // function : LineEditReturnPressed()
368 //=================================================================================
369 void BasicGUI_PlaneDlg::LineEditReturnPressed()
371 QLineEdit* send = (QLineEdit*)sender();
372 if ( send == GroupPntDir->LineEdit1 ||
373 send == GroupPntDir->LineEdit2 ||
374 send == Group3Pnts->LineEdit1 ||
375 send == Group3Pnts->LineEdit2 ||
376 send == Group3Pnts->LineEdit3 ||
377 send == GroupFace->LineEdit1 )
379 myEditCurrentArgument = send;
380 GEOMBase_Skeleton::LineEditReturnPressed();
385 //=================================================================================
386 // function : ActivateThisDialog()
388 //=================================================================================
389 void BasicGUI_PlaneDlg::ActivateThisDialog()
391 GEOMBase_Skeleton::ActivateThisDialog();
392 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
393 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
395 // myGeomGUI->SetState( 0 );
397 ConstructorsClicked( getConstructorId() );
400 //=================================================================================
401 // function : DeactivateActiveDialog()
402 // purpose : public slot to deactivate if active
403 //=================================================================================
404 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
406 // myGeomGUI->SetState( -1 );
407 GEOMBase_Skeleton::DeactivateActiveDialog();
410 //=================================================================================
411 // function : enterEvent()
413 //=================================================================================
414 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
416 if ( !GroupConstructors->isEnabled() )
417 ActivateThisDialog();
421 //=================================================================================
422 // function : ValueChangedInSpinBox()
424 //=================================================================================
425 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
430 //=================================================================================
431 // function : getSize()
433 //=================================================================================
434 double BasicGUI_PlaneDlg::getSize() const
436 switch ( getConstructorId() )
438 case 0 : return GroupPntDir->SpinBox_DX->GetValue();
439 case 1 : return Group3Pnts->SpinBox_DX->GetValue();
440 case 2 : return GroupFace->SpinBox_DX->GetValue();
445 //=================================================================================
446 // function : createOperation
448 //=================================================================================
449 GEOM::GEOM_IOperations_ptr BasicGUI_PlaneDlg::createOperation()
451 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
454 //=================================================================================
455 // function : isEqual
456 // purpose : it may also be needed to check for min distance between gp_Pnt-s...
457 //=================================================================================
458 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
460 return thePnt1->_is_equivalent( thePnt2 );
463 //=================================================================================
464 // function : isValid
466 //=================================================================================
467 bool BasicGUI_PlaneDlg::isValid( QString& msg )
469 const int id = getConstructorId();
470 if ( getSize() <= 0 )
472 msg = QString( "Please, enter size greater than 0." );
476 return !CORBA::is_nil( myPoint ) && !CORBA::is_nil( myDir );
478 return !CORBA::is_nil( myPoint1 ) && !CORBA::is_nil( myPoint2 ) && !CORBA::is_nil( myPoint3 ) &&
479 !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
481 return !CORBA::is_nil( myFace );
485 //=================================================================================
486 // function : execute
488 //=================================================================================
489 bool BasicGUI_PlaneDlg::execute( ObjectList& objects )
493 GEOM::GEOM_Object_var anObj;
495 switch ( getConstructorId() )
498 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlanePntVec( myPoint, myDir, getSize() );
502 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneThreePnt( myPoint1, myPoint2, myPoint3, getSize() );
506 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePlaneFace( myFace, getSize() );
511 if ( !anObj->_is_nil() )
512 objects.push_back( anObj._retn() );
517 //=================================================================================
518 // function : closeEvent
520 //=================================================================================
521 void BasicGUI_PlaneDlg::closeEvent( QCloseEvent* e )
523 GEOMBase_Skeleton::closeEvent( e );