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_PrismDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_PrismDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
38 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qvalidator.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qlineedit.h>
47 #include <qcheckbox.h>
50 #include <qwhatsthis.h>
58 //=================================================================================
59 // class : GeometryGUI_PrismDlg()
60 // purpose : Constructs a GeometryGUI_PrismDlg which is a child of 'parent', with the
61 // name 'name' and widget flags set to 'f'.
62 // The dialog will by default be modeless, unless you set 'modal' to
63 // TRUE to construct a modal dialog.
64 //=================================================================================
65 GeometryGUI_PrismDlg::GeometryGUI_PrismDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
66 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
69 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PRISM")));
70 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
73 setName( "GeometryGUI_PrismDlg" );
75 setCaption( tr( "GEOM_PRISM_TITLE" ) );
76 setSizeGripEnabled( TRUE );
77 GeometryGUI_PrismDlgLayout = new QGridLayout( this );
78 GeometryGUI_PrismDlgLayout->setSpacing( 6 );
79 GeometryGUI_PrismDlgLayout->setMargin( 11 );
81 /**************************************************************/
82 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
83 GroupConstructors->setTitle( tr( "GEOM_PRISM" ) );
84 GroupConstructors->setExclusive( TRUE );
85 GroupConstructors->setColumnLayout(0, Qt::Vertical );
86 GroupConstructors->layout()->setSpacing( 0 );
87 GroupConstructors->layout()->setMargin( 0 );
88 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
89 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
90 GroupConstructorsLayout->setSpacing( 6 );
91 GroupConstructorsLayout->setMargin( 11 );
92 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
93 Constructor1->setText( tr( "" ) );
94 Constructor1->setPixmap( image0 );
95 Constructor1->setChecked( TRUE );
96 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
97 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
98 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupConstructorsLayout->addItem( spacer, 0, 2 );
100 GeometryGUI_PrismDlgLayout->addWidget( GroupConstructors, 0, 0 );
102 /**************************************************************/
103 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
104 GroupConstructor1->setTitle( tr( "GEOM_PRISM_BSV" ) );
105 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
106 GroupConstructor1->layout()->setSpacing( 0 );
107 GroupConstructor1->layout()->setMargin( 0 );
108 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
109 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
110 GroupConstructor1Layout->setSpacing( 6 );
111 GroupConstructor1Layout->setMargin( 11 );
112 LineEditC1A2Line = new QLineEdit( GroupConstructor1, "LineEditC1A2Line" );
113 LineEditC1A2Line->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Line->sizePolicy().hasHeightForWidth() ) );
114 GroupConstructor1Layout->addMultiCellWidget( LineEditC1A2Line, 1, 1, 2, 3 );
115 LineEditC1A1Base = new QLineEdit( GroupConstructor1, "LineEditC1A1Base" );
116 LineEditC1A1Base->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Base->sizePolicy().hasHeightForWidth() ) );
117 GroupConstructor1Layout->addMultiCellWidget( LineEditC1A1Base, 0, 0, 2, 3 );
118 SelectButtonC1A1Base = new QPushButton( GroupConstructor1, "SelectButtonC1A1Base" );
119 SelectButtonC1A1Base->setText( tr( "" ) );
120 SelectButtonC1A1Base->setPixmap( image1 );
121 GroupConstructor1Layout->addWidget( SelectButtonC1A1Base, 0, 1 );
122 SelectButtonC1A2Line = new QPushButton( GroupConstructor1, "SelectButtonC1A2Line" );
123 SelectButtonC1A2Line->setText( tr( "" ) );
124 SelectButtonC1A2Line->setPixmap( image1 );
125 GroupConstructor1Layout->addWidget( SelectButtonC1A2Line, 1, 1 );
126 TextLabelBase = new QLabel( GroupConstructor1, "TextLabelBase" );
127 TextLabelBase->setText( tr( "GEOM_BASE" ) );
128 TextLabelBase->setMinimumSize( QSize( 50, 0 ) );
129 TextLabelBase->setFrameShape( QLabel::NoFrame );
130 TextLabelBase->setFrameShadow( QLabel::Plain );
131 GroupConstructor1Layout->addWidget( TextLabelBase, 0, 0 );
132 TextLabelVector = new QLabel( GroupConstructor1, "TextLabelVector" );
133 TextLabelVector->setText( tr( "GEOM_VECTOR" ) );
134 TextLabelVector->setMinimumSize( QSize( 50, 0 ) );
135 TextLabelVector->setFrameShape( QLabel::NoFrame );
136 TextLabelVector->setFrameShadow( QLabel::Plain );
137 GroupConstructor1Layout->addWidget( TextLabelVector, 1, 0 );
139 SpinBox_C1A3Height = new GeometryGUI_SpinBox( GroupConstructor1, "GeomSpinBox_C1A3Height" ) ;
140 SpinBox_C1A3Height->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, SpinBox_C1A3Height->sizePolicy().hasHeightForWidth() ) );
141 GroupConstructor1Layout->addWidget( SpinBox_C1A3Height, 2, 3 );
143 CheckBoxC3A1Reverse = new QCheckBox( GroupConstructor1, "CheckBoxC3A1Reverse" );
144 CheckBoxC3A1Reverse->setText( tr( "GEOM_REVERSE" ) );
145 GroupConstructor1Layout->addMultiCellWidget( CheckBoxC3A1Reverse, 2, 2, 0, 1 );
146 TextLabelHeight = new QLabel( GroupConstructor1, "TextLabelHeight" );
147 TextLabelHeight->setText( tr( "GEOM_HEIGHT" ) );
148 TextLabelHeight->setMinimumSize( QSize( 50, 0 ) );
149 TextLabelHeight->setFrameShape( QLabel::NoFrame );
150 TextLabelHeight->setFrameShadow( QLabel::Plain );
151 GroupConstructor1Layout->addWidget( TextLabelHeight, 2, 2 );
152 GeometryGUI_PrismDlgLayout->addWidget( GroupConstructor1, 1, 0 );
154 /**************************************************************/
155 GroupButtons = new QGroupBox( this, "GroupButtons" );
156 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
157 GroupButtons->setTitle( tr( "" ) );
158 GroupButtons->setColumnLayout(0, Qt::Vertical );
159 GroupButtons->layout()->setSpacing( 0 );
160 GroupButtons->layout()->setMargin( 0 );
161 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
162 GroupButtonsLayout->setAlignment( Qt::AlignTop );
163 GroupButtonsLayout->setSpacing( 6 );
164 GroupButtonsLayout->setMargin( 11 );
165 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
166 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
167 buttonCancel->setAutoDefault( TRUE );
168 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
169 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
170 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
171 buttonApply->setAutoDefault( TRUE );
172 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
173 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
174 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
175 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
176 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
177 buttonOk->setAutoDefault( TRUE );
178 buttonOk->setDefault( TRUE );
179 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
180 GeometryGUI_PrismDlgLayout->addWidget( GroupButtons, 2, 0 );
187 //=================================================================================
188 // function : ~GeometryGUI_PrismDlg()
189 // purpose : Destroys the object and frees any allocated resources
190 //=================================================================================
191 GeometryGUI_PrismDlg::~GeometryGUI_PrismDlg()
193 /* no need to delete child widgets, Qt does it all for us */
198 //=================================================================================
201 //=================================================================================
202 void GeometryGUI_PrismDlg::Init( SALOME_Selection* Sel )
206 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
207 step = St.toDouble() ;
209 /* min, max, step and decimals for spin boxes */
210 SpinBox_C1A3Height->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
211 SpinBox_C1A3Height->SetValue( 100.0 ) ; /* = myHeight */
215 mySimulationTopoDs.Nullify() ;
216 myBaseTopo.Nullify() ;
217 myConstructorId = 0 ;
218 myDx = myDy = myDz = 0.0 ;
220 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
222 GroupConstructor1->show();
223 myConstructorId = 0 ;
224 myEditCurrentArgument = LineEditC1A1Base ;
225 Constructor1->setChecked( TRUE );
226 myOkBase = myOkLine = false ;
228 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
230 /* Retrieves geom component */
231 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
232 myGeom = GEOM::GEOM_Gen::_narrow(comp);
233 /* Filters definition */
234 myEdgeFilter = new GEOM_ShapeTypeFilter( TopAbs_EDGE, myGeom );
237 // TODO first selection into selection ?
239 /* signals and slots connections */
240 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
241 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
242 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
244 connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) );
245 connect( SelectButtonC1A1Base, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
246 connect( SelectButtonC1A2Line, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
248 connect( LineEditC1A1Base, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
249 connect( LineEditC1A2Line, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
251 connect( CheckBoxC3A1Reverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseVector(int) ) ) ;
253 connect( SpinBox_C1A3Height, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
255 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
256 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
257 /* to close dialog if study change */
258 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
260 /* Move widget on the botton right corner of main widget */
262 myGeomGUI->DefineDlgPosition( this, x, y ) ;
264 this->show() ; /* Displays Dialog */
271 //=================================================================================
272 // function : ConstructorsClicked()
273 // purpose : Radio button management
274 //=================================================================================
275 void GeometryGUI_PrismDlg::ConstructorsClicked(int constructorId)
277 myGeomGUI->EraseSimulationShape() ;
279 switch (constructorId)
281 case 0: /* base shape + an edge used as a vector */
283 GroupConstructor1->show();
284 myConstructorId = constructorId ;
285 myEditCurrentArgument = LineEditC1A1Base ;
286 LineEditC1A2Line->setText(tr("")) ;
288 SpinBox_C1A3Height->SetValue(100) ;
291 Constructor1->setChecked( TRUE );
292 myOkBase = myOkLine = false ;
293 SelectionIntoArgument() ;
300 //=================================================================================
301 // function : ClickOnOk()
303 //=================================================================================
304 void GeometryGUI_PrismDlg::ClickOnOk()
306 this->ClickOnApply() ;
307 this->ClickOnCancel() ;
312 //=================================================================================
313 // function : ClickOnApply()
315 //=================================================================================
316 void GeometryGUI_PrismDlg::ClickOnApply()
320 if( !myOkBase || !myOkLine )
324 myGeomGUI->EraseSimulationShape() ;
325 mySimulationTopoDs.Nullify() ;
326 gp_Vec Vec(myDx, myDy, myDz );
329 P1.SetCoord( 0.0, 0.0, 0.0 ) ;
330 P2.SetCoord( Vec.X(), Vec.Y(), Vec.Z() ) ;
331 switch(myConstructorId)
335 if( myOkBase && myOkLine ) {
336 myGeomGUI->MakePrismAndDisplay( myGeomShape, P1, P2 ) ;
342 catch(Standard_Failure) {
343 MESSAGE("Exception intercepted in GeometryGUI_PrismDlg" << endl ) ;
351 //=================================================================================
352 // function : ClickOnCancel()
354 //=================================================================================
355 void GeometryGUI_PrismDlg::ClickOnCancel()
357 mySelection->ClearFilters() ;
358 myGeomGUI->EraseSimulationShape() ;
359 mySimulationTopoDs.Nullify() ;
360 disconnect( mySelection, 0, this, 0 );
361 myGeomGUI->ResetState() ;
367 //=================================================================================
368 // function : SelectionIntoArgument()
369 // purpose : Called when selection has changed
370 //=================================================================================
371 void GeometryGUI_PrismDlg::SelectionIntoArgument()
373 myGeomGUI->EraseSimulationShape() ;
374 mySimulationTopoDs.Nullify() ;
376 /* Future the name of selection */
377 QString aString = "";
379 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
381 switch (myConstructorId)
385 if ( myEditCurrentArgument == LineEditC1A1Base ) {
386 LineEditC1A1Base->setText("") ;
389 else if ( myEditCurrentArgument == LineEditC1A2Line ) {
390 LineEditC1A2Line->setText("") ;
401 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
404 gp_Pnt aPoint1, aPoint2 ;
406 if ( myEditCurrentArgument == LineEditC1A1Base ) {
407 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
408 Standard_Boolean testResult ;
409 myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
412 if ( S.ShapeType() <= 2 )
415 LineEditC1A1Base->setText(aString) ;
420 else if ( myEditCurrentArgument == LineEditC1A2Line && myGeomGUI->LinearEdgeExtremities(S, aPoint1, aPoint2) ) {
421 myGeomGUI->GetBipointDxDyDz( aPoint1, aPoint2, myDx, myDy, myDz ) ;
422 myEditCurrentArgument->setText(aString) ;
426 if( myOkBase && myOkLine ) {
427 MakePrismSimulationAndDisplay( myBaseTopo ) ;
434 //=================================================================================
435 // function : MakePrismSimulationAndDisplay()
437 //=================================================================================
438 void GeometryGUI_PrismDlg::MakePrismSimulationAndDisplay( const TopoDS_Shape& S )
441 gp_Vec Vec(myDx, myDy, myDz );
444 mySimulationTopoDs = BRepPrimAPI_MakePrism(S, Vec, Standard_False).Shape() ;
446 catch(Standard_Failure) {
447 MESSAGE( "Exception catched in MakePrismSimulationAndDisplay" << endl ) ;
450 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
457 //=================================================================================
458 // function : SetEditCurrentArgument()
460 //=================================================================================
461 void GeometryGUI_PrismDlg::SetEditCurrentArgument()
463 QPushButton* send = (QPushButton*)sender();
464 mySelection->ClearFilters() ;
466 switch (myConstructorId)
468 case 0: /* default constructor */
470 if( send == SelectButtonC1A1Base ) {
471 LineEditC1A1Base->setFocus() ;
472 myEditCurrentArgument = LineEditC1A1Base ;
474 else if(send == SelectButtonC1A2Line) {
475 LineEditC1A2Line->setFocus() ;
476 myEditCurrentArgument = LineEditC1A2Line;
477 mySelection->AddFilter(myEdgeFilter) ;
479 SelectionIntoArgument() ;
486 //=================================================================================
487 // function : ValueChangedInSpinBox()
489 //=================================================================================
490 void GeometryGUI_PrismDlg::ValueChangedInSpinBox( double newValue )
492 QObject* send = (QObject*)sender();
494 if( send == SpinBox_C1A3Height ) {
495 myHeight = newValue ;
496 if( myOkBase && myOkLine ) {
497 myGeomGUI->EraseSimulationShape() ;
498 mySimulationTopoDs.Nullify() ;
499 MakePrismSimulationAndDisplay( myBaseTopo ) ;
506 //=================================================================================
507 // function : LineEditReturnPressed()
509 //=================================================================================
510 void GeometryGUI_PrismDlg::LineEditReturnPressed()
512 QLineEdit* send = (QLineEdit*)sender();
513 if( send == LineEditC1A1Base )
514 myEditCurrentArgument = LineEditC1A1Base ;
515 else if ( send == LineEditC1A2Line )
516 myEditCurrentArgument = LineEditC1A2Line ;
520 /* User name of object input management */
521 /* If successfull the selection is changed and signal emitted... */
522 /* so SelectionIntoArgument() is automatically called. */
523 const QString objectUserName = myEditCurrentArgument->text() ;
524 QWidget* thisWidget = (QWidget*)this ;
525 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
526 myEditCurrentArgument->setText( objectUserName ) ;
533 //=================================================================================
534 // function : DeactivateActiveDialog()
536 //=================================================================================
537 void GeometryGUI_PrismDlg::DeactivateActiveDialog()
539 if ( GroupConstructors->isEnabled() ) {
540 GroupConstructors->setEnabled(false) ;
541 GroupConstructor1->setEnabled(false) ;
542 GroupButtons->setEnabled(false) ;
543 disconnect( mySelection, 0, this, 0 );
544 myGeomGUI->EraseSimulationShape() ;
551 //=================================================================================
552 // function : closeEvent()
554 //=================================================================================
555 void GeometryGUI_PrismDlg::closeEvent( QCloseEvent* e )
557 this->ClickOnCancel() ; /* same than click on cancel button */
561 //=================================================================================
562 // function : enterEvent()
563 // purpose : when mouse enter onto the QWidget
564 //=================================================================================
565 void GeometryGUI_PrismDlg::enterEvent( QEvent * )
567 if ( GroupConstructors->isEnabled() )
569 ActivateThisDialog() ;
574 //=================================================================================
575 // function : ActivateThisDialog()
577 //=================================================================================
578 void GeometryGUI_PrismDlg::ActivateThisDialog()
580 /* Emit a signal to deactivate any active dialog */
581 myGeomGUI->EmitSignalDeactivateDialog() ;
582 GroupConstructors->setEnabled(true) ;
583 GroupConstructor1->setEnabled(true) ;
584 GroupButtons->setEnabled(true) ;
586 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
587 if( !mySimulationTopoDs.IsNull() )
588 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
593 //=================================================================================
594 // function : ReverseVector()
595 // purpose : 'state' not used here
596 //=================================================================================
597 void GeometryGUI_PrismDlg::ReverseVector(int state)
602 if(myOkBase && myOkLine) {
603 myGeomGUI->EraseSimulationShape() ;
604 mySimulationTopoDs.Nullify() ;
605 MakePrismSimulationAndDisplay( myBaseTopo ) ;