2 // File : GeometryGUI_MirrorDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_MirrorDlg.h"
12 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 #include <Geom_Plane.hxx>
19 #include <BRep_Tool.hxx>
21 #include <qbuttongroup.h>
22 #include <qgroupbox.h>
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
30 #include <qwhatsthis.h>
37 //=================================================================================
38 // class : GeometryGUI_MirrorDlg()
39 // purpose : Constructs a GeometryGUI_MirrorDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 GeometryGUI_MirrorDlg::GeometryGUI_MirrorDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
45 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MIRROR")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
52 setName( "GeometryGUI_MirrorDlg" );
54 setCaption( tr( "GEOM_MIRROR_TITLE" ) );
55 setSizeGripEnabled( TRUE );
56 GeometryGUI_MirrorDlgLayout = new QGridLayout( this );
57 GeometryGUI_MirrorDlgLayout->setSpacing( 6 );
58 GeometryGUI_MirrorDlgLayout->setMargin( 11 );
60 /***************************************************************/
61 GroupButtons = new QGroupBox( this, "GroupButtons" );
62 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
63 GroupButtons->setTitle( tr( "" ) );
64 GroupButtons->setColumnLayout(0, Qt::Vertical );
65 GroupButtons->layout()->setSpacing( 0 );
66 GroupButtons->layout()->setMargin( 0 );
67 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
68 GroupButtonsLayout->setAlignment( Qt::AlignTop );
69 GroupButtonsLayout->setSpacing( 6 );
70 GroupButtonsLayout->setMargin( 11 );
71 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
72 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
73 buttonCancel->setAutoDefault( TRUE );
74 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
75 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
76 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
77 buttonApply->setAutoDefault( TRUE );
78 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
79 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
80 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
81 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
82 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
83 buttonOk->setAutoDefault( TRUE );
84 buttonOk->setDefault( TRUE );
85 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
87 GeometryGUI_MirrorDlgLayout->addWidget( GroupButtons, 2, 0 );
89 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
90 GroupConstructors->setTitle( tr( "GEOM_MIRROR" ) );
91 GroupConstructors->setExclusive( TRUE );
92 GroupConstructors->setColumnLayout(0, Qt::Vertical );
93 GroupConstructors->layout()->setSpacing( 0 );
94 GroupConstructors->layout()->setMargin( 0 );
95 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
96 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
97 GroupConstructorsLayout->setSpacing( 6 );
98 GroupConstructorsLayout->setMargin( 11 );
99 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
101 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
102 Constructor1->setText( tr( "" ) );
103 Constructor1->setPixmap( image0 );
104 Constructor1->setChecked( TRUE );
105 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
106 Constructor1->setMinimumSize( QSize( 50, 0 ) );
107 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
108 GeometryGUI_MirrorDlgLayout->addWidget( GroupConstructors, 0, 0 );
110 /***************************************************************/
111 GroupC1 = new QGroupBox( this, "GroupC1" );
112 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
113 GroupC1->setColumnLayout(0, Qt::Vertical );
114 GroupC1->layout()->setSpacing( 0 );
115 GroupC1->layout()->setMargin( 0 );
116 GroupC1Layout = new QGridLayout( GroupC1->layout() );
117 GroupC1Layout->setAlignment( Qt::AlignTop );
118 GroupC1Layout->setSpacing( 6 );
119 GroupC1Layout->setMargin( 11 );
120 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
121 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
122 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
123 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
124 TextLabelC1A1->setFrameShadow( QLabel::Plain );
125 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
126 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
127 TextLabelC1A2->setText( tr( "GEOM_PLANE_MIRROR" ) );
128 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
129 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
130 TextLabelC1A2->setFrameShadow( QLabel::Plain );
131 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
132 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
133 SelectButtonC1A1->setText( tr( "" ) );
134 SelectButtonC1A1->setPixmap( image1 );
135 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
136 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
137 SelectButtonC1A2->setText( tr( "" ) );
138 SelectButtonC1A2->setPixmap( image1 );
139 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
140 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
141 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
142 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
143 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
144 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
145 GeometryGUI_MirrorDlgLayout->addWidget( GroupC1, 1, 0 );
152 //=================================================================================
153 // function : ~GeometryGUI_MirrorDlg()
154 // purpose : Destroys the object and frees any allocated resources
155 //=================================================================================
156 GeometryGUI_MirrorDlg::~GeometryGUI_MirrorDlg()
158 /* no need to delete child widgets, Qt does it all for us */
163 //=================================================================================
166 //=================================================================================
167 void GeometryGUI_MirrorDlg::Init( SALOME_Selection* Sel )
172 mySimulationTopoDs.Nullify() ;
173 myConstructorId = 0 ;
175 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
178 myEditCurrentArgument = LineEditC1A1 ;
179 Constructor1->setChecked( TRUE );
180 myOkShape1 = myOkShape2 = false ;
182 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
184 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
185 myGeom = GEOM::GEOM_Gen::_narrow(comp);
186 /* Filter definition */
188 myFaceFilter = new GEOM_FaceFilter( StdSelect_Plane, myGeom );
190 // TODO previous selection into argument ?
192 /* signals and slots connections */
193 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
194 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
195 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
196 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
197 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
198 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
200 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
201 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
203 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
204 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
205 /* to close dialog if study change */
206 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
208 /* Move widget on the botton right corner of main widget */
210 myGeomGUI->DefineDlgPosition( this, x, y ) ;
212 this->show() ; /* Displays Dialog */
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose : Radio button management
222 //=================================================================================
223 void GeometryGUI_MirrorDlg::ConstructorsClicked(int constructorId)
225 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
227 switch (constructorId)
232 myConstructorId = constructorId ;
233 myEditCurrentArgument = LineEditC1A1 ;
234 LineEditC1A2->setText(tr("")) ;
235 Constructor1->setChecked( TRUE );
236 myOkShape1 = myOkShape2 = false ;
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void GeometryGUI_MirrorDlg::ClickOnOk()
249 this->ClickOnApply() ;
250 this->ClickOnCancel() ;
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 void GeometryGUI_MirrorDlg::ClickOnApply()
261 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
262 switch(myConstructorId)
266 if(myOkShape1 && myOkShape2) {
267 myGeomGUI->MakeMirrorAndDisplay(myGeomShape1 ,myGeomShape2 ) ;
277 //=================================================================================
278 // function : ClickOnCancel()
280 //=================================================================================
281 void GeometryGUI_MirrorDlg::ClickOnCancel()
283 mySelection->ClearFilters() ;
284 myGeomGUI->EraseSimulationShape() ;
285 mySimulationTopoDs.Nullify() ;
286 disconnect( mySelection, 0, this, 0 );
287 myGeomGUI->ResetState() ;
294 //=================================================================================
295 // function : SelectionIntoArgument()
296 // purpose : Called when selection has changed
297 //=================================================================================
298 void GeometryGUI_MirrorDlg::SelectionIntoArgument()
300 myEditCurrentArgument->setText("") ;
301 myGeomGUI->EraseSimulationShape() ;
302 mySimulationTopoDs.Nullify() ;
304 QString aString = ""; /* name of selection */
306 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
308 switch (myConstructorId)
312 if ( myEditCurrentArgument == LineEditC1A1 ) {
315 else if ( myEditCurrentArgument == LineEditC1A2 ) {
326 Standard_Boolean testResult ;
327 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
328 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
331 if ( myEditCurrentArgument == LineEditC1A1 ) {
332 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
336 LineEditC1A1->setText(aString) ;
339 else if ( myEditCurrentArgument == LineEditC1A2 ) {
340 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
344 LineEditC1A2->setText(aString) ;
348 if(myOkShape1 && myOkShape2) {
349 MakeMirrorSimulationAndDisplay( myShape1, myShape2 ) ;
357 //=================================================================================
358 // function : MakeMirrorSimulationAndDisplay()
359 // purpose : S1 is a shape and S2 a mirror.
360 //=================================================================================
361 void GeometryGUI_MirrorDlg::MakeMirrorSimulationAndDisplay( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
363 this->mySimulationTopoDs.Nullify() ;
366 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(S2)) ;
367 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf) ;
368 const gp_Ax3 pos = myPlane->Position() ;
369 const gp_Pnt loc = pos.Location() ; /* location of the plane */
370 const gp_Dir dir = pos.Direction() ; /* Main direction of the plane (Z axis) */
372 /* plane used for mirroring */
373 gp_Ax2 pln(loc, dir) ;
374 gp_Trsf theTransformation ;
375 theTransformation.SetMirror(pln) ;
376 BRepBuilderAPI_Transform myBRepTransformation( S1, theTransformation, Standard_False ) ;
378 this->mySimulationTopoDs = myBRepTransformation.Shape() ;
379 if( this->mySimulationTopoDs.IsNull() )
382 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
384 catch(Standard_Failure) {
385 MESSAGE( "Exception catched in MakeMirrorSimulationAndDisplay" ) ;
393 //=================================================================================
394 // function : SetEditCurrentArgument()
396 //=================================================================================
397 void GeometryGUI_MirrorDlg::SetEditCurrentArgument()
399 QPushButton* send = (QPushButton*)sender();
401 switch (myConstructorId)
405 if( send == SelectButtonC1A1 ) {
406 LineEditC1A1->setFocus() ;
407 myEditCurrentArgument = LineEditC1A1 ;
408 mySelection->ClearFilters() ;
409 SelectionIntoArgument() ;
411 else if(send == SelectButtonC1A2) {
412 LineEditC1A2->setFocus() ;
413 myEditCurrentArgument = LineEditC1A2;
414 mySelection->AddFilter(myFaceFilter) ;
415 SelectionIntoArgument() ;
425 //=================================================================================
426 // function : LineEditReturnPressed()
428 //=================================================================================
429 void GeometryGUI_MirrorDlg::LineEditReturnPressed()
431 QLineEdit* send = (QLineEdit*)sender();
432 if( send == LineEditC1A1 )
433 myEditCurrentArgument = LineEditC1A1 ;
434 else if ( send == LineEditC1A2 )
435 myEditCurrentArgument = LineEditC1A2 ;
439 /* User name of object input management */
440 /* If successfull the selection is changed and signal emitted... */
441 /* so SelectionIntoArgument() is automatically called. */
442 const QString objectUserName = myEditCurrentArgument->text() ;
443 QWidget* thisWidget = (QWidget*)this ;
444 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
445 myEditCurrentArgument->setText( objectUserName ) ;
452 //=================================================================================
453 // function : DeactivateActiveDialog()
455 //=================================================================================
456 void GeometryGUI_MirrorDlg::DeactivateActiveDialog()
458 if ( GroupConstructors->isEnabled() ) {
459 GroupConstructors->setEnabled(false) ;
460 GroupC1->setEnabled(false) ;
461 GroupButtons->setEnabled(false) ;
462 disconnect( mySelection, 0, this, 0 );
469 //=================================================================================
470 // function : closeEvent()
472 //=================================================================================
473 void GeometryGUI_MirrorDlg::closeEvent( QCloseEvent* e )
475 this->ClickOnCancel() ; /* same than click on cancel button */
479 //=================================================================================
480 // function : enterEvent()
481 // purpose : when mouse enter onto the QWidget
482 //=================================================================================
483 void GeometryGUI_MirrorDlg::enterEvent( QEvent * )
485 if ( GroupConstructors->isEnabled() )
487 ActivateThisDialog() ;
492 //=================================================================================
493 // function : ActivateThisDialog()
495 //=================================================================================
496 void GeometryGUI_MirrorDlg::ActivateThisDialog()
498 /* Emit a signal to deactivate any active dialog */
499 myGeomGUI->EmitSignalDeactivateDialog() ;
500 GroupConstructors->setEnabled(true) ;
501 GroupC1->setEnabled(true) ;
502 GroupButtons->setEnabled(true) ;
503 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );