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_BndBoxDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "GeometryGUI_BndBoxDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <BRepPrimAPI_MakeBox.hxx>
38 #include <BRepBndLib.hxx>
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_BndBoxDlg()
55 // purpose : Constructs a GeometryGUI_BndBoxDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_BndBoxDlg::GeometryGUI_BndBoxDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BOUNDING_BOX")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
67 setName( "GeometryGUI_BndBoxDlg" );
69 setCaption( tr( "GEOM_BNDBOX_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 GeometryGUI_BndBoxDlgLayout = new QGridLayout( this );
72 GeometryGUI_BndBoxDlgLayout->setSpacing( 6 );
73 GeometryGUI_BndBoxDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
78 GroupConstructors->setExclusive( TRUE );
79 GroupConstructors->setColumnLayout(0, Qt::Vertical );
80 GroupConstructors->layout()->setSpacing( 0 );
81 GroupConstructors->layout()->setMargin( 0 );
82 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84 GroupConstructorsLayout->setSpacing( 6 );
85 GroupConstructorsLayout->setMargin( 11 );
86 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
87 Constructor1->setText( tr( "" ) );
88 Constructor1->setPixmap( image0 );
89 Constructor1->setChecked( TRUE );
90 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
91 Constructor1->sizePolicy().hasHeightForWidth() ) );
92 Constructor1->setMinimumSize( QSize( 60, 0 ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupConstructorsLayout->addItem( spacer, 0, 1 );
96 GeometryGUI_BndBoxDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
100 GroupConstructor1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
101 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
102 GroupConstructor1->layout()->setSpacing( 0 );
103 GroupConstructor1->layout()->setMargin( 0 );
104 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
105 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
106 GroupConstructor1Layout->setSpacing( 6 );
107 GroupConstructor1Layout->setMargin( 11 );
108 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
109 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
110 // GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
111 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
112 SelectButtonC1A1->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
113 SelectButtonC1A1->setText( tr( "" ) );
114 SelectButtonC1A1->setPixmap( image1 );
115 // GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
117 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
118 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
119 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121 TextLabelC1A1->setFrameShadow( QLabel::Plain );
122 // GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
124 QHBoxLayout* bl = new QHBoxLayout;
125 bl->setMargin(0); bl->setSpacing(6);
126 bl->addWidget(TextLabelC1A1); bl->addWidget(SelectButtonC1A1); bl->addWidget(LineEditC1A1);
127 GroupConstructor1Layout->addMultiCellLayout(bl, 0, 0, 0, 2);
129 TextLabel_Min = new QLabel( GroupConstructor1, "TextLabel_Min" );
130 TextLabel_Min->setText( tr( "GEOM_MIN" ) );
131 TextLabel_Min->setMinimumSize( QSize( 50, 0 ) );
132 TextLabel_Min->setFrameShape( QLabel::NoFrame );
133 TextLabel_Min->setFrameShadow( QLabel::Plain );
134 GroupConstructor1Layout->addWidget( TextLabel_Min, 1, 1 );
136 TextLabel_Max = new QLabel( GroupConstructor1, "TextLabel_Max" );
137 TextLabel_Max->setText( tr( "GEOM_MAX" ) );
138 TextLabel_Max->setMinimumSize( QSize( 50, 0 ) );
139 TextLabel_Max->setFrameShape( QLabel::NoFrame );
140 TextLabel_Max->setFrameShadow( QLabel::Plain );
141 GroupConstructor1Layout->addWidget( TextLabel_Max, 1, 2 );
143 TextLabel_X = new QLabel( GroupConstructor1, "TextLabel_X" );
144 TextLabel_X->setText( tr( "GEOM_X" ) );
145 TextLabel_X->setMinimumSize( QSize( 50, 0 ) );
146 TextLabel_X->setFrameShape( QLabel::NoFrame );
147 TextLabel_X->setFrameShadow( QLabel::Plain );
148 GroupConstructor1Layout->addWidget( TextLabel_X, 2, 0 );
149 LineEdit_MinX = new QLineEdit( GroupConstructor1, "LineEdit_MinX" );
150 LineEdit_MinX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
151 LineEdit_MinX->sizePolicy().hasHeightForWidth() ) );
152 //LineEdit_MinX->setEnabled( FALSE );
153 LineEdit_MinX->setReadOnly( TRUE );
154 GroupConstructor1Layout->addWidget( LineEdit_MinX, 2, 1 );
155 LineEdit_MaxX = new QLineEdit( GroupConstructor1, "LineEdit_MaxX" );
156 LineEdit_MaxX->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
157 LineEdit_MaxX->sizePolicy().hasHeightForWidth() ) );
158 //LineEdit_MaxX->setEnabled( FALSE );
159 LineEdit_MaxX->setReadOnly( TRUE );
160 GroupConstructor1Layout->addWidget( LineEdit_MaxX, 2, 2 );
162 TextLabel_Y = new QLabel( GroupConstructor1, "TextLabel_Y" );
163 TextLabel_Y->setText( tr( "GEOM_Y" ) );
164 TextLabel_Y->setMinimumSize( QSize( 50, 0 ) );
165 TextLabel_Y->setFrameShape( QLabel::NoFrame );
166 TextLabel_Y->setFrameShadow( QLabel::Plain );
167 GroupConstructor1Layout->addWidget( TextLabel_Y, 3, 0 );
168 LineEdit_MinY = new QLineEdit( GroupConstructor1, "LineEdit_MinY" );
169 LineEdit_MinY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
170 LineEdit_MinY->sizePolicy().hasHeightForWidth() ) );
171 //LineEdit_MinY->setEnabled( FALSE );
172 LineEdit_MinY->setReadOnly( TRUE );
173 GroupConstructor1Layout->addWidget( LineEdit_MinY, 3, 1 );
174 LineEdit_MaxY = new QLineEdit( GroupConstructor1, "LineEdit_MaxY" );
175 LineEdit_MaxY->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
176 LineEdit_MaxY->sizePolicy().hasHeightForWidth() ) );
177 //LineEdit_MaxY->setEnabled( FALSE );
178 LineEdit_MaxY->setReadOnly( TRUE );
179 GroupConstructor1Layout->addWidget( LineEdit_MaxY, 3, 2 );
181 TextLabel_Z = new QLabel( GroupConstructor1, "TextLabel_Z" );
182 TextLabel_Z->setText( tr( "GEOM_Z" ) );
183 TextLabel_Z->setMinimumSize( QSize( 50, 0 ) );
184 TextLabel_Z->setFrameShape( QLabel::NoFrame );
185 TextLabel_Z->setFrameShadow( QLabel::Plain );
186 GroupConstructor1Layout->addWidget( TextLabel_Z, 4, 0 );
187 LineEdit_MinZ = new QLineEdit( GroupConstructor1, "LineEdit_MinZ" );
188 LineEdit_MinZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
189 LineEdit_MinZ->sizePolicy().hasHeightForWidth() ) );
190 //LineEdit_MinZ->setEnabled( FALSE );
191 LineEdit_MinZ->setReadOnly( TRUE );
192 GroupConstructor1Layout->addWidget( LineEdit_MinZ, 4, 1 );
193 LineEdit_MaxZ = new QLineEdit( GroupConstructor1, "LineEdit_MaxZ" );
194 LineEdit_MaxZ->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
195 LineEdit_MaxZ->sizePolicy().hasHeightForWidth() ) );
196 //LineEdit_MaxZ->setEnabled( FALSE );
197 LineEdit_MaxZ->setReadOnly( TRUE );
198 GroupConstructor1Layout->addWidget( LineEdit_MaxZ, 4, 2 );
200 GeometryGUI_BndBoxDlgLayout->addWidget( GroupConstructor1, 1, 0 );
202 /***************************************************************/
203 GroupButtons = new QGroupBox( this, "GroupButtons" );
204 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
205 GroupButtons->setTitle( tr( "" ) );
206 GroupButtons->setColumnLayout(0, Qt::Vertical );
207 GroupButtons->layout()->setSpacing( 0 );
208 GroupButtons->layout()->setMargin( 0 );
209 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
210 GroupButtonsLayout->setAlignment( Qt::AlignTop );
211 GroupButtonsLayout->setSpacing( 6 );
212 GroupButtonsLayout->setMargin( 11 );
213 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
214 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
215 buttonCancel->setAutoDefault( TRUE );
216 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
218 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
219 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
220 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
221 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
223 GeometryGUI_BndBoxDlgLayout->addWidget( GroupButtons, 2, 0 );
224 /***************************************************************/
226 Init(Sel) ; /* Initialisations */
230 //=================================================================================
231 // function : ~GeometryGUI_BndBoxDlg()
232 // purpose : Destroys the object and frees any allocated resources
233 //=================================================================================
234 GeometryGUI_BndBoxDlg::~GeometryGUI_BndBoxDlg()
236 // no need to delete child widgets, Qt does it all for us
240 //=================================================================================
243 //=================================================================================
244 void GeometryGUI_BndBoxDlg::Init( SALOME_Selection* Sel )
246 myConstructorId = 0 ;
247 Constructor1->setChecked( TRUE );
248 myEditCurrentArgument = LineEditC1A1 ;
250 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
251 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
253 // TODO : previous selection into argument ?
255 /* Filter definitions */
256 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
257 myGeom = GEOM::GEOM_Gen::_narrow(comp);
259 /* signals and slots connections */
260 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
261 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
262 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
263 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
265 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
266 /* to close dialog if study change */
267 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
269 mySimulationTopoDs.Nullify() ;
271 /* Move widget on the botton right corner of main widget */
273 myGeomGUI->DefineDlgPosition( this, x, y ) ;
275 this->show() ; /* displays Dialog */
281 //=================================================================================
282 // function : ConstructorsClicked()
283 // purpose : Radio button management
284 //=================================================================================
285 void GeometryGUI_BndBoxDlg::ConstructorsClicked(int constructorId)
292 //=================================================================================
293 // function : ClickOnCancel()
295 //=================================================================================
296 void GeometryGUI_BndBoxDlg::ClickOnCancel()
298 myGeomGUI->EraseSimulationShape() ;
299 mySimulationTopoDs.Nullify() ;
300 disconnect( mySelection, 0, this, 0 );
301 myGeomGUI->ResetState() ;
307 //=================================================================================
308 // function : SelectionIntoArgument()
309 // purpose : Called when selection as changed or other case
310 //=================================================================================
311 void GeometryGUI_BndBoxDlg::SelectionIntoArgument()
313 LineEdit_MinX->setText("") ;
314 LineEdit_MinY->setText("") ;
315 LineEdit_MinZ->setText("") ;
316 LineEdit_MaxX->setText("") ;
317 LineEdit_MaxY->setText("") ;
318 LineEdit_MaxZ->setText("") ;
319 myEditCurrentArgument->setText("") ;
320 mySimulationTopoDs.Nullify() ;
322 QString aString = ""; /* future the name of selection */
324 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
331 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
335 myEditCurrentArgument->setText( "" );
339 LineEditC1A1->setText(aString) ;
340 this->CalculateAndDisplayBndBox(S) ;
346 //=================================================================================
347 // function : SetEditCurrentArgument()
349 //=================================================================================
350 void GeometryGUI_BndBoxDlg::SetEditCurrentArgument()
352 QPushButton* send = (QPushButton*)sender();
353 switch (myConstructorId)
355 case 0: /* default constructor */
357 if(send == SelectButtonC1A1) {
358 LineEditC1A1->setFocus() ;
359 myEditCurrentArgument = LineEditC1A1;
361 SelectionIntoArgument() ;
370 //=================================================================================
371 // function : LineEditReturnPressed()
373 //=================================================================================
374 void GeometryGUI_BndBoxDlg::LineEditReturnPressed()
376 QLineEdit* send = (QLineEdit*)sender();
377 if( send == LineEditC1A1 )
378 myEditCurrentArgument = LineEditC1A1 ;
382 /* User name of object input management */
383 /* If successfull the selection is changed and signal emitted... */
384 /* so SelectionIntoArgument() is automatically called. */
385 const QString objectUserName = myEditCurrentArgument->text() ;
386 QWidget* thisWidget = (QWidget*)this ;
387 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
388 myEditCurrentArgument->setText( objectUserName ) ;
395 //=================================================================================
396 // function : DeactivateActiveDialog()
398 //=================================================================================
399 void GeometryGUI_BndBoxDlg::DeactivateActiveDialog()
401 if ( GroupConstructors->isEnabled() ) {
402 disconnect( mySelection, 0, this, 0 );
403 GroupConstructors->setEnabled(false) ;
404 GroupConstructor1->setEnabled(false) ;
405 GroupButtons->setEnabled(false) ;
411 //=================================================================================
412 // function : ActivateThisDialog()
414 //=================================================================================
415 void GeometryGUI_BndBoxDlg::ActivateThisDialog()
417 /* Emit a signal to deactivate the active dialog */
418 myGeomGUI->EmitSignalDeactivateDialog() ;
419 GroupConstructors->setEnabled(true) ;
420 GroupConstructor1->setEnabled(true) ;
421 GroupButtons->setEnabled(true) ;
422 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
427 //=================================================================================
428 // function : enterEvent()
430 //=================================================================================
431 void GeometryGUI_BndBoxDlg::enterEvent(QEvent* e)
433 if ( GroupConstructors->isEnabled() )
435 ActivateThisDialog() ;
440 //=================================================================================
441 // function : closeEvent()
443 //=================================================================================
444 void GeometryGUI_BndBoxDlg::closeEvent( QCloseEvent* e )
446 /* same than click on cancel button */
447 this->ClickOnCancel() ;
452 //=================================================================================
453 // function : CalculateAndDisplayBndBox()
455 //=================================================================================
456 void GeometryGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
458 LineEdit_MinX->setText("") ;
459 LineEdit_MinY->setText("") ;
460 LineEdit_MinZ->setText("") ;
461 LineEdit_MaxX->setText("") ;
462 LineEdit_MaxY->setText("") ;
463 LineEdit_MaxZ->setText("") ;
467 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
470 BRepBndLib::Add(S,B);
471 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
472 LineEdit_MinX->setText( tr("%1").arg( axmin, 12, 'f', 6 ) ) ;
473 LineEdit_MinY->setText( tr("%1").arg( aymin, 12, 'f', 6 ) ) ;
474 LineEdit_MinZ->setText( tr("%1").arg( azmin, 12, 'f', 6 ) ) ;
475 LineEdit_MaxX->setText( tr("%1").arg( axmax, 12, 'f', 6 ) ) ;
476 LineEdit_MaxY->setText( tr("%1").arg( aymax, 12, 'f', 6 ) ) ;
477 LineEdit_MaxZ->setText( tr("%1").arg( azmax, 12, 'f', 6 ) ) ;
479 mySimulationTopoDs = BRepPrimAPI_MakeBox( gp_Pnt(axmin,aymin,azmin),
480 gp_Pnt(axmax,aymax,azmax) ).Shape();
481 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
483 catch(Standard_Failure) {
484 MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()" << endl ) ;