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 setConstructorId( 2 ); // simplest constructor
179 ConstructorsClicked( 2 );
182 //=================================================================================
183 // function : ConstructorsClicked()
184 // purpose : Radio button management
185 //=================================================================================
186 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked( int constructorId )
188 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
190 disconnect( aSelMgr, 0, this, 0 );
192 switch ( constructorId ) {
195 //globalSelection( GEOM_PLANE );
196 TColStd_MapOfInteger aMap;
197 aMap.Add( GEOM_PLANE );
198 aMap.Add( GEOM_MARKER );
199 globalSelection( aMap );
205 myEditCurrentArgument = Group1->LineEdit1;
206 Group1->LineEdit1->setText( "" );
207 myFace = GEOM::GEOM_Object::_nil();
209 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
214 //globalSelection( GEOM_LINE );
215 GEOM::GEOM_Object_var anObj;
216 localSelection( anObj, TopAbs_EDGE );
222 myEditCurrentArgument = Group2->LineEdit1;
223 Group2->LineEdit1->setText( "" );
224 Group2->LineEdit2->setText( "" );
225 myVectX = GEOM::GEOM_Object::_nil();
226 myVectZ = GEOM::GEOM_Object::_nil();
228 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
237 Group3->RadioButton1->setChecked( true );
243 qApp->processEvents();
245 resize( minimumSize() );
250 //=================================================================================
251 // function : GroupClicked()
252 // purpose : Radio button management
253 //=================================================================================
254 void BasicGUI_WorkingPlaneDlg::GroupClicked( int groupId )
256 aOriginType = groupId;
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
266 if ( ClickOnApply() )
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
276 buttonApply()->setFocus();
277 myGeomGUI->application()->putInfo( "" );
279 if ( updateWPlane( false ) ) {
280 myGeomGUI->SetWorkingPlane( myWPlane );
281 myGeomGUI->ActiveWorkingPlane();
287 //=================================================================================
288 // function : SelectionIntoArgument()
289 // purpose : Called when selection as changed or other case
290 //=================================================================================
291 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
293 myEditCurrentArgument->setText( "" );
296 const int id = getConstructorId();
297 if ( IObjectCount() != 1 ) {
299 myFace = GEOM::GEOM_Object::_nil();
300 else if ( id == 1 ) {
301 if ( myEditCurrentArgument == Group2->LineEdit1 )
302 myVectX = GEOM::GEOM_Object::_nil();
303 else if ( myEditCurrentArgument == Group2->LineEdit2 )
304 myVectZ = GEOM::GEOM_Object::_nil();
310 Standard_Boolean aRes = Standard_False;
311 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
313 if ( !aRes || CORBA::is_nil( aSelectedObject ) )
316 aName = GEOMBase::GetName(aSelectedObject);
318 if ( myEditCurrentArgument == Group1->LineEdit1 )
319 myFace = aSelectedObject;
320 else if ( myEditCurrentArgument == Group2->LineEdit1 ||
321 myEditCurrentArgument == Group2->LineEdit2 ) {
322 if ( aRes && !aSelectedObject->_is_nil() ) {
324 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
325 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
326 TColStd_IndexedMapOfInteger aMap;
327 aSelMgr->GetIndexes( firstIObject(), aMap );
328 if ( aMap.Extent() == 1 ) {
329 int anIndex = aMap( 1 );
330 aName = aName + ":edge_" + QString::number( anIndex );
332 GEOM::GEOM_IShapesOperations_var aShapesOp =
333 getGeomEngine()->GetIShapesOperations( getStudyId() );
334 if ( myEditCurrentArgument == Group2->LineEdit1 )
335 myVectX = aShapesOp->GetSubShape( aSelectedObject, anIndex );
337 myVectZ = aShapesOp->GetSubShape( aSelectedObject, anIndex );
340 if ( myEditCurrentArgument == Group2->LineEdit1 )
341 myVectX = aSelectedObject;
343 myVectZ = aSelectedObject;
345 aSelMgr->clearSelected();
350 myEditCurrentArgument->setText( aName );
356 //=================================================================================
357 // function : SetEditCurrentArgument()
359 //=================================================================================
360 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
362 QPushButton* send = (QPushButton*)sender();
364 if ( send == Group1->PushButton1 ) {
365 myEditCurrentArgument = Group1->LineEdit1;
366 globalSelection( GEOM_PLANE );
368 else if ( send == Group2->PushButton1 ) {
369 myEditCurrentArgument = Group2->LineEdit1;
370 GEOM::GEOM_Object_var anObj;
371 localSelection( anObj, TopAbs_EDGE );
373 else if ( send == Group2->PushButton2 ) {
374 myEditCurrentArgument = Group2->LineEdit2;
375 GEOM::GEOM_Object_var anObj;
376 localSelection( anObj, TopAbs_EDGE );
379 myEditCurrentArgument->setFocus();
380 SelectionIntoArgument();
384 //=================================================================================
385 // function : LineEditReturnPressed()
387 //=================================================================================
388 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
390 QLineEdit* send = (QLineEdit*)sender();
391 if ( send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2 ) {
392 myEditCurrentArgument = send;
393 GEOMBase_Skeleton::LineEditReturnPressed();
398 //=================================================================================
399 // function : onReverse()
401 //=================================================================================
402 void BasicGUI_WorkingPlaneDlg::onReverse()
408 //=================================================================================
409 // function : ActivateThisDialog()
411 //=================================================================================
412 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
414 GEOMBase_Skeleton::ActivateThisDialog();
415 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ) )->selectionMgr(),
416 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
418 ConstructorsClicked( getConstructorId() );
422 //=================================================================================
423 // function : DeactivateActiveDialog()
424 // purpose : public slot to deactivate if active
425 //=================================================================================
426 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
428 // myGeomGUI->SetState( -1 );
429 GEOMBase_Skeleton::DeactivateActiveDialog();
432 //=================================================================================
433 // function : enterEvent()
435 //=================================================================================
436 void BasicGUI_WorkingPlaneDlg::enterEvent( QEvent* )
438 if ( !mainFrame()->GroupConstructors->isEnabled() )
439 ActivateThisDialog();
442 //=================================================================================
443 // function : updateWPlane
445 //=================================================================================
446 bool BasicGUI_WorkingPlaneDlg::updateWPlane( const bool showPreview )
450 const int id = getConstructorId();
452 if ( id == 0 ) { // by planar face selection
453 if ( CORBA::is_nil( myFace ) ) {
455 showError( "Face has to be selected" );
459 // PAL12781: set center of WPL to face's center of mass
460 // like it is done for LCS creation
461 CORBA::Double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
462 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
465 GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
466 myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
467 aMeasureOp->GetPosition( myFace, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
469 if ( aMeasureOp->IsDone() ) {
470 gp_Pnt aPnt ( Ox, Oy, Oz );
471 gp_Dir aDirN ( Zx, Zy, Zz );
472 gp_Dir aDirX ( Xx, Xy, Xz );
473 myWPlane = gp_Ax3( aPnt, aDirN, aDirX );
477 showError( "Wrong shape selected (has to be a planar face)" );
481 else if ( id == 1 ) { // by two vectors (Ox & Oz)
482 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
484 showError( "Two vectors have to be selected" );
488 TopoDS_Edge aVectX, aVectZ;
489 TopoDS_Vertex VX1, VX2, VZ1, VZ2;
492 if ( !GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
493 !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE ) ) {
495 showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
499 TopExp::Vertices( aVectX, VX1, VX2, Standard_True );
500 TopExp::Vertices( aVectZ, VZ1, VZ2, Standard_True );
502 if ( VX1.IsNull() || VX2.IsNull() ) {
504 showError( "Bad OX vector" );
507 if ( VZ1.IsNull() || VZ2.IsNull() ) {
509 showError( "Bad OZ vector" );
513 aVX = gp_Vec( BRep_Tool::Pnt( VX1 ), BRep_Tool::Pnt( VX2 ) );
514 aVZ = gp_Vec( BRep_Tool::Pnt( VZ1 ), BRep_Tool::Pnt( VZ2 ) );
516 if ( aVX.Magnitude() < Precision::Confusion() ) {
518 showError( "Bad OX vector" );
521 if ( aVZ.Magnitude() < Precision::Confusion() ) {
523 showError( "Bad OZ vector" );
527 gp_Dir aDirX = gp_Dir( aVX.X(), aVX.Y(), aVX.Z() );
528 gp_Dir aDirZ = gp_Dir( aVZ.X(), aVZ.Y(), aVZ.Z() );
530 if ( aDirX.IsParallel( aDirZ, Precision::Angular() ) ) {
532 showError( "Parallel vectors selected" );
536 myWPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX );
539 else if ( id == 2 ) { // by selection from standard (OXY or OYZ, or OZX)
542 if ( aOriginType == 1 ) anAx2 = gp::XOY();
543 else if ( aOriginType == 2 ) anAx2 = gp::YOZ();
544 else if ( aOriginType == 0 ) anAx2 = gp::ZOX();
546 myWPlane = gp_Ax3( anAx2 );
553 if ( myReverseCB->isChecked() ) {
559 GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations( getStudyId() );
560 GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker
561 ( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
562 myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
563 myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
564 displayPreview( anObj );