Salome HOME
Add Python wrappings for Python console.
[modules/gui.git] / src / LightApp / LightApp_OCCSelector.cxx
index 446ae593bf46bdbea8381408e4d4823d1f35c556..97c7ebd933030e7315eb7b99f23fa7f134b058fe 100644 (file)
@@ -1,17 +1,20 @@
-// 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
 /*!
   Constructor
 */
+#ifndef DISABLE_OCCVIEWER
 LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr )
 : SUIT_Selector( mgr, viewer ),
   myViewer( viewer )
 {
-  if ( myViewer )
+  if ( myViewer ) {
     connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
+    connect( myViewer, SIGNAL( deselection() ), this, SLOT( onDeselection() ) );
+  }
 }
+#else
+LightApp_OCCSelector::LightApp_OCCSelector(  SUIT_SelectionMgr* mgr )
+: SUIT_Selector( mgr )
+{}
+#endif
 
 /*!
   Destructor.
@@ -47,10 +58,13 @@ LightApp_OCCSelector::~LightApp_OCCSelector()
 /*!
   Gets viewer.
 */
+#ifndef DISABLE_OCCVIEWER
 OCCViewer_Viewer* LightApp_OCCSelector::viewer() const
 {
   return myViewer;
 }
+#endif
+
 
 /*!On selection changed.*/
 void LightApp_OCCSelector::onSelectionChanged()
@@ -58,12 +72,22 @@ void LightApp_OCCSelector::onSelectionChanged()
   selectionChanged();
 }
 
+/*!On selection cleared.*/
+void LightApp_OCCSelector::onDeselection()
+{
+  mySelectedExternals.clear();
+}
+
 /*!Gets selection list.*/
 void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
 {
+#ifndef DISABLE_OCCVIEWER
   if ( !myViewer )
     return;
 
+  if ( !myViewer->isSelectionEnabled() )
+    return;
+
   AIS_ListOfInteractive aSelList;
   myViewer->getSelectedObjects( aSelList );
   for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
@@ -77,11 +101,18 @@ void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
 #endif
     }
+  // add externally selected objects
+  SUIT_DataOwnerPtrList::const_iterator anExtIter;
+  for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
+    aList.append(*anExtIter);
+  }
+#endif
 }
 
 /*!Sets selection list.*/
 void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
 {
+#ifndef DISABLE_OCCVIEWER
   if ( !myViewer )
     return;
 
@@ -99,23 +130,29 @@ void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
     if ( !entryStr.isEmpty() )
       aDisplayed.insert( entryStr, it.Value() );
   }
+  
+  mySelectedExternals.clear();
 
   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
   {
     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
     if ( owner && aDisplayed.contains( owner->entry() ) )
       aSelList.Append( aDisplayed[owner->entry()] );
+    else
+      mySelectedExternals.append(*itr);
   }
 
   myViewer->unHighlightAll( false );
   myViewer->setObjectsSelected( aSelList );
+#endif
 }
 
+#ifndef DISABLE_OCCVIEWER
 /*!Gets entry ob object.*/
 QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
 {
   if ( anAIS.IsNull() || !anAIS->HasOwner() )
-    return QString::null;
+    return QString();
 
   QString res;
 
@@ -127,3 +164,4 @@ QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS
 
   return res;
 }
+#endif