itom
Loading...
Searching...
No Matches
AbstractNode.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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 für 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#include <qpair.h>
38#include <qsharedpointer.h>
39#include <qscopedpointer.h>
40
41namespace ito {
42
43class Channel; // forward declaration
44class AbstractNode;
45
46//----------------------------------------------------------------------------------------------------------------------------------
47/* runtime type information enumeration for type of plot
48
49*/
50typedef enum
51{
52 rttiUnknown = 0x0000, //default node type
53 rttiPlotNode = 0x1000, //arbitrary nodes in a tree of graphic nodes
54 rttiFilterNode = 0x2000,
55 rttiPlotNodeDObj = 0x0100,
56 rttiPlotNodePCL = 0x0200,
57 rttiPlotNode1D = 0x0001,
58 rttiPlotNode2D = 0x0002,
59 rttiPlotNode25D = 0x0003,
60 rttiPlotNode3D = 0x0004
61} rttiNodeType;
62
63class ChannelPrivate; //forward declaration
64class AbstractNodePrivate; //forward declaration
65
66//----------------------------------------------------------------------------------------------------------------------------------
78class ITOMCOMMONPLOT_EXPORT Channel
79{
80public:
81
82 /* the UpdateState enumeration defines possible states during the
83 of the sender parameter of a channel.
84
85 Usually, the update state is idle. If a parameter has been changed,
86 its connected channels are set to StateUpdatePending, such that the
87 channel is informed about the upcoming propagation of this changed input
88 parameter. This update information is then recursively propagated to
89 all child nodes (and their child nodes) of the affected node.
90
91 Then, the value of the changed sender parameter is copied via all
92 affected channels to their respective receiver parameters. The state
93 is then changed to StateUpdateReceived.
94
95 The view of affected nodes is then updated once all input channels,
96 whose state has been set to StateUpdatePending is changed to StateUpdateReceived.
97 This guarantees that the real update of the view is only done once all
98 input channels have finished propagating their changed parameters.
99 */
101 {
102 StateIdle,
104 StateUpdateReceived
105 };
106
108
111 Channel();
112
114
118 Channel(AbstractNode *sender, ito::Param *senderParam,
119 AbstractNode *receiver, ito::Param *receiverParam);
120
122 virtual ~Channel();
123
125 Channel(const Channel& cpy);
126
128 Channel &operator=(const Channel& rhs);
129
131 AbstractNode* getSender() const;
132
134 AbstractNode* getReceiver() const;
135
137 UpdateState getUpdateState() const;
138
140 /* This is equivalent to QLatin1String(getSender()->getName())
141 */
142 QString getSenderParamName() const;
143
145 /* This is equivalent to QLatin1String(getReceiver()->getName())
146 */
147 QString getReceiverParamName() const;
148
150 /*
151 By propagating updates, the whole sub tree of nodes, which has a direct or indirect channel connection to the sender
152 of this channel is informed about an incoming update.
153
154 Note: this function does not propagate any updated data. It only informs about a future update of data.
155
156 \return ito::retOk if the update pending flag has been set or if it was already set. Returns ito::retError if an error occurred.
157 */
158 RetVal propagateUpdatePending();
159
161 RetVal setUpdateReceived();
162
164 uint getHash() const;
165
167 ito::Param * getSenderParam() const;
168
170 ito::Param * getReceiverParam() const;
171
173 void resetUpdateState(void);
174
176 bool isSender(const AbstractNode *node) const;
177
179 bool isReceiver(const AbstractNode *node) const;
180
181 //----------------------------------------------------------------------------------------------------------------------------------
183 static uint calcChannelHash(const AbstractNode *sender,
184 const ito::Param *senderParam,
185 const AbstractNode *receiver,
186 const ito::Param *receiverParam);
187
188private:
189 QScopedPointer<ChannelPrivate> d_ptr;
191};
192
193//----------------------------------------------------------------------------------------------------------------------------------
221class ITOMCOMMONPLOT_EXPORT AbstractNode
222{
223 public:
224
225 typedef QPair<QString, QString> ParamNamePair;
226
228 AbstractNode();
229
231 virtual ~AbstractNode(); //>! will delete the node and all data associated with it, except m_pCurrentData if m_isCurrent is set to TRUE
232
233 virtual RetVal applyUpdate(void) = 0;
238 /* if all channels, whose receiver is this node and that are marked for updates (pending updates),
239 are updated with new values, this method is internally called. It calls applyUpdate, that has to be overwritten
240 by the real plot/figure class, and starts to update all outgoing channels afterwards.
241 */
242 virtual RetVal update(void) = 0;
245 /*
246 If the channel is created, it is appended to the channel list of this node and also attached to the channel list of the receiver node.
247
248 \param senderParamName is the output parameter name of this node, that is used as sending parameter
249 \param receiver is the receiver node
250 \param receiverParamName is the input parameter of the receiver, that is used as destination for the channel.
251 \param replaceChannelIfExists defines if an existing channel with the same sender / receiver combination should be destroyed and created again or if
252 the existing channel is kept without creating the new one.
253
254 \seealso attachChannel
255 */
256 RetVal createChannel(const QString &senderParamName, AbstractNode *receiver, const QString &receiverParamName, bool replaceChannelIfExists = false);
257
259 /*
260 \seealso detachChannel
261 */
262 RetVal removeChannel(QSharedPointer<Channel> channel);
263
265 /*
266 @excludedConnections can be an optional pair of two strings, where the first string is the name of the sender parameter and the 2nd string the name of the receiver parameter.
267 If channels to the given receiver are found, that match to one entry in excludedConnections, they will not be removed.
268 */
269 RetVal removeAllChannelsToReceiver(const AbstractNode *receiver, QList<ParamNamePair> excludedConnections = QList<ParamNamePair>());
270
272 QList<QSharedPointer<Channel> > getConnectedInputChannels(const QString &inputParamName) const;
273
275 QList<QSharedPointer<Channel> > getConnectedInputChannels(const ito::Param *inputParam) const;
276
278 QList<QSharedPointer<Channel> > getConnectedOutputChannels(const QString &outputParamName) const;
279
281 QList<QSharedPointer<Channel> > getConnectedOutputChannels(const ito::Param *outputParam) const;
282
284 /* This method has to copy the new value to the receiver and continue the recursive update to other child nodes.
285 */
286 RetVal updateChannelData(QSharedPointer<Channel> updatedChannel);
287
289 /*
290 if the parameter singleOutputChannel is a null object, this method calls Channel::propagateUpdatePending to
291 all channels, whose sender is this node. Else, the propagateUpdatePending method is only called for the
292 one singleOutputChannel.
293
294 \return ito::retError if singleOutputChannel is valid, however not part of the current output channels of this node. Else: ito::retOk.
295 */
296 RetVal setUpdatePending(QSharedPointer<ito::Channel> singleOutputChannel = QSharedPointer<ito::Channel>());
297
299 ito::Param* getInputParam(const QString &paramName) const;
300
302 ito::Param* getOutputParam(const QString &paramName) const;
303
305 /* This node takes the ownership of the parameter and deletes it during the destructor.
306 */
307 RetVal addOutputParam(ito::Param* param);
308
311 RetVal removeAndDeleteOutputParam(const QString &paramName);
312
314 /* This node takes the ownership of the parameter and deletes it during the destructor.
315 */
316 RetVal addInputParam(ito::Param* param);
317
320 RetVal removeAndDeleteInputParam(const QString &paramName);
321
323 /* If one or multiple output parameters of a node have been changed, call this method to let the changes
324 be propagated to the receiver parameters of all channels, whose sender is this node and whose sender parameter
325 is equal to the given names.
326 */
327 RetVal updateChannels(const QList<QString> &outputParamNames);
328
330 rttiNodeType getType() const;
331
333 bool isConnected() const;
334
336 unsigned int getUniqueID(void) const;
337
338 protected:
340 /*
341 This method does not detach this channel from the other node, that is sender or receiver of the channel.
342 */
343 RetVal detachChannel(QSharedPointer<Channel> channel);
344
346 RetVal attachChannel(QSharedPointer<Channel> channel);
347
349 RetVal inputParamChanged(const ito::ParamBase *updatedInputParam);
353 static unsigned int UID;
354
355 private:
356 QScopedPointer<AbstractNodePrivate> d_ptr;
358};
359
360//----------------------------------------------------------------------------------------------------------------------------------
361} // namespace ito
362
363#endif //ABSTRACTNODE_H
Every plot designer plugin in itom, that should be able to open dependent sub-plots (e....
Definition AbstractNode.h:222
static unsigned int UID
highest used UID of any node. This value is auto-incremented upon every
Definition AbstractNode.h:353
Q_DECLARE_PRIVATE(AbstractNode)
virtual RetVal update(void)=0
update of this node if the values of all changed input channels are propagated to the corresponding i...
A channel defines a propagation pipeline between two parameters of two nodes. The nodes are instances...
Definition AbstractNode.h:79
Q_DECLARE_PRIVATE(Channel)
UpdateState
Definition AbstractNode.h:101
@ StateUpdatePending
the channel is in an idle state (default)
Definition AbstractNode.h:103
<
Definition param.h:95
class for parameter handling e.g. to pass parameters to plugins
Definition param.h:477
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40