1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "DependencyTree_Selector.h"
22 #include "DependencyTree_View.h"
23 #include "DependencyTree_ViewModel.h"
24 #include "DependencyTree_Object.h"
27 #include <LightApp_DataOwner.h>
31 #include <GeometryGUI.h>
33 DependencyTree_Selector::DependencyTree_Selector( DependencyTree_ViewModel* theModel, SUIT_SelectionMgr* theSelMgr )
34 :LightApp_GVSelector( (GraphicsView_Viewer*)theModel, theSelMgr )
36 myView = dynamic_cast<DependencyTree_View*>( theModel->getActiveViewPort() );
39 DependencyTree_Selector::~DependencyTree_Selector()
43 //=================================================================================
44 // function : getSelection()
45 // purpose : get list of selected Data Owner objects.
46 //=================================================================================
47 void DependencyTree_Selector::getSelection( SUIT_DataOwnerPtrList& theList ) const
49 for( myView->initSelected(); myView->moreSelected(); myView->nextSelected() )
50 if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( myView->selectedObject() ) ) {
53 GEOM::GEOM_BaseObject_var anObj = GeometryGUI::GetGeomGen()->GetObject( treeObject->getEntry().c_str() );
54 if( anObj->_is_nil() )
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";
65 Handle(SALOME_InteractiveObject) tmpIO =
66 new SALOME_InteractiveObject( studyEntry.toStdString().c_str(),
68 name.toStdString().c_str());
70 theList.append( new LightApp_DataOwner( tmpIO ) );
74 //=================================================================================
75 // function : setSelection()
76 // purpose : set to selected list of Data Owner objects.
77 //=================================================================================
78 void DependencyTree_Selector::setSelection( const SUIT_DataOwnerPtrList& theList )
80 myView->clearSelected();
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->() );
85 if( !owner->IO().IsNull() ) {
86 const char* name = owner->IO()->getName();
88 if( strcmp( owner->IO()->getComponentDataType(), "GEOM" ) != 0 )
91 if( strcmp( name, "TEMP_IO_UNPUBLISHED" ) == 0 )
92 entry = owner->IO()->getEntry();
94 GEOM::GEOM_Object_var geomObject = GEOMBase::ConvertIOinGEOMObject( owner->IO() );
95 if( geomObject->_is_nil() )
97 entry = geomObject->GetEntry();
99 DependencyTree_Object* object = myView->getObjectByEntry( entry );
101 myView->setSelected( object );
102 object->select( object->pos().x(), object->pos().y(), object->getRect() );