2 // File : GeometryGUI_PipeDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_PipeDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
26 #include <qwhatsthis.h>
30 #include <Standard_ErrorHandler.hxx>
31 #include <Standard_Failure.hxx>
32 #include <BRepOffsetAPI_MakePipe.hxx>
33 #include <BRepAlgoAPI.hxx>
36 //=================================================================================
37 // class : GeometryGUI_PipeDlg()
38 // purpose : Constructs a GeometryGUI_PipeDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 GeometryGUI_PipeDlg::GeometryGUI_PipeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
44 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PIPE")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
50 setName( "GeometryGUI_PipeDlg" );
52 setCaption( tr( "GEOM_PIPE_TITLE" ) );
53 setSizeGripEnabled( TRUE );
54 GeometryGUI_PipeDlgLayout = new QGridLayout( this );
55 GeometryGUI_PipeDlgLayout->setSpacing( 6 );
56 GeometryGUI_PipeDlgLayout->setMargin( 11 );
58 /***************************************************************/
59 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
60 GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
61 GroupConstructors->setExclusive( TRUE );
62 GroupConstructors->setColumnLayout(0, Qt::Vertical );
63 GroupConstructors->layout()->setSpacing( 0 );
64 GroupConstructors->layout()->setMargin( 0 );
65 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
66 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
67 GroupConstructorsLayout->setSpacing( 6 );
68 GroupConstructorsLayout->setMargin( 11 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 Constructor1->setMinimumSize( QSize( 50, 0 ) );
75 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
76 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
77 GroupConstructorsLayout->addItem( spacer, 0, 1 );
78 GeometryGUI_PipeDlgLayout->addWidget( GroupConstructors, 0, 0 );
81 GroupButtons = new QGroupBox( this, "GroupButtons" );
82 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
83 GroupButtons->setTitle( tr( "" ) );
84 GroupButtons->setColumnLayout(0, Qt::Vertical );
85 GroupButtons->layout()->setSpacing( 0 );
86 GroupButtons->layout()->setMargin( 0 );
87 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
88 GroupButtonsLayout->setAlignment( Qt::AlignTop );
89 GroupButtonsLayout->setSpacing( 6 );
90 GroupButtonsLayout->setMargin( 11 );
91 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
92 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
93 buttonCancel->setAutoDefault( TRUE );
94 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
95 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
96 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
97 buttonApply->setAutoDefault( TRUE );
98 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
99 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
101 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
102 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
103 buttonOk->setAutoDefault( TRUE );
104 buttonOk->setDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
106 GeometryGUI_PipeDlgLayout->addWidget( GroupButtons, 2, 0 );
108 /***************************************************************/
109 GroupC1 = new QGroupBox( this, "GroupC1" );
110 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
111 GroupC1->setMinimumSize( QSize( 0, 0 ) );
112 GroupC1->setFrameShape( QGroupBox::Box );
113 GroupC1->setFrameShadow( QGroupBox::Sunken );
114 GroupC1->setColumnLayout(0, Qt::Vertical );
115 GroupC1->layout()->setSpacing( 0 );
116 GroupC1->layout()->setMargin( 0 );
117 GroupC1Layout = new QGridLayout( GroupC1->layout() );
118 GroupC1Layout->setAlignment( Qt::AlignTop );
119 GroupC1Layout->setSpacing( 6 );
120 GroupC1Layout->setMargin( 11 );
121 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
122 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
123 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124 SelectButtonC1A1->setText( tr( "" ) );
125 SelectButtonC1A1->setPixmap( image1 );
126 SelectButtonC1A1->setToggleButton( FALSE );
127 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
128 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
129 TextLabelC1A1->setText( tr( "GEOM_BASE_OBJECT" ) );
130 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
131 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
132 TextLabelC1A1->setFrameShadow( QLabel::Plain );
133 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
134 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
135 TextLabelC1A2->setText( tr( "GEOM_PATH_OBJECT" ) );
136 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
137 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
138 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
139 SelectButtonC1A2->setText( tr( "" ) );
140 SelectButtonC1A2->setPixmap( image1 );
141 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
142 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
143 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
144 GeometryGUI_PipeDlgLayout->addWidget( GroupC1, 1, 0 );
145 /***************************************************************/
152 //=================================================================================
153 // function : ~GeometryGUI_PipeDlg()
154 // purpose : Destroys the object and frees any allocated resources
155 //=================================================================================
156 GeometryGUI_PipeDlg::~GeometryGUI_PipeDlg()
158 /* no need to delete child widgets, Qt does it all for us */
162 //=================================================================================
165 //=================================================================================
166 void GeometryGUI_PipeDlg::Init( SALOME_Selection* Sel )
171 myConstructorId = 0 ;
173 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
176 myConstructorId = 0 ;
177 myEditCurrentArgument = LineEditC1A1 ;
178 Constructor1->setChecked( TRUE );
179 myOkShape1 = myOkShape2 = false ;
181 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
182 mySimulationTopoDs.Nullify() ;
184 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
185 myGeom = GEOM::GEOM_Gen::_narrow(comp);
187 // TODO : previous selection into argument ?
189 /* signals and slots connections */
190 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
191 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
192 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
193 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
194 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
195 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
197 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
198 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
200 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
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 */
216 //=================================================================================
217 // function : ConstructorsClicked()
218 // purpose : Radio button management
219 //=================================================================================
220 void GeometryGUI_PipeDlg::ConstructorsClicked(int constructorId)
222 myGeomGUI->EraseSimulationShape() ;
223 mySimulationTopoDs.Nullify() ;
224 //GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
226 switch (constructorId)
236 //=================================================================================
237 // function : ClickOnOk()
239 //=================================================================================
240 void GeometryGUI_PipeDlg::ClickOnOk()
242 this->ClickOnApply() ;
243 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnAply()
252 //=================================================================================
253 void GeometryGUI_PipeDlg::ClickOnApply()
255 myGeomGUI->EraseSimulationShape() ;
256 mySimulationTopoDs.Nullify() ;
257 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
259 switch(myConstructorId)
263 if(myOkShape1 && myOkShape2) {
264 myGeomGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1) ;
275 //=================================================================================
276 // function : ClickOnCancel()
278 //=================================================================================
279 void GeometryGUI_PipeDlg::ClickOnCancel()
281 myGeomGUI->EraseSimulationShape() ;
282 mySimulationTopoDs.Nullify() ;
283 disconnect( mySelection, 0, this, 0 );
284 myGeomGUI->ResetState() ;
291 //=================================================================================
292 // function : SelectionIntoArgument()
293 // purpose : Called when selection has changed
294 //=================================================================================
295 void GeometryGUI_PipeDlg::SelectionIntoArgument()
297 myGeomGUI->EraseSimulationShape() ;
298 mySimulationTopoDs.Nullify() ;
300 myEditCurrentArgument->setText("") ;
301 QString aString = ""; /* name of future selection */
303 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
305 switch (myConstructorId)
309 if ( myEditCurrentArgument == LineEditC1A1 ) {
312 else if ( myEditCurrentArgument == LineEditC1A2 ) {
323 Standard_Boolean testResult ;
324 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
326 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
329 if ( myEditCurrentArgument == LineEditC1A1 &&
330 S.ShapeType() != TopAbs_COMPSOLID &&
331 S.ShapeType() != TopAbs_COMPOUND &&
332 S.ShapeType() != TopAbs_SOLID &&
333 S.ShapeType() != TopAbs_SHAPE ) {
334 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
338 LineEditC1A1->setText(aString) ;
341 else if ( myEditCurrentArgument == LineEditC1A2 && ( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) {
342 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
346 LineEditC1A2->setText(aString) ;
350 if (myOkShape1 && myOkShape2 && !myShape1.IsNull() && !myShape2.IsNull())
356 if( myShape2.ShapeType() == TopAbs_WIRE )
357 aWire = TopoDS::Wire(myShape2) ;
359 if ( myShape2.ShapeType() == TopAbs_EDGE )
361 TopoDS_Edge aEdge = TopoDS::Edge(myShape2) ;
362 aWire = BRepBuilderAPI_MakeWire(aEdge);
368 tds = BRepOffsetAPI_MakePipe(aWire,myShape1 ) ;
369 if ( BRepAlgoAPI::IsValid(tds) )
372 mySimulationTopoDs = tds;
373 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
376 catch(Standard_Failure)
384 //=================================================================================
385 // function : SetEditCurrentArgument()
387 //=================================================================================
388 void GeometryGUI_PipeDlg::SetEditCurrentArgument()
390 QPushButton* send = (QPushButton*)sender();
391 switch (myConstructorId)
393 case 0: /* default constructor */
395 if( send == SelectButtonC1A1 ) {
396 LineEditC1A1->setFocus() ;
397 myEditCurrentArgument = LineEditC1A1 ;
399 else if(send == SelectButtonC1A2) {
400 LineEditC1A2->setFocus() ;
401 myEditCurrentArgument = LineEditC1A2;
403 SelectionIntoArgument() ;
411 //=================================================================================
412 // function : LineEditReturnPressed()
414 //=================================================================================
415 void GeometryGUI_PipeDlg::LineEditReturnPressed()
417 QLineEdit* send = (QLineEdit*)sender();
418 if( send == LineEditC1A1 )
419 myEditCurrentArgument = LineEditC1A1 ;
420 else if ( send == LineEditC1A2 )
421 myEditCurrentArgument = LineEditC1A2 ;
425 /* User name of object input management */
426 /* If successfull the selection is changed and signal emitted... */
427 /* so SelectionIntoArgument() is automatically called. */
428 const QString objectUserName = myEditCurrentArgument->text() ;
429 QWidget* thisWidget = (QWidget*)this ;
430 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
431 myEditCurrentArgument->setText( objectUserName ) ;
437 //=================================================================================
438 // function : DeactivateActiveDialog()
440 //=================================================================================
441 void GeometryGUI_PipeDlg::DeactivateActiveDialog()
443 if ( GroupConstructors->isEnabled() ) {
444 GroupConstructors->setEnabled(false) ;
445 GroupC1->setEnabled(false) ;
446 GroupButtons->setEnabled(false) ;
447 disconnect( mySelection, 0, this, 0 );
448 myGeomGUI->EraseSimulationShape() ;
456 //=================================================================================
457 // function : closeEvent()
459 //=================================================================================
460 void GeometryGUI_PipeDlg::closeEvent( QCloseEvent* e )
462 this->ClickOnCancel() ; /* same than click on cancel button */
466 //=================================================================================
467 // function : enterEvent()
468 // purpose : when mouse enter onto the QWidget
469 //=================================================================================
470 void GeometryGUI_PipeDlg::enterEvent( QEvent * )
472 if ( GroupConstructors->isEnabled() )
474 ActivateThisDialog() ;
479 //=================================================================================
480 // function : ActivateThisDialog()
482 //=================================================================================
483 void GeometryGUI_PipeDlg::ActivateThisDialog()
485 /* Emit a signal to deactivate any active dialog */
486 myGeomGUI->EmitSignalDeactivateDialog() ;
487 GroupConstructors->setEnabled(true) ;
488 GroupC1->setEnabled(true) ;
489 GroupButtons->setEnabled(true) ;
490 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
491 if( !mySimulationTopoDs.IsNull() )
492 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;