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 : GeometryGUI_MirrorDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_MirrorDlg.h"
32 #include "GeometryGUI.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
38 #include <Geom_Plane.hxx>
39 #include <BRep_Tool.hxx>
41 #include <qbuttongroup.h>
42 #include <qgroupbox.h>
44 #include <qlineedit.h>
45 #include <qpushbutton.h>
46 #include <qradiobutton.h>
50 #include <qwhatsthis.h>
57 //=================================================================================
58 // class : GeometryGUI_MirrorDlg()
59 // purpose : Constructs a GeometryGUI_MirrorDlg which is a child of 'parent', with the
60 // name 'name' and widget flags set to 'f'.
61 // The dialog will by default be modeless, unless you set 'modal' to
62 // TRUE to construct a modal dialog.
63 //=================================================================================
64 GeometryGUI_MirrorDlg::GeometryGUI_MirrorDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
65 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
68 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MIRROR")));
69 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
72 setName( "GeometryGUI_MirrorDlg" );
74 setCaption( tr( "GEOM_MIRROR_TITLE" ) );
75 setSizeGripEnabled( TRUE );
76 GeometryGUI_MirrorDlgLayout = new QGridLayout( this );
77 GeometryGUI_MirrorDlgLayout->setSpacing( 6 );
78 GeometryGUI_MirrorDlgLayout->setMargin( 11 );
80 /***************************************************************/
81 GroupButtons = new QGroupBox( this, "GroupButtons" );
82 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
83 GroupButtons->setTitle( tr( "" ) );
84 GroupButtons->setColumnLayout(0, Qt::Vertical );
85 GroupButtons->layout()->setSpacing( 0 );
86 GroupButtons->layout()->setMargin( 0 );
87 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
88 GroupButtonsLayout->setAlignment( Qt::AlignTop );
89 GroupButtonsLayout->setSpacing( 6 );
90 GroupButtonsLayout->setMargin( 11 );
91 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
92 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
93 buttonCancel->setAutoDefault( TRUE );
94 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
95 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
96 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
97 buttonApply->setAutoDefault( TRUE );
98 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
99 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
101 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
102 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
103 buttonOk->setAutoDefault( TRUE );
104 buttonOk->setDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
107 GeometryGUI_MirrorDlgLayout->addWidget( GroupButtons, 2, 0 );
109 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
110 GroupConstructors->setTitle( tr( "GEOM_MIRROR" ) );
111 GroupConstructors->setExclusive( TRUE );
112 GroupConstructors->setColumnLayout(0, Qt::Vertical );
113 GroupConstructors->layout()->setSpacing( 0 );
114 GroupConstructors->layout()->setMargin( 0 );
115 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
116 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
117 GroupConstructorsLayout->setSpacing( 6 );
118 GroupConstructorsLayout->setMargin( 11 );
119 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120 GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
121 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
122 Constructor1->setText( tr( "" ) );
123 Constructor1->setPixmap( image0 );
124 Constructor1->setChecked( TRUE );
125 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
126 Constructor1->setMinimumSize( QSize( 50, 0 ) );
127 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
128 GeometryGUI_MirrorDlgLayout->addWidget( GroupConstructors, 0, 0 );
130 /***************************************************************/
131 GroupC1 = new QGroupBox( this, "GroupC1" );
132 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
133 GroupC1->setColumnLayout(0, Qt::Vertical );
134 GroupC1->layout()->setSpacing( 0 );
135 GroupC1->layout()->setMargin( 0 );
136 GroupC1Layout = new QGridLayout( GroupC1->layout() );
137 GroupC1Layout->setAlignment( Qt::AlignTop );
138 GroupC1Layout->setSpacing( 6 );
139 GroupC1Layout->setMargin( 11 );
140 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
141 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
142 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
143 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
144 TextLabelC1A1->setFrameShadow( QLabel::Plain );
145 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
146 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
147 TextLabelC1A2->setText( tr( "GEOM_PLANE_MIRROR" ) );
148 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
149 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
150 TextLabelC1A2->setFrameShadow( QLabel::Plain );
151 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
152 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
153 SelectButtonC1A1->setText( tr( "" ) );
154 SelectButtonC1A1->setPixmap( image1 );
155 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
156 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
157 SelectButtonC1A2->setText( tr( "" ) );
158 SelectButtonC1A2->setPixmap( image1 );
159 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
160 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
161 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
162 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
163 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
164 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
165 GeometryGUI_MirrorDlgLayout->addWidget( GroupC1, 1, 0 );
172 //=================================================================================
173 // function : ~GeometryGUI_MirrorDlg()
174 // purpose : Destroys the object and frees any allocated resources
175 //=================================================================================
176 GeometryGUI_MirrorDlg::~GeometryGUI_MirrorDlg()
178 /* no need to delete child widgets, Qt does it all for us */
183 //=================================================================================
186 //=================================================================================
187 void GeometryGUI_MirrorDlg::Init( SALOME_Selection* Sel )
192 mySimulationTopoDs.Nullify() ;
193 myConstructorId = 0 ;
195 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
198 myEditCurrentArgument = LineEditC1A1 ;
199 Constructor1->setChecked( TRUE );
200 myOkShape1 = myOkShape2 = false ;
202 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
204 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
205 myGeom = GEOM::GEOM_Gen::_narrow(comp);
206 /* Filter definition */
208 myFaceFilter = new GEOM_FaceFilter( StdSelect_Plane, myGeom );
210 // TODO previous selection into argument ?
212 /* signals and slots connections */
213 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
214 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
215 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
216 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
217 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
218 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
220 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
221 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
223 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
224 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
225 /* to close dialog if study change */
226 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
228 /* Move widget on the botton right corner of main widget */
230 myGeomGUI->DefineDlgPosition( this, x, y ) ;
232 this->show() ; /* Displays Dialog */
239 //=================================================================================
240 // function : ConstructorsClicked()
241 // purpose : Radio button management
242 //=================================================================================
243 void GeometryGUI_MirrorDlg::ConstructorsClicked(int constructorId)
245 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
247 switch (constructorId)
252 myConstructorId = constructorId ;
253 myEditCurrentArgument = LineEditC1A1 ;
254 LineEditC1A2->setText(tr("")) ;
255 Constructor1->setChecked( TRUE );
256 myOkShape1 = myOkShape2 = false ;
263 //=================================================================================
264 // function : ClickOnOk()
266 //=================================================================================
267 void GeometryGUI_MirrorDlg::ClickOnOk()
269 this->ClickOnApply() ;
270 this->ClickOnCancel() ;
275 //=================================================================================
276 // function : ClickOnApply()
278 //=================================================================================
279 void GeometryGUI_MirrorDlg::ClickOnApply()
281 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
282 switch(myConstructorId)
286 if(myOkShape1 && myOkShape2) {
287 myGeomGUI->MakeMirrorAndDisplay(myGeomShape1 ,myGeomShape2 ) ;
297 //=================================================================================
298 // function : ClickOnCancel()
300 //=================================================================================
301 void GeometryGUI_MirrorDlg::ClickOnCancel()
303 mySelection->ClearFilters() ;
304 myGeomGUI->EraseSimulationShape() ;
305 mySimulationTopoDs.Nullify() ;
306 disconnect( mySelection, 0, this, 0 );
307 myGeomGUI->ResetState() ;
314 //=================================================================================
315 // function : SelectionIntoArgument()
316 // purpose : Called when selection has changed
317 //=================================================================================
318 void GeometryGUI_MirrorDlg::SelectionIntoArgument()
320 myEditCurrentArgument->setText("") ;
321 myGeomGUI->EraseSimulationShape() ;
322 mySimulationTopoDs.Nullify() ;
324 QString aString = ""; /* name of selection */
326 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
328 switch (myConstructorId)
332 if ( myEditCurrentArgument == LineEditC1A1 ) {
335 else if ( myEditCurrentArgument == LineEditC1A2 ) {
346 Standard_Boolean testResult ;
347 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
348 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
351 if ( myEditCurrentArgument == LineEditC1A1 ) {
352 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
356 LineEditC1A1->setText(aString) ;
359 else if ( myEditCurrentArgument == LineEditC1A2 ) {
360 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
364 LineEditC1A2->setText(aString) ;
368 if(myOkShape1 && myOkShape2) {
369 MakeMirrorSimulationAndDisplay( myShape1, myShape2 ) ;
377 //=================================================================================
378 // function : MakeMirrorSimulationAndDisplay()
379 // purpose : S1 is a shape and S2 a mirror.
380 //=================================================================================
381 void GeometryGUI_MirrorDlg::MakeMirrorSimulationAndDisplay( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
383 this->mySimulationTopoDs.Nullify() ;
386 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(S2)) ;
387 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf) ;
388 const gp_Ax3 pos = myPlane->Position() ;
389 const gp_Pnt loc = pos.Location() ; /* location of the plane */
390 const gp_Dir dir = pos.Direction() ; /* Main direction of the plane (Z axis) */
392 /* plane used for mirroring */
393 gp_Ax2 pln(loc, dir) ;
394 gp_Trsf theTransformation ;
395 theTransformation.SetMirror(pln) ;
396 BRepBuilderAPI_Transform myBRepTransformation( S1, theTransformation, Standard_False ) ;
398 this->mySimulationTopoDs = myBRepTransformation.Shape() ;
399 if( this->mySimulationTopoDs.IsNull() )
402 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
404 catch(Standard_Failure) {
405 MESSAGE( "Exception catched in MakeMirrorSimulationAndDisplay" ) ;
413 //=================================================================================
414 // function : SetEditCurrentArgument()
416 //=================================================================================
417 void GeometryGUI_MirrorDlg::SetEditCurrentArgument()
419 QPushButton* send = (QPushButton*)sender();
421 switch (myConstructorId)
425 if( send == SelectButtonC1A1 ) {
426 LineEditC1A1->setFocus() ;
427 myEditCurrentArgument = LineEditC1A1 ;
428 mySelection->ClearFilters() ;
429 SelectionIntoArgument() ;
431 else if(send == SelectButtonC1A2) {
432 LineEditC1A2->setFocus() ;
433 myEditCurrentArgument = LineEditC1A2;
434 mySelection->AddFilter(myFaceFilter) ;
435 SelectionIntoArgument() ;
445 //=================================================================================
446 // function : LineEditReturnPressed()
448 //=================================================================================
449 void GeometryGUI_MirrorDlg::LineEditReturnPressed()
451 QLineEdit* send = (QLineEdit*)sender();
452 if( send == LineEditC1A1 )
453 myEditCurrentArgument = LineEditC1A1 ;
454 else if ( send == LineEditC1A2 )
455 myEditCurrentArgument = LineEditC1A2 ;
459 /* User name of object input management */
460 /* If successfull the selection is changed and signal emitted... */
461 /* so SelectionIntoArgument() is automatically called. */
462 const QString objectUserName = myEditCurrentArgument->text() ;
463 QWidget* thisWidget = (QWidget*)this ;
464 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
465 myEditCurrentArgument->setText( objectUserName ) ;
472 //=================================================================================
473 // function : DeactivateActiveDialog()
475 //=================================================================================
476 void GeometryGUI_MirrorDlg::DeactivateActiveDialog()
478 if ( GroupConstructors->isEnabled() ) {
479 GroupConstructors->setEnabled(false) ;
480 GroupC1->setEnabled(false) ;
481 GroupButtons->setEnabled(false) ;
482 disconnect( mySelection, 0, this, 0 );
489 //=================================================================================
490 // function : closeEvent()
492 //=================================================================================
493 void GeometryGUI_MirrorDlg::closeEvent( QCloseEvent* e )
495 this->ClickOnCancel() ; /* same than click on cancel button */
499 //=================================================================================
500 // function : enterEvent()
501 // purpose : when mouse enter onto the QWidget
502 //=================================================================================
503 void GeometryGUI_MirrorDlg::enterEvent( QEvent * )
505 if ( GroupConstructors->isEnabled() )
507 ActivateThisDialog() ;
512 //=================================================================================
513 // function : ActivateThisDialog()
515 //=================================================================================
516 void GeometryGUI_MirrorDlg::ActivateThisDialog()
518 /* Emit a signal to deactivate any active dialog */
519 myGeomGUI->EmitSignalDeactivateDialog() ;
520 GroupConstructors->setEnabled(true) ;
521 GroupC1->setEnabled(true) ;
522 GroupButtons->setEnabled(true) ;
523 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );