Salome HOME
new presentation using DTM
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_GVSelector.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_GVSelector.h"
20
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_DataObject.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Prs.h"
25 #include "HYDROGUI_Tool2.h"
26
27 #include <GraphicsView_Object.h>
28 #include <GraphicsView_Selector.h>
29 #include <GraphicsView_ViewPort.h>
30 #include <GraphicsView_Viewer.h>
31
32 #include <LightApp_DataOwner.h>
33
34 HYDROGUI_GVSelector::HYDROGUI_GVSelector( HYDROGUI_Module* theModule,
35                                           GraphicsView_Viewer* theViewer,
36                                           SUIT_SelectionMgr* theSelMgr )
37 : LightApp_GVSelector( theViewer, theSelMgr ),
38   myModule( theModule )
39 {
40 }
41
42 HYDROGUI_GVSelector::~HYDROGUI_GVSelector()
43 {
44 }
45
46 void HYDROGUI_GVSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
47 {
48   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
49   {
50     for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
51     {
52       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( aViewPort->selectedObject() ) )
53       {
54         QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aPrs->getObject() );
55         theList.append( new LightApp_DataOwner( anEntry ) );
56       }
57     }
58   }
59 }
60
61 void HYDROGUI_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
62 {
63   HYDROGUI_DataModel* aModel = myModule->getDataModel();
64   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
65   {
66     aViewPort->clearSelected();
67     SUIT_DataOwnerPtrList::const_iterator it;
68     GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
69     for ( it = theList.begin(); it != theList.end(); ++it )
70     {
71       LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( (*it).operator->() );
72       if ( anOwner )
73       {
74         QString anEntry = anOwner->entry();
75         Handle(HYDROData_Entity) aModelObject = aModel->objectByEntry( anEntry );
76         if( !aModelObject.IsNull() )
77         {
78           if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( aModelObject, anObjectList ) )
79             aViewPort->setSelected( aPrs );
80         }
81       }
82     }
83   }
84 }