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_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_ScaleDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <BRepBuilderAPI_Transform.hxx>
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
48 #include <qwhatsthis.h>
50 #include <qvalidator.h>
54 //=================================================================================
55 // class : GeometryGUI_ScaleDlg()
56 // purpose : Constructs a GeometryGUI_ScaleDlg 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_ScaleDlg::GeometryGUI_ScaleDlg( 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( "GEOM",tr("ICON_DLG_SCALE")));
65 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
68 setName( "GeometryGUI_ScaleDlg" );
70 setCaption( tr( "GEOM_SCALE_TITLE" ) );
71 setSizeGripEnabled( TRUE );
72 GeometryGUI_ScaleDlgLayout = new QGridLayout( this );
73 GeometryGUI_ScaleDlgLayout->setSpacing( 6 );
74 GeometryGUI_ScaleDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_SCALE" ) );
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 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
88 GroupConstructorsLayout->addItem( spacer, 0, 1 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
94 Constructor1->setMinimumSize( QSize( 50, 0 ) );
95 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
96 GeometryGUI_ScaleDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupC1 = new QGroupBox( this, "GroupC1" );
100 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
101 GroupC1->setColumnLayout(0, Qt::Vertical );
102 GroupC1->layout()->setSpacing( 0 );
103 GroupC1->layout()->setMargin( 0 );
104 GroupC1Layout = new QGridLayout( GroupC1->layout() );
105 GroupC1Layout->setAlignment( Qt::AlignTop );
106 GroupC1Layout->setSpacing( 6 );
107 GroupC1Layout->setMargin( 11 );
108 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
109 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
110 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
111 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
112 TextLabelC1A1->setFrameShadow( QLabel::Plain );
113 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
114 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
115 TextLabelC1A2->setText( tr( "GEOM_CENTRAL_POINT" ) );
116 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
117 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
118 TextLabelC1A2->setFrameShadow( QLabel::Plain );
119 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
120 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
121 SelectButtonC1A1->setText( tr( "" ) );
122 SelectButtonC1A1->setPixmap( image1 );
123 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
124 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
125 SelectButtonC1A2->setText( tr( "" ) );
126 SelectButtonC1A2->setPixmap( image1 );
127 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
128 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
130 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
131 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
132 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
133 LineEditC1A3 = new QLineEdit( GroupC1, "LineEditC1A3" );
134 GroupC1Layout->addWidget( LineEditC1A3, 2, 2 );
135 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
136 TextLabelC1A3->setText( tr( "GEOM_SCALE_FACTOR" ) );
137 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
138 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
139 GeometryGUI_ScaleDlgLayout->addWidget( GroupC1, 1, 0 );
141 /***************************************************************/
142 GroupButtons = new QGroupBox( this, "GroupButtons" );
143 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
144 GroupButtons->setTitle( tr( "" ) );
145 GroupButtons->setColumnLayout(0, Qt::Vertical );
146 GroupButtons->layout()->setSpacing( 0 );
147 GroupButtons->layout()->setMargin( 0 );
148 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
152 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
153 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
154 buttonCancel->setAutoDefault( TRUE );
155 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
156 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
157 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
158 buttonApply->setAutoDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
160 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
161 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
162 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
163 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
164 buttonOk->setAutoDefault( TRUE );
165 buttonOk->setDefault( TRUE );
166 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
167 GeometryGUI_ScaleDlgLayout->addWidget( GroupButtons, 2, 0 );
173 //=================================================================================
174 // function : ~GeometryGUI_ScaleDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 GeometryGUI_ScaleDlg::~GeometryGUI_ScaleDlg()
179 /* no need to delete child widgets, Qt does it all for us */
183 //=================================================================================
186 //=================================================================================
187 void GeometryGUI_ScaleDlg::Init( SALOME_Selection* Sel )
190 LineEditC1A3->setMaxLength( 10 );
191 QDoubleValidator *Va = new QDoubleValidator( -999999, +999999, 3, LineEditC1A3 ) ;
192 LineEditC1A3->setValidator( Va ) ;
195 myConstructorId = 0 ;
196 Constructor1->setChecked( TRUE );
197 myEditCurrentArgument = LineEditC1A1 ;
199 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
200 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
201 myOkPoint1 = myOkBaseTopo = false ;
203 LineEditC1A3->setText("2.0") ;
204 mySimulationTopoDs.Nullify() ;
205 myBaseTopo.Nullify() ;
206 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
208 // TODO : previous selection into argument ?
210 /* Filters definition */
211 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
212 myGeom = GEOM::GEOM_Gen::_narrow(comp);
213 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
214 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
216 /* signals and slots connections */
217 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
218 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
219 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
220 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
221 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
222 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
224 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
225 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
227 connect( LineEditC1A3, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
228 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
229 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
230 /* to close dialog if study change */
231 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
233 /* Move widget on the botton right corner of main widget */
235 myGeomGUI->DefineDlgPosition( this, x, y ) ;
237 this->show() ; /* displays Dialog */
243 //=================================================================================
244 // function : ConstructorsClicked()
245 // purpose : Radio button management
246 //=================================================================================
247 void GeometryGUI_ScaleDlg::ConstructorsClicked(int constructorId)
249 myGeomGUI->EraseSimulationShape() ;
251 switch (constructorId)
256 myConstructorId = constructorId ;
257 myEditCurrentArgument = LineEditC1A1 ;
258 Constructor1->setChecked( TRUE );
259 LineEditC1A1->setText(tr("")) ;
260 LineEditC1A2->setText(tr("")) ;
261 myOkPoint1 = myOkBaseTopo = false ;
263 /* filter for next selections */
264 mySelection->ClearFilters() ;
265 mySelection->AddFilter( myVertexFilter );
266 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
273 //=================================================================================
274 // function : ClickOnOk()
276 //=================================================================================
277 void GeometryGUI_ScaleDlg::ClickOnOk()
279 this->ClickOnApply() ;
280 this->ClickOnCancel() ;
285 //=================================================================================
286 // function : ClickOnApply()
288 //=================================================================================
289 void GeometryGUI_ScaleDlg::ClickOnApply()
291 myGeomGUI->EraseSimulationShape() ;
292 mySimulationTopoDs.Nullify() ;
293 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
295 switch(myConstructorId)
299 if( myOkBaseTopo && myOkPoint1 )
300 myGeomGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor ) ;
309 //=================================================================================
310 // function : ClickOnCancel()
312 //=================================================================================
313 void GeometryGUI_ScaleDlg::ClickOnCancel()
315 mySelection->ClearFilters() ;
316 myGeomGUI->EraseSimulationShape() ;
317 mySimulationTopoDs.Nullify() ;
318 disconnect( mySelection, 0, this, 0 );
319 myGeomGUI->ResetState() ;
324 //=================================================================================
325 // function : LineEditReturnPressed()
327 //=================================================================================
328 void GeometryGUI_ScaleDlg::LineEditReturnPressed()
330 QLineEdit* send = (QLineEdit*)sender();
331 if( send == LineEditC1A1 )
332 myEditCurrentArgument = LineEditC1A1 ;
333 else if ( send == LineEditC1A2 )
334 myEditCurrentArgument = LineEditC1A2 ;
338 /* User name of object input management */
339 /* If successfull the selection is changed and signal emitted... */
340 /* so SelectionIntoArgument() is automatically called. */
341 const QString objectUserName = myEditCurrentArgument->text() ;
342 QWidget* thisWidget = (QWidget*)this ;
343 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
344 myEditCurrentArgument->setText( objectUserName ) ;
350 //=================================================================================
351 // function : TextChangedInLineEdit()
353 //=================================================================================
354 void GeometryGUI_ScaleDlg::TextChangedInLineEdit(const QString& newText)
356 QLineEdit* send = (QLineEdit*)sender();
357 if(send == LineEditC1A3) {
358 myGeomGUI->EraseSimulationShape() ;
359 myFactor = newText.toFloat();
360 if( fabs(myFactor) > 0.00001 && myOkBaseTopo && myOkPoint1 )
361 MakeScaleSimulationAndDisplay(myBaseTopo) ;
368 //=================================================================================
369 // function : SelectionIntoArgument()
370 // purpose : Called when selection as changed or other case
371 //=================================================================================
372 void GeometryGUI_ScaleDlg::SelectionIntoArgument()
374 myEditCurrentArgument->setText("") ;
375 myGeomGUI->EraseSimulationShape() ;
376 mySimulationTopoDs.Nullify() ;
378 QString aString = ""; /* name of selection */
380 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
382 if ( myEditCurrentArgument == LineEditC1A1 ) {
383 myEditCurrentArgument->setText("") ;
384 myOkBaseTopo = false ;
386 else if ( myEditCurrentArgument == LineEditC1A2 ) {
387 myEditCurrentArgument->setText("") ;
395 Standard_Boolean testResult ;
396 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
397 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
401 if ( myEditCurrentArgument == LineEditC1A1 ) {
402 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
405 myEditCurrentArgument->setText(aString) ;
407 myOkBaseTopo = true ;
409 else if ( myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
410 myEditCurrentArgument->setText(aString) ;
414 if( myOkBaseTopo && myOkPoint1 ) {
415 MakeScaleSimulationAndDisplay( myBaseTopo ) ;
421 //=================================================================================
422 // function : SetEditCurrentArgument()
424 //=================================================================================
425 void GeometryGUI_ScaleDlg::SetEditCurrentArgument()
427 QPushButton* send = (QPushButton*)sender();
428 switch (myConstructorId)
430 case 0: /* default constructor */
432 if(send == SelectButtonC1A1) {
433 LineEditC1A1->setFocus() ;
434 myEditCurrentArgument = LineEditC1A1;
435 mySelection->ClearFilters() ;
436 SelectionIntoArgument() ;
438 else if(send == SelectButtonC1A2) {
439 LineEditC1A2->setFocus() ;
440 myEditCurrentArgument = LineEditC1A2;
441 mySelection->AddFilter(myVertexFilter) ;
442 SelectionIntoArgument() ;
451 //=================================================================================
452 // function : DeactivateActiveDialog()
454 //=================================================================================
455 void GeometryGUI_ScaleDlg::DeactivateActiveDialog()
457 if ( GroupConstructors->isEnabled() ) {
458 GroupConstructors->setEnabled(false) ;
459 GroupC1->setEnabled(false) ;
460 GroupButtons->setEnabled(false) ;
461 disconnect( mySelection, 0, this, 0 );
462 myGeomGUI->EraseSimulationShape() ;
463 mySelection->ClearFilters() ;
470 //=================================================================================
471 // function : ActivateThisDialog()
473 //=================================================================================
474 void GeometryGUI_ScaleDlg::ActivateThisDialog()
476 /* Emit a signal to deactivate the active dialog */
477 myGeomGUI->EmitSignalDeactivateDialog() ;
478 GroupConstructors->setEnabled(true) ;
479 GroupC1->setEnabled(true) ;
480 GroupButtons->setEnabled(true) ;
482 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
483 if( !mySimulationTopoDs.IsNull() )
484 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
490 //=================================================================================
491 // function : enterEvent()
493 //=================================================================================
494 void GeometryGUI_ScaleDlg::enterEvent(QEvent* e)
496 if ( GroupConstructors->isEnabled() )
498 ActivateThisDialog() ;
502 //=================================================================================
503 // function : closeEvent()
505 //=================================================================================
506 void GeometryGUI_ScaleDlg::closeEvent( QCloseEvent* e )
508 this->ClickOnCancel() ; /* same than click on cancel button */
512 //=================================================================================
513 // function : MakeScaleSimulationAndDisplay()
515 //=================================================================================
516 void GeometryGUI_ScaleDlg::MakeScaleSimulationAndDisplay( const TopoDS_Shape& S )
518 this->mySimulationTopoDs.Nullify() ;
521 gp_Trsf theTransformation ;
522 theTransformation.SetScale( myPoint1, myFactor) ;
523 BRepBuilderAPI_Transform myBRepTransformation( S, theTransformation, Standard_False) ;
524 mySimulationTopoDs = myBRepTransformation.Shape() ;
525 if( mySimulationTopoDs.IsNull() )
528 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
530 catch(Standard_Failure) {
531 MESSAGE( "Exception catched in MakeScaleSimulationAndDisplay" ) ;