Salome HOME
0496cbba68a9a227c4cb731df7afabe76fba53a1
[modules/geom.git] / src / DependencyTree / DependencyTree_Selector.cxx
1 // Copyright (C) 2014-2023  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( treeObject->getEntry().c_str() );
54       if( anObj->_is_nil() )
55         continue;
56           CORBA::String_var studyEntryVar = anObj->GetStudyEntry();
57       studyEntry = studyEntryVar.in();
58       if( studyEntry.isEmpty() ) {
59         studyEntry = treeObject->getEntry().c_str();
60         name = "TEMP_IO_UNPUBLISHED";
61       }
62       else {
63         name = "TEMP_IO";
64       }
65       Handle(SALOME_InteractiveObject) tmpIO =
66         new SALOME_InteractiveObject( studyEntry.toStdString().c_str(), 
67                                                                           "GEOM", 
68                                                                           name.toStdString().c_str());
69
70       theList.append( new LightApp_DataOwner( tmpIO ) );
71     }
72 }
73
74 //=================================================================================
75 // function : setSelection()
76 // purpose  : set to selected list of Data Owner objects.
77 //=================================================================================
78 void DependencyTree_Selector::setSelection( const SUIT_DataOwnerPtrList& theList )
79 {
80   myView->clearSelected();
81
82   for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) {
83     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
84     if ( owner )
85       if( !owner->IO().IsNull() ) {
86         const char* name = owner->IO()->getName();
87         const char* entry;
88         if( strcmp( owner->IO()->getComponentDataType(), "GEOM" ) != 0 )
89           return;
90
91         if( strcmp( name, "TEMP_IO_UNPUBLISHED" ) == 0 )
92           entry = owner->IO()->getEntry();
93         else {
94           GEOM::GEOM_Object_var geomObject = GEOMBase::ConvertIOinGEOMObject( owner->IO() );
95           if( geomObject->_is_nil() )
96             return;
97           entry = geomObject->GetEntry();
98         }
99         DependencyTree_Object* object = myView->getObjectByEntry( entry );
100         if( object ) {
101            myView->setSelected( object );
102            object->select( object->pos().x(), object->pos().y(), object->getRect() );
103         }
104       }
105   }
106 }