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_MaxToleranceDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "GeometryGUI_MaxToleranceDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 // Open CASCADE Includes
38 #include <TopExp_Explorer.hxx>
39 #include <BRep_Tool.hxx>
42 #include <qbuttongroup.h>
43 #include <qgroupbox.h>
45 #include <qlineedit.h>
46 #include <qpushbutton.h>
47 #include <qradiobutton.h>
51 #include <qwhatsthis.h>
57 //=================================================================================
58 // class : GeometryGUI_MaxToleranceDlg()
59 // purpose : Constructs a GeometryGUI_MaxToleranceDlg 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_MaxToleranceDlg::GeometryGUI_MaxToleranceDlg( 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 )
67 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_TOLERANCE")));
68 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
71 setName( "GeometryGUI_MaxToleranceDlg" );
73 setCaption( tr( "GEOM_TOLERANCE_TITLE" ) );
74 setSizeGripEnabled( TRUE );
75 GeometryGUI_MaxToleranceDlgLayout = new QGridLayout( this );
76 GeometryGUI_MaxToleranceDlgLayout->setSpacing( 6 );
77 GeometryGUI_MaxToleranceDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
81 GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
82 GroupConstructors->setExclusive( TRUE );
83 GroupConstructors->setColumnLayout(0, Qt::Vertical );
84 GroupConstructors->layout()->setSpacing( 0 );
85 GroupConstructors->layout()->setMargin( 0 );
86 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
87 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
88 GroupConstructorsLayout->setSpacing( 6 );
89 GroupConstructorsLayout->setMargin( 11 );
90 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
91 Constructor1->setText( tr( "" ) );
92 Constructor1->setPixmap( image0 );
93 Constructor1->setChecked( TRUE );
94 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
95 Constructor1->sizePolicy().hasHeightForWidth() ) );
96 Constructor1->setMinimumSize( QSize( 60, 0 ) );
97 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
98 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupConstructorsLayout->addItem( spacer, 0, 1 );
100 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupConstructors, 0, 0 );
102 /***************************************************************/
103 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
104 GroupConstructor1->setTitle( tr( "GEOM_TOLERANCE_CONSTR" ) );
105 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
106 GroupConstructor1->layout()->setSpacing( 0 );
107 GroupConstructor1->layout()->setMargin( 0 );
108 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
109 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
110 GroupConstructor1Layout->setSpacing( 6 );
111 GroupConstructor1Layout->setMargin( 11 );
113 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
114 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
115 // GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
116 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
117 SelectButtonC1A1->setText( tr( "" ) );
118 SelectButtonC1A1->setPixmap( image1 );
119 // GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
120 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
121 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
122 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
123 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
124 TextLabelC1A1->setFrameShadow( QLabel::Plain );
125 // GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
127 QHBoxLayout* bl = new QHBoxLayout;
128 bl->setMargin(0); bl->setSpacing(6);
129 bl->addWidget(TextLabelC1A1); bl->addWidget(SelectButtonC1A1); bl->addWidget(LineEditC1A1);
130 GroupConstructor1Layout->addMultiCellLayout(bl, 0, 0, 0, 2);
132 TextLabel_Min = new QLabel( GroupConstructor1, "TextLabel_Min" );
133 TextLabel_Min->setText( tr( "GEOM_MIN" ) );
134 TextLabel_Min->setMinimumSize( QSize( 50, 0 ) );
135 TextLabel_Min->setFrameShape( QLabel::NoFrame );
136 TextLabel_Min->setFrameShadow( QLabel::Plain );
137 GroupConstructor1Layout->addWidget( TextLabel_Min, 1, 1 );
139 TextLabel_Max = new QLabel( GroupConstructor1, "TextLabel_Max" );
140 TextLabel_Max->setText( tr( "GEOM_MAX" ) );
141 TextLabel_Max->setMinimumSize( QSize( 50, 0 ) );
142 TextLabel_Max->setFrameShape( QLabel::NoFrame );
143 TextLabel_Max->setFrameShadow( QLabel::Plain );
144 GroupConstructor1Layout->addWidget( TextLabel_Max, 1, 2 );
146 TextLabel_Face = new QLabel( GroupConstructor1, "TextLabel_Face" );
147 TextLabel_Face->setText( tr( "GEOM_TOLERANCE_FACE" ) );
148 TextLabel_Face->setMinimumSize( QSize( 50, 0 ) );
149 TextLabel_Face->setFrameShape( QLabel::NoFrame );
150 TextLabel_Face->setFrameShadow( QLabel::Plain );
151 GroupConstructor1Layout->addWidget( TextLabel_Face, 2, 0 );
152 LineEdit_MinFace = new QLineEdit( GroupConstructor1, "LineEdit_MinFace" );
153 LineEdit_MinFace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
154 LineEdit_MinFace->sizePolicy().hasHeightForWidth() ) );
155 //LineEdit_MinFace->setEnabled( FALSE );
156 LineEdit_MinFace->setReadOnly( TRUE );
157 GroupConstructor1Layout->addWidget( LineEdit_MinFace, 2, 1 );
158 LineEdit_MaxFace = new QLineEdit( GroupConstructor1, "LineEdit_MaxFace" );
159 LineEdit_MaxFace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
160 LineEdit_MaxFace->sizePolicy().hasHeightForWidth() ) );
161 //LineEdit_MaxFace->setEnabled( FALSE );
162 LineEdit_MaxFace->setReadOnly( TRUE );
163 GroupConstructor1Layout->addWidget( LineEdit_MaxFace, 2, 2 );
165 TextLabel_Edge = new QLabel( GroupConstructor1, "TextLabel_Edge" );
166 TextLabel_Edge->setText( tr( "GEOM_TOLERANCE_EDGE" ) );
167 TextLabel_Edge->setMinimumSize( QSize( 50, 0 ) );
168 TextLabel_Edge->setFrameShape( QLabel::NoFrame );
169 TextLabel_Edge->setFrameShadow( QLabel::Plain );
170 GroupConstructor1Layout->addWidget( TextLabel_Edge, 3, 0 );
171 LineEdit_MinEdge = new QLineEdit( GroupConstructor1, "LineEdit_MinEdge" );
172 LineEdit_MinEdge->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
173 LineEdit_MinEdge->sizePolicy().hasHeightForWidth() ) );
174 //LineEdit_MinEdge->setEnabled( FALSE );
175 LineEdit_MinEdge->setReadOnly( TRUE );
176 GroupConstructor1Layout->addWidget( LineEdit_MinEdge, 3, 1 );
177 LineEdit_MaxEdge = new QLineEdit( GroupConstructor1, "LineEdit_MaxEdge" );
178 LineEdit_MaxEdge->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
179 LineEdit_MaxEdge->sizePolicy().hasHeightForWidth() ) );
180 //LineEdit_MaxEdge->setEnabled( FALSE );
181 LineEdit_MaxEdge->setReadOnly( TRUE );
182 GroupConstructor1Layout->addWidget( LineEdit_MaxEdge, 3, 2 );
184 TextLabel_Vertex = new QLabel( GroupConstructor1, "TextLabel_Vertex" );
185 TextLabel_Vertex->setText( tr( "GEOM_TOLERANCE_VERTEX" ) );
186 TextLabel_Vertex->setMinimumSize( QSize( 50, 0 ) );
187 TextLabel_Vertex->setFrameShape( QLabel::NoFrame );
188 TextLabel_Vertex->setFrameShadow( QLabel::Plain );
189 GroupConstructor1Layout->addWidget( TextLabel_Vertex, 4, 0 );
190 LineEdit_MinVertex = new QLineEdit( GroupConstructor1, "LineEdit_MinVertex" );
191 LineEdit_MinVertex->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
192 LineEdit_MinVertex->sizePolicy().hasHeightForWidth() ) );
193 //LineEdit_MinVertex->setEnabled( FALSE );
194 LineEdit_MinVertex->setReadOnly( TRUE );
195 GroupConstructor1Layout->addWidget( LineEdit_MinVertex, 4, 1 );
196 LineEdit_MaxVertex = new QLineEdit( GroupConstructor1, "LineEdit_MaxVertex" );
197 LineEdit_MaxVertex->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
198 LineEdit_MaxVertex->sizePolicy().hasHeightForWidth() ) );
199 //LineEdit_MaxVertex->setEnabled( FALSE );
200 LineEdit_MaxVertex->setReadOnly( TRUE );
201 GroupConstructor1Layout->addWidget( LineEdit_MaxVertex, 4, 2 );
203 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupConstructor1, 1, 0 );
205 /***************************************************************/
206 GroupButtons = new QGroupBox( this, "GroupButtons" );
207 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
208 GroupButtons->setTitle( tr( "" ) );
209 GroupButtons->setColumnLayout(0, Qt::Vertical );
210 GroupButtons->layout()->setSpacing( 0 );
211 GroupButtons->layout()->setMargin( 0 );
212 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
213 GroupButtonsLayout->setAlignment( Qt::AlignTop );
214 GroupButtonsLayout->setSpacing( 6 );
215 GroupButtonsLayout->setMargin( 11 );
216 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
217 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
218 buttonCancel->setAutoDefault( TRUE );
219 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
220 // buttonApply = new QPushButton( GroupButtons, "buttonApply" );
221 // buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
222 // buttonApply->setAutoDefault( TRUE );
223 // GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
224 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
225 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
226 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
227 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
228 // buttonOk = new QPushButton( GroupButtons, "buttonOk" );
229 // buttonOk->setText( tr( "GEOM_BUT_OK" ) );
230 // buttonOk->setAutoDefault( TRUE );
231 // buttonOk->setDefault( TRUE );
232 // GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
233 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupButtons, 2, 0 );
234 /***************************************************************/
236 Init(Sel) ; /* Initialisations */
240 //=================================================================================
241 // function : ~GeometryGUI_MaxToleranceDlg()
242 // purpose : Destroys the object and frees any allocated resources
243 //=================================================================================
244 GeometryGUI_MaxToleranceDlg::~GeometryGUI_MaxToleranceDlg()
246 // no need to delete child widgets, Qt does it all for us
250 //=================================================================================
253 //=================================================================================
254 void GeometryGUI_MaxToleranceDlg::Init( SALOME_Selection* Sel )
256 myConstructorId = 0 ;
257 Constructor1->setChecked( TRUE );
258 myEditCurrentArgument = LineEditC1A1 ;
260 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
261 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
263 // TODO : previous selection into argument ?
265 /* Filter definitions */
266 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
267 myGeom = GEOM::GEOM_Gen::_narrow(comp);
269 /* signals and slots connections */
270 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
271 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
272 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
273 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
275 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
277 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
278 /* to close dialog if study change */
279 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
281 /* Move widget on the botton right corner of main widget */
283 myGeomGUI->DefineDlgPosition( this, x, y ) ;
285 this->show() ; /* displays Dialog */
290 //=================================================================================
291 // function : ConstructorsClicked()
292 // purpose : Radio button management
293 //=================================================================================
294 void GeometryGUI_MaxToleranceDlg::ConstructorsClicked(int constructorId)
301 //=================================================================================
302 // function : ClickOnCancel()
304 //=================================================================================
305 void GeometryGUI_MaxToleranceDlg::ClickOnCancel()
307 disconnect( mySelection, 0, this, 0 );
308 myGeomGUI->ResetState() ;
314 //=================================================================================
315 // function : SelectionIntoArgument()
316 // purpose : Called when selection as changed or other case
317 //=================================================================================
318 void GeometryGUI_MaxToleranceDlg::SelectionIntoArgument()
320 LineEdit_MinFace->setText("") ;
321 LineEdit_MinEdge->setText("") ;
322 LineEdit_MinVertex->setText("") ;
323 LineEdit_MaxFace->setText("") ;
324 LineEdit_MaxEdge->setText("") ;
325 LineEdit_MaxVertex->setText("") ;
326 myEditCurrentArgument->setText("") ;
328 QString aString = ""; /* future the name of selection */
330 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
337 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
341 myEditCurrentArgument->setText( "" );
345 LineEditC1A1->setText(aString) ;
346 this->CalculateMaxTolerance(S) ;
352 //=================================================================================
353 // function : SetEditCurrentArgument()
355 //=================================================================================
356 void GeometryGUI_MaxToleranceDlg::SetEditCurrentArgument()
358 QPushButton* send = (QPushButton*)sender();
359 switch (myConstructorId)
361 case 0: /* default constructor */
363 if(send == SelectButtonC1A1) {
364 LineEditC1A1->setFocus() ;
365 myEditCurrentArgument = LineEditC1A1;
367 SelectionIntoArgument() ;
376 //=================================================================================
377 // function : LineEditReturnPressed()
379 //=================================================================================
380 void GeometryGUI_MaxToleranceDlg::LineEditReturnPressed()
382 QLineEdit* send = (QLineEdit*)sender();
383 if( send == LineEditC1A1 )
384 myEditCurrentArgument = LineEditC1A1 ;
388 /* User name of object input management */
389 /* If successfull the selection is changed and signal emitted... */
390 /* so SelectionIntoArgument() is automatically called. */
391 const QString objectUserName = myEditCurrentArgument->text() ;
392 QWidget* thisWidget = (QWidget*)this ;
393 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
394 myEditCurrentArgument->setText( objectUserName ) ;
401 //=================================================================================
402 // function : DeactivateActiveDialog()
404 //=================================================================================
405 void GeometryGUI_MaxToleranceDlg::DeactivateActiveDialog()
407 if ( GroupConstructors->isEnabled() ) {
408 disconnect( mySelection, 0, this, 0 );
409 GroupConstructors->setEnabled(false) ;
410 GroupConstructor1->setEnabled(false) ;
411 GroupButtons->setEnabled(false) ;
417 //=================================================================================
418 // function : ActivateThisDialog()
420 //=================================================================================
421 void GeometryGUI_MaxToleranceDlg::ActivateThisDialog()
423 /* Emit a signal to deactivate the active dialog */
424 myGeomGUI->EmitSignalDeactivateDialog() ;
425 GroupConstructors->setEnabled(true) ;
426 GroupConstructor1->setEnabled(true) ;
427 GroupButtons->setEnabled(true) ;
428 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
433 //=================================================================================
434 // function : enterEvent()
436 //=================================================================================
437 void GeometryGUI_MaxToleranceDlg::enterEvent(QEvent* e)
439 if ( GroupConstructors->isEnabled() )
441 ActivateThisDialog() ;
446 //=================================================================================
447 // function : closeEvent()
449 //=================================================================================
450 void GeometryGUI_MaxToleranceDlg::closeEvent( QCloseEvent* e )
452 /* same than click on cancel button */
453 this->ClickOnCancel() ;
458 //=================================================================================
459 // function : CalculateMaxTolerance()
461 //=================================================================================
462 void GeometryGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
464 LineEdit_MinFace->setText("") ;
465 LineEdit_MinEdge->setText("") ;
466 LineEdit_MinVertex->setText("") ;
467 LineEdit_MaxFace->setText("") ;
468 LineEdit_MaxEdge->setText("") ;
469 LineEdit_MaxVertex->setText("") ;
473 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
474 Standard_Integer nbF,nbE,nbV;
475 TMF=TME=TMV=-RealLast();
476 TmF=TmE=TmV=RealLast();
479 bool m_isFace = false;
480 bool m_isEdge = false;
481 bool m_isVertex = false;
484 for( TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next() )
487 TopoDS_Face Face=TopoDS::Face(ExF.Current());
488 T=BRep_Tool::Tolerance(Face);
493 for( TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next() )
496 TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
497 T=BRep_Tool::Tolerance(Edge);
502 for( TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next() )
505 TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
506 T=BRep_Tool::Tolerance(Vertex);
513 LineEdit_MinFace->setText( tr("%1").arg( TmF, 5, 'e', 8 ) ) ;
514 LineEdit_MaxFace->setText( tr("%1").arg( TMF, 5, 'e', 8 ) ) ;
518 LineEdit_MinFace->setText( "" ) ;
519 LineEdit_MaxFace->setText( "" ) ;
523 LineEdit_MinEdge->setText( tr("%1").arg( TmE, 5, 'e', 8 ) ) ;
524 LineEdit_MaxEdge->setText( tr("%1").arg( TME, 5, 'e', 8 ) ) ;
528 LineEdit_MinEdge->setText( "" ) ;
529 LineEdit_MaxEdge->setText( "" ) ;
533 LineEdit_MinVertex->setText( tr("%1").arg( TmV, 5, 'e', 8 ) ) ;
534 LineEdit_MaxVertex->setText( tr("%1").arg( TMV, 5, 'e', 8 ) ) ;
538 LineEdit_MinVertex->setText( "" ) ;
539 LineEdit_MaxVertex->setText( "" ) ;
542 catch(Standard_Failure)
544 MESSAGE("Catch intercepted in CalculateMaxTolerance()" << endl ) ;