itom 2.2.1
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2016, Institut fuer Technische Optik (ITO), 00005 Universitaet Stuttgart, Germany 00006 00007 This file is part of itom and its software development toolkit (SDK). 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 In addition, as a special exception, the Institut fuer Technische 00015 Optik (ITO) gives you certain additional rights. 00016 These rights are described in the ITO LGPL Exception version 1.0, 00017 which can be found in the file LGPL_EXCEPTION.txt in this package. 00018 00019 itom is distributed in the hope that it will be useful, but 00020 WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00022 General Public Licence for more details. 00023 00024 You should have received a copy of the GNU Library General Public License 00025 along with itom. If not, see <http://www.gnu.org/licenses/>. 00026 *********************************************************************** */ 00027 00028 #ifndef AbstractNode_H 00029 #define AbstractNode_H 00030 00031 #include "plotCommon.h" 00032 #include "../common/sharedStructures.h" 00033 00034 #include <qlist.h> 00035 #include <qobject.h> 00036 #include <qhash.h> 00037 00038 namespace ito { 00039 00040 class Channel; // forward declaration 00041 class AbstractNode; 00042 00043 //---------------------------------------------------------------------------------------------------------------------------------- 00044 ITOMCOMMONPLOT_EXPORT uint calculateChannelHash(AbstractNode *parent, ito::Param *parentParam, AbstractNode *child, ito::Param *childParam); 00045 00046 //---------------------------------------------------------------------------------------------------------------------------------- 00047 typedef enum 00048 { 00049 rttiUnknown = 0x0000, //default node type 00050 rttiPlotNode = 0x1000, //arbitray nodes in a tree of graphic nodes 00051 rttiFilterNode = 0x2000, 00052 rttiPlotNodeDObj = 0x0100, 00053 rttiPlotNodePCL = 0x0200, 00054 rttiPlotNode1D = 0x0001, 00055 rttiPlotNode2D = 0x0002, 00056 rttiPlotNode25D = 0x0003, 00057 rttiPlotNode3D = 0x0004 00058 } rttiNodeType; 00059 00060 00061 //---------------------------------------------------------------------------------------------------------------------------------- 00062 class ITOMCOMMONPLOT_EXPORT Channel 00063 { 00064 public: 00065 enum ChanDirection { 00066 undefined, 00067 parentToChild, 00068 childToParent 00069 }; 00070 private: 00071 static unsigned int UID; 00072 unsigned int m_uniqueID; 00073 AbstractNode* m_pParent; 00074 AbstractNode* m_pChild; 00075 ChanDirection m_direction; 00076 ito::Param* m_pParentParam; 00077 ito::Param* m_pChildParam; 00078 bool m_deleteParentOnDisconnect, m_deleteChildOnDisconnect; 00081 bool m_updatePending; 00082 bool m_channelBuffering; 00083 uint m_hashVal; 00084 00085 public: 00086 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) {} 00087 00088 Channel(AbstractNode *parent, ito::Param *parentParam, bool deleteOnParentDisconnect, AbstractNode *child, ito::Param *childParam, bool deleteOnChildDiconnect, ChanDirection direction, bool update = false); 00089 00090 ~Channel() {} 00091 00092 inline AbstractNode* getParent() const { return m_pParent; } 00093 00094 inline AbstractNode* getChild() const { return m_pChild; } 00095 00096 inline ChanDirection getDirection() const { return m_direction; } 00097 00098 inline bool getUpdatePending() const { return m_updatePending; } 00099 00100 inline unsigned int getUniqueID() const { return m_uniqueID; } 00101 00103 inline ito::Param* getOwnParam(AbstractNode* self) const 00104 { 00105 if(self == m_pParent) 00106 return m_pParentParam; 00107 else if(self == m_pChild) 00108 return m_pChildParam; 00109 else 00110 return NULL; 00111 } 00112 00114 inline ito::Param* getPartnerParam(AbstractNode* self) const 00115 { 00116 if(self == m_pParent) 00117 return m_pChildParam; 00118 else if(self == m_pChild) 00119 return m_pParentParam; 00120 else 00121 return NULL; 00122 } 00123 00124 inline QString getSenderParamName() const 00125 { 00126 if (m_direction == Channel::childToParent) 00127 return QString(m_pChildParam->getName()); 00128 else if (m_direction == Channel::parentToChild) 00129 return QString(m_pParentParam->getName()); 00130 else 00131 return QString(); 00132 } 00133 00134 inline signed char getDeleteBehaviour(AbstractNode* query) const 00135 { 00136 if(query == m_pParent) 00137 return m_deleteParentOnDisconnect; 00138 else if(query == m_pChild) 00139 return m_deleteChildOnDisconnect; 00140 else 00141 return -1; 00142 } 00143 00145 RetVal propagateUpdatePending(); 00146 00147 inline bool getChannelBuffering() const { return m_channelBuffering; } 00148 00149 inline void setChannelBuffering(bool buffering) { m_channelBuffering = buffering; return; } 00150 00152 inline uint getHash() const { return m_hashVal; } 00153 00154 inline ito::Param * getParentParam() const { return m_pParentParam; } 00155 00156 inline ito::Param * getChildParam() const { return m_pChildParam; } 00157 00159 inline void resetUpdatePending(void){ m_updatePending = false;} 00160 00162 inline bool isSender(AbstractNode *query) 00163 { 00164 if (((m_direction == Channel::childToParent) && (m_pChild == query)) 00165 || ((m_direction == Channel::parentToChild) && (m_pParent == query))) 00166 return true; 00167 else 00168 return false; 00169 } 00170 00172 inline bool isReceiver(AbstractNode *query) const 00173 { 00174 if (((m_direction == Channel::childToParent) && (m_pParent == query)) 00175 || ((m_direction == Channel::parentToChild) && (m_pChild == query))) 00176 return true; 00177 else 00178 return false; 00179 } 00180 00182 inline AbstractNode* getSender(void) const 00183 { 00184 if(m_direction == Channel::childToParent) 00185 return m_pChild; 00186 else if (m_direction == Channel::parentToChild) 00187 return m_pParent; 00188 else return NULL; 00189 } 00190 00192 inline AbstractNode* getReceiver(void) const 00193 { 00194 if(m_direction == Channel::childToParent) 00195 return m_pParent; 00196 else if (m_direction == Channel::parentToChild) 00197 return m_pChild; 00198 else return NULL; 00199 } 00200 }; 00201 00202 //---------------------------------------------------------------------------------------------------------------------------------- 00203 class ITOMCOMMONPLOT_EXPORT AbstractNode 00204 { 00205 public: 00206 AbstractNode(); 00207 00208 virtual ~AbstractNode(); //>! will delete the node and all data associated with it, except m_pCurrentData if m_isCurrent is set to TRUE 00209 00210 virtual RetVal applyUpdate(void) = 0; 00213 virtual RetVal update(void) = 0; 00215 RetVal updateParam(const ito::ParamBase *input, int isSource = 0); 00218 RetVal updateParam(const QHash<QString, ito::ParamBase*> *inputs) 00219 { 00220 ito::RetVal retval = ito::retOk; 00221 00222 foreach (const ito::ParamBase *thisParam, *inputs) 00223 { 00224 retval += updateParam(thisParam); 00225 if (retval.containsError()) 00226 return retval; 00227 } 00228 return retval; 00229 } 00230 00231 inline rttiNodeType getType() const { return m_NodeType; } 00232 00235 virtual RetVal addChannel(AbstractNode *child, ito::Param* parentParam, ito::Param* childParam, Channel::ChanDirection direction, bool deleteOnParentDisconnect, bool deleteOnChildDisconnect) = 0; 00236 virtual RetVal addChannel(Channel *newChannel) = 0; 00237 00238 virtual RetVal removeChannelFromList(unsigned int UniqueID) = 0; 00239 virtual RetVal removeChannel(Channel *delChannel) = 0; 00240 00241 RetVal getUpdateStatus(void) const; 00242 00243 RetVal updateChannels(const QList<QString> ¶mNames); 00244 00245 inline bool isConnected() const { return !(m_pChannels.isEmpty()); } 00246 00247 inline int getUniqueID(void) const { return m_uniqueID; } 00248 00249 RetVal setUpdatePending(int uniqueID = -1); 00250 00251 Channel * getInputChannel(const char *inpParamName) const; 00252 00253 inline ito::Param* getInputParam(const QString ¶mName) const 00254 { 00255 if (m_pInput.contains(paramName)) 00256 { 00257 return m_pInput[paramName]; 00258 } 00259 return NULL; 00260 } 00261 00262 inline ito::Param* getOutputParam(const QString ¶mName) const 00263 { 00264 if (m_pOutput.contains(paramName)) 00265 { 00266 return m_pOutput[paramName]; 00267 } 00268 return NULL; 00269 } 00270 00271 protected: 00272 rttiNodeType m_NodeType; 00273 QHash<QString, ito::Param*> m_pInput; 00274 QHash<QString, ito::Param*> m_pOutput; 00275 QHash<unsigned int, Channel*> m_pChannels; 00276 00277 int m_uniqueID; 00278 static unsigned int UID; 00279 }; 00280 00281 //---------------------------------------------------------------------------------------------------------------------------------- 00282 } // namespace ito 00283 00284 #endif