Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / LinkMatrix.hxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
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.
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 #ifndef _LINKMATRIX_HXX_
20 #define _LINKMATRIX_HXX_
21
22 #include <vector>
23 #include <set>
24 #include <map>
25 #include <list>
26
27 namespace YACS
28 {
29   namespace ENGINE
30   {
31     class OutPort;
32     class InPort;
33     class OutGate;
34     class InGate;
35   }
36
37   namespace HMI
38   {
39     class AbstractSceneItem;
40     class SceneItem;
41     class SceneComposedNodeItem;
42     class SceneLinkItem;
43     class QtGuiContext;
44
45     class LNode
46     {
47     public:
48       LNode(int x, int y) : _x(x), _y(y) {};
49       LNode(std::pair<int,int> m) : _x(m.first), _y(m.second) {};
50       virtual ~LNode() {};
51       inline int getX() const {return _x; };
52       inline int getY() const {return _y; };
53       inline std::pair<int,int> getPos() const { return std::pair<int,int>(_x, _y); };
54       inline bool isEqual(const LNode& o) const { return ((_x == o._x) && (_y == o._y)); };
55       double distance(const LNode& o) const;
56     protected:
57       int _x;
58       int _y;
59     };
60
61     typedef std::list<LNode> LNodePath;
62
63     struct linkdef
64     {
65       std::pair<int,int> from;
66       std::pair<int,int> to;
67       YACS::HMI::SceneLinkItem* item;
68     };
69
70     struct linkPoint
71     {
72       double x;
73       double y;
74     };
75
76     typedef  std::list<linkPoint> LinkPath;
77
78     class LinkMatrix
79     {
80     public:
81       LinkMatrix(SceneComposedNodeItem* bloc);
82       virtual ~LinkMatrix();
83       void compute();
84       void explore(AbstractSceneItem *child, bool setObstacle=false);
85       void defineCost(AbstractSceneItem *child);
86       void getBoundingBox(SceneItem *obstacle, int margin, bool setObstacle=false);
87       std::pair<int,int> cellFrom(YACS::ENGINE::OutPort* outp);
88       std::pair<int,int> cellFrom(YACS::ENGINE::OutGate* outp);
89       std::pair<int,int> cellTo(YACS::ENGINE::InPort* inp);
90       std::pair<int,int> cellTo(YACS::ENGINE::InGate* inp);
91       std::list<linkdef> getListOfCtrlLinkDef();
92       std::list<linkdef> getListOfDataLinkDef();
93       LinkPath getPath(LNodePath lnp);
94
95       int cost(int i, int j) const;
96       inline int imax() const { return _im; };
97       inline int jmax() const { return _jm; };
98       
99     protected:
100       SceneComposedNodeItem* _bloc;
101       int _im;
102       int _jm;
103       std::set<double> _sxm;
104       std::set<double> _sym;
105       std::vector<double> _xm;
106       std::vector<double> _ym;
107       std::map<double,int> _x2i;
108       std::map<double,int> _y2j;
109       std::vector<int> _cost;
110       QtGuiContext* _context;
111     };
112   }
113 }
114
115 #endif