]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_PropertiesDlg.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/geom.git] / src / GEOMGUI / GeometryGUI_PropertiesDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GeometryGUI_PropertiesDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_PropertiesDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
39 #include <qlabel.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
43 #include <qlayout.h>
44 #include <qvariant.h>
45 #include <qtooltip.h>
46 #include <qwhatsthis.h>
47 #include <qimage.h>
48 #include <qpixmap.h>
49
50 #include <TopExp_Explorer.hxx>
51
52
53 //=================================================================================
54 // class    : GeometryGUI_PropertiesDlg()
55 // purpose  : Constructs a GeometryGUI_PropertiesDlg which is a child of 'parent', with the 
56 //            name 'name' and widget flags set to 'f'.
57 //            The dialog will by default be modeless, unless you set 'modal' to
58 //            TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_PropertiesDlg::GeometryGUI_PropertiesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
62 {
63     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BASICPROPERTIES")));
64     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
65
66     if ( !name )
67         setName( "GeometryGUI_PropertiesDlg" );
68     resize( 303, 275 ); 
69     setCaption( tr( "GEOM_PROPERTIES_TITLE"  ) );
70     setSizeGripEnabled( TRUE );
71     GeometryGUI_PropertiesDlgLayout = new QGridLayout( this ); 
72     GeometryGUI_PropertiesDlgLayout->setSpacing( 6 );
73     GeometryGUI_PropertiesDlgLayout->setMargin( 11 );
74     
75     /***************************************************************/
76     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77     GroupConstructors->setTitle( tr( "GEOM_PROPERTIES"  ) );
78     GroupConstructors->setExclusive( TRUE );
79     GroupConstructors->setColumnLayout(0, Qt::Vertical );
80     GroupConstructors->layout()->setSpacing( 0 );
81     GroupConstructors->layout()->setMargin( 0 );
82     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84     GroupConstructorsLayout->setSpacing( 6 );
85     GroupConstructorsLayout->setMargin( 11 );
86     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
87     Constructor1->setText( tr( ""  ) );
88     Constructor1->setPixmap( image0 );
89     Constructor1->setChecked( TRUE );
90     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
91     Constructor1->setMinimumSize( QSize( 60, 0 ) );
92     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
93     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94     GroupConstructorsLayout->addItem( spacer, 0, 1 );
95     GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructors, 0, 0 );
96
97     /***************************************************************/
98     GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
99     GroupConstructor1->setTitle( tr( "GEOM_PROPERTIES_CONSTR"  ) );
100     GroupConstructor1->setColumnLayout(0, Qt::Vertical );
101     GroupConstructor1->layout()->setSpacing( 0 );
102     GroupConstructor1->layout()->setMargin( 0 );
103     GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
104     GroupConstructor1Layout->setAlignment( Qt::AlignTop );
105     GroupConstructor1Layout->setSpacing( 6 );
106     GroupConstructor1Layout->setMargin( 11 );
107     LineEditC1A1 = new QLineEdit( GroupConstructor1, "LineEditC1A1" );
108     LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
109     GroupConstructor1Layout->addWidget( LineEditC1A1, 0, 2 );
110     SelectButtonC1A1 = new QPushButton( GroupConstructor1, "SelectButtonC1A1" );
111     SelectButtonC1A1->setText( tr( ""  ) );
112     SelectButtonC1A1->setPixmap( image1 );
113     GroupConstructor1Layout->addWidget( SelectButtonC1A1, 0, 1 );
114     TextLabelC1A1 = new QLabel( GroupConstructor1, "TextLabelC1A1" );
115     TextLabelC1A1->setText( tr( "GEOM_OBJECT"  ) );
116     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
117     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
118     TextLabelC1A1->setFrameShadow( QLabel::Plain );
119     GroupConstructor1Layout->addWidget( TextLabelC1A1, 0, 0 );
120     TextLabel_Length = new QLabel( GroupConstructor1, "TextLabel_Length" );
121     TextLabel_Length->setText( tr( "GEOM_LENGTH"  ) );
122     TextLabel_Length->setMinimumSize( QSize( 50, 0 ) );
123     TextLabel_Length->setFrameShape( QLabel::NoFrame );
124     TextLabel_Length->setFrameShadow( QLabel::Plain );
125     GroupConstructor1Layout->addWidget( TextLabel_Length, 1, 0 );
126     LineEdit_Length = new QLineEdit( GroupConstructor1, "LineEdit_Length" );
127     LineEdit_Length->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Length->sizePolicy().hasHeightForWidth() ) );
128     //    LineEdit_Length->setEnabled( FALSE );
129     LineEdit_Length->setReadOnly( TRUE );
130     GroupConstructor1Layout->addWidget( LineEdit_Length, 1, 2 );
131     LineEdit_Surface = new QLineEdit( GroupConstructor1, "LineEdit_Surface" );
132     LineEdit_Surface->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Surface->sizePolicy().hasHeightForWidth() ) );
133     //LineEdit_Surface->setEnabled( FALSE );
134     LineEdit_Surface->setReadOnly( TRUE );
135     GroupConstructor1Layout->addWidget( LineEdit_Surface, 2, 2 );
136     TextLabel_Surface = new QLabel( GroupConstructor1, "TextLabel_Surface" );
137     TextLabel_Surface->setText( tr( "GEOM_PROPERTIES_SURFACE"  ) );
138     TextLabel_Surface->setMinimumSize( QSize( 50, 0 ) );
139     TextLabel_Surface->setFrameShape( QLabel::NoFrame );
140     TextLabel_Surface->setFrameShadow( QLabel::Plain );
141     GroupConstructor1Layout->addWidget( TextLabel_Surface, 2, 0 );
142     TextLabel_Volume = new QLabel( GroupConstructor1, "TextLabel_Volume" );
143     TextLabel_Volume->setText( tr( "GEOM_PROPERTIES_VOLUME"  ) );
144     TextLabel_Volume->setMinimumSize( QSize( 50, 0 ) );
145     TextLabel_Volume->setFrameShape( QLabel::NoFrame );
146     TextLabel_Volume->setFrameShadow( QLabel::Plain );
147     GroupConstructor1Layout->addWidget( TextLabel_Volume, 3, 0 );
148     LineEdit_Volume = new QLineEdit( GroupConstructor1, "LineEdit_Volume" );
149     LineEdit_Volume->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Volume->sizePolicy().hasHeightForWidth() ) );
150     //LineEdit_Volume->setEnabled( FALSE );
151     LineEdit_Volume->setReadOnly( TRUE );
152     GroupConstructor1Layout->addWidget( LineEdit_Volume, 3, 2 );
153     GeometryGUI_PropertiesDlgLayout->addWidget( GroupConstructor1, 1, 0 );
154
155     /***************************************************************/
156     GroupButtons = new QGroupBox( this, "GroupButtons" );
157     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
158     GroupButtons->setTitle( tr( ""  ) );
159     GroupButtons->setColumnLayout(0, Qt::Vertical );
160     GroupButtons->layout()->setSpacing( 0 );
161     GroupButtons->layout()->setMargin( 0 );
162     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
163     GroupButtonsLayout->setAlignment( Qt::AlignTop );
164     GroupButtonsLayout->setSpacing( 6 );
165     GroupButtonsLayout->setMargin( 11 );
166     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
167     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
168     buttonCancel->setAutoDefault( TRUE );
169     GroupButtonsLayout->addWidget( buttonCancel, 0, 1 );
170  
171     QSpacerItem* spacer_8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
172     GroupButtonsLayout->addItem( spacer_8, 0, 0 );
173     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
174     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
175
176     GeometryGUI_PropertiesDlgLayout->addWidget( GroupButtons, 2, 0 );
177     /***************************************************************/
178
179     Init(Sel) ; /* Initialisations */
180 }
181
182
183 //=================================================================================
184 // function : ~GeometryGUI_PropertiesDlg()
185 // purpose  : Destroys the object and frees any allocated resources
186 //=================================================================================
187 GeometryGUI_PropertiesDlg::~GeometryGUI_PropertiesDlg()
188 {
189     // no need to delete child widgets, Qt does it all for us
190 }
191
192
193 //=================================================================================
194 // function : Init()
195 // purpose  :
196 //=================================================================================
197 void GeometryGUI_PropertiesDlg::Init( SALOME_Selection* Sel )
198 {
199   myConstructorId = 0 ;
200   Constructor1->setChecked( TRUE );
201   myEditCurrentArgument = LineEditC1A1 ;        
202   mySelection = Sel;
203   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
204   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
205   
206   // TODO : previous selection into argument ?
207
208   /* Filter definitions */
209   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
210   myGeom = GEOM::GEOM_Gen::_narrow(comp);
211
212   /* signals and slots connections */
213   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
214   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
215   connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
216   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
218   
219   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
220   /* to close dialog if study change */
221   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
222
223   /* Move widget on the botton right corner of main widget */
224   int x, y ;
225   myGeomGUI->DefineDlgPosition( this, x, y ) ;
226   this->move( x, y ) ;
227   this->show() ; /* displays Dialog */
228   return ;
229 }
230
231
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose  : Radio button management
235 //=================================================================================
236 void GeometryGUI_PropertiesDlg::ConstructorsClicked(int constructorId)
237 {
238   return ;
239 }
240
241
242
243 //=================================================================================
244 // function : ClickOnCancel()
245 // purpose  :
246 //=================================================================================
247 void GeometryGUI_PropertiesDlg::ClickOnCancel()
248 {
249   myGeomGUI->EraseSimulationShape() ;
250   disconnect( mySelection, 0, this, 0 );
251   myGeomGUI->EraseSimulationShape() ; 
252   myGeomGUI->ResetState() ;
253   reject() ;
254   return ;
255 }
256
257
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose  : Called when selection as changed or other case
261 //=================================================================================
262 void GeometryGUI_PropertiesDlg::SelectionIntoArgument()
263 {
264   myGeomGUI->EraseSimulationShape() ;
265   mySimulationTopoDs.Nullify() ;
266   
267   LineEdit_Length->setText("") ;
268   LineEdit_Surface->setText("") ;
269   LineEdit_Volume->setText("") ;
270   myEditCurrentArgument->setText("") ;
271
272   QString aString = ""; /* future the name of selection */
273
274   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
275   if ( nbSel != 1 ) {
276     return ;
277   }
278
279   /*  nbSel == 1  */ 
280   TopoDS_Shape S;
281   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
282     return ;
283   
284   if( S.IsNull() || S.ShapeType() == TopAbs_VERTEX ) {
285     myEditCurrentArgument->setText( "" );
286     return ;
287   }
288  
289   LineEditC1A1->setText(aString) ;
290
291   /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
292   if( myGeomGUI->CreateArrowForLinearEdge( S, mySimulationTopoDs ) ) {
293     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
294   }
295   this->CalculateAndDisplayProperties(S) ;
296   
297   return ;
298 }
299
300
301 //=================================================================================
302 // function : SetEditCurrentArgument()
303 // purpose  :
304 //=================================================================================
305 void GeometryGUI_PropertiesDlg::SetEditCurrentArgument()
306 {
307   QPushButton* send = (QPushButton*)sender();
308   switch (myConstructorId)
309     {
310     case 0: /* default constructor */
311       { 
312         if(send == SelectButtonC1A1) {
313           LineEditC1A1->setFocus() ;
314           myEditCurrentArgument = LineEditC1A1;
315         }
316         SelectionIntoArgument() ;
317         break;
318       }
319     }
320   return ;
321 }
322
323
324
325 //=================================================================================
326 // function : LineEditReturnPressed()
327 // purpose  :
328 //=================================================================================
329 void GeometryGUI_PropertiesDlg::LineEditReturnPressed()
330 {  
331   QLineEdit* send = (QLineEdit*)sender();  
332   if( send == LineEditC1A1 )
333     myEditCurrentArgument = LineEditC1A1 ;
334   else
335     return ;
336   
337   /* User name of object input management                          */
338   /* If successfull the selection is changed and signal emitted... */
339   /* so SelectionIntoArgument() is automatically called.           */
340   const QString objectUserName = myEditCurrentArgument->text() ;
341   QWidget* thisWidget = (QWidget*)this ;
342   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
343     myEditCurrentArgument->setText( objectUserName ) ;
344   }
345   return ;
346 }
347
348
349 //=================================================================================
350 // function : DeactivateActiveDialog()
351 // purpose  :
352 //=================================================================================
353 void GeometryGUI_PropertiesDlg::DeactivateActiveDialog()
354 {
355   if ( GroupConstructors->isEnabled() ) {    
356     disconnect( mySelection, 0, this, 0 );
357     GroupConstructors->setEnabled(false) ;
358     GroupConstructor1->setEnabled(false) ;
359     myGeomGUI->EraseSimulationShape() ;
360     GroupButtons->setEnabled(false) ;
361   }
362   return ;
363 }
364
365
366 //=================================================================================
367 // function : ActivateThisDialog()
368 // purpose  :
369 //=================================================================================
370 void GeometryGUI_PropertiesDlg::ActivateThisDialog()
371 {
372   /* Emit a signal to deactivate the active dialog */
373   myGeomGUI->EmitSignalDeactivateDialog() ;   
374   GroupConstructors->setEnabled(true) ;
375   GroupConstructor1->setEnabled(true) ;
376   GroupButtons->setEnabled(true) ;
377   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
378   
379   if( !mySimulationTopoDs.IsNull() )
380     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
381   
382   return ;
383 }
384
385
386 //=================================================================================
387 // function : enterEvent()
388 // purpose  :
389 //=================================================================================
390 void GeometryGUI_PropertiesDlg::enterEvent(QEvent* e)
391 {
392   if ( GroupConstructors->isEnabled() )
393     return ;  
394   ActivateThisDialog() ;
395   return ;
396 }
397
398
399 //=================================================================================
400 // function : closeEvent()
401 // purpose  :
402 //=================================================================================
403 void GeometryGUI_PropertiesDlg::closeEvent( QCloseEvent* e )
404 {
405   /* same than click on cancel button */
406   this->ClickOnCancel() ;
407   return ;
408 }
409
410
411 //=================================================================================
412 // function : CalculateAndDisplayProperties()
413 // purpose  :
414 //=================================================================================
415 void GeometryGUI_PropertiesDlg::CalculateAndDisplayProperties(const TopoDS_Shape& S)
416 {
417   LineEdit_Length->setText("") ;
418   LineEdit_Surface->setText("") ;
419   LineEdit_Volume->setText("") ;
420   if( S.IsNull() ) 
421     return ;
422
423   Standard_Real result;
424   GProp_GProps LProps;
425   GProp_GProps SProps;
426   QString resString;
427
428   try 
429     {
430       BRepGProp::LinearProperties(S,LProps);
431       result = LProps.Mass();
432       if (!IsEqual( result, 0.0))
433         {       
434           resString = tr("%1").arg( result, 12, 'f', 6 ) ;
435           LineEdit_Length->setText(resString) ;
436         }
437
438       BRepGProp::SurfaceProperties(S, SProps);
439       result = SProps.Mass();
440       if (!IsEqual( result, 0.0))
441         {       
442           resString = tr("%1").arg( result, 12, 'f', 6 ) ;
443           LineEdit_Surface->setText(resString) ;
444         }
445         
446       result = 0.0;
447       if (S.ShapeType() < TopAbs_SHELL)
448         {
449           for( TopExp_Explorer Exp(S,TopAbs_SOLID); Exp.More(); Exp.Next() ) 
450             { 
451               GProp_GProps VProps;
452               BRepGProp::VolumeProperties(Exp.Current(), VProps);
453               result += VProps.Mass();
454             }
455         }
456       if (!IsEqual( result, 0.0 ))
457         {       
458           resString = tr("%1").arg( result, 12, 'f', 6 ) ;
459           LineEdit_Volume->setText(resString) ;
460         }
461     }
462   catch(Standard_Failure) 
463     {
464       MESSAGE("Catch intercepted in CalculateAndDisplayProperties()" << endl ) ;
465     }
466   return ;
467 }