Salome HOME
NRI : First integration.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_WireDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_WireDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10 #include "GeometryGUI_WireDlg.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 // class    : GeometryGUI_WireDlg()
33 // purpose  : Constructs a GeometryGUI_WireDlg which is a child of 'parent', with the 
34 //            name 'name' and widget flags set to 'f'.
35 //            The dialog will by default be modeless, unless you set 'modal' to
36 //            TRUE to construct a modal dialog.
37 //=================================================================================
38 GeometryGUI_WireDlg::GeometryGUI_WireDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
39     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
40 {
41     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BUILD_WIRE")));
42     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
43
44     if ( !name )
45         setName( "GeometryGUI_WireDlg" );
46     resize( 303, 185 ); 
47     setCaption( tr( "GEOM_WIRE_TITLE"  ) );
48     setSizeGripEnabled( TRUE );
49     GeometryGUI_WireDlgLayout = new QGridLayout( this ); 
50     GeometryGUI_WireDlgLayout->setSpacing( 6 );
51     GeometryGUI_WireDlgLayout->setMargin( 11 );
52
53     /***************************************************************/
54     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
55     GroupConstructors->setTitle( tr( "GEOM_WIRE"  ) );
56     GroupConstructors->setExclusive( TRUE );
57     GroupConstructors->setColumnLayout(0, Qt::Vertical );
58     GroupConstructors->layout()->setSpacing( 0 );
59     GroupConstructors->layout()->setMargin( 0 );
60     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
61     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
62     GroupConstructorsLayout->setSpacing( 6 );
63     GroupConstructorsLayout->setMargin( 11 );
64     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
65     Constructor1->setText( tr( ""  ) );
66     Constructor1->setPixmap( image0 );
67     Constructor1->setChecked( TRUE );
68     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
69     Constructor1->setMinimumSize( QSize( 50, 0 ) );
70     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
71     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
72     GroupConstructorsLayout->addItem( spacer, 0, 1 );
73     GeometryGUI_WireDlgLayout->addWidget( GroupConstructors, 0, 0 );
74     
75     /***************************************************************/
76     GroupButtons = new QGroupBox( this, "GroupButtons" );
77     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
78     GroupButtons->setTitle( tr( ""  ) );
79     GroupButtons->setColumnLayout(0, Qt::Vertical );
80     GroupButtons->layout()->setSpacing( 0 );
81     GroupButtons->layout()->setMargin( 0 );
82     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
83     GroupButtonsLayout->setAlignment( Qt::AlignTop );
84     GroupButtonsLayout->setSpacing( 6 );
85     GroupButtonsLayout->setMargin( 11 );
86     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
87     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
88     buttonCancel->setAutoDefault( TRUE );
89     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
90     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
91     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
92     buttonApply->setAutoDefault( TRUE );
93     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
94     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
96     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
97     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
98     buttonOk->setAutoDefault( TRUE );
99     buttonOk->setDefault( TRUE );
100     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
101     GeometryGUI_WireDlgLayout->addWidget( GroupButtons, 2, 0 );
102
103     /***************************************************************/
104     GroupC1 = new QGroupBox( this, "GroupC1" );
105     GroupC1->setTitle( tr( "GEOM_WIRE_CONNECT"  ) );
106     GroupC1->setMinimumSize( QSize( 0, 0 ) );
107     GroupC1->setFrameShape( QGroupBox::Box );
108     GroupC1->setFrameShadow( QGroupBox::Sunken );
109     GroupC1->setColumnLayout(0, Qt::Vertical );
110     GroupC1->layout()->setSpacing( 0 );
111     GroupC1->layout()->setMargin( 0 );
112     GroupC1Layout = new QGridLayout( GroupC1->layout() );
113     GroupC1Layout->setAlignment( Qt::AlignTop );
114     GroupC1Layout->setSpacing( 6 );
115     GroupC1Layout->setMargin( 11 );
116     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
117     TextLabelC1A1->setText( tr( "GEOM_OBJECTS"  ) );
118     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
119     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
120     TextLabelC1A1->setFrameShadow( QLabel::Plain );
121     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
122     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
123     SelectButtonC1A1->setText( tr( ""  ) );
124     SelectButtonC1A1->setPixmap( image1 );
125     SelectButtonC1A1->setToggleButton( FALSE );
126     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
127     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
128     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
129     GeometryGUI_WireDlgLayout->addWidget( GroupC1, 1, 0 );
130
131     Init(Sel) ; /* Initialisations */
132 }
133
134 //=================================================================================
135 // function : ~GeometryGUI_WireDlg()
136 // purpose  : Destroys the object and frees any allocated resources
137 //=================================================================================
138 GeometryGUI_WireDlg::~GeometryGUI_WireDlg()
139 {
140     // no need to delete child widgets, Qt does it all for us
141 }
142
143
144 //=================================================================================
145 // function : Init()
146 // purpose  :
147 //=================================================================================
148 void GeometryGUI_WireDlg::Init( SALOME_Selection* Sel )
149 {
150
151   GroupC1->show();
152   myConstructorId = 0 ;
153   Constructor1->setChecked( TRUE );
154   myEditCurrentArgument = LineEditC1A1 ;        
155   mySelection = Sel;  
156   this->myOkListShapes = false ;
157   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
158   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
159
160   // TODO : previous selection into argument
161
162   /* Filter definitions */
163   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
164   myGeom = GEOM::GEOM_Gen::_narrow(comp);
165
166   /* signals and slots connections */
167   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
168   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
169   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
170   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
171
172   connect( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
173   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
174   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
175   /* to close dialog if study change */
176   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
177
178   /* Move widget on the botton right corner of main widget */
179   int x, y ;
180   myGeomGUI->DefineDlgPosition( this, x, y ) ;
181   this->move( x, y ) ;
182   this->show() ; /* displays Dialog */
183
184   return ;
185 }
186
187
188 //=================================================================================
189 // function : ConstructorsClicked()
190 // purpose  : Radio button management
191 //=================================================================================
192 void GeometryGUI_WireDlg::ConstructorsClicked(int constructorId)
193 {
194   return ;
195 }
196
197
198 //=================================================================================
199 // function : ClickOnApply()
200 // purpose  :
201 //=================================================================================
202 void GeometryGUI_WireDlg::ClickOnApply()
203 {
204   switch(myConstructorId)
205     { 
206     case 0 :
207       { 
208         if(myOkListShapes) {      
209           myGeomGUI->MakeWireAndDisplay( myListShapes ) ;
210         }
211         break ;
212       }
213     }
214   // accept();
215   return ;
216 }
217
218 //=================================================================================
219 // function : ClickOnOk()
220 // purpose  :
221 //=================================================================================
222 void GeometryGUI_WireDlg::ClickOnOk()
223 {
224   this->ClickOnApply() ;
225   this->ClickOnCancel() ;
226
227   return ;
228 }
229
230 //=================================================================================
231 // function : ClickOnCancel()
232 // purpose  :
233 //=================================================================================
234 void GeometryGUI_WireDlg::ClickOnCancel()
235 {
236   myGeomGUI->ResetState() ;
237   reject() ;
238   return ;
239 }
240
241
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose  : Called when selection as changed or other case
245 //=================================================================================
246 void GeometryGUI_WireDlg::SelectionIntoArgument()
247 {
248   /* All this for first constructor */
249   // if(myEditCurrentArgument == LineEditC1A1 )
250
251   myEditCurrentArgument->setText("") ;
252   myOkListShapes = false;
253   QString aString = ""; /* Future name of selection */
254
255   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
256   if(nbSel < 1)
257     return ;
258   
259   myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
260   myEditCurrentArgument->setText(aString) ;
261   myOkListShapes = true ;
262   /* no simulation */
263   return ;
264 }
265
266
267 //=================================================================================
268 // function : SetEditCurrentArgument()
269 // purpose  :
270 //=================================================================================
271 void GeometryGUI_WireDlg::SetEditCurrentArgument()
272 {
273   QPushButton* send = (QPushButton*)sender();
274   switch (myConstructorId)
275     {
276     case 0: /* default constructor */
277       { 
278         if(send == SelectButtonC1A1) {
279           LineEditC1A1->setFocus() ;
280           myEditCurrentArgument = LineEditC1A1;
281         }
282         SelectionIntoArgument() ;
283         break;
284       }
285     }
286   return ;
287 }
288
289
290
291 //=================================================================================
292 // function : LineEditReturnPressed()
293 // purpose  :
294 //=================================================================================
295 void GeometryGUI_WireDlg::LineEditReturnPressed()
296 {
297   return ;
298 }
299
300
301 //=================================================================================
302 // function : DeactivateActiveDialog()
303 // purpose  :
304 //=================================================================================
305 void GeometryGUI_WireDlg::DeactivateActiveDialog()
306 {
307   if ( GroupConstructors->isEnabled() ) {
308     GroupConstructors->setEnabled(false) ;
309     GroupC1->setEnabled(false) ;
310     GroupButtons->setEnabled(false) ;
311   }
312   return ;
313 }
314
315
316 //=================================================================================
317 // function : ActivateThisDialog()
318 // purpose  :
319 //=================================================================================
320 void GeometryGUI_WireDlg::ActivateThisDialog()
321 {
322   /* Emit a signal to deactivate the active dialog */
323   myGeomGUI->EmitSignalDeactivateDialog() ;   
324   GroupConstructors->setEnabled(true) ;
325   GroupC1->setEnabled(true) ;
326   GroupButtons->setEnabled(true) ;
327   return ;
328 }
329
330
331 //=================================================================================
332 // function : enterEvent()
333 // purpose  :
334 //=================================================================================
335 void GeometryGUI_WireDlg::enterEvent(QEvent* e)
336 {
337   if ( GroupConstructors->isEnabled() )
338     return ;  
339   ActivateThisDialog() ;
340   return ;
341 }
342
343
344 //=================================================================================
345 // function : closeEvent()
346 // purpose  :
347 //=================================================================================
348 void GeometryGUI_WireDlg::closeEvent( QCloseEvent* e )
349 {
350   /* same than click on cancel button */
351   this->ClickOnCancel() ;
352   return ;
353 }
354
355