2 // File : GeometryGUI_WhatisDlg.cxx
3 // Created : Mon Mar 04 14:48:16 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 #include "GeometryGUI_WhatisDlg.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 <BRepTools_ShapeSet.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>
38 //=================================================================================
39 // class : GeometryGUI_WhatisDlg()
40 // purpose : Constructs a GeometryGUI_WhatisDlg 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_WhatisDlg::GeometryGUI_WhatisDlg( 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_WHATIS")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
52 setName( "GeometryGUI_WhatisDlg" );
54 setCaption( tr( "GEOM_WHATIS_TITLE" ) );
55 setSizeGripEnabled( TRUE );
56 GeometryGUI_WhatisDlgLayout = new QGridLayout( this );
57 GeometryGUI_WhatisDlgLayout->setSpacing( 6 );
58 GeometryGUI_WhatisDlgLayout->setMargin( 11 );
60 /***************************************************************/
61 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
62 GroupConstructors->setTitle( tr( "GEOM_WHATIS" ) );
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_WhatisDlgLayout->addWidget( GroupConstructors, 0, 0 );
83 /***************************************************************/
84 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
85 GroupConstructor1->setTitle( tr( "GEOM_WHATIS_OBJECT" ) );
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 );
93 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
94 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
95 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
96 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
97 SelectButtonC1A1->setText( tr( "" ) );
98 SelectButtonC1A1->setPixmap( image1 );
99 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
100 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
101 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
102 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
103 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
104 TextLabelC1A1->setFrameShadow( QLabel::Plain );
105 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
107 Text = new QTextView(GroupConstructor1);
108 Text->setTextFormat( Qt::PlainText );
109 GroupConstructor1Layout->addMultiCellWidget( Text, 1, 1, 0, 2 );
111 GeometryGUI_WhatisDlgLayout->addWidget( GroupConstructor1, 1, 0 );
113 /***************************************************************/
114 GroupButtons = new QGroupBox( this, "GroupButtons" );
115 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
116 GroupButtons->setTitle( tr( "" ) );
117 GroupButtons->setColumnLayout(0, Qt::Vertical );
118 GroupButtons->layout()->setSpacing( 0 );
119 GroupButtons->layout()->setMargin( 0 );
120 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
121 GroupButtonsLayout->setAlignment( Qt::AlignTop );
122 GroupButtonsLayout->setSpacing( 6 );
123 GroupButtonsLayout->setMargin( 11 );
124 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
125 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
126 buttonCancel->setAutoDefault( TRUE );
127 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
129 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
130 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
131 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
132 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
134 GeometryGUI_WhatisDlgLayout->addWidget( GroupButtons, 2, 0 );
135 /***************************************************************/
137 Init(Sel) ; /* Initialisations */
141 //=================================================================================
142 // function : ~GeometryGUI_WhatisDlg()
143 // purpose : Destroys the object and frees any allocated resources
144 //=================================================================================
145 GeometryGUI_WhatisDlg::~GeometryGUI_WhatisDlg()
147 // no need to delete child widgets, Qt does it all for us
151 //=================================================================================
154 //=================================================================================
155 void GeometryGUI_WhatisDlg::Init( SALOME_Selection* Sel )
157 myConstructorId = 0 ;
158 Constructor1->setChecked( TRUE );
159 myEditCurrentArgument = LineEditC1A1 ;
161 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
162 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
164 // TODO : previous selection into argument ?
166 /* Filter definitions */
167 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
168 myGeom = GEOM::GEOM_Gen::_narrow(comp);
170 /* signals and slots connections */
171 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
172 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
173 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
174 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
176 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
178 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
179 /* to close dialog if study change */
180 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
184 /* Move widget on the botton right corner of main widget */
186 myGeomGUI->DefineDlgPosition( this, x, y ) ;
188 this->show() ; /* displays Dialog */
194 //=================================================================================
195 // function : ConstructorsClicked()
196 // purpose : Radio button management
197 //=================================================================================
198 void GeometryGUI_WhatisDlg::ConstructorsClicked(int constructorId)
205 //=================================================================================
206 // function : ClickOnCancel()
208 //=================================================================================
209 void GeometryGUI_WhatisDlg::ClickOnCancel()
211 myGeomGUI->EraseSimulationShape() ;
212 disconnect( mySelection, 0, this, 0 );
213 myGeomGUI->ResetState() ;
219 //=================================================================================
220 // function : SelectionIntoArgument()
221 // purpose : Called when selection as changed or other case
222 //=================================================================================
223 void GeometryGUI_WhatisDlg::SelectionIntoArgument()
225 myGeomGUI->EraseSimulationShape() ;
226 mySimulationTopoDs.Nullify() ;
229 myEditCurrentArgument->setText("") ;
231 SelectedName = ""; /* future the name of selection */
233 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, SelectedName) ;
240 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
244 myEditCurrentArgument->setText( "" );
248 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
249 if( myGeomGUI->CreateArrowForLinearEdge( S, mySimulationTopoDs ) ) {
250 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
252 LineEditC1A1->setText(SelectedName) ;
253 this->CalculateWhatis(S) ;
259 //=================================================================================
260 // function : SetEditCurrentArgument()
262 //=================================================================================
263 void GeometryGUI_WhatisDlg::SetEditCurrentArgument()
265 QPushButton* send = (QPushButton*)sender();
266 switch (myConstructorId)
268 case 0: /* default constructor */
270 if(send == SelectButtonC1A1) {
271 LineEditC1A1->setFocus() ;
272 myEditCurrentArgument = LineEditC1A1;
274 SelectionIntoArgument() ;
283 //=================================================================================
284 // function : LineEditReturnPressed()
286 //=================================================================================
287 void GeometryGUI_WhatisDlg::LineEditReturnPressed()
289 QLineEdit* send = (QLineEdit*)sender();
290 if( send == LineEditC1A1 )
291 myEditCurrentArgument = LineEditC1A1 ;
295 /* User name of object input management */
296 /* If successfull the selection is changed and signal emitted... */
297 /* so SelectionIntoArgument() is automatically called. */
298 const QString objectUserName = myEditCurrentArgument->text() ;
299 QWidget* thisWidget = (QWidget*)this ;
300 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
301 myEditCurrentArgument->setText( objectUserName ) ;
307 //=================================================================================
308 // function : DeactivateActiveDialog()
310 //=================================================================================
311 void GeometryGUI_WhatisDlg::DeactivateActiveDialog()
313 if ( GroupConstructors->isEnabled() ) {
314 disconnect( mySelection, 0, this, 0 );
315 GroupConstructors->setEnabled(false) ;
316 GroupConstructor1->setEnabled(false) ;
317 myGeomGUI->EraseSimulationShape() ;
318 GroupButtons->setEnabled(false) ;
324 //=================================================================================
325 // function : ActivateThisDialog()
327 //=================================================================================
328 void GeometryGUI_WhatisDlg::ActivateThisDialog()
330 /* Emit a signal to deactivate the active dialog */
331 myGeomGUI->EmitSignalDeactivateDialog() ;
332 GroupConstructors->setEnabled(true) ;
333 GroupConstructor1->setEnabled(true) ;
334 GroupButtons->setEnabled(true) ;
335 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
336 if( !mySimulationTopoDs.IsNull() )
337 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
342 //=================================================================================
343 // function : enterEvent()
345 //=================================================================================
346 void GeometryGUI_WhatisDlg::enterEvent(QEvent* e)
348 if ( GroupConstructors->isEnabled() )
350 ActivateThisDialog() ;
355 //=================================================================================
356 // function : closeEvent()
358 //=================================================================================
359 void GeometryGUI_WhatisDlg::closeEvent( QCloseEvent* e )
361 /* same than click on cancel button */
362 this->ClickOnCancel() ;
367 //=================================================================================
368 // function : CalculateWhatis()
370 //=================================================================================
371 void GeometryGUI_WhatisDlg::CalculateWhatis(const TopoDS_Shape& S)
377 TCollection_AsciiString Astr;
378 Astr = Astr + " Number of shapes in " + strdup(SelectedName.latin1()) + ": \n";
381 BRepTools_ShapeSet BS;
385 Text->setText( Astr.ToCString() );
387 catch(Standard_Failure) {
388 MESSAGE("Catch intercepted in CalculateWhatis()" << endl ) ;