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