Salome HOME
sources v1.2
[modules/geom.git] / src / GEOMGUI / GeometryGUI_SubShapeDlg.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_SubShapeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_SubShapeDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_RightFrame.h"
36 #include "OCCViewer_Viewer3d.h"
37 #include "utilities.h"
38
39 #include <TopExp_Explorer.hxx>
40
41 #include <qbuttongroup.h>
42 #include <qcheckbox.h>
43 #include <qcombobox.h>
44 #include <qgroupbox.h>
45 #include <qlabel.h>
46 #include <qlineedit.h>
47 #include <qpushbutton.h>
48 #include <qradiobutton.h>
49 #include <qlayout.h>
50 #include <qvariant.h>
51 #include <qtooltip.h>
52 #include <qwhatsthis.h>
53 #include <qimage.h>
54 #include <qpixmap.h>
55
56
57 #include <qmessagebox.h> 
58
59 //=================================================================================
60 // class    : GeometryGUI_SubShapeDlg()
61 // purpose  : Constructs a GeometryGUI_SubShapeDlg which is a child of 'parent', with the
62 //            name 'name' and widget flags set to 'f'.
63 //            The dialog will by default be modeless, unless you set 'modal' to
64 //            TRUE to construct a modal dialog.
65 //=================================================================================
66 GeometryGUI_SubShapeDlg::GeometryGUI_SubShapeDlg( QWidget* parent,
67                                                   const char* name,
68                                                   SALOME_Selection* Sel,
69                                                   Handle (AIS_InteractiveContext) ic,
70                                                   bool modal,
71                                                   WFlags fl )
72   
73     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
74 {
75     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SUBSHAPE")));
76     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
77
78     if ( !name )
79         setName( "GeometryGUI_SUBSHAPE" );
80     resize( 303, 239 ); 
81     setCaption( tr( "GEOM_SUBSHAPE_TITLE"  ) );
82     setSizeGripEnabled( TRUE );
83     GeometryGUI_SubShapeDlgLayout = new QGridLayout( this ); 
84     GeometryGUI_SubShapeDlgLayout->setSpacing( 6 );
85     GeometryGUI_SubShapeDlgLayout->setMargin( 11 );
86
87     /***************************************************************/
88     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
89     GroupConstructors->setTitle( tr( "GEOM_SUB_SHAPE"  ) );
90     GroupConstructors->setExclusive( TRUE );
91     GroupConstructors->setColumnLayout(0, Qt::Vertical );
92     GroupConstructors->layout()->setSpacing( 0 );
93     GroupConstructors->layout()->setMargin( 0 );
94     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
95     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
96     GroupConstructorsLayout->setSpacing( 6 );
97     GroupConstructorsLayout->setMargin( 11 );
98     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
99     Constructor1->setText( tr( ""  ) );
100     Constructor1->setPixmap( image0 );
101     Constructor1->setChecked( TRUE );
102     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
103     Constructor1->setMinimumSize( QSize( 50, 0 ) );
104     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
105     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
106     GroupConstructorsLayout->addItem( spacer, 0, 1 );
107     GeometryGUI_SubShapeDlgLayout->addWidget( GroupConstructors, 0, 0 );
108
109     /***************************************************************/
110     GroupButtons = new QGroupBox( this, "GroupButtons" );
111     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
112     GroupButtons->setTitle( tr( ""  ) );
113     GroupButtons->setColumnLayout(0, Qt::Vertical );
114     GroupButtons->layout()->setSpacing( 0 );
115     GroupButtons->layout()->setMargin( 0 );
116     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
117     GroupButtonsLayout->setAlignment( Qt::AlignTop );
118     GroupButtonsLayout->setSpacing( 6 );
119     GroupButtonsLayout->setMargin( 11 );
120     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
121     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
122     buttonCancel->setAutoDefault( TRUE );
123     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
124     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
125     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
126     buttonApply->setAutoDefault( TRUE );
127     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
128     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
129     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
130     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
131     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
132     buttonOk->setAutoDefault( TRUE );
133     buttonOk->setDefault( TRUE );
134     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
135     GeometryGUI_SubShapeDlgLayout->addWidget( GroupButtons, 2, 0 );
136
137     /***************************************************************/
138     GroupC1 = new QGroupBox( this, "GroupC1" );
139     GroupC1->setTitle( tr( "GEOM_ARGUMENTS"  ) );
140     GroupC1->setMinimumSize( QSize( 0, 0 ) );
141     GroupC1->setFrameShape( QGroupBox::Box );
142     GroupC1->setFrameShadow( QGroupBox::Sunken );
143     GroupC1->setColumnLayout(0, Qt::Vertical );
144     GroupC1->layout()->setSpacing( 0 );
145     GroupC1->layout()->setMargin( 0 );
146     GroupC1Layout = new QGridLayout( GroupC1->layout() );
147     GroupC1Layout->setAlignment( Qt::AlignTop );
148     GroupC1Layout->setSpacing( 6 );
149     GroupC1Layout->setMargin( 11 );
150     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
151     TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT"  ) );
152     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
153     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
154     TextLabelC1A1->setFrameShadow( QLabel::Plain );
155     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
156     TextLabelComboBox1 = new QLabel( GroupC1, "TextLabelComboBox1" );
157     TextLabelComboBox1->setText( tr( "GEOM_SUBSHAPE_TYPE"  ) );
158     GroupC1Layout->addMultiCellWidget( TextLabelComboBox1, 1, 1, 0, 1 );
159     ComboBox1 = new QComboBox( FALSE, GroupC1, "ComboBox1" );
160     ComboBox1->setMaxCount( 100 );
161     GroupC1Layout->addMultiCellWidget( ComboBox1, 1, 1, 2, 3 );
162     CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
163     CheckBox1->setText( tr( "GEOM_SUBSHAPE_SELECT"  ) );
164     CheckBox1->setChecked( FALSE );
165     GroupC1Layout->addMultiCellWidget( CheckBox1, 2, 2, 0, 1 );
166     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
167     GroupC1Layout->addMultiCellWidget( LineEditC1A1, 0, 0, 2, 3 );
168     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
169     SelectButtonC1A1->setText( tr( ""  ) );
170     SelectButtonC1A1->setPixmap( image1 );
171     SelectButtonC1A1->setToggleButton( FALSE );
172     SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
173     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
174     GeometryGUI_SubShapeDlgLayout->addWidget( GroupC1, 1, 0 );
175     /***************************************************************/
176    
177     /* Initialisations */
178     Init(Sel, ic) ;
179 }
180
181
182 //=================================================================================
183 // function : ~GeometryGUI_SubShapeDlg()
184 // purpose  : Destroys the object and frees any allocated resources
185 //=================================================================================
186 GeometryGUI_SubShapeDlg::~GeometryGUI_SubShapeDlg()
187 {
188     // no need to delete child widgets, Qt does it all for us
189 }
190
191
192 //=================================================================================
193 // function : Init()
194 // purpose  :
195 //=================================================================================
196 void GeometryGUI_SubShapeDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
197 {
198
199   GroupC1->show();
200   myConstructorId = 0 ;
201   Constructor1->setChecked( TRUE );
202   myEditCurrentArgument = LineEditC1A1 ;
203   mySelection = Sel;
204   myShape.Nullify() ;
205
206   myIC = ic ;
207   myUseLocalContext = false ;
208   myLocalContextId = -1;
209   myAbort = false ;
210   myOkShape = false ;
211   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
212
213   /* type for sub shape selection */
214   ComboBox1->insertItem("Compound");
215   ComboBox1->insertItem("Compsolid");
216   ComboBox1->insertItem("Solid");
217   ComboBox1->insertItem("Shell");
218   ComboBox1->insertItem("Face");
219   ComboBox1->insertItem("Wire");
220   ComboBox1->insertItem("Edge");
221   ComboBox1->insertItem("Vertex");
222   ComboBox1->insertItem("Shape");
223
224   myWithShape = true;
225   myShapeType = ComboBox1->currentItem();
226
227   /* Select sub shapes mode not checked */
228   CheckBox1->setChecked( FALSE );
229   myOkSelectSubMode = CheckBox1->isChecked();
230
231   // TODO : previous selection into argument ?
232
233   /* Filter definitions */
234   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
235   myGeom = GEOM::GEOM_Gen::_narrow(comp);
236
237   /* signals and slots connections */
238   connect( buttonOk, SIGNAL( clicked() ),            this, SLOT( ClickOnOk() ) );
239   connect( buttonCancel, SIGNAL( clicked() ),        this, SLOT( ClickOnCancel() ) ) ;
240   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
241   connect( GroupConstructors, SIGNAL(clicked(int) ), this, SLOT( ConstructorsClicked(int) ) );
242
243   connect( SelectButtonC1A1, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
244   connect( CheckBox1, SIGNAL (stateChanged(int) ), this, SLOT( AllOrNotAll() ) ) ;
245
246   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
247
248   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
249   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
250   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
251
252   connect( ComboBox1, SIGNAL( activated(int) ), this, SLOT( ComboTextChanged() ) );
253
254   /* Move widget on the botton right corner of main widget */
255   int x, y ;
256   myGeomGUI->DefineDlgPosition( this, x, y ) ;
257   this->move( x, y ) ;
258   this->show() ; /* display Dialog */
259   return ;
260 }
261
262
263 //=================================================================================
264 // function : ConstructorsClicked()
265 // purpose  : Radio button management
266 //=================================================================================
267 void GeometryGUI_SubShapeDlg::ConstructorsClicked(int constructorId)
268 {
269   return ;
270 }
271
272 //=================================================================================
273 // function : ClickOnOk()
274 // purpose  :
275 //=================================================================================
276 void GeometryGUI_SubShapeDlg::ClickOnOk()
277 {
278   this->ClickOnApply() ;
279
280   /* User has aborted or not operation of explode all with many sub shapes */
281   if( this->myAbort == false )
282     this->ClickOnCancel() ;
283   else
284     this->myAbort = false ;
285     
286   return ;
287 }
288
289
290 //=================================================================================
291 // function : ClickOnApply()
292 // purpose  :
293 //=================================================================================
294 void GeometryGUI_SubShapeDlg::ClickOnApply()
295 {
296   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
297   bool testResult = false ;
298
299   this->myAbort = false ; /* Not aborted by default */
300     
301   switch(myConstructorId)
302     { 
303     case 0 :
304       { 
305         /* Explode all sub shapes */
306         if( myOkShape && !myOkSelectSubMode ) {
307           
308           /* More than 30 subshapes : ask confirmation */
309           unsigned int nb = NumberOfSubShapes( myShape, myShapeType ) ;
310           if( nb > 30 ) {
311             const QString caption  = tr("GEOM_CONFIRM") ;
312             const QString text = tr("GEOM_CONFIRM_INFO").arg(nb) ;
313             const QString button0  = tr("GEOM_BUT_EXPLODE") ;
314             const QString button1  = tr("GEOM_BUT_CANCEL") ;
315             
316             if( QMessageBox::warning( this, caption, text, button0, button1 ) == 0 )
317               testResult = myGeomGUI->OnSubShapeGetAll( myShape, myShapeIOR, myShapeType ) ;
318             else
319               this->myAbort = true ;  /* aborted */
320           }
321           else {
322             testResult = myGeomGUI->OnSubShapeGetAll( myShape, myShapeIOR, myShapeType ) ;
323           }
324         }
325         /* explode only selected sub shapes */
326         else if( myOkShape && myOkSelectSubMode ) {
327           testResult = myGeomGUI->OnSubShapeGetSelected( myShape, myShapeIOR, myShapeType, myLocalContextId, myUseLocalContext ) ; 
328         }
329         if( !testResult ) {
330           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
331           this->myAbort = true;
332         }
333         else {
334           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
335         }  
336         /* Reset all arguments and local context to allow user a new selection ...*/
337         this->ResetStateOfDialog() ;
338         break ;
339       }
340     }
341   return ;
342 }
343
344
345 //=================================================================================
346 // function : ClickOnCancel()
347 // purpose  :
348 //=================================================================================
349 void GeometryGUI_SubShapeDlg::ClickOnCancel()
350 {
351   disconnect( mySelection, 0, this, 0 );
352   myGeomGUI->ResetState() ;
353   
354   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
355     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
356     myIC = v3d->getAISContext(); 
357     if(myUseLocalContext) {
358       myIC->CloseLocalContext(myLocalContextId) ;
359       myGeomGUI->OnDisplayAll(true) ;
360       this->myUseLocalContext = false ;
361     }
362   }
363   reject() ;
364   return ;
365 }
366
367
368 //=================================================================================
369 // function : SelectionIntoArgument()
370 // purpose  : Called when selection as changed or other case
371 //          : used only by SelectButtonC1A1 (LineEditC1A1)
372 //=================================================================================
373 void GeometryGUI_SubShapeDlg::SelectionIntoArgument()
374 {
375   
376   /* Reset all arguments and local context when selection as changed */
377   this->ResetStateOfDialog() ;
378   
379   QString aString = ""; /* future name of selection */
380   
381   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
382
383   if ( nbSel != 1 ) {
384     LineEditC1A1->setText("") ;
385     myOkShape = false;
386     return ;
387   }
388   
389   /* nbSel == 1 */
390   TopoDS_Shape S ;
391   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
392
393   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
394     return ;
395   
396   if( !IO->hasEntry() ) {
397     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")) ;
398     return ;
399   }
400
401   if ( !S.IsNull() && S.ShapeType() != TopAbs_VERTEX ) 
402   {
403     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) 
404       {
405         Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
406         myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
407         LineEditC1A1->setText(aString) ;
408         myShape = S ;
409         myOkShape = true ;
410       } 
411     else
412       {
413         SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
414           SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
415           SALOMEDS::GenericAttribute_var anAttr;
416           SALOMEDS::AttributeIOR_var     anIOR;
417           if ( !obj->_is_nil() ) 
418             {
419               if (obj->FindAttribute(anAttr, "AttributeIOR")) 
420                 {
421                   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
422                   myShapeIOR = anIOR->Value();
423                   myOkShape = true ;
424                   myShape = S ;
425                   LineEditC1A1->setText(aString) ;
426                 }
427             }
428         }
429     
430     int SelectedShapeType = ComboBox1->currentItem();
431     int count = ComboBox1->count();
432     if ( myWithShape ) count = count - 1;
433
434     int i = 0;
435     while ( i <= myShape.ShapeType() ) {
436       ComboBox1->removeItem(0);
437       i++;
438     }
439
440     if (myShape.ShapeType()==TopAbs_COMPOUND) 
441       {
442         if (myWithShape == false) {
443           ComboBox1->insertItem("Shape");
444           myWithShape = true;
445         }
446       }
447     else
448       {
449         if (myWithShape == true) {
450           ComboBox1->removeItem( ComboBox1->count() -1 );
451           myWithShape = false;
452         }
453       }
454     
455     int count1 = ComboBox1->count();
456     if ( myWithShape ) count1 = count1 - 1;
457     
458     if ( SelectedShapeType > myShape.ShapeType() ) {
459       if ( SelectedShapeType == 8 ) {
460         if ( myShape.ShapeType() != TopAbs_COMPOUND ) {
461           ComboBox1->setCurrentItem(0);
462           myShapeType = 8 - count1;
463         }
464       } else {
465         ComboBox1->setCurrentItem( count1 - count + SelectedShapeType );
466         myShapeType = 8 - count1 + ComboBox1->currentItem();
467       }
468     } else {
469       ComboBox1->setCurrentItem(0);
470       myShapeType = 8 - count1;
471     }      
472   }
473 }
474
475
476 //=================================================================================
477 // function : SetEditCurrentArgument()
478 // purpose  :
479 //=================================================================================
480 void GeometryGUI_SubShapeDlg::SetEditCurrentArgument()
481 {
482   QPushButton* send = (QPushButton*)sender();
483   switch (myConstructorId)
484     {
485     case 0: /* default constructor */
486       {
487         if(send == SelectButtonC1A1) {
488           LineEditC1A1->setFocus() ;
489           myEditCurrentArgument = LineEditC1A1;   
490           SelectionIntoArgument() ;
491         }
492         break;
493       }
494     }
495   return ;
496 }
497
498
499
500 //=================================================================================
501 // function : LineEditReturnPressed()
502 // purpose  :
503 //=================================================================================
504 void GeometryGUI_SubShapeDlg::LineEditReturnPressed()
505 {  
506   QLineEdit* send = (QLineEdit*)sender();  
507   if( send == LineEditC1A1 )
508     myEditCurrentArgument = LineEditC1A1 ;
509   else
510     return ;
511   
512   /* User name of object input management                          */
513   /* If successfull the selection is changed and signal emitted... */
514   /* so SelectionIntoArgument() is automatically called.           */
515   const QString objectUserName = myEditCurrentArgument->text() ;
516   QWidget* thisWidget = (QWidget*)this ;
517   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
518     myEditCurrentArgument->setText( objectUserName ) ;
519   }
520   return ;
521 }
522
523
524 //=================================================================================
525 // function : DeactivateActiveDialog()
526 // purpose  :
527 //=================================================================================
528 void GeometryGUI_SubShapeDlg::DeactivateActiveDialog()
529 {
530   /* Check if active */
531   if ( GroupConstructors->isEnabled() ) {
532
533     this->ResetStateOfDialog() ;
534  
535     disconnect( mySelection, 0, this, 0 );
536     GroupConstructors->setEnabled(false) ;
537     GroupC1->setEnabled(false) ;
538     GroupButtons->setEnabled(false) ;
539     myGeomGUI->ResetState() ;    
540     myGeomGUI->SetActiveDialogBox(0) ;
541     myGeomGUI->OnDisplayAll(true) ;
542   }
543   return ;
544 }
545
546
547 //=================================================================================
548 // function : ActivateThisDialog()
549 // purpose  :
550 //=================================================================================
551 void GeometryGUI_SubShapeDlg::ActivateThisDialog()
552 {
553   /* Emit a signal to deactivate other active dialog */
554   myGeomGUI->EmitSignalDeactivateDialog() ;
555   GroupConstructors->setEnabled(true) ;
556   GroupC1->setEnabled(true) ;
557   GroupButtons->setEnabled(true) ;
558   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
559   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
560   return ;
561 }
562
563
564 //=================================================================================
565 // function : enterEvent()
566 // purpose  :
567 //=================================================================================
568 void GeometryGUI_SubShapeDlg::enterEvent(QEvent* e)
569 {
570   if ( GroupConstructors->isEnabled() )
571     return ;  
572   ActivateThisDialog() ;
573   return ;
574 }
575
576
577 //=================================================================================
578 // function : closeEvent()
579 // purpose  :
580 //=================================================================================
581 void GeometryGUI_SubShapeDlg::closeEvent( QCloseEvent* e )
582 {
583   /* same than click on cancel button */
584   this->ClickOnCancel() ;
585   return ;
586 }
587
588
589 //=================================================================================
590 // function : AllOrNotAll()
591 // purpose  : Allow user selection of all or only selected sub shapes
592 //          : Called when 'CheckBox1' state change
593 //=================================================================================
594 void GeometryGUI_SubShapeDlg::AllOrNotAll()
595 {
596   
597   /* No sub shape selection if main shape not selected */
598   if( !this->myOkShape ) {
599     ResetStateOfDialog() ;
600     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ;
601     return ;
602   }
603   
604   if (myShapeType ==TopAbs_SHAPE && myShape.ShapeType()==TopAbs_COMPOUND) 
605     {
606       /* Select sub shapes mode not checked */
607       myOkSelectSubMode = false ;    
608       CheckBox1->setChecked( FALSE );
609       //no meaning to allow user selection for type = shape
610       //TODO - add another message
611       //myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ;
612       return ;
613     }
614
615   myOkSelectSubMode = CheckBox1->isChecked() ;
616
617   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
618     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
619     myIC = v3d->getAISContext(); 
620     if( this->myUseLocalContext ) {
621       myIC->CloseLocalContext(myLocalContextId) ;
622       this->myUseLocalContext = false ;
623       myGeomGUI->OnDisplayAll(true) ;
624     }
625   } else {
626     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
627     return;
628   }
629
630   if( myOkShape && myOkSelectSubMode ) {
631     /* local context is defined into the method */
632     myGeomGUI->PrepareSubShapeSelection( this->myShapeType, this->myLocalContextId ) ;    
633     myUseLocalContext = true ;
634     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE")) ;
635   }
636   return ;
637 }
638
639
640 //=================================================================================
641 // function : ResetStateOfDialog()
642 // purpose  : Completely reset the state of method including local context
643 //=================================================================================
644 void GeometryGUI_SubShapeDlg::ResetStateOfDialog()
645 {
646   /* To leave current selection if explode all as been aborted by user */
647   if( this->myAbort == true ) {
648     this->myOkShape = false ;
649     this->myEditCurrentArgument->setText("") ;
650   }
651   else {
652     ; /* nothing to do : keep selection argument */
653   }
654
655   int SelectedShapeType = ComboBox1->currentItem();
656   int count = ComboBox1->count();
657   if ( myWithShape ) count = count - 1;
658   /* type for sub shape selection */
659   ComboBox1->clear();
660   ComboBox1->insertItem("Compound");
661   ComboBox1->insertItem("Compsolid");
662   ComboBox1->insertItem("Solid");
663   ComboBox1->insertItem("Shell");
664   ComboBox1->insertItem("Face");
665   ComboBox1->insertItem("Wire");
666   ComboBox1->insertItem("Edge");
667   ComboBox1->insertItem("Vertex");
668   ComboBox1->insertItem("Shape");
669   this->myWithShape=true;
670   ComboBox1->setCurrentItem( 8 - count + SelectedShapeType );
671
672   
673   /* unpress buttons : due to abort box*/
674   this->buttonApply->setDown(FALSE) ;
675   this->buttonOk->setDown(FALSE) ;
676
677   /* Select sub shapes mode not checked */
678   this->myOkSelectSubMode = false ;    
679   this->CheckBox1->setChecked( FALSE );
680
681   /* Close its local contact if opened */
682   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
683     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
684     myIC = v3d->getAISContext(); 
685     if( this->myUseLocalContext ) {
686       myIC->CloseLocalContext(this->myLocalContextId) ;
687       this->myUseLocalContext = false ;
688       myGeomGUI->OnDisplayAll(true) ;
689     }
690   }
691   return ;
692 }
693
694
695
696 //=================================================================================
697 // function : ComboTextChanged()
698 // purpose  : 
699 //=================================================================================
700 void GeometryGUI_SubShapeDlg::ComboTextChanged()
701 {
702   if ( myOkShape )
703     this->myShapeType = ComboBox1->currentItem() + myShape.ShapeType() + 1;
704   else
705     this->myShapeType = ComboBox1->currentItem();
706
707   /* Select sub shapes mode not checked */
708   CheckBox1->setChecked( FALSE );
709   myOkSelectSubMode = FALSE ;
710
711   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
712     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
713     myIC = v3d->getAISContext();
714     if( this->myUseLocalContext ) {
715       myIC->CloseLocalContext(myLocalContextId) ;
716       this->myUseLocalContext = false ;
717       myGeomGUI->OnDisplayAll(true) ;
718     }
719   }
720   return ;
721 }
722
723
724 //=================================================================================
725 // function : NumberOfSubShapes()
726 // purpose  :
727 //=================================================================================
728 unsigned int GeometryGUI_SubShapeDlg::NumberOfSubShapes( const TopoDS_Shape& S, const int shapeType )
729 {
730   if( S.IsNull() )
731     return 0 ;
732   
733   unsigned int index = 0 ;
734   TopExp_Explorer Exp( S, TopAbs_ShapeEnum(shapeType) );
735   TopTools_MapOfShape M;
736   while ( Exp.More() ) {
737     if ( M.Add(Exp.Current()) )
738       index++;
739     Exp.Next();
740   }
741   M.Clear() ;
742   return index ;
743 }
744
745