Salome HOME
Porting to Qt4.
[modules/geom.git] / src / GEOMGUI / GEOMGUI_OCCSelector.cxx
index c0868ae60170cbb3c8631cf473d7cda25d566bdb..27d2340fdfd5276d254b3fcd800114ec4a2da1df 100644 (file)
@@ -15,7 +15,7 @@
 // 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/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "GEOMGUI_OCCSelector.h"
 
@@ -23,8 +23,6 @@
 
 #include <OCCViewer_ViewModel.h>
 
-#include <SALOME_InteractiveObject.hxx>
-
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <SelectMgr_Selection.hxx>
 #include <SelectBasics_SensitiveEntity.hxx>
+#include <StdSelect_BRepOwner.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
-#include <SelectMgr_IndexedMapOfOwner.hxx>
 #include <NCollection_DataMap.hxx>
 
+#include <SUIT_Session.h>
+#include <SalomeApp_Study.h>
+
 
 //================================================================
 // Function : GEOMGUI_OCCSelector
@@ -73,7 +74,7 @@ void GEOMGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
     {
       for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
        {
-         Handle(SelectMgr_EntityOwner) anOwner = ic->SelectedOwner();
+         Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(ic->SelectedOwner());
          if ( anOwner.IsNull() )
            continue;
          
@@ -123,6 +124,12 @@ void GEOMGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
            }
        }
     }
+  // add externally selected objects
+  SUIT_DataOwnerPtrList::const_iterator anExtIter;
+  for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
+    aList.append(*anExtIter);
+  }
+  
 }
 
 //================================================================
@@ -172,11 +179,7 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
 
   Handle(AIS_InteractiveContext) ic = vw->getAISContext();
 
-#ifndef WNT
   NCollection_DataMap<TCollection_AsciiString, TColStd_IndexedMapOfInteger> indexesMap; // "entry - list_of_int" map for LOCAL selection
-#else
-  NCollection_DataMap<Standard_CString, TColStd_IndexedMapOfInteger> indexesMap; // "entry - list_of_int" map for LOCAL selection
-#endif
   QMap<QString,int> globalSelMap; // only Key=entry from this map is used.  value(int) is NOT used at all.
   SelectMgr_IndexedMapOfOwner ownersmap; // map of owners to be selected
   
@@ -192,12 +195,12 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
     {
       QString entry = subOwner->entry();
 #ifndef WNT
-      if ( indexesMap.IsBound( TCollection_AsciiString((char*)entry.latin1())))
+      if ( indexesMap.IsBound( TCollection_AsciiString(entry.toLatin1().data())))
 #else
-         if ( indexesMap.IsBound( (char*)entry.latin1()))
+         if ( indexesMap.IsBound( (char*)entry.toLatin1()))
 #endif
       {
-       TColStd_IndexedMapOfInteger& subIndexes = indexesMap.ChangeFind((char*)entry.latin1());
+       TColStd_IndexedMapOfInteger& subIndexes = indexesMap.ChangeFind(entry.toLatin1().data());
        subIndexes.Add( subOwner->index() );
        //indexesMap.replace( entry, subIndexes );
       }
@@ -205,7 +208,7 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
       {
        TColStd_IndexedMapOfInteger subIndexes;
        subIndexes.Add( subOwner->index() );
-       indexesMap.Bind((char*)entry.latin1(), subIndexes);
+       indexesMap.Bind(entry.toLatin1().data(), subIndexes);
       }
     } 
     else // the owner is NOT a sub owner, maybe it is a DataOwner == GLOBAL selection
@@ -213,7 +216,10 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
       const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
       if ( owner )
       {
-       globalSelMap[owner->entry()] = 1;
+       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+       QString anEntry = appStudy->referencedToEntry( owner->entry() );
+       
+       globalSelMap[anEntry] = 1;
       }
     }
   }
@@ -231,7 +237,9 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
 
       for  ( int i = 1, n = owners.Extent(); i <= n; i++ ) 
       {
-       Handle(SelectMgr_EntityOwner) anOwner = owners( i );
+
+       Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(owners( i ));
+
        if ( anOwner.IsNull() || !anOwner->HasShape() )
          continue;
 
@@ -239,18 +247,19 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
        if ( !anOwner->ComesFromDecomposition() && globalSelMap.contains( entryStr ) ) 
        {
          ownersmap.Add( anOwner );
+         globalSelMap[entryStr]++;
        }
        // LOCAL selection
        else
        {
          Handle(AIS_Shape) aisShape = Handle(AIS_Shape)::DownCast( io );
 
-         if ( !aisShape.IsNull() && indexesMap.IsBound( (char*)entryStr.latin1() ) )
+         if ( !aisShape.IsNull() && indexesMap.IsBound( entryStr.toLatin1().data() ) )
          {
            TopoDS_Shape shape = aisShape->Shape();
            TopTools_IndexedMapOfShape aMapOfShapes;
            TopExp::MapShapes( shape, aMapOfShapes );
-           const TColStd_IndexedMapOfInteger& subIndexes = indexesMap.ChangeFind((char*)entryStr.latin1());
+           const TColStd_IndexedMapOfInteger& subIndexes = indexesMap.ChangeFind(entryStr.toLatin1().data());
 
            const TopoDS_Shape& aSubShape = anOwner->Shape();
            int  aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
@@ -283,4 +292,20 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
   }
 
   vw->update();
+  
+  // fill extra selected
+  mySelectedExternals.clear();
+  for ( SUIT_DataOwnerPtrList::const_iterator itr2 = aList.begin(); itr2 != aList.end(); ++itr2 ) {
+    const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr2).operator->() );
+    if ( !subOwner )
+    {
+      const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr2).operator->() );
+      if ( owner )
+      {
+       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+       QString anEntry = appStudy->referencedToEntry( owner->entry() );
+       if (globalSelMap[anEntry] == 1) mySelectedExternals.append(*itr2);
+      }
+    }
+  }
 }