Salome HOME
23126: [CEA 1562] Regression : Wrong nodes position using SetEnforcedVertex on a...
[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   mySelectionMgr->clearSelected();
138
139   SUIT_SelectionFilter* filter;
140   foreach( filter, myGeomFilters )
141     delete filter;
142 }
143
144 //================================================================================
145 /*!
146  *  Create a layout, initialize fields
147  */
148 //================================================================================
149
150 void StdMeshersGUI_SubShapeSelectorWdg::init()
151 {
152   myParamValue = "";
153   myIsNotCorrected = true; // to dont call the GetCorrectedValue method twice
154   myListOfIDs.clear();
155   mySelectedIDs.clear();
156
157   myAddButton->setEnabled( false );
158   myRemoveButton->setEnabled( false );
159
160   mySMESHGUI     = SMESHGUI::GetSMESHGUI();
161   mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
162   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
163
164   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
165     aViewWindow->SetSelectionMode( ActorSelection );
166
167   myFilter=0;
168   //setFilter();
169
170   connect( myAddButton,    SIGNAL(clicked()), SLOT(onAdd()));
171   connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove()));
172   connect( myPrevButton,   SIGNAL(clicked()), SLOT(onPrevious()));
173   connect( myNextButton,   SIGNAL(clicked()), SLOT(onNext()));
174   
175   connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(selectionIntoArgument()));
176   connect( myListWidget,   SIGNAL(itemSelectionChanged()),    this, SLOT(onListSelectionChanged()));
177
178   updateState();
179 }
180
181 //================================================================================
182 /*!
183  * \brief Install filters to select sub-shapes of mySubShType or their groups
184  */
185 //================================================================================
186
187 void StdMeshersGUI_SubShapeSelectorWdg::setFilter()
188 {
189   SalomeApp_Study* study = mySMESHGUI->activeStudy();
190   GEOM_TypeFilter* typeFilter = new GEOM_TypeFilter(study, mySubShType, /*isShapeType=*/true );
191   GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study);
192   gpoupFilter->addSubType( mySubShType );
193   myGeomFilters.append( typeFilter );
194   myGeomFilters.append( gpoupFilter );
195   myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR );
196   mySelectionMgr->installFilter( myFilter );
197 }
198
199 //================================================================================
200 /*!
201  *  Create a layout, initialize fields
202  */
203 //================================================================================
204
205 void StdMeshersGUI_SubShapeSelectorWdg::ShowPreview( bool visible)
206 {
207   if ( !myPreviewActor )
208     return;
209
210   if ( myIsShown != visible ) {
211     myPreviewActor->SetShown( visible );
212     
213     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
214       aViewWindow->Repaint();
215
216     myIsShown = visible;
217   }
218 }
219
220 //================================================================================
221 /*!
222  * \brief Clears selected IDs. This is a workaround of a bug that
223  *        SUIT_SelectionMgr::clearSelected() does not emit currentSelectionChanged
224  */
225 //================================================================================
226
227 void StdMeshersGUI_SubShapeSelectorWdg::ClearSelected()
228 {
229   mySelectedIDs.clear();
230   selectionIntoArgument();
231 }
232
233 //=================================================================================
234 // function : selectionIntoArgument()
235 // purpose  : Called when selection as changed or other case
236 //=================================================================================
237 void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument()
238 {
239   if ( !myPreviewActor )
240     return;
241
242   mySelectedIDs.clear();
243
244   // get selected mesh
245   SALOME_ListIO aList;
246   mySelectionMgr->selectedObjects( aList );
247   int nbSel = aList.Extent();
248
249   if (nbSel > 0) {
250     SALOME_ListIteratorOfListIO anIt (aList);
251
252     for ( ; anIt.More(); anIt.Next()) // Loop on selected objects
253     {
254       Handle(SALOME_InteractiveObject) IO = anIt.Value();
255
256       GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() );
257       if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study
258         // commented for IPAL52836
259         //
260         // GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape();
261         // QString aFatherEntry = "";
262         // QString aMainFatherEntry = "";
263         // TopoDS_Shape shape;
264         // if ( !CORBA::is_nil( aGeomFatherObj ) ) {
265         //   // Get Main Shape
266         //   GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry.c_str() );
267         //   if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) {  // Main Shape is a Group
268         //     GEOM::GEOM_Object_var aMainFatherObj = aGeomMain->GetMainShape();
269         //     if ( !CORBA::is_nil( aMainFatherObj ) )
270         //       aMainFatherEntry = aMainFatherObj->GetStudyEntry();
271         //   }
272         //   aFatherEntry = aGeomFatherObj->GetStudyEntry();
273         // }
274
275         // if (( ! aFatherEntry.isEmpty() ) &&
276         //     ( aFatherEntry == myEntry.c_str() || aFatherEntry == aMainFatherEntry ) )
277         {
278           TopoDS_Shape shape;
279           if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object
280             GEOMBase::GetShape(aGeomObj, shape);
281             if ( !shape.IsNull() ) {
282               TopExp_Explorer exp( shape, mySubShType );
283               for ( ; exp.More(); exp.Next() ) {
284                 int index = myPreviewActor->GetIndexByShape( exp.Current() );
285                 if ( index ) {
286                   mySelectedIDs.append( index );
287                   myPreviewActor->HighlightID( index );
288                 }
289               }
290             }
291           } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/  ) {
292             GEOMBase::GetShape(aGeomObj, shape); 
293             if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) {
294               int index = myPreviewActor->GetIndexByShape( shape );
295               if ( index ) {
296                 mySelectedIDs.append( index );
297                 myPreviewActor->HighlightID( index );
298               }
299             }
300           }
301         }
302       } else { // Selected Actor from Actor Collection
303         QString anEntry = IO->getEntry();
304         QString str = "_";
305         int index = anEntry.lastIndexOf( str );
306         anEntry.remove(0, index+1);
307         int ind = anEntry.toInt();
308         if ( ind )
309           mySelectedIDs.append( ind );
310       }
311     }
312   }
313   // update add button
314   myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) &&
315                            mySelectedIDs.size() > 0 &&
316                            ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) );
317
318   //Connect Selected Ids in viewer and dialog's Ids list
319   bool signalsBlocked = myListWidget->blockSignals( true );
320   myListWidget->clearSelection();
321   if ( mySelectedIDs.size() > 0 ) {
322     for (int i = 0; i < mySelectedIDs.size(); i++) {
323       QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
324       QList<QListWidgetItem*> anItems = myListWidget->findItems ( anID, Qt::MatchExactly );
325       QListWidgetItem* item;
326       foreach(item, anItems)
327         item->setSelected(true);
328     }
329   }
330   myListWidget->blockSignals( signalsBlocked );
331 }
332
333 //=================================================================================
334 // function : onAdd()
335 // purpose  : Called when Add Button Clicked
336 //=================================================================================
337 void StdMeshersGUI_SubShapeSelectorWdg::onAdd()
338 {
339   if ( mySelectedIDs.size() < 1 )
340     return;
341
342   myListWidget->blockSignals( true );
343   for (int i = 0; i < mySelectedIDs.size() && (myMaxSize == -1 || myListOfIDs.size() < myMaxSize); i++) {
344     if ( myListOfIDs.indexOf( mySelectedIDs.at(i) ) == -1 ) {
345       QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
346
347       QListWidgetItem* anItem = new QListWidgetItem( anID, myListWidget );
348       anItem->setSelected(true);
349       
350       myListOfIDs.append( mySelectedIDs.at(i) );
351     }
352   }
353   onListSelectionChanged();
354   myListWidget->blockSignals( false );
355
356   mySelectedIDs.clear();
357   myAddButton->setEnabled( false );
358 }
359          
360 //=================================================================================
361 // function : onRemove()
362 // purpose  : Called when Remove Button Clicked
363 //=================================================================================
364 void StdMeshersGUI_SubShapeSelectorWdg::onRemove()
365 {
366   if ( myListWidget->count() < 1 )
367     return;
368
369   myListWidget->blockSignals( true );
370   QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
371   QListWidgetItem* item;
372   foreach(item, selItems) {
373     QString idStr = item->text();
374     int id = idStr.toInt();
375
376     int index = myListOfIDs.indexOf( id );
377     myListOfIDs.removeAt( index );
378     delete item;
379   }
380
381   onListSelectionChanged();
382   myListWidget->blockSignals( false );
383   
384   myAddButton->setEnabled( !mySelectedIDs.isEmpty() );
385 }
386
387 void StdMeshersGUI_SubShapeSelectorWdg::onPrevious()
388 {
389   if ( myPreviewActor ) {
390     myPreviewActor->previous();
391     myListWidget->clearSelection();
392     updateButtons();
393     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
394       aViewWindow->Repaint();
395   }
396 }
397
398 void StdMeshersGUI_SubShapeSelectorWdg::onNext()
399 {
400   if ( myPreviewActor ) {
401     myPreviewActor->next();
402     myListWidget->clearSelection();
403     updateButtons();
404     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
405       aViewWindow->Repaint();
406   }
407 }
408
409 //=================================================================================
410 // function : onListSelectionChanged()
411 // purpose  : Called when selection in element list is changed
412 //=================================================================================
413 void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged()
414 {
415   if ( !myPreviewActor )
416     return;
417
418   //mySelectionMgr->clearSelected();
419   TColStd_MapOfInteger aIndexes;
420   QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
421   QListWidgetItem* anItem;
422   foreach(anItem, selItems)
423     myPreviewActor->HighlightID( anItem->text().toInt() );
424
425   // update remove button
426   myRemoveButton->setEnabled( selItems.size() > 0 );
427
428   emit selectionChanged();
429 }
430
431 //=================================================================================
432 // function : setGeomShape
433 // purpose  : Called to set geometry whose sub-shapes are selected
434 //================================================================================
435 void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEntry,
436                                                            const QString& theMainShapeEntry )
437 {
438   if ( !theEntry.isEmpty() || theMainShapeEntry.isEmpty() )
439   {
440     myParamValue = theEntry;
441     myEntry      = theEntry.toStdString();
442     myMainEntry  = theMainShapeEntry.toStdString();
443
444     if ( myMainEntry.empty() ) myMainEntry = myEntry;
445     if ( myEntry.empty() )     myEntry     = myMainEntry;
446     if ( myMainEntry.length() > myEntry.length() &&
447          theMainShapeEntry.startsWith( theEntry ))
448       std::swap( myMainEntry, myEntry );
449
450     myGeomShape = GetTopoDSByEntry( myEntry.c_str() );
451     if ( myEntry == myMainEntry )
452       myMainShape = myGeomShape;
453     else
454       myMainShape = GetTopoDSByEntry( myMainEntry.c_str() );
455     updateState();
456     myIsNotCorrected = true;
457   }
458 }
459
460 //=================================================================================
461 // function : updateState
462 // purpose  : update Widget state
463 //=================================================================================
464 void StdMeshersGUI_SubShapeSelectorWdg::updateState()
465 {
466   bool state = false;
467   if ( !myGeomShape.IsNull() )
468     state = true;
469   myInfoLabel->setVisible( false );
470   myPrevButton->setVisible( false );
471   myNextButton->setVisible( false );
472   
473   myListWidget->setEnabled( state );
474   myAddButton->setEnabled( mySelectedIDs.size() > 0 );
475   
476   if (state) {
477     SUIT_OverrideCursor wc;
478     myPreviewActor = new SMESH_PreviewActorsCollection();
479     myPreviewActor->SetSelector( mySelector );
480     myPreviewActor->Init( myGeomShape, myMainShape, mySubShType, myEntry.c_str() );
481     myPreviewActor->SetShown( false );
482     myIsShown = false;
483     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
484       myRenderer = aViewWindow->getRenderer();
485       myPreviewActor->AddToRender( myRenderer );
486       aViewWindow->Repaint();
487     }
488     updateButtons();
489   }
490 }
491
492 //=================================================================================
493 // function : GetGeomObjectByEntry
494 // purpose  : Called to get GeomObject
495 //=================================================================================
496 GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry( const QString& theEntry )
497 {
498   GEOM::GEOM_Object_var aGeomObj;
499   SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
500   if ( !aStudy->_is_nil() )
501   {
502     SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( theEntry.toLatin1().data() );
503     if (!aSObj->_is_nil() )
504     {
505       CORBA::Object_var obj = aSObj->GetObject();
506       aGeomObj = GEOM::GEOM_Object::_narrow(obj);
507       aSObj->UnRegister();
508     }
509   }
510   return aGeomObj._retn();
511 }
512
513 //=================================================================================
514 // function : setObjectByEntry
515 // purpose  : Called to get GeomObject
516 //=================================================================================
517 TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg::GetTopoDSByEntry( const QString& theEntry )
518 {
519   TopoDS_Shape shape;
520   GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( theEntry );
521   GEOMBase::GetShape(aGeomObj, shape);
522   return shape;
523 }
524
525 //=================================================================================
526 // function : GetListOfIds
527 // purpose  : Called to get the list of SubShapes IDs
528 //=================================================================================
529 SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs()
530 {
531   SMESH::long_array_var anArray = new SMESH::long_array;
532
533   // if ( myMainEntry != "" && myIsNotCorrected )
534   //   myListOfIDs = GetCorrectedListOfIDs( true );
535
536   int size = myListOfIDs.size();
537   anArray->length( size );
538   for (int i = 0; i < size; i++)
539     anArray[i] = myListOfIDs.at(i);
540
541   return anArray;
542 }
543
544 //=================================================================================
545 // function : SetListOfIds
546 // purpose  : Called to set the list of SubShapes IDs. Returns false if any ID is invalid
547 //=================================================================================
548 bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds)
549 {
550   mySelectedIDs.clear();
551   myListOfIDs.clear();
552   int size = theIds->length();
553   for ( int i = 0; i < size; i++ )
554     mySelectedIDs.append( theIds[ i ] );
555
556   myListWidget->blockSignals( true );
557   myListWidget->clear();
558   myListWidget->blockSignals( false );
559
560   bool isOk = true;
561   if ( myPreviewActor )
562   {
563     for ( int i = 0; i < size && isOk; i++ )
564       isOk = myPreviewActor->IsValidIndex( theIds[ i ] );
565   }
566   else if ( !myMainShape.IsNull() )
567   {
568     TopTools_IndexedMapOfShape aMainMap;
569     TopExp::MapShapes(myMainShape, aMainMap);
570     for ( int i = 0; i < size && isOk; i++ )
571       isOk = ( theIds[ i ] > 0 && theIds[ i ] <= aMainMap.Extent() );
572   }
573   // mySelectedIDs = GetCorrectedListOfIDs( false, &isOk );
574   onAdd();
575   return isOk;
576 }
577
578 //=================================================================================
579 // function : SetMainShapeEntry
580 // purpose  : Called to set the Entry of main shape of the mesh
581 //=================================================================================
582 // void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry )
583 // {
584 //   myMainEntry = theEntry;
585 //   myMainShape = GetTopoDSByEntry( theEntry );
586 //   myIsNotCorrected = true;
587 // }
588
589 //=================================================================================
590 // function : GetMainShapeEntry
591 // purpose  : Called to get the Main Object Entry
592 //=================================================================================
593 const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry()
594 {
595   if ( myMainEntry.empty() ) myMainEntry = "";
596   return myMainEntry.c_str();
597 }
598
599 //=================================================================================
600 // function : GetCorrectedListOfIds
601 // purpose  : Called to convert the list of IDs from sub-shape IDs to main shape IDs
602 //=================================================================================
603 // QList<int>
604 // StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape,
605 //                                                           bool* isOK )
606 // {
607 //   if (( myMainShape.IsNull() || myGeomShape.IsNull() ) &&  fromSubshapeToMainshape )
608 //     return myListOfIDs;
609 //   else if (( myMainShape.IsNull() /*||*/&& myGeomShape.IsNull() ) &&  !fromSubshapeToMainshape )
610 //     return mySelectedIDs;
611
612 //   if ( !fromSubshapeToMainshape ) // called from SetListOfIDs
613 //   {
614 //     if ( myMainShape.IsNull() )
615 //       std::swap( myMainShape, myGeomShape );
616 //   }
617
618 //   QList<int> aList;
619 //   TopTools_IndexedMapOfShape aGeomMap, aMainMap;
620 //   TopExp::MapShapes(myMainShape, aMainMap);
621 //   if ( !myGeomShape.IsNull() )
622 //     TopExp::MapShapes(myGeomShape, aGeomMap);
623
624 //   bool ok = true;
625 //   if ( fromSubshapeToMainshape ) // convert indexes from sub-shape to mainshape
626 //   {
627 //     int size = myListOfIDs.size();
628 //     for (int i = 0; i < size; i++) {
629 //       int index = myListOfIDs.at(i);
630 //       if ( aGeomMap.Extent() < index )
631 //       {
632 //         ok = false;
633 //       }
634 //       else
635 //       {
636 //         TopoDS_Shape aSubShape = aGeomMap.FindKey( index );
637 //         if ( mySubShType != aSubShape.ShapeType() )
638 //           ok = false;
639 //         if ( !aMainMap.Contains( aSubShape ))
640 //           ok = false;
641 //         else
642 //           index = aMainMap.FindIndex( aSubShape );
643 //       }
644 //       aList.append( index );
645 //     }
646 //     myIsNotCorrected = false;
647 //   }
648 //   else // convert indexes from main shape to sub-shape, or just check indices
649 //   {
650 //     int size = mySelectedIDs.size();
651 //     for (int i = 0; i < size; i++) {
652 //       int index = mySelectedIDs.at(i);
653 //       if ( aMainMap.Extent() < index )
654 //       {
655 //         ok = false;
656 //       }
657 //       else
658 //       {
659 //         TopoDS_Shape aSubShape = aMainMap.FindKey( index );
660 //         if ( mySubShType != aSubShape.ShapeType() )
661 //           ok = false;
662 //         if ( !aGeomMap.Contains( aSubShape ) && !aGeomMap.IsEmpty() )
663 //           ok = false;
664 //         else
665 //           index = aGeomMap.FindIndex( aSubShape );
666 //       }
667 //       aList.append( index );
668 //     }
669 //   }
670 //   if ( isOK ) *isOK = ok;
671
672 //   return aList;
673 // }
674
675 void StdMeshersGUI_SubShapeSelectorWdg::updateButtons()
676 {
677   if ( myPreviewActor ) {
678     int total = myPreviewActor->count();
679     int chunk = myPreviewActor->currentChunk();
680     int chunkSize = myPreviewActor->chunkSize();
681     int imin = chunk*chunkSize+1;
682     int imax = std::min((chunk+1)*chunkSize, total);
683     bool vis = imax > 0 && total > chunkSize;
684     myInfoLabel->setVisible( vis );
685     myPrevButton->setVisible( vis );
686     myNextButton->setVisible( vis );
687     myInfoLabel->setText( tr( "X_FROM_Y_ITEMS_SHOWN" ).arg(imin).arg(imax).arg(total) );
688     myPrevButton->setEnabled( myPreviewActor->hasPrevious() );
689     myNextButton->setEnabled( myPreviewActor->hasNext() );
690   }
691 }