Salome HOME
Merge branch 'fbt/add_header_for_mpi_compilation'
[modules/geom.git] / src / DependencyTree / DependencyTree_Selector.cxx
1 // Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "DependencyTree_Selector.h"
22 #include "DependencyTree_View.h"
23 #include "DependencyTree_ViewModel.h"
24 #include "DependencyTree_Object.h"
25
26 // GUI includes
27 #include <LightApp_DataOwner.h>
28
29 //GEOM includes
30 #include <GEOMBase.h>
31 #include <GeometryGUI.h>
32
33 DependencyTree_Selector::DependencyTree_Selector( DependencyTree_ViewModel* theModel, SUIT_SelectionMgr* theSelMgr )
34 :LightApp_GVSelector( (GraphicsView_Viewer*)theModel, theSelMgr )
35 {
36   myView = dynamic_cast<DependencyTree_View*>( theModel->getActiveViewPort() );
37 }
38
39 DependencyTree_Selector::~DependencyTree_Selector()
40 {
41 }
42
43 //=================================================================================
44 // function : getSelection()
45 // purpose  : get list of selected Data Owner objects.
46 //=================================================================================
47 void DependencyTree_Selector::getSelection( SUIT_DataOwnerPtrList& theList ) const
48 {
49   for( myView->initSelected(); myView->moreSelected(); myView->nextSelected() )
50     if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( myView->selectedObject() ) ) {
51       QString studyEntry;
52       QString name;
53       GEOM::GEOM_BaseObject_var anObj = GeometryGUI::GetGeomGen()->GetObject( myView->getStudyId(),
54                                                                               treeObject->getEntry().c_str() );
55       if( anObj->_is_nil() )
56         continue;
57           CORBA::String_var studyEntryVar = anObj->GetStudyEntry();
58       studyEntry = studyEntryVar.in();
59       if( studyEntry.isEmpty() ) {
60         studyEntry = treeObject->getEntry().c_str();
61         name = "TEMP_IO_UNPUBLISHED";
62       }
63       else {
64         name = "TEMP_IO";
65       }
66       Handle(SALOME_InteractiveObject) tmpIO =
67         new SALOME_InteractiveObject( studyEntry.toStdString().c_str(), 
68                                                                           "GEOM", 
69                                                                           name.toStdString().c_str());
70
71       theList.append( new LightApp_DataOwner( tmpIO ) );
72     }
73 }
74
75 //=================================================================================
76 // function : setSelection()
77 // purpose  : set to selected list of Data Owner objects.
78 //=================================================================================
79 void DependencyTree_Selector::setSelection( const SUIT_DataOwnerPtrList& theList )
80 {
81   myView->clearSelected();
82
83   for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) {
84     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
85     if ( owner )
86       if( !owner->IO().IsNull() ) {
87         const char* name = owner->IO()->getName();
88         const char* entry;
89         if( strcmp( owner->IO()->getComponentDataType(), "GEOM" ) != 0 )
90           return;
91
92         if( strcmp( name, "TEMP_IO_UNPUBLISHED" ) == 0 )
93           entry = owner->IO()->getEntry();
94         else {
95           GEOM::GEOM_Object_var geomObject = GEOMBase::ConvertIOinGEOMObject( owner->IO() );
96           if( geomObject->_is_nil() )
97             return;
98           entry = geomObject->GetEntry();
99         }
100         DependencyTree_Object* object = myView->getObjectByEntry( entry );
101         if( object ) {
102            myView->setSelected( object );
103            object->select( object->pos().x(), object->pos().y(), object->getRect() );
104         }
105       }
106   }
107 }