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