Salome HOME
af60f62de26cb5b67236e7ed58043d1d2e63865d
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_SubShapeSelectorWdg.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : StdMeshersGUI_SubShapeSelectorWdg.cxx
21 // Author : Open CASCADE S.A.S. (dmv)
22 // SMESH includes
23 //
24 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
25
26 // SMESH Includes
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESH_Actor.h"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_LogicalFilter.hxx"
32 #include "SMESH_PreviewActorsCollection.h"
33 #include "SMESH_Type.h"
34
35 // SALOME GUI includes
36 #include <LightApp_SelectionMgr.h>
37 #include <SALOME_ListIO.hxx>
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SVTK_Selector.h>
41 #include <SVTK_ViewModel.h>
42 #include <SVTK_ViewWindow.h>
43
44 // GEOM Includes
45 #include <GEOMBase.h>
46 #include <GEOM_TypeFilter.h>
47 #include <GEOM_CompoundFilter.h>
48
49 // Qt includes
50 #include <QPushButton>
51 #include <QGridLayout>
52 #include <QListWidget>
53 #include <QCheckBox>
54 #include <QLineEdit>
55
56 // OCCT includes
57 #include <TColStd_MapOfInteger.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopExp.hxx>
60 #include <TopExp_Explorer.hxx>
61
62
63 #define SPACING 6
64 #define MARGIN 0
65
66 //================================================================================
67 /*!
68  *  Constructor
69  */
70 //================================================================================
71
72 StdMeshersGUI_SubShapeSelectorWdg
73 ::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent, TopAbs_ShapeEnum aSubShType ): 
74   QWidget( parent ),
75   myPreviewActor( 0 ),
76   myMaxSize( -1 )
77 {
78   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
79
80   QGridLayout* edgesLayout = new QGridLayout( this );
81   edgesLayout->setMargin( MARGIN );
82   edgesLayout->setSpacing( SPACING );
83   
84   myListWidget   = new QListWidget( this );
85   myAddButton    = new QPushButton( tr( "SMESH_BUT_ADD" ),    this );
86   myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this );
87   myInfoLabel    = new QLabel( this );
88   myPrevButton   = new QPushButton( "<<", this );
89   myNextButton   = new QPushButton( ">>", this );
90   myListWidget->setSelectionMode( QListWidget::ExtendedSelection );
91
92   edgesLayout->addWidget(myListWidget,   0, 0, 3, 3);
93   edgesLayout->addWidget(myAddButton,    0, 3);
94   edgesLayout->addWidget(myRemoveButton, 1, 3);
95   edgesLayout->addWidget(myInfoLabel,    3, 0, 1, 3);
96   edgesLayout->addWidget(myPrevButton,   4, 0);
97   edgesLayout->addWidget(myNextButton,   4, 2);
98
99   edgesLayout->setRowStretch(2, 5);
100   edgesLayout->setColumnStretch(1, 5);
101
102   myListWidget->setMinimumWidth(300);
103   myInfoLabel->setMinimumWidth(300);
104   myInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
105   myInfoLabel->setAlignment(Qt::AlignCenter);
106
107   mySubShType = aSubShType;
108
109   init();
110 }
111
112 //================================================================================
113 /*!
114  *  Destructor
115  */
116 //================================================================================
117
118 StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg()
119 {
120   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
121     if ( myPreviewActor ) {
122       myPreviewActor->RemoveFromRender( myRenderer );
123       aViewWindow->Repaint();
124
125       delete myPreviewActor;
126       myPreviewActor = 0;
127     }
128   }
129   myEntry = "";
130   myParamValue = "";
131   myMainShape.Nullify();
132
133   if ( mySelectionMgr && myFilter )
134     mySelectionMgr->removeFilter( myFilter );
135   delete myFilter; myFilter=0;
136
137   SUIT_SelectionFilter* filter;
138   foreach( filter, myGeomFilters )
139     delete filter;
140 }
141
142 //================================================================================
143 /*!
144  *  Create a layout, initialize fields
145  */
146 //================================================================================
147
148 void StdMeshersGUI_SubShapeSelectorWdg::init()
149 {
150   myParamValue = "";
151   myIsNotCorrected = true; // to dont call the GetCorrectedValue method twice
152   myListOfIDs.clear();
153   mySelectedIDs.clear();
154
155   myAddButton->setEnabled( false );
156   myRemoveButton->setEnabled( false );
157
158   mySMESHGUI     = SMESHGUI::GetSMESHGUI();
159   mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
160   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
161
162   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
163     aViewWindow->SetSelectionMode( ActorSelection );
164
165   myFilter=0;
166   //setFilter();
167
168   connect( myAddButton,    SIGNAL(clicked()), SLOT(onAdd()));
169   connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove()));
170   connect( myPrevButton,   SIGNAL(clicked()), SLOT(onPrevious()));
171   connect( myNextButton,   SIGNAL(clicked()), SLOT(onNext()));
172   
173   connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(selectionIntoArgument()));
174   connect( myListWidget,   SIGNAL(itemSelectionChanged()),    this, SLOT(onListSelectionChanged()));
175
176   updateState();
177 }
178
179 //================================================================================
180 /*!
181  * \brief Install filters to select sub-shapes of mySubShType or their groups
182  */
183 //================================================================================
184
185 void StdMeshersGUI_SubShapeSelectorWdg::setFilter()
186 {
187   SalomeApp_Study* study = mySMESHGUI->activeStudy();
188   GEOM_TypeFilter* typeFilter = new GEOM_TypeFilter(study, mySubShType, /*isShapeType=*/true );
189   GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study);
190   gpoupFilter->addSubType( mySubShType );
191   myGeomFilters.append( typeFilter );
192   myGeomFilters.append( gpoupFilter );
193   myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR );
194   mySelectionMgr->installFilter( myFilter );
195 }
196
197 //================================================================================
198 /*!
199  *  Create a layout, initialize fields
200  */
201 //================================================================================
202
203 void StdMeshersGUI_SubShapeSelectorWdg::ShowPreview( bool visible)
204 {
205   if ( !myPreviewActor )
206     return;
207
208   if ( myIsShown != visible ) {
209     myPreviewActor->SetShown( visible );
210     
211     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
212       aViewWindow->Repaint();
213
214     myIsShown = visible;
215   }
216 }
217
218 //================================================================================
219 /*!
220  * \brief Clears selected IDs. This is a workaround of a bug that
221  *        SUIT_SelectionMgr::clearSelected() does not emit currentSelectionChanged
222  */
223 //================================================================================
224
225 void StdMeshersGUI_SubShapeSelectorWdg::ClearSelected()
226 {
227   mySelectedIDs.clear();
228   selectionIntoArgument();
229 }
230
231 //=================================================================================
232 // function : selectionIntoArgument()
233 // purpose  : Called when selection as changed or other case
234 //=================================================================================
235 void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument()
236 {
237   if ( !myPreviewActor )
238     return;
239
240   mySelectedIDs.clear();
241
242   // get selected mesh
243   SALOME_ListIO aList;
244   mySelectionMgr->selectedObjects( aList );
245   int nbSel = aList.Extent();
246
247   if (nbSel > 0) {
248     SALOME_ListIteratorOfListIO anIt (aList);
249
250     for ( ; anIt.More(); anIt.Next()) // Loop on selected objects
251     {
252       Handle(SALOME_InteractiveObject) IO = anIt.Value();
253
254       GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() );
255       if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study
256         GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape();
257         QString aFatherEntry = "";
258         QString aMainFatherEntry = "";
259         TopoDS_Shape shape;
260         if ( !CORBA::is_nil( aGeomFatherObj ) ) {
261           // Get Main Shape
262           GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry.c_str() );
263           if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) {  // Main Shape is a Group
264             GEOM::GEOM_Object_var aMainFatherObj = aGeomMain->GetMainShape();
265             if ( !CORBA::is_nil( aMainFatherObj ) )
266               aMainFatherEntry = aMainFatherObj->GetStudyEntry();
267           }
268           aFatherEntry = aGeomFatherObj->GetStudyEntry();
269         }
270
271         if (( ! aFatherEntry.isEmpty() ) &&
272             ( aFatherEntry == myEntry.c_str() || aFatherEntry == aMainFatherEntry ) )
273         {
274           if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object
275             GEOMBase::GetShape(aGeomObj, shape);
276             if ( !shape.IsNull() ) {
277               TopExp_Explorer exp( shape, mySubShType );
278               for ( ; exp.More(); exp.Next() ) {
279                 int index = myPreviewActor->GetIndexByShape( exp.Current() );
280                 if ( index ) {
281                   mySelectedIDs.append( index );
282                   myPreviewActor->HighlightID( index );
283                 }
284               }
285             }
286           } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/  ) {
287             GEOMBase::GetShape(aGeomObj, shape); 
288             if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) {
289               int index = myPreviewActor->GetIndexByShape( shape );
290               if ( index ) {
291                 mySelectedIDs.append( index );
292                 myPreviewActor->HighlightID( index );
293               }
294             }
295           }
296         }
297       } else { // Selected Actor from Actor Collection
298         QString anEntry = IO->getEntry();
299         QString str = "_";
300         int index = anEntry.lastIndexOf( str );
301         anEntry.remove(0, index+1);
302         int ind = anEntry.toInt();
303         if ( ind )
304           mySelectedIDs.append( ind );
305       }
306     }
307   }
308   // update add button
309   myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) &&
310                            mySelectedIDs.size() > 0 &&
311                            ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) );
312
313   //Connect Selected Ids in viewer and dialog's Ids list
314   bool signalsBlocked = myListWidget->blockSignals( true );
315   myListWidget->clearSelection();
316   if ( mySelectedIDs.size() > 0 ) {
317     for (int i = 0; i < mySelectedIDs.size(); i++) {
318       QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
319       QList<QListWidgetItem*> anItems = myListWidget->findItems ( anID, Qt::MatchExactly );
320       QListWidgetItem* item;
321       foreach(item, anItems)
322         item->setSelected(true);
323     }
324   }
325   myListWidget->blockSignals( signalsBlocked );
326 }
327
328 //=================================================================================
329 // function : onAdd()
330 // purpose  : Called when Add Button Clicked
331 //=================================================================================
332 void StdMeshersGUI_SubShapeSelectorWdg::onAdd()
333 {
334   if ( mySelectedIDs.size() < 1 )
335     return;
336
337   myListWidget->blockSignals( true );
338   for (int i = 0; i < mySelectedIDs.size() && (myMaxSize == -1 || myListOfIDs.size() < myMaxSize); i++) {
339     if ( myListOfIDs.indexOf( mySelectedIDs.at(i) ) == -1 ) {
340       QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
341
342       QListWidgetItem* anItem = new QListWidgetItem( anID, myListWidget );
343       anItem->setSelected(true);
344       
345       myListOfIDs.append( mySelectedIDs.at(i) );
346     }
347   }
348   onListSelectionChanged();
349   myListWidget->blockSignals( false );
350
351   mySelectedIDs.clear();
352   myAddButton->setEnabled( false );
353 }
354          
355 //=================================================================================
356 // function : onRemove()
357 // purpose  : Called when Remove Button Clicked
358 //=================================================================================
359 void StdMeshersGUI_SubShapeSelectorWdg::onRemove()
360 {
361   if ( myListWidget->count() < 1 )
362     return;
363
364   myListWidget->blockSignals( true );
365   QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
366   QListWidgetItem* item;
367   foreach(item, selItems) {
368     QString idStr = item->text();
369     int id = idStr.toInt();
370
371     int index = myListOfIDs.indexOf( id );
372     myListOfIDs.removeAt( index );
373     delete item;
374   }
375
376   onListSelectionChanged();
377   myListWidget->blockSignals( false );
378   
379   myAddButton->setEnabled( !mySelectedIDs.isEmpty() );
380 }
381
382 void StdMeshersGUI_SubShapeSelectorWdg::onPrevious()
383 {
384   if ( myPreviewActor ) {
385     myPreviewActor->previous();
386     myListWidget->clearSelection();
387     updateButtons();
388     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
389       aViewWindow->Repaint();
390   }
391 }
392
393 void StdMeshersGUI_SubShapeSelectorWdg::onNext()
394 {
395   if ( myPreviewActor ) {
396     myPreviewActor->next();
397     myListWidget->clearSelection();
398     updateButtons();
399     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
400       aViewWindow->Repaint();
401   }
402 }
403
404 //=================================================================================
405 // function : onListSelectionChanged()
406 // purpose  : Called when selection in element list is changed
407 //=================================================================================
408 void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged()
409 {
410   if ( !myPreviewActor )
411     return;
412
413   mySelectionMgr->clearSelected();
414   TColStd_MapOfInteger aIndexes;
415   QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
416   QListWidgetItem* anItem;
417   foreach(anItem, selItems)
418     myPreviewActor->HighlightID( anItem->text().toInt() );
419
420   // update remove button
421   myRemoveButton->setEnabled( selItems.size() > 0 );
422 }
423
424 //=================================================================================
425 // function : setGeomShape
426 // purpose  : Called to set geometry whose sub-shapes are selected
427 //================================================================================
428 void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEntry,
429                                                            const QString& theMainShapeEntry )
430 {
431   if ( !theEntry.isEmpty() || theMainShapeEntry.isEmpty() )
432   {
433     myParamValue = theEntry;
434     myEntry      = theEntry.toStdString();
435     myMainEntry  = theMainShapeEntry.toStdString();
436
437     if ( myMainEntry.empty() ) myMainEntry = myEntry;
438     if ( myEntry.empty() )     myEntry     = myMainEntry;
439     if ( myMainEntry.length() > myEntry.length() &&
440          theMainShapeEntry.startsWith( theEntry ))
441       std::swap( myMainEntry, myEntry );
442
443     myGeomShape = GetTopoDSByEntry( myEntry.c_str() );
444     if ( myEntry == myMainEntry )
445       myMainShape = myGeomShape;
446     else
447       myMainShape = GetTopoDSByEntry( myMainEntry.c_str() );
448     updateState();
449     myIsNotCorrected = true;
450   }
451 }
452
453 //=================================================================================
454 // function : updateState
455 // purpose  : update Widget state
456 //=================================================================================
457 void StdMeshersGUI_SubShapeSelectorWdg::updateState()
458 {
459   bool state = false;
460   if ( !myGeomShape.IsNull() )
461     state = true;
462   myInfoLabel->setVisible( false );
463   myPrevButton->setVisible( false );
464   myNextButton->setVisible( false );
465   
466   myListWidget->setEnabled( state );
467   myAddButton->setEnabled( mySelectedIDs.size() > 0 );
468   
469   if (state) {
470     SUIT_OverrideCursor wc;
471     myPreviewActor = new SMESH_PreviewActorsCollection();
472     myPreviewActor->SetSelector( mySelector );
473     myPreviewActor->Init( myGeomShape, myMainShape, mySubShType, myEntry.c_str() );
474     myPreviewActor->SetShown( false );
475     myIsShown = false;
476     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
477       myRenderer = aViewWindow->getRenderer();
478       myPreviewActor->AddToRender( myRenderer );
479       aViewWindow->Repaint();
480     }
481     updateButtons();
482   }
483 }
484
485 //=================================================================================
486 // function : GetGeomObjectByEntry
487 // purpose  : Called to get GeomObject
488 //=================================================================================
489 GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry( const QString& theEntry )
490 {
491   GEOM::GEOM_Object_var aGeomObj;
492   SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
493   if ( !aStudy->_is_nil() )
494   {
495     SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( theEntry.toLatin1().data() );
496     if (!aSObj->_is_nil() )
497     {
498       CORBA::Object_var obj = aSObj->GetObject();
499       aGeomObj = GEOM::GEOM_Object::_narrow(obj);
500       aSObj->UnRegister();
501     }
502   }
503   return aGeomObj._retn();
504 }
505
506 //=================================================================================
507 // function : setObjectByEntry
508 // purpose  : Called to get GeomObject
509 //=================================================================================
510 TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg::GetTopoDSByEntry( const QString& theEntry )
511 {
512   TopoDS_Shape shape;
513   GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( theEntry );
514   GEOMBase::GetShape(aGeomObj, shape);
515   return shape;
516 }
517
518 //=================================================================================
519 // function : GetListOfIds
520 // purpose  : Called to get the list of SubShapes IDs
521 //=================================================================================
522 SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs()
523 {
524   SMESH::long_array_var anArray = new SMESH::long_array;
525
526   // if ( myMainEntry != "" && myIsNotCorrected )
527   //   myListOfIDs = GetCorrectedListOfIDs( true );
528
529   int size = myListOfIDs.size();
530   anArray->length( size );
531   for (int i = 0; i < size; i++)
532     anArray[i] = myListOfIDs.at(i);
533
534   return anArray;
535 }
536
537 //=================================================================================
538 // function : SetListOfIds
539 // purpose  : Called to set the list of SubShapes IDs. Returns false if any ID is invalid
540 //=================================================================================
541 bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds)
542 {
543   mySelectedIDs.clear();
544   myListOfIDs.clear();
545   int size = theIds->length();
546   for ( int i = 0; i < size; i++ )
547     mySelectedIDs.append( theIds[ i ] );
548
549   myListWidget->blockSignals( true );
550   myListWidget->clear();
551   myListWidget->blockSignals( false );
552
553   bool isOk = true;
554   if ( myPreviewActor )
555   {
556     for ( int i = 0; i < size && isOk; i++ )
557       isOk = myPreviewActor->IsValidIndex( theIds[ i ] );
558   }
559   else if ( !myMainShape.IsNull() )
560   {
561     TopTools_IndexedMapOfShape aMainMap;
562     TopExp::MapShapes(myMainShape, aMainMap);
563     for ( int i = 0; i < size && isOk; i++ )
564       isOk = ( theIds[ i ] > 0 && theIds[ i ] <= aMainMap.Extent() );
565   }
566   // mySelectedIDs = GetCorrectedListOfIDs( false, &isOk );
567   onAdd();
568   return isOk;
569 }
570
571 //=================================================================================
572 // function : SetMainShapeEntry
573 // purpose  : Called to set the Entry of main shape of the mesh
574 //=================================================================================
575 // void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry )
576 // {
577 //   myMainEntry = theEntry;
578 //   myMainShape = GetTopoDSByEntry( theEntry );
579 //   myIsNotCorrected = true;
580 // }
581
582 //=================================================================================
583 // function : GetMainShapeEntry
584 // purpose  : Called to get the Main Object Entry
585 //=================================================================================
586 const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry()
587 {
588   if ( myMainEntry.empty() ) myMainEntry = "";
589   return myMainEntry.c_str();
590 }
591
592 //=================================================================================
593 // function : GetCorrectedListOfIds
594 // purpose  : Called to convert the list of IDs from sub-shape IDs to main shape IDs
595 //=================================================================================
596 // QList<int>
597 // StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape,
598 //                                                           bool* isOK )
599 // {
600 //   if (( myMainShape.IsNull() || myGeomShape.IsNull() ) &&  fromSubshapeToMainshape )
601 //     return myListOfIDs;
602 //   else if (( myMainShape.IsNull() /*||*/&& myGeomShape.IsNull() ) &&  !fromSubshapeToMainshape )
603 //     return mySelectedIDs;
604
605 //   if ( !fromSubshapeToMainshape ) // called from SetListOfIDs
606 //   {
607 //     if ( myMainShape.IsNull() )
608 //       std::swap( myMainShape, myGeomShape );
609 //   }
610
611 //   QList<int> aList;
612 //   TopTools_IndexedMapOfShape aGeomMap, aMainMap;
613 //   TopExp::MapShapes(myMainShape, aMainMap);
614 //   if ( !myGeomShape.IsNull() )
615 //     TopExp::MapShapes(myGeomShape, aGeomMap);
616
617 //   bool ok = true;
618 //   if ( fromSubshapeToMainshape ) // convert indexes from sub-shape to mainshape
619 //   {
620 //     int size = myListOfIDs.size();
621 //     for (int i = 0; i < size; i++) {
622 //       int index = myListOfIDs.at(i);
623 //       if ( aGeomMap.Extent() < index )
624 //       {
625 //         ok = false;
626 //       }
627 //       else
628 //       {
629 //         TopoDS_Shape aSubShape = aGeomMap.FindKey( index );
630 //         if ( mySubShType != aSubShape.ShapeType() )
631 //           ok = false;
632 //         if ( !aMainMap.Contains( aSubShape ))
633 //           ok = false;
634 //         else
635 //           index = aMainMap.FindIndex( aSubShape );
636 //       }
637 //       aList.append( index );
638 //     }
639 //     myIsNotCorrected = false;
640 //   }
641 //   else // convert indexes from main shape to sub-shape, or just check indices
642 //   {
643 //     int size = mySelectedIDs.size();
644 //     for (int i = 0; i < size; i++) {
645 //       int index = mySelectedIDs.at(i);
646 //       if ( aMainMap.Extent() < index )
647 //       {
648 //         ok = false;
649 //       }
650 //       else
651 //       {
652 //         TopoDS_Shape aSubShape = aMainMap.FindKey( index );
653 //         if ( mySubShType != aSubShape.ShapeType() )
654 //           ok = false;
655 //         if ( !aGeomMap.Contains( aSubShape ) && !aGeomMap.IsEmpty() )
656 //           ok = false;
657 //         else
658 //           index = aGeomMap.FindIndex( aSubShape );
659 //       }
660 //       aList.append( index );
661 //     }
662 //   }
663 //   if ( isOK ) *isOK = ok;
664
665 //   return aList;
666 // }
667
668 void StdMeshersGUI_SubShapeSelectorWdg::updateButtons()
669 {
670   if ( myPreviewActor ) {
671     int total = myPreviewActor->count();
672     int chunk = myPreviewActor->currentChunk();
673     int chunkSize = myPreviewActor->chunkSize();
674     int imin = chunk*chunkSize+1;
675     int imax = std::min((chunk+1)*chunkSize, total);
676     bool vis = imax > 0 && total > chunkSize;
677     myInfoLabel->setVisible( vis );
678     myPrevButton->setVisible( vis );
679     myNextButton->setVisible( vis );
680     myInfoLabel->setText( tr( "X_FROM_Y_ITEMS_SHOWN" ).arg(imin).arg(imax).arg(total) );
681     myPrevButton->setEnabled( myPreviewActor->hasPrevious() );
682     myNextButton->setEnabled( myPreviewActor->hasNext() );
683   }
684 }