From: mpa Date: Mon, 2 Jun 2014 08:20:08 +0000 (+0400) Subject: - add new Dependency Tree selector X-Git-Tag: V7_5_0a1~50^2~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1673cb51cebf68db0c529273851e41a696c38358;p=modules%2Fgeom.git - add new Dependency Tree selector --- diff --git a/src/DependencyTree/CMakeLists.txt b/src/DependencyTree/CMakeLists.txt index 2ab2bc271..4b5943fcd 100644 --- a/src/DependencyTree/CMakeLists.txt +++ b/src/DependencyTree/CMakeLists.txt @@ -74,6 +74,7 @@ SET(DependencyTree_HEADERS DependencyTree.h DependencyTree_Arrow.h DependencyTree_Object.h + DependencyTree_Selector.h ) # header files / to be processed by moc @@ -92,6 +93,7 @@ SET(DependencyTree_SOURCES DependencyTree_View.cxx DependencyTree_Object.cxx DependencyTree_Arrow.cxx + DependencyTree_Selector.cxx #arrow.cxx DependencyTree_ViewModel.cxx ${_moc_SOURCES} diff --git a/src/DependencyTree/DependencyTree.cxx b/src/DependencyTree/DependencyTree.cxx index 583ba43e8..97b428988 100644 --- a/src/DependencyTree/DependencyTree.cxx +++ b/src/DependencyTree/DependencyTree.cxx @@ -39,14 +39,18 @@ #include #include "DependencyTree_View.h" +#include + #include #include #include #include #include +#include #include + #include #include @@ -58,12 +62,16 @@ DependencyTree::DependencyTree() SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); if ( !app ) return; + LightApp_SelectionMgr* mySelMgr = app->selectionMgr(); + SUIT_ViewManager *svm = app->getViewManager(GraphicsView_Viewer::Type(), false ); if(!svm) { myView = new DependencyTree_View(); DependencyTree_ViewModel* ViewModel = new DependencyTree_ViewModel(GraphicsView_Viewer::Type(), myView); SUIT_ViewManager *svm = app->createViewManager( ViewModel ); + new DependencyTree_Selector( ViewModel, + ( SUIT_SelectionMgr*)mySelMgr ); SUIT_ViewWindow* svw = svm->getActiveView(); GraphicsView_ViewFrame* aViewFrame = 0; if (!svw) svw = svm->createViewWindow(); diff --git a/src/DependencyTree/DependencyTree_Selector.cxx b/src/DependencyTree/DependencyTree_Selector.cxx new file mode 100644 index 000000000..5c1c9a7e5 --- /dev/null +++ b/src/DependencyTree/DependencyTree_Selector.cxx @@ -0,0 +1,101 @@ +// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "DependencyTree_Selector.h" +#include "DependencyTree_View.h" +#include "DependencyTree_ViewModel.h" +#include "DependencyTree_Object.h" + +// GUI includes +#include + +//GEOM includes +#include + +#include + +DependencyTree_Selector::DependencyTree_Selector( DependencyTree_ViewModel* theModel, SUIT_SelectionMgr* theSelMgr ) +:LightApp_GVSelector( (GraphicsView_Viewer*)theModel, theSelMgr ) +{ + myView = dynamic_cast( theModel->getActiveViewPort() ); +} + +DependencyTree_Selector::~DependencyTree_Selector() +{ +} + +//================================================================================= +// function : getSelection() +// purpose : get list of selected Data Owner objects. +//================================================================================= +void DependencyTree_Selector::getSelection( SUIT_DataOwnerPtrList& theList ) const +{ + for( myView->initSelected(); myView->moreSelected(); myView->nextSelected() ) + if( DependencyTree_Object* treeObject = dynamic_cast( myView->selectedObject() ) ) { + const char* entry; + const char* name; + QString studyEntry = treeObject->getGeomObject()->GetStudyEntry(); + if( studyEntry.isEmpty() ) { + entry = treeObject->getEntry().c_str(); + name = "TEMP_IO_UNPUBLISHED"; + } + else { + entry = studyEntry.toStdString().c_str(); + name = "TEMP_IO"; + } + Handle(SALOME_InteractiveObject) tmpIO = + new SALOME_InteractiveObject( entry, "GEOM", name); + + theList.append( new LightApp_DataOwner( tmpIO ) ); + } +} + +//================================================================================= +// function : setSelection() +// purpose : set to selected list of Data Owner objects. +//================================================================================= +void DependencyTree_Selector::setSelection( const SUIT_DataOwnerPtrList& theList ) +{ + myView->clearSelected(); + + for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) { + const LightApp_DataOwner* owner = dynamic_cast( (*it).operator->() ); + if ( owner ) + if( !owner->IO().IsNull() ) { + const char* name = owner->IO()->getName(); + const char* entry; + if( strcmp( owner->IO()->getComponentDataType(), "GEOM" ) != 0 ) + return; + + if( strcmp( name, "TEMP_IO_UNPUBLISHED" ) == 0 ) + entry = owner->IO()->getEntry(); + else { + GEOM::GEOM_Object_var geomObject = GEOMBase::ConvertIOinGEOMObject( owner->IO() ); + if( geomObject->_is_nil() ) + return; + entry = geomObject->GetEntry(); + } + DependencyTree_Object* object = myView->getObjectByEntry( QString( entry ) ); + if( object ) { + myView->setSelected( object ); + object->select( object->pos().x(), object->pos().y(), object->getRect() ); + } + } + } +} diff --git a/src/DependencyTree/DependencyTree_Selector.h b/src/DependencyTree/DependencyTree_Selector.h new file mode 100644 index 000000000..9ff9c9e7e --- /dev/null +++ b/src/DependencyTree/DependencyTree_Selector.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef DEPENDENCYTREE_SELECTOR_H +#define DEPENDENCYTREE_SELECTOR_H + +#include + +class DependencyTree_ViewModel; +class DependencyTree_View; + +class DependencyTree_Selector: public LightApp_GVSelector +{ + +public: + DependencyTree_Selector( DependencyTree_ViewModel*, SUIT_SelectionMgr* ); + ~DependencyTree_Selector(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + DependencyTree_View* myView; + +}; + +#endif diff --git a/src/DependencyTree/DependencyTree_View.cxx b/src/DependencyTree/DependencyTree_View.cxx index 8841b0474..e17a506e2 100644 --- a/src/DependencyTree/DependencyTree_View.cxx +++ b/src/DependencyTree/DependencyTree_View.cxx @@ -21,8 +21,6 @@ #include "DependencyTree_Object.h" #include "DependencyTree_Arrow.h" -#include -#include #include // GUI includes @@ -61,6 +59,8 @@ myComputedCost(0) mySelectionMgr = app->selectionMgr(); if ( !mySelectionMgr ) return; + myMainEntries = new GEOM::string_array(); + getNewTreeModel(); } @@ -136,7 +136,7 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame ) connect( myHierarchyDepth, SIGNAL( valueChanged ( int ) ), this, SLOT( onHierarchyType() ) ); connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) ); connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) ); - connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel( false ) ) ); + connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel() ) ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) ); setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) ); @@ -144,15 +144,10 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame ) setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) ); } -void DependencyTree_View::updateModel( bool getSelectedObjects ) +void DependencyTree_View::updateModel( bool theUseSelectedObject, bool theUseOB ) { - getNewTreeModel( getSelectedObjects ); - - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - - setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) ); - setNodesMovable( resMgr->booleanValue( "Geometry", "dependency_tree_move_nodes", true ) ); - setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) ); + getNewTreeModel( theUseSelectedObject, theUseOB ); + onHierarchyType(); } void DependencyTree_View::drawTree() @@ -235,25 +230,6 @@ void DependencyTree_View::drawTree() } -int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend ) -{ - GraphicsView_ViewPort::select( theRect, theIsAppend ); - - mySelectionMgr->clearSelected(); - - // get selection - SALOME_ListIO listIO; - int StudyId = myStudy->StudyId(); - for( initSelected(); moreSelected(); nextSelected() ) - if( DependencyTree_Object* treeObject = dynamic_cast( selectedObject() ) ) { - CORBA::String_var studyEntry = treeObject->getGeomObject()->GetStudyEntry(); - Handle(SALOME_InteractiveObject) tmpIO = - new SALOME_InteractiveObject( studyEntry.in(), "GEOM", "TEMP_IO"); - listIO.Append( tmpIO ); - } - mySelectionMgr->setSelectedObjects( listIO, true ); -} - void DependencyTree_View::customEvent( QEvent * event ) { if( event->type() == DRAW_EVENT ) { @@ -295,6 +271,11 @@ void DependencyTree_View::mouseMoveEvent(QMouseEvent *event) } } +DependencyTree_Object* DependencyTree_View::getObjectByEntry( QString theEntry ) +{ + return myTreeMap[theEntry.toStdString()]; +} + void DependencyTree_View::setHierarchyType( const int theType ) { myIsUpdate = false; @@ -427,9 +408,14 @@ void DependencyTree_View::closeEvent( QCloseEvent* event ) event->accept(); } -void DependencyTree_View::onUpdateModel( bool getSelectedObjects ) +void DependencyTree_View::onUpdateModel() +{ + updateModel( false ); +} + +void DependencyTree_View::onRebuildModel() { - updateModel( getSelectedObjects ); + updateModel( true, false ); } void DependencyTree_View::updateView() @@ -614,32 +600,46 @@ void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard ) } } -void DependencyTree_View::getNewTreeModel( bool getSelectedObjects ) +void DependencyTree_View::getNewTreeModel( bool theUseSelectedObject, bool theUseOB ) { - clearView( true ); - if( getSelectedObjects ) - mySelectionMgr->selectedObjects( myMainObjects ); - - // create a list of selected object entry GEOM::string_array_var objectsEntry = new GEOM::string_array(); - objectsEntry->length( myMainObjects.Extent()); int iter = 0; - for ( SALOME_ListIteratorOfListIO It( myMainObjects ); It.More(); It.Next(), iter++ ) { - Handle( SALOME_InteractiveObject ) io = It.Value(); - GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil(); - geomObject = GEOMBase::ConvertIOinGEOMObject( io ); - QString entry = geomObject->GetEntry(); - objectsEntry[ iter ] = entry.toLatin1().constData(); + + if( theUseSelectedObject ) { + if( theUseOB ) { + SALOME_ListIO mainObjects; + mySelectionMgr->selectedObjects( mainObjects ); + // create a list of selected object entry + objectsEntry->length( mainObjects.Extent()); + for ( SALOME_ListIteratorOfListIO It( mainObjects ); It.More(); It.Next(), iter++ ) { + Handle( SALOME_InteractiveObject ) io = It.Value(); + GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil(); + geomObject = GEOMBase::ConvertIOinGEOMObject( io ); + QString entry = geomObject->GetEntry(); + objectsEntry[ iter ] = entry.toLatin1().constData(); + } + } + else { + objectsEntry->length( nbSelected() ); + for( initSelected(); moreSelected(); nextSelected(), iter++ ) + if( DependencyTree_Object* treeObject = dynamic_cast( selectedObject() ) ) { + objectsEntry[ iter ] = treeObject->getEntry().c_str(); + std::cout << "\n\n\n ----------- entry = " << treeObject->getEntry() << std::endl; + } + } + + myMainEntries = objectsEntry; } // get string which describes dependency tree structure SALOMEDS::TMPFile_var SeqFile = - GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, objectsEntry ); + GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, myMainEntries ); char* buf = (char*) &SeqFile[0]; std::cout << "\n\n\n\n\n TREE = " << buf << std::endl; + clearView( true ); // get dependency tree structure GEOMUtils::ConvertStringToTree( buf, myTreeModel ); diff --git a/src/DependencyTree/DependencyTree_View.h b/src/DependencyTree/DependencyTree_View.h index accc5e624..4c1b86e8d 100644 --- a/src/DependencyTree/DependencyTree_View.h +++ b/src/DependencyTree/DependencyTree_View.h @@ -29,6 +29,9 @@ #include #include +#include +#include + #include #include @@ -74,13 +77,14 @@ public: ~DependencyTree_View(); void init( GraphicsView_ViewFrame* ); - void updateModel( bool = true ); + void updateModel( bool = true, bool = true ); void drawTree(); - virtual int select( const QRectF&, bool ); virtual void customEvent ( QEvent* ); void mouseMoveEvent(QMouseEvent *event); + DependencyTree_Object* getObjectByEntry( QString ); + void setHierarchyType( const int ); void setNodesMovable( const bool ); void setPrefBackgroundColor( const QColor& ); @@ -99,7 +103,8 @@ public: QMutex myMutex; public slots: - void onUpdateModel( bool = true ); + void onUpdateModel(); + void onRebuildModel(); protected: void closeEvent( QCloseEvent* ); @@ -126,7 +131,7 @@ private: std::map< int, std::vector< std::string > >&, int, const int ); void drawWardArrows( GEOMUtils::LevelsList ); - void getNewTreeModel( bool = true ); + void getNewTreeModel( bool = true, bool = true ); void clearView( bool ); int checkMaxLevelsNumber(); @@ -163,7 +168,7 @@ private: DependencyTree_ComputeDlg_QThread* qthread; - SALOME_ListIO myMainObjects; + GEOM::string_array_var myMainEntries; SALOMEDS::Study_var myStudy; LightApp_SelectionMgr* mySelectionMgr; diff --git a/src/DependencyTree/DependencyTree_ViewModel.cxx b/src/DependencyTree/DependencyTree_ViewModel.cxx index 813e94c72..afeda3d61 100644 --- a/src/DependencyTree/DependencyTree_ViewModel.cxx +++ b/src/DependencyTree/DependencyTree_ViewModel.cxx @@ -128,7 +128,7 @@ void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu ) theMenu->clear(); theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) ); theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) ); - theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onUpdateModel() ) ); + theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onRebuildModel() ) ); } } diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index c93a28241..8fed3dfef 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1630,7 +1630,7 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->insert( separator(), -1, -1 ); // ----------- mgr->insert( action( GEOMOp::OpShowDependencyTree ), -1, -1 ); // Show dependency tree - mgr->setRule( action( GEOMOp::OpShowDependencyTree ), clientOCCorVTKorOB + " and selcount>0" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule ); + mgr->setRule( action( GEOMOp::OpShowDependencyTree ), clientOCCorVTKorOB + " and selcount>0 and ($component={'GEOM'}) and type='Shape'", QtxPopupMgr::VisibleRule ); mgr->hide( mgr->actionId( action( myEraseAll ) ) );