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_WhatisDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "GeometryGUI_WhatisDlg.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 <BRepTools_ShapeSet.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <TopoDS_Iterator.hxx>
45 #include <qtextview.h>
46 #include <qbuttongroup.h>
47 #include <qgroupbox.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
51 #include <qradiobutton.h>
55 #include <qwhatsthis.h>
61 //=================================================================================
62 // class : GeometryGUI_WhatisDlg()
63 // purpose : Constructs a GeometryGUI_WhatisDlg which is a child of 'parent', with the
64 // name 'name' and widget flags set to 'f'.
65 // The dialog will by default be modeless, unless you set 'modal' to
66 // TRUE to construct a modal dialog.
67 //=================================================================================
68 GeometryGUI_WhatisDlg::GeometryGUI_WhatisDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
69 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
71 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_WHATIS")));
72 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
75 setName( "GeometryGUI_WhatisDlg" );
77 setCaption( tr( "GEOM_WHATIS_TITLE" ) );
78 setSizeGripEnabled( TRUE );
79 GeometryGUI_WhatisDlgLayout = new QGridLayout( this );
80 GeometryGUI_WhatisDlgLayout->setSpacing( 6 );
81 GeometryGUI_WhatisDlgLayout->setMargin( 11 );
83 /***************************************************************/
84 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
85 GroupConstructors->setTitle( tr( "GEOM_WHATIS" ) );
86 GroupConstructors->setExclusive( TRUE );
87 GroupConstructors->setColumnLayout(0, Qt::Vertical );
88 GroupConstructors->layout()->setSpacing( 0 );
89 GroupConstructors->layout()->setMargin( 0 );
90 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
91 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
92 GroupConstructorsLayout->setSpacing( 6 );
93 GroupConstructorsLayout->setMargin( 11 );
94 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
95 Constructor1->setText( tr( "" ) );
96 Constructor1->setPixmap( image0 );
97 Constructor1->setChecked( TRUE );
98 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,
99 Constructor1->sizePolicy().hasHeightForWidth() ) );
100 Constructor1->setMinimumSize( QSize( 60, 0 ) );
101 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
102 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
103 GroupConstructorsLayout->addItem( spacer, 0, 1 );
104 GeometryGUI_WhatisDlgLayout->addWidget( GroupConstructors, 0, 0 );
106 /***************************************************************/
107 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
108 GroupConstructor1->setTitle( tr( "GEOM_WHATIS_OBJECT" ) );
109 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
110 GroupConstructor1->layout()->setSpacing( 0 );
111 GroupConstructor1->layout()->setMargin( 0 );
112 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
113 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
114 GroupConstructor1Layout->setSpacing( 6 );
115 GroupConstructor1Layout->setMargin( 11 );
116 LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
117 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
118 GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
119 SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
120 SelectButtonC1A1->setText( tr( "" ) );
121 SelectButtonC1A1->setPixmap( image1 );
122 GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
123 TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
124 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
125 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
126 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
127 TextLabelC1A1->setFrameShadow( QLabel::Plain );
128 GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
130 Text = new QTextView(GroupConstructor1);
131 Text->setTextFormat( Qt::PlainText );
132 GroupConstructor1Layout->addMultiCellWidget( Text, 1, 1, 0, 2 );
134 GeometryGUI_WhatisDlgLayout->addWidget( GroupConstructor1, 1, 0 );
136 /***************************************************************/
137 GroupButtons = new QGroupBox( this, "GroupButtons" );
138 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
139 GroupButtons->setTitle( tr( "" ) );
140 GroupButtons->setColumnLayout(0, Qt::Vertical );
141 GroupButtons->layout()->setSpacing( 0 );
142 GroupButtons->layout()->setMargin( 0 );
143 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
144 GroupButtonsLayout->setAlignment( Qt::AlignTop );
145 GroupButtonsLayout->setSpacing( 6 );
146 GroupButtonsLayout->setMargin( 11 );
147 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
148 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
149 buttonCancel->setAutoDefault( TRUE );
150 GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
152 QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
153 GroupButtonsLayout->addItem( spacer_8, 0, 0 );
154 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
155 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
157 GeometryGUI_WhatisDlgLayout->addWidget( GroupButtons, 2, 0 );
158 /***************************************************************/
160 Init(Sel) ; /* Initialisations */
164 //=================================================================================
165 // function : ~GeometryGUI_WhatisDlg()
166 // purpose : Destroys the object and frees any allocated resources
167 //=================================================================================
168 GeometryGUI_WhatisDlg::~GeometryGUI_WhatisDlg()
170 // no need to delete child widgets, Qt does it all for us
174 //=================================================================================
177 //=================================================================================
178 void GeometryGUI_WhatisDlg::Init( SALOME_Selection* Sel )
180 myConstructorId = 0 ;
181 Constructor1->setChecked( TRUE );
182 myEditCurrentArgument = LineEditC1A1 ;
184 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
185 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
187 // TODO : previous selection into argument ?
189 /* Filter definitions */
190 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
191 myGeom = GEOM::GEOM_Gen::_narrow(comp);
193 /* signals and slots connections */
194 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
195 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
196 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
197 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
199 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
201 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
202 /* to close dialog if study change */
203 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
207 /* Move widget on the botton right corner of main widget */
209 myGeomGUI->DefineDlgPosition( this, x, y ) ;
211 this->show() ; /* displays Dialog */
217 //=================================================================================
218 // function : ConstructorsClicked()
219 // purpose : Radio button management
220 //=================================================================================
221 void GeometryGUI_WhatisDlg::ConstructorsClicked(int constructorId)
228 //=================================================================================
229 // function : ClickOnCancel()
231 //=================================================================================
232 void GeometryGUI_WhatisDlg::ClickOnCancel()
234 myGeomGUI->EraseSimulationShape() ;
235 disconnect( mySelection, 0, this, 0 );
236 myGeomGUI->ResetState() ;
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose : Called when selection as changed or other case
245 //=================================================================================
246 void GeometryGUI_WhatisDlg::SelectionIntoArgument()
248 myGeomGUI->EraseSimulationShape() ;
249 mySimulationTopoDs.Nullify() ;
252 myEditCurrentArgument->setText("") ;
254 SelectedName = ""; /* future the name of selection */
256 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, SelectedName) ;
263 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
267 myEditCurrentArgument->setText( "" );
271 /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
272 if( myGeomGUI->CreateArrowForLinearEdge( S, mySimulationTopoDs ) ) {
273 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
275 LineEditC1A1->setText(SelectedName) ;
276 this->CalculateWhatis(S) ;
282 //=================================================================================
283 // function : SetEditCurrentArgument()
285 //=================================================================================
286 void GeometryGUI_WhatisDlg::SetEditCurrentArgument()
288 QPushButton* send = (QPushButton*)sender();
289 switch (myConstructorId)
291 case 0: /* default constructor */
293 if(send == SelectButtonC1A1) {
294 LineEditC1A1->setFocus() ;
295 myEditCurrentArgument = LineEditC1A1;
297 SelectionIntoArgument() ;
306 //=================================================================================
307 // function : LineEditReturnPressed()
309 //=================================================================================
310 void GeometryGUI_WhatisDlg::LineEditReturnPressed()
312 QLineEdit* send = (QLineEdit*)sender();
313 if( send == LineEditC1A1 )
314 myEditCurrentArgument = LineEditC1A1 ;
318 /* User name of object input management */
319 /* If successfull the selection is changed and signal emitted... */
320 /* so SelectionIntoArgument() is automatically called. */
321 const QString objectUserName = myEditCurrentArgument->text() ;
322 QWidget* thisWidget = (QWidget*)this ;
323 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
324 myEditCurrentArgument->setText( objectUserName ) ;
330 //=================================================================================
331 // function : DeactivateActiveDialog()
333 //=================================================================================
334 void GeometryGUI_WhatisDlg::DeactivateActiveDialog()
336 if ( GroupConstructors->isEnabled() ) {
337 disconnect( mySelection, 0, this, 0 );
338 GroupConstructors->setEnabled(false) ;
339 GroupConstructor1->setEnabled(false) ;
340 myGeomGUI->EraseSimulationShape() ;
341 GroupButtons->setEnabled(false) ;
347 //=================================================================================
348 // function : ActivateThisDialog()
350 //=================================================================================
351 void GeometryGUI_WhatisDlg::ActivateThisDialog()
353 /* Emit a signal to deactivate the active dialog */
354 myGeomGUI->EmitSignalDeactivateDialog() ;
355 GroupConstructors->setEnabled(true) ;
356 GroupConstructor1->setEnabled(true) ;
357 GroupButtons->setEnabled(true) ;
358 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
359 if( !mySimulationTopoDs.IsNull() )
360 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
365 //=================================================================================
366 // function : enterEvent()
368 //=================================================================================
369 void GeometryGUI_WhatisDlg::enterEvent(QEvent* e)
371 if ( GroupConstructors->isEnabled() )
373 ActivateThisDialog() ;
378 //=================================================================================
379 // function : closeEvent()
381 //=================================================================================
382 void GeometryGUI_WhatisDlg::closeEvent( QCloseEvent* e )
384 /* same than click on cancel button */
385 this->ClickOnCancel() ;
390 //=================================================================================
391 // function : CalculateWhatis()
393 //=================================================================================
394 void GeometryGUI_WhatisDlg::CalculateWhatis(const TopoDS_Shape& S)
400 TCollection_AsciiString Astr;
401 Astr = Astr + " Number of shapes in " + strdup(SelectedName.latin1()) + ": \n";
404 // BRepTools_ShapeSet BS;
406 // BS.DumpExtent(Astr);
408 int iType, nbTypes [TopAbs_SHAPE];
409 for (iType = 0; iType < TopAbs_SHAPE; ++iType)
410 nbTypes[ iType ] = 0;
411 nbTypes[ S.ShapeType() ]++;
413 TopTools_MapOfShape aMapOfShape;
414 aMapOfShape.Add( S );
415 TopTools_ListOfShape aListOfShape;
416 aListOfShape.Append( S );
418 TopTools_ListIteratorOfListOfShape itL(aListOfShape);
419 for (; itL.More(); itL.Next())
421 TopoDS_Iterator it(itL.Value());
422 for (; it.More(); it.Next())
424 TopoDS_Shape s = it.Value();
425 if (aMapOfShape.Add( s ))
427 aListOfShape.Append( s );
428 nbTypes[ s.ShapeType() ] ++;
433 Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[ TopAbs_VERTEX ]) + "\n";
434 Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[ TopAbs_EDGE ]) + "\n";
435 Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[ TopAbs_WIRE ]) + "\n";
436 Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[ TopAbs_FACE ]) + "\n";
437 Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[ TopAbs_SHELL ]) + "\n";
438 Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[ TopAbs_SOLID ]) + "\n";
439 Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[ TopAbs_COMPSOLID ]) + "\n";
440 Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[ TopAbs_COMPOUND ]) + "\n";
441 Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent()) + "\n";
443 Text->setText( Astr.ToCString() );
445 catch(Standard_Failure) {
446 MESSAGE("Catch intercepted in CalculateWhatis()" << endl ) ;