Correction of GUI part

This commit is contained in:
mpa 2014-05-23 12:09:19 +04:00
parent 48a0c1cf09
commit a782d52dec
7 changed files with 315 additions and 308 deletions

View File

@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/src/GEOMGUI ${PROJECT_SOURCE_DIR}/src/GEOMGUI
${PROJECT_SOURCE_DIR}/src/GEOMBase ${PROJECT_SOURCE_DIR}/src/GEOMBase
${PROJECT_SOURCE_DIR}/src/GEOM ${PROJECT_SOURCE_DIR}/src/GEOM
${PROJECT_SOURCE_DIR}/src/GEOMUtils
${PROJECT_BINARY_DIR}/idl ${PROJECT_BINARY_DIR}/idl
@ -64,6 +65,7 @@ SET(_link_LIBRARIES
${GUI_GraphicsView} ${GUI_GraphicsView}
${GUI_SalomeObject} ${GUI_SalomeObject}
GEOMUtils GEOMUtils
${KERNEL_SalomeDS}
) )
# --- headers --- # --- headers ---

View File

@ -26,6 +26,7 @@ class DependencyTree_Object;
class DependencyTree_Arrow : public QGraphicsLineItem class DependencyTree_Arrow : public QGraphicsLineItem
{ {
public: public:
DependencyTree_Arrow( DependencyTree_Object* startItem, DependencyTree_Object* endItem, DependencyTree_Arrow( DependencyTree_Object* startItem, DependencyTree_Object* endItem,

View File

@ -19,9 +19,15 @@
#include "DependencyTree_Object.h" #include "DependencyTree_Object.h"
// GEOM includes
#include <GeometryGUI.h>
#include <GEOM_BaseObject.hxx>
// GUI includes // GUI includes
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
// Qt includes // Qt includes
#include <QFont> #include <QFont>
@ -29,7 +35,7 @@
const int itemH = 20; const int itemH = 20;
const int itemW = 90; const int itemW = 90;
DependencyTree_Object::DependencyTree_Object( const QString& theEntry, QGraphicsItem* theParent ) DependencyTree_Object::DependencyTree_Object( const std::string& theEntry, QGraphicsItem* theParent )
:GraphicsView_Object( theParent ), :GraphicsView_Object( theParent ),
myIsMainObject( false ), myIsMainObject( false ),
myIsLongName( false ) myIsLongName( false )
@ -135,7 +141,7 @@ void DependencyTree_Object::unselect()
// function : getEntry() // function : getEntry()
// purpose : get entry of current item // purpose : get entry of current item
//================================================================================= //=================================================================================
QString DependencyTree_Object::getEntry() const std::string DependencyTree_Object::getEntry() const
{ {
return myEntry; return myEntry;
} }
@ -146,9 +152,18 @@ QString DependencyTree_Object::getEntry() const
//================================================================================= //=================================================================================
void DependencyTree_Object::updateName() void DependencyTree_Object::updateName()
{ {
QString name = myEntry; SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
if ( !app ) return;
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( study->studyDS());
int StudyId = aStudyDS->StudyId();
GEOM::_objref_GEOM_BaseObject* object = GeometryGUI::GetGeomGen()->GetObject( StudyId, myEntry.c_str() );
setName( myEntry ); QString name = object->GetName();
// QString name = myEntry.c_str();
setName( name );
myTextItem->setText( name ); myTextItem->setText( name );
double textWidth = myTextItem->sceneBoundingRect().width(); double textWidth = myTextItem->sceneBoundingRect().width();

View File

@ -28,7 +28,8 @@ class DependencyTree_Object: public GraphicsView_Object
{ {
public: public:
DependencyTree_Object( const QString&, QGraphicsItem* = 0 );
DependencyTree_Object( const std::string&, QGraphicsItem* = 0 );
~DependencyTree_Object(); ~DependencyTree_Object();
virtual void compute() {}; virtual void compute() {};
@ -39,7 +40,7 @@ public:
virtual bool select( double, double, const QRectF& ); virtual bool select( double, double, const QRectF& );
virtual void unselect(); virtual void unselect();
QString getEntry() const; std::string getEntry() const;
void updateName(); void updateName();
@ -60,7 +61,7 @@ private:
QGraphicsPolygonItem* myPolygonItem; QGraphicsPolygonItem* myPolygonItem;
QGraphicsSimpleTextItem* myTextItem; QGraphicsSimpleTextItem* myTextItem;
QString myEntry; std::string myEntry;
bool myIsMainObject; bool myIsMainObject;
bool myIsLongName; bool myIsLongName;

View File

@ -17,52 +17,30 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
// //
#include <GraphicsView_ViewPort.h>
#include <GraphicsView_Scene.h>
#include <GraphicsView_ViewFrame.h>
#include "DependencyTree_View.h" #include "DependencyTree_View.h"
#include "DependencyTree_Object.h" #include "DependencyTree_Object.h"
#include "DependencyTree_Arrow.h" #include "DependencyTree_Arrow.h"
#include <GEOM_InteractiveObject.hxx>
#include <QMenu> #include <GeometryGUI.h>
#include <QList> #include <GEOMBase.h>
#include <QString>
#include <QGraphicsView>
#include <QSpinBox>
#include <QWidgetAction>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include <QGridLayout>
#include <QCloseEvent>
#include <QTimerEvent>
#include <QtxActionToolMgr.h>
// GUI includes // GUI includes
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <iostream>
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <SalomeApp_Study.h> #include <SalomeApp_Study.h>
#include <QtxActionToolMgr.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
#include <SALOME_ListIteratorOfListIO.hxx> #include <SALOME_ListIteratorOfListIO.hxx>
#include <GEOM_InteractiveObject.hxx>
#include <GeometryGUI.h> // Qt includes
#include <GEOMBase.h> #include <QCloseEvent>
#include "GEOMUtils.hxx" #include <QTimerEvent>
#include <QGraphicsScene>
#include <iostream>
int iter = 0; int iter = 0;
DependencyTree_View::DependencyTree_View( QWidget* theParent ) DependencyTree_View::DependencyTree_View( QWidget* theParent )
@ -77,12 +55,7 @@ myIsUpdate( true )
if ( !app ) return; if ( !app ) return;
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy()); SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
SALOMEDS::Study_var myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS());
_PTR(Study) aStudy = study->studyDS();
if ( !aStudy )
return;
SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if ( !aSelMgr ) return; if ( !aSelMgr ) return;
@ -96,57 +69,26 @@ myIsUpdate( true )
for ( SALOME_ListIteratorOfListIO It( aSelList ); It.More(); It.Next() ) { for ( SALOME_ListIteratorOfListIO It( aSelList ); It.More(); It.Next() ) {
Handle( SALOME_InteractiveObject ) io = It.Value(); Handle( SALOME_InteractiveObject ) io = It.Value();
// if ( io->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
// Handle(GEOM_InteractiveObject) objectGEOM = Handle(GEOM_InteractiveObject)::DownCast( io );
// const char* ior = objectGEOM->getIOR();
// objectGEOM.getEntry();
// objectGEOM.getName();
// std::cout << "\n\n\n !!!!! IOR = " << ior << std::endl;
// }
GEOM::GEOM_Object_var myObject = GEOM::GEOM_Object::_nil(); GEOM::GEOM_Object_var myObject = GEOM::GEOM_Object::_nil();
myObject = GEOMBase::ConvertIOinGEOMObject( io ); myObject = GEOMBase::ConvertIOinGEOMObject( io );
//QString ior = GEOMBase::GetIORFromObject(myObject);
QString ior = myObject->GetEntry(); QString ior = myObject->GetEntry();
ObjectIORs[aaa] = ior.toLatin1().constData(); ObjectIORs[aaa] = ior.toLatin1().constData();
aaa++; aaa++;
std::cout << "\n\n IOR = " << ior.toStdString() << std::endl; std::cout << "\n\n IOR = " << ior.toStdString() << std::endl;
// if ( !CORBA::is_nil( myObject ) )
// myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) );
} }
//
// SALOME_ListIO selected;
// aSelMgr->selectedObjects( selected );
// if ( selected.IsEmpty() ) return;
//
// GEOM::string_array ObjectIORs;
// ObjectIORs.lenght( selected.Extent())
// for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
// Handle( SALOME_InteractiveObject ) io = It.Value();
// const char* entry = io->getEntry();
// ObjectIORs.push_back( entry );
// //CORBA::String_var IOR = app->orb()->object_to_string( io );
// //if ( strcmp(IOR.in(), "") != 0 )
// //{
//// QString objIOR = GEOMBase::GetIORFromObject( io );
// //char* GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
//
// }
// get dependencies tree as a stream
SALOMEDS::TMPFile_var SeqFile = SALOMEDS::TMPFile_var SeqFile =
GeometryGUI::GetGeomGen()->GetDependencyTree( aStudyDS, ObjectIORs ); GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, ObjectIORs );
// convert stream into string char* buf;
char* treeStr; buf = (char*) &SeqFile[0];
treeStr = (char*) &SeqFile[0];
std::cout << "\n TREE = " << treeStr << std::endl; std::cout << "\n\n\n\n\n TREE = " << buf << std::endl;
GEOMUtils::ConvertStringToTree( buf, myTreeModel );
// parse string to deal with 'TreeModel' object
GEOMUtils::TreeModel tree;
GEOMUtils::ConvertStringToTree( treeStr, tree );
} }
DependencyTree_View::~DependencyTree_View() DependencyTree_View::~DependencyTree_View()
@ -156,74 +98,133 @@ DependencyTree_View::~DependencyTree_View()
void DependencyTree_View::drawArrows() void DependencyTree_View::drawArrows()
{ {
QMap<QString,QPair<LevelsList,LevelsList> >::iterator i; GEOMUtils::TreeModel::const_iterator i;
for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) { for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
DependencyTree_Object* Main_object = myTreeMap[i.key()]; DependencyTree_Object* Main_object = myTreeMap[i->first];
LevelInfo Levelup = i.value().first.at(0); GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
if( myDisplayAscendants ->isChecked() ) { if( myDisplayAscendants ->isChecked() ) {
QMap<QString, NodeLinks>::iterator node; GEOMUtils::LevelInfo::const_iterator node;
for (node = Levelup.begin(); node != Levelup.end(); node++ ) { for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[node.key()]; DependencyTree_Object* object = myTreeMap[node->first];
addArrow(Main_object, object); DependencyTree_Arrow* arrow = Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(Main_object, object)];
if( arrow && !isItemAdded( arrow) )
addItem( arrow );
} }
} }
if( myDisplayAscendants ->isChecked() ) if( myDisplayAscendants ->isChecked() )
drawWardArrows( i.value().first ); drawWardArrows( i->second.first );
if( myDisplayDescendants->isChecked() ) if( myDisplayDescendants->isChecked() )
drawWardArrows( i.value().second ); drawWardArrows( i->second.second );
} }
} }
void DependencyTree_View::drawWardArrows( LevelsList theWard ) void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
{ {
for(int j = 0; j < theWard.size(); j++ ) { for(int j = 0; j < theWard.size(); j++ ) {
if( j >= myLevelsNumber ) if( j >= myLevelsNumber )
break; break;
LevelInfo Level = theWard.at(j); GEOMUtils::LevelInfo Level = theWard.at(j);
QMap<QString, NodeLinks>::iterator node; GEOMUtils::LevelInfo::const_iterator node;
for (node = Level.begin(); node != Level.end(); node++ ) { for (node = Level.begin(); node != Level.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[node.key()]; DependencyTree_Object* object = myTreeMap[node->first];
QList<QString> Links = node.value(); GEOMUtils::NodeLinks Links = node->second;
for( int link = 0; link < Links.size(); link++ ) { for( int link = 0; link < Links.size(); link++ ) {
DependencyTree_Object* LinkObject = myTreeMap[Links[link]]; DependencyTree_Object* LinkObject = myTreeMap[Links[link]];
if( isItemAdded( object ) && isItemAdded( LinkObject ) ) { if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
addArrow(object, LinkObject); DependencyTree_Arrow* arrow = Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)];
if( arrow && !isItemAdded( arrow) )
addItem( arrow );
} }
} }
} }
} }
} }
void DependencyTree_View::parseTree()
void DependencyTree_View::parseData( QString& theData )
{ {
int cursor = 0;
while( theData.indexOf('-',cursor) != -1 ) //find next selected object GEOMUtils::TreeModel::const_iterator i;
{ for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
int objectIndex = theData.indexOf( '-', cursor ); std::string objectEntry = i->first;
QString objectEntry = theData.mid( cursor, objectIndex - cursor );
addNode( objectEntry ); addNode( objectEntry );
std::cout<<"\n\nMainObject = " << objectEntry.toStdString() <<std::endl; parseTreeWard( i->second.first );
cursor = objectIndex; if( i->second.first.size() > myMaxUpwardLevelsNumber )
myMaxUpwardLevelsNumber = i->second.first.size();
parseTreeWard( i->second.second );
if( i->second.second.size() > myMaxDownwardLevelsNumber )
myMaxDownwardLevelsNumber = i->second.second.size();
}
int upwardIndexBegin = theData.indexOf("{",cursor) + 1; for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
int upwardIndexFinish = theData.indexOf("}",upwardIndexBegin); DependencyTree_Object* Main_object = myTreeMap[i->first];
std::cout<<" Upward:" << std::endl; GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
LevelsList upwardList = parseWard( theData, cursor ); GEOMUtils::LevelInfo::const_iterator node;
if( upwardList.size() > myMaxUpwardLevelsNumber ) for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
myMaxUpwardLevelsNumber = upwardList.size(); DependencyTree_Object* object = myTreeMap[node->first];
std::cout<<" Downward:" << std::endl; addArrow( Main_object, object );
LevelsList downwardList = parseWard( theData, cursor ); }
if( downwardList.size() > myMaxDownwardLevelsNumber ) parseTreeWardArrow( i->second.first );
myMaxDownwardLevelsNumber = downwardList.size(); parseTreeWardArrow( i->second.second );
}
myTreeModel[objectEntry] = QPair<LevelsList,LevelsList>( upwardList, downwardList );
}
void DependencyTree_View::parseTreeWard(const GEOMUtils::LevelsList theWard)
{
int levelsNumber = theWard.size();
for( int level = 0; level < levelsNumber; level++ ) {
GEOMUtils::LevelInfo levelInfo = theWard[ level ];
GEOMUtils::LevelInfo::const_iterator node;
for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
addNode( node->first );
}
} }
} }
void DependencyTree_View::parseTreeWardArrow(const GEOMUtils::LevelsList theWard)
{
for(int j = 0; j < theWard.size(); j++ ) {
GEOMUtils::LevelInfo Level = theWard.at(j);
GEOMUtils::LevelInfo::const_iterator node;
for (node = Level.begin(); node != Level.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[node->first];
std::vector<std::string> Links = node->second;
for( int link = 0; link < Links.size(); link++ ) {
DependencyTree_Object* LinkObject = myTreeMap[Links[link]];
if( object && LinkObject )
addArrow( object, LinkObject );
}
}
}
}
//void DependencyTree_View::parseData( QString& theData )
//{
// int cursor = 0;
//
// while( theData.indexOf('-',cursor) != -1 ) //find next selected object
// {
// int objectIndex = theData.indexOf( '-', cursor );
// QString objectEntry = theData.mid( cursor, objectIndex - cursor );
// //addNode( objectEntry );
// std::cout<<"\n\nMainObject = " << objectEntry.toStdString() <<std::endl;
// cursor = objectIndex;
//
// int upwardIndexBegin = theData.indexOf("{",cursor) + 1;
// int upwardIndexFinish = theData.indexOf("}",upwardIndexBegin);
// std::cout<<" Upward:" << std::endl;
// LevelsList upwardList = parseWard( theData, cursor );
// if( upwardList.size() > myMaxUpwardLevelsNumber )
// myMaxUpwardLevelsNumber = upwardList.size();
// std::cout<<" Downward:" << std::endl;
// LevelsList downwardList = parseWard( theData, cursor );
// if( downwardList.size() > myMaxDownwardLevelsNumber )
// myMaxDownwardLevelsNumber = downwardList.size();
//
// myTreeModel[objectEntry] = QPair<LevelsList,LevelsList>( upwardList, downwardList );
// }
//}
void DependencyTree_View::addNode( const QString& theEntry ) void DependencyTree_View::addNode( const std::string& theEntry )
{ {
if( !myTreeMap[theEntry] ) if( !myTreeMap[theEntry] )
myTreeMap[theEntry] = new DependencyTree_Object( theEntry ); myTreeMap[theEntry] = new DependencyTree_Object( theEntry );
@ -233,9 +234,10 @@ void DependencyTree_View::addArrow( DependencyTree_Object *startItem, Dependency
{ {
bool isFind = false; bool isFind = false;
std::cout << " " << startItem->getEntry().toStdString() << " " << endItem->getEntry().toStdString() << std::endl; std::cout << " " << startItem->getEntry() << " " << endItem->getEntry() << std::endl;
for( int i = 0; i < Arrows.size(); i++ ) { std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator i;
DependencyTree_Arrow* arrow = Arrows.at(i); for (i = Arrows.begin(); i != Arrows.end(); i++ ) {
DependencyTree_Arrow* arrow = i->second;
if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem ) { if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem ) {
isFind = true; isFind = true;
std::cout<<" theSame " << std::endl; std::cout<<" theSame " << std::endl;
@ -249,67 +251,60 @@ void DependencyTree_View::addArrow( DependencyTree_Object *startItem, Dependency
if( !isFind ) { if( !isFind ) {
DependencyTree_Arrow *arrow = new DependencyTree_Arrow(startItem, endItem); DependencyTree_Arrow *arrow = new DependencyTree_Arrow(startItem, endItem);
Arrows.append( arrow ); //Arrows.append( arrow );
addItem(arrow); //addItem(arrow);
Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>( startItem, endItem )] = arrow;
std::cout<<" addArrow " << std::endl; std::cout<<" addArrow " << std::endl;
} }
} }
DependencyTree_View::LevelsList DependencyTree_View::parseWard( const QString& theData, int& theCursor ) //DependencyTree_View::LevelsList DependencyTree_View::parseWard( const QString& theData, int& theCursor )
{ //{
int indexStart = theData.indexOf( "{", theCursor ) + 1; // int indexStart = theData.indexOf( "{", theCursor ) + 1;
int indexEnd = theData.indexOf( "}", indexStart ); // int indexEnd = theData.indexOf( "}", indexStart );
//
QString ward = theData.mid( indexStart, indexEnd - indexStart ); // QString ward = theData.mid( indexStart, indexEnd - indexStart );
QStringList levelsListStr = ward.split( ';' ); // QStringList levelsListStr = ward.split( ';' );
LevelsList levelsListData; // LevelsList levelsListData;
for( int level = 0; level < levelsListStr.size(); level++ ) { // for( int level = 0; level < levelsListStr.size(); level++ ) {
std::cout<<" Level" << level + 1 << ":" << std::endl; // std::cout<<" Level" << level + 1 << ":" << std::endl;
QStringList namesListStr = levelsListStr[level].split( ',' ); // QStringList namesListStr = levelsListStr[level].split( ',' );
LevelInfo levelInfoData; // LevelInfo levelInfoData;
for( int node = 0; node < namesListStr.size(); node++ ) { // for( int node = 0; node < namesListStr.size(); node++ ) {
QStringList linksListStr = namesListStr[node].split( '_' ); // QStringList linksListStr = namesListStr[node].split( '_' );
QString nodeItem = linksListStr[0]; // QString nodeItem = linksListStr[0];
if( !nodeItem.isEmpty() ) { // if( !nodeItem.isEmpty() ) {
addNode( nodeItem ); // //addNode( nodeItem );
NodeLinks linksListData; // NodeLinks linksListData;
std::cout<<" " << nodeItem.toStdString() << " - "; // std::cout<<" " << nodeItem.toStdString() << " - ";
for( int link = 1; link < linksListStr.size(); link++ ) { // for( int link = 1; link < linksListStr.size(); link++ ) {
QString linkItem = linksListStr[link]; // QString linkItem = linksListStr[link];
addNode( linkItem ); // //addNode( linkItem );
linksListData.append( linkItem ); // linksListData.append( linkItem );
std::cout << linkItem.toStdString() << ", "; // std::cout << linkItem.toStdString() << ", ";
}// Links // }// Links
levelInfoData[nodeItem] = linksListData; // levelInfoData[nodeItem] = linksListData;
std::cout << std::endl; // std::cout << std::endl;
} // }
}// Level's objects // }// Level's objects
levelsListData.append(levelInfoData); // levelsListData.append(levelInfoData);
}// Levels // }// Levels
//
theCursor = indexEnd + 1; // theCursor = indexEnd + 1;
//
return levelsListData; // return levelsListData;
} //}
void DependencyTree_View::drawTree() void DependencyTree_View::drawTree()
{ {
int horDistance, verDistance; int horDistance, verDistance;
myCurrentLevel = 0; myCurrentLevel = 0;
std::cout<<"\n\n\n\n MY TREE MODEL SIZE = " << myTreeModel.size() << std::endl; GEOMUtils::TreeModel::const_iterator i;
std::cout<<"\n\n\n\n MY TREE MAP SIZE = " << myTreeMap.size() << std::endl;
for( int j = 0; j < myTreeModel.keys().size(); j++ )
std::cout<< " STRING = " << myTreeModel.keys().at(j).toStdString() << std::endl;
QMap<QString,QPair<LevelsList,LevelsList> >::iterator i;
for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) { for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
myCurrentLevel = 0; myCurrentLevel = 0;
QString objectEntry = i.key(); std::string objectEntry = i->first;
std::cout<< " NAME = " << objectEntry.toStdString() << std::endl;
DependencyTree_Object* objectItem = myTreeMap[ objectEntry ]; DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
objectItem->setEnabled(true);
if( objectItem->isEnabled() )
std::cout<<"OK!!! "<< std::endl;
horDistance = 100 + int( objectItem->boundingRect().width() ); horDistance = 100 + int( objectItem->boundingRect().width() );
verDistance = 3 * int( objectItem->boundingRect().height() ); verDistance = 3 * int( objectItem->boundingRect().height() );
if( isItemAdded( objectItem ) ) { if( isItemAdded( objectItem ) ) {
@ -317,58 +312,60 @@ void DependencyTree_View::drawTree()
} }
else { else {
addItem( objectItem ); addItem( objectItem );
std::cout<<"\nLevel = " << myCurrentLevel << " Object = " << objectEntry.toStdString() << std::endl;
myLevelMap[ objectEntry ] = myCurrentLevel; myLevelMap[ objectEntry ] = myCurrentLevel;
myLevelsObject[ myCurrentLevel ].append( objectEntry ); myLevelsObject[ myCurrentLevel ].push_back( objectEntry );
} }
objectItem->setIsMainObject( true ); objectItem->setIsMainObject( true );
int levelposition = myCurrentLevel; int levelposition = myCurrentLevel;
if( myDisplayAscendants ->isChecked() ){ if( myDisplayAscendants ->isChecked() ){
drawWard( i.value().first, -1 ); drawWard( i->second.first, -1 );
myCurrentLevel = levelposition; myCurrentLevel = levelposition;
} }
if( myDisplayDescendants->isChecked() ) if( myDisplayDescendants->isChecked() )
drawWard( i.value().second, 1 ); drawWard( i->second.second, 1 );
//centerOn( objectItem );
} }
QMap< int, QList<QString> >::iterator j; std::map< int, std::vector<std::string> >::const_iterator j;
for (j = myLevelsObject.begin(); j != myLevelsObject.end(); j++ ) { for (j = myLevelsObject.begin(); j != myLevelsObject.end(); j++ ) {
int step = -horDistance*( j.value().size() - 1 )/2; int step = -horDistance*( j->second.size() - 1 )/2;
std::cout<<"\n\n LEVEL = " << j.key() << std::endl; std::cout<<"\n\n LEVEL = " << j->first << std::endl;
for( int object = 0; object < j.value().size(); object++ ) { for( int object = 0; object < j->second.size(); object++ ) {
if( myIsCompute ) { if( myIsCompute ) {
std::cout << j.value().at( object ).toStdString() << ", "; std::cout << j->second.at( object ) << ", ";
DependencyTree_Object* anObject = myTreeMap[ j.value().at( object ) ]; DependencyTree_Object* anObject = myTreeMap[ j->second.at( object ) ];
anObject->setPos( step, verDistance*j.key() ); anObject->setPos( step, verDistance*j->first );
step += horDistance; step += horDistance;
//sleep(1); //sleep(1);
} }
} }
} }
centerOn( scene()->sceneRect().center() );
} }
void DependencyTree_View::drawWard( const DependencyTree_View::LevelsList theWard, const int theLevelStep ) void DependencyTree_View::drawWard( const GEOMUtils::LevelsList theWard, const int theLevelStep )
{ {
std::cout << "\n\n myLevelsNumber2 = " << myLevelsNumber << std::endl;
int levelsNumber = theWard.size(); int levelsNumber = theWard.size();
std::cout << "\n\n levelsNumber = " << levelsNumber << std::endl;
for( int level = 0; level < levelsNumber; level++ ) { for( int level = 0; level < levelsNumber; level++ ) {
if( level >= myLevelsNumber ) if( level >= myLevelsNumber )
return; return;
myCurrentLevel += theLevelStep; myCurrentLevel += theLevelStep;
LevelInfo levelInfo = theWard.at( level ); GEOMUtils::LevelInfo levelInfo = theWard.at( level );
QMap<QString, NodeLinks>::iterator node; GEOMUtils::LevelInfo::const_iterator node;
for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) { for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
DependencyTree_Object* object = myTreeMap[ node.key() ]; DependencyTree_Object* object = myTreeMap[ node->first ];
if( !isItemAdded( object ) ) { if( !isItemAdded( object ) ) {
std::cout<< "\n\n\n addItem = " << object->getEntry() << std::endl;
addItem( object ); addItem( object );
myLevelMap[ node.key() ] = myCurrentLevel; myLevelMap[ node->first ] = myCurrentLevel;
myLevelsObject[ myCurrentLevel ].append( node.key() ); myLevelsObject[ myCurrentLevel ].push_back( node->first );
} }
} }
} }
} }
void DependencyTree_View::onUpdateTree() void DependencyTree_View::onUpdateTree()
@ -377,22 +374,20 @@ void DependencyTree_View::onUpdateTree()
myLevelsObject.clear(); myLevelsObject.clear();
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
if( isItemAdded( object ) && object ) if( isItemAdded( object ) && object )
removeItem( object ); removeItem( object );
} }
std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
std::cout<<"\n\n\n\n ARROWS = " << Arrows.size() << std::endl; for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
DependencyTree_Arrow* object = Arrows[ j->first ];
for(int j = 0; j<Arrows.size();j++) if( isItemAdded( object ) && object )
if( isItemAdded( Arrows[j]) ) removeItem( object );
removeItem( Arrows[j] ); }
Arrows.clear();
drawTree(); drawTree();
drawArrows(); drawArrows();
@ -413,13 +408,26 @@ int DependencyTree_View::checkMaxLevelsNumber()
void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame ) void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
{ {
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QString Data = "MainObject1-upward{up11_up21_up22,up12_up23,up13_up24;up21_up11,up22_up21_up12,up23_up23,up24}"
std::string Data = "MainObject1-upward{up11_up21_up22,up12_up23,up13_up24;up21_up11,up22_up21_up12,up23_up23,up24}"
"downward{down11_MainObject1,down12_MainObject1;down21_down11,down22_down12,down23_down12,down24_down24_down11,down25_down12;down31_down11_down23,down32_down25}" "downward{down11_MainObject1,down12_MainObject1;down21_down11,down22_down12,down23_down12,down24_down24_down11,down25_down12;down31_down11_down23,down32_down25}"
"down23-upward{down12_MainObject1;MainObject1_up11_up12_up13;up11_up21_up22,up12_up23,up13_up24;up21,up22_up21_up12,up23,up24}" "down23-upward{down12_MainObject1;MainObject1_up11_up12_up13;up11_up21_up22,up12_up23,up13_up24;up21,up22_up21_up12,up23,up24}"
"downward{down31_down11_down23}" "downward{down31_down11_down23}"
"MainObject2-upward{up21,newup11_newup31,newup12_newup21;newup21_newup31LongName;newup31LongName}downward{newdown11_MainObject2,newdown12_MainObject2,newdown13_MainObject2;newdown21_newdown13,down21;newdown31_newdown11}"; "MainObject2-upward{up21,newup11_newup31,newup12_newup21;newup21_newup31LongName;newup31LongName}downward{newdown11_MainObject2,newdown12_MainObject2,newdown13_MainObject2;newdown21_newdown13,down21;newdown31_newdown11}"
"MainObject3-upward{moUP1_moUP4,moUP2_moUP3;moUP4,moUP3_down23}downward{moDOWN1_MainObject3}";
parseData( Data );
//GEOMUtils::ConvertStringToTree( Data, myTreeModel );
// GEOMUtils::TreeModel::const_iterator i;
// for ( i = aTreeModel.begin(); i != aTreeModel.end(); i++ ) {
// std::string objectEntry = i->first;
// std::cout << "\n\n Main object = " << objectEntry << std::endl;
// }
// parseData( Data );
parseTree();
myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) ); myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) );
@ -436,6 +444,7 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
ShowChildrenAction->setDefaultWidget( myDisplayDescendants ); ShowChildrenAction->setDefaultWidget( myDisplayDescendants );
myLevelsNumber = checkMaxLevelsNumber(); myLevelsNumber = checkMaxLevelsNumber();
std::cout << "\n\n myLevelsNumber1 = " << myLevelsNumber << std::endl;
myHierarchyDepth = new QSpinBox(); myHierarchyDepth = new QSpinBox();
myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() ); myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
myHierarchyDepth->setValue( 0 ); myHierarchyDepth->setValue( 0 );
@ -497,9 +506,10 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
void DependencyTree_View::onMoveNodes( bool theIsMoveNodes ) void DependencyTree_View::onMoveNodes( bool theIsMoveNodes )
{ {
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
if( object )
object->setMovable( theIsMoveNodes ); object->setMovable( theIsMoveNodes );
} }
} }
@ -527,22 +537,21 @@ void DependencyTree_View::updateView()
myLevelsObject.clear(); myLevelsObject.clear();
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
if( isItemAdded( object ) && object ) if( isItemAdded( object ) && object )
removeItem( object ); removeItem( object );
} }
std::cout<<"\n\n\n\n ARROWS = " << Arrows.size() << std::endl; std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
for(int j = 0; j<Arrows.size();j++) DependencyTree_Arrow* object = Arrows[ j->first ];
if( isItemAdded( Arrows[j]) ) if( isItemAdded( object ) && object )
removeItem( Arrows[j] ); removeItem( object );
}
Arrows.clear();
@ -638,51 +647,54 @@ void DependencyTree_View::setPrefBackgroundColor( const QColor& theColor )
void DependencyTree_View::setNodeColor( const QColor& theColor ) void DependencyTree_View::setNodeColor( const QColor& theColor )
{ {
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
object->setColor( theColor ); object->setColor( theColor );
} }
} }
void DependencyTree_View::setMainNodeColor( const QColor& theColor ) void DependencyTree_View::setMainNodeColor( const QColor& theColor )
{ {
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
object->setMainObjectColor( theColor ); object->setMainObjectColor( theColor );
} }
} }
void DependencyTree_View::setSelectNodeColor( const QColor& theColor ) void DependencyTree_View::setSelectNodeColor( const QColor& theColor )
{ {
QMap<QString,DependencyTree_Object*>::iterator i; std::map<std::string,DependencyTree_Object*>::const_iterator i;
for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
DependencyTree_Object* object = myTreeMap[ i.key() ]; DependencyTree_Object* object = myTreeMap[ i->first ];
object->setSelectColor( theColor ); object->setSelectColor( theColor );
} }
} }
void DependencyTree_View::setArrowColor( const QColor& theColor ) void DependencyTree_View::setArrowColor( const QColor& theColor )
{ {
for( int i = 0; i < Arrows.size(); i++ ) { std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
DependencyTree_Arrow* arrow = Arrows[i]; for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
DependencyTree_Arrow* arrow = Arrows[ j->first ];
arrow->setColor( theColor ); arrow->setColor( theColor );
} }
} }
void DependencyTree_View::setHighlightArrowColor( const QColor& theColor ) void DependencyTree_View::setHighlightArrowColor( const QColor& theColor )
{ {
for( int i = 0; i < Arrows.size(); i++ ) { std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
DependencyTree_Arrow* arrow = Arrows[i]; for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
DependencyTree_Arrow* arrow = Arrows[ j->first ];
arrow->setHighlightColor( theColor ); arrow->setHighlightColor( theColor );
} }
} }
void DependencyTree_View::setSelectArrowColor( const QColor& theColor ) void DependencyTree_View::setSelectArrowColor( const QColor& theColor )
{ {
for( int i = 0; i < Arrows.size(); i++ ) { std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
DependencyTree_Arrow* arrow = Arrows[i]; for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
DependencyTree_Arrow* arrow = Arrows[ j->first ];
arrow->setSelectColor( theColor ); arrow->setSelectColor( theColor );
} }
} }

View File

@ -23,30 +23,26 @@
#include <GraphicsView_ViewPort.h> #include <GraphicsView_ViewPort.h>
#include <GraphicsView_ViewFrame.h> #include <GraphicsView_ViewFrame.h>
#include <QGraphicsView> #include <GEOMUtils.hxx>
#include <QList>
#include <QMap>
#include <QString>
#include <QPair>
#include <QWidgetAction> #include <QWidgetAction>
#include <QPushButton>
#include <QSpinBox> #include <QSpinBox>
#include <QCheckBox> #include <QCheckBox>
#include <QProgressBar> #include <QProgressBar>
#include <QThread> #include <QThread>
#include <QDialog>
#include "DependencyTree_Arrow.h"
class DependencyTree_Object; class DependencyTree_Object;
class DependencyTree_Arrow;
class DependencyTree_View; class DependencyTree_View;
class DependencyTree_ComputeDlg_QThread : public QThread class DependencyTree_ComputeDlg_QThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
DependencyTree_ComputeDlg_QThread(DependencyTree_View*);
DependencyTree_ComputeDlg_QThread( DependencyTree_View* );
bool result(); bool result();
void cancel(); void cancel();
@ -62,10 +58,10 @@ private:
class DependencyTree_View: public GraphicsView_ViewPort class DependencyTree_View: public GraphicsView_ViewPort
{ {
Q_OBJECT Q_OBJECT
public: public:
DependencyTree_View( QWidget* = 0 );
DependencyTree_View( QWidget* theParent=0 );
~DependencyTree_View(); ~DependencyTree_View();
void setHierarchyType( const int ); void setHierarchyType( const int );
@ -78,18 +74,18 @@ public:
void setHighlightArrowColor( const QColor& ); void setHighlightArrowColor( const QColor& );
void setSelectArrowColor( const QColor& ); void setSelectArrowColor( const QColor& );
typedef QList<QString> NodeLinks; // typedef QList<QString> NodeLinks;
typedef QMap<QString, NodeLinks> LevelInfo; // typedef QMap<QString, NodeLinks> LevelInfo;
typedef QList<LevelInfo> LevelsList; // typedef QList<LevelInfo> LevelsList;
typedef QMap<QString,QPair<LevelsList,LevelsList> > TreeModel; // typedef QMap<QString,QPair<LevelsList,LevelsList> > TreeModel;
TreeModel myTreeModel; GEOMUtils::TreeModel myTreeModel;
QMap<QString,DependencyTree_Object*> myTreeMap; std::map<std::string,DependencyTree_Object*> myTreeMap;
QList<DependencyTree_Arrow*> Arrows; std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>,DependencyTree_Arrow*> Arrows;
QMap<QString,int> myLevelMap; std::map<std::string,int> myLevelMap;
QMap< int, QList<QString> > myLevelsObject; std::map< int, std::vector<std::string> > myLevelsObject;
int myCurrentLevel; int myCurrentLevel;
void init( GraphicsView_ViewFrame* ); void init( GraphicsView_ViewFrame* );
@ -112,15 +108,20 @@ private slots:
void onCancel(); void onCancel();
private: private:
void parseData( QString& data ); // void parseData( QString& data );
void addNode( const QString& entry );
void parseTree();
void parseTreeWard(const GEOMUtils::LevelsList);
void parseTreeWardArrow(const GEOMUtils::LevelsList);
void addNode( const std::string& entry );
void addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem ); void addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem );
void findArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem ); void findArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem );
DependencyTree_View::LevelsList parseWard( const QString& data, int& cursor ); // GEOMUtils::LevelsList parseWard( const QString& data, int& cursor );
void drawTree(); void drawTree();
void drawWard( DependencyTree_View::LevelsList ward, const int levelStep ); void drawWard( GEOMUtils::LevelsList ward, const int levelStep );
void drawArrows(); void drawArrows();
void drawWardArrows( LevelsList ); void drawWardArrows( GEOMUtils::LevelsList );
int checkMaxLevelsNumber(); int checkMaxLevelsNumber();
int myLevelsNumber; int myLevelsNumber;
@ -132,7 +133,7 @@ private:
QCheckBox* myDisplayAscendants; QCheckBox* myDisplayAscendants;
QCheckBox* myDisplayDescendants; QCheckBox* myDisplayDescendants;
QString myData; std::string myData;
bool myIsUpdate; bool myIsUpdate;
@ -145,34 +146,8 @@ private:
QWidgetAction* cancelAction; QWidgetAction* cancelAction;
QWidgetAction* progressAction; QWidgetAction* progressAction;
//SALOMEDS::Study_var myStudy;
}; };
///*!
// * \brief Dialog to display Cancel button
// */
//
//class DependencyTree_ComputeDlg_QThreadQDialog : public QDialog
//{
// Q_OBJECT
//
//public:
// DependencyTree_ComputeDlg_QThreadQDialog(QWidget* parent, DependencyTree_View*);
// bool result();
//
//protected:
// void timerEvent(QTimerEvent *timer);
// void closeEvent(QCloseEvent *event);
//
//private slots:
// void onCancel();
//
//private:
//
// DependencyTree_ComputeDlg_QThread qthread;
// QPushButton * cancelButton;
// QProgressBar* progressBar;
//};
#endif #endif

View File

@ -39,6 +39,7 @@ INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/src/GEOMBase ${PROJECT_SOURCE_DIR}/src/GEOMBase
${PROJECT_SOURCE_DIR}/src/Material ${PROJECT_SOURCE_DIR}/src/Material
${PROJECT_SOURCE_DIR}/src/DependencyTree ${PROJECT_SOURCE_DIR}/src/DependencyTree
${PROJECT_SOURCE_DIR}/src/GEOMUtils
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )