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_PipeDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_PipeDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
46 #include <qwhatsthis.h>
50 #include <Standard_ErrorHandler.hxx>
51 #include <Standard_Failure.hxx>
52 #include <BRepOffsetAPI_MakePipe.hxx>
53 #if OCC_VERSION_MAJOR >= 5
54 #include <BRepAlgo.hxx>
56 #include <BRepAlgoAPI.hxx>
60 //=================================================================================
61 // class : GeometryGUI_PipeDlg()
62 // purpose : Constructs a GeometryGUI_PipeDlg which is a child of 'parent', with the
63 // name 'name' and widget flags set to 'f'.
64 // The dialog will by default be modeless, unless you set 'modal' to
65 // TRUE to construct a modal dialog.
66 //=================================================================================
67 GeometryGUI_PipeDlg::GeometryGUI_PipeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
68 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
70 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PIPE")));
71 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
74 setName( "GeometryGUI_PipeDlg" );
76 setCaption( tr( "GEOM_PIPE_TITLE" ) );
77 setSizeGripEnabled( TRUE );
78 GeometryGUI_PipeDlgLayout = new QGridLayout( this );
79 GeometryGUI_PipeDlgLayout->setSpacing( 6 );
80 GeometryGUI_PipeDlgLayout->setMargin( 11 );
82 /***************************************************************/
83 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
84 GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
85 GroupConstructors->setExclusive( TRUE );
86 GroupConstructors->setColumnLayout(0, Qt::Vertical );
87 GroupConstructors->layout()->setSpacing( 0 );
88 GroupConstructors->layout()->setMargin( 0 );
89 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
90 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
91 GroupConstructorsLayout->setSpacing( 6 );
92 GroupConstructorsLayout->setMargin( 11 );
93 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
94 Constructor1->setText( tr( "" ) );
95 Constructor1->setPixmap( image0 );
96 Constructor1->setChecked( TRUE );
97 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
98 Constructor1->setMinimumSize( QSize( 50, 0 ) );
99 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
100 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
101 GroupConstructorsLayout->addItem( spacer, 0, 1 );
102 GeometryGUI_PipeDlgLayout->addWidget( GroupConstructors, 0, 0 );
105 GroupButtons = new QGroupBox( this, "GroupButtons" );
106 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
107 GroupButtons->setTitle( tr( "" ) );
108 GroupButtons->setColumnLayout(0, Qt::Vertical );
109 GroupButtons->layout()->setSpacing( 0 );
110 GroupButtons->layout()->setMargin( 0 );
111 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
112 GroupButtonsLayout->setAlignment( Qt::AlignTop );
113 GroupButtonsLayout->setSpacing( 6 );
114 GroupButtonsLayout->setMargin( 11 );
115 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
116 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
117 buttonCancel->setAutoDefault( TRUE );
118 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
119 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
120 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
121 buttonApply->setAutoDefault( TRUE );
122 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
123 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
124 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
125 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
126 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
127 buttonOk->setAutoDefault( TRUE );
128 buttonOk->setDefault( TRUE );
129 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
130 GeometryGUI_PipeDlgLayout->addWidget( GroupButtons, 2, 0 );
132 /***************************************************************/
133 GroupC1 = new QGroupBox( this, "GroupC1" );
134 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
135 GroupC1->setMinimumSize( QSize( 0, 0 ) );
136 GroupC1->setFrameShape( QGroupBox::Box );
137 GroupC1->setFrameShadow( QGroupBox::Sunken );
138 GroupC1->setColumnLayout(0, Qt::Vertical );
139 GroupC1->layout()->setSpacing( 0 );
140 GroupC1->layout()->setMargin( 0 );
141 GroupC1Layout = new QGridLayout( GroupC1->layout() );
142 GroupC1Layout->setAlignment( Qt::AlignTop );
143 GroupC1Layout->setSpacing( 6 );
144 GroupC1Layout->setMargin( 11 );
145 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
146 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
147 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
148 SelectButtonC1A1->setText( tr( "" ) );
149 SelectButtonC1A1->setPixmap( image1 );
150 SelectButtonC1A1->setToggleButton( FALSE );
151 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
152 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
153 TextLabelC1A1->setText( tr( "GEOM_BASE_OBJECT" ) );
154 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
155 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
156 TextLabelC1A1->setFrameShadow( QLabel::Plain );
157 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
158 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
159 TextLabelC1A2->setText( tr( "GEOM_PATH_OBJECT" ) );
160 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
161 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
162 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
163 SelectButtonC1A2->setText( tr( "" ) );
164 SelectButtonC1A2->setPixmap( image1 );
165 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
166 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
167 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
168 GeometryGUI_PipeDlgLayout->addWidget( GroupC1, 1, 0 );
169 /***************************************************************/
176 //=================================================================================
177 // function : ~GeometryGUI_PipeDlg()
178 // purpose : Destroys the object and frees any allocated resources
179 //=================================================================================
180 GeometryGUI_PipeDlg::~GeometryGUI_PipeDlg()
182 /* no need to delete child widgets, Qt does it all for us */
186 //=================================================================================
189 //=================================================================================
190 void GeometryGUI_PipeDlg::Init( SALOME_Selection* Sel )
195 myConstructorId = 0 ;
197 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
200 myConstructorId = 0 ;
201 myEditCurrentArgument = LineEditC1A1 ;
202 Constructor1->setChecked( TRUE );
203 myOkShape1 = myOkShape2 = false ;
205 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
206 mySimulationTopoDs.Nullify() ;
208 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
209 myGeom = GEOM::GEOM_Gen::_narrow(comp);
211 // TODO : previous selection into argument ?
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
216 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
217 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
218 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
219 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
221 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
222 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
224 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
225 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
226 /* to close dialog if study change */
227 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
229 /* Move widget on the botton right corner of main widget */
231 myGeomGUI->DefineDlgPosition( this, x, y ) ;
233 this->show() ; /* Displays Dialog */
240 //=================================================================================
241 // function : ConstructorsClicked()
242 // purpose : Radio button management
243 //=================================================================================
244 void GeometryGUI_PipeDlg::ConstructorsClicked(int constructorId)
246 myGeomGUI->EraseSimulationShape() ;
247 mySimulationTopoDs.Nullify() ;
248 //GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
250 switch (constructorId)
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void GeometryGUI_PipeDlg::ClickOnOk()
266 this->ClickOnApply() ;
267 this->ClickOnCancel() ;
273 //=================================================================================
274 // function : ClickOnAply()
276 //=================================================================================
277 void GeometryGUI_PipeDlg::ClickOnApply()
279 myGeomGUI->EraseSimulationShape() ;
280 mySimulationTopoDs.Nullify() ;
281 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
283 switch(myConstructorId)
287 if(myOkShape1 && myOkShape2) {
288 myGeomGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1) ;
299 //=================================================================================
300 // function : ClickOnCancel()
302 //=================================================================================
303 void GeometryGUI_PipeDlg::ClickOnCancel()
305 myGeomGUI->EraseSimulationShape() ;
306 mySimulationTopoDs.Nullify() ;
307 disconnect( mySelection, 0, this, 0 );
308 myGeomGUI->ResetState() ;
315 //=================================================================================
316 // function : SelectionIntoArgument()
317 // purpose : Called when selection has changed
318 //=================================================================================
319 void GeometryGUI_PipeDlg::SelectionIntoArgument()
321 myGeomGUI->EraseSimulationShape() ;
322 mySimulationTopoDs.Nullify() ;
324 myEditCurrentArgument->setText("") ;
325 QString aString = ""; /* name of future selection */
327 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
329 switch (myConstructorId)
333 if ( myEditCurrentArgument == LineEditC1A1 ) {
336 else if ( myEditCurrentArgument == LineEditC1A2 ) {
347 Standard_Boolean testResult ;
348 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
350 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
353 if ( myEditCurrentArgument == LineEditC1A1 &&
354 S.ShapeType() != TopAbs_COMPSOLID &&
355 S.ShapeType() != TopAbs_COMPOUND &&
356 S.ShapeType() != TopAbs_SOLID &&
357 S.ShapeType() != TopAbs_SHAPE ) {
358 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
362 LineEditC1A1->setText(aString) ;
365 else if ( myEditCurrentArgument == LineEditC1A2 && ( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) {
366 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
370 LineEditC1A2->setText(aString) ;
374 if (myOkShape1 && myOkShape2 && !myShape1.IsNull() && !myShape2.IsNull())
380 if( myShape2.ShapeType() == TopAbs_WIRE )
381 aWire = TopoDS::Wire(myShape2) ;
383 if ( myShape2.ShapeType() == TopAbs_EDGE )
385 TopoDS_Edge aEdge = TopoDS::Edge(myShape2) ;
386 aWire = BRepBuilderAPI_MakeWire(aEdge);
392 tds = BRepOffsetAPI_MakePipe(aWire,myShape1 ) ;
393 #if OCC_VERSION_MAJOR >= 5
394 if ( BRepAlgo::IsValid(tds) )
396 if ( BRepAlgoAPI::IsValid(tds) )
400 mySimulationTopoDs = tds;
401 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
404 catch(Standard_Failure)
412 //=================================================================================
413 // function : SetEditCurrentArgument()
415 //=================================================================================
416 void GeometryGUI_PipeDlg::SetEditCurrentArgument()
418 QPushButton* send = (QPushButton*)sender();
419 switch (myConstructorId)
421 case 0: /* default constructor */
423 if( send == SelectButtonC1A1 ) {
424 LineEditC1A1->setFocus() ;
425 myEditCurrentArgument = LineEditC1A1 ;
427 else if(send == SelectButtonC1A2) {
428 LineEditC1A2->setFocus() ;
429 myEditCurrentArgument = LineEditC1A2;
431 SelectionIntoArgument() ;
439 //=================================================================================
440 // function : LineEditReturnPressed()
442 //=================================================================================
443 void GeometryGUI_PipeDlg::LineEditReturnPressed()
445 QLineEdit* send = (QLineEdit*)sender();
446 if( send == LineEditC1A1 )
447 myEditCurrentArgument = LineEditC1A1 ;
448 else if ( send == LineEditC1A2 )
449 myEditCurrentArgument = LineEditC1A2 ;
453 /* User name of object input management */
454 /* If successfull the selection is changed and signal emitted... */
455 /* so SelectionIntoArgument() is automatically called. */
456 const QString objectUserName = myEditCurrentArgument->text() ;
457 QWidget* thisWidget = (QWidget*)this ;
458 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
459 myEditCurrentArgument->setText( objectUserName ) ;
465 //=================================================================================
466 // function : DeactivateActiveDialog()
468 //=================================================================================
469 void GeometryGUI_PipeDlg::DeactivateActiveDialog()
471 if ( GroupConstructors->isEnabled() ) {
472 GroupConstructors->setEnabled(false) ;
473 GroupC1->setEnabled(false) ;
474 GroupButtons->setEnabled(false) ;
475 disconnect( mySelection, 0, this, 0 );
476 myGeomGUI->EraseSimulationShape() ;
484 //=================================================================================
485 // function : closeEvent()
487 //=================================================================================
488 void GeometryGUI_PipeDlg::closeEvent( QCloseEvent* e )
490 this->ClickOnCancel() ; /* same than click on cancel button */
494 //=================================================================================
495 // function : enterEvent()
496 // purpose : when mouse enter onto the QWidget
497 //=================================================================================
498 void GeometryGUI_PipeDlg::enterEvent( QEvent * )
500 if ( GroupConstructors->isEnabled() )
502 ActivateThisDialog() ;
507 //=================================================================================
508 // function : ActivateThisDialog()
510 //=================================================================================
511 void GeometryGUI_PipeDlg::ActivateThisDialog()
513 /* Emit a signal to deactivate any active dialog */
514 myGeomGUI->EmitSignalDeactivateDialog() ;
515 GroupConstructors->setEnabled(true) ;
516 GroupC1->setEnabled(true) ;
517 GroupButtons->setEnabled(true) ;
518 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
519 if( !mySimulationTopoDs.IsNull() )
520 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;