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