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_CheckShape.cxx
25 // Author : Nicolas REJNERI
30 #include "GeometryGUI_CheckShape.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 // Open Cascade Include
38 #include <BRepCheck_Analyzer.hxx>
41 #include <qtextview.h>
42 #include <qbuttongroup.h>
43 #include <qgroupbox.h>
45 #include <qlineedit.h>
46 #include <qpushbutton.h>
47 #include <qradiobutton.h>
51 #include <qwhatsthis.h>
56 //=================================================================================
57 // class : GeometryGUI_CheckShape()
58 // purpose : Constructs a GeometryGUI_CheckShape which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // TRUE to construct a modal dialog.
62 //=================================================================================
63 GeometryGUI_CheckShape::GeometryGUI_CheckShape( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_CHECKSHAPE")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
70 setName( "DialogBox_CHECKSHAPE" );
72 setCaption( tr( "GEOM_CHECK_TITLE" ) );
73 setSizeGripEnabled( TRUE );
74 GeometryGUI_CheckShapeLayout = new QGridLayout( this );
75 GeometryGUI_CheckShapeLayout->setSpacing( 6 );
76 GeometryGUI_CheckShapeLayout->setMargin( 11 );
78 /***************************************************************/
79 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
80 GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
81 GroupConstructors->setExclusive( TRUE );
82 GroupConstructors->setColumnLayout(0, Qt::Vertical );
83 GroupConstructors->layout()->setSpacing( 0 );
84 GroupConstructors->layout()->setMargin( 0 );
85 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
86 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
87 GroupConstructorsLayout->setSpacing( 6 );
88 GroupConstructorsLayout->setMargin( 11 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
94 Constructor1->sizePolicy().hasHeightForWidth() ) );
95 Constructor1->setMinimumSize( QSize( 60, 0 ) );
96 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
97 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
98 GroupConstructorsLayout->addItem( spacer, 0, 1 );
99 GeometryGUI_CheckShapeLayout->addWidget( GroupConstructors, 0, 0 );
101 /***************************************************************/
102 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
103 GroupConstructor1->setTitle( tr( "GEOM_CHECK_INFOS") );
104 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
105 GroupConstructor1->layout()->setSpacing( 0 );
106 GroupConstructor1->layout()->setMargin( 0 );
107 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
108 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
109 GroupConstructor1Layout->setSpacing( 6 );
110 GroupConstructor1Layout->setMargin( 11 );
111 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
112 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
113 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
114 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
115 SelectButtonC1A1->setText( tr( "" ) );
116 SelectButtonC1A1->setPixmap( image1 );
117 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
118 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
119 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
120 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
121 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
122 TextLabelC1A1->setFrameShadow( QLabel::Plain );
123 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
125 Text = new QTextView(GroupConstructor1);
126 Text->setTextFormat( Qt::PlainText );
127 GroupConstructor1Layout->addMultiCellWidget( Text, 1, 1, 0, 2 );
129 GeometryGUI_CheckShapeLayout->addWidget( GroupConstructor1, 1, 0 );
131 /***************************************************************/
132 GroupButtons = new QGroupBox( this, "GroupButtons" );
133 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
134 GroupButtons->setTitle( tr( "" ) );
135 GroupButtons->setColumnLayout(0, Qt::Vertical );
136 GroupButtons->layout()->setSpacing( 0 );
137 GroupButtons->layout()->setMargin( 0 );
138 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
139 GroupButtonsLayout->setAlignment( Qt::AlignTop );
140 GroupButtonsLayout->setSpacing( 6 );
141 GroupButtonsLayout->setMargin( 11 );
142 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
143 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
144 buttonCancel->setAutoDefault( TRUE );
145 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
146 // buttonApply = new QPushButton( GroupButtons, "buttonApply" );
147 // buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
148 // buttonApply->setAutoDefault( TRUE );
149 // GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
150 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
151 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
152 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
153 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
154 // buttonOk = new QPushButton( GroupButtons, "buttonOk" );
155 // buttonOk->setText( tr( "GEOM_BUT_OK" ) );
156 // buttonOk->setAutoDefault( TRUE );
157 // buttonOk->setDefault( TRUE );
158 // GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
159 GeometryGUI_CheckShapeLayout->addWidget( GroupButtons, 2, 0 );
160 /***************************************************************/
162 Init(Sel) ; /* Initialisations */
166 //=================================================================================
167 // function : ~GeometryGUI_CheckShape()
168 // purpose : Destroys the object and frees any allocated resources
169 //=================================================================================
170 GeometryGUI_CheckShape::~GeometryGUI_CheckShape()
172 // no need to delete child widgets, Qt does it all for us
176 //=================================================================================
179 //=================================================================================
180 void GeometryGUI_CheckShape::Init( SALOME_Selection* Sel )
182 myConstructorId = 0 ;
183 Constructor1->setChecked( TRUE );
184 myEditCurrentArgument = LineEditC1A1 ;
186 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
187 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
189 // TODO : previous selection into argument ?
191 /* Filter definitions */
192 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
193 myGeom = GEOM::GEOM_Gen::_narrow(comp);
195 /* signals and slots connections */
196 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
197 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
198 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
199 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
201 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
203 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
204 /* to close dialog if study change */
205 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
209 /* Move widget on the botton right corner of main widget */
211 myGeomGUI->DefineDlgPosition( this, x, y ) ;
213 this->show() ; /* displays Dialog */
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose : Radio button management
222 //=================================================================================
223 void GeometryGUI_CheckShape::ConstructorsClicked(int constructorId)
230 //=================================================================================
231 // function : ClickOnCancel()
233 //=================================================================================
234 void GeometryGUI_CheckShape::ClickOnCancel()
236 disconnect( mySelection, 0, this, 0 );
237 myGeomGUI->ResetState() ;
243 //=================================================================================
244 // function : SelectionIntoArgument()
245 // purpose : Called when selection as changed or other case
246 //=================================================================================
247 void GeometryGUI_CheckShape::SelectionIntoArgument()
250 myEditCurrentArgument->setText("") ;
252 SelectedName = ""; /* future the name of selection */
254 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, SelectedName) ;
261 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
265 myEditCurrentArgument->setText( "" );
269 LineEditC1A1->setText(SelectedName) ;
276 //=================================================================================
277 // function : SetEditCurrentArgument()
279 //=================================================================================
280 void GeometryGUI_CheckShape::SetEditCurrentArgument()
282 QPushButton* send = (QPushButton*)sender();
283 switch (myConstructorId)
285 case 0: /* default constructor */
287 if(send == SelectButtonC1A1) {
288 LineEditC1A1->setFocus() ;
289 myEditCurrentArgument = LineEditC1A1;
291 SelectionIntoArgument() ;
300 //=================================================================================
301 // function : LineEditReturnPressed()
303 //=================================================================================
304 void GeometryGUI_CheckShape::LineEditReturnPressed()
306 QLineEdit* send = (QLineEdit*)sender();
307 if( send == LineEditC1A1 )
308 myEditCurrentArgument = LineEditC1A1 ;
312 /* User name of object input management */
313 /* If successfull the selection is changed and signal emitted... */
314 /* so SelectionIntoArgument() is automatically called. */
315 const QString objectUserName = myEditCurrentArgument->text() ;
316 QWidget* thisWidget = (QWidget*)this ;
317 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
318 myEditCurrentArgument->setText( objectUserName ) ;
324 //=================================================================================
325 // function : DeactivateActiveDialog()
327 //=================================================================================
328 void GeometryGUI_CheckShape::DeactivateActiveDialog()
330 if ( GroupConstructors->isEnabled() ) {
331 disconnect( mySelection, 0, this, 0 );
332 GroupConstructors->setEnabled(false) ;
333 GroupConstructor1->setEnabled(false) ;
334 GroupButtons->setEnabled(false) ;
340 //=================================================================================
341 // function : ActivateThisDialog()
343 //=================================================================================
344 void GeometryGUI_CheckShape::ActivateThisDialog()
346 /* Emit a signal to deactivate the active dialog */
347 myGeomGUI->EmitSignalDeactivateDialog() ;
348 GroupConstructors->setEnabled(true) ;
349 GroupConstructor1->setEnabled(true) ;
350 GroupButtons->setEnabled(true) ;
351 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
356 //=================================================================================
357 // function : enterEvent()
359 //=================================================================================
360 void GeometryGUI_CheckShape::enterEvent(QEvent* e)
362 if ( GroupConstructors->isEnabled() )
364 ActivateThisDialog() ;
369 //=================================================================================
370 // function : closeEvent()
372 //=================================================================================
373 void GeometryGUI_CheckShape::closeEvent( QCloseEvent* e )
375 /* same than click on cancel button */
376 this->ClickOnCancel() ;
381 //=================================================================================
382 // function : Check()
384 //=================================================================================
385 void GeometryGUI_CheckShape::Check(const TopoDS_Shape S)
392 BRepCheck_Analyzer ana(S,false);
394 Text->setText( "This Shape seems to be valid." );
396 Text->setText( "This Shape is not valid." );
398 catch(Standard_Failure) {
399 MESSAGE("Catch intercepted in Check()" << endl ) ;