- add new Dependency Tree selector

This commit is contained in:
mpa 2014-06-02 12:20:08 +04:00
parent 3acd20a785
commit 1673cb51ce
8 changed files with 213 additions and 53 deletions

View File

@ -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}

View File

@ -39,14 +39,18 @@
#include <QtxActionToolMgr.h>
#include "DependencyTree_View.h"
#include <DependencyTree_Selector.h>
#include <GraphicsView_Viewer.h>
#include <GraphicsView_ViewFrame.h>
#include <GraphicsView_Scene.h>
#include <SUIT_Session.h>
#include <SUIT_ViewManager.h>
#include <SUIT_SelectionMgr.h>
#include <SalomeApp_Application.h>
#include <QList>
#include <QGraphicsView>
@ -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();

View File

@ -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 <LightApp_DataOwner.h>
//GEOM includes
#include <GEOMBase.h>
#include <iostream>
DependencyTree_Selector::DependencyTree_Selector( DependencyTree_ViewModel* theModel, SUIT_SelectionMgr* theSelMgr )
:LightApp_GVSelector( (GraphicsView_Viewer*)theModel, theSelMgr )
{
myView = dynamic_cast<DependencyTree_View*>( 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<DependencyTree_Object*>( 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<const LightApp_DataOwner*>( (*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() );
}
}
}
}

View File

@ -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 <LightApp_GVSelector.h>
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

View File

@ -21,8 +21,6 @@
#include "DependencyTree_Object.h"
#include "DependencyTree_Arrow.h"
#include <GEOM_InteractiveObject.hxx>
#include <GeometryGUI.h>
#include <GEOMBase.h>
// 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<DependencyTree_Object*>( 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( getSelectedObjects );
updateModel( false );
}
void DependencyTree_View::onRebuildModel()
{
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<DependencyTree_Object*>( 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 );

View File

@ -29,6 +29,9 @@
#include <SALOME_ListIO.hxx>
#include <GEOMUtils.hxx>
#include <GEOM_InteractiveObject.hxx>
#include <GeometryGUI.h>
#include <QWidgetAction>
#include <QPushButton>
@ -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;

View File

@ -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() ) );
}
}

View File

@ -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 ) ) );