Salome HOME
Update French translation file
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_SubShapeSelectorWdg.cxx
index 26527d85b14f223611883dc92b9d6601bd51f4f9..80259747bf3876b0b240a01bc1beb36308892124 100644 (file)
@@ -1,40 +1,38 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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
 // Author : Open CASCADE S.A.S. (dmv)
 // SMESH includes
 //
-
 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
 
 // SMESH Includes
-#include <SMESH_Type.h>
+#include "SMESH_Type.h"
 #include "SMESHGUI_MeshUtils.h"
-#include <SMESH_Actor.h>
-#include <SMESH_PreviewActorsCollection.h>
-#include <SMESH_ActorUtils.h>
+#include "SMESH_Actor.h"
+#include "SMESH_PreviewActorsCollection.h"
+#include "SMESH_ActorUtils.h"
 #include "SMESHGUI_GroupUtils.h"
 #include "SMESH_Gen_i.hxx"
 #include "SMESHGUI_GEOMGenUtils.h"
+#include "SMESH_LogicalFilter.hxx"
 
 // SVTK Includes
 #include <SVTK_ViewWindow.h>
@@ -52,6 +50,8 @@
 
 // GEOM Includes
 #include <GEOMBase.h>
+#include <GEOM_TypeFilter.h>
+#include <GEOM_CompoundFilter.h>
 
 // Qt includes
 #include <QPushButton>
 #include <TopoDS_Shape.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
+#include <StdSelect_TypeOfEdge.hxx>
 
 // SALOME KERNEL includes
 #include <SALOMEDS_SObject.hxx>
 
+
 #define SPACING 6
 #define MARGIN 0
 
 //================================================================================
 
 StdMeshersGUI_SubShapeSelectorWdg
-::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent ): 
+::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent, TopAbs_ShapeEnum aSubShType ): 
   QWidget( parent ),
   myPreviewActor( 0 ),
-  myMaxSize( 0 )
+  myMaxSize( -1 )
 {
   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
 
@@ -91,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();
 }
@@ -131,6 +141,14 @@ StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg()
   myEntry = "";
   myParamValue = "";
   myMainShape.Nullify();
+
+  if ( mySelectionMgr && myFilter )
+    mySelectionMgr->removeFilter( myFilter );
+  delete myFilter; myFilter=0;
+
+  SUIT_SelectionFilter* filter;
+  foreach( filter, myGeomFilters )
+    delete filter;
 }
 
 //================================================================================
@@ -146,6 +164,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::init()
   myListOfIDs.clear();
   mySelectedIDs.clear();
 
+  myAddButton->setEnabled( false );
+  myRemoveButton->setEnabled( false );
+
   mySMESHGUI     = SMESHGUI::GetSMESHGUI();
   mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
@@ -153,8 +174,13 @@ void StdMeshersGUI_SubShapeSelectorWdg::init()
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode( ActorSelection );
 
+  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()));
@@ -162,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
@@ -199,65 +243,81 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument()
   mySelectionMgr->selectedObjects( aList );
   int nbSel = aList.Extent();
 
-  if (nbSel < 1)
-    return;
-
-  SALOME_ListIteratorOfListIO anIt (aList);
+  if (nbSel > 0) {
+    SALOME_ListIteratorOfListIO anIt (aList);
     
-  for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects
-    Handle(SALOME_InteractiveObject) IO = anIt.Value();
-
-    GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() );  
-    if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study
-      GEOM::GEOM_Object_ptr aGeomFatherObj = aGeomObj->GetMainShape();
-      QString aFatherEntry = "";
-      QString aMainFatherEntry = "";
-      TopoDS_Shape shape;
-      if ( !CORBA::is_nil( aGeomFatherObj ) ) {
-        // Get Main Shape
-        GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry );
-        if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) {  // Main Shape is a Group
-          GEOM::GEOM_Object_ptr aMainFatherObj = aGeomMain->GetMainShape();
-          if ( !CORBA::is_nil( aMainFatherObj ) )
-            aMainFatherEntry = aMainFatherObj->GetStudyEntry();
-        }
-        aFatherEntry = aGeomFatherObj->GetStudyEntry();
-      }
+    for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects
+      Handle(SALOME_InteractiveObject) IO = anIt.Value();
       
-      if ( aFatherEntry != "" && ( aFatherEntry == myEntry || aFatherEntry == aMainFatherEntry ) ) {
-        if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object
-          GEOMBase::GetShape(aGeomObj, shape); 
-          if ( !shape.IsNull() ) {
-            TopExp_Explorer exp( shape, mySubShType );
-            for ( ; exp.More(); exp.Next() ) {
-              int index = myPreviewActor->GetIndexByShape( exp.Current() );
+      GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() );  
+      if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study
+        GEOM::GEOM_Object_ptr aGeomFatherObj = aGeomObj->GetMainShape();
+        QString aFatherEntry = "";
+        QString aMainFatherEntry = "";
+        TopoDS_Shape shape;
+        if ( !CORBA::is_nil( aGeomFatherObj ) ) {
+          // Get Main Shape
+          GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry );
+          if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) {  // Main Shape is a Group
+            GEOM::GEOM_Object_ptr aMainFatherObj = aGeomMain->GetMainShape();
+            if ( !CORBA::is_nil( aMainFatherObj ) )
+              aMainFatherEntry = aMainFatherObj->GetStudyEntry();
+          }
+          aFatherEntry = aGeomFatherObj->GetStudyEntry();
+        }
+        
+        if ( aFatherEntry != "" && ( aFatherEntry == myEntry || aFatherEntry == aMainFatherEntry ) )
+        {
+          if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object
+            GEOMBase::GetShape(aGeomObj, shape); 
+            if ( !shape.IsNull() ) {
+              TopExp_Explorer exp( shape, mySubShType );
+              for ( ; exp.More(); exp.Next() ) {
+                int index = myPreviewActor->GetIndexByShape( exp.Current() );
+                if ( index ) {
+                  mySelectedIDs.append( index );
+                  myPreviewActor->HighlightID( index );
+                }
+              }
+            }
+          } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/  ) {
+            GEOMBase::GetShape(aGeomObj, shape); 
+            if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) {
+              int index = myPreviewActor->GetIndexByShape( shape );
               if ( index ) {
                 mySelectedIDs.append( index );
                 myPreviewActor->HighlightID( index );
               }
             }
           }
-        } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/  ) {
-          GEOMBase::GetShape(aGeomObj, shape); 
-          if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) {
-            int index = myPreviewActor->GetIndexByShape( shape );
-            if ( index ) {
-              mySelectedIDs.append( index );
-              myPreviewActor->HighlightID( index );
-            }
-          }
         }
+      } else { // Selected Actor from Actor Collection
+        QString anEntry = IO->getEntry();
+        QString str = "_";
+        int index = anEntry.lastIndexOf( str );
+        anEntry.remove(0, index+1);
+        int ind = anEntry.toInt();
+        if ( ind )
+          mySelectedIDs.append( ind );
       }
-    } else { // Selected Actor from Actor Collection
-      QString anEntry = IO->getEntry();
-      QString str = "_";
-      int index = anEntry.lastIndexOf( str );
-      anEntry.remove(0, index+1);
-      int ind = anEntry.toInt();
-      if ( ind )
-        mySelectedIDs.append( ind );
     }
   }
+  // update add button
+  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++) {
+      QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
+      QList<QListWidgetItem*> anItems = myListWidget->findItems ( anID, Qt::MatchExactly );
+      QListWidgetItem* item;
+      foreach(item, anItems)
+        item->setSelected(true);
+    }
+  }
+  myListWidget->blockSignals( signalsBlocked );
 }
 
 //=================================================================================
@@ -270,7 +330,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::onAdd()
     return;
 
   myListWidget->blockSignals( true );
-  for (int i = 0; i < mySelectedIDs.size() && (myMaxSize 1 || myListOfIDs.size() < myMaxSize); i++) {
+  for (int i = 0; i < mySelectedIDs.size() && (myMaxSize == -1 || myListOfIDs.size() < myMaxSize); i++) {
     if ( myListOfIDs.indexOf( mySelectedIDs.at(i) ) == -1 ) {
       QString anID = QString(" %1").arg( mySelectedIDs.at(i) );
 
@@ -282,7 +342,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::onAdd()
   }
   onListSelectionChanged();
   myListWidget->blockSignals( false );
-  myAddButton->setEnabled( myListOfIDs.size() < myMaxSize );
+  myAddButton->setEnabled( myMaxSize == -1 || myListOfIDs.size() < myMaxSize );
 }
          
 //=================================================================================
@@ -312,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
@@ -327,11 +409,14 @@ void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged()
   QListWidgetItem* anItem;
   foreach(anItem, selItems)
     myPreviewActor->HighlightID( anItem->text().toInt() );
+
+  // update remove button
+  myRemoveButton->setEnabled( selItems.size() > 0 );
 }
 
 //=================================================================================
 // function : setGeomShape
-// purpose  : Called to set geometry
+// purpose  : Called to set geometry whose sub-shapes are selected
 //================================================================================
 void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEntry )
 {
@@ -353,10 +438,12 @@ 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( state );
-  myRemoveButton->setEnabled( state );
+  myAddButton->setEnabled( mySelectedIDs.size() > 0 );
   
   if (state) {
     myPreviewActor = new SMESH_PreviewActorsCollection();
@@ -369,6 +456,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState()
       myPreviewActor->AddToRender( myRenderer );
       aViewWindow->Repaint();
     }
+    updateButtons();
   }
 }
 
@@ -445,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 )
 {
@@ -502,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() );
+  }
+}