2 // File : GeometryGUI_WireDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_WireDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
26 #include <qwhatsthis.h>
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 )
41 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BUILD_WIRE")));
42 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
45 setName( "GeometryGUI_WireDlg" );
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 );
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 );
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 );
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 );
131 Init(Sel) ; /* Initialisations */
134 //=================================================================================
135 // function : ~GeometryGUI_WireDlg()
136 // purpose : Destroys the object and frees any allocated resources
137 //=================================================================================
138 GeometryGUI_WireDlg::~GeometryGUI_WireDlg()
140 // no need to delete child widgets, Qt does it all for us
144 //=================================================================================
147 //=================================================================================
148 void GeometryGUI_WireDlg::Init( SALOME_Selection* Sel )
152 myConstructorId = 0 ;
153 Constructor1->setChecked( TRUE );
154 myEditCurrentArgument = LineEditC1A1 ;
156 this->myOkListShapes = false ;
157 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
158 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
160 // TODO : previous selection into argument
162 /* Filter definitions */
163 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
164 myGeom = GEOM::GEOM_Gen::_narrow(comp);
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) ) );
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() ) ) ;
178 /* Move widget on the botton right corner of main widget */
180 myGeomGUI->DefineDlgPosition( this, x, y ) ;
182 this->show() ; /* displays Dialog */
188 //=================================================================================
189 // function : ConstructorsClicked()
190 // purpose : Radio button management
191 //=================================================================================
192 void GeometryGUI_WireDlg::ConstructorsClicked(int constructorId)
198 //=================================================================================
199 // function : ClickOnApply()
201 //=================================================================================
202 void GeometryGUI_WireDlg::ClickOnApply()
204 switch(myConstructorId)
209 myGeomGUI->MakeWireAndDisplay( myListShapes ) ;
218 //=================================================================================
219 // function : ClickOnOk()
221 //=================================================================================
222 void GeometryGUI_WireDlg::ClickOnOk()
224 this->ClickOnApply() ;
225 this->ClickOnCancel() ;
230 //=================================================================================
231 // function : ClickOnCancel()
233 //=================================================================================
234 void GeometryGUI_WireDlg::ClickOnCancel()
236 myGeomGUI->ResetState() ;
242 //=================================================================================
243 // function : SelectionIntoArgument()
244 // purpose : Called when selection as changed or other case
245 //=================================================================================
246 void GeometryGUI_WireDlg::SelectionIntoArgument()
248 /* All this for first constructor */
249 // if(myEditCurrentArgument == LineEditC1A1 )
251 myEditCurrentArgument->setText("") ;
252 myOkListShapes = false;
253 QString aString = ""; /* Future name of selection */
255 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
259 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
260 myEditCurrentArgument->setText(aString) ;
261 myOkListShapes = true ;
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void GeometryGUI_WireDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
274 switch (myConstructorId)
276 case 0: /* default constructor */
278 if(send == SelectButtonC1A1) {
279 LineEditC1A1->setFocus() ;
280 myEditCurrentArgument = LineEditC1A1;
282 SelectionIntoArgument() ;
291 //=================================================================================
292 // function : LineEditReturnPressed()
294 //=================================================================================
295 void GeometryGUI_WireDlg::LineEditReturnPressed()
301 //=================================================================================
302 // function : DeactivateActiveDialog()
304 //=================================================================================
305 void GeometryGUI_WireDlg::DeactivateActiveDialog()
307 if ( GroupConstructors->isEnabled() ) {
308 GroupConstructors->setEnabled(false) ;
309 GroupC1->setEnabled(false) ;
310 GroupButtons->setEnabled(false) ;
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void GeometryGUI_WireDlg::ActivateThisDialog()
322 /* Emit a signal to deactivate the active dialog */
323 myGeomGUI->EmitSignalDeactivateDialog() ;
324 GroupConstructors->setEnabled(true) ;
325 GroupC1->setEnabled(true) ;
326 GroupButtons->setEnabled(true) ;
331 //=================================================================================
332 // function : enterEvent()
334 //=================================================================================
335 void GeometryGUI_WireDlg::enterEvent(QEvent* e)
337 if ( GroupConstructors->isEnabled() )
339 ActivateThisDialog() ;
344 //=================================================================================
345 // function : closeEvent()
347 //=================================================================================
348 void GeometryGUI_WireDlg::closeEvent( QCloseEvent* e )
350 /* same than click on cancel button */
351 this->ClickOnCancel() ;