2 // File : GeometryGUI_PrismDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_PrismDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Config.h"
16 #include "utilities.h"
18 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qvalidator.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
25 #include <qlineedit.h>
27 #include <qcheckbox.h>
30 #include <qwhatsthis.h>
38 //=================================================================================
39 // class : GeometryGUI_PrismDlg()
40 // purpose : Constructs a GeometryGUI_PrismDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 GeometryGUI_PrismDlg::GeometryGUI_PrismDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
46 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PRISM")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
53 setName( "GeometryGUI_PrismDlg" );
55 setCaption( tr( "GEOM_PRISM_TITLE" ) );
56 setSizeGripEnabled( TRUE );
57 GeometryGUI_PrismDlgLayout = new QGridLayout( this );
58 GeometryGUI_PrismDlgLayout->setSpacing( 6 );
59 GeometryGUI_PrismDlgLayout->setMargin( 11 );
61 /**************************************************************/
62 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
63 GroupConstructors->setTitle( tr( "GEOM_PRISM" ) );
64 GroupConstructors->setExclusive( TRUE );
65 GroupConstructors->setColumnLayout(0, Qt::Vertical );
66 GroupConstructors->layout()->setSpacing( 0 );
67 GroupConstructors->layout()->setMargin( 0 );
68 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
69 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
70 GroupConstructorsLayout->setSpacing( 6 );
71 GroupConstructorsLayout->setMargin( 11 );
72 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
73 Constructor1->setText( tr( "" ) );
74 Constructor1->setPixmap( image0 );
75 Constructor1->setChecked( TRUE );
76 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
77 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
78 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79 GroupConstructorsLayout->addItem( spacer, 0, 2 );
80 GeometryGUI_PrismDlgLayout->addWidget( GroupConstructors, 0, 0 );
82 /**************************************************************/
83 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
84 GroupConstructor1->setTitle( tr( "GEOM_PRISM_BSV" ) );
85 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
86 GroupConstructor1->layout()->setSpacing( 0 );
87 GroupConstructor1->layout()->setMargin( 0 );
88 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
89 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
90 GroupConstructor1Layout->setSpacing( 6 );
91 GroupConstructor1Layout->setMargin( 11 );
92 LineEditC1A2Line = new QLineEdit( GroupConstructor1, "LineEditC1A2Line" );
93 LineEditC1A2Line->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Line->sizePolicy().hasHeightForWidth() ) );
94 GroupConstructor1Layout->addMultiCellWidget( LineEditC1A2Line, 1, 1, 2, 3 );
95 LineEditC1A1Base = new QLineEdit( GroupConstructor1, "LineEditC1A1Base" );
96 LineEditC1A1Base->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Base->sizePolicy().hasHeightForWidth() ) );
97 GroupConstructor1Layout->addMultiCellWidget( LineEditC1A1Base, 0, 0, 2, 3 );
98 SelectButtonC1A1Base = new QPushButton( GroupConstructor1, "SelectButtonC1A1Base" );
99 SelectButtonC1A1Base->setText( tr( "" ) );
100 SelectButtonC1A1Base->setPixmap( image1 );
101 GroupConstructor1Layout->addWidget( SelectButtonC1A1Base, 0, 1 );
102 SelectButtonC1A2Line = new QPushButton( GroupConstructor1, "SelectButtonC1A2Line" );
103 SelectButtonC1A2Line->setText( tr( "" ) );
104 SelectButtonC1A2Line->setPixmap( image1 );
105 GroupConstructor1Layout->addWidget( SelectButtonC1A2Line, 1, 1 );
106 TextLabelBase = new QLabel( GroupConstructor1, "TextLabelBase" );
107 TextLabelBase->setText( tr( "GEOM_BASE" ) );
108 TextLabelBase->setMinimumSize( QSize( 50, 0 ) );
109 TextLabelBase->setFrameShape( QLabel::NoFrame );
110 TextLabelBase->setFrameShadow( QLabel::Plain );
111 GroupConstructor1Layout->addWidget( TextLabelBase, 0, 0 );
112 TextLabelVector = new QLabel( GroupConstructor1, "TextLabelVector" );
113 TextLabelVector->setText( tr( "GEOM_VECTOR" ) );
114 TextLabelVector->setMinimumSize( QSize( 50, 0 ) );
115 TextLabelVector->setFrameShape( QLabel::NoFrame );
116 TextLabelVector->setFrameShadow( QLabel::Plain );
117 GroupConstructor1Layout->addWidget( TextLabelVector, 1, 0 );
119 SpinBox_C1A3Height = new GeometryGUI_SpinBox( GroupConstructor1, "GeomSpinBox_C1A3Height" ) ;
120 SpinBox_C1A3Height->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_C1A3Height->sizePolicy().hasHeightForWidth() ) );
121 GroupConstructor1Layout->addWidget( SpinBox_C1A3Height, 2, 3 );
123 CheckBoxC3A1Reverse = new QCheckBox( GroupConstructor1, "CheckBoxC3A1Reverse" );
124 CheckBoxC3A1Reverse->setText( tr( "GEOM_REVERSE" ) );
125 GroupConstructor1Layout->addMultiCellWidget( CheckBoxC3A1Reverse, 2, 2, 0, 1 );
126 TextLabelHeight = new QLabel( GroupConstructor1, "TextLabelHeight" );
127 TextLabelHeight->setText( tr( "GEOM_HEIGHT" ) );
128 TextLabelHeight->setMinimumSize( QSize( 50, 0 ) );
129 TextLabelHeight->setFrameShape( QLabel::NoFrame );
130 TextLabelHeight->setFrameShadow( QLabel::Plain );
131 GroupConstructor1Layout->addWidget( TextLabelHeight, 2, 2 );
132 GeometryGUI_PrismDlgLayout->addWidget( GroupConstructor1, 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_PrismDlgLayout->addWidget( GroupButtons, 2, 0 );
167 //=================================================================================
168 // function : ~GeometryGUI_PrismDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 GeometryGUI_PrismDlg::~GeometryGUI_PrismDlg()
173 /* no need to delete child widgets, Qt does it all for us */
178 //=================================================================================
181 //=================================================================================
182 void GeometryGUI_PrismDlg::Init( SALOME_Selection* Sel )
186 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
187 step = St.toDouble() ;
189 /* min, max, step and decimals for spin boxes */
190 SpinBox_C1A3Height->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
191 SpinBox_C1A3Height->SetValue( 100.0 ) ; /* = myHeight */
195 mySimulationTopoDs.Nullify() ;
196 myBaseTopo.Nullify() ;
197 myConstructorId = 0 ;
198 myDx = myDy = myDz = 0.0 ;
200 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
202 GroupConstructor1->show();
203 myConstructorId = 0 ;
204 myEditCurrentArgument = LineEditC1A1Base ;
205 Constructor1->setChecked( TRUE );
206 myOkBase = myOkLine = false ;
208 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
210 /* Retrieves geom component */
211 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
212 myGeom = GEOM::GEOM_Gen::_narrow(comp);
213 /* Filters definition */
214 myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
217 // TODO first selection into selection ?
219 /* signals and slots connections */
220 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
221 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
222 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
224 connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) );
225 connect( SelectButtonC1A1Base, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
226 connect( SelectButtonC1A2Line, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
228 connect( LineEditC1A1Base, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
229 connect( LineEditC1A2Line, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
231 connect( CheckBoxC3A1Reverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseVector(int) ) ) ;
233 connect( SpinBox_C1A3Height, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
235 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
237 /* to close dialog if study change */
238 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
240 /* Move widget on the botton right corner of main widget */
242 myGeomGUI->DefineDlgPosition( this, x, y ) ;
244 this->show() ; /* Displays Dialog */
251 //=================================================================================
252 // function : ConstructorsClicked()
253 // purpose : Radio button management
254 //=================================================================================
255 void GeometryGUI_PrismDlg::ConstructorsClicked(int constructorId)
257 myGeomGUI->EraseSimulationShape() ;
259 switch (constructorId)
261 case 0: /* base shape + an edge used as a vector */
263 GroupConstructor1->show();
264 myConstructorId = constructorId ;
265 myEditCurrentArgument = LineEditC1A1Base ;
266 LineEditC1A2Line->setText(tr("")) ;
268 SpinBox_C1A3Height->SetValue(100) ;
271 Constructor1->setChecked( TRUE );
272 myOkBase = myOkLine = false ;
273 SelectionIntoArgument() ;
280 //=================================================================================
281 // function : ClickOnOk()
283 //=================================================================================
284 void GeometryGUI_PrismDlg::ClickOnOk()
286 this->ClickOnApply() ;
287 this->ClickOnCancel() ;
292 //=================================================================================
293 // function : ClickOnApply()
295 //=================================================================================
296 void GeometryGUI_PrismDlg::ClickOnApply()
300 if( !myOkBase || !myOkLine )
304 myGeomGUI->EraseSimulationShape() ;
305 mySimulationTopoDs.Nullify() ;
306 gp_Vec Vec(myDx, myDy, myDz );
309 P1.SetCoord( 0.0, 0.0, 0.0 ) ;
310 P2.SetCoord( Vec.X(), Vec.Y(), Vec.Z() ) ;
311 switch(myConstructorId)
315 if( myOkBase && myOkLine ) {
316 myGeomGUI->MakePrismAndDisplay( myGeomShape, P1, P2 ) ;
322 catch(Standard_Failure) {
323 MESSAGE("Exception intercepted in GeometryGUI_PrismDlg" << endl ) ;
331 //=================================================================================
332 // function : ClickOnCancel()
334 //=================================================================================
335 void GeometryGUI_PrismDlg::ClickOnCancel()
337 mySelection->ClearFilters() ;
338 myGeomGUI->EraseSimulationShape() ;
339 mySimulationTopoDs.Nullify() ;
340 disconnect( mySelection, 0, this, 0 );
341 myGeomGUI->ResetState() ;
347 //=================================================================================
348 // function : SelectionIntoArgument()
349 // purpose : Called when selection has changed
350 //=================================================================================
351 void GeometryGUI_PrismDlg::SelectionIntoArgument()
353 myGeomGUI->EraseSimulationShape() ;
354 mySimulationTopoDs.Nullify() ;
356 /* Future the name of selection */
357 QString aString = "";
359 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
361 switch (myConstructorId)
365 if ( myEditCurrentArgument == LineEditC1A1Base ) {
366 LineEditC1A1Base->setText("") ;
369 else if ( myEditCurrentArgument == LineEditC1A2Line ) {
370 LineEditC1A2Line->setText("") ;
381 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
384 gp_Pnt aPoint1, aPoint2 ;
386 if ( myEditCurrentArgument == LineEditC1A1Base ) {
387 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
388 Standard_Boolean testResult ;
389 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
392 if ( S.ShapeType() <= 2 )
395 LineEditC1A1Base->setText(aString) ;
400 else if ( myEditCurrentArgument == LineEditC1A2Line && myGeomGUI->LinearEdgeExtremities(S, aPoint1, aPoint2) ) {
401 myGeomGUI->GetBipointDxDyDz( aPoint1, aPoint2, myDx, myDy, myDz ) ;
402 myEditCurrentArgument->setText(aString) ;
406 if( myOkBase && myOkLine ) {
407 MakePrismSimulationAndDisplay( myBaseTopo ) ;
414 //=================================================================================
415 // function : MakePrismSimulationAndDisplay()
417 //=================================================================================
418 void GeometryGUI_PrismDlg::MakePrismSimulationAndDisplay( const TopoDS_Shape& S )
421 gp_Vec Vec(myDx, myDy, myDz );
424 mySimulationTopoDs = BRepPrimAPI_MakePrism(S, Vec, Standard_False).Shape() ;
426 catch(Standard_Failure) {
427 MESSAGE( "Exception catched in MakePrismSimulationAndDisplay" << endl ) ;
430 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
437 //=================================================================================
438 // function : SetEditCurrentArgument()
440 //=================================================================================
441 void GeometryGUI_PrismDlg::SetEditCurrentArgument()
443 QPushButton* send = (QPushButton*)sender();
444 mySelection->ClearFilters() ;
446 switch (myConstructorId)
448 case 0: /* default constructor */
450 if( send == SelectButtonC1A1Base ) {
451 LineEditC1A1Base->setFocus() ;
452 myEditCurrentArgument = LineEditC1A1Base ;
454 else if(send == SelectButtonC1A2Line) {
455 LineEditC1A2Line->setFocus() ;
456 myEditCurrentArgument = LineEditC1A2Line;
457 mySelection->AddFilter(myEdgeFilter) ;
459 SelectionIntoArgument() ;
466 //=================================================================================
467 // function : ValueChangedInSpinBox()
469 //=================================================================================
470 void GeometryGUI_PrismDlg::ValueChangedInSpinBox( double newValue )
472 QObject* send = (QObject*)sender();
474 if( send == SpinBox_C1A3Height ) {
475 myHeight = newValue ;
476 if( myOkBase && myOkLine ) {
477 myGeomGUI->EraseSimulationShape() ;
478 mySimulationTopoDs.Nullify() ;
479 MakePrismSimulationAndDisplay( myBaseTopo ) ;
486 //=================================================================================
487 // function : LineEditReturnPressed()
489 //=================================================================================
490 void GeometryGUI_PrismDlg::LineEditReturnPressed()
492 QLineEdit* send = (QLineEdit*)sender();
493 if( send == LineEditC1A1Base )
494 myEditCurrentArgument = LineEditC1A1Base ;
495 else if ( send == LineEditC1A2Line )
496 myEditCurrentArgument = LineEditC1A2Line ;
500 /* User name of object input management */
501 /* If successfull the selection is changed and signal emitted... */
502 /* so SelectionIntoArgument() is automatically called. */
503 const QString objectUserName = myEditCurrentArgument->text() ;
504 QWidget* thisWidget = (QWidget*)this ;
505 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
506 myEditCurrentArgument->setText( objectUserName ) ;
513 //=================================================================================
514 // function : DeactivateActiveDialog()
516 //=================================================================================
517 void GeometryGUI_PrismDlg::DeactivateActiveDialog()
519 if ( GroupConstructors->isEnabled() ) {
520 GroupConstructors->setEnabled(false) ;
521 GroupConstructor1->setEnabled(false) ;
522 GroupButtons->setEnabled(false) ;
523 disconnect( mySelection, 0, this, 0 );
524 myGeomGUI->EraseSimulationShape() ;
531 //=================================================================================
532 // function : closeEvent()
534 //=================================================================================
535 void GeometryGUI_PrismDlg::closeEvent( QCloseEvent* e )
537 this->ClickOnCancel() ; /* same than click on cancel button */
541 //=================================================================================
542 // function : enterEvent()
543 // purpose : when mouse enter onto the QWidget
544 //=================================================================================
545 void GeometryGUI_PrismDlg::enterEvent( QEvent * )
547 if ( GroupConstructors->isEnabled() )
549 ActivateThisDialog() ;
554 //=================================================================================
555 // function : ActivateThisDialog()
557 //=================================================================================
558 void GeometryGUI_PrismDlg::ActivateThisDialog()
560 /* Emit a signal to deactivate any active dialog */
561 myGeomGUI->EmitSignalDeactivateDialog() ;
562 GroupConstructors->setEnabled(true) ;
563 GroupConstructor1->setEnabled(true) ;
564 GroupButtons->setEnabled(true) ;
566 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
567 if( !mySimulationTopoDs.IsNull() )
568 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
573 //=================================================================================
574 // function : ReverseVector()
575 // purpose : 'state' not used here
576 //=================================================================================
577 void GeometryGUI_PrismDlg::ReverseVector(int state)
582 if(myOkBase && myOkLine) {
583 myGeomGUI->EraseSimulationShape() ;
584 mySimulationTopoDs.Nullify() ;
585 MakePrismSimulationAndDisplay( myBaseTopo ) ;