2 // File : GeometryGUI_ScaleDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_ScaleDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <BRepBuilderAPI_Transform.hxx>
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
28 #include <qwhatsthis.h>
30 #include <qvalidator.h>
34 //=================================================================================
35 // class : GeometryGUI_ScaleDlg()
36 // purpose : Constructs a GeometryGUI_ScaleDlg which is a child of 'parent', with the
37 // name 'name' and widget flags set to 'f'.
38 // The dialog will by default be modeless, unless you set 'modal' to
39 // TRUE to construct a modal dialog.
40 //=================================================================================
41 GeometryGUI_ScaleDlg::GeometryGUI_ScaleDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SCALE")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
48 setName( "GeometryGUI_ScaleDlg" );
50 setCaption( tr( "GEOM_SCALE_TITLE" ) );
51 setSizeGripEnabled( TRUE );
52 GeometryGUI_ScaleDlgLayout = new QGridLayout( this );
53 GeometryGUI_ScaleDlgLayout->setSpacing( 6 );
54 GeometryGUI_ScaleDlgLayout->setMargin( 11 );
56 /***************************************************************/
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_SCALE" ) );
59 GroupConstructors->setExclusive( TRUE );
60 GroupConstructors->setColumnLayout(0, Qt::Vertical );
61 GroupConstructors->layout()->setSpacing( 0 );
62 GroupConstructors->layout()->setMargin( 0 );
63 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
64 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
65 GroupConstructorsLayout->setSpacing( 6 );
66 GroupConstructorsLayout->setMargin( 11 );
67 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
68 GroupConstructorsLayout->addItem( spacer, 0, 1 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 Constructor1->setMinimumSize( QSize( 50, 0 ) );
75 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
76 GeometryGUI_ScaleDlgLayout->addWidget( GroupConstructors, 0, 0 );
78 /***************************************************************/
79 GroupC1 = new QGroupBox( this, "GroupC1" );
80 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
81 GroupC1->setColumnLayout(0, Qt::Vertical );
82 GroupC1->layout()->setSpacing( 0 );
83 GroupC1->layout()->setMargin( 0 );
84 GroupC1Layout = new QGridLayout( GroupC1->layout() );
85 GroupC1Layout->setAlignment( Qt::AlignTop );
86 GroupC1Layout->setSpacing( 6 );
87 GroupC1Layout->setMargin( 11 );
88 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
89 TextLabelC1A1->setText( tr( "GEOM_OBJECT" ) );
90 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
91 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
92 TextLabelC1A1->setFrameShadow( QLabel::Plain );
93 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
94 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
95 TextLabelC1A2->setText( tr( "GEOM_CENTRAL_POINT" ) );
96 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
97 TextLabelC1A2->setFrameShape( QLabel::NoFrame );
98 TextLabelC1A2->setFrameShadow( QLabel::Plain );
99 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
100 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
101 SelectButtonC1A1->setText( tr( "" ) );
102 SelectButtonC1A1->setPixmap( image1 );
103 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
104 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
105 SelectButtonC1A2->setText( tr( "" ) );
106 SelectButtonC1A2->setPixmap( image1 );
107 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
108 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
109 LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
110 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
111 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
112 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
113 LineEditC1A3 = new QLineEdit( GroupC1, "LineEditC1A3" );
114 GroupC1Layout->addWidget( LineEditC1A3, 2, 2 );
115 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
116 TextLabelC1A3->setText( tr( "GEOM_SCALE_FACTOR" ) );
117 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
118 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
119 GeometryGUI_ScaleDlgLayout->addWidget( GroupC1, 1, 0 );
121 /***************************************************************/
122 GroupButtons = new QGroupBox( this, "GroupButtons" );
123 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
124 GroupButtons->setTitle( tr( "" ) );
125 GroupButtons->setColumnLayout(0, Qt::Vertical );
126 GroupButtons->layout()->setSpacing( 0 );
127 GroupButtons->layout()->setMargin( 0 );
128 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
129 GroupButtonsLayout->setAlignment( Qt::AlignTop );
130 GroupButtonsLayout->setSpacing( 6 );
131 GroupButtonsLayout->setMargin( 11 );
132 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
133 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
134 buttonCancel->setAutoDefault( TRUE );
135 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
136 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
137 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
138 buttonApply->setAutoDefault( TRUE );
139 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
140 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
141 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
142 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
143 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
144 buttonOk->setAutoDefault( TRUE );
145 buttonOk->setDefault( TRUE );
146 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
147 GeometryGUI_ScaleDlgLayout->addWidget( GroupButtons, 2, 0 );
153 //=================================================================================
154 // function : ~GeometryGUI_ScaleDlg()
155 // purpose : Destroys the object and frees any allocated resources
156 //=================================================================================
157 GeometryGUI_ScaleDlg::~GeometryGUI_ScaleDlg()
159 /* no need to delete child widgets, Qt does it all for us */
163 //=================================================================================
166 //=================================================================================
167 void GeometryGUI_ScaleDlg::Init( SALOME_Selection* Sel )
170 LineEditC1A3->setMaxLength( 10 );
171 QDoubleValidator *Va = new QDoubleValidator( -999999, +999999, 3, LineEditC1A3 ) ;
172 LineEditC1A3->setValidator( Va ) ;
175 myConstructorId = 0 ;
176 Constructor1->setChecked( TRUE );
177 myEditCurrentArgument = LineEditC1A1 ;
179 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
180 myPoint1.SetCoord( 0.0, 0.0, 0.0 );
181 myOkPoint1 = myOkBaseTopo = false ;
183 LineEditC1A3->setText("2.0") ;
184 mySimulationTopoDs.Nullify() ;
185 myBaseTopo.Nullify() ;
186 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
188 // TODO : previous selection into argument ?
190 /* Filters definition */
191 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
192 myGeom = GEOM::GEOM_Gen::_narrow(comp);
193 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
194 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
196 /* signals and slots connections */
197 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
198 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
199 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
200 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
201 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
202 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
204 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
205 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
207 connect( LineEditC1A3, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
208 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
209 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
210 /* to close dialog if study change */
211 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
213 /* Move widget on the botton right corner of main widget */
215 myGeomGUI->DefineDlgPosition( this, x, y ) ;
217 this->show() ; /* displays Dialog */
223 //=================================================================================
224 // function : ConstructorsClicked()
225 // purpose : Radio button management
226 //=================================================================================
227 void GeometryGUI_ScaleDlg::ConstructorsClicked(int constructorId)
229 myGeomGUI->EraseSimulationShape() ;
231 switch (constructorId)
236 myConstructorId = constructorId ;
237 myEditCurrentArgument = LineEditC1A1 ;
238 Constructor1->setChecked( TRUE );
239 LineEditC1A1->setText(tr("")) ;
240 LineEditC1A2->setText(tr("")) ;
241 myOkPoint1 = myOkBaseTopo = false ;
243 /* filter for next selections */
244 mySelection->ClearFilters() ;
245 mySelection->AddFilter( myVertexFilter );
246 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
253 //=================================================================================
254 // function : ClickOnOk()
256 //=================================================================================
257 void GeometryGUI_ScaleDlg::ClickOnOk()
259 this->ClickOnApply() ;
260 this->ClickOnCancel() ;
265 //=================================================================================
266 // function : ClickOnApply()
268 //=================================================================================
269 void GeometryGUI_ScaleDlg::ClickOnApply()
271 myGeomGUI->EraseSimulationShape() ;
272 mySimulationTopoDs.Nullify() ;
273 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
275 switch(myConstructorId)
279 if( myOkBaseTopo && myOkPoint1 )
280 myGeomGUI->MakeScaleAndDisplay(myGeomShape, myPoint1, myFactor ) ;
289 //=================================================================================
290 // function : ClickOnCancel()
292 //=================================================================================
293 void GeometryGUI_ScaleDlg::ClickOnCancel()
295 mySelection->ClearFilters() ;
296 myGeomGUI->EraseSimulationShape() ;
297 mySimulationTopoDs.Nullify() ;
298 disconnect( mySelection, 0, this, 0 );
299 myGeomGUI->ResetState() ;
304 //=================================================================================
305 // function : LineEditReturnPressed()
307 //=================================================================================
308 void GeometryGUI_ScaleDlg::LineEditReturnPressed()
310 QLineEdit* send = (QLineEdit*)sender();
311 if( send == LineEditC1A1 )
312 myEditCurrentArgument = LineEditC1A1 ;
313 else if ( send == LineEditC1A2 )
314 myEditCurrentArgument = LineEditC1A2 ;
318 /* User name of object input management */
319 /* If successfull the selection is changed and signal emitted... */
320 /* so SelectionIntoArgument() is automatically called. */
321 const QString objectUserName = myEditCurrentArgument->text() ;
322 QWidget* thisWidget = (QWidget*)this ;
323 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
324 myEditCurrentArgument->setText( objectUserName ) ;
330 //=================================================================================
331 // function : TextChangedInLineEdit()
333 //=================================================================================
334 void GeometryGUI_ScaleDlg::TextChangedInLineEdit(const QString& newText)
336 QLineEdit* send = (QLineEdit*)sender();
337 if(send == LineEditC1A3) {
338 myGeomGUI->EraseSimulationShape() ;
339 myFactor = newText.toFloat();
340 if( fabs(myFactor) > 0.00001 && myOkBaseTopo && myOkPoint1 )
341 MakeScaleSimulationAndDisplay(myBaseTopo) ;
348 //=================================================================================
349 // function : SelectionIntoArgument()
350 // purpose : Called when selection as changed or other case
351 //=================================================================================
352 void GeometryGUI_ScaleDlg::SelectionIntoArgument()
354 myEditCurrentArgument->setText("") ;
355 myGeomGUI->EraseSimulationShape() ;
356 mySimulationTopoDs.Nullify() ;
358 QString aString = ""; /* name of selection */
360 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
362 if ( myEditCurrentArgument == LineEditC1A1 ) {
363 myEditCurrentArgument->setText("") ;
364 myOkBaseTopo = false ;
366 else if ( myEditCurrentArgument == LineEditC1A2 ) {
367 myEditCurrentArgument->setText("") ;
375 Standard_Boolean testResult ;
376 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
377 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
381 if ( myEditCurrentArgument == LineEditC1A1 ) {
382 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
385 myEditCurrentArgument->setText(aString) ;
387 myOkBaseTopo = true ;
389 else if ( myEditCurrentArgument == LineEditC1A2 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
390 myEditCurrentArgument->setText(aString) ;
394 if( myOkBaseTopo && myOkPoint1 ) {
395 MakeScaleSimulationAndDisplay( myBaseTopo ) ;
401 //=================================================================================
402 // function : SetEditCurrentArgument()
404 //=================================================================================
405 void GeometryGUI_ScaleDlg::SetEditCurrentArgument()
407 QPushButton* send = (QPushButton*)sender();
408 switch (myConstructorId)
410 case 0: /* default constructor */
412 if(send == SelectButtonC1A1) {
413 LineEditC1A1->setFocus() ;
414 myEditCurrentArgument = LineEditC1A1;
415 mySelection->ClearFilters() ;
416 SelectionIntoArgument() ;
418 else if(send == SelectButtonC1A2) {
419 LineEditC1A2->setFocus() ;
420 myEditCurrentArgument = LineEditC1A2;
421 mySelection->AddFilter(myVertexFilter) ;
422 SelectionIntoArgument() ;
431 //=================================================================================
432 // function : DeactivateActiveDialog()
434 //=================================================================================
435 void GeometryGUI_ScaleDlg::DeactivateActiveDialog()
437 if ( GroupConstructors->isEnabled() ) {
438 GroupConstructors->setEnabled(false) ;
439 GroupC1->setEnabled(false) ;
440 GroupButtons->setEnabled(false) ;
441 disconnect( mySelection, 0, this, 0 );
442 myGeomGUI->EraseSimulationShape() ;
443 mySelection->ClearFilters() ;
450 //=================================================================================
451 // function : ActivateThisDialog()
453 //=================================================================================
454 void GeometryGUI_ScaleDlg::ActivateThisDialog()
456 /* Emit a signal to deactivate the active dialog */
457 myGeomGUI->EmitSignalDeactivateDialog() ;
458 GroupConstructors->setEnabled(true) ;
459 GroupC1->setEnabled(true) ;
460 GroupButtons->setEnabled(true) ;
462 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
463 if( !mySimulationTopoDs.IsNull() )
464 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
470 //=================================================================================
471 // function : enterEvent()
473 //=================================================================================
474 void GeometryGUI_ScaleDlg::enterEvent(QEvent* e)
476 if ( GroupConstructors->isEnabled() )
478 ActivateThisDialog() ;
482 //=================================================================================
483 // function : closeEvent()
485 //=================================================================================
486 void GeometryGUI_ScaleDlg::closeEvent( QCloseEvent* e )
488 this->ClickOnCancel() ; /* same than click on cancel button */
492 //=================================================================================
493 // function : MakeScaleSimulationAndDisplay()
495 //=================================================================================
496 void GeometryGUI_ScaleDlg::MakeScaleSimulationAndDisplay( const TopoDS_Shape& S )
498 this->mySimulationTopoDs.Nullify() ;
501 gp_Trsf theTransformation ;
502 theTransformation.SetScale( myPoint1, myFactor) ;
503 BRepBuilderAPI_Transform myBRepTransformation( S, theTransformation, Standard_False) ;
504 mySimulationTopoDs = myBRepTransformation.Shape() ;
505 if( mySimulationTopoDs.IsNull() )
508 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
510 catch(Standard_Failure) {
511 MESSAGE( "Exception catched in MakeScaleSimulationAndDisplay" ) ;