Salome HOME
19c5d0b23a1fef91082979012471135d595378db
[modules/geom.git] / src / DependencyTree / DependencyTree_View.h
1 // Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef DEPENDENCYTREE_VIEW_H
21 #define DEPENDENCYTREE_VIEW_H
22
23 #include <GraphicsView_ViewPort.h>
24 #include <GraphicsView_ViewFrame.h>
25
26 #include <GEOMUtils.hxx>
27
28 #include <QWidgetAction>
29 #include <QPushButton>
30 #include <QSpinBox>
31 #include <QCheckBox>
32 #include <QProgressBar>
33 #include <QThread>
34
35 class DependencyTree_Object;
36 class DependencyTree_Arrow;
37 class DependencyTree_View;
38
39 class DependencyTree_ComputeDlg_QThread : public QThread
40 {
41   Q_OBJECT
42
43 public:
44
45   DependencyTree_ComputeDlg_QThread( DependencyTree_View* );
46   bool result();
47   void cancel();
48
49   DependencyTree_View*   getView() { return myView; };
50
51 protected:
52   void run();
53
54 private:
55   DependencyTree_View* myView;
56 };
57
58 class DependencyTree_View: public GraphicsView_ViewPort
59 {
60   Q_OBJECT
61
62 public:
63
64   DependencyTree_View( QWidget* = 0 );
65   ~DependencyTree_View();
66
67   void setHierarchyType( const int );
68   void setNodesMovable( const bool );
69   void setPrefBackgroundColor( const QColor& );
70   void setNodeColor( const QColor& );
71   void setMainNodeColor( const QColor& );
72   void setSelectNodeColor( const QColor& );
73   void setArrowColor( const QColor& );
74   void setHighlightArrowColor( const QColor& );
75   void setSelectArrowColor( const QColor& );
76
77   virtual int select( const QRectF&, bool );
78
79 //  typedef QList<QString> NodeLinks;
80 //  typedef QMap<QString, NodeLinks> LevelInfo;
81 //  typedef QList<LevelInfo> LevelsList;
82 //  typedef QMap<QString,QPair<LevelsList,LevelsList> > TreeModel;
83
84   GEOMUtils::TreeModel myTreeModel;
85   std::map<std::string,DependencyTree_Object*> myTreeMap;
86   std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>,DependencyTree_Arrow*> Arrows;
87
88   std::map<std::string,int> myLevelMap;
89
90   std::map< int, std::vector<std::string> > myLevelsObject;
91   int myCurrentLevel;
92
93   void init( GraphicsView_ViewFrame* );
94
95   void onRedrawTree();
96
97   void setIsCompute( bool theIsCompute );
98   bool getIsCompute() { return myIsCompute; };
99 private slots:
100   void onUpdateTree();
101   void updateView();
102   void onMoveNodes( bool );
103   void onHierarchyType();
104
105 protected:
106   void timerEvent(QTimerEvent *timer);
107   void closeEvent(QCloseEvent *event);
108
109 private slots:
110   void onCancel();
111
112 private:
113 //  void parseData( QString& data );
114
115   void parseTree();
116   void parseTreeWard(const GEOMUtils::LevelsList);
117   void parseTreeWardArrow(const GEOMUtils::LevelsList);
118
119   void addNode( const std::string& entry );
120   void addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem );
121   void findArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem );
122 //  GEOMUtils::LevelsList parseWard( const QString& data, int& cursor );
123   void drawTree();
124   void drawWard( GEOMUtils::LevelsList ward, const int levelStep );
125   void drawArrows();
126   void drawWardArrows( GEOMUtils::LevelsList );
127
128   int checkMaxLevelsNumber();
129   int myLevelsNumber;
130   int myMaxDownwardLevelsNumber;
131   int myMaxUpwardLevelsNumber;
132
133   QCheckBox* myNodesMovable;
134   QSpinBox* myHierarchyDepth;
135   QCheckBox* myDisplayAscendants;
136   QCheckBox* myDisplayDescendants;
137
138   std::string myData;
139
140   int myTimer;
141
142   bool myIsUpdate;
143
144   GraphicsView_ViewFrame* myViewFrame;
145
146   bool myIsCompute;
147   DependencyTree_ComputeDlg_QThread* qthread;
148   QPushButton *               cancelButton;
149   QProgressBar*               progressBar;
150   QWidgetAction*  cancelAction;
151   QWidgetAction*  progressAction;
152
153   //SALOMEDS::Study_var myStudy;
154
155 };
156
157 #endif