myMaxDownwardLevelsNumber(0),
myMaxUpwardLevelsNumber(0),
myLevelsNumber(0),
-myIsCompute(true),
+myIsCompute(false),
myIsUpdate( true ),
myTotalCost(0),
myComputedCost(0)
void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
{
+ qthread = new DependencyTree_ComputeDlg_QThread( this );
+
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) );
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( updateView() ) );
+ connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel( false ) ) );
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) );
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();
calcTotalCost();
std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl;
- clearSelected();
+ if( !myIsCompute )
+ return;
+
clearView( false );
+ clearSelected();
// draw nodes on scene
std::map< std::string, int > entryLevelMap;
if( isItemAdded( objectItem ) )
currentLevel = entryLevelMap[ objectEntry ];
else {
- addItem( objectItem );
+ addNewItem( objectItem );
objectItem->unselect();
entryLevelMap[ objectEntry ] = currentLevel;
levelObjects[ currentLevel ].push_back( objectEntry );
DependencyTree_Object* object = myTreeMap[node->first];
DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(Main_object, object)];
if( arrow && !isItemAdded( arrow) )
- addItem( arrow );
+ addNewItem( arrow );
}
}
}
drawWardArrows( j->second.second );
}
std::cout << "\n ComputedCost = " << myComputedCost << std::endl;
+
}
int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
mySelectionMgr->setSelectedObjects( listIO, true );
}
-void DependencyTree_View::customEvent ( QEvent * event )
+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;
+ if ( !cancelButton->isChecked() )
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);
+ fitAll();
+ QApplication::removePostedEvents( this, ( QEvent::Type )DRAW_EVENT );
}
}
event->accept();
}
-void DependencyTree_View::addItem( QGraphicsItem* theObject )
+void DependencyTree_View::addNewItem( QGraphicsItem* theObject )
{
- GraphicsView_ViewPort::addItem( theObject );
qthread->sleepDraw();
+ if( theObject )
+ addItem( theObject );
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
QApplication::postEvent( this, new QEvent( ( QEvent::Type )DRAW_EVENT ) );
}
event->accept();
}
+void DependencyTree_View::onUpdateModel( bool getSelectedObjects )
+{
+ updateModel( getSelectedObjects );
+}
+
void DependencyTree_View::updateView()
{
if( !myIsUpdate )
return;
-// clearView( false );
-
- qthread = new DependencyTree_ComputeDlg_QThread( this );
-
changeWidgetState( true );
- //myTimer = startTimer( 100 ); // millisecs
qthread->start();
+
+
+
+
}
void DependencyTree_View::onMoveNodes( bool theIsMoveNodes )
for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[ node->first ];
if( !isItemAdded( object ) ) {
- addItem( object );
+ addNewItem( object );
object->unselect();
theEntryLevelMap[ node->first ] = theCurrentLevel;
theLevelObjects[ theCurrentLevel ].push_back( node->first );
if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)];
if( arrow && !isItemAdded( arrow) )
- addItem( arrow );
+ addNewItem( arrow );
}
}
}
}
}
-void DependencyTree_View::getNewTreeModel()
+void DependencyTree_View::getNewTreeModel( bool getSelectedObjects )
{
clearView( true );
- SALOME_ListIO aSelList;
- mySelectionMgr->selectedObjects( aSelList );
+ if( getSelectedObjects )
+ mySelectionMgr->selectedObjects( myMainObjects );
// create a list of selected object entry
GEOM::string_array_var objectsEntry = new GEOM::string_array();
- objectsEntry->length( aSelList.Extent());
+ objectsEntry->length( myMainObjects.Extent());
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();
GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
geomObject = GEOMBase::ConvertIOinGEOMObject( io );
EntryObjectMap::const_iterator objectIter;
for( objectIter = myTreeMap.begin(); objectIter != myTreeMap.end(); objectIter++ ) {
DependencyTree_Object* object = objectIter->second;
- if( isItemAdded( object ) && object )
+ if( object )
+ if( isItemAdded( object ) )
removeItem( object );
}
ArrowsInfo::const_iterator arrowIter;
for( arrowIter = myArrows.begin(); arrowIter != myArrows.end(); arrowIter++ ) {
DependencyTree_Arrow* object = arrowIter->second;
- if( isItemAdded( object ) && object )
+ if( object )
+ if( isItemAdded( object ) )
removeItem( object );
}
if( isClearModel ) {
myMaxDownwardLevelsNumber = 0;
myMaxUpwardLevelsNumber = 0;
myLevelsNumber = 0;
- myIsCompute = true;
+ myIsCompute = false;
myIsUpdate = true;
}
}
void DependencyTree_ComputeDlg_QThread::run()
{
+ myView->myMutex.lock();
+ // QMutexLocker lock( &myView->myMutex );
myView->setIsCompute( true );
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 ) );
+ myView->myMutex.unlock();
+ //exec();
}
void DependencyTree_ComputeDlg_QThread::sleepDraw()
{
- msleep(10);
+ msleep(1);
}
void DependencyTree_ComputeDlg_QThread::cancel()
#include <SalomeApp_Application.h>
+#include <SALOME_ListIO.hxx>
+
#include <GEOMUtils.hxx>
#include <QWidgetAction>
#include <QCheckBox>
#include <QProgressBar>
#include <QThread>
+#include <QMutex>
class DependencyTree_Object;
class DependencyTree_Arrow;
~DependencyTree_View();
void init( GraphicsView_ViewFrame* );
- void updateModel();
+ void updateModel( bool = true );
void drawTree();
virtual int select( const QRectF&, bool );
virtual void customEvent ( QEvent* );
- void addItem( QGraphicsItem* );
void mouseMoveEvent(QMouseEvent *event);
void setHierarchyType( const int );
void setIsCompute( bool );
bool getIsCompute();
+
+ QMutex myMutex;
+
+public slots:
+ void onUpdateModel( bool = true );
+
protected:
-// void timerEvent( QTimerEvent* );
void closeEvent( QCloseEvent* );
private slots:
void addNode( const std::string& );
void addArrow( DependencyTree_Object*, DependencyTree_Object* );
+ void addNewItem( QGraphicsItem* );
void parseTree();
void parseTreeWard(const GEOMUtils::LevelsList);
std::map< int, std::vector< std::string > >&, int, const int );
void drawWardArrows( GEOMUtils::LevelsList );
- void getNewTreeModel();
+ void getNewTreeModel( bool = true );
void clearView( bool );
int checkMaxLevelsNumber();
DependencyTree_ComputeDlg_QThread* qthread;
+ SALOME_ListIO myMainObjects;
SALOMEDS::Study_var myStudy;
LightApp_SelectionMgr* mySelectionMgr;
+
};
#endif