2 // File : GeometryGUI_MaxToleranceDlg.cxx
3 // Created : Mon Mar 04 14:08:28 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "GeometryGUI_MaxToleranceDlg.h"
13 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 // Open CASCADE Includes
19 #include <TopExp_Explorer.hxx>
20 #include <BRep_Tool.hxx>
23 #include <qbuttongroup.h>
24 #include <qgroupbox.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28 #include <qradiobutton.h>
32 #include <qwhatsthis.h>
38 //=================================================================================
39 // class : GeometryGUI_MaxToleranceDlg()
40 // purpose : Constructs a GeometryGUI_MaxToleranceDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 GeometryGUI_MaxToleranceDlg::GeometryGUI_MaxToleranceDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
46 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_TOLERANCE")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
52 setName( "GeometryGUI_MaxToleranceDlg" );
54 setCaption( tr( "GEOM_TOLERANCE_TITLE" ) );
55 setSizeGripEnabled( TRUE );
56 GeometryGUI_MaxToleranceDlgLayout = new QGridLayout( this );
57 GeometryGUI_MaxToleranceDlgLayout->setSpacing( 6 );
58 GeometryGUI_MaxToleranceDlgLayout->setMargin( 11 );
60 /***************************************************************/
61 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
62 GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
63 GroupConstructors->setExclusive( TRUE );
64 GroupConstructors->setColumnLayout(0, Qt::Vertical );
65 GroupConstructors->layout()->setSpacing( 0 );
66 GroupConstructors->layout()->setMargin( 0 );
67 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
68 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
69 GroupConstructorsLayout->setSpacing( 6 );
70 GroupConstructorsLayout->setMargin( 11 );
71 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
72 Constructor1->setText( tr( "" ) );
73 Constructor1->setPixmap( image0 );
74 Constructor1->setChecked( TRUE );
75 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
76 Constructor1->sizePolicy().hasHeightForWidth() ) );
77 Constructor1->setMinimumSize( QSize( 60, 0 ) );
78 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
79 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
80 GroupConstructorsLayout->addItem( spacer, 0, 1 );
81 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupConstructors, 0, 0 );
83 /***************************************************************/
84 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
85 GroupConstructor1->setTitle( tr( "GEOM_TOLERANCE_CONSTR" ) );
86 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
87 GroupConstructor1->layout()->setSpacing( 0 );
88 GroupConstructor1->layout()->setMargin( 0 );
89 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
90 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
91 GroupConstructor1Layout->setSpacing( 6 );
92 GroupConstructor1Layout->setMargin( 11 );
94 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
95 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
96 // GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
97 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
98 SelectButtonC1A1->setText( tr( "" ) );
99 SelectButtonC1A1->setPixmap( image1 );
100 // GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
101 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
102 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
103 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
104 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
105 TextLabelC1A1->setFrameShadow( QLabel::Plain );
106 // GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
108 QHBoxLayout* bl = new QHBoxLayout;
109 bl->setMargin(0); bl->setSpacing(6);
110 bl->addWidget(TextLabelC1A1); bl->addWidget(SelectButtonC1A1); bl->addWidget(LineEditC1A1);
111 GroupConstructor1Layout->addMultiCellLayout(bl, 0, 0, 0, 2);
113 TextLabel_Min = new QLabel( GroupConstructor1, "TextLabel_Min" );
114 TextLabel_Min->setText( tr( "GEOM_MIN" ) );
115 TextLabel_Min->setMinimumSize( QSize( 50, 0 ) );
116 TextLabel_Min->setFrameShape( QLabel::NoFrame );
117 TextLabel_Min->setFrameShadow( QLabel::Plain );
118 GroupConstructor1Layout->addWidget( TextLabel_Min, 1, 1 );
120 TextLabel_Max = new QLabel( GroupConstructor1, "TextLabel_Max" );
121 TextLabel_Max->setText( tr( "GEOM_MAX" ) );
122 TextLabel_Max->setMinimumSize( QSize( 50, 0 ) );
123 TextLabel_Max->setFrameShape( QLabel::NoFrame );
124 TextLabel_Max->setFrameShadow( QLabel::Plain );
125 GroupConstructor1Layout->addWidget( TextLabel_Max, 1, 2 );
127 TextLabel_Face = new QLabel( GroupConstructor1, "TextLabel_Face" );
128 TextLabel_Face->setText( tr( "GEOM_TOLERANCE_FACE" ) );
129 TextLabel_Face->setMinimumSize( QSize( 50, 0 ) );
130 TextLabel_Face->setFrameShape( QLabel::NoFrame );
131 TextLabel_Face->setFrameShadow( QLabel::Plain );
132 GroupConstructor1Layout->addWidget( TextLabel_Face, 2, 0 );
133 LineEdit_MinFace = new QLineEdit( GroupConstructor1, "LineEdit_MinFace" );
134 LineEdit_MinFace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
135 LineEdit_MinFace->sizePolicy().hasHeightForWidth() ) );
136 //LineEdit_MinFace->setEnabled( FALSE );
137 LineEdit_MinFace->setReadOnly( TRUE );
138 GroupConstructor1Layout->addWidget( LineEdit_MinFace, 2, 1 );
139 LineEdit_MaxFace = new QLineEdit( GroupConstructor1, "LineEdit_MaxFace" );
140 LineEdit_MaxFace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
141 LineEdit_MaxFace->sizePolicy().hasHeightForWidth() ) );
142 //LineEdit_MaxFace->setEnabled( FALSE );
143 LineEdit_MaxFace->setReadOnly( TRUE );
144 GroupConstructor1Layout->addWidget( LineEdit_MaxFace, 2, 2 );
146 TextLabel_Edge = new QLabel( GroupConstructor1, "TextLabel_Edge" );
147 TextLabel_Edge->setText( tr( "GEOM_TOLERANCE_EDGE" ) );
148 TextLabel_Edge->setMinimumSize( QSize( 50, 0 ) );
149 TextLabel_Edge->setFrameShape( QLabel::NoFrame );
150 TextLabel_Edge->setFrameShadow( QLabel::Plain );
151 GroupConstructor1Layout->addWidget( TextLabel_Edge, 3, 0 );
152 LineEdit_MinEdge = new QLineEdit( GroupConstructor1, "LineEdit_MinEdge" );
153 LineEdit_MinEdge->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
154 LineEdit_MinEdge->sizePolicy().hasHeightForWidth() ) );
155 //LineEdit_MinEdge->setEnabled( FALSE );
156 LineEdit_MinEdge->setReadOnly( TRUE );
157 GroupConstructor1Layout->addWidget( LineEdit_MinEdge, 3, 1 );
158 LineEdit_MaxEdge = new QLineEdit( GroupConstructor1, "LineEdit_MaxEdge" );
159 LineEdit_MaxEdge->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
160 LineEdit_MaxEdge->sizePolicy().hasHeightForWidth() ) );
161 //LineEdit_MaxEdge->setEnabled( FALSE );
162 LineEdit_MaxEdge->setReadOnly( TRUE );
163 GroupConstructor1Layout->addWidget( LineEdit_MaxEdge, 3, 2 );
165 TextLabel_Vertex = new QLabel( GroupConstructor1, "TextLabel_Vertex" );
166 TextLabel_Vertex->setText( tr( "GEOM_TOLERANCE_VERTEX" ) );
167 TextLabel_Vertex->setMinimumSize( QSize( 50, 0 ) );
168 TextLabel_Vertex->setFrameShape( QLabel::NoFrame );
169 TextLabel_Vertex->setFrameShadow( QLabel::Plain );
170 GroupConstructor1Layout->addWidget( TextLabel_Vertex, 4, 0 );
171 LineEdit_MinVertex = new QLineEdit( GroupConstructor1, "LineEdit_MinVertex" );
172 LineEdit_MinVertex->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
173 LineEdit_MinVertex->sizePolicy().hasHeightForWidth() ) );
174 //LineEdit_MinVertex->setEnabled( FALSE );
175 LineEdit_MinVertex->setReadOnly( TRUE );
176 GroupConstructor1Layout->addWidget( LineEdit_MinVertex, 4, 1 );
177 LineEdit_MaxVertex = new QLineEdit( GroupConstructor1, "LineEdit_MaxVertex" );
178 LineEdit_MaxVertex->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
179 LineEdit_MaxVertex->sizePolicy().hasHeightForWidth() ) );
180 //LineEdit_MaxVertex->setEnabled( FALSE );
181 LineEdit_MaxVertex->setReadOnly( TRUE );
182 GroupConstructor1Layout->addWidget( LineEdit_MaxVertex, 4, 2 );
184 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupConstructor1, 1, 0 );
186 /***************************************************************/
187 GroupButtons = new QGroupBox( this, "GroupButtons" );
188 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
189 GroupButtons->setTitle( tr( "" ) );
190 GroupButtons->setColumnLayout(0, Qt::Vertical );
191 GroupButtons->layout()->setSpacing( 0 );
192 GroupButtons->layout()->setMargin( 0 );
193 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
194 GroupButtonsLayout->setAlignment( Qt::AlignTop );
195 GroupButtonsLayout->setSpacing( 6 );
196 GroupButtonsLayout->setMargin( 11 );
197 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
198 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
199 buttonCancel->setAutoDefault( TRUE );
200 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
201 // buttonApply = new QPushButton( GroupButtons, "buttonApply" );
202 // buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
203 // buttonApply->setAutoDefault( TRUE );
204 // GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
205 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
206 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
207 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
208 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
209 // buttonOk = new QPushButton( GroupButtons, "buttonOk" );
210 // buttonOk->setText( tr( "GEOM_BUT_OK" ) );
211 // buttonOk->setAutoDefault( TRUE );
212 // buttonOk->setDefault( TRUE );
213 // GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
214 GeometryGUI_MaxToleranceDlgLayout->addWidget( GroupButtons, 2, 0 );
215 /***************************************************************/
217 Init(Sel) ; /* Initialisations */
221 //=================================================================================
222 // function : ~GeometryGUI_MaxToleranceDlg()
223 // purpose : Destroys the object and frees any allocated resources
224 //=================================================================================
225 GeometryGUI_MaxToleranceDlg::~GeometryGUI_MaxToleranceDlg()
227 // no need to delete child widgets, Qt does it all for us
231 //=================================================================================
234 //=================================================================================
235 void GeometryGUI_MaxToleranceDlg::Init( SALOME_Selection* Sel )
237 myConstructorId = 0 ;
238 Constructor1->setChecked( TRUE );
239 myEditCurrentArgument = LineEditC1A1 ;
241 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
242 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
244 // TODO : previous selection into argument ?
246 /* Filter definitions */
247 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
248 myGeom = GEOM::GEOM_Gen::_narrow(comp);
250 /* signals and slots connections */
251 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
252 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
253 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
254 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
256 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
258 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
259 /* to close dialog if study change */
260 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
262 /* Move widget on the botton right corner of main widget */
264 myGeomGUI->DefineDlgPosition( this, x, y ) ;
266 this->show() ; /* displays Dialog */
271 //=================================================================================
272 // function : ConstructorsClicked()
273 // purpose : Radio button management
274 //=================================================================================
275 void GeometryGUI_MaxToleranceDlg::ConstructorsClicked(int constructorId)
282 //=================================================================================
283 // function : ClickOnCancel()
285 //=================================================================================
286 void GeometryGUI_MaxToleranceDlg::ClickOnCancel()
288 disconnect( mySelection, 0, this, 0 );
289 myGeomGUI->ResetState() ;
295 //=================================================================================
296 // function : SelectionIntoArgument()
297 // purpose : Called when selection as changed or other case
298 //=================================================================================
299 void GeometryGUI_MaxToleranceDlg::SelectionIntoArgument()
301 LineEdit_MinFace->setText("") ;
302 LineEdit_MinEdge->setText("") ;
303 LineEdit_MinVertex->setText("") ;
304 LineEdit_MaxFace->setText("") ;
305 LineEdit_MaxEdge->setText("") ;
306 LineEdit_MaxVertex->setText("") ;
307 myEditCurrentArgument->setText("") ;
309 QString aString = ""; /* future the name of selection */
311 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
318 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
322 myEditCurrentArgument->setText( "" );
326 LineEditC1A1->setText(aString) ;
327 this->CalculateMaxTolerance(S) ;
333 //=================================================================================
334 // function : SetEditCurrentArgument()
336 //=================================================================================
337 void GeometryGUI_MaxToleranceDlg::SetEditCurrentArgument()
339 QPushButton* send = (QPushButton*)sender();
340 switch (myConstructorId)
342 case 0: /* default constructor */
344 if(send == SelectButtonC1A1) {
345 LineEditC1A1->setFocus() ;
346 myEditCurrentArgument = LineEditC1A1;
348 SelectionIntoArgument() ;
357 //=================================================================================
358 // function : LineEditReturnPressed()
360 //=================================================================================
361 void GeometryGUI_MaxToleranceDlg::LineEditReturnPressed()
363 QLineEdit* send = (QLineEdit*)sender();
364 if( send == LineEditC1A1 )
365 myEditCurrentArgument = LineEditC1A1 ;
369 /* User name of object input management */
370 /* If successfull the selection is changed and signal emitted... */
371 /* so SelectionIntoArgument() is automatically called. */
372 const QString objectUserName = myEditCurrentArgument->text() ;
373 QWidget* thisWidget = (QWidget*)this ;
374 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
375 myEditCurrentArgument->setText( objectUserName ) ;
382 //=================================================================================
383 // function : DeactivateActiveDialog()
385 //=================================================================================
386 void GeometryGUI_MaxToleranceDlg::DeactivateActiveDialog()
388 if ( GroupConstructors->isEnabled() ) {
389 disconnect( mySelection, 0, this, 0 );
390 GroupConstructors->setEnabled(false) ;
391 GroupConstructor1->setEnabled(false) ;
392 GroupButtons->setEnabled(false) ;
398 //=================================================================================
399 // function : ActivateThisDialog()
401 //=================================================================================
402 void GeometryGUI_MaxToleranceDlg::ActivateThisDialog()
404 /* Emit a signal to deactivate the active dialog */
405 myGeomGUI->EmitSignalDeactivateDialog() ;
406 GroupConstructors->setEnabled(true) ;
407 GroupConstructor1->setEnabled(true) ;
408 GroupButtons->setEnabled(true) ;
409 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
414 //=================================================================================
415 // function : enterEvent()
417 //=================================================================================
418 void GeometryGUI_MaxToleranceDlg::enterEvent(QEvent* e)
420 if ( GroupConstructors->isEnabled() )
422 ActivateThisDialog() ;
427 //=================================================================================
428 // function : closeEvent()
430 //=================================================================================
431 void GeometryGUI_MaxToleranceDlg::closeEvent( QCloseEvent* e )
433 /* same than click on cancel button */
434 this->ClickOnCancel() ;
439 //=================================================================================
440 // function : CalculateMaxTolerance()
442 //=================================================================================
443 void GeometryGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
445 LineEdit_MinFace->setText("") ;
446 LineEdit_MinEdge->setText("") ;
447 LineEdit_MinVertex->setText("") ;
448 LineEdit_MaxFace->setText("") ;
449 LineEdit_MaxEdge->setText("") ;
450 LineEdit_MaxVertex->setText("") ;
454 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
455 Standard_Integer nbF,nbE,nbV;
456 TMF=TME=TMV=-RealLast();
457 TmF=TmE=TmV=RealLast();
460 bool m_isFace = false;
461 bool m_isEdge = false;
462 bool m_isVertex = false;
465 for( TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next() )
468 TopoDS_Face Face=TopoDS::Face(ExF.Current());
469 T=BRep_Tool::Tolerance(Face);
474 for( TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next() )
477 TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
478 T=BRep_Tool::Tolerance(Edge);
483 for( TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next() )
486 TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
487 T=BRep_Tool::Tolerance(Vertex);
494 LineEdit_MinFace->setText( tr("%1").arg( TmF, 5, 'e', 8 ) ) ;
495 LineEdit_MaxFace->setText( tr("%1").arg( TMF, 5, 'e', 8 ) ) ;
499 LineEdit_MinFace->setText( "" ) ;
500 LineEdit_MaxFace->setText( "" ) ;
504 LineEdit_MinEdge->setText( tr("%1").arg( TmE, 5, 'e', 8 ) ) ;
505 LineEdit_MaxEdge->setText( tr("%1").arg( TME, 5, 'e', 8 ) ) ;
509 LineEdit_MinEdge->setText( "" ) ;
510 LineEdit_MaxEdge->setText( "" ) ;
514 LineEdit_MinVertex->setText( tr("%1").arg( TmV, 5, 'e', 8 ) ) ;
515 LineEdit_MaxVertex->setText( tr("%1").arg( TMV, 5, 'e', 8 ) ) ;
519 LineEdit_MinVertex->setText( "" ) ;
520 LineEdit_MaxVertex->setText( "" ) ;
523 catch(Standard_Failure)
525 MESSAGE("Catch intercepted in CalculateMaxTolerance()" << endl ) ;