]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
0020918: EDF 1447 SMESH: Mesh common borders
authoreap <eap@opencascade.com>
Fri, 12 Nov 2010 15:00:50 +0000 (15:00 +0000)
committereap <eap@opencascade.com>
Fri, 12 Nov 2010 15:00:50 +0000 (15:00 +0000)
   Add possibility of selecting many objects

src/StdMeshersGUI/StdMeshersGUI_ObjectReferenceParamWdg.cxx
src/StdMeshersGUI/StdMeshersGUI_ObjectReferenceParamWdg.h

index 06f2431eca8ce45ea55b924d1833517269a5b29b..e69489aeb33c3c3fa9ac4786b610383e95e82d5b 100644 (file)
 #include <LightApp_SelectionMgr.h>
 #include <SVTK_ViewWindow.h>
 #include <SALOME_ListIO.hxx>
+#include <SALOME_ListIteratorOfListIO.hxx>
 
 // SALOME KERNEL incldues
 #include <SALOMEDSClient_SObject.hxx>
+#include <SALOMEDSClient_Study.hxx>
 
 // Qt includes
 #include <QPushButton>
@@ -54,8 +56,8 @@
 //================================================================================
 
 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
-( SUIT_SelectionFilter* f, QWidget* parent)
-  : QWidget( parent )
+( SUIT_SelectionFilter* f, QWidget* parent, bool multiSelection)
+  : QWidget( parent ), myMultiSelection( multiSelection )
 {
   myFilter = f;
   init();
@@ -69,8 +71,8 @@ StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
 //================================================================================
 
 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
-( MeshObjectType objType, QWidget* parent )
-  : QWidget( parent )
+( MeshObjectType objType, QWidget* parent, bool multiSelection )
+  : QWidget( parent ), myMultiSelection( multiSelection )
 {
   myFilter = new SMESH_TypeFilter( objType );
   init();
@@ -84,7 +86,10 @@ StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
 {
   if ( myFilter )
+  {
+    mySelectionMgr->removeFilter( myFilter );
     delete myFilter;
+  }
 }
 
 
@@ -184,7 +189,7 @@ void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
 
 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
 {
-  myObject = CORBA::Object::_nil();
+  myObjects.clear();
   myObjNameLineEdit->setText( "" );
   myParamValue = "";
 
@@ -194,11 +199,43 @@ void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
   if ( sobj ) {
     std::string name = sobj->GetName();
     myObjNameLineEdit->setText( name.c_str() );
-    myObject = CORBA::Object::_duplicate( obj );
+    myObjects.push_back( CORBA::Object::_duplicate( obj ));
     myParamValue = sobj->GetID().c_str();
   }
 }
 
+//================================================================================
+/*!
+ * \brief Initialize selected objects
+ * \param objects - entries of objects
+ */
+//================================================================================
+
+void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
+{
+  myObjects.clear();
+  myObjNameLineEdit->setText( "" );
+  myParamValue = "";
+
+  for ( unsigned i = 0; i < objects->length(); ++i )
+  {
+    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+    _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
+    CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
+    if ( !CORBA::is_nil( anObj )) {
+      std::string name = aSObj->GetName();
+      QString text = myObjNameLineEdit->text();
+      if ( !text.isEmpty() )
+        text += " ";
+      text += name.c_str();
+      myObjNameLineEdit->setText( text );
+      myObjects.push_back( anObj );
+      myParamValue += " ";
+      myParamValue += objects[i];
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief Takes selected object
@@ -212,7 +249,26 @@ void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
     SALOME_ListIO aList;
     mySelectionMgr->selectedObjects(aList);
     if (aList.Extent() == 1)
+    {
       obj = SMESH::IObjectToObject( aList.First() );
-    SetObject( obj.in() );
+      SetObject( obj.in() );
+    }
+    else if (myMultiSelection)
+    {
+      SMESH::string_array_var objIds = new SMESH::string_array;
+      objIds->length( aList.Extent());
+      SALOME_ListIteratorOfListIO io( aList );
+      int i = 0;
+      for ( ; io.More(); io.Next(), ++i )
+      {
+        Handle(SALOME_InteractiveObject) anIO = io.Value();
+        if ( anIO->hasEntry() )
+          objIds[i] = anIO->getEntry();
+        else
+          i--;
+      }
+      objIds->length(i);
+      SetObjects( objIds );
+    }
   }
 }
index c5fabc25e741af1fa2efac0114a97ac90e2c3f98..e8c3871945955be5b755b0ae4bfbc7584c33c988 100644 (file)
@@ -37,6 +37,8 @@
 // CORBA includes
 #include <CORBA.h>
 
+#include CORBA_SERVER_HEADER(SMESH_Mesh)
+
 class SUIT_SelectionFilter;
 class SMESHGUI;
 class LightApp_SelectionMgr;
@@ -52,22 +54,29 @@ class STDMESHERSGUI_EXPORT StdMeshersGUI_ObjectReferenceParamWdg : public QWidge
 
 public:
   StdMeshersGUI_ObjectReferenceParamWdg( SUIT_SelectionFilter* filter, 
-                                         QWidget*              parent);
+                                         QWidget*              parent,
+                                         bool                  multiSelection=false);
   StdMeshersGUI_ObjectReferenceParamWdg( MeshObjectType objType,
-                                         QWidget*       parent);
+                                         QWidget*       parent,
+                                         bool           multiSelection=false);
   ~StdMeshersGUI_ObjectReferenceParamWdg();
 
   void SetObject(CORBA::Object_ptr obj);
 
+  void SetObjects(SMESH::string_array_var& objEntries);
+
   template<class TInterface> 
-    typename TInterface::_var_type GetObject() const {
-    if ( IsObjectSelected() ) return TInterface::_narrow(myObject);
+    typename TInterface::_var_type GetObject(unsigned i=0) const {
+    if ( IsObjectSelected(i) ) return TInterface::_narrow(myObjects[i]);
     return TInterface::_nil();
   }
 
+  int NbObjects() const { return myObjects.size(); }
+
   QString GetValue() const { return myParamValue; }
 
-  bool IsObjectSelected() const { return !CORBA::is_nil(myObject); }
+  bool IsObjectSelected(unsigned i=0) const
+  { return i < myObjects.size() && !CORBA::is_nil(myObjects[i]); }
 
   void AvoidSimultaneousSelection( StdMeshersGUI_ObjectReferenceParamWdg* other);
 
@@ -97,7 +106,10 @@ private:
   void init();
   
 private:
- CORBA::Object_var      myObject;
+
+  bool                                myMultiSelection;
+  std::vector<CORBA::Object_var>      myObjects;
+
  SUIT_SelectionFilter*  myFilter;
  bool                   mySelectionActivated;