1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_EdgeDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_EdgeDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
46 #include <qwhatsthis.h>
52 //=================================================================================
53 // class : GeometryGUI_EdgeDlg()
54 // purpose : Constructs a GeometryGUI_EdgeDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 GeometryGUI_EdgeDlg::GeometryGUI_EdgeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
60 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
62 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_BUILD_EDGE")));
63 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
66 setName( "GeometryGUI_EdgeDlg" );
68 setCaption( tr( "GEOM_EDGE_TITLE" ) );
69 setSizeGripEnabled( TRUE );
70 GeometryGUI_EdgeDlgLayout = new QGridLayout( this );
71 GeometryGUI_EdgeDlgLayout->setSpacing( 6 );
72 GeometryGUI_EdgeDlgLayout->setMargin( 11 );
74 /***************************************************************/
75 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
76 GroupConstructors->setTitle( tr( "GEOM_EDGE" ) );
77 GroupConstructors->setExclusive( TRUE );
78 GroupConstructors->setColumnLayout(0, Qt::Vertical );
79 GroupConstructors->layout()->setSpacing( 0 );
80 GroupConstructors->layout()->setMargin( 0 );
81 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
82 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
83 GroupConstructorsLayout->setSpacing( 6 );
84 GroupConstructorsLayout->setMargin( 11 );
85 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
86 Constructor1->setText( tr( "" ) );
87 Constructor1->setPixmap( image0 );
88 Constructor1->setChecked( TRUE );
89 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
90 Constructor1->setMinimumSize( QSize( 50, 0 ) );
91 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
92 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
93 GroupConstructorsLayout->addItem( spacer, 0, 1 );
94 GeometryGUI_EdgeDlgLayout->addWidget( GroupConstructors, 0, 0 );
96 /***************************************************************/
97 GroupC1 = new QGroupBox( this, "GroupC1" );
98 GroupC1->setTitle( tr( "GEOM_POINTS" ) );
99 GroupC1->setMinimumSize( QSize( 0, 0 ) );
100 GroupC1->setFrameShape( QGroupBox::Box );
101 GroupC1->setFrameShadow( QGroupBox::Sunken );
102 GroupC1->setColumnLayout(0, Qt::Vertical );
103 GroupC1->layout()->setSpacing( 0 );
104 GroupC1->layout()->setMargin( 0 );
105 GroupC1Layout = new QGridLayout( GroupC1->layout() );
106 GroupC1Layout->setAlignment( Qt::AlignTop );
107 GroupC1Layout->setSpacing( 6 );
108 GroupC1Layout->setMargin( 11 );
109 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
110 SelectButtonC1A2->setText( tr( "" ) );
111 SelectButtonC1A2->setPixmap( image1 );
112 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
113 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
114 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
115 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
116 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
117 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
118 SelectButtonC1A1->setText( tr( "" ) );
119 SelectButtonC1A1->setPixmap( image1 );
120 SelectButtonC1A1->setToggleButton( FALSE );
121 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
122 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
123 TextLabelC1A1->setText( tr( "GEOM_POINT_I" ).arg("1") );
124 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
125 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
126 TextLabelC1A1->setFrameShadow( QLabel::Plain );
127 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
128 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
129 TextLabelC1A2->setText( tr( "GEOM_POINT_I" ).arg("2") );
130 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
131 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
132 GeometryGUI_EdgeDlgLayout->addWidget( GroupC1, 1, 0 );
134 /***************************************************************/
135 GroupButtons = new QGroupBox( this, "GroupButtons" );
136 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
137 GroupButtons->setTitle( tr( "" ) );
138 GroupButtons->setColumnLayout(0, Qt::Vertical );
139 GroupButtons->layout()->setSpacing( 0 );
140 GroupButtons->layout()->setMargin( 0 );
141 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
142 GroupButtonsLayout->setAlignment( Qt::AlignTop );
143 GroupButtonsLayout->setSpacing( 6 );
144 GroupButtonsLayout->setMargin( 11 );
145 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
146 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
147 buttonCancel->setAutoDefault( TRUE );
148 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
149 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
150 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
151 buttonApply->setAutoDefault( TRUE );
152 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
153 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
154 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
155 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
156 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
157 buttonOk->setAutoDefault( TRUE );
158 buttonOk->setDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
160 GeometryGUI_EdgeDlgLayout->addWidget( GroupButtons, 2, 0 );
161 /***************************************************************/
163 Init(Sel) ; /* Initialisations */
167 //=================================================================================
168 // function : ~GeometryGUI_EdgeDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 GeometryGUI_EdgeDlg::~GeometryGUI_EdgeDlg()
173 // no need to delete child widgets, Qt does it all for us
177 //=================================================================================
180 //=================================================================================
181 void GeometryGUI_EdgeDlg::Init( SALOME_Selection* Sel )
187 myConstructorId = 0 ;
188 Constructor1->setChecked( TRUE );
189 myEditCurrentArgument = LineEditC1A1 ;
191 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
192 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
193 myPoint2.SetCoord( 0.0, 0.0, 0.0 );
194 myOkPoint1 = myOkPoint2 = false ;
195 mySimulationTopoDs.Nullify() ;
196 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
198 // TODO : previous selection into argument ?
200 /* Filters definition */
201 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
202 myGeom = GEOM::GEOM_Gen::_narrow(comp);
203 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
204 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
206 /* signals and slots connections */
207 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
208 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
209 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
210 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
211 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
212 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
214 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
215 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
217 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
218 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
219 /* to close dialog if study change */
220 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
222 /* Move widget on the botton right corner of main widget */
224 myGeomGUI->DefineDlgPosition( this, x, y ) ;
226 this->show() ; /* displays Dialog */
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void GeometryGUI_EdgeDlg::ConstructorsClicked(int constructorId)
238 switch (constructorId)
248 //=================================================================================
249 // function : ClickOnOk()
251 //=================================================================================
252 void GeometryGUI_EdgeDlg::ClickOnOk()
254 this->ClickOnApply() ;
255 this->ClickOnCancel() ;
260 //=================================================================================
261 // function : ClickOnApply()
263 //=================================================================================
264 void GeometryGUI_EdgeDlg::ClickOnApply()
266 myGeomGUI->EraseSimulationShape() ;
267 mySimulationTopoDs.Nullify() ;
268 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
269 switch(myConstructorId)
273 if(myOkPoint1 && myOkPoint2)
274 myGeomGUI->MakeLinearEdgeAndDisplay( myPoint1, myPoint2 ) ;
283 //=================================================================================
284 // function : ClickOnCancel()
286 //=================================================================================
287 void GeometryGUI_EdgeDlg::ClickOnCancel()
289 mySelection->ClearFilters() ;
290 myGeomGUI->EraseSimulationShape() ;
291 mySimulationTopoDs.Nullify() ;
292 disconnect( mySelection, 0, this, 0 );
293 myGeomGUI->ResetState() ;
299 //=================================================================================
300 // function : SelectionIntoArgument()
301 // purpose : Called when selection as changed or other case
302 //=================================================================================
303 void GeometryGUI_EdgeDlg::SelectionIntoArgument()
305 myEditCurrentArgument->setText("") ;
306 myGeomGUI->EraseSimulationShape() ;
307 mySimulationTopoDs.Nullify() ;
309 QString aString = ""; /* name of future selection */
311 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
313 if ( myEditCurrentArgument == LineEditC1A1 ) {
316 else if ( myEditCurrentArgument == LineEditC1A2 ) {
324 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
327 if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
328 myEditCurrentArgument->setText(aString) ;
331 else if ( myConstructorId == 0 && myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint2) ) {
332 myEditCurrentArgument->setText(aString) ;
336 if( myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion() ) {
337 mySimulationTopoDs = BRepBuilderAPI_MakeEdge( myPoint1, myPoint2 ).Shape();
338 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
343 //=================================================================================
344 // function : LineEditReturnPressed()
346 //=================================================================================
347 void GeometryGUI_EdgeDlg::LineEditReturnPressed()
349 QLineEdit* send = (QLineEdit*)sender();
350 if( send == LineEditC1A1 )
351 myEditCurrentArgument = LineEditC1A1 ;
352 else if ( send == LineEditC1A2 )
353 myEditCurrentArgument = LineEditC1A2 ;
357 /* User name of object input management */
358 /* If successfull the selection is changed and signal emitted... */
359 /* so SelectionIntoArgument() is automatically called. */
360 const QString objectUserName = myEditCurrentArgument->text() ;
361 QWidget* thisWidget = (QWidget*)this ;
362 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
363 myEditCurrentArgument->setText( objectUserName ) ;
370 //=================================================================================
371 // function : SetEditCurrentArgument()
373 //=================================================================================
374 void GeometryGUI_EdgeDlg::SetEditCurrentArgument()
376 QPushButton* send = (QPushButton*)sender();
377 mySelection->ClearFilters() ;
378 switch (myConstructorId)
380 case 0: /* default constructor */
382 if(send == SelectButtonC1A1) {
383 LineEditC1A1->setFocus() ;
384 myEditCurrentArgument = LineEditC1A1;
386 else if(send == SelectButtonC1A2) {
387 LineEditC1A2->setFocus() ;
388 myEditCurrentArgument = LineEditC1A2;
390 mySelection->AddFilter(myVertexFilter) ;
391 SelectionIntoArgument() ;
399 //=================================================================================
400 // function : DeactivateActiveDialog()
402 //=================================================================================
403 void GeometryGUI_EdgeDlg::DeactivateActiveDialog()
405 if ( GroupConstructors->isEnabled() ) {
407 GroupConstructors->setEnabled(false) ;
408 GroupC1->setEnabled(false) ;
409 // TODO other constructors
411 GroupButtons->setEnabled(false) ;
412 disconnect( mySelection, 0, this, 0 );
413 myGeomGUI->EraseSimulationShape() ;
414 mySelection->ClearFilters() ;
420 //=================================================================================
421 // function : ActivateThisDialog()
423 //=================================================================================
424 void GeometryGUI_EdgeDlg::ActivateThisDialog()
426 /* Emit a signal to deactivate the active dialog */
427 myGeomGUI->EmitSignalDeactivateDialog() ;
428 GroupConstructors->setEnabled(true) ;
429 GroupC1->setEnabled(true) ;
430 GroupButtons->setEnabled(true) ;
432 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
433 if( !mySimulationTopoDs.IsNull() )
434 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
440 //=================================================================================
441 // function : enterEvent()
443 //=================================================================================
444 void GeometryGUI_EdgeDlg::enterEvent(QEvent* e)
446 if ( GroupConstructors->isEnabled() )
448 ActivateThisDialog() ;
453 //=================================================================================
454 // function : closeEvent()
456 //=================================================================================
457 void GeometryGUI_EdgeDlg::closeEvent( QCloseEvent* e )
459 /* same than click on cancel button */
460 this->ClickOnCancel() ;