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