Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/geom.git] / src / GEOMGUI / GeometryGUI_EdgeDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_EdgeDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10 #include "GeometryGUI_EdgeDlg.h"
11
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
16
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
19 #include <qlabel.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
23 #include <qlayout.h>
24 #include <qvariant.h>
25 #include <qtooltip.h>
26 #include <qwhatsthis.h>
27 #include <qimage.h>
28 #include <qpixmap.h>
29
30
31
32 //=================================================================================
33 // class    : GeometryGUI_EdgeDlg()
34 // purpose  : Constructs a GeometryGUI_EdgeDlg which is a child of 'parent', with the 
35 //            name 'name' and widget flags set to 'f'.
36 //            The dialog will by default be modeless, unless you set 'modal' to
37 //            TRUE to construct a modal dialog.
38 //=================================================================================
39 GeometryGUI_EdgeDlg::GeometryGUI_EdgeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
40     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 {
42     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BUILD_EDGE")));
43     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
44
45     if ( !name )
46         setName( "GeometryGUI_EdgeDlg" );
47     resize( 303, 225 ); 
48     setCaption( tr( "GEOM_EDGE_TITLE"  ) );
49     setSizeGripEnabled( TRUE );
50     GeometryGUI_EdgeDlgLayout = new QGridLayout( this ); 
51     GeometryGUI_EdgeDlgLayout->setSpacing( 6 );
52     GeometryGUI_EdgeDlgLayout->setMargin( 11 );
53     
54     /***************************************************************/
55     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
56     GroupConstructors->setTitle( tr( "GEOM_EDGE"  ) );
57     GroupConstructors->setExclusive( TRUE );
58     GroupConstructors->setColumnLayout(0, Qt::Vertical );
59     GroupConstructors->layout()->setSpacing( 0 );
60     GroupConstructors->layout()->setMargin( 0 );
61     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
62     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
63     GroupConstructorsLayout->setSpacing( 6 );
64     GroupConstructorsLayout->setMargin( 11 );
65     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
66     Constructor1->setText( tr( ""  ) );
67     Constructor1->setPixmap( image0 );
68     Constructor1->setChecked( TRUE );
69     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
70     Constructor1->setMinimumSize( QSize( 50, 0 ) );
71     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
72     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
73     GroupConstructorsLayout->addItem( spacer, 0, 1 );
74     GeometryGUI_EdgeDlgLayout->addWidget( GroupConstructors, 0, 0 );
75
76     /***************************************************************/
77     GroupC1 = new QGroupBox( this, "GroupC1" );
78     GroupC1->setTitle( tr( "GEOM_POINTS"  ) );
79     GroupC1->setMinimumSize( QSize( 0, 0 ) );
80     GroupC1->setFrameShape( QGroupBox::Box );
81     GroupC1->setFrameShadow( QGroupBox::Sunken );
82     GroupC1->setColumnLayout(0, Qt::Vertical );
83     GroupC1->layout()->setSpacing( 0 );
84     GroupC1->layout()->setMargin( 0 );
85     GroupC1Layout = new QGridLayout( GroupC1->layout() );
86     GroupC1Layout->setAlignment( Qt::AlignTop );
87     GroupC1Layout->setSpacing( 6 );
88     GroupC1Layout->setMargin( 11 );
89     SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
90     SelectButtonC1A2->setText( tr( ""  ) );
91     SelectButtonC1A2->setPixmap( image1 );
92     GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
93     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
94     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
95     LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
96     GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
97     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
98     SelectButtonC1A1->setText( tr( ""  ) );
99     SelectButtonC1A1->setPixmap( image1 );
100     SelectButtonC1A1->setToggleButton( FALSE );
101     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
102     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
103     TextLabelC1A1->setText( tr( "GEOM_POINT_I"  ).arg("1") );
104     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
105     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
106     TextLabelC1A1->setFrameShadow( QLabel::Plain );
107     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
108     TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
109     TextLabelC1A2->setText( tr( "GEOM_POINT_I"  ).arg("2") );
110     TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
111     GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
112     GeometryGUI_EdgeDlgLayout->addWidget( GroupC1, 1, 0 );
113
114     /***************************************************************/
115     GroupButtons = new QGroupBox( this, "GroupButtons" );
116     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
117     GroupButtons->setTitle( tr( ""  ) );
118     GroupButtons->setColumnLayout(0, Qt::Vertical );
119     GroupButtons->layout()->setSpacing( 0 );
120     GroupButtons->layout()->setMargin( 0 );
121     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
122     GroupButtonsLayout->setAlignment( Qt::AlignTop );
123     GroupButtonsLayout->setSpacing( 6 );
124     GroupButtonsLayout->setMargin( 11 );
125     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
126     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
127     buttonCancel->setAutoDefault( TRUE );
128     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
129     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
130     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
131     buttonApply->setAutoDefault( TRUE );
132     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
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_EdgeDlgLayout->addWidget( GroupButtons, 2, 0 );
141     /***************************************************************/
142
143     Init(Sel) ; /* Initialisations */
144 }
145
146
147 //=================================================================================
148 // function : ~GeometryGUI_EdgeDlg()
149 // purpose  : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_EdgeDlg::~GeometryGUI_EdgeDlg()
152 {
153     // no need to delete child widgets, Qt does it all for us
154 }
155
156
157 //=================================================================================
158 // function : Init()
159 // purpose  :
160 //=================================================================================
161 void GeometryGUI_EdgeDlg::Init( SALOME_Selection* Sel )
162 {
163
164   GroupC1->show();
165   // GroupC2->hide();
166   // GroupC3->hide();
167   myConstructorId = 0 ;
168   Constructor1->setChecked( TRUE );
169   myEditCurrentArgument = LineEditC1A1 ;        
170   mySelection = Sel;
171   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
172   myPoint1.SetCoord( 0.0, 0.0, 0.0 );
173   myPoint2.SetCoord( 0.0, 0.0, 0.0 );
174   myOkPoint1 = myOkPoint2 = false ;
175   mySimulationTopoDs.Nullify() ;
176   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;  
177
178   // TODO : previous selection into argument ?
179
180   /* Filters definition */
181   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
182   myGeom = GEOM::GEOM_Gen::_narrow(comp);
183   myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
184   mySelection->AddFilter(myVertexFilter) ; /* first filter used */
185
186   /* signals and slots connections */
187   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
188   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
189   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
190   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
191   connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
192   connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
193
194   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
195   connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
196    
197   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
198   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
199   /* to close dialog if study change */
200   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ; 
201
202   /* Move widget on the botton right corner of main widget */
203   int x, y ;
204   myGeomGUI->DefineDlgPosition( this, x, y ) ;
205   this->move( x, y ) ;
206   this->show() ; /* displays Dialog */
207
208   return ;
209 }
210
211
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose  : Radio button management
215 //=================================================================================
216 void GeometryGUI_EdgeDlg::ConstructorsClicked(int constructorId)
217 {
218   switch (constructorId)
219     {
220     case 0:
221       { 
222         break;
223       }
224     }
225   return ;
226 }
227
228 //=================================================================================
229 // function : ClickOnOk()
230 // purpose  :
231 //=================================================================================
232 void GeometryGUI_EdgeDlg::ClickOnOk()
233 {
234   this->ClickOnApply() ;
235   this->ClickOnCancel() ;
236
237   return ;
238 }
239
240 //=================================================================================
241 // function : ClickOnApply()
242 // purpose  :
243 //=================================================================================
244 void GeometryGUI_EdgeDlg::ClickOnApply()
245 {
246   myGeomGUI->EraseSimulationShape() ;
247   mySimulationTopoDs.Nullify() ;
248   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
249   switch(myConstructorId)
250     { 
251     case 0 :
252       { 
253         if(myOkPoint1 && myOkPoint2) 
254           myGeomGUI->MakeLinearEdgeAndDisplay( myPoint1, myPoint2 ) ;
255         break ;
256       }
257     }
258   // accept();
259   return ;
260 }
261
262
263 //=================================================================================
264 // function : ClickOnCancel()
265 // purpose  :
266 //=================================================================================
267 void GeometryGUI_EdgeDlg::ClickOnCancel()
268 {
269   mySelection->ClearFilters() ;
270   myGeomGUI->EraseSimulationShape() ;
271   mySimulationTopoDs.Nullify() ;
272   disconnect( mySelection, 0, this, 0 );
273   myGeomGUI->ResetState() ;
274   reject() ;
275   return ;
276 }
277
278
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose  : Called when selection as changed or other case
282 //=================================================================================
283 void GeometryGUI_EdgeDlg::SelectionIntoArgument()
284 {
285   myEditCurrentArgument->setText("") ;
286   myGeomGUI->EraseSimulationShape() ; 
287   mySimulationTopoDs.Nullify() ;
288   
289   QString aString = ""; /* name of future selection */
290
291   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
292   if ( nbSel != 1 ) {
293     if ( myEditCurrentArgument == LineEditC1A1 ) {
294       myOkPoint1 = false ;
295     }
296     else if ( myEditCurrentArgument == LineEditC1A2 ) {
297       myOkPoint2 = false ;
298     }
299     return ;
300   }
301
302   // nbSel == 1 !
303   TopoDS_Shape S;
304   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
305     return ;
306
307   if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
308     myEditCurrentArgument->setText(aString) ;
309     myOkPoint1 = true ;
310   }
311   else if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint2)  ) {
312     myEditCurrentArgument->setText(aString) ;
313     myOkPoint2 = true ;
314   }
315   
316   if( myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion() ) {
317     mySimulationTopoDs = BRepBuilderAPI_MakeEdge( myPoint1, myPoint2 ).Shape();
318     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
319   } 
320   return ;
321 }
322
323 //=================================================================================
324 // function : LineEditReturnPressed()
325 // purpose  :
326 //=================================================================================
327 void GeometryGUI_EdgeDlg::LineEditReturnPressed()
328 {
329   QLineEdit* send = (QLineEdit*)sender();  
330   if( send == LineEditC1A1 )
331     myEditCurrentArgument = LineEditC1A1 ;
332   else if ( send == LineEditC1A2 )
333     myEditCurrentArgument = LineEditC1A2 ; 
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 //=================================================================================
351 // function : SetEditCurrentArgument()
352 // purpose  :
353 //=================================================================================
354 void GeometryGUI_EdgeDlg::SetEditCurrentArgument()
355 {
356   QPushButton* send = (QPushButton*)sender();
357   mySelection->ClearFilters() ;
358   switch (myConstructorId)
359     {
360     case 0: /* default constructor */
361       { 
362         if(send == SelectButtonC1A1) {
363           LineEditC1A1->setFocus() ;
364           myEditCurrentArgument = LineEditC1A1;   
365         }
366         else if(send == SelectButtonC1A2) {
367           LineEditC1A2->setFocus() ;      
368           myEditCurrentArgument = LineEditC1A2;
369         }       
370         mySelection->AddFilter(myVertexFilter) ;
371         SelectionIntoArgument() ;
372         break;
373       }
374     }
375   return ;
376 }
377
378
379 //=================================================================================
380 // function : DeactivateActiveDialog()
381 // purpose  :
382 //=================================================================================
383 void GeometryGUI_EdgeDlg::DeactivateActiveDialog()
384 {
385   if ( GroupConstructors->isEnabled() ) {
386
387     GroupConstructors->setEnabled(false) ;
388     GroupC1->setEnabled(false) ;
389     // TODO other constructors
390     // 
391     GroupButtons->setEnabled(false) ;
392     disconnect( mySelection, 0, this, 0 );
393     myGeomGUI->EraseSimulationShape() ;
394     mySelection->ClearFilters() ;
395   }
396   return ;
397 }
398
399
400 //=================================================================================
401 // function : ActivateThisDialog()
402 // purpose  :
403 //=================================================================================
404 void GeometryGUI_EdgeDlg::ActivateThisDialog()
405 {
406   /* Emit a signal to deactivate the active dialog */
407   myGeomGUI->EmitSignalDeactivateDialog() ; 
408   GroupConstructors->setEnabled(true) ;
409   GroupC1->setEnabled(true) ;
410   GroupButtons->setEnabled(true) ;
411
412   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
413   if( !mySimulationTopoDs.IsNull() )
414     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
415
416   return ;
417 }
418
419
420 //=================================================================================
421 // function : enterEvent()
422 // purpose  :
423 //=================================================================================
424 void GeometryGUI_EdgeDlg::enterEvent(QEvent* e)
425 {
426   if ( GroupConstructors->isEnabled() )
427     return ;  
428   ActivateThisDialog() ;
429   return ;
430 }
431
432
433 //=================================================================================
434 // function : closeEvent()
435 // purpose  :
436 //=================================================================================
437 void GeometryGUI_EdgeDlg::closeEvent( QCloseEvent* e )
438 {
439   /* same than click on cancel button */
440   this->ClickOnCancel() ;
441   return ;
442 }