X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_VTKSelector.cxx;h=c5f81eecb1236625d3b74157b64c709ebfb34488;hb=567efd9864811a8eb7de02faa4e3f76f29f66d9c;hp=b393b3043b94976f76f106ea8193452fdcd79f9e;hpb=9f1a66957ba9a2308f8fdc3f9397140af9df5fd0;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx index b393b3043..c5f81eecb 100644 --- a/src/LightApp/LightApp_VTKSelector.cxx +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -1,57 +1,109 @@ -// 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/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "LightApp_VTKSelector.h" #include "LightApp_DataOwner.h" -#include "SVTK_ViewModelBase.h" -#include "SVTK_Selector.h" -#include "SVTK_ViewWindow.h" -#include "SVTK_Functor.h" +#include "SUIT_Desktop.h" -#include "SALOME_Actor.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#ifndef DISABLE_VTKVIEWER + #include "SVTK_ViewModelBase.h" + #include "SVTK_ViewManager.h" + #include "SVTK_Selector.h" + #include "SVTK_ViewWindow.h" + #include "SVTK_Functor.h" + #include "VTKViewer_Algorithm.h" + #include + #include "SVTK_ViewModel.h" +#endif -#include "VTKViewer_Algorithm.h" +#ifndef DISABLE_SALOMEOBJECT + #include "SALOME_Actor.h" + #include "SALOME_ListIO.hxx" +#endif -#include +#include +#ifndef DISABLE_VTKVIEWER +#ifndef DISABLE_SALOMEOBJECT /*! Constructor. */ +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 +*/ +SVTK_ViewWindow* LightApp_SVTKDataOwner -::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO, - const TColStd_IndexedMapOfInteger& theIds, - Selection_Mode theMode, - SALOME_Actor* theActor): - LightApp_DataOwner( theIO ), - mySelectionMode(theMode), - myActor(theActor) +::GetActiveViewWindow() const { - myIds = theIds; // workaround - there is no constructor copy for the container + if(SUIT_ViewWindow* aViewWindow = myDesktop->activeWindow()) + return dynamic_cast(aViewWindow); + + return NULL; } /*! - Destuctor. + Gets dataowners ids list. */ +const TColStd_IndexedMapOfInteger& LightApp_SVTKDataOwner -::~LightApp_SVTKDataOwner() +::GetIds() const { + if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){ + if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){ + aSelector->GetIndex(IO(),myIds); + } + } + + return myIds; +} + +/*! + Gets selection mode. +*/ +Selection_Mode +LightApp_SVTKDataOwner +::GetMode() const +{ + if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){ + if(SVTK_Selector* aSelector = aViewWindow->GetSelector()){ + return aSelector->SelectionMode(); + } + } + + return ActorSelection; // workaround for embedded VTK viewer in a module : is it safe ? } /*! @@ -61,15 +113,33 @@ SALOME_Actor* LightApp_SVTKDataOwner ::GetActor() const { - return myActor.GetPointer(); + if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow()){ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors()); + return Find(aCopy.GetActors(),TIsSameIObject(IO())); + } + + return NULL; +} + +#endif + +/*! + Destuctor. +*/ +/* +LightApp_SVTKDataOwner::~LightApp_SVTKDataOwner() +{ } +*/ +#ifndef DISABLE_VTKVIEWER /*! Constructor. */ LightApp_VTKSelector ::LightApp_VTKSelector( SVTK_ViewModelBase* viewer, - SUIT_SelectionMgr* mgr ): + SUIT_SelectionMgr* mgr ): SUIT_Selector( mgr, viewer ), myViewer( viewer ) { @@ -77,14 +147,6 @@ LightApp_VTKSelector connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); } -/*! - Destructor. -*/ -LightApp_VTKSelector -::~LightApp_VTKSelector() -{ -} - /*! Gets viewer. */ @@ -105,6 +167,7 @@ LightApp_VTKSelector return myViewer->getType(); } +#endif /*! On selection changed. */ @@ -115,6 +178,8 @@ LightApp_VTKSelector selectionChanged(); } +#ifndef DISABLE_VTKVIEWER + /*! Gets list of selected data owners.(output \a aList). */ @@ -122,27 +187,24 @@ void LightApp_VTKSelector ::getSelection( SUIT_DataOwnerPtrList& aList ) const { - if(myViewer){ - if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){ - if(SVTK_ViewWindow* aView = dynamic_cast(aViewMgr->getActiveView())){ - if(SVTK_Selector* aSelector = aView->GetSelector()){ - Selection_Mode aMode = aSelector->SelectionMode(); - const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); - SALOME_ListIteratorOfListIO anIter(aListIO); - for(; anIter.More(); anIter.Next()){ - Handle(SALOME_InteractiveObject) anIO = anIter.Value(); - if(anIO->hasEntry()){ - TColStd_IndexedMapOfInteger anIds; - aSelector->GetIndex(anIO,anIds); - SALOME_Actor* anActor = aSelector->GetActor(anIO); - if( !anActor ){ - using namespace SVTK; - anActor = Find(aView->getRenderer()->GetActors(),TIsSameIObject(anIO)); - } - aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor)); - } - } - } + if( myViewer ) { + if( SVTK_Viewer* aSViewer = dynamic_cast(myViewer) ) { + if( !aSViewer->isSelectionEnabled() ) + return; + } + if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){ + if(SVTK_ViewManager* aViewMgr = dynamic_cast(aViewManager)){ + if(SVTK_ViewWindow* aView = dynamic_cast(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())); + } + } + } } } } @@ -155,52 +217,53 @@ void LightApp_VTKSelector ::setSelection( const SUIT_DataOwnerPtrList& theList ) { - if(myViewer){ + SVTK_Viewer* aViewer = dynamic_cast(myViewer); + if(myViewer && aViewer && aViewer->isSelectionEnabled()){ if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){ if(SVTK_ViewWindow* aView = dynamic_cast(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(aDataOwner)){ - aSelector->SetSelectionMode(anOwner->GetMode()); - Handle(SALOME_InteractiveObject) anIO = anOwner->IO(); - - if( anOwner->GetActor() ) - aSelector->AddIObject( anOwner->GetActor() ); - else - aSelector->AddIObject(anIO); - - anAppendList.Append(anIO); - aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false); - }else if(const LightApp_DataOwner* anOwner = dynamic_cast(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(); - - 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(); - } + 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(aDataOwner)){ + MESSAGE("aSelector->SetSelectionMode("<GetMode()<<");"); + aSelector->SetSelectionMode(anOwner->GetMode()); + Handle(SALOME_InteractiveObject) anIO = anOwner->IO(); + + aSelector->AddIObject(anIO); + + anAppendList.Append(anIO); + aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false); + }else if(const LightApp_DataOwner* anOwner = dynamic_cast(aDataOwner)){ + Handle(SALOME_InteractiveObject) anIO = + new SALOME_InteractiveObject(anOwner->entry().toLatin1(),""); + 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() ); + + QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(), + REnd = toRemove.end(); + for( ; RIt!=REnd; RIt++ ) + aSelector->RemoveIObject( RIt.value() ); + + aView->onSelectionChanged(); + } } } } } + +#endif