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
22 // File : BasicGUI_WorkingPlaneDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_WorkingPlaneDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <BRep_Tool.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45 #include <TopoDS_Shape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <GEOMImpl_Types.hxx>
54 //=================================================================================
55 // class : BasicGUI_WorkingPlaneDlg()
56 // purpose : Constructs a BasicGUI_WorkingPlaneDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
62 bool modal, Qt::WindowFlags fl )
63 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
65 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_FACE" ) ) );
67 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_VECTOR" ) ) );
68 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_WPLANE_ORIGIN" ) ) );
70 setWindowTitle( tr( "GEOM_WPLANE_TITLE" ) );
72 /***************************************************************/
73 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WPLANE" ) );
74 mainFrame()->RadioButton1->setIcon( image1 );
75 mainFrame()->RadioButton2->setIcon( image2 );
76 mainFrame()->RadioButton3->setIcon( image3 );
78 Group1 = new DlgRef_1Sel( centralWidget() );
80 Group1->GroupBox1->setTitle( tr( "GEOM_WPLANE_FACE" ) );
81 Group1->TextLabel1->setText( tr( "GEOM_SELECTION" ) );
82 Group1->PushButton1->setIcon( image0 );
83 Group1->LineEdit1->setReadOnly( true );
85 Group2 = new DlgRef_2Sel( centralWidget() );
87 Group2->GroupBox1->setTitle( tr( "GEOM_WPLANE_VECTOR" ) );
88 Group2->TextLabel1->setText( tr( "GEOM_WPLANE_VX" ) );
89 Group2->TextLabel2->setText( tr( "GEOM_WPLANE_VZ" ) );
90 Group2->PushButton1->setIcon( image0 );
91 Group2->PushButton2->setIcon( image0 );
92 Group2->LineEdit1->setReadOnly( true );
93 Group2->LineEdit2->setReadOnly( true );
95 Group3 = new DlgRef_3Check( centralWidget() );
97 Group3->GroupBox1->setTitle( tr( "GEOM_WPLANE_ORIGIN" ) );
98 Group3->RadioButton1->setText( tr( "GEOM_WPLANE_OXY" ) );
99 Group3->RadioButton2->setText( tr( "GEOM_WPLANE_OYZ" ) );
100 Group3->RadioButton3->setText( tr( "GEOM_WPLANE_OZX" ) );
102 /***************************************************************/
103 QGroupBox* aReverseGroupBox = new QGroupBox( centralWidget() );
104 QHBoxLayout* aReverseGroupBoxLayout = new QHBoxLayout( aReverseGroupBox );
105 aReverseGroupBoxLayout->setMargin( 9 );
106 aReverseGroupBoxLayout->setSpacing( 6 );
108 myReverseCB = new QCheckBox( aReverseGroupBox );
109 myReverseCB->setText( tr( "GEOM_REVERSE_PLANE" ) );
110 aReverseGroupBoxLayout->addWidget( myReverseCB );
112 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
113 layout->setMargin( 0 ); layout->setSpacing( 6 );
114 layout->addWidget( Group1 );
115 layout->addWidget( Group2 );
116 layout->addWidget( Group3 );
117 layout->addWidget( aReverseGroupBox );
119 setHelpFileName( "create_wplane_page.html" );
124 //=================================================================================
125 // function : ~BasicGUI_WorkingPlaneDlg()
126 // purpose : Destroys the object and frees any allocated resources
127 //=================================================================================
128 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
132 //=================================================================================
135 //=================================================================================
136 void BasicGUI_WorkingPlaneDlg::Init()
139 myEditCurrentArgument = Group1->LineEdit1;
140 myWPlane = myGeomGUI->GetWorkingPlane();
142 // myGeomGUI->SetState( 0 );
144 myFace = GEOM::GEOM_Object::_nil();
145 myVectX = GEOM::GEOM_Object::_nil();
146 myVectZ = GEOM::GEOM_Object::_nil();
150 /* Filter definition */
151 globalSelection( GEOM_PLANE );
153 /* signals and slots connections */
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() ) );
160 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
162 connect( Group1->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
163 connect( Group1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
164 connect( Group2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
165 connect( Group2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
166 connect( Group2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
167 connect( Group2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
169 connect( Group3->GroupBox1, SIGNAL( clicked( int ) ), this, SLOT( GroupClicked( int ) ) );
171 connect( myReverseCB, SIGNAL( clicked() ), this, SLOT( onReverse() ) );
173 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
174 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
176 initName( tr( "GEOM_WPLANE" ) );
178 ConstructorsClicked( 0 );
181 //=================================================================================
182 // function : ConstructorsClicked()
183 // purpose : Radio button management
184 //=================================================================================
185 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId )
187 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
189 disconnect( aSelMgr, 0, this, 0 );
191 switch ( constructorId ) {
194 //globalSelection( GEOM_PLANE );
195 TColStd_MapOfInteger aMap;
196 aMap.Add( GEOM_PLANE );
197 aMap.Add( GEOM_MARKER );
198 globalSelection( aMap );
204 myEditCurrentArgument = Group1->LineEdit1;
205 Group1->LineEdit1->setText( "" );
206 myFace = GEOM::GEOM_Object::_nil();
208 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
213 //globalSelection( GEOM_LINE );
214 GEOM::GEOM_Object_var anObj;
215 localSelection( anObj, TopAbs_EDGE );
221 myEditCurrentArgument = Group2->LineEdit1;
222 Group2->LineEdit1->setText( "" );
223 Group2->LineEdit2->setText( "" );
224 myVectX = GEOM::GEOM_Object::_nil();
225 myVectZ = GEOM::GEOM_Object::_nil();
227 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236 Group3->RadioButton1->setChecked( true );
242 qApp->processEvents();
244 resize( minimumSize() );
249 //=================================================================================
250 // function : GroupClicked()
251 // purpose : Radio button management
252 //=================================================================================
253 void BasicGUI_WorkingPlaneDlg::GroupClicked( int groupId )
255 aOriginType = groupId;
259 //=================================================================================
260 // function : ClickOnOk()
262 //=================================================================================
263 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
265 if ( ClickOnApply() )
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
275 buttonApply()->setFocus();
276 myGeomGUI->application()->putInfo( "" );
278 if ( updateWPlane( false ) ) {
279 myGeomGUI->SetWorkingPlane( myWPlane );
280 myGeomGUI->ActiveWorkingPlane();
286 //=================================================================================
287 // function : SelectionIntoArgument()
288 // purpose : Called when selection as changed or other case
289 //=================================================================================
290 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
292 myEditCurrentArgument->setText( "" );
295 const int id = getConstructorId();
296 if ( IObjectCount() != 1 ) {
298 myFace = GEOM::GEOM_Object::_nil();
299 else if ( id == 1 ) {
300 if ( myEditCurrentArgument == Group2->LineEdit1 )
301 myVectX = GEOM::GEOM_Object::_nil();
302 else if ( myEditCurrentArgument == Group2->LineEdit2 )
303 myVectZ = GEOM::GEOM_Object::_nil();
309 Standard_Boolean aRes = Standard_False;
310 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
312 if ( !aRes || CORBA::is_nil( aSelectedObject ) )
315 aName = GEOMBase::GetName(aSelectedObject);
317 if ( myEditCurrentArgument == Group1->LineEdit1 )
318 myFace = aSelectedObject;
319 else if ( myEditCurrentArgument == Group2->LineEdit1 ||
320 myEditCurrentArgument == Group2->LineEdit2 ) {
321 if ( aRes && !aSelectedObject->_is_nil() ) {
323 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
324 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
325 TColStd_IndexedMapOfInteger aMap;
326 aSelMgr->GetIndexes( firstIObject(), aMap );
327 if ( aMap.Extent() == 1 ) {
328 int anIndex = aMap( 1 );
329 aName = aName + ":edge_" + QString::number( anIndex );
331 GEOM::GEOM_IShapesOperations_var aShapesOp =
332 getGeomEngine()->GetIShapesOperations( getStudyId() );
333 if ( myEditCurrentArgument == Group2->LineEdit1 )
334 myVectX = aShapesOp->GetSubShape( aSelectedObject, anIndex );
336 myVectZ = aShapesOp->GetSubShape( aSelectedObject, anIndex );
339 if ( myEditCurrentArgument == Group2->LineEdit1 )
340 myVectX = aSelectedObject;
342 myVectZ = aSelectedObject;
344 aSelMgr->clearSelected();
349 myEditCurrentArgument->setText( aName );
355 //=================================================================================
356 // function : SetEditCurrentArgument()
358 //=================================================================================
359 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
361 QPushButton* send = (QPushButton*)sender();
363 if ( send == Group1->PushButton1 ) {
364 myEditCurrentArgument = Group1->LineEdit1;
365 globalSelection( GEOM_PLANE );
367 else if ( send == Group2->PushButton1 ) {
368 myEditCurrentArgument = Group2->LineEdit1;
369 GEOM::GEOM_Object_var anObj;
370 localSelection( anObj, TopAbs_EDGE );
372 else if ( send == Group2->PushButton2 ) {
373 myEditCurrentArgument = Group2->LineEdit2;
374 GEOM::GEOM_Object_var anObj;
375 localSelection( anObj, TopAbs_EDGE );
378 myEditCurrentArgument->setFocus();
379 SelectionIntoArgument();
383 //=================================================================================
384 // function : LineEditReturnPressed()
386 //=================================================================================
387 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
389 QLineEdit* send = (QLineEdit*)sender();
390 if ( send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2 ) {
391 myEditCurrentArgument = send;
392 GEOMBase_Skeleton::LineEditReturnPressed();
397 //=================================================================================
398 // function : onReverse()
400 //=================================================================================
401 void BasicGUI_WorkingPlaneDlg::onReverse()
407 //=================================================================================
408 // function : ActivateThisDialog()
410 //=================================================================================
411 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
413 GEOMBase_Skeleton::ActivateThisDialog();
414 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ) )->selectionMgr(),
415 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
417 ConstructorsClicked( getConstructorId() );
421 //=================================================================================
422 // function : DeactivateActiveDialog()
423 // purpose : public slot to deactivate if active
424 //=================================================================================
425 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
427 // myGeomGUI->SetState( -1 );
428 GEOMBase_Skeleton::DeactivateActiveDialog();
431 //=================================================================================
432 // function : enterEvent()
434 //=================================================================================
435 void BasicGUI_WorkingPlaneDlg::enterEvent( QEvent* )
437 if ( !mainFrame()->GroupConstructors->isEnabled() )
438 ActivateThisDialog();
441 //=================================================================================
442 // function : updateWPlane
444 //=================================================================================
445 bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
449 const int id = getConstructorId();
451 if ( id == 0 ) { // by planar face selection
452 if ( CORBA::is_nil( myFace ) ) {
454 showError( "Face has to be selected" );
458 // PAL12781: set center of WPL to face's center of mass
459 // like it is done for LCS creation
460 CORBA::Double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
461 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
464 GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
465 myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
466 aMeasureOp->GetPosition( myFace, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
468 if ( aMeasureOp->IsDone() ) {
469 gp_Pnt aPnt ( Ox, Oy, Oz );
470 gp_Dir aDirN ( Zx, Zy, Zz );
471 gp_Dir aDirX ( Xx, Xy, Xz );
472 myWPlane = gp_Ax3( aPnt, aDirN, aDirX );
476 showError( "Wrong shape selected (has to be a planar face)" );
480 else if ( id == 1 ) { // by two vectors (Ox & Oz)
481 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
483 showError( "Two vectors have to be selected" );
487 TopoDS_Edge aVectX, aVectZ;
488 TopoDS_Vertex VX1, VX2, VZ1, VZ2;
491 if ( !GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
492 !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE ) ) {
494 showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
498 TopExp::Vertices( aVectX, VX1, VX2, Standard_True );
499 TopExp::Vertices( aVectZ, VZ1, VZ2, Standard_True );
501 if ( VX1.IsNull() || VX2.IsNull() ) {
503 showError( "Bad OX vector" );
506 if ( VZ1.IsNull() || VZ2.IsNull() ) {
508 showError( "Bad OZ vector" );
512 aVX = gp_Vec( BRep_Tool::Pnt( VX1 ), BRep_Tool::Pnt( VX2 ) );
513 aVZ = gp_Vec( BRep_Tool::Pnt( VZ1 ), BRep_Tool::Pnt( VZ2 ) );
515 if ( aVX.Magnitude() < Precision::Confusion() ) {
517 showError( "Bad OX vector" );
520 if ( aVZ.Magnitude() < Precision::Confusion() ) {
522 showError( "Bad OZ vector" );
526 gp_Dir aDirX = gp_Dir( aVX.X(), aVX.Y(), aVX.Z() );
527 gp_Dir aDirZ = gp_Dir( aVZ.X(), aVZ.Y(), aVZ.Z() );
529 if ( aDirX.IsParallel( aDirZ, Precision::Angular() ) ) {
531 showError( "Parallel vectors selected" );
535 myWPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX );
538 else if ( id == 2 ) { // by selection from standard (OXY or OYZ, or OZX)
541 if ( aOriginType == 1 ) anAx2 = gp::XOY();
542 else if ( aOriginType == 2 ) anAx2 = gp::YOZ();
543 else if ( aOriginType == 0 ) anAx2 = gp::ZOX();
545 myWPlane = gp_Ax3( anAx2 );
552 if ( myReverseCB->isChecked() ) {
558 GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
559 GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
560 myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
561 myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
562 displayPreview( anObj );