2 // File : GeometryGUI_CheckShape.cxx
3 // Created : Tue Mar 12 17:23:51 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 #include "GeometryGUI_CheckShape.h"
13 #include "GeometryGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
18 // Open Cascade Include
19 #include <BRepCheck_Analyzer.hxx>
22 #include <qtextview.h>
23 #include <qbuttongroup.h>
24 #include <qgroupbox.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28 #include <qradiobutton.h>
32 #include <qwhatsthis.h>
37 //=================================================================================
38 // class : GeometryGUI_CheckShape()
39 // purpose : Constructs a GeometryGUI_CheckShape 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_CheckShape::GeometryGUI_CheckShape( 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 )
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_CHECKSHAPE")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
51 setName( "DialogBox_CHECKSHAPE" );
53 setCaption( tr( "GEOM_CHECK_TITLE" ) );
54 setSizeGripEnabled( TRUE );
55 GeometryGUI_CheckShapeLayout = new QGridLayout( this );
56 GeometryGUI_CheckShapeLayout->setSpacing( 6 );
57 GeometryGUI_CheckShapeLayout->setMargin( 11 );
59 /***************************************************************/
60 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
61 GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
62 GroupConstructors->setExclusive( TRUE );
63 GroupConstructors->setColumnLayout(0, Qt::Vertical );
64 GroupConstructors->layout()->setSpacing( 0 );
65 GroupConstructors->layout()->setMargin( 0 );
66 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
67 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
68 GroupConstructorsLayout->setSpacing( 6 );
69 GroupConstructorsLayout->setMargin( 11 );
70 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
71 Constructor1->setText( tr( "" ) );
72 Constructor1->setPixmap( image0 );
73 Constructor1->setChecked( TRUE );
74 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
75 Constructor1->sizePolicy().hasHeightForWidth() ) );
76 Constructor1->setMinimumSize( QSize( 60, 0 ) );
77 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
78 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79 GroupConstructorsLayout->addItem( spacer, 0, 1 );
80 GeometryGUI_CheckShapeLayout->addWidget( GroupConstructors, 0, 0 );
82 /***************************************************************/
83 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
84 GroupConstructor1->setTitle( tr( "GEOM_CHECK_INFOS") );
85 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
86 GroupConstructor1->layout()->setSpacing( 0 );
87 GroupConstructor1->layout()->setMargin( 0 );
88 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
89 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
90 GroupConstructor1Layout->setSpacing( 6 );
91 GroupConstructor1Layout->setMargin( 11 );
92 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
93 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
94 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
95 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
96 SelectButtonC1A1->setText( tr( "" ) );
97 SelectButtonC1A1->setPixmap( image1 );
98 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
99 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
100 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
101 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
102 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
103 TextLabelC1A1->setFrameShadow( QLabel::Plain );
104 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
106 Text = new QTextView(GroupConstructor1);
107 Text->setTextFormat( Qt::PlainText );
108 GroupConstructor1Layout->addMultiCellWidget( Text, 1, 1, 0, 2 );
110 GeometryGUI_CheckShapeLayout->addWidget( GroupConstructor1, 1, 0 );
112 /***************************************************************/
113 GroupButtons = new QGroupBox( this, "GroupButtons" );
114 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
115 GroupButtons->setTitle( tr( "" ) );
116 GroupButtons->setColumnLayout(0, Qt::Vertical );
117 GroupButtons->layout()->setSpacing( 0 );
118 GroupButtons->layout()->setMargin( 0 );
119 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
120 GroupButtonsLayout->setAlignment( Qt::AlignTop );
121 GroupButtonsLayout->setSpacing( 6 );
122 GroupButtonsLayout->setMargin( 11 );
123 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
124 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
125 buttonCancel->setAutoDefault( TRUE );
126 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
127 // buttonApply = new QPushButton( GroupButtons, "buttonApply" );
128 // buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
129 // buttonApply->setAutoDefault( TRUE );
130 // GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
131 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
132 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
133 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
134 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
135 // buttonOk = new QPushButton( GroupButtons, "buttonOk" );
136 // buttonOk->setText( tr( "GEOM_BUT_OK" ) );
137 // buttonOk->setAutoDefault( TRUE );
138 // buttonOk->setDefault( TRUE );
139 // GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
140 GeometryGUI_CheckShapeLayout->addWidget( GroupButtons, 2, 0 );
141 /***************************************************************/
143 Init(Sel) ; /* Initialisations */
147 //=================================================================================
148 // function : ~GeometryGUI_CheckShape()
149 // purpose : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_CheckShape::~GeometryGUI_CheckShape()
153 // no need to delete child widgets, Qt does it all for us
157 //=================================================================================
160 //=================================================================================
161 void GeometryGUI_CheckShape::Init( SALOME_Selection* Sel )
163 myConstructorId = 0 ;
164 Constructor1->setChecked( TRUE );
165 myEditCurrentArgument = LineEditC1A1 ;
167 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
168 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
170 // TODO : previous selection into argument ?
172 /* Filter definitions */
173 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
174 myGeom = GEOM::GEOM_Gen::_narrow(comp);
176 /* signals and slots connections */
177 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
178 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
179 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
180 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
182 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
184 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
185 /* to close dialog if study change */
186 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
190 /* Move widget on the botton right corner of main widget */
192 myGeomGUI->DefineDlgPosition( this, x, y ) ;
194 this->show() ; /* displays Dialog */
200 //=================================================================================
201 // function : ConstructorsClicked()
202 // purpose : Radio button management
203 //=================================================================================
204 void GeometryGUI_CheckShape::ConstructorsClicked(int constructorId)
211 //=================================================================================
212 // function : ClickOnCancel()
214 //=================================================================================
215 void GeometryGUI_CheckShape::ClickOnCancel()
217 disconnect( mySelection, 0, this, 0 );
218 myGeomGUI->ResetState() ;
224 //=================================================================================
225 // function : SelectionIntoArgument()
226 // purpose : Called when selection as changed or other case
227 //=================================================================================
228 void GeometryGUI_CheckShape::SelectionIntoArgument()
231 myEditCurrentArgument->setText("") ;
233 SelectedName = ""; /* future the name of selection */
235 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, SelectedName) ;
242 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
246 myEditCurrentArgument->setText( "" );
250 LineEditC1A1->setText(SelectedName) ;
257 //=================================================================================
258 // function : SetEditCurrentArgument()
260 //=================================================================================
261 void GeometryGUI_CheckShape::SetEditCurrentArgument()
263 QPushButton* send = (QPushButton*)sender();
264 switch (myConstructorId)
266 case 0: /* default constructor */
268 if(send == SelectButtonC1A1) {
269 LineEditC1A1->setFocus() ;
270 myEditCurrentArgument = LineEditC1A1;
272 SelectionIntoArgument() ;
281 //=================================================================================
282 // function : LineEditReturnPressed()
284 //=================================================================================
285 void GeometryGUI_CheckShape::LineEditReturnPressed()
287 QLineEdit* send = (QLineEdit*)sender();
288 if( send == LineEditC1A1 )
289 myEditCurrentArgument = LineEditC1A1 ;
293 /* User name of object input management */
294 /* If successfull the selection is changed and signal emitted... */
295 /* so SelectionIntoArgument() is automatically called. */
296 const QString objectUserName = myEditCurrentArgument->text() ;
297 QWidget* thisWidget = (QWidget*)this ;
298 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
299 myEditCurrentArgument->setText( objectUserName ) ;
305 //=================================================================================
306 // function : DeactivateActiveDialog()
308 //=================================================================================
309 void GeometryGUI_CheckShape::DeactivateActiveDialog()
311 if ( GroupConstructors->isEnabled() ) {
312 disconnect( mySelection, 0, this, 0 );
313 GroupConstructors->setEnabled(false) ;
314 GroupConstructor1->setEnabled(false) ;
315 GroupButtons->setEnabled(false) ;
321 //=================================================================================
322 // function : ActivateThisDialog()
324 //=================================================================================
325 void GeometryGUI_CheckShape::ActivateThisDialog()
327 /* Emit a signal to deactivate the active dialog */
328 myGeomGUI->EmitSignalDeactivateDialog() ;
329 GroupConstructors->setEnabled(true) ;
330 GroupConstructor1->setEnabled(true) ;
331 GroupButtons->setEnabled(true) ;
332 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
337 //=================================================================================
338 // function : enterEvent()
340 //=================================================================================
341 void GeometryGUI_CheckShape::enterEvent(QEvent* e)
343 if ( GroupConstructors->isEnabled() )
345 ActivateThisDialog() ;
350 //=================================================================================
351 // function : closeEvent()
353 //=================================================================================
354 void GeometryGUI_CheckShape::closeEvent( QCloseEvent* e )
356 /* same than click on cancel button */
357 this->ClickOnCancel() ;
362 //=================================================================================
363 // function : Check()
365 //=================================================================================
366 void GeometryGUI_CheckShape::Check(const TopoDS_Shape S)
373 BRepCheck_Analyzer ana(S,false);
375 Text->setText( "This Shape seems to be valid." );
377 Text->setText( "This Shape is not valid." );
379 catch(Standard_Failure) {
380 MESSAGE("Catch intercepted in Check()" << endl ) ;