2 // File : GeometryGUI_BndBoxDlg.cxx
3 // Created : Mon Mar 04 13:16:16 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 #include "GeometryGUI_BndBoxDlg.h"
14 #include "GeometryGUI.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
19 #include <BRepPrimAPI_MakeBox.hxx>
20 #include <BRepBndLib.hxx>
22 #include <qbuttongroup.h>
23 #include <qgroupbox.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
31 #include <qwhatsthis.h>
35 //=================================================================================
36 // class : GeometryGUI_BndBoxDlg()
37 // purpose : Constructs a GeometryGUI_BndBoxDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 GeometryGUI_BndBoxDlg::GeometryGUI_BndBoxDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
43 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BOUNDING_BOX")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
49 setName( "GeometryGUI_BndBoxDlg" );
51 setCaption( tr( "GEOM_BNDBOX_TITLE" ) );
52 setSizeGripEnabled( TRUE );
53 GeometryGUI_BndBoxDlgLayout = new QGridLayout( this );
54 GeometryGUI_BndBoxDlgLayout->setSpacing( 6 );
55 GeometryGUI_BndBoxDlgLayout->setMargin( 11 );
57 /***************************************************************/
58 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
59 GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
60 GroupConstructors->setExclusive( TRUE );
61 GroupConstructors->setColumnLayout(0, Qt::Vertical );
62 GroupConstructors->layout()->setSpacing( 0 );
63 GroupConstructors->layout()->setMargin( 0 );
64 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
65 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
66 GroupConstructorsLayout->setSpacing( 6 );
67 GroupConstructorsLayout->setMargin( 11 );
68 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
69 Constructor1->setText( tr( "" ) );
70 Constructor1->setPixmap( image0 );
71 Constructor1->setChecked( TRUE );
72 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
73 Constructor1->sizePolicy().hasHeightForWidth() ) );
74 Constructor1->setMinimumSize( QSize( 60, 0 ) );
75 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
76 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
77 GroupConstructorsLayout->addItem( spacer, 0, 1 );
78 GeometryGUI_BndBoxDlgLayout->addWidget( GroupConstructors, 0, 0 );
80 /***************************************************************/
81 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
82 GroupConstructor1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
83 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
84 GroupConstructor1->layout()->setSpacing( 0 );
85 GroupConstructor1->layout()->setMargin( 0 );
86 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
87 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
88 GroupConstructor1Layout->setSpacing( 6 );
89 GroupConstructor1Layout->setMargin( 11 );
90 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
91 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
92 // GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
93 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
94 SelectButtonC1A1->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
95 SelectButtonC1A1->setText( tr( "" ) );
96 SelectButtonC1A1->setPixmap( image1 );
97 // GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
99 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
100 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
101 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
102 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
103 TextLabelC1A1->setFrameShadow( QLabel::Plain );
104 // GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
106 QHBoxLayout* bl = new QHBoxLayout;
107 bl->setMargin(0); bl->setSpacing(6);
108 bl->addWidget(TextLabelC1A1); bl->addWidget(SelectButtonC1A1); bl->addWidget(LineEditC1A1);
109 GroupConstructor1Layout->addMultiCellLayout(bl, 0, 0, 0, 2);
111 TextLabel_Min = new QLabel( GroupConstructor1, "TextLabel_Min" );
112 TextLabel_Min->setText( tr( "GEOM_MIN" ) );
113 TextLabel_Min->setMinimumSize( QSize( 50, 0 ) );
114 TextLabel_Min->setFrameShape( QLabel::NoFrame );
115 TextLabel_Min->setFrameShadow( QLabel::Plain );
116 GroupConstructor1Layout->addWidget( TextLabel_Min, 1, 1 );
118 TextLabel_Max = new QLabel( GroupConstructor1, "TextLabel_Max" );
119 TextLabel_Max->setText( tr( "GEOM_MAX" ) );
120 TextLabel_Max->setMinimumSize( QSize( 50, 0 ) );
121 TextLabel_Max->setFrameShape( QLabel::NoFrame );
122 TextLabel_Max->setFrameShadow( QLabel::Plain );
123 GroupConstructor1Layout->addWidget( TextLabel_Max, 1, 2 );
125 TextLabel_X = new QLabel( GroupConstructor1, "TextLabel_X" );
126 TextLabel_X->setText( tr( "GEOM_X" ) );
127 TextLabel_X->setMinimumSize( QSize( 50, 0 ) );
128 TextLabel_X->setFrameShape( QLabel::NoFrame );
129 TextLabel_X->setFrameShadow( QLabel::Plain );
130 GroupConstructor1Layout->addWidget( TextLabel_X, 2, 0 );
131 LineEdit_MinX = new QLineEdit( GroupConstructor1, "LineEdit_MinX" );
132 LineEdit_MinX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
133 LineEdit_MinX->sizePolicy().hasHeightForWidth() ) );
134 //LineEdit_MinX->setEnabled( FALSE );
135 LineEdit_MinX->setReadOnly( TRUE );
136 GroupConstructor1Layout->addWidget( LineEdit_MinX, 2, 1 );
137 LineEdit_MaxX = new QLineEdit( GroupConstructor1, "LineEdit_MaxX" );
138 LineEdit_MaxX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
139 LineEdit_MaxX->sizePolicy().hasHeightForWidth() ) );
140 //LineEdit_MaxX->setEnabled( FALSE );
141 LineEdit_MaxX->setReadOnly( TRUE );
142 GroupConstructor1Layout->addWidget( LineEdit_MaxX, 2, 2 );
144 TextLabel_Y = new QLabel( GroupConstructor1, "TextLabel_Y" );
145 TextLabel_Y->setText( tr( "GEOM_Y" ) );
146 TextLabel_Y->setMinimumSize( QSize( 50, 0 ) );
147 TextLabel_Y->setFrameShape( QLabel::NoFrame );
148 TextLabel_Y->setFrameShadow( QLabel::Plain );
149 GroupConstructor1Layout->addWidget( TextLabel_Y, 3, 0 );
150 LineEdit_MinY = new QLineEdit( GroupConstructor1, "LineEdit_MinY" );
151 LineEdit_MinY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
152 LineEdit_MinY->sizePolicy().hasHeightForWidth() ) );
153 //LineEdit_MinY->setEnabled( FALSE );
154 LineEdit_MinY->setReadOnly( TRUE );
155 GroupConstructor1Layout->addWidget( LineEdit_MinY, 3, 1 );
156 LineEdit_MaxY = new QLineEdit( GroupConstructor1, "LineEdit_MaxY" );
157 LineEdit_MaxY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
158 LineEdit_MaxY->sizePolicy().hasHeightForWidth() ) );
159 //LineEdit_MaxY->setEnabled( FALSE );
160 LineEdit_MaxY->setReadOnly( TRUE );
161 GroupConstructor1Layout->addWidget( LineEdit_MaxY, 3, 2 );
163 TextLabel_Z = new QLabel( GroupConstructor1, "TextLabel_Z" );
164 TextLabel_Z->setText( tr( "GEOM_Z" ) );
165 TextLabel_Z->setMinimumSize( QSize( 50, 0 ) );
166 TextLabel_Z->setFrameShape( QLabel::NoFrame );
167 TextLabel_Z->setFrameShadow( QLabel::Plain );
168 GroupConstructor1Layout->addWidget( TextLabel_Z, 4, 0 );
169 LineEdit_MinZ = new QLineEdit( GroupConstructor1, "LineEdit_MinZ" );
170 LineEdit_MinZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
171 LineEdit_MinZ->sizePolicy().hasHeightForWidth() ) );
172 //LineEdit_MinZ->setEnabled( FALSE );
173 LineEdit_MinZ->setReadOnly( TRUE );
174 GroupConstructor1Layout->addWidget( LineEdit_MinZ, 4, 1 );
175 LineEdit_MaxZ = new QLineEdit( GroupConstructor1, "LineEdit_MaxZ" );
176 LineEdit_MaxZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
177 LineEdit_MaxZ->sizePolicy().hasHeightForWidth() ) );
178 //LineEdit_MaxZ->setEnabled( FALSE );
179 LineEdit_MaxZ->setReadOnly( TRUE );
180 GroupConstructor1Layout->addWidget( LineEdit_MaxZ, 4, 2 );
182 GeometryGUI_BndBoxDlgLayout->addWidget( GroupConstructor1, 1, 0 );
184 /***************************************************************/
185 GroupButtons = new QGroupBox( this, "GroupButtons" );
186 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
187 GroupButtons->setTitle( tr( "" ) );
188 GroupButtons->setColumnLayout(0, Qt::Vertical );
189 GroupButtons->layout()->setSpacing( 0 );
190 GroupButtons->layout()->setMargin( 0 );
191 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
192 GroupButtonsLayout->setAlignment( Qt::AlignTop );
193 GroupButtonsLayout->setSpacing( 6 );
194 GroupButtonsLayout->setMargin( 11 );
195 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
196 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
197 buttonCancel->setAutoDefault( TRUE );
198 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
200 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
201 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
202 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
203 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
205 GeometryGUI_BndBoxDlgLayout->addWidget( GroupButtons, 2, 0 );
206 /***************************************************************/
208 Init(Sel) ; /* Initialisations */
212 //=================================================================================
213 // function : ~GeometryGUI_BndBoxDlg()
214 // purpose : Destroys the object and frees any allocated resources
215 //=================================================================================
216 GeometryGUI_BndBoxDlg::~GeometryGUI_BndBoxDlg()
218 // no need to delete child widgets, Qt does it all for us
222 //=================================================================================
225 //=================================================================================
226 void GeometryGUI_BndBoxDlg::Init( SALOME_Selection* Sel )
228 myConstructorId = 0 ;
229 Constructor1->setChecked( TRUE );
230 myEditCurrentArgument = LineEditC1A1 ;
232 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
233 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
235 // TODO : previous selection into argument ?
237 /* Filter definitions */
238 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
239 myGeom = GEOM::GEOM_Gen::_narrow(comp);
241 /* signals and slots connections */
242 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
243 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
244 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
245 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
247 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
248 /* to close dialog if study change */
249 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
251 mySimulationTopoDs.Nullify() ;
253 /* Move widget on the botton right corner of main widget */
255 myGeomGUI->DefineDlgPosition( this, x, y ) ;
257 this->show() ; /* displays Dialog */
263 //=================================================================================
264 // function : ConstructorsClicked()
265 // purpose : Radio button management
266 //=================================================================================
267 void GeometryGUI_BndBoxDlg::ConstructorsClicked(int constructorId)
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void GeometryGUI_BndBoxDlg::ClickOnCancel()
280 myGeomGUI->EraseSimulationShape() ;
281 mySimulationTopoDs.Nullify() ;
282 disconnect( mySelection, 0, this, 0 );
283 myGeomGUI->ResetState() ;
289 //=================================================================================
290 // function : SelectionIntoArgument()
291 // purpose : Called when selection as changed or other case
292 //=================================================================================
293 void GeometryGUI_BndBoxDlg::SelectionIntoArgument()
295 LineEdit_MinX->setText("") ;
296 LineEdit_MinY->setText("") ;
297 LineEdit_MinZ->setText("") ;
298 LineEdit_MaxX->setText("") ;
299 LineEdit_MaxY->setText("") ;
300 LineEdit_MaxZ->setText("") ;
301 myEditCurrentArgument->setText("") ;
302 mySimulationTopoDs.Nullify() ;
304 QString aString = ""; /* future the name of selection */
306 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
313 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
317 myEditCurrentArgument->setText( "" );
321 LineEditC1A1->setText(aString) ;
322 this->CalculateAndDisplayBndBox(S) ;
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void GeometryGUI_BndBoxDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
335 switch (myConstructorId)
337 case 0: /* default constructor */
339 if(send == SelectButtonC1A1) {
340 LineEditC1A1->setFocus() ;
341 myEditCurrentArgument = LineEditC1A1;
343 SelectionIntoArgument() ;
352 //=================================================================================
353 // function : LineEditReturnPressed()
355 //=================================================================================
356 void GeometryGUI_BndBoxDlg::LineEditReturnPressed()
358 QLineEdit* send = (QLineEdit*)sender();
359 if( send == LineEditC1A1 )
360 myEditCurrentArgument = LineEditC1A1 ;
364 /* User name of object input management */
365 /* If successfull the selection is changed and signal emitted... */
366 /* so SelectionIntoArgument() is automatically called. */
367 const QString objectUserName = myEditCurrentArgument->text() ;
368 QWidget* thisWidget = (QWidget*)this ;
369 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
370 myEditCurrentArgument->setText( objectUserName ) ;
377 //=================================================================================
378 // function : DeactivateActiveDialog()
380 //=================================================================================
381 void GeometryGUI_BndBoxDlg::DeactivateActiveDialog()
383 if ( GroupConstructors->isEnabled() ) {
384 disconnect( mySelection, 0, this, 0 );
385 GroupConstructors->setEnabled(false) ;
386 GroupConstructor1->setEnabled(false) ;
387 GroupButtons->setEnabled(false) ;
393 //=================================================================================
394 // function : ActivateThisDialog()
396 //=================================================================================
397 void GeometryGUI_BndBoxDlg::ActivateThisDialog()
399 /* Emit a signal to deactivate the active dialog */
400 myGeomGUI->EmitSignalDeactivateDialog() ;
401 GroupConstructors->setEnabled(true) ;
402 GroupConstructor1->setEnabled(true) ;
403 GroupButtons->setEnabled(true) ;
404 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
409 //=================================================================================
410 // function : enterEvent()
412 //=================================================================================
413 void GeometryGUI_BndBoxDlg::enterEvent(QEvent* e)
415 if ( GroupConstructors->isEnabled() )
417 ActivateThisDialog() ;
422 //=================================================================================
423 // function : closeEvent()
425 //=================================================================================
426 void GeometryGUI_BndBoxDlg::closeEvent( QCloseEvent* e )
428 /* same than click on cancel button */
429 this->ClickOnCancel() ;
434 //=================================================================================
435 // function : CalculateAndDisplayBndBox()
437 //=================================================================================
438 void GeometryGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
440 LineEdit_MinX->setText("") ;
441 LineEdit_MinY->setText("") ;
442 LineEdit_MinZ->setText("") ;
443 LineEdit_MaxX->setText("") ;
444 LineEdit_MaxY->setText("") ;
445 LineEdit_MaxZ->setText("") ;
449 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
452 BRepBndLib::Add(S,B);
453 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
454 LineEdit_MinX->setText( tr("%1").arg( axmin, 12, 'f', 6 ) ) ;
455 LineEdit_MinY->setText( tr("%1").arg( aymin, 12, 'f', 6 ) ) ;
456 LineEdit_MinZ->setText( tr("%1").arg( azmin, 12, 'f', 6 ) ) ;
457 LineEdit_MaxX->setText( tr("%1").arg( axmax, 12, 'f', 6 ) ) ;
458 LineEdit_MaxY->setText( tr("%1").arg( aymax, 12, 'f', 6 ) ) ;
459 LineEdit_MaxZ->setText( tr("%1").arg( azmax, 12, 'f', 6 ) ) ;
461 mySimulationTopoDs = BRepPrimAPI_MakeBox( gp_Pnt(axmin,aymin,azmin),
462 gp_Pnt(axmax,aymax,azmax) ).Shape();
463 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
465 catch(Standard_Failure) {
466 MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()" << endl ) ;