Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / LightApp / LightApp_VTKSelector.cxx
index d28da9faed22f01f9c422bd8777d048cf3ed6c53..70db9624fa29aab715200b7910c4fbb30dfb4e8d 100644 (file)
@@ -1,24 +1,30 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2016  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 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 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// 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 
+// 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
 //
+
 #include "LightApp_VTKSelector.h"
 #include "LightApp_DataOwner.h"
 
+#include "SUIT_Desktop.h"
+
 #ifndef DISABLE_VTKVIEWER
   #include "SVTK_ViewModelBase.h"
   #include "SVTK_ViewManager.h"
   #include "SVTK_Functor.h"
   #include "VTKViewer_Algorithm.h"
   #include <vtkRenderer.h>
+  #include "SVTK_ViewModel.h"
 #endif
 
 #ifndef DISABLE_SALOMEOBJECT
   #include "SALOME_Actor.h"
-  #include "SALOME_ListIteratorOfListIO.hxx"
+  #include "SALOME_ListIO.hxx"
 #endif
 
-
+#include <utilities.h>
 
 #ifndef DISABLE_VTKVIEWER
 #ifndef DISABLE_SALOMEOBJECT
 /*!
   Constructor.
 */
-LightApp_SVTKDataOwner
-::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
-                         SUIT_Desktop* theDesktop ):
-  LightApp_DataOwner( theIO ),
-  myDesktop( theDesktop )
-{}
-#endif
-
-/*!
-  Destuctor.
-*/
-LightApp_SVTKDataOwner
-::~LightApp_SVTKDataOwner()
+LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO,
+                                                                  SUIT_Desktop* theDesktop )
+: LightApp_DataOwner( theIO ),
+myDesktop( theDesktop )
+{
+}
+#else
+LightApp_SVTKDataOwner::LightApp_SVTKDataOwner( const QString& theEntry )
+: LightApp_DataOwner( theEntry )
 {
 }
+#endif
 
 /*!
   \return active SVTK view window
@@ -99,7 +103,7 @@ LightApp_SVTKDataOwner
     }
   }
   
-  return -1;
+  return ActorSelection; // workaround for embedded VTK viewer in a module : is it safe ?
 }
 
 /*!
@@ -111,7 +115,8 @@ LightApp_SVTKDataOwner
 {
   if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){
     using namespace SVTK;
-    return Find<SALOME_Actor>(aViewWindow->getRenderer()->GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
+    VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
+    return Find<SALOME_Actor>(aCopy.GetActors(),TIsSameIObject<SALOME_Actor>(IO()));
   }
 
   return NULL;
@@ -119,6 +124,14 @@ LightApp_SVTKDataOwner
 
 #endif
 
+/*!
+  Destuctor.
+*/
+/*
+LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner()
+{
+}
+*/
 
 #ifndef DISABLE_VTKVIEWER
 /*!
@@ -126,7 +139,7 @@ LightApp_SVTKDataOwner
 */
 LightApp_VTKSelector
 ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer, 
-                       SUIT_SelectionMgr* mgr ): 
+                        SUIT_SelectionMgr* mgr ): 
   SUIT_Selector( mgr, viewer ),
   myViewer( viewer )
 {
@@ -134,14 +147,6 @@ LightApp_VTKSelector
     connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
 }
 
-/*!
-  Destructor.
-*/
-LightApp_VTKSelector
-::~LightApp_VTKSelector()
-{
-}
-
 /*!
   Gets viewer.
 */
@@ -182,20 +187,24 @@ void
 LightApp_VTKSelector
 ::getSelection( SUIT_DataOwnerPtrList& aList ) const
 {
-  if(myViewer){
+  if( myViewer ) {
+    if( SVTK_Viewer* aSViewer = dynamic_cast<SVTK_Viewer*>(myViewer) ) {
+      if( !aSViewer->isSelectionEnabled() ) 
+       return;
+    }
     if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
       if(SVTK_ViewManager* aViewMgr = dynamic_cast<SVTK_ViewManager*>(aViewManager)){
-       if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
-         if(SVTK_Selector* aSelector = aView->GetSelector()){
-           const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
-           SALOME_ListIteratorOfListIO anIter(aListIO);
-           for(; anIter.More(); anIter.Next()){
-             Handle(SALOME_InteractiveObject) anIO = anIter.Value();
-             if(anIO->hasEntry())
-               aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
-           }
-         }
-       }
+        if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
+          if(SVTK_Selector* aSelector = aView->GetSelector()){
+            const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
+            SALOME_ListIteratorOfListIO anIter(aListIO);
+            for(; anIter.More(); anIter.Next()){
+              Handle(SALOME_InteractiveObject) anIO = anIter.Value();
+              if(anIO->hasEntry())
+                aList.append(new LightApp_SVTKDataOwner(anIO,aViewMgr->getDesktop()));
+            }
+          }
+        }
       }
     }
   }
@@ -208,48 +217,50 @@ void
 LightApp_VTKSelector
 ::setSelection( const SUIT_DataOwnerPtrList& theList )
 {
-  if(myViewer){
+  SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myViewer);
+  if(myViewer && aViewer && aViewer->isSelectionEnabled()){
     if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){
       if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewMgr->getActiveView())){
-       if(SVTK_Selector* aSelector = aView->GetSelector()){
-         SALOME_ListIO anAppendList;
-         const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
-         SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
-         for(; anIter != theList.end(); ++anIter){
-           const SUIT_DataOwner* aDataOwner = (*anIter).get();
-           if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
-             aSelector->SetSelectionMode(anOwner->GetMode());
-             Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
+        if(SVTK_Selector* aSelector = aView->GetSelector()){
+          SALOME_ListIO anAppendList;
+          const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
+          SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
+          for(; anIter != theList.end(); ++anIter){
+            const SUIT_DataOwner* aDataOwner = (*anIter).get();
+            if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
+              MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
+              aSelector->SetSelectionMode(anOwner->GetMode());
+              Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
 
-             aSelector->AddIObject(anIO);
+              aSelector->AddIObject(anIO);
 
-             anAppendList.Append(anIO);
-             aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
-           }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
-             Handle(SALOME_InteractiveObject) anIO = 
-               new SALOME_InteractiveObject(anOwner->entry().latin1(),"");
-             aSelector->AddIObject(anIO);
-             anAppendList.Append(anIO);
-           }
-         }
-         // To remove IOs, which is not selected.
-         QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
-         SALOME_ListIteratorOfListIO anIt( aStoredList );
-         for( ; anIt.More(); anIt.Next() )
-           if( !anIt.Value().IsNull() )
-             toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
+              anAppendList.Append(anIO);
+              aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
+            }else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner)){
+              Handle(SALOME_InteractiveObject) anIO = 
+                new SALOME_InteractiveObject(anOwner->entry().toUtf8(),"");
+              aSelector->AddIObject(anIO);
+              anAppendList.Append(anIO);
+            }
+          }
+          // To remove IOs, which is not selected.
+          QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
+          SALOME_ListIteratorOfListIO anIt( aStoredList );
+          for( ; anIt.More(); anIt.Next() )
+            if( !anIt.Value().IsNull() )
+              toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
 
-         anIt = SALOME_ListIteratorOfListIO(anAppendList);
-         for( ; anIt.More(); anIt.Next() )
-           toRemove.remove( anIt.Value()->getEntry() );
+          anIt = SALOME_ListIteratorOfListIO(anAppendList);
+          for( ; anIt.More(); anIt.Next() )
+            toRemove.remove( anIt.Value()->getEntry() );
 
-         QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
-                                                                            REnd = toRemove.end();
-         for( ; RIt!=REnd; RIt++ )
-           aSelector->RemoveIObject( RIt.data() );
-         
-         aView->onSelectionChanged();
-       }
+          QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
+                                                                             REnd = toRemove.end();
+          for( ; RIt!=REnd; RIt++ )
+            aSelector->RemoveIObject( RIt.value() );
+          
+          aView->onSelectionChanged();
+        }
       }
     }
   }