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_WorkingPlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GeometryGUI_WorkingPlaneDlg.h"
31 #include "GeometryGUI.h"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "utilities.h"
36 #include <BRepAdaptor_Surface.hxx>
41 #include <qbuttongroup.h>
42 #include <qgroupbox.h>
44 #include <qlineedit.h>
45 #include <qpushbutton.h>
46 #include <qradiobutton.h>
50 #include <qwhatsthis.h>
54 //=================================================================================
55 // class : GeometryGUI_WorkingPlaneDlg()
56 // purpose : Constructs a GeometryGUI_WorkingPlaneDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 GeometryGUI_WorkingPlaneDlg::GeometryGUI_WorkingPlaneDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
62 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
64 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_WPLANE_FACE")));
65 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
68 setName( "GeometryGUI_WorkingPlaneDlg" );
70 setCaption( tr( "GEOM_WPLANE_TITLE" ) );
71 setSizeGripEnabled( TRUE );
72 GeometryGUI_WorkingPlaneDlgLayout = new QGridLayout( this );
73 GeometryGUI_WorkingPlaneDlgLayout->setSpacing( 6 );
74 GeometryGUI_WorkingPlaneDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_WPLANE" ) );
79 GroupConstructors->setExclusive( TRUE );
80 GroupConstructors->setColumnLayout(0, Qt::Vertical );
81 GroupConstructors->layout()->setSpacing( 0 );
82 GroupConstructors->layout()->setMargin( 0 );
83 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85 GroupConstructorsLayout->setSpacing( 6 );
86 GroupConstructorsLayout->setMargin( 11 );
87 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
88 Constructor1->setText( tr( "" ) );
89 Constructor1->setPixmap( image0 );
90 Constructor1->setChecked( TRUE );
91 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
92 Constructor1->setMinimumSize( QSize( 50, 0 ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupConstructorsLayout->addItem( spacer, 0, 1 );
96 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupButtons = new QGroupBox( this, "GroupButtons" );
100 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
101 GroupButtons->setTitle( tr( "" ) );
102 GroupButtons->setColumnLayout(0, Qt::Vertical );
103 GroupButtons->layout()->setSpacing( 0 );
104 GroupButtons->layout()->setMargin( 0 );
105 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106 GroupButtonsLayout->setAlignment( Qt::AlignTop );
107 GroupButtonsLayout->setSpacing( 6 );
108 GroupButtonsLayout->setMargin( 11 );
109 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
110 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
111 buttonCancel->setAutoDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
113 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
114 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
115 buttonApply->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
119 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
121 buttonOk->setAutoDefault( TRUE );
122 buttonOk->setDefault( TRUE );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupButtons, 2, 0 );
126 /***************************************************************/
127 GroupC1 = new QGroupBox( this, "GroupC1" );
128 GroupC1->setTitle( tr( "GEOM_WPLANE_FACE" ) );
129 GroupC1->setMinimumSize( QSize( 0, 0 ) );
130 GroupC1->setFrameShape( QGroupBox::Box );
131 GroupC1->setFrameShadow( QGroupBox::Sunken );
132 GroupC1->setColumnLayout(0, Qt::Vertical );
133 GroupC1->layout()->setSpacing( 0 );
134 GroupC1->layout()->setMargin( 0 );
135 GroupC1Layout = new QGridLayout( GroupC1->layout() );
136 GroupC1Layout->setAlignment( Qt::AlignTop );
137 GroupC1Layout->setSpacing( 6 );
138 GroupC1Layout->setMargin( 11 );
139 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
140 TextLabelC1A1->setText( tr( "GEOM_SELECTION" ) );
141 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
142 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
143 TextLabelC1A1->setFrameShadow( QLabel::Plain );
144 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
145 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
146 SelectButtonC1A1->setText( tr( "" ) );
147 SelectButtonC1A1->setPixmap( image1 );
148 SelectButtonC1A1->setToggleButton( FALSE );
149 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
150 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
151 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
152 GeometryGUI_WorkingPlaneDlgLayout->addWidget( GroupC1, 1, 0 );
153 /***************************************************************/
155 Init(Sel) ; /* Initialisations */
158 //=================================================================================
159 // function : ~GeometryGUI_WorkingPlaneDlg()
160 // purpose : Destroys the object and frees any allocated resources
161 //=================================================================================
162 GeometryGUI_WorkingPlaneDlg::~GeometryGUI_WorkingPlaneDlg()
164 // no need to delete child widgets, Qt does it all for us
168 //=================================================================================
171 //=================================================================================
172 void GeometryGUI_WorkingPlaneDlg::Init( SALOME_Selection* Sel )
176 myConstructorId = 0 ;
177 Constructor1->setChecked( TRUE );
178 myEditCurrentArgument = LineEditC1A1 ;
180 this->myOkPlane = false ;
181 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
182 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
184 // TODO : previous selection into argument ?
186 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
187 myGeom = GEOM::GEOM_Gen::_narrow(comp);
188 /* Filter definition */
189 myFaceFilter = new GEOM_FaceFilter( StdSelect_Plane, myGeom );
190 mySelection->AddFilter( myFaceFilter ); /* filter for next selection */
192 /* signals and slots connections */
193 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
194 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
195 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
196 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
198 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
200 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
201 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
202 /* to close dialog if study change */
203 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
205 /* Move widget on the botton right corner of main widget */
207 myGeomGUI->DefineDlgPosition( this, x, y ) ;
209 this->show() ; /* displays Dialog */
215 //=================================================================================
216 // function : ConstructorsClicked()
217 // purpose : Radio button management
218 //=================================================================================
219 void GeometryGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
224 //=================================================================================
225 // function : ClickOnOk()
227 //=================================================================================
228 void GeometryGUI_WorkingPlaneDlg::ClickOnOk()
230 this->ClickOnApply() ;
231 this->ClickOnCancel() ;
236 //=================================================================================
237 // function : ClickOnApply()
239 //=================================================================================
240 void GeometryGUI_WorkingPlaneDlg::ClickOnApply()
242 mySelection->ClearFilters() ;
243 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
244 switch(myConstructorId)
249 myGeomGUI->MakeWorkingPlane( this->myLoc, this->myDir ) ;
259 //=================================================================================
260 // function : ClickOnCancel()
262 //=================================================================================
263 void GeometryGUI_WorkingPlaneDlg::ClickOnCancel()
265 mySelection->ClearFilters() ;
266 disconnect( mySelection, 0, this, 0 );
267 myGeomGUI->ResetState() ;
273 //=================================================================================
274 // function : SelectionIntoArgument()
275 // purpose : Called when selection as changed or other case
276 //=================================================================================
277 void GeometryGUI_WorkingPlaneDlg::SelectionIntoArgument()
279 /* All this for first constructor */
280 // if(myEditCurrentArgument == LineEditC1A1 )
282 myEditCurrentArgument->setText("") ;
283 QString aString = ""; /* future the name of selection */
285 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
287 switch (myConstructorId)
291 if ( myEditCurrentArgument == LineEditC1A1 ) {
302 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
305 if ( myEditCurrentArgument == LineEditC1A1 ) {
306 BRepAdaptor_Surface surf(TopoDS::Face(S));
307 gp_Pln Plane = surf.Plane();
308 myLoc = Plane.Location();
309 myDir = Plane.Axis().Direction();
311 LineEditC1A1->setText(aString) ;
320 //=================================================================================
321 // function : SetEditCurrentArgument()
323 //=================================================================================
324 void GeometryGUI_WorkingPlaneDlg::SetEditCurrentArgument()
326 QPushButton* send = (QPushButton*)sender();
327 switch (myConstructorId)
329 case 0: /* default constructor */
331 if(send == SelectButtonC1A1) {
332 LineEditC1A1->setFocus() ;
333 myEditCurrentArgument = LineEditC1A1;
335 mySelection->AddFilter(myFaceFilter) ;
336 SelectionIntoArgument() ;
345 //=================================================================================
346 // function : LineEditReturnPressed()
348 //=================================================================================
349 void GeometryGUI_WorkingPlaneDlg::LineEditReturnPressed()
351 QLineEdit* send = (QLineEdit*)sender();
352 if( send == LineEditC1A1 )
353 myEditCurrentArgument = LineEditC1A1 ;
356 /* User name of object input management */
357 /* If successfull the selection is changed and signal emitted... */
358 /* so SelectionIntoArgument() is automatically called. */
359 const QString objectUserName = myEditCurrentArgument->text() ;
360 QWidget* thisWidget = (QWidget*)this ;
361 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
362 myEditCurrentArgument->setText( objectUserName ) ;
368 //=================================================================================
369 // function : DeactivateActiveDialog()
371 //=================================================================================
372 void GeometryGUI_WorkingPlaneDlg::DeactivateActiveDialog()
374 if ( GroupConstructors->isEnabled() ) {
375 mySelection->ClearFilters() ;
376 disconnect( mySelection, 0, this, 0 );
377 GroupConstructors->setEnabled(false) ;
378 GroupC1->setEnabled(false) ;
379 GroupButtons->setEnabled(false) ;
385 //=================================================================================
386 // function : ActivateThisDialog()
388 //=================================================================================
389 void GeometryGUI_WorkingPlaneDlg::ActivateThisDialog()
391 /* Emit a signal to deactivate the active dialog */
392 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
393 myGeomGUI->EmitSignalDeactivateDialog() ;
394 GroupConstructors->setEnabled(true) ;
395 GroupC1->setEnabled(true) ;
396 GroupButtons->setEnabled(true) ;
401 //=================================================================================
402 // function : enterEvent()
404 //=================================================================================
405 void GeometryGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
407 if ( GroupConstructors->isEnabled() )
409 ActivateThisDialog() ;
414 //=================================================================================
415 // function : closeEvent()
417 //=================================================================================
418 void GeometryGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
420 /* same than click on cancel button */
421 this->ClickOnCancel() ;