mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-25 04:00:33 +05:00
- add new method for view
- edit the work of thread
This commit is contained in:
parent
2bda43c6b2
commit
5434de9c2b
@ -35,9 +35,10 @@
|
|||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QTimerEvent>
|
#include <QApplication>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
#define DRAW_EVENT ( QEvent::User + 1 )
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
|
|||||||
QWidgetAction* hierarchyDepthAction = new QWidgetAction( theViewFrame );
|
QWidgetAction* hierarchyDepthAction = new QWidgetAction( theViewFrame );
|
||||||
hierarchyDepthAction->setDefaultWidget( myHierarchyDepth );
|
hierarchyDepthAction->setDefaultWidget( myHierarchyDepth );
|
||||||
|
|
||||||
QPushButton* updateButton = new QPushButton( tr( "UPDATE" ) );
|
updateButton = new QPushButton( tr( "UPDATE" ) );
|
||||||
QWidgetAction* updateAction = new QWidgetAction( theViewFrame );
|
QWidgetAction* updateAction = new QWidgetAction( theViewFrame );
|
||||||
updateAction->setDefaultWidget( updateButton );
|
updateAction->setDefaultWidget( updateButton );
|
||||||
|
|
||||||
@ -159,6 +160,7 @@ void DependencyTree_View::drawTree()
|
|||||||
std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl;
|
std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl;
|
||||||
|
|
||||||
clearSelected();
|
clearSelected();
|
||||||
|
clearView( false );
|
||||||
|
|
||||||
// draw nodes on scene
|
// draw nodes on scene
|
||||||
std::map< std::string, int > entryLevelMap;
|
std::map< std::string, int > entryLevelMap;
|
||||||
@ -171,7 +173,6 @@ void DependencyTree_View::drawTree()
|
|||||||
return;
|
return;
|
||||||
currentLevel = 0;
|
currentLevel = 0;
|
||||||
myComputedCost++;
|
myComputedCost++;
|
||||||
sleep(1);
|
|
||||||
std::string objectEntry = i->first;
|
std::string objectEntry = i->first;
|
||||||
DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
|
DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
|
||||||
horDistance = 100 + int( objectItem->boundingRect().width() );
|
horDistance = 100 + int( objectItem->boundingRect().width() );
|
||||||
@ -226,7 +227,6 @@ 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;
|
||||||
fitAll( true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
|
int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
|
||||||
@ -248,6 +248,40 @@ int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
|
|||||||
mySelectionMgr->setSelectedObjects( listIO, true );
|
mySelectionMgr->setSelectedObjects( listIO, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DependencyTree_View::customEvent ( QEvent * event )
|
||||||
|
{
|
||||||
|
if( event->type() == DRAW_EVENT ) {
|
||||||
|
//qthread->sleepDraw();
|
||||||
|
|
||||||
|
std::cout << "\n\n\n DRAW_EVENT!!! " << std::endl;
|
||||||
|
QPushButton* cancelButton = dynamic_cast<QPushButton*>( cancelAction->defaultWidget() );
|
||||||
|
QProgressBar* progressBar = dynamic_cast<QProgressBar*>( progressAction->defaultWidget() );
|
||||||
|
|
||||||
|
std::cout << "\n\n *** myIsCompute " << myIsCompute << std::endl;
|
||||||
|
if ( !cancelButton->isChecked() ) {
|
||||||
|
std::cout << "\n\n *** getComputeProgress = " << getComputeProgress() << std::endl;
|
||||||
|
progressBar->setValue( progressBar->maximum() * getComputeProgress() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "\n\n *** qthread->isFinished() = " << qthread->isFinished() << std::endl;
|
||||||
|
if( !myIsCompute || qthread->isFinished() ) {
|
||||||
|
changeWidgetState( false );
|
||||||
|
cancelButton->setChecked( false );
|
||||||
|
progressBar->setValue(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DependencyTree_View::addItem( QGraphicsItem* theObject )
|
||||||
|
{
|
||||||
|
GraphicsView_ViewPort::addItem( theObject );
|
||||||
|
qthread->sleepDraw();
|
||||||
|
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
|
||||||
|
QApplication::postEvent( this, new QEvent( ( QEvent::Type )DRAW_EVENT ) );
|
||||||
|
}
|
||||||
|
|
||||||
void DependencyTree_View::mouseMoveEvent(QMouseEvent *event)
|
void DependencyTree_View::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsView::mouseMoveEvent( event );
|
QGraphicsView::mouseMoveEvent( event );
|
||||||
@ -362,23 +396,23 @@ bool DependencyTree_View::getIsCompute()
|
|||||||
return myIsCompute;
|
return myIsCompute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DependencyTree_View::timerEvent(QTimerEvent *event)
|
//void DependencyTree_View::timerEvent(QTimerEvent *event)
|
||||||
{
|
//{
|
||||||
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 << "TIMER! " << std::endl;
|
// std::cout << "TIMER! " << std::endl;
|
||||||
if ( !cancelButton->isChecked() )
|
// if ( !cancelButton->isChecked() )
|
||||||
progressBar->setValue( progressBar->maximum() * getComputeProgress() );
|
// progressBar->setValue( progressBar->maximum() * getComputeProgress() );
|
||||||
|
//
|
||||||
if( !myIsCompute || qthread->isFinished() ) {
|
// if( !myIsCompute || qthread->isFinished() ) {
|
||||||
changeWidgetState( false );
|
// changeWidgetState( false );
|
||||||
killTimer( myTimer );
|
// killTimer( myTimer );
|
||||||
cancelButton->setChecked( false );
|
// cancelButton->setChecked( false );
|
||||||
progressBar->setValue(0);
|
// progressBar->setValue(0);
|
||||||
}
|
// }
|
||||||
event->accept();
|
// event->accept();
|
||||||
}
|
//}
|
||||||
|
|
||||||
void DependencyTree_View::closeEvent( QCloseEvent* event )
|
void DependencyTree_View::closeEvent( QCloseEvent* event )
|
||||||
{
|
{
|
||||||
@ -395,13 +429,13 @@ void DependencyTree_View::updateView()
|
|||||||
if( !myIsUpdate )
|
if( !myIsUpdate )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clearView( false );
|
// clearView( false );
|
||||||
|
|
||||||
qthread = new DependencyTree_ComputeDlg_QThread( this );
|
qthread = new DependencyTree_ComputeDlg_QThread( this );
|
||||||
|
|
||||||
changeWidgetState( true );
|
changeWidgetState( true );
|
||||||
|
|
||||||
myTimer = startTimer( 100 ); // millisecs
|
//myTimer = startTimer( 100 ); // millisecs
|
||||||
qthread->start();
|
qthread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +569,6 @@ void DependencyTree_View::drawWard( const GEOMUtils::LevelsList& theWard,
|
|||||||
if( level >= myLevelsNumber || !myIsCompute )
|
if( level >= myLevelsNumber || !myIsCompute )
|
||||||
return;
|
return;
|
||||||
myComputedCost++;
|
myComputedCost++;
|
||||||
sleep(1);
|
|
||||||
theCurrentLevel += theLevelStep;
|
theCurrentLevel += theLevelStep;
|
||||||
GEOMUtils::LevelInfo levelInfo = theWard.at( level );
|
GEOMUtils::LevelInfo levelInfo = theWard.at( level );
|
||||||
GEOMUtils::LevelInfo::const_iterator node;
|
GEOMUtils::LevelInfo::const_iterator node;
|
||||||
@ -557,7 +590,6 @@ void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
|
|||||||
if( j >= myLevelsNumber || !myIsCompute )
|
if( j >= myLevelsNumber || !myIsCompute )
|
||||||
break;
|
break;
|
||||||
myComputedCost++;
|
myComputedCost++;
|
||||||
sleep(1);
|
|
||||||
GEOMUtils::LevelInfo Level = theWard.at(j);
|
GEOMUtils::LevelInfo Level = theWard.at(j);
|
||||||
GEOMUtils::LevelInfo::const_iterator node;
|
GEOMUtils::LevelInfo::const_iterator node;
|
||||||
for (node = Level.begin(); node != Level.end(); node++ ) {
|
for (node = Level.begin(); node != Level.end(); node++ ) {
|
||||||
@ -672,6 +704,7 @@ void DependencyTree_View::changeWidgetState( bool theIsCompute )
|
|||||||
myHierarchyDepth->setEnabled( !theIsCompute );
|
myHierarchyDepth->setEnabled( !theIsCompute );
|
||||||
myDisplayAscendants->setEnabled( !theIsCompute );
|
myDisplayAscendants->setEnabled( !theIsCompute );
|
||||||
myDisplayDescendants->setEnabled( !theIsCompute );
|
myDisplayDescendants->setEnabled( !theIsCompute );
|
||||||
|
updateButton->setEnabled( !theIsCompute );
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread( DependencyTree_View* theView )
|
DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread( DependencyTree_View* theView )
|
||||||
@ -683,11 +716,14 @@ void DependencyTree_ComputeDlg_QThread::run()
|
|||||||
{
|
{
|
||||||
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 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DependencyTree_ComputeDlg_QThread::result()
|
void DependencyTree_ComputeDlg_QThread::sleepDraw()
|
||||||
{
|
{
|
||||||
|
msleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DependencyTree_ComputeDlg_QThread::cancel()
|
void DependencyTree_ComputeDlg_QThread::cancel()
|
||||||
|
@ -46,7 +46,7 @@ class DependencyTree_ComputeDlg_QThread : public QThread
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DependencyTree_ComputeDlg_QThread( DependencyTree_View* );
|
DependencyTree_ComputeDlg_QThread( DependencyTree_View* );
|
||||||
bool result();
|
void sleepDraw();
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
DependencyTree_View* getView() { return myView; };
|
DependencyTree_View* getView() { return myView; };
|
||||||
@ -75,6 +75,8 @@ public:
|
|||||||
void drawTree();
|
void drawTree();
|
||||||
|
|
||||||
virtual int select( const QRectF&, bool );
|
virtual int select( const QRectF&, bool );
|
||||||
|
virtual void customEvent ( QEvent* );
|
||||||
|
void addItem( QGraphicsItem* );
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
|
||||||
void setHierarchyType( const int );
|
void setHierarchyType( const int );
|
||||||
@ -91,7 +93,7 @@ public:
|
|||||||
bool getIsCompute();
|
bool getIsCompute();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent( QTimerEvent* );
|
// void timerEvent( QTimerEvent* );
|
||||||
void closeEvent( QCloseEvent* );
|
void closeEvent( QCloseEvent* );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -139,6 +141,7 @@ private:
|
|||||||
QCheckBox* myDisplayDescendants;
|
QCheckBox* myDisplayDescendants;
|
||||||
QWidgetAction* cancelAction;
|
QWidgetAction* cancelAction;
|
||||||
QWidgetAction* progressAction;
|
QWidgetAction* progressAction;
|
||||||
|
QPushButton* updateButton;
|
||||||
|
|
||||||
int myTimer;
|
int myTimer;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user