Vuo  2.3.2
VuoCompilerCable.cc
Go to the documentation of this file.
1 
10 #include <sstream>
11 
12 #include "VuoCable.hh"
13 #include "VuoCompilerCable.hh"
15 #include "VuoCompilerNode.hh"
16 #include "VuoCompilerPortClass.hh"
17 #include "VuoCompilerType.hh"
18 #include "VuoNode.hh"
19 #include "VuoNodeClass.hh"
20 #include "VuoPort.hh"
21 
25 VuoCompilerCable::VuoCompilerCable(VuoCompilerNode * fromNode, VuoCompilerPort * fromPort, VuoCompilerNode * toNode, VuoCompilerPort * toPort, bool addCableToPorts)
26  : VuoBaseDetail<VuoCable>("VuoCompilerCable",
27  new VuoCable( fromNode? fromNode->getBase() : NULL,
28  fromPort? fromPort->getBase() : NULL,
29  toNode? toNode->getBase() : NULL,
30  toPort? toPort->getBase() : NULL,
31  addCableToPorts))
32 {
33  getBase()->setCompiler(this);
34  isAlwaysEventOnly = false;
35  isHidden = false;
36 }
37 
43 {
44  this->isAlwaysEventOnly = isEventOnly;
45 }
46 
52 {
53  return this->isAlwaysEventOnly;
54 }
55 
59 void VuoCompilerCable::setHidden(bool hidden)
60 {
61  this->isHidden = hidden;
62 }
63 
68 {
69  return this->isHidden;
70 }
71 
75 bool VuoCompilerCable::portHasData(VuoPort *port)
76 {
77  return (port &&
79  (port->getClass()->hasCompiler() && static_cast<VuoCompilerPortClass *>(port->getClass()->getCompiler())->getDataVuoType())));
80 }
81 
87 {
88  ostringstream declaration;
89 
90  VuoNode *fromNode = getBase()->getFromNode();
91  VuoPort *fromPort = getBase()->getFromPort();
92  VuoNode *toNode = getBase()->getToNode();
93  VuoPort *toPort = getBase()->getToPort();
94 
95  if ((fromNode || getBase()->isPublishedInputCable())
96  && (toNode || getBase()->isPublishedOutputCable())
97  && fromPort && toPort)
98  {
99  string fromNodeIdentifier = (getBase()->isPublishedInputCable() ?
101  (fromNode->hasCompiler() ?
102  fromNode->getCompiler()->getGraphvizIdentifier() :
103  fromNode->getRawGraphvizIdentifier()));
104  string toNodeIdentifier = (getBase()->isPublishedOutputCable() ?
106  (toNode->hasCompiler() ?
107  toNode->getCompiler()->getGraphvizIdentifier() :
108  toNode->getRawGraphvizIdentifier()));
109 
110  declaration << fromNodeIdentifier << ":" << fromPort->getClass()->getName() << " -> "
111  << toNodeIdentifier << ":" << toPort->getClass()->getName();
112 
113  // Cable attributes
114  bool isExplicitlyEventOnly = (isAlwaysEventOnly && portHasData( getBase()->getFromPort() ) && portHasData( getBase()->getToPort() ));
115  if (isExplicitlyEventOnly || isHidden)
116  {
117  declaration << " [";
118 
119  if (isExplicitlyEventOnly)
120  declaration << "event=true";
121 
122  if (isExplicitlyEventOnly && isHidden)
123  declaration << " ";
124 
125  if (isHidden)
126  declaration << "style=invis";
127 
128  declaration << "]";
129  }
130 
131  declaration << ";";
132  }
133 
134  return declaration.str();
135 }
136 
141 {
142  if (isAlwaysEventOnly)
143  return false;
144 
145  VuoPort *fromPort = getBase()->getFromPort();
146  VuoPort *toPort = getBase()->getToPort();
147 
148  bool fromPortHasData = portHasData(fromPort);
149  bool toPortHasData = portHasData(toPort);
150 
151  // If not currently connected to a 'From' port, decide on the basis of the 'To' port alone.
152  if (! fromPort)
153  return toPortHasData;
154 
155  // If not currently connected to a 'To' port, decide on the basis of the 'From' port alone.
156  else if (! toPort)
157  return fromPortHasData;
158 
159  // If connected at both ends, the cable carries data if and only if each of its connected ports contain data.
160  else
161  return (fromPortHasData && toPortHasData);
162 }
163 
167 void VuoCompilerCable::generateTransmission(Module *module, BasicBlock *block, Value *toNodeContextValue, Value *toPortContextValue,
168  Value *outputDataPointer, bool shouldTransmitEvent)
169 {
170  VuoCompilerInputEventPort *inputEventPort = static_cast<VuoCompilerInputEventPort *>(getBase()->getToPort()->getCompiler());
171 
172  if (outputDataPointer)
173  {
174  outputDataPointer = inputEventPort->getDataType()->convertToPortData(block, outputDataPointer);
175  inputEventPort->generateReplaceData(module, block, toNodeContextValue, outputDataPointer, toPortContextValue);
176  }
177 
178  if (shouldTransmitEvent)
179  inputEventPort->generateStoreEvent(module, block, toNodeContextValue, true, toPortContextValue);
180 }