Salome HOME
4c1b86e8d6d26c60c425e629ca56755a9d58603b
[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 #include <GraphicsView_Scene.h>
26
27 #include <SalomeApp_Application.h>
28
29 #include <SALOME_ListIO.hxx>
30
31 #include <GEOMUtils.hxx>
32 #include <GEOM_InteractiveObject.hxx>
33 #include <GeometryGUI.h>
34
35
36 #include <QWidgetAction>
37 #include <QPushButton>
38 #include <QSpinBox>
39 #include <QCheckBox>
40 #include <QProgressBar>
41 #include <QThread>
42 #include <QMutex>
43
44 class DependencyTree_Object;
45 class DependencyTree_Arrow;
46 class DependencyTree_View;
47
48 class DependencyTree_ComputeDlg_QThread : public QThread
49 {
50   Q_OBJECT
51
52 public:
53
54   DependencyTree_ComputeDlg_QThread( DependencyTree_View* );
55   void sleepDraw();
56   void cancel();
57
58   DependencyTree_View*   getView() { return myView; };
59
60 protected:
61   void run();
62
63 private:
64   DependencyTree_View* myView;
65 };
66
67 typedef std::map<std::string,DependencyTree_Object*> EntryObjectMap;
68 typedef std::map<std::pair<DependencyTree_Object*,DependencyTree_Object*>,DependencyTree_Arrow*> ArrowsInfo;
69
70 class DependencyTree_View: public GraphicsView_ViewPort
71 {
72   Q_OBJECT
73
74 public:
75
76   DependencyTree_View( QWidget* = 0 );
77   ~DependencyTree_View();
78
79   void init( GraphicsView_ViewFrame* );
80   void updateModel( bool = true, bool = true );
81   void drawTree();
82
83   virtual void customEvent ( QEvent* );
84   void mouseMoveEvent(QMouseEvent *event);
85
86   DependencyTree_Object* getObjectByEntry( QString );
87
88   void setHierarchyType( const int );
89   void setNodesMovable( const bool );
90   void setPrefBackgroundColor( const QColor& );
91   void setNodeColor( const QColor& );
92   void setMainNodeColor( const QColor& );
93   void setSelectNodeColor( const QColor& );
94   void setArrowColor( const QColor& );
95   void setHighlightArrowColor( const QColor& );
96   void setSelectArrowColor( const QColor& );
97
98   void setIsCompute( bool );
99   bool getIsCompute();
100
101   bool updateObjectName( const std::string &theEntry );
102
103   QMutex myMutex;
104
105 public slots:
106   void onUpdateModel();
107   void onRebuildModel();
108
109 protected:
110   void closeEvent( QCloseEvent* );
111
112 private slots:
113   void updateView();
114   void onMoveNodes( bool );
115   void onHierarchyType();
116   void onCancel();
117
118 signals:
119
120 private:
121
122   void addNode( const std::string& );
123   void addArrow( DependencyTree_Object*, DependencyTree_Object* );
124   void addNewItem( QGraphicsItem* );
125
126   void parseTree();
127   void parseTreeWard(const GEOMUtils::LevelsList);
128   void parseTreeWardArrow(const GEOMUtils::LevelsList);
129
130   void drawWard( const GEOMUtils::LevelsList&, std::map< std::string, int >&,
131                  std::map< int, std::vector< std::string > >&, int, const int );
132   void drawWardArrows( GEOMUtils::LevelsList );
133
134   void getNewTreeModel( bool = true, bool = true );
135   void clearView( bool );
136
137   int checkMaxLevelsNumber();
138   void calcTotalCost();
139   double getComputeProgress();
140
141   void changeWidgetState( bool );
142
143   GEOMUtils::TreeModel myTreeModel;
144
145   EntryObjectMap myTreeMap;
146   ArrowsInfo myArrows;
147
148   int myLevelsNumber;
149   int myMaxDownwardLevelsNumber;
150   int myMaxUpwardLevelsNumber;
151
152   QCheckBox* myNodesMovable;
153   QSpinBox* myHierarchyDepth;
154   QCheckBox* myDisplayAscendants;
155   QCheckBox* myDisplayDescendants;
156   QWidgetAction*  cancelAction;
157   QWidgetAction*  progressAction;
158   QPushButton* updateButton;
159
160   int myTimer;
161
162   bool myIsUpdate;
163
164   bool myIsCompute;
165
166   int myTotalCost;
167   int myComputedCost;
168
169   DependencyTree_ComputeDlg_QThread* qthread;
170
171   GEOM::string_array_var myMainEntries;
172
173   SALOMEDS::Study_var myStudy;
174   LightApp_SelectionMgr* mySelectionMgr;
175
176
177 };
178
179 #endif