Salome HOME
Update copyright information
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_SubShapeSelectorWdg.cxx
index 9a8e3827cdba266006dc49908b8f40e824c8512e..8c2240803cd2f493ca37e0d90c9524a86efa4bd6 100644 (file)
@@ -1,20 +1,20 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // File   : StdMeshersGUI_SubShapeSelectorWdg.cxx
@@ -50,7 +50,7 @@
 
 // GEOM Includes
 #include <GEOMBase.h>
-#include <GEOM_EdgeFilter.h>
+#include <GEOM_TypeFilter.h>
 #include <GEOM_CompoundFilter.h>
 
 // Qt includes
@@ -82,7 +82,7 @@
 //================================================================================
 
 StdMeshersGUI_SubShapeSelectorWdg
-::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent ): 
+::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent, TopAbs_ShapeEnum aSubShType ): 
   QWidget( parent ),
   myPreviewActor( 0 ),
   myMaxSize( -1 )
@@ -93,22 +93,30 @@ StdMeshersGUI_SubShapeSelectorWdg
   edgesLayout->setMargin( MARGIN );
   edgesLayout->setSpacing( SPACING );
   
-  myListWidget    = new QListWidget( this );
+  myListWidget   = new QListWidget( this );
   myAddButton    = new QPushButton( tr( "SMESH_BUT_ADD" ),    this );
   myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this );      
+  myInfoLabel    = new QLabel( this );
+  myPrevButton   = new QPushButton( "<<", this );
+  myNextButton   = new QPushButton( ">>", this );
   myListWidget->setSelectionMode( QListWidget::ExtendedSelection );
 
   edgesLayout->addWidget(myListWidget,   0, 0, 3, 3);
-  edgesLayout->addWidget(myAddButton,    0, 4);
-  edgesLayout->addWidget(myRemoveButton, 1, 4);
+  edgesLayout->addWidget(myAddButton,    0, 3);
+  edgesLayout->addWidget(myRemoveButton, 1, 3);
+  edgesLayout->addWidget(myInfoLabel,    3, 0, 1, 3);
+  edgesLayout->addWidget(myPrevButton,   4, 0);
+  edgesLayout->addWidget(myNextButton,   4, 2);
 
   edgesLayout->setRowStretch(2, 5);
-  edgesLayout->setColumnStretch(2, 5);
+  edgesLayout->setColumnStretch(1, 5);
 
-  setLayout( edgesLayout );
-  setMinimumWidth( 300 );
+  myListWidget->setMinimumWidth(300);
+  myInfoLabel->setMinimumWidth(300);
+  myInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+  myInfoLabel->setAlignment(Qt::AlignCenter);
 
-  mySubShType = TopAbs_EDGE;
+  mySubShType = aSubShType;
 
   init();
 }
@@ -166,18 +174,13 @@ void StdMeshersGUI_SubShapeSelectorWdg::init()
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode( ActorSelection );
 
-
-  SalomeApp_Study* study = mySMESHGUI->activeStudy();
-  GEOM_EdgeFilter* edgeFilter = new GEOM_EdgeFilter(study,StdSelect_AnyEdge);
-  GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study);
-  gpoupFilter->addSubType( TopAbs_EDGE );
-  myGeomFilters.append( edgeFilter );
-  myGeomFilters.append( gpoupFilter );
-  myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR );
-  mySelectionMgr->installFilter( myFilter );
+  myFilter=0;
+  //setFilter();
 
   connect( myAddButton,    SIGNAL(clicked()), SLOT(onAdd()));
   connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove()));
+  connect( myPrevButton,   SIGNAL(clicked()), SLOT(onPrevious()));
+  connect( myNextButton,   SIGNAL(clicked()), SLOT(onNext()));
   
   connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
   connect( myListWidget,   SIGNAL(itemSelectionChanged()),    this, SLOT(onListSelectionChanged()));
@@ -185,6 +188,24 @@ void StdMeshersGUI_SubShapeSelectorWdg::init()
   updateState();
 }
 
+//================================================================================
+/*!
+ * \brief Install filters to select sub-shapes of mySubShType or their groups
+ */
+//================================================================================
+
+void StdMeshersGUI_SubShapeSelectorWdg::setFilter()
+{
+  SalomeApp_Study* study = mySMESHGUI->activeStudy();
+  GEOM_TypeFilter* typeFilter = new GEOM_TypeFilter(study, mySubShType, /*isShapeType=*/true );
+  GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study);
+  gpoupFilter->addSubType( mySubShType );
+  myGeomFilters.append( typeFilter );
+  myGeomFilters.append( gpoupFilter );
+  myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR );
+  mySelectionMgr->installFilter( myFilter );
+}
+
 //================================================================================
 /*!
  *  Create a layout, initialize fields
@@ -285,6 +306,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument()
   myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && mySelectedIDs.size() > 0 && ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) );
 
   //Connect Selected Ids in viewer and dialog's Ids list
+  bool signalsBlocked = myListWidget->blockSignals( true );
   myListWidget->clearSelection();
   if ( mySelectedIDs.size() > 0 ) {
     for (int i = 0; i < mySelectedIDs.size(); i++) {
@@ -295,6 +317,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument()
         item->setSelected(true);
     }
   }
+  myListWidget->blockSignals( signalsBlocked );
 }
 
 //=================================================================================
@@ -349,6 +372,28 @@ void StdMeshersGUI_SubShapeSelectorWdg::onRemove()
   myAddButton->setEnabled( true );
 }
 
+void StdMeshersGUI_SubShapeSelectorWdg::onPrevious()
+{
+  if ( myPreviewActor ) {
+    myPreviewActor->previous();
+    myListWidget->clearSelection();
+    updateButtons();
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->Repaint();
+  }
+}
+
+void StdMeshersGUI_SubShapeSelectorWdg::onNext()
+{
+  if ( myPreviewActor ) {
+    myPreviewActor->next();
+    myListWidget->clearSelection();
+    updateButtons();
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->Repaint();
+  }
+}
+
 //=================================================================================
 // function : onListSelectionChanged()
 // purpose  : Called when selection in element list is changed
@@ -371,7 +416,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged()
 
 //=================================================================================
 // function : setGeomShape
-// purpose  : Called to set geometry
+// purpose  : Called to set geometry whose sub-shapes are selected
 //================================================================================
 void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEntry )
 {
@@ -393,6 +438,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState()
   bool state = false;
   if ( !myGeomShape.IsNull() )
     state = true;
+  myInfoLabel->setVisible( false );
+  myPrevButton->setVisible( false );
+  myNextButton->setVisible( false );
   
   myListWidget->setEnabled( state );
   myAddButton->setEnabled( mySelectedIDs.size() > 0 );
@@ -408,6 +456,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState()
       myPreviewActor->AddToRender( myRenderer );
       aViewWindow->Repaint();
     }
+    updateButtons();
   }
 }
 
@@ -484,7 +533,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI
 
 //=================================================================================
 // function : SetMainShapeEntry
-// purpose  : Called to set the Main Object Entry
+// purpose  : Called to set the Entry of main shape of the mesh
 //=================================================================================
 void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry )
 {
@@ -507,7 +556,7 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry()
 
 //=================================================================================
 // function : GetCorrectedListOfIds
-// purpose  : Called to convert the list of IDs from subshape IDs to main shape IDs
+// purpose  : Called to convert the list of IDs from sub-shape IDs to main shape IDs
 //=================================================================================
 QList<int> StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape )
 {
@@ -522,7 +571,7 @@ QList<int> StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu
   TopExp::MapShapes(myGeomShape, aGeomMap);
   TopExp::MapShapes(myMainShape, aMainMap);
 
-  if ( fromSubshapeToMainshape ) { // convert indexes from subshape to mainshape
+  if ( fromSubshapeToMainshape ) { // convert indexes from sub-shape to mainshape
     int size = myListOfIDs.size();
     for (int i = 0; i < size; i++) {
       TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) );
@@ -530,7 +579,7 @@ QList<int> StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu
       aList.append( index );
     }
     myIsNotCorrected = false;
-  } else { // convert indexes from main shape to subshape
+  } else { // convert indexes from main shape to sub-shape
     int size = mySelectedIDs.size();
     for (int i = 0; i < size; i++) {
       TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) );
@@ -541,3 +590,21 @@ QList<int> StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu
 
   return aList;
 }
+
+void StdMeshersGUI_SubShapeSelectorWdg::updateButtons()
+{
+  if ( myPreviewActor ) {
+    int total = myPreviewActor->count();
+    int chunk = myPreviewActor->currentChunk();
+    int chunkSize = myPreviewActor->chunkSize();
+    int imin = chunk*chunkSize+1;
+    int imax = std::min((chunk+1)*chunkSize, total);
+    bool vis = imax > 0 && total > chunkSize;
+    myInfoLabel->setVisible( vis );
+    myPrevButton->setVisible( vis );
+    myNextButton->setVisible( vis );
+    myInfoLabel->setText( tr( "X_FROM_Y_ITEMS_SHOWN" ).arg(imin).arg(imax).arg(total) );
+    myPrevButton->setEnabled( myPreviewActor->hasPrevious() );
+    myNextButton->setEnabled( myPreviewActor->hasNext() );
+  }
+}