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 #include <BRepAlgoAPI.hxx>
56 //=================================================================================
57 // class : GeometryGUI_PipeDlg()
58 // purpose : Constructs a GeometryGUI_PipeDlg which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // TRUE to construct a modal dialog.
62 //=================================================================================
63 GeometryGUI_PipeDlg::GeometryGUI_PipeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PIPE")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
70 setName( "GeometryGUI_PipeDlg" );
72 setCaption( tr( "GEOM_PIPE_TITLE" ) );
73 setSizeGripEnabled( TRUE );
74 GeometryGUI_PipeDlgLayout = new QGridLayout( this );
75 GeometryGUI_PipeDlgLayout->setSpacing( 6 );
76 GeometryGUI_PipeDlgLayout->setMargin( 11 );
78 /***************************************************************/
79 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
80 GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
81 GroupConstructors->setExclusive( TRUE );
82 GroupConstructors->setColumnLayout(0, Qt::Vertical );
83 GroupConstructors->layout()->setSpacing( 0 );
84 GroupConstructors->layout()->setMargin( 0 );
85 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
86 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
87 GroupConstructorsLayout->setSpacing( 6 );
88 GroupConstructorsLayout->setMargin( 11 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
94 Constructor1->setMinimumSize( QSize( 50, 0 ) );
95 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
96 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupConstructorsLayout->addItem( spacer, 0, 1 );
98 GeometryGUI_PipeDlgLayout->addWidget( GroupConstructors, 0, 0 );
101 GroupButtons = new QGroupBox( this, "GroupButtons" );
102 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
103 GroupButtons->setTitle( tr( "" ) );
104 GroupButtons->setColumnLayout(0, Qt::Vertical );
105 GroupButtons->layout()->setSpacing( 0 );
106 GroupButtons->layout()->setMargin( 0 );
107 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
108 GroupButtonsLayout->setAlignment( Qt::AlignTop );
109 GroupButtonsLayout->setSpacing( 6 );
110 GroupButtonsLayout->setMargin( 11 );
111 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
112 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
113 buttonCancel->setAutoDefault( TRUE );
114 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
115 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
116 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
117 buttonApply->setAutoDefault( TRUE );
118 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
119 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
121 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
122 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
123 buttonOk->setAutoDefault( TRUE );
124 buttonOk->setDefault( TRUE );
125 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
126 GeometryGUI_PipeDlgLayout->addWidget( GroupButtons, 2, 0 );
128 /***************************************************************/
129 GroupC1 = new QGroupBox( this, "GroupC1" );
130 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
131 GroupC1->setMinimumSize( QSize( 0, 0 ) );
132 GroupC1->setFrameShape( QGroupBox::Box );
133 GroupC1->setFrameShadow( QGroupBox::Sunken );
134 GroupC1->setColumnLayout(0, Qt::Vertical );
135 GroupC1->layout()->setSpacing( 0 );
136 GroupC1->layout()->setMargin( 0 );
137 GroupC1Layout = new QGridLayout( GroupC1->layout() );
138 GroupC1Layout->setAlignment( Qt::AlignTop );
139 GroupC1Layout->setSpacing( 6 );
140 GroupC1Layout->setMargin( 11 );
141 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
142 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
143 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
144 SelectButtonC1A1->setText( tr( "" ) );
145 SelectButtonC1A1->setPixmap( image1 );
146 SelectButtonC1A1->setToggleButton( FALSE );
147 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
148 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
149 TextLabelC1A1->setText( tr( "GEOM_BASE_OBJECT" ) );
150 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
151 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
152 TextLabelC1A1->setFrameShadow( QLabel::Plain );
153 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
154 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
155 TextLabelC1A2->setText( tr( "GEOM_PATH_OBJECT" ) );
156 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
157 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
158 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
159 SelectButtonC1A2->setText( tr( "" ) );
160 SelectButtonC1A2->setPixmap( image1 );
161 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
162 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
163 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
164 GeometryGUI_PipeDlgLayout->addWidget( GroupC1, 1, 0 );
165 /***************************************************************/
172 //=================================================================================
173 // function : ~GeometryGUI_PipeDlg()
174 // purpose : Destroys the object and frees any allocated resources
175 //=================================================================================
176 GeometryGUI_PipeDlg::~GeometryGUI_PipeDlg()
178 /* no need to delete child widgets, Qt does it all for us */
182 //=================================================================================
185 //=================================================================================
186 void GeometryGUI_PipeDlg::Init( SALOME_Selection* Sel )
191 myConstructorId = 0 ;
193 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
196 myConstructorId = 0 ;
197 myEditCurrentArgument = LineEditC1A1 ;
198 Constructor1->setChecked( TRUE );
199 myOkShape1 = myOkShape2 = false ;
201 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
202 mySimulationTopoDs.Nullify() ;
204 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
205 myGeom = GEOM::GEOM_Gen::_narrow(comp);
207 // TODO : previous selection into argument ?
209 /* signals and slots connections */
210 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
211 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
212 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
213 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
214 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
215 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
217 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
218 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
220 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
221 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
222 /* to close dialog if study change */
223 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
225 /* Move widget on the botton right corner of main widget */
227 myGeomGUI->DefineDlgPosition( this, x, y ) ;
229 this->show() ; /* Displays Dialog */
236 //=================================================================================
237 // function : ConstructorsClicked()
238 // purpose : Radio button management
239 //=================================================================================
240 void GeometryGUI_PipeDlg::ConstructorsClicked(int constructorId)
242 myGeomGUI->EraseSimulationShape() ;
243 mySimulationTopoDs.Nullify() ;
244 //GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
246 switch (constructorId)
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void GeometryGUI_PipeDlg::ClickOnOk()
262 this->ClickOnApply() ;
263 this->ClickOnCancel() ;
269 //=================================================================================
270 // function : ClickOnAply()
272 //=================================================================================
273 void GeometryGUI_PipeDlg::ClickOnApply()
275 myGeomGUI->EraseSimulationShape() ;
276 mySimulationTopoDs.Nullify() ;
277 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
279 switch(myConstructorId)
283 if(myOkShape1 && myOkShape2) {
284 myGeomGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1) ;
295 //=================================================================================
296 // function : ClickOnCancel()
298 //=================================================================================
299 void GeometryGUI_PipeDlg::ClickOnCancel()
301 myGeomGUI->EraseSimulationShape() ;
302 mySimulationTopoDs.Nullify() ;
303 disconnect( mySelection, 0, this, 0 );
304 myGeomGUI->ResetState() ;
311 //=================================================================================
312 // function : SelectionIntoArgument()
313 // purpose : Called when selection has changed
314 //=================================================================================
315 void GeometryGUI_PipeDlg::SelectionIntoArgument()
317 myGeomGUI->EraseSimulationShape() ;
318 mySimulationTopoDs.Nullify() ;
320 myEditCurrentArgument->setText("") ;
321 QString aString = ""; /* name of future selection */
323 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
325 switch (myConstructorId)
329 if ( myEditCurrentArgument == LineEditC1A1 ) {
332 else if ( myEditCurrentArgument == LineEditC1A2 ) {
343 Standard_Boolean testResult ;
344 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
346 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
349 if ( myEditCurrentArgument == LineEditC1A1 &&
350 S.ShapeType() != TopAbs_COMPSOLID &&
351 S.ShapeType() != TopAbs_COMPOUND &&
352 S.ShapeType() != TopAbs_SOLID &&
353 S.ShapeType() != TopAbs_SHAPE ) {
354 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
358 LineEditC1A1->setText(aString) ;
361 else if ( myEditCurrentArgument == LineEditC1A2 && ( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) {
362 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
366 LineEditC1A2->setText(aString) ;
370 if (myOkShape1 && myOkShape2 && !myShape1.IsNull() && !myShape2.IsNull())
376 if( myShape2.ShapeType() == TopAbs_WIRE )
377 aWire = TopoDS::Wire(myShape2) ;
379 if ( myShape2.ShapeType() == TopAbs_EDGE )
381 TopoDS_Edge aEdge = TopoDS::Edge(myShape2) ;
382 aWire = BRepBuilderAPI_MakeWire(aEdge);
388 tds = BRepOffsetAPI_MakePipe(aWire,myShape1 ) ;
389 if ( BRepAlgoAPI::IsValid(tds) )
392 mySimulationTopoDs = tds;
393 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
396 catch(Standard_Failure)
404 //=================================================================================
405 // function : SetEditCurrentArgument()
407 //=================================================================================
408 void GeometryGUI_PipeDlg::SetEditCurrentArgument()
410 QPushButton* send = (QPushButton*)sender();
411 switch (myConstructorId)
413 case 0: /* default constructor */
415 if( send == SelectButtonC1A1 ) {
416 LineEditC1A1->setFocus() ;
417 myEditCurrentArgument = LineEditC1A1 ;
419 else if(send == SelectButtonC1A2) {
420 LineEditC1A2->setFocus() ;
421 myEditCurrentArgument = LineEditC1A2;
423 SelectionIntoArgument() ;
431 //=================================================================================
432 // function : LineEditReturnPressed()
434 //=================================================================================
435 void GeometryGUI_PipeDlg::LineEditReturnPressed()
437 QLineEdit* send = (QLineEdit*)sender();
438 if( send == LineEditC1A1 )
439 myEditCurrentArgument = LineEditC1A1 ;
440 else if ( send == LineEditC1A2 )
441 myEditCurrentArgument = LineEditC1A2 ;
445 /* User name of object input management */
446 /* If successfull the selection is changed and signal emitted... */
447 /* so SelectionIntoArgument() is automatically called. */
448 const QString objectUserName = myEditCurrentArgument->text() ;
449 QWidget* thisWidget = (QWidget*)this ;
450 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
451 myEditCurrentArgument->setText( objectUserName ) ;
457 //=================================================================================
458 // function : DeactivateActiveDialog()
460 //=================================================================================
461 void GeometryGUI_PipeDlg::DeactivateActiveDialog()
463 if ( GroupConstructors->isEnabled() ) {
464 GroupConstructors->setEnabled(false) ;
465 GroupC1->setEnabled(false) ;
466 GroupButtons->setEnabled(false) ;
467 disconnect( mySelection, 0, this, 0 );
468 myGeomGUI->EraseSimulationShape() ;
476 //=================================================================================
477 // function : closeEvent()
479 //=================================================================================
480 void GeometryGUI_PipeDlg::closeEvent( QCloseEvent* e )
482 this->ClickOnCancel() ; /* same than click on cancel button */
486 //=================================================================================
487 // function : enterEvent()
488 // purpose : when mouse enter onto the QWidget
489 //=================================================================================
490 void GeometryGUI_PipeDlg::enterEvent( QEvent * )
492 if ( GroupConstructors->isEnabled() )
494 ActivateThisDialog() ;
499 //=================================================================================
500 // function : ActivateThisDialog()
502 //=================================================================================
503 void GeometryGUI_PipeDlg::ActivateThisDialog()
505 /* Emit a signal to deactivate any active dialog */
506 myGeomGUI->EmitSignalDeactivateDialog() ;
507 GroupConstructors->setEnabled(true) ;
508 GroupC1->setEnabled(true) ;
509 GroupButtons->setEnabled(true) ;
510 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
511 if( !mySimulationTopoDs.IsNull() )
512 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;