2 // File : GeometryGUI_EdgeDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_EdgeDlg.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>
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 )
42 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_BUILD_EDGE")));
43 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
46 setName( "GeometryGUI_EdgeDlg" );
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 );
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 );
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 );
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 /***************************************************************/
143 Init(Sel) ; /* Initialisations */
147 //=================================================================================
148 // function : ~GeometryGUI_EdgeDlg()
149 // purpose : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_EdgeDlg::~GeometryGUI_EdgeDlg()
153 // no need to delete child widgets, Qt does it all for us
157 //=================================================================================
160 //=================================================================================
161 void GeometryGUI_EdgeDlg::Init( SALOME_Selection* Sel )
167 myConstructorId = 0 ;
168 Constructor1->setChecked( TRUE );
169 myEditCurrentArgument = LineEditC1A1 ;
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 ) ;
178 // TODO : previous selection into argument ?
180 /* Filters definition */
181 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
182 myGeom = GEOM::GEOM_Gen::_narrow(comp);
183 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
184 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
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() ) ) ;
194 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
195 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
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() ) ) ;
202 /* Move widget on the botton right corner of main widget */
204 myGeomGUI->DefineDlgPosition( this, x, y ) ;
206 this->show() ; /* displays Dialog */
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose : Radio button management
215 //=================================================================================
216 void GeometryGUI_EdgeDlg::ConstructorsClicked(int constructorId)
218 switch (constructorId)
228 //=================================================================================
229 // function : ClickOnOk()
231 //=================================================================================
232 void GeometryGUI_EdgeDlg::ClickOnOk()
234 this->ClickOnApply() ;
235 this->ClickOnCancel() ;
240 //=================================================================================
241 // function : ClickOnApply()
243 //=================================================================================
244 void GeometryGUI_EdgeDlg::ClickOnApply()
246 myGeomGUI->EraseSimulationShape() ;
247 mySimulationTopoDs.Nullify() ;
248 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
249 switch(myConstructorId)
253 if(myOkPoint1 && myOkPoint2)
254 myGeomGUI->MakeLinearEdgeAndDisplay( myPoint1, myPoint2 ) ;
263 //=================================================================================
264 // function : ClickOnCancel()
266 //=================================================================================
267 void GeometryGUI_EdgeDlg::ClickOnCancel()
269 mySelection->ClearFilters() ;
270 myGeomGUI->EraseSimulationShape() ;
271 mySimulationTopoDs.Nullify() ;
272 disconnect( mySelection, 0, this, 0 );
273 myGeomGUI->ResetState() ;
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose : Called when selection as changed or other case
282 //=================================================================================
283 void GeometryGUI_EdgeDlg::SelectionIntoArgument()
285 myEditCurrentArgument->setText("") ;
286 myGeomGUI->EraseSimulationShape() ;
287 mySimulationTopoDs.Nullify() ;
289 QString aString = ""; /* name of future selection */
291 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
293 if ( myEditCurrentArgument == LineEditC1A1 ) {
296 else if ( myEditCurrentArgument == LineEditC1A2 ) {
304 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
307 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
308 myEditCurrentArgument->setText(aString) ;
311 else if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint2) ) {
312 myEditCurrentArgument->setText(aString) ;
316 if( myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion() ) {
317 mySimulationTopoDs = BRepBuilderAPI_MakeEdge( myPoint1, myPoint2 ).Shape();
318 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
323 //=================================================================================
324 // function : LineEditReturnPressed()
326 //=================================================================================
327 void GeometryGUI_EdgeDlg::LineEditReturnPressed()
329 QLineEdit* send = (QLineEdit*)sender();
330 if( send == LineEditC1A1 )
331 myEditCurrentArgument = LineEditC1A1 ;
332 else if ( send == LineEditC1A2 )
333 myEditCurrentArgument = LineEditC1A2 ;
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 ) ;
350 //=================================================================================
351 // function : SetEditCurrentArgument()
353 //=================================================================================
354 void GeometryGUI_EdgeDlg::SetEditCurrentArgument()
356 QPushButton* send = (QPushButton*)sender();
357 mySelection->ClearFilters() ;
358 switch (myConstructorId)
360 case 0: /* default constructor */
362 if(send == SelectButtonC1A1) {
363 LineEditC1A1->setFocus() ;
364 myEditCurrentArgument = LineEditC1A1;
366 else if(send == SelectButtonC1A2) {
367 LineEditC1A2->setFocus() ;
368 myEditCurrentArgument = LineEditC1A2;
370 mySelection->AddFilter(myVertexFilter) ;
371 SelectionIntoArgument() ;
379 //=================================================================================
380 // function : DeactivateActiveDialog()
382 //=================================================================================
383 void GeometryGUI_EdgeDlg::DeactivateActiveDialog()
385 if ( GroupConstructors->isEnabled() ) {
387 GroupConstructors->setEnabled(false) ;
388 GroupC1->setEnabled(false) ;
389 // TODO other constructors
391 GroupButtons->setEnabled(false) ;
392 disconnect( mySelection, 0, this, 0 );
393 myGeomGUI->EraseSimulationShape() ;
394 mySelection->ClearFilters() ;
400 //=================================================================================
401 // function : ActivateThisDialog()
403 //=================================================================================
404 void GeometryGUI_EdgeDlg::ActivateThisDialog()
406 /* Emit a signal to deactivate the active dialog */
407 myGeomGUI->EmitSignalDeactivateDialog() ;
408 GroupConstructors->setEnabled(true) ;
409 GroupC1->setEnabled(true) ;
410 GroupButtons->setEnabled(true) ;
412 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
413 if( !mySimulationTopoDs.IsNull() )
414 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
420 //=================================================================================
421 // function : enterEvent()
423 //=================================================================================
424 void GeometryGUI_EdgeDlg::enterEvent(QEvent* e)
426 if ( GroupConstructors->isEnabled() )
428 ActivateThisDialog() ;
433 //=================================================================================
434 // function : closeEvent()
436 //=================================================================================
437 void GeometryGUI_EdgeDlg::closeEvent( QCloseEvent* e )
439 /* same than click on cancel button */
440 this->ClickOnCancel() ;