itom  3.0.0
AbstractNode.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef AbstractNode_H
29 #define AbstractNode_H
30 
31 #include "plotCommon.h"
32 #include "../common/sharedStructures.h"
33 
34 #include <qlist.h>
35 #include <qobject.h>
36 #include <qhash.h>
37 
38 namespace ito {
39 
40 class Channel; // forward declaration
41 class AbstractNode;
42 
43 //----------------------------------------------------------------------------------------------------------------------------------
44 ITOMCOMMONPLOT_EXPORT uint calculateChannelHash(AbstractNode *parent, ito::Param *parentParam, AbstractNode *child, ito::Param *childParam);
45 
46 //----------------------------------------------------------------------------------------------------------------------------------
47 typedef enum
48 {
49  rttiUnknown = 0x0000, //default node type
50  rttiPlotNode = 0x1000, //arbitray nodes in a tree of graphic nodes
51  rttiFilterNode = 0x2000,
52  rttiPlotNodeDObj = 0x0100,
53  rttiPlotNodePCL = 0x0200,
54  rttiPlotNode1D = 0x0001,
55  rttiPlotNode2D = 0x0002,
56  rttiPlotNode25D = 0x0003,
57  rttiPlotNode3D = 0x0004
58 } rttiNodeType;
59 
60 
61 //----------------------------------------------------------------------------------------------------------------------------------
62 class ITOMCOMMONPLOT_EXPORT Channel
63 {
64  public:
65  enum ChanDirection {
66  undefined,
67  parentToChild,
68  childToParent
69  };
70  private:
71  static unsigned int UID;
72  unsigned int m_uniqueID;
75  ChanDirection m_direction;
78  bool m_deleteParentOnDisconnect, m_deleteChildOnDisconnect;
83  uint m_hashVal;
84 
85  public:
86  Channel() : m_uniqueID(UID++), m_pParent(NULL), m_pChild(NULL), m_direction(Channel::undefined), m_pParentParam(NULL), m_pChildParam(NULL), m_deleteParentOnDisconnect(false), m_deleteChildOnDisconnect(false), m_updatePending(false), m_channelBuffering(false), m_hashVal(0) {}
87 
88  Channel(AbstractNode *parent, ito::Param *parentParam, bool deleteOnParentDisconnect, AbstractNode *child, ito::Param *childParam, bool deleteOnChildDiconnect, ChanDirection direction, bool update = false);
89 
90  ~Channel() {}
91 
92  inline AbstractNode* getParent() const { return m_pParent; }
93 
94  inline AbstractNode* getChild() const { return m_pChild; }
95 
96  inline ChanDirection getDirection() const { return m_direction; }
97 
98  inline bool getUpdatePending() const { return m_updatePending; }
99 
100  inline unsigned int getUniqueID() const { return m_uniqueID; }
101 
103  inline ito::Param* getOwnParam(AbstractNode* self) const
104  {
105  if(self == m_pParent)
106  return m_pParentParam;
107  else if(self == m_pChild)
108  return m_pChildParam;
109  else
110  return NULL;
111  }
112 
115  {
116  if(self == m_pParent)
117  return m_pChildParam;
118  else if(self == m_pChild)
119  return m_pParentParam;
120  else
121  return NULL;
122  }
123 
124  inline QString getSenderParamName() const
125  {
126  if (m_direction == Channel::childToParent)
127  return QString(m_pChildParam->getName());
128  else if (m_direction == Channel::parentToChild)
129  return QString(m_pParentParam->getName());
130  else
131  return QString();
132  }
133 
134  inline signed char getDeleteBehaviour(AbstractNode* query) const
135  {
136  if(query == m_pParent)
137  return m_deleteParentOnDisconnect;
138  else if(query == m_pChild)
139  return m_deleteChildOnDisconnect;
140  else
141  return -1;
142  }
143 
145  RetVal propagateUpdatePending();
146 
147  inline bool getChannelBuffering() const { return m_channelBuffering; }
148 
149  inline void setChannelBuffering(bool buffering) { m_channelBuffering = buffering; return; }
150 
152  inline uint getHash() const { return m_hashVal; }
153 
154  inline ito::Param * getParentParam() const { return m_pParentParam; }
155 
156  inline ito::Param * getChildParam() const { return m_pChildParam; }
157 
159  inline void resetUpdatePending(void){ m_updatePending = false;}
160 
162  inline bool isSender(AbstractNode *query)
163  {
164  if (((m_direction == Channel::childToParent) && (m_pChild == query))
165  || ((m_direction == Channel::parentToChild) && (m_pParent == query)))
166  return true;
167  else
168  return false;
169  }
170 
172  inline bool isReceiver(AbstractNode *query) const
173  {
174  if (((m_direction == Channel::childToParent) && (m_pParent == query))
175  || ((m_direction == Channel::parentToChild) && (m_pChild == query)))
176  return true;
177  else
178  return false;
179  }
180 
182  inline AbstractNode* getSender(void) const
183  {
184  if(m_direction == Channel::childToParent)
185  return m_pChild;
186  else if (m_direction == Channel::parentToChild)
187  return m_pParent;
188  else return NULL;
189  }
190 
192  inline AbstractNode* getReceiver(void) const
193  {
194  if(m_direction == Channel::childToParent)
195  return m_pParent;
196  else if (m_direction == Channel::parentToChild)
197  return m_pChild;
198  else return NULL;
199  }
200 };
201 
202 //----------------------------------------------------------------------------------------------------------------------------------
203 class ITOMCOMMONPLOT_EXPORT AbstractNode
204 {
205  public:
206  AbstractNode();
207 
208  virtual ~AbstractNode(); //>! will delete the node and all data associated with it, except m_pCurrentData if m_isCurrent is set to TRUE
209 
210  virtual RetVal applyUpdate(void) = 0;
213  virtual RetVal update(void) = 0;
215  RetVal updateParam(const ito::ParamBase *input, int isSource = 0);
218  RetVal updateParam(const QHash<QString, ito::ParamBase*> *inputs)
219  {
220  ito::RetVal retval = ito::retOk;
221 
222  foreach (const ito::ParamBase *thisParam, *inputs)
223  {
224  retval += updateParam(thisParam);
225  if (retval.containsError())
226  return retval;
227  }
228  return retval;
229  }
230 
231  inline rttiNodeType getType() const { return m_NodeType; }
232 
235  virtual RetVal addChannel(AbstractNode *child, ito::Param* parentParam, ito::Param* childParam, Channel::ChanDirection direction, bool deleteOnParentDisconnect, bool deleteOnChildDisconnect) = 0;
236  virtual RetVal addChannel(Channel *newChannel) = 0;
237 
238  virtual RetVal removeChannelFromList(unsigned int UniqueID) = 0;
239  virtual RetVal removeChannel(Channel *delChannel) = 0;
240 
241  RetVal getUpdateStatus(void) const;
242 
243  RetVal updateChannels(const QList<QString> &paramNames);
244 
245  inline bool isConnected() const { return !(m_pChannels.isEmpty()); }
246 
247  inline int getUniqueID(void) const { return m_uniqueID; }
248 
249  RetVal setUpdatePending(int uniqueID = -1);
250 
251  Channel * getInputChannel(const char *inpParamName) const;
252 
253  inline ito::Param* getInputParam(const QString &paramName) const
254  {
255  if (m_pInput.contains(paramName))
256  {
257  return m_pInput[paramName];
258  }
259  return NULL;
260  }
261 
262  inline ito::Param* getOutputParam(const QString &paramName) const
263  {
264  if (m_pOutput.contains(paramName))
265  {
266  return m_pOutput[paramName];
267  }
268  return NULL;
269  }
270 
271  protected:
272  rttiNodeType m_NodeType;
273  QHash<QString, ito::Param*> m_pInput;
274  QHash<QString, ito::Param*> m_pOutput;
275  QHash<unsigned int, Channel*> m_pChannels;
276 
278  static unsigned int UID;
279 };
280 
281 //----------------------------------------------------------------------------------------------------------------------------------
282 } // namespace ito
283 
284 #endif
bool m_channelBuffering
tells the receiver to wait for updates before proceeding
Definition: AbstractNode.h:82
ito::Param * m_pChildParam
the parameter-connector on the parentīs side (can be sending or receiving)
Definition: AbstractNode.h:77
unsigned int m_uniqueID
Definition: AbstractNode.h:72
ito::Param * getPartnerParam(AbstractNode *self) const
Definition: AbstractNode.h:114
bool isSender(AbstractNode *query)
Definition: AbstractNode.h:162
bool isReceiver(AbstractNode *query) const
Definition: AbstractNode.h:172
Class for managing status values (like errors or warning)
Definition: retVal.h:54
class for parameter handling e.g. to pass paramters to plugins
Definition: param.h:251
Definition: typeDefs.h:58
Definition: apiFunctionsGraph.cpp:39
Definition: AbstractNode.h:203
int m_uniqueID
>
Definition: AbstractNode.h:277
ito::Param * m_pParentParam
Definition: AbstractNode.h:76
AbstractNode * m_pParent
Definition: AbstractNode.h:73
QHash< QString, ito::Param * > m_pInput
the type of the actual node inheriting this abstract node
Definition: AbstractNode.h:273
AbstractNode * m_pChild
Definition: AbstractNode.h:74
ChanDirection m_direction
Definition: AbstractNode.h:75
uint getHash() const
Definition: AbstractNode.h:152
AbstractNode * getSender(void) const
Definition: AbstractNode.h:182
int containsError() const
Definition: retVal.h:150
const char * getName(void) const
returns parameter name (returned string is no copy, do not delete it)
Definition: param.h:182
bool m_updatePending
Definition: AbstractNode.h:81
uint m_hashVal
marks, if the Receiver has received and is buffering data from a new source
Definition: AbstractNode.h:83
void resetUpdatePending(void)
Definition: AbstractNode.h:159
Definition: param.h:67
QHash< unsigned int, Channel * > m_pChannels
the node&#39;s output parameters
Definition: AbstractNode.h:275
RetVal updateParam(const QHash< QString, ito::ParamBase * > *inputs)
this function must ONLY be used for the root of a tree. Sets several input parameters at once ...
Definition: AbstractNode.h:218
AbstractNode * getReceiver(void) const
Definition: AbstractNode.h:192
bool m_deleteParentOnDisconnect
the parameter-connector on the childīs side (can be sending or receiving)
Definition: AbstractNode.h:78
Definition: AbstractNode.h:62
QHash< QString, ito::Param * > m_pOutput
the node&#39;s input parameters
Definition: AbstractNode.h:274
ito::Param * getOwnParam(AbstractNode *self) const
Definition: AbstractNode.h:103