]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_PipeDlg.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/geom.git] / src / GEOMGUI / GeometryGUI_PipeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GeometryGUI_PipeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_PipeDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
39 #include <qlabel.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
43 #include <qlayout.h>
44 #include <qvariant.h>
45 #include <qtooltip.h>
46 #include <qwhatsthis.h>
47 #include <qimage.h>
48 #include <qpixmap.h>
49
50 #include <Standard_ErrorHandler.hxx> 
51 #include <Standard_Failure.hxx>
52 #include <BRepOffsetAPI_MakePipe.hxx> 
53 #include <BRepAlgoAPI.hxx>
54
55
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 )
65 {
66     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_PIPE")));
67     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
68
69     if ( !name )
70         setName( "GeometryGUI_PipeDlg" );
71     resize( 303, 225 ); 
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 );
77     
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 );
99
100
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 );
127
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     /***************************************************************/
166
167     /* Initialisation */
168     Init( Sel ) ; 
169 }
170
171
172 //=================================================================================
173 // function : ~GeometryGUI_PipeDlg()
174 // purpose  : Destroys the object and frees any allocated resources
175 //=================================================================================
176 GeometryGUI_PipeDlg::~GeometryGUI_PipeDlg()
177 {
178   /* no need to delete child widgets, Qt does it all for us */
179 }
180
181
182 //=================================================================================
183 // function : Init()
184 // purpose  :
185 //=================================================================================
186 void GeometryGUI_PipeDlg::Init( SALOME_Selection* Sel )
187 {  
188   mySelection = Sel ;
189   myShape1.Nullify() ;
190   myShape2.Nullify() ;
191   myConstructorId = 0 ;
192   
193   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
194
195   GroupC1->show();
196   myConstructorId = 0 ;
197   myEditCurrentArgument = LineEditC1A1 ;        
198   Constructor1->setChecked( TRUE );
199   myOkShape1 = myOkShape2 = false ;
200
201   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
202   mySimulationTopoDs.Nullify() ;
203
204   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
205   myGeom = GEOM::GEOM_Gen::_narrow(comp);
206   
207   // TODO : previous selection into argument ?
208
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() ) ) ;
216
217   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
218   connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
219
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() ) ) ;
224  
225   /* Move widget on the botton right corner of main widget */
226   int x, y ;
227   myGeomGUI->DefineDlgPosition( this, x, y ) ;
228   this->move( x, y ) ;
229   this->show() ; /* Displays Dialog */ 
230
231   return ;
232 }
233
234
235
236 //=================================================================================
237 // function : ConstructorsClicked()
238 // purpose  : Radio button management
239 //=================================================================================
240 void GeometryGUI_PipeDlg::ConstructorsClicked(int constructorId)
241 {
242   myGeomGUI->EraseSimulationShape() ;
243   mySimulationTopoDs.Nullify() ;
244   //GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
245
246   switch (constructorId)
247     {
248     case 0:
249       { 
250         break;
251       }
252     }
253  return ;
254 }
255
256 //=================================================================================
257 // function : ClickOnOk()
258 // purpose  :
259 //=================================================================================
260 void GeometryGUI_PipeDlg::ClickOnOk()
261 {
262   this->ClickOnApply() ;
263   this->ClickOnCancel() ;
264
265   return ;
266 }
267
268
269 //=================================================================================
270 // function : ClickOnAply()
271 // purpose  :
272 //=================================================================================
273 void GeometryGUI_PipeDlg::ClickOnApply()
274 {
275   myGeomGUI->EraseSimulationShape() ;
276   mySimulationTopoDs.Nullify() ;
277   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
278
279   switch(myConstructorId)
280     { 
281     case 0 :
282       {
283         if(myOkShape1 && myOkShape2) {    
284           myGeomGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1) ;
285         }
286         break ;
287       }
288     }
289   // accept();
290   return ;
291 }
292
293
294
295 //=================================================================================
296 // function : ClickOnCancel()
297 // purpose  :
298 //=================================================================================
299 void GeometryGUI_PipeDlg::ClickOnCancel()
300 {
301   myGeomGUI->EraseSimulationShape() ;
302   mySimulationTopoDs.Nullify() ;
303   disconnect( mySelection, 0, this, 0 );
304   myGeomGUI->ResetState() ;
305   reject() ;
306   return ;
307 }
308
309
310
311 //=================================================================================
312 // function : SelectionIntoArgument()
313 // purpose  : Called when selection has changed
314 //=================================================================================
315 void GeometryGUI_PipeDlg::SelectionIntoArgument()
316 {
317   myGeomGUI->EraseSimulationShape() ;
318   mySimulationTopoDs.Nullify() ;
319
320   myEditCurrentArgument->setText("") ;
321   QString aString = ""; /* name of future selection */
322
323   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
324   if ( nbSel != 1 ) {
325     switch (myConstructorId) 
326       {
327       case 0:
328         {
329           if ( myEditCurrentArgument == LineEditC1A1 ) {
330             myOkShape1 = false ;
331           }
332           else if ( myEditCurrentArgument == LineEditC1A2 ) {
333             myOkShape2 = false ;
334           }
335           break ;
336         } 
337       }
338     return ;
339   }
340
341   /*  nbSel == 1  */ 
342   TopoDS_Shape S;
343   Standard_Boolean testResult ;
344   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
345   
346   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
347     return ;  
348  
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) ;
355     if( !testResult )
356       return ;
357     myShape1 = S ;
358     LineEditC1A1->setText(aString) ;
359     myOkShape1 = true ;
360   }    
361   else if ( myEditCurrentArgument == LineEditC1A2 && ( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) {
362     myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
363     if( !testResult )
364       return ; 
365     myShape2 = S ;
366     LineEditC1A2->setText(aString) ;
367     myOkShape2 = true ;
368   }
369
370   if (myOkShape1 && myOkShape2 && !myShape1.IsNull() && !myShape2.IsNull())
371     {
372         //Make preview
373         TopoDS_Shape tds ;
374         TopoDS_Wire aWire ;
375
376         if( myShape2.ShapeType() == TopAbs_WIRE ) 
377             aWire = TopoDS::Wire(myShape2) ;
378         else 
379             if ( myShape2.ShapeType() == TopAbs_EDGE ) 
380                 {
381                         TopoDS_Edge aEdge = TopoDS::Edge(myShape2) ;
382                         aWire = BRepBuilderAPI_MakeWire(aEdge);
383
384                 }
385
386         try 
387         {
388                 tds = BRepOffsetAPI_MakePipe(aWire,myShape1 ) ;
389                 if (  BRepAlgoAPI::IsValid(tds) ) 
390                 {
391                         //Draw Pipe
392                         mySimulationTopoDs = tds;
393                         myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
394                 }
395         }
396         catch(Standard_Failure) 
397         {
398         }
399     }
400 }
401
402
403
404 //=================================================================================
405 // function : SetEditCurrentArgument()
406 // purpose  :
407 //=================================================================================
408 void GeometryGUI_PipeDlg::SetEditCurrentArgument()
409 {
410   QPushButton* send = (QPushButton*)sender();
411   switch (myConstructorId)
412     {
413     case 0: /* default constructor */
414       { 
415         if( send == SelectButtonC1A1 ) {
416           LineEditC1A1->setFocus() ;
417           myEditCurrentArgument = LineEditC1A1 ;
418         }
419         else if(send == SelectButtonC1A2) {
420           LineEditC1A2->setFocus() ;
421           myEditCurrentArgument = LineEditC1A2;
422         }
423         SelectionIntoArgument() ;
424         break;
425       }
426     }
427   return ;
428 }
429
430
431 //=================================================================================
432 // function : LineEditReturnPressed()
433 // purpose  :
434 //=================================================================================
435 void GeometryGUI_PipeDlg::LineEditReturnPressed()
436 {
437   QLineEdit* send = (QLineEdit*)sender();  
438   if( send == LineEditC1A1 )
439     myEditCurrentArgument = LineEditC1A1 ;
440   else if ( send == LineEditC1A2 )
441     myEditCurrentArgument = LineEditC1A2 ; 
442   else
443     return ;
444   
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 ) ;
452   }
453   return ;
454 }
455
456
457 //=================================================================================
458 // function : DeactivateActiveDialog()
459 // purpose  :
460 //=================================================================================
461 void GeometryGUI_PipeDlg::DeactivateActiveDialog()
462 {
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() ;
469   }
470   return ;
471 }
472
473
474
475
476 //=================================================================================
477 // function : closeEvent()
478 // purpose  :
479 //=================================================================================
480 void GeometryGUI_PipeDlg::closeEvent( QCloseEvent* e )
481 {
482   this->ClickOnCancel() ; /* same than click on cancel button */
483 }
484
485
486 //=================================================================================
487 // function : enterEvent()
488 // purpose  : when mouse enter onto the QWidget
489 //=================================================================================
490 void GeometryGUI_PipeDlg::enterEvent( QEvent *  )
491 {
492   if ( GroupConstructors->isEnabled() )
493     return ;
494   ActivateThisDialog() ;
495 }
496
497
498
499 //=================================================================================
500 // function : ActivateThisDialog()
501 // purpose  :
502 //=================================================================================
503 void GeometryGUI_PipeDlg::ActivateThisDialog()
504 {
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 ) ;
513   return ;
514 }