]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
- add new method for view
authormpa <mpa@opencascade.com>
Wed, 28 May 2014 11:06:55 +0000 (15:06 +0400)
committermpa <mpa@opencascade.com>
Wed, 28 May 2014 11:06:55 +0000 (15:06 +0400)
- edit the work of thread

src/DependencyTree/CMakeLists.txt
src/DependencyTree/DependencyTree.cxx
src/DependencyTree/DependencyTree_Arrow.cxx
src/DependencyTree/DependencyTree_Arrow.h
src/DependencyTree/DependencyTree_Object.cxx
src/DependencyTree/DependencyTree_Object.h
src/DependencyTree/DependencyTree_View.cxx
src/DependencyTree/DependencyTree_View.h

index 36d21200597617b756c4de733db04f8ad5bffc13..2ab2bc27154870fde73c50a25eef94539cae23ec 100644 (file)
@@ -72,8 +72,8 @@ SET(_link_LIBRARIES
 
 SET(DependencyTree_HEADERS
   DependencyTree.h
-  DependencyTree_Object.h
   DependencyTree_Arrow.h
+  DependencyTree_Object.h
   )
 
 # header files / to be processed by moc
index c3de20da41966cf056a0650edd569b2eb1ab4f7c..6fdc892babb967b2008af0ceb4557dc1f3a0f71e 100644 (file)
@@ -73,7 +73,11 @@ DependencyTree::DependencyTree()
              svm->setTitle("DEPENDENCY_TREE");
            }
            else {
-             svm->getActiveView()->setFocus();
+          if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
+               if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
+                 svm->getActiveView()->setFocus();
+                 view->updateModel();
+               }
            }
 
 
index 3f6925ad8818337e1be946b236c5ae4ff52ee3de..f403cd90684ef4b0c0373ceda3a9cc37a607f88b 100644 (file)
@@ -48,6 +48,7 @@ myEndItem( theEndItem )
   myStartItem = theStartItem;
   myEndItem = theEndItem;
 
+  myLine = QLineF( myStartItem->pos(), myEndItem->pos() );
   myArrowHead  = createArrowHead( myStartItem->pos(), myEndItem->pos() );
   myReverseArrowHead = createArrowHead( myEndItem->pos(), myStartItem->pos() );
 
@@ -79,8 +80,8 @@ QRectF DependencyTree_Arrow::boundingRect() const
   }
   else {
     extra = ( pen().width() + 20 ) / 2.0;
-    boundingRect = QRectF( line().p1(), QSizeF( line().p2().x() - line().p1().x(),
-                                                line().p2().y() - line().p1().y() ) );
+    boundingRect = QRectF( myLine.p1(), QSizeF( myLine.p2().x() - myLine.p1().x(),
+                                                myLine.p2().y() - myLine.p1().y() ) );
   }
   return boundingRect.normalized().adjusted( -extra, -extra, extra, extra );
 }
@@ -209,7 +210,7 @@ void DependencyTree_Arrow::paint( QPainter* painter, const QStyleOptionGraphicsI
     myArrowHead  = createArrowHead( myStartItem->pos(), myEndItem->pos() );
     myReverseArrowHead = createArrowHead( myEndItem->pos(), myStartItem->pos() );
 
-    painter->drawLine( line() );
+    painter->drawLine( myLine );
     painter->drawPolygon( myArrowHead );
     if( myIsBiLink )
       painter->drawPolygon( myReverseArrowHead );
@@ -238,21 +239,21 @@ QPolygonF DependencyTree_Arrow::createArrowHead( QPointF theStartPoint, QPointF
         break;
       p1 = p2;
     }
-    setLine( QLineF( intersectPoint, theStartPoint ) );
+    myLine = QLineF( intersectPoint, theStartPoint );
   }
   else
-    setLine( QLineF( theEndPoint, theStartPoint ) );
+    myLine = QLineF( theEndPoint, theStartPoint );
 
-  double angle = acos(line().dx() / line().length());
-  if( line().dy() >= 0 )
+  double angle = acos(myLine.dx() / myLine.length());
+  if( myLine.dy() >= 0 )
     angle = ( M_PI * 2 ) - angle;
 
-  QPointF arrowP1 = line().p1() + QPointF( sin( angle + M_PI / 3 ) * arrowSize,
+  QPointF arrowP1 = myLine.p1() + QPointF( sin( angle + M_PI / 3 ) * arrowSize,
                                            cos( angle + M_PI / 3 ) * arrowSize );
-  QPointF arrowP2 = line().p1() + QPointF( sin( angle + M_PI - M_PI / 3 ) * arrowSize,
+  QPointF arrowP2 = myLine.p1() + QPointF( sin( angle + M_PI - M_PI / 3 ) * arrowSize,
                                            cos( angle + M_PI - M_PI / 3 ) * arrowSize );
 
   QPolygonF anArrowHead;
-  anArrowHead << line().p1() << arrowP1 << arrowP2;
+  anArrowHead << myLine.p1() << arrowP1 << arrowP2;
   return anArrowHead;
 }
index 1518c72eaab9bc374c0fe1cbfa282aab6f126dd1..0877556515c7c1fe6b3cdf7edff938fbbd8eb813 100644 (file)
@@ -67,6 +67,8 @@ private:
 
   QRectF                  mySelfDependencyArrow;
 
+  QLineF                  myLine;
+
 };
 
 #endif
index 2f839df33183cb823c1098466f116fe396c3a1bb..21d2f79718b8f3f245b9df649e8c13d508e9c264 100644 (file)
@@ -37,8 +37,7 @@ const int itemW = 90;
 
 DependencyTree_Object::DependencyTree_Object( const std::string& theEntry, QGraphicsItem* theParent )
 :GraphicsView_Object( theParent ),
-myIsMainObject( false ),
-myIsLongName( false )
+myIsMainObject( false )
 {
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
@@ -61,6 +60,13 @@ myIsLongName( false )
   myTextItem->setFont( textFont );
 
   myEntry = theEntry;
+
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if ( !app ) return;
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+  int studyId = GeometryGUI::ClientStudyToStudy( study->studyDS())->StudyId();
+  myGeomObject = GeometryGUI::GetGeomGen()->GetObject( studyId, myEntry.c_str() );
+
   updateName();
 
   addToGroup( myPolygonItem );
@@ -85,8 +91,7 @@ bool DependencyTree_Object::highlight( double theX, double theY )
     myPolygonItem->setBrush( color );
     myPolygonItem->setPen( getPen( color ) );
 
-    if( myIsLongName )
-      myPolygonItem->setToolTip( getName() );
+    myPolygonItem->setToolTip( getName() );
   }
   return GraphicsView_Object::highlight( theX, theY );
 }
@@ -146,29 +151,31 @@ std::string DependencyTree_Object::getEntry() const
   return myEntry;
 }
 
+//=================================================================================
+// function : getGeomObject()
+// purpose  : get geometry object of current item
+//=================================================================================
+GEOM::GEOM_BaseObject_var DependencyTree_Object::getGeomObject() const
+{
+  return myGeomObject;
+}
+
 //=================================================================================
 // function : updateName()
 // purpose  : update name of current item using its entry
 //=================================================================================
 void DependencyTree_Object::updateName()
 {
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  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() );
 
-  QString name = object->GetName();
-  QString StudyEntry = object->GetStudyEntry();
-  std::cout << "\n\n\n StudyEntry = " << StudyEntry.toStdString() << "  " << StudyEntry.isEmpty() <<  std::endl;
+  QString name = myGeomObject->GetName();
+  QString studyEntry = myGeomObject->GetStudyEntry();
 
-
-  if( StudyEntry.isEmpty() ) {
+  if( studyEntry.isEmpty() ) {
        if( name.isEmpty() )
       name = "unpublished";
-    myColor = resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) );
+    myColor = QColor( 255, 255, 255 );
+    myPolygonItem->setBrush( myColor );
+    myPolygonItem->setPen( getPen( myColor ) );
   }
 
   setName( name );
@@ -181,7 +188,6 @@ void DependencyTree_Object::updateName()
   double polygonHeight = myPolygonItem->sceneBoundingRect().height();
 
   if( ( textWidth - 4 ) > polygonWidth ) {
-    myIsLongName = true;
     int numberSymbol = int( polygonWidth * name.length() / textWidth );
     QString newName = name.left( numberSymbol - 3 ) + "...";
     myTextItem->setText( newName );
index da04b69014927ec28e87ef390db004c0b61595df..a4a27b3035b7408dba9a61fa4b299a3edce8f870 100644 (file)
 
 #include <GraphicsView_Object.h>
 
+// GEOM includes
+#include <GeometryGUI.h>
+#include <GEOM_BaseObject.hxx>
+
 #include <QPen>
 
 class DependencyTree_Object: public GraphicsView_Object
@@ -32,39 +36,41 @@ public:
   DependencyTree_Object( const std::string&, QGraphicsItem* = 0 );
   ~DependencyTree_Object();
 
-  virtual void              compute() {};
+  virtual void                compute() {};
+
+  virtual bool                highlight( double, double );
+  virtual void                unhighlight();
 
-  virtual bool              highlight( double, double );
-  virtual void              unhighlight();
+  virtual bool                select( double, double, const QRectF& );
+  virtual void                unselect();
 
-  virtual bool              select( double, double, const QRectF& );
-  virtual void              unselect();
+  std::string                 getEntry() const;
 
-  std::string               getEntry() const;
+  GEOM::GEOM_BaseObject_var  getGeomObject() const;
 
-  void                      updateName();
+  void                        updateName();
 
-  void                      setColor(const QColor& );
-  void                      setSelectColor(const QColor& );
-  void                      setMainObjectColor(const QColor& );
+  void                        setColor(const QColor& );
+  void                        setSelectColor(const QColor& );
+  void                        setMainObjectColor(const QColor& );
 
-  void                      setIsMainObject( bool );
+  void                        setIsMainObject( bool );
 
 private:
 
-  QPen                      getPen( const QColor& );
+  QPen                        getPen( const QColor& );
 
-  QColor                    myColor;
-  QColor                    mySelectColor;
-  QColor                    myMainObjectColor;
+  QColor                      myColor;
+  QColor                      mySelectColor;
+  QColor                      myMainObjectColor;
 
-  QGraphicsPolygonItem*     myPolygonItem;
-  QGraphicsSimpleTextItem*  myTextItem;
+  QGraphicsPolygonItem*       myPolygonItem;
+  QGraphicsSimpleTextItem*    myTextItem;
 
-  std::string                   myEntry;
+  GEOM::GEOM_BaseObject_var   myGeomObject;
+  std::string                 myEntry;
 
-  bool                      myIsMainObject;
-  bool                      myIsLongName;
+  bool                        myIsMainObject;
 
 };
 
index 4785f4101d768ade431f0706f715d5309eab3c9f..674850696fb08f462ff96f449ad5c19b2caca9fe 100644 (file)
@@ -28,7 +28,6 @@
 // GUI includes
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
-#include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <QtxActionToolMgr.h>
 #include <LightApp_SelectionMgr.h>
@@ -41,7 +40,6 @@
 
 
 #include <iostream>
-int iter = 0;
 
 DependencyTree_View::DependencyTree_View( QWidget* theParent )
 :GraphicsView_ViewPort(theParent),
@@ -49,581 +47,215 @@ myMaxDownwardLevelsNumber(0),
 myMaxUpwardLevelsNumber(0),
 myLevelsNumber(0),
 myIsCompute(true),
-myIsUpdate( true )
+myIsUpdate( true ),
+myTotalCost(0),
+myComputedCost(0)
 {
   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 myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS());
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS());
 
-  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
-  if ( !aSelMgr ) return;
+  mySelectionMgr = app->selectionMgr();
+  if ( !mySelectionMgr ) return;
 
-  SALOME_ListIO aSelList;
-  aSelMgr->selectedObjects(aSelList);
-
-  GEOM::string_array_var ObjectIORs = new GEOM::string_array();
-    ObjectIORs->length( aSelList.Extent());
-    int aaa=0;
-
-   for ( SALOME_ListIteratorOfListIO It( aSelList ); It.More(); It.Next() ) {
-    Handle( SALOME_InteractiveObject ) io = It.Value();
-
-
-    GEOM::GEOM_Object_var myObject = GEOM::GEOM_Object::_nil();
-    myObject = GEOMBase::ConvertIOinGEOMObject( io );
-    QString ior = myObject->GetEntry();
-    ObjectIORs[aaa] = ior.toLatin1().constData();
-    aaa++;
-
-    std::cout << "\n\n IOR = " << ior.toStdString() << std::endl;
-  }
-
-  SALOMEDS::TMPFile_var SeqFile =
-  GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, ObjectIORs );
-  char* buf;
-  buf = (char*) &SeqFile[0];
-
-  std::cout << "\n\n\n\n\n TREE = " << buf << std::endl;
-
-  GEOMUtils::ConvertStringToTree( buf, myTreeModel );
-
-  aSelMgr->clearSelected();
+  getNewTreeModel();
 }
 
 DependencyTree_View::~DependencyTree_View()
 {
-
-}
-
-void DependencyTree_View::drawArrows()
-{
-       GEOMUtils::TreeModel::const_iterator i;
-       for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
-               DependencyTree_Object* Main_object = myTreeMap[i->first];
-           if( i->second.first.size() > 0 ) {
-                 GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
-                 if( myDisplayAscendants ->isChecked() ) {
-                       GEOMUtils::LevelInfo::const_iterator node;
-                   for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
-                     DependencyTree_Object* object = myTreeMap[node->first];
-                     DependencyTree_Arrow* arrow = Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(Main_object, object)];
-                     if( arrow && !isItemAdded( arrow) )
-                       addItem( arrow );
-                   }
-                 }
-           }
-               if( myDisplayAscendants ->isChecked() )
-       drawWardArrows( i->second.first );
-               if( myDisplayDescendants->isChecked() )
-       drawWardArrows( i->second.second );
-
-         }
-}
-
-void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
-{
-         for(int j = 0; j < theWard.size(); j++ ) {
-                 if( j >= myLevelsNumber )
-               break;
-                 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];
-                   GEOMUtils::NodeLinks Links = node->second;
-          for( int link = 0; link < Links.size(); link++ ) {
-            DependencyTree_Object* LinkObject = myTreeMap[Links[link]];
-            if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
-                   DependencyTree_Arrow* arrow = Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)];
-                   if( arrow && !isItemAdded( arrow) )
-                     addItem( arrow );
-               }
-          }
-                 }
-         }
-}
-
-void DependencyTree_View::parseTree()
-{
-
-  GEOMUtils::TreeModel::const_iterator i;
-  for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
-    std::string objectEntry = i->first;
-    addNode( objectEntry );
-    parseTreeWard( i->second.first );
-    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();
-  }
-
-  for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
-    DependencyTree_Object* Main_object = myTreeMap[i->first];
-    if( i->second.first.size() > 0 ) {
-      GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
-      GEOMUtils::LevelInfo::const_iterator node;
-      for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
-        DependencyTree_Object* object = myTreeMap[node->first];
-        addArrow( Main_object, object );
-      }
-    }
-    parseTreeWardArrow( i->second.first );
-    parseTreeWardArrow( i->second.second );
-  }
-
-
-}
-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 std::string& theEntry )
-{
-  if( !myTreeMap[theEntry] )
-    myTreeMap[theEntry] = new DependencyTree_Object( theEntry );
-}
-
-void DependencyTree_View::addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem )
-{
-  bool isFind = false;
-
-  std::cout << "   " << startItem->getEntry() << "   " << endItem->getEntry() << std::endl;
-  std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator i;
-  for (i = Arrows.begin(); i != Arrows.end(); i++ ) {
-         DependencyTree_Arrow* arrow = i->second;
-    if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem ) {
-      isFind = true;
-      std::cout<<" theSame " << std::endl;
-    }
-    else if( arrow->getStartItem() == endItem && arrow->getEndItem() == startItem ) {
-      arrow->setIsBiLink( true );
-      std::cout<<" Bilink " << std::endl;
-      isFind = true;
-    }
-  }
-
-  if( !isFind ) {
-         DependencyTree_Arrow *arrow = new DependencyTree_Arrow(startItem, endItem);
-           //Arrows.append( arrow );
-           //addItem(arrow);
-           Arrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>( startItem, endItem )] = arrow;
-           std::cout<<" addArrow " << std::endl;
-  }
-}
-
-//DependencyTree_View::LevelsList DependencyTree_View::parseWard( const QString& theData, int& theCursor )
-//{
-//       int indexStart = theData.indexOf( "{", theCursor ) + 1;
-//       int indexEnd = theData.indexOf( "}", indexStart );
-//
-//       QString ward = theData.mid( indexStart, indexEnd - indexStart );
-//       QStringList levelsListStr = ward.split( ';' );
-//       LevelsList levelsListData;
-//       for( int level = 0; level < levelsListStr.size(); level++ ) {
-//         std::cout<<"    Level" << level + 1 << ":" << std::endl;
-//         QStringList namesListStr = levelsListStr[level].split( ',' );
-//         LevelInfo levelInfoData;
-//         for( int node = 0; node < namesListStr.size(); node++ ) {
-//           QStringList linksListStr = namesListStr[node].split( '_' );
-//           QString nodeItem = linksListStr[0];
-//           if( !nodeItem.isEmpty() ) {
-//             //addNode( nodeItem );
-//             NodeLinks linksListData;
-//             std::cout<<"      " << nodeItem.toStdString() << " - ";
-//             for( int link = 1; link < linksListStr.size(); link++ ) {
-//               QString linkItem = linksListStr[link];
-//               //addNode( linkItem );
-//               linksListData.append( linkItem );
-//               std::cout << linkItem.toStdString() << ", ";
-//             }// Links
-//             levelInfoData[nodeItem] = linksListData;
-//             std::cout << std::endl;
-//           }
-//         }// Level's objects
-//         levelsListData.append(levelInfoData);
-//       }// Levels
-//
-//       theCursor = indexEnd + 1;
-//
-//       return levelsListData;
-//}
-
-void DependencyTree_View::drawTree()
-{
-
-  int horDistance, verDistance;
-  myCurrentLevel = 0;
-    GEOMUtils::TreeModel::const_iterator i;
-    for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
-      myCurrentLevel = 0;
-      std::string objectEntry = i->first;
-      DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
-      horDistance = 100 + int( objectItem->boundingRect().width() );
-      verDistance = 3 * int( objectItem->boundingRect().height() );
-      if( isItemAdded( objectItem ) ) {
-        myCurrentLevel = myLevelMap[ objectEntry ];
-      }
-      else {
-        addItem( objectItem );
-        myLevelMap[ objectEntry ] = myCurrentLevel;
-        myLevelsObject[ myCurrentLevel ].push_back( objectEntry );
-      }
-      objectItem->setIsMainObject( true );
-
-      int levelposition = myCurrentLevel;
-      if( myDisplayAscendants ->isChecked() ){
-        drawWard( i->second.first, -1 );
-        myCurrentLevel = levelposition;
-      }
-      if( myDisplayDescendants->isChecked() )
-        drawWard( i->second.second, 1 );
-      }
-
-               std::map< int, std::vector<std::string> >::const_iterator j;
-               for (j = myLevelsObject.begin(); j != myLevelsObject.end(); j++ ) {
-                 int step = -horDistance*( j->second.size() - 1 )/2;
-                       std::cout<<"\n\n LEVEL = " << j->first << std::endl;
-                 for( int object = 0; object < j->second.size(); object++ ) {
-                        if( myIsCompute ) {
-                         std::cout << j->second.at( object ) << ", ";
-                        DependencyTree_Object* anObject = myTreeMap[ j->second.at( object ) ];
-                        anObject->setPos( step, verDistance*j->first );
-                        step += horDistance;
-                        //sleep(1);
-                        }
-                 }
-               }
-  centerOn( scene()->sceneRect().center() );
-  fitAll( true );
-
-}
-
-void DependencyTree_View::drawWard( const GEOMUtils::LevelsList theWard, const int theLevelStep )
-{
-       std::cout << "\n\n myLevelsNumber2 = " << myLevelsNumber << std::endl;
-         int levelsNumber = theWard.size();
-       std::cout << "\n\n levelsNumber = " << levelsNumber << std::endl;
-         for( int level = 0; level < levelsNumber; level++ ) {
-                 if( level >= myLevelsNumber )
-               return;
-           myCurrentLevel += theLevelStep;
-           GEOMUtils::LevelInfo levelInfo = theWard.at( level );
-           GEOMUtils::LevelInfo::const_iterator node;
-               for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
-             DependencyTree_Object* object = myTreeMap[ node->first ];
-             if( !isItemAdded( object ) ) {
-               addItem( object );
-               myLevelMap[ node->first ] = myCurrentLevel;
-               myLevelsObject[ myCurrentLevel ].push_back( node->first );
-             }
-           }
-        }
-
 }
 
-void DependencyTree_View::onUpdateTree()
-{
-  myLevelMap.clear();
-  myLevelsObject.clear();
-
-
-  std::map<std::string,DependencyTree_Object*>::const_iterator i;
-       for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
-               DependencyTree_Object* object = myTreeMap[ i->first ];
-               if( isItemAdded( object ) && object )
-          removeItem( object );
-
-       }
-
-   std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
-   for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
-     DependencyTree_Arrow* object = Arrows[ j->first ];
-     if( isItemAdded( object ) && object )
-       removeItem( object );
-   }
-
-  drawTree();
-  drawArrows();
-}
-
-
-int DependencyTree_View::checkMaxLevelsNumber()
-{
-  if( myDisplayAscendants ->isChecked() && myDisplayDescendants->isChecked() )
-    return myMaxUpwardLevelsNumber>myMaxDownwardLevelsNumber?myMaxUpwardLevelsNumber:myMaxDownwardLevelsNumber;
-  else if( myDisplayAscendants ->isChecked() )
-    return myMaxUpwardLevelsNumber;
-  else if( myDisplayDescendants->isChecked() )
-    return  myMaxDownwardLevelsNumber;
-}
-
-
 void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
 {
-         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-
-         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}"
-                                "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}"
-                                "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}";
-
-
-         //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();
-
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
   myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) );
-  QWidgetAction* moveNodesAction = new QWidgetAction( theViewFrame );
-  moveNodesAction->setDefaultWidget( myNodesMovable );
+  QWidgetAction* nodesMovableAction = new QWidgetAction( theViewFrame );
+  nodesMovableAction->setDefaultWidget( myNodesMovable );
 
-  myDisplayAscendants  = new QCheckBox( tr( "DISPLAY_ASCENDANTS" ));
-  myDisplayAscendants ->setChecked( true );
-  QWidgetAction* ShowParentsAction = new QWidgetAction(theViewFrame);
+  myDisplayAscendants = new QCheckBox( tr( "DISPLAY_ASCENDANTS" ) );
+  QWidgetAction* ShowParentsAction = new QWidgetAction( theViewFrame );
   ShowParentsAction->setDefaultWidget( myDisplayAscendants  );
 
   myDisplayDescendants = new QCheckBox(tr("DISPLAY_DESCENDANTS"));
   QWidgetAction* ShowChildrenAction = new QWidgetAction(theViewFrame);
   ShowChildrenAction->setDefaultWidget( myDisplayDescendants );
 
+  QLabel* hierarchyDepthLabel = new QLabel( tr( "HIERARCHY_DEPTH" ) );
+  QWidgetAction* hierarchyDepthLabelAction = new QWidgetAction(theViewFrame);
+  hierarchyDepthLabelAction->setDefaultWidget( hierarchyDepthLabel );
+
   myLevelsNumber = checkMaxLevelsNumber();
-  std::cout << "\n\n myLevelsNumber1 = " << myLevelsNumber << std::endl;
+
   myHierarchyDepth = new QSpinBox();
   myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
+  myHierarchyDepth->setSpecialValueText( tr( "SHOW_ALL" ) );
   myHierarchyDepth->setValue( 0 );
-  myHierarchyDepth->setSpecialValueText( "All" );
-  QWidgetAction* LevelsAction = new QWidgetAction(theViewFrame);
-  LevelsAction->setDefaultWidget( myHierarchyDepth );
-
-  QLabel* LevelsLabel = new QLabel( tr("HIERARCHY_DEPTH") );
-  QWidgetAction* LevelsLebelAction = new QWidgetAction(theViewFrame);
-  LevelsLebelAction->setDefaultWidget( LevelsLabel );
+  QWidgetAction* hierarchyDepthAction = new QWidgetAction( theViewFrame );
+  hierarchyDepthAction->setDefaultWidget( myHierarchyDepth );
 
+  QPushButton* updateButton = new QPushButton( tr( "UPDATE" ) );
+  QWidgetAction* updateAction = new QWidgetAction( theViewFrame );
+  updateAction->setDefaultWidget( updateButton );
 
-  QPushButton* UpdateButton = new QPushButton(tr("Update"));
-  QWidgetAction* UpdateAction = new QWidgetAction(theViewFrame);
-  UpdateAction->setDefaultWidget( UpdateButton );
-
-  cancelButton = new QPushButton(tr("CANCEL"));
-  cancelButton->setCheckable(true);
-  cancelButton->setVisible( false );
-  cancelAction = new QWidgetAction(theViewFrame);
+  QPushButton* cancelButton = new QPushButton( tr( "CANCEL" ) );
+  cancelButton->setCheckable( true );
+  cancelAction = new QWidgetAction( theViewFrame );
   cancelAction->setDefaultWidget( cancelButton );
-  cancelAction->setVisible(false);
+  cancelAction->setVisible( false );
 
-  progressBar  = new QProgressBar(this);
+  QProgressBar* progressBar = new QProgressBar( this );
   progressBar->setMinimum( 0 );
-  progressBar->setMaximum( 1000 );
-  progressBar->setFixedWidth(100);
-  progressAction = new QWidgetAction(theViewFrame);
+  progressBar->setMaximum( 100 );
+  progressBar->setFixedWidth( 100 );
+  progressAction = new QWidgetAction( theViewFrame );
   progressAction->setDefaultWidget( progressBar );
-  progressAction->setVisible(false);
+  progressAction->setVisible( false );
+
+  QAction* separator1 = theViewFrame->toolMgr()->separator( false );
+  QAction* separator2 = theViewFrame->toolMgr()->separator( false );
 
-  QAction* separator = theViewFrame->toolMgr()->separator(false);
-  theViewFrame->toolMgr()->append( separator, theViewFrame->getToolBarId() );
-  theViewFrame->toolMgr()->append( moveNodesAction, theViewFrame->getToolBarId() );
-  theViewFrame->toolMgr()->append( LevelsLebelAction, theViewFrame->getToolBarId() );
-  theViewFrame->toolMgr()->append( LevelsAction, theViewFrame->getToolBarId() );
+  theViewFrame->toolMgr()->append( separator1, theViewFrame->getToolBarId() );
+  theViewFrame->toolMgr()->append( nodesMovableAction, theViewFrame->getToolBarId() );
+  theViewFrame->toolMgr()->append( hierarchyDepthLabelAction, theViewFrame->getToolBarId() );
+  theViewFrame->toolMgr()->append( hierarchyDepthAction, theViewFrame->getToolBarId() );
   theViewFrame->toolMgr()->append( ShowParentsAction, theViewFrame->getToolBarId() );
   theViewFrame->toolMgr()->append( ShowChildrenAction, theViewFrame->getToolBarId() );
-  QAction* separator2 = theViewFrame->toolMgr()->separator(false);
+
   theViewFrame->toolMgr()->append( separator2, theViewFrame->getToolBarId() );
-  theViewFrame->toolMgr()->append( UpdateAction, theViewFrame->getToolBarId() );
-  std::cout<<"\n\n\n\n ToolBarId = " << theViewFrame->getToolBarId() << std::endl;
+  theViewFrame->toolMgr()->append( updateAction, theViewFrame->getToolBarId() );
   theViewFrame->toolMgr()->append( progressAction, theViewFrame->getToolBarId() );
   theViewFrame->toolMgr()->append( cancelAction, theViewFrame->getToolBarId() );
 
-  connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
-
+  connect( myNodesMovable, SIGNAL( toggled( bool ) ), this, SLOT( onMoveNodes( bool ) ) );
   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( myNodesMovable, SIGNAL( toggled(bool) ), this, SLOT( onMoveNodes( bool ) ) );
+  connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
+  connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
+  connect( updateButton, SIGNAL( clicked() ), this, SLOT( updateView() ) );
+  connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
 
   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 ) );
-
-
-}
-
-void DependencyTree_View::onMoveNodes( bool theIsMoveNodes )
-{
-  std::map<std::string,DependencyTree_Object*>::const_iterator i;
-  for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
-    DependencyTree_Object* object = myTreeMap[ i->first ];
-    if( object )
-      object->setMovable( theIsMoveNodes );
-  }
 }
 
-void DependencyTree_View::onHierarchyType()
+void DependencyTree_View::updateModel()
 {
-  myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
-  if( myHierarchyDepth->value() > checkMaxLevelsNumber() )
-    myHierarchyDepth->setValue( checkMaxLevelsNumber() );
+  getNewTreeModel();
 
-  if( myHierarchyDepth->value() == 0 )
-    myLevelsNumber = myHierarchyDepth->maximum();
-  else
-    myLevelsNumber = myHierarchyDepth->value();
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
-  updateView();
+  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 ) );
 }
-void DependencyTree_View::updateView()
-{
-
-  if( !myIsUpdate )
-    return;
-
-         myLevelMap.clear();
-         myLevelsObject.clear();
-
-
-         std::map<std::string,DependencyTree_Object*>::const_iterator i;
-               for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
-                       DependencyTree_Object* object = myTreeMap[ i->first ];
-                       if( isItemAdded( object ) && object )
-                 removeItem( object );
-
-               }
-
-
-                  std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
-                  for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
-                    DependencyTree_Arrow* object = Arrows[ j->first ];
-                    if( isItemAdded( object ) && object )
-                      removeItem( object );
-                  }
 
+void DependencyTree_View::drawTree()
+{
+  myComputedCost = 0;
+  calcTotalCost();
+  std::cout << "\n\n\n TOTAL COST = " << myTotalCost << std::endl;
 
+  clearSelected();
 
+  // draw nodes on scene
+  std::map< std::string, int > entryLevelMap;
+  std::map< int, std::vector< std::string > > levelObjects;
+  int currentLevel;
+  int horDistance, verDistance;
+  GEOMUtils::TreeModel::const_reverse_iterator i;
+  for( i = myTreeModel.rbegin(); i != myTreeModel.rend(); i++ ) {
+       if( !myIsCompute )
+      return;
+    currentLevel = 0;
+    myComputedCost++;
+    sleep(1);
+    std::string objectEntry = i->first;
+    DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
+    horDistance = 100 + int( objectItem->boundingRect().width() );
+    verDistance = 3 * int( objectItem->boundingRect().height() );
+    if( isItemAdded( objectItem ) )
+      currentLevel = entryLevelMap[ objectEntry ];
+    else {
+      addItem( objectItem );
+      objectItem->unselect();
+      entryLevelMap[ objectEntry ] = currentLevel;
+      levelObjects[ currentLevel ].push_back( objectEntry );
+    }
+    objectItem->setIsMainObject( true );
 
-       iter = 0;
-  qthread = new DependencyTree_ComputeDlg_QThread(this);// = DependencyTree_ComputeDlg_QThread(this);// const_cast<DependencyTree_View*>(this) );
-  cancelAction->setVisible( true );
-  progressAction->setVisible(true);
-  myNodesMovable->setEnabled(false);
-  myHierarchyDepth->setEnabled( false);
-  myDisplayAscendants->setEnabled( false );
-  myDisplayDescendants->setEnabled( false );
-  myTimer = startTimer(100); // millisecs
-  qthread->start();
-}
+    if( myDisplayAscendants->isChecked() )
+      drawWard( i->second.first, entryLevelMap, levelObjects, currentLevel, -1 );
+    if( myDisplayDescendants->isChecked() )
+      drawWard( i->second.second, entryLevelMap, levelObjects, currentLevel, 1 );
+  }
 
-void DependencyTree_View::onRedrawTree()
-{
-  drawTree();
-  drawArrows();
-}
-void DependencyTree_View::onCancel()
-{
-  qthread->cancel();
-  cancelButton->setText( tr("CANCELING"));
-  cancelButton->setEnabled(false);
-  killTimer( myTimer );
-  qthread->killTimer( myTimer );
-  qthread->deleteLater();
+  std::map< int, std::vector< std::string > >::const_iterator level;
+  for( level = levelObjects.begin(); level != levelObjects.end(); level++ ) {
+    int step = -horDistance * ( level->second.size() - 1 ) / 2;
+    std::cout<<"\n\n LEVEL = " << level->first << std::endl;
+    for( int objIter = 0; objIter < level->second.size(); objIter++ ) {
+        std::cout << level->second.at( objIter ) << ", ";
+        DependencyTree_Object* anObject = myTreeMap[ level->second.at( objIter ) ];
+        anObject->setPos( step, verDistance * level->first );
+        step += horDistance;
+    }
+  }
 
+  // draw arrows on scene
+  GEOMUtils::TreeModel::const_iterator j;
+  for( j = myTreeModel.begin(); j != myTreeModel.end(); j++ ) {
+    DependencyTree_Object* Main_object = myTreeMap[ j->first ];
+    if( j->second.first.size() > 0 ) {
+      GEOMUtils::LevelInfo Levelup = j->second.first.at(0);
+      if( myDisplayAscendants ->isChecked() ) {
+        GEOMUtils::LevelInfo::const_iterator node;
+        for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
+          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 );
+        }
+      }
+    }
+    if( myDisplayAscendants->isChecked() )
+      drawWardArrows( j->second.first );
+    if( myDisplayDescendants->isChecked() )
+      drawWardArrows( j->second.second );
+  }
+  std::cout << "\n ComputedCost = " << myComputedCost << std::endl;
+  fitAll( true );
 }
 
-void DependencyTree_View::timerEvent(QTimerEvent *event)
+int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
 {
-  if ( !cancelButton->isChecked() ) // not yet cancelled
-   // progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
-         progressBar->setValue( iter++ );
-
-  if(!myIsCompute || qthread->isFinished())
-  {
-         cancelAction->setVisible( false );
-         progressAction->setVisible(false);
-         cancelButton->setText( tr("CANCEL"));
-         cancelButton->setEnabled(true);
-         myNodesMovable->setEnabled( true );
-         myHierarchyDepth->setEnabled( true );
-         myDisplayAscendants->setEnabled( true );
-         myDisplayDescendants->setEnabled( true );
-  }
+  GraphicsView_ViewPort::select( theRect, theIsAppend );
 
-  event->accept();
-}
+  mySelectionMgr->clearSelected();
 
-void DependencyTree_View::closeEvent(QCloseEvent *event)
-{
-  if(qthread->isRunning())
-  {
-      event->ignore();
-      return;
+  // 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 );
     }
-  event->accept();
+  mySelectionMgr->setSelectedObjects( listIO, true );
 }
 
-void DependencyTree_View::setIsCompute( bool theIsCompute )
+void DependencyTree_View::mouseMoveEvent(QMouseEvent *event)
 {
-  myIsCompute = theIsCompute;
+  QGraphicsView::mouseMoveEvent( event );
+  ArrowsInfo::const_iterator j;
+  for (j = myArrows.begin(); j != myArrows.end(); j++ ) {
+    DependencyTree_Arrow* arrow = myArrows[ j->first ];
+    arrow->update();
+  }
 }
 
 void DependencyTree_View::setHierarchyType( const int theType )
@@ -644,6 +276,9 @@ void DependencyTree_View::setHierarchyType( const int theType )
     break;
   }
   myIsUpdate = true;
+
+  myLevelsNumber = checkMaxLevelsNumber();
+
   onHierarchyType();
 }
 
@@ -665,7 +300,7 @@ void DependencyTree_View::setPrefBackgroundColor( const QColor& theColor )
 
 void DependencyTree_View::setNodeColor( const QColor& theColor )
 {
-  std::map<std::string,DependencyTree_Object*>::const_iterator i;
+  EntryObjectMap::const_iterator i;
   for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
     DependencyTree_Object* object = myTreeMap[ i->first ];
     object->setColor( theColor );
@@ -674,7 +309,7 @@ void DependencyTree_View::setNodeColor( const QColor& theColor )
 
 void DependencyTree_View::setMainNodeColor( const QColor& theColor )
 {
-         std::map<std::string,DependencyTree_Object*>::const_iterator i;
+  EntryObjectMap::const_iterator i;
   for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
     DependencyTree_Object* object = myTreeMap[ i->first ];
     object->setMainObjectColor( theColor );
@@ -683,7 +318,7 @@ void DependencyTree_View::setMainNodeColor( const QColor& theColor )
 
 void DependencyTree_View::setSelectNodeColor( const QColor& theColor )
 {
-         std::map<std::string,DependencyTree_Object*>::const_iterator i;
+  EntryObjectMap::const_iterator i;
   for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
     DependencyTree_Object* object = myTreeMap[ i->first ];
     object->setSelectColor( theColor );
@@ -692,60 +327,354 @@ void DependencyTree_View::setSelectNodeColor( const QColor& theColor )
 
 void DependencyTree_View::setArrowColor( const QColor& theColor )
 {
-  std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
-  for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
-    DependencyTree_Arrow* arrow = Arrows[ j->first ];
+  ArrowsInfo::const_iterator j;
+  for (j = myArrows.begin(); j != myArrows.end(); j++ ) {
+    DependencyTree_Arrow* arrow = myArrows[ j->first ];
     arrow->setColor( theColor );
   }
 }
 
 void DependencyTree_View::setHighlightArrowColor( const QColor& theColor )
 {
-         std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
-  for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
-    DependencyTree_Arrow* arrow = Arrows[ j->first ];
+       ArrowsInfo::const_iterator j;
+  for (j = myArrows.begin(); j != myArrows.end(); j++ ) {
+    DependencyTree_Arrow* arrow = myArrows[ j->first ];
     arrow->setHighlightColor( theColor );
   }
 }
 
 void DependencyTree_View::setSelectArrowColor( const QColor& theColor )
 {
-         std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>, DependencyTree_Arrow* >::const_iterator j;
-  for (j = Arrows.begin(); j != Arrows.end(); j++ ) {
-    DependencyTree_Arrow* arrow = Arrows[ j->first ];
+       ArrowsInfo::const_iterator j;
+  for (j = myArrows.begin(); j != myArrows.end(); j++ ) {
+    DependencyTree_Arrow* arrow = myArrows[ j->first ];
     arrow->setSelectColor( theColor );
   }
 }
 
-int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
+void DependencyTree_View::setIsCompute( bool theIsCompute )
+{
+  myIsCompute = theIsCompute;
+}
+
+bool DependencyTree_View::getIsCompute()
+{
+  return myIsCompute;
+}
+
+void DependencyTree_View::timerEvent(QTimerEvent *event)
 {
-       GraphicsView_ViewPort::select( theRect, theIsAppend );
+  QPushButton* cancelButton = dynamic_cast<QPushButton*>( cancelAction->defaultWidget() );
+  QProgressBar* progressBar = dynamic_cast<QProgressBar*>( progressAction->defaultWidget() );
 
-    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  std::cout << "TIMER! " << std::endl;
+  if ( !cancelButton->isChecked() )
+    progressBar->setValue( progressBar->maximum() * getComputeProgress() );
 
-    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  if( !myIsCompute || qthread->isFinished() ) {
+    changeWidgetState( false );
+    killTimer( myTimer );
+    cancelButton->setChecked( false );
+    progressBar->setValue(0);
+  }
+  event->accept();
+}
 
-    // get selection
-    SALOME_ListIO listIO;
-aSelMgr->clearSelected();
-    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
-    SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( study->studyDS());
-    int StudyId = aStudyDS->StudyId();
-    for( initSelected(); moreSelected(); nextSelected() )
-      if( DependencyTree_Object* aDepObject = dynamic_cast<DependencyTree_Object*>( selectedObject() ) ) {
-          GEOM::_objref_GEOM_BaseObject* object = GeometryGUI::GetGeomGen()->GetObject( StudyId, aDepObject->getEntry().c_str() );
-          CORBA::String_var aChildEntry = object->GetStudyEntry();
-      Handle(SALOME_InteractiveObject) tmpIO =
-        new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO");
-      listIO.Append(tmpIO);
+void DependencyTree_View::closeEvent( QCloseEvent* event )
+{
+  if(qthread->isRunning())
+  {
+    event->ignore();
+    return;
+  }
+  event->accept();
+}
+
+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 )
+{
+  EntryObjectMap::const_iterator i;
+  for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
+    DependencyTree_Object* object = myTreeMap[ i->first ];
+    if( object )
+      object->setMovable( theIsMoveNodes );
+  }
+}
+
+void DependencyTree_View::onHierarchyType()
+{
+  myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
+  if( myHierarchyDepth->value() > checkMaxLevelsNumber() )
+    myHierarchyDepth->setValue( checkMaxLevelsNumber() );
+
+  if( myHierarchyDepth->value() == 0 )
+    myLevelsNumber = myHierarchyDepth->maximum();
+  else
+    myLevelsNumber = myHierarchyDepth->value();
+
+  updateView();
+}
+
+void DependencyTree_View::onCancel()
+{
+  qthread->cancel();
+  //qthread->deleteLater();
+}
+
+void DependencyTree_View::addNode( const std::string& theEntry )
+{
+  if( !myTreeMap[theEntry] )
+    myTreeMap[theEntry] = new DependencyTree_Object( theEntry );
+}
+
+void DependencyTree_View::addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem )
+{
+  bool isFind = false;
+
+  std::cout << "   " << startItem->getEntry() << "   " << endItem->getEntry() << std::endl;
+  ArrowsInfo::const_iterator i;
+  for (i = myArrows.begin(); i != myArrows.end(); i++ ) {
+         DependencyTree_Arrow* arrow = i->second;
+    if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem ) {
+      isFind = true;
+      std::cout<<" theSame " << std::endl;
+    }
+    else if( arrow->getStartItem() == endItem && arrow->getEndItem() == startItem ) {
+      arrow->setIsBiLink( true );
+      std::cout<<" Bilink " << std::endl;
+      isFind = true;
+    }
+  }
+
+  if( !isFind ) {
+         DependencyTree_Arrow *arrow = new DependencyTree_Arrow(startItem, endItem);
+           myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>( startItem, endItem )] = arrow;
+           std::cout<<" addArrow " << std::endl;
+  }
+}
+
+void DependencyTree_View::parseTree()
+{
+
+  GEOMUtils::TreeModel::const_iterator i;
+  for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
+    std::string objectEntry = i->first;
+    addNode( objectEntry );
+    parseTreeWard( i->second.first );
+    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();
+  }
+
+  for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
+    DependencyTree_Object* Main_object = myTreeMap[i->first];
+    if( i->second.first.size() > 0 ) {
+      GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
+      GEOMUtils::LevelInfo::const_iterator node;
+      for (node = Levelup.begin(); node != Levelup.end(); node++ ) {
+        DependencyTree_Object* object = myTreeMap[node->first];
+        addArrow( Main_object, object );
       }
-  aSelMgr->setSelectedObjects( listIO, true );
+    }
+    parseTreeWardArrow( i->second.first );
+    parseTreeWardArrow( i->second.second );
+  }
+
+
+}
+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::drawWard( const GEOMUtils::LevelsList& theWard,
+                                    std::map< std::string, int >& theEntryLevelMap,
+                                    std::map< int, std::vector< std::string > >& theLevelObjects,
+                                    int theCurrentLevel, const int theLevelStep )
+{
+  for( int level = 0; level < theWard.size(); level++ ) {
+    if( level >= myLevelsNumber || !myIsCompute )
+      return;
+    myComputedCost++;
+    sleep(1);
+    theCurrentLevel += theLevelStep;
+    GEOMUtils::LevelInfo levelInfo = theWard.at( level );
+    GEOMUtils::LevelInfo::const_iterator node;
+    for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
+      DependencyTree_Object* object = myTreeMap[ node->first ];
+      if( !isItemAdded( object ) ) {
+        addItem( object );
+        object->unselect();
+        theEntryLevelMap[ node->first ] = theCurrentLevel;
+        theLevelObjects[ theCurrentLevel ].push_back( node->first );
+      }
+    }
+  }
+}
+
+void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
+{
+  for(int j = 0; j < theWard.size(); j++ ) {
+    if( j >= myLevelsNumber || !myIsCompute )
+      break;
+    myComputedCost++;
+    sleep(1);
+    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];
+      GEOMUtils::NodeLinks Links = node->second;
+      for( int link = 0; link < Links.size(); link++ ) {
+        DependencyTree_Object* LinkObject = myTreeMap[Links[link]];
+        if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
+          DependencyTree_Arrow* arrow = myArrows[std::pair<DependencyTree_Object*,DependencyTree_Object*>(object, LinkObject)];
+          if( arrow && !isItemAdded( arrow) )
+            addItem( arrow );
+        }
+      }
+    }
+  }
+}
+
+void DependencyTree_View::getNewTreeModel()
+{
+  clearView( true );
+
+  SALOME_ListIO aSelList;
+  mySelectionMgr->selectedObjects( aSelList );
+
+  // create a list of selected object entry
+  GEOM::string_array_var objectsEntry = new GEOM::string_array();
+  objectsEntry->length( aSelList.Extent());
+  int iter = 0;
+  for ( SALOME_ListIteratorOfListIO It( aSelList ); 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();
+  }
+
+  // get string which describes dependency tree structure
+  SALOMEDS::TMPFile_var SeqFile =
+    GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, objectsEntry );
+  char* buf = (char*) &SeqFile[0];
+
+  std::cout << "\n\n\n\n\n TREE = " << buf << std::endl;
+
+  // get dependency tree structure
+  GEOMUtils::ConvertStringToTree( buf, myTreeModel );
+
+  mySelectionMgr->clearSelected();
+
+  parseTree();
+
 }
 
-//================================================================================
-//================================================================================
+void DependencyTree_View::clearView( bool isClearModel )
+{
+  EntryObjectMap::const_iterator objectIter;
+  for( objectIter = myTreeMap.begin(); objectIter != myTreeMap.end(); objectIter++ ) {
+    DependencyTree_Object* object = objectIter->second;
+    if( isItemAdded( object ) && object )
+      removeItem( object );
+  }
+
+  ArrowsInfo::const_iterator arrowIter;
+  for( arrowIter = myArrows.begin(); arrowIter != myArrows.end(); arrowIter++ ) {
+    DependencyTree_Arrow* object = arrowIter->second;
+    if( isItemAdded( object ) && object )
+      removeItem( object );
+  }
+  if( isClearModel ) {
+    myTreeMap.clear();
+    myArrows.clear();
+    myTreeModel.clear();
+    myMaxDownwardLevelsNumber = 0;
+    myMaxUpwardLevelsNumber = 0;
+    myLevelsNumber = 0;
+    myIsCompute = true;
+    myIsUpdate = true;
+  }
+}
 
-DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread(DependencyTree_View* theView)
+int DependencyTree_View::checkMaxLevelsNumber()
+{
+  if( myDisplayAscendants->isChecked() && myDisplayDescendants->isChecked() )
+    return myMaxUpwardLevelsNumber>myMaxDownwardLevelsNumber?myMaxUpwardLevelsNumber:myMaxDownwardLevelsNumber;
+  else if( myDisplayAscendants ->isChecked() )
+    return myMaxUpwardLevelsNumber;
+  else if( myDisplayDescendants->isChecked() )
+    return  myMaxDownwardLevelsNumber;
+}
+
+void DependencyTree_View::calcTotalCost()
+{
+  myTotalCost = myTreeModel.size();
+  GEOMUtils::TreeModel::const_iterator i;
+  for( i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
+    if( myDisplayAscendants->isChecked() )
+      myTotalCost += 2*( myLevelsNumber < i->second.first.size() ? myLevelsNumber : i->second.first.size() );
+    if( myDisplayDescendants->isChecked() )
+      myTotalCost += 2*( myLevelsNumber < i->second.second.size() ? myLevelsNumber : i->second.second.size() );
+  }
+}
+
+double DependencyTree_View::getComputeProgress()
+{
+  return double( myComputedCost ) / double( myTotalCost );
+}
+
+void DependencyTree_View::changeWidgetState( bool theIsCompute )
+{
+  cancelAction->setVisible( theIsCompute );
+  progressAction->setVisible( theIsCompute );
+
+  myHierarchyDepth->setEnabled( !theIsCompute );
+  myDisplayAscendants->setEnabled( !theIsCompute );
+  myDisplayDescendants->setEnabled( !theIsCompute );
+}
+
+DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread( DependencyTree_View* theView )
 {
   myView = theView;
 }
@@ -753,7 +682,7 @@ DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread(DependencyT
 void DependencyTree_ComputeDlg_QThread::run()
 {
   myView->setIsCompute( true );
-  myView->onRedrawTree();
+  myView->drawTree();
 }
 
 bool DependencyTree_ComputeDlg_QThread::result()
@@ -765,81 +694,3 @@ void DependencyTree_ComputeDlg_QThread::cancel()
 {
   myView->setIsCompute( false );
 }
-
-////================================================================================
-////================================================================================
-//
-//DependencyTree_ComputeDlg_QThreadQDialog::DependencyTree_ComputeDlg_QThreadQDialog(QWidget* parent,
-//             DependencyTree_View* theView)
-//  : QDialog(parent,
-//            Qt::WindowSystemMenuHint |
-//            Qt::WindowCloseButtonHint |
-//            Qt::Dialog |
-//            Qt::WindowMaximizeButtonHint),
-//    qthread( theView )
-//{
-//  // --
-//  setWindowTitle(tr("TITLE"));
-//  setMinimumWidth( 200 );
-//
-//  cancelButton = new QPushButton(tr("CANCEL"));
-//  cancelButton->setDefault(true);
-//  cancelButton->setCheckable(true);
-//
-//  progressBar  = new QProgressBar(this);
-//  progressBar->setMinimum( 0 );
-//  progressBar->setMaximum( 1000 );
-//
-//  QGridLayout* layout = new QGridLayout(this);
-//  layout->setMargin( 11 );
-//  layout->setSpacing( 6 );
-//  int row = 0;
-//  layout->addWidget(progressBar,  row++, 0, 1, 2);
-//  layout->addWidget(cancelButton, row++, 0, 1, 2);
-//  adjustSize();
-//  update();
-//
-//  connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
-//  // --
-//  startTimer(300); // millisecs
-//  qthread.start();
-//}
-//
-//bool DependencyTree_ComputeDlg_QThreadQDialog::result()
-//{
-//  return qthread.result();
-//}
-//
-//void DependencyTree_ComputeDlg_QThreadQDialog::onCancel()
-//{
-//  qthread.cancel();
-//  cancelButton->setText( tr("CANCELING"));
-//  cancelButton->setEnabled(false);
-//}
-//
-//void DependencyTree_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
-//{
-//  if ( !cancelButton->isChecked() ) // not yet cancelled
-//   // progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
-//       progressBar->setValue( 10 );
-//
-//  if(qthread.isFinished())
-//  {
-//    close();
-//  }
-//
-//  event->accept();
-//}
-//
-//void DependencyTree_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
-//{
-//  if(qthread.isRunning())
-//  {
-//      event->ignore();
-//      return;
-//    }
-//  event->accept();
-//}
-//
-
-
index 19c5d0b23a1fef91082979012471135d595378db..a640462ca4cb5ce39d5fb5a0ff4d2acc71597636 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <GraphicsView_ViewPort.h>
 #include <GraphicsView_ViewFrame.h>
+#include <GraphicsView_Scene.h>
+
+#include <SalomeApp_Application.h>
 
 #include <GEOMUtils.hxx>
 
@@ -55,6 +58,9 @@ private:
   DependencyTree_View* myView;
 };
 
+typedef std::map<std::string,DependencyTree_Object*> EntryObjectMap;
+typedef std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>,DependencyTree_Arrow*> ArrowsInfo;
+
 class DependencyTree_View: public GraphicsView_ViewPort
 {
   Q_OBJECT
@@ -64,6 +70,13 @@ public:
   DependencyTree_View( QWidget* = 0 );
   ~DependencyTree_View();
 
+  void init( GraphicsView_ViewFrame* );
+  void updateModel();
+  void drawTree();
+
+  virtual int select( const QRectF&, bool );
+  void mouseMoveEvent(QMouseEvent *event);
+
   void setHierarchyType( const int );
   void setNodesMovable( const bool );
   void setPrefBackgroundColor( const QColor& );
@@ -74,58 +87,48 @@ public:
   void setHighlightArrowColor( const QColor& );
   void setSelectArrowColor( const QColor& );
 
-  virtual int select( const QRectF&, bool );
+  void setIsCompute( bool );
+  bool getIsCompute();
 
-//  typedef QList<QString> NodeLinks;
-//  typedef QMap<QString, NodeLinks> LevelInfo;
-//  typedef QList<LevelInfo> LevelsList;
-//  typedef QMap<QString,QPair<LevelsList,LevelsList> > TreeModel;
-
-  GEOMUtils::TreeModel myTreeModel;
-  std::map<std::string,DependencyTree_Object*> myTreeMap;
-  std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>,DependencyTree_Arrow*> Arrows;
-
-  std::map<std::string,int> myLevelMap;
-
-  std::map< int, std::vector<std::string> > myLevelsObject;
-  int myCurrentLevel;
-
-  void init( GraphicsView_ViewFrame* );
-
-  void onRedrawTree();
+protected:
+  void timerEvent( QTimerEvent* );
+  void closeEvent( QCloseEvent* );
 
-  void setIsCompute( bool theIsCompute );
-  bool getIsCompute() { return myIsCompute; };
 private slots:
-  void onUpdateTree();
   void updateView();
   void onMoveNodes( bool );
   void onHierarchyType();
-
-protected:
-  void timerEvent(QTimerEvent *timer);
-  void closeEvent(QCloseEvent *event);
-
-private slots:
   void onCancel();
 
+signals:
+
 private:
-//  void parseData( QString& data );
+
+  void addNode( const std::string& );
+  void addArrow( DependencyTree_Object*, DependencyTree_Object* );
 
   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 findArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem );
-//  GEOMUtils::LevelsList parseWard( const QString& data, int& cursor );
-  void drawTree();
-  void drawWard( GEOMUtils::LevelsList ward, const int levelStep );
-  void drawArrows();
+  void drawWard( const GEOMUtils::LevelsList&, std::map< std::string, int >&,
+                 std::map< int, std::vector< std::string > >&, int, const int );
   void drawWardArrows( GEOMUtils::LevelsList );
 
+  void getNewTreeModel();
+  void clearView( bool );
+
   int checkMaxLevelsNumber();
+  void calcTotalCost();
+  double getComputeProgress();
+
+  void changeWidgetState( bool );
+
+  GEOMUtils::TreeModel myTreeModel;
+
+  EntryObjectMap myTreeMap;
+  ArrowsInfo myArrows;
+
   int myLevelsNumber;
   int myMaxDownwardLevelsNumber;
   int myMaxUpwardLevelsNumber;
@@ -134,23 +137,23 @@ private:
   QSpinBox* myHierarchyDepth;
   QCheckBox* myDisplayAscendants;
   QCheckBox* myDisplayDescendants;
-
-  std::string myData;
+  QWidgetAction*  cancelAction;
+  QWidgetAction*  progressAction;
 
   int myTimer;
 
   bool myIsUpdate;
 
-  GraphicsView_ViewFrame* myViewFrame;
-
   bool myIsCompute;
+
+  int myTotalCost;
+  int myComputedCost;
+
   DependencyTree_ComputeDlg_QThread* qthread;
-  QPushButton *               cancelButton;
-  QProgressBar*               progressBar;
-  QWidgetAction*  cancelAction;
-  QWidgetAction*  progressAction;
 
-  //SALOMEDS::Study_var myStudy;
+
+  SALOMEDS::Study_var myStudy;
+  LightApp_SelectionMgr* mySelectionMgr;
 
 };