- add possibility to rebuild dependency tree by selecting objects

This commit is contained in:
mpa 2014-05-29 15:18:22 +04:00
parent 2d26f49c9f
commit 66d16d30f7
5 changed files with 65 additions and 69 deletions

View File

@ -86,33 +86,3 @@ DependencyTree::DependencyTree()
DependencyTree::~DependencyTree() DependencyTree::~DependencyTree()
{ {
} }
//void DependencyTree::setBackgroundColor( const QColor& theColor )
//{
// //myView->setBackgroundColor( theColor );
// myBackgroundColor = theColor;
//}
//void DependencyTree::setNodeColor( const QColor& theColor )
//{
// myView->setNodeColor( theColor );
//}
//void DependencyTree::setMainNodeColor( const QColor& theColor )
//{
// myView->setMainNodeColor( theColor );
//}
//void DependencyTree::setSelectNodeColor( const QColor& theColor )
//{
// myView->setSelectNodeColor( theColor );
//}
//void DependencyTree::setArrowColor( const QColor& theColor )
//{
// myView->setArrowColor( theColor );
//}
//void DependencyTree::setHighlightArrowColor( const QColor& theColor )
//{
// myView->setHighlightArrowColor( theColor );
//}
//void DependencyTree::setSelectArrowColor( const QColor& theColor )
//{
// myView->setSelectArrowColor( theColor );
//}

View File

@ -169,6 +169,7 @@ void DependencyTree_Object::updateName()
QString name = myGeomObject->GetName(); QString name = myGeomObject->GetName();
QString studyEntry = myGeomObject->GetStudyEntry(); QString studyEntry = myGeomObject->GetStudyEntry();
std::cout<<"\n\n name = " << name.toStdString() << " studyEntry = " << studyEntry.toStdString() << std::endl;
if( studyEntry.isEmpty() ) { if( studyEntry.isEmpty() ) {
if( name.isEmpty() ) if( name.isEmpty() )

View File

@ -47,7 +47,7 @@ DependencyTree_View::DependencyTree_View( QWidget* theParent )
myMaxDownwardLevelsNumber(0), myMaxDownwardLevelsNumber(0),
myMaxUpwardLevelsNumber(0), myMaxUpwardLevelsNumber(0),
myLevelsNumber(0), myLevelsNumber(0),
myIsCompute(true), myIsCompute(false),
myIsUpdate( true ), myIsUpdate( true ),
myTotalCost(0), myTotalCost(0),
myComputedCost(0) myComputedCost(0)
@ -70,6 +70,8 @@ DependencyTree_View::~DependencyTree_View()
void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame ) void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
{ {
qthread = new DependencyTree_ComputeDlg_QThread( this );
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) ); myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) );
@ -134,7 +136,7 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
connect( myHierarchyDepth, SIGNAL( valueChanged ( int ) ), this, SLOT( onHierarchyType() ) ); connect( myHierarchyDepth, SIGNAL( valueChanged ( int ) ), this, SLOT( onHierarchyType() ) );
connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) ); connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) ); connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
connect( updateButton, SIGNAL( clicked() ), this, SLOT( updateView() ) ); connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel( false ) ) );
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) ); setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) );
@ -142,9 +144,9 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) ); setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) );
} }
void DependencyTree_View::updateModel() void DependencyTree_View::updateModel( bool getSelectedObjects )
{ {
getNewTreeModel(); getNewTreeModel( getSelectedObjects );
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
@ -159,8 +161,11 @@ void DependencyTree_View::drawTree()
calcTotalCost(); calcTotalCost();
std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl; std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl;
clearSelected(); if( !myIsCompute )
return;
clearView( false ); clearView( false );
clearSelected();
// draw nodes on scene // draw nodes on scene
std::map< std::string, int > entryLevelMap; std::map< std::string, int > entryLevelMap;
@ -180,7 +185,7 @@ void DependencyTree_View::drawTree()
if( isItemAdded( objectItem ) ) if( isItemAdded( objectItem ) )
currentLevel = entryLevelMap[ objectEntry ]; currentLevel = entryLevelMap[ objectEntry ];
else { else {
addItem( objectItem ); addNewItem( objectItem );
objectItem->unselect(); objectItem->unselect();
entryLevelMap[ objectEntry ] = currentLevel; entryLevelMap[ objectEntry ] = currentLevel;
levelObjects[ currentLevel ].push_back( objectEntry ); levelObjects[ currentLevel ].push_back( objectEntry );
@ -217,7 +222,7 @@ void DependencyTree_View::drawTree()
DependencyTree_Object* object = myTreeMap[node->first]; DependencyTree_Object* object = myTreeMap[node->first];
DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(Main_object, object)]; DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(Main_object, object)];
if( arrow && !isItemAdded( arrow) ) if( arrow && !isItemAdded( arrow) )
addItem( arrow ); addNewItem( arrow );
} }
} }
} }
@ -227,6 +232,7 @@ void DependencyTree_View::drawTree()
drawWardArrows( j->second.second ); drawWardArrows( j->second.second );
} }
std::cout << "\n ComputedCost = " << myComputedCost << std::endl; std::cout << "\n ComputedCost = " << myComputedCost << std::endl;
} }
int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend ) int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
@ -248,36 +254,33 @@ int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
mySelectionMgr->setSelectedObjects( listIO, true ); mySelectionMgr->setSelectedObjects( listIO, true );
} }
void DependencyTree_View::customEvent ( QEvent * event ) void DependencyTree_View::customEvent( QEvent * event )
{ {
if( event->type() == DRAW_EVENT ) { if( event->type() == DRAW_EVENT ) {
//qthread->sleepDraw();
std::cout << "\n\n\n DRAW_EVENT!!! " << std::endl;
QPushButton* cancelButton = dynamic_cast<QPushButton*>( cancelAction->defaultWidget() ); QPushButton* cancelButton = dynamic_cast<QPushButton*>( cancelAction->defaultWidget() );
QProgressBar* progressBar = dynamic_cast<QProgressBar*>( progressAction->defaultWidget() ); QProgressBar* progressBar = dynamic_cast<QProgressBar*>( progressAction->defaultWidget() );
std::cout << "\n\n *** myIsCompute " << myIsCompute << std::endl; if ( !cancelButton->isChecked() )
if ( !cancelButton->isChecked() ) {
std::cout << "\n\n *** getComputeProgress = " << getComputeProgress() << std::endl;
progressBar->setValue( progressBar->maximum() * getComputeProgress() ); progressBar->setValue( progressBar->maximum() * getComputeProgress() );
}
std::cout << "\n\n *** qthread->isFinished() = " << qthread->isFinished() << std::endl; std::cout << "\n\n *** qthread->isFinished() = " << qthread->isFinished() << std::endl;
if( !myIsCompute || qthread->isFinished() ) { if( !myIsCompute || qthread->isFinished() ) {
changeWidgetState( false ); changeWidgetState( false );
cancelButton->setChecked( false ); cancelButton->setChecked( false );
progressBar->setValue(0); progressBar->setValue(0);
fitAll();
QApplication::removePostedEvents( this, ( QEvent::Type )DRAW_EVENT );
} }
} }
event->accept(); event->accept();
} }
void DependencyTree_View::addItem( QGraphicsItem* theObject ) void DependencyTree_View::addNewItem( QGraphicsItem* theObject )
{ {
GraphicsView_ViewPort::addItem( theObject );
qthread->sleepDraw(); qthread->sleepDraw();
if( theObject )
addItem( theObject );
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
QApplication::postEvent( this, new QEvent( ( QEvent::Type )DRAW_EVENT ) ); QApplication::postEvent( this, new QEvent( ( QEvent::Type )DRAW_EVENT ) );
} }
@ -424,19 +427,23 @@ void DependencyTree_View::closeEvent( QCloseEvent* event )
event->accept(); event->accept();
} }
void DependencyTree_View::onUpdateModel( bool getSelectedObjects )
{
updateModel( getSelectedObjects );
}
void DependencyTree_View::updateView() void DependencyTree_View::updateView()
{ {
if( !myIsUpdate ) if( !myIsUpdate )
return; return;
// clearView( false );
qthread = new DependencyTree_ComputeDlg_QThread( this );
changeWidgetState( true ); changeWidgetState( true );
//myTimer = startTimer( 100 ); // millisecs
qthread->start(); qthread->start();
} }
void DependencyTree_View::onMoveNodes( bool theIsMoveNodes ) void DependencyTree_View::onMoveNodes( bool theIsMoveNodes )
@ -575,7 +582,7 @@ void DependencyTree_View::drawWard( const GEOMUtils::LevelsList& theWard,
for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) { for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[ node->first ]; DependencyTree_Object* object = myTreeMap[ node->first ];
if( !isItemAdded( object ) ) { if( !isItemAdded( object ) ) {
addItem( object ); addNewItem( object );
object->unselect(); object->unselect();
theEntryLevelMap[ node->first ] = theCurrentLevel; theEntryLevelMap[ node->first ] = theCurrentLevel;
theLevelObjects[ theCurrentLevel ].push_back( node->first ); theLevelObjects[ theCurrentLevel ].push_back( node->first );
@ -600,25 +607,25 @@ void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
if( isItemAdded( object ) && isItemAdded( LinkObject ) ) { if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)]; DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)];
if( arrow && !isItemAdded( arrow) ) if( arrow && !isItemAdded( arrow) )
addItem( arrow ); addNewItem( arrow );
} }
} }
} }
} }
} }
void DependencyTree_View::getNewTreeModel() void DependencyTree_View::getNewTreeModel( bool getSelectedObjects )
{ {
clearView( true ); clearView( true );
SALOME_ListIO aSelList; if( getSelectedObjects )
mySelectionMgr->selectedObjects( aSelList ); mySelectionMgr->selectedObjects( myMainObjects );
// create a list of selected object entry // create a list of selected object entry
GEOM::string_array_var objectsEntry = new GEOM::string_array(); GEOM::string_array_var objectsEntry = new GEOM::string_array();
objectsEntry->length( aSelList.Extent()); objectsEntry->length( myMainObjects.Extent());
int iter = 0; int iter = 0;
for ( SALOME_ListIteratorOfListIO It( aSelList ); It.More(); It.Next(), iter++ ) { for ( SALOME_ListIteratorOfListIO It( myMainObjects ); It.More(); It.Next(), iter++ ) {
Handle( SALOME_InteractiveObject ) io = It.Value(); Handle( SALOME_InteractiveObject ) io = It.Value();
GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil(); GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
geomObject = GEOMBase::ConvertIOinGEOMObject( io ); geomObject = GEOMBase::ConvertIOinGEOMObject( io );
@ -647,14 +654,16 @@ void DependencyTree_View::clearView( bool isClearModel )
EntryObjectMap::const_iterator objectIter; EntryObjectMap::const_iterator objectIter;
for( objectIter = myTreeMap.begin(); objectIter != myTreeMap.end(); objectIter++ ) { for( objectIter = myTreeMap.begin(); objectIter != myTreeMap.end(); objectIter++ ) {
DependencyTree_Object* object = objectIter->second; DependencyTree_Object* object = objectIter->second;
if( isItemAdded( object ) && object ) if( object )
if( isItemAdded( object ) )
removeItem( object ); removeItem( object );
} }
ArrowsInfo::const_iterator arrowIter; ArrowsInfo::const_iterator arrowIter;
for( arrowIter = myArrows.begin(); arrowIter != myArrows.end(); arrowIter++ ) { for( arrowIter = myArrows.begin(); arrowIter != myArrows.end(); arrowIter++ ) {
DependencyTree_Arrow* object = arrowIter->second; DependencyTree_Arrow* object = arrowIter->second;
if( isItemAdded( object ) && object ) if( object )
if( isItemAdded( object ) )
removeItem( object ); removeItem( object );
} }
if( isClearModel ) { if( isClearModel ) {
@ -664,7 +673,7 @@ void DependencyTree_View::clearView( bool isClearModel )
myMaxDownwardLevelsNumber = 0; myMaxDownwardLevelsNumber = 0;
myMaxUpwardLevelsNumber = 0; myMaxUpwardLevelsNumber = 0;
myLevelsNumber = 0; myLevelsNumber = 0;
myIsCompute = true; myIsCompute = false;
myIsUpdate = true; myIsUpdate = true;
} }
} }
@ -714,16 +723,19 @@ DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread( Dependency
void DependencyTree_ComputeDlg_QThread::run() void DependencyTree_ComputeDlg_QThread::run()
{ {
myView->myMutex.lock();
// QMutexLocker lock( &myView->myMutex );
myView->setIsCompute( true ); myView->setIsCompute( true );
myView->drawTree(); myView->drawTree();
myView->fitAll( true );
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
QApplication::postEvent( myView, new QEvent( ( QEvent::Type )DRAW_EVENT ) ); QApplication::postEvent( myView, new QEvent( ( QEvent::Type )DRAW_EVENT ) );
myView->myMutex.unlock();
//exec();
} }
void DependencyTree_ComputeDlg_QThread::sleepDraw() void DependencyTree_ComputeDlg_QThread::sleepDraw()
{ {
msleep(10); msleep(1);
} }
void DependencyTree_ComputeDlg_QThread::cancel() void DependencyTree_ComputeDlg_QThread::cancel()

View File

@ -26,6 +26,8 @@
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <SALOME_ListIO.hxx>
#include <GEOMUtils.hxx> #include <GEOMUtils.hxx>
#include <QWidgetAction> #include <QWidgetAction>
@ -34,6 +36,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QProgressBar> #include <QProgressBar>
#include <QThread> #include <QThread>
#include <QMutex>
class DependencyTree_Object; class DependencyTree_Object;
class DependencyTree_Arrow; class DependencyTree_Arrow;
@ -71,12 +74,11 @@ public:
~DependencyTree_View(); ~DependencyTree_View();
void init( GraphicsView_ViewFrame* ); void init( GraphicsView_ViewFrame* );
void updateModel(); void updateModel( bool = true );
void drawTree(); void drawTree();
virtual int select( const QRectF&, bool ); virtual int select( const QRectF&, bool );
virtual void customEvent ( QEvent* ); virtual void customEvent ( QEvent* );
void addItem( QGraphicsItem* );
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void setHierarchyType( const int ); void setHierarchyType( const int );
@ -92,8 +94,13 @@ public:
void setIsCompute( bool ); void setIsCompute( bool );
bool getIsCompute(); bool getIsCompute();
QMutex myMutex;
public slots:
void onUpdateModel( bool = true );
protected: protected:
// void timerEvent( QTimerEvent* );
void closeEvent( QCloseEvent* ); void closeEvent( QCloseEvent* );
private slots: private slots:
@ -108,6 +115,7 @@ private:
void addNode( const std::string& ); void addNode( const std::string& );
void addArrow( DependencyTree_Object*, DependencyTree_Object* ); void addArrow( DependencyTree_Object*, DependencyTree_Object* );
void addNewItem( QGraphicsItem* );
void parseTree(); void parseTree();
void parseTreeWard(const GEOMUtils::LevelsList); void parseTreeWard(const GEOMUtils::LevelsList);
@ -117,7 +125,7 @@ private:
std::map< int, std::vector< std::string > >&, int, const int ); std::map< int, std::vector< std::string > >&, int, const int );
void drawWardArrows( GEOMUtils::LevelsList ); void drawWardArrows( GEOMUtils::LevelsList );
void getNewTreeModel(); void getNewTreeModel( bool = true );
void clearView( bool ); void clearView( bool );
int checkMaxLevelsNumber(); int checkMaxLevelsNumber();
@ -154,10 +162,12 @@ private:
DependencyTree_ComputeDlg_QThread* qthread; DependencyTree_ComputeDlg_QThread* qthread;
SALOME_ListIO myMainObjects;
SALOMEDS::Study_var myStudy; SALOMEDS::Study_var myStudy;
LightApp_SelectionMgr* mySelectionMgr; LightApp_SelectionMgr* mySelectionMgr;
}; };
#endif #endif

View File

@ -119,13 +119,16 @@ void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
GraphicsView_Viewer::contextMenuPopup( theMenu ); GraphicsView_Viewer::contextMenuPopup( theMenu );
std::cout<<"\n\n\n\n *****contextMenuPopup " << std::endl; std::cout<<"\n\n\n\n *****contextMenuPopup " << std::endl;
if( DependencyTree_View* aViewPort = dynamic_cast<DependencyTree_View*>(getActiveViewPort()) ) if( DependencyTree_View* aViewPort = dynamic_cast<DependencyTree_View*>(getActiveViewPort()) )
{ {
int aNbSelected = aViewPort->nbSelected(); int aNbSelected = aViewPort->nbSelected();
std::cout<<"\n aNbSelected " << aNbSelected << std::endl; std::cout<<"\n aNbSelected " << aNbSelected << std::endl;
if( aNbSelected > 0 ) { if( aNbSelected > 0 ) {
theMenu->clear();
theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) ); theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) ); theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onUpdateModel() ) );
} }
} }