Vuo  2.3.2
VuoRendererPublishedPort.cc
Go to the documentation of this file.
1 
11 
12 #include "VuoCable.hh"
13 #include "VuoCompilerPort.hh"
14 
18 VuoRendererPublishedPort::VuoRendererPublishedPort(VuoPublishedPort *basePublishedPort, bool isPublishedOutput)
19  : VuoRendererPort(basePublishedPort,
20  NULL,
21  // "Published input" ports are *output* ports within the published input node,
22  // and vice versa.
23  !isPublishedOutput,
24  false,
25  false
26  )
27 {
28  this->compositionViewportPos = QPoint();
29  this->isActive = false;
30  this->permanent = false;
31 
32  setFlag(QGraphicsItem::ItemIsSelectable, true);
34 }
35 
40 {
41  getBase()->getClass()->setName(name);
43 }
44 
53 bool VuoRendererPublishedPort::canAccommodateInternalPort(VuoRendererPort *internalPort, bool eventOnlyConnection)
54 {
55  if (! isCompatibleAliasWithSpecializationForInternalPort(internalPort, eventOnlyConnection))
56  return false;
57 
58  // If this is a published output port that already has has a connected data-carrying cable,
59  // it cannot accommodate another data-carrying cable.
60  bool isPublishedOutput = getInput();
61  if (isPublishedOutput && !eventOnlyConnection)
62  {
63  foreach (VuoCable *connectedCable, getBase()->getConnectedCables(true))
64  if (connectedCable->getRenderer()->effectivelyCarriesData() &&
65  connectedCable->getFromNode() &&
66  connectedCable->getToNode())
67  {
68  return false;
69  }
70  }
71 
72  return true;
73 }
74 
89 {
90  // Temporarily disallow direct cable connections between published inputs and published outputs.
91  // @todo: Allow for https://b33p.net/kosada/node/7756 .
92  if (dynamic_cast<VuoRendererPublishedPort *>(internalPort))
93  return false;
94 
95  bool isPublishedInput = !getInput();
96  return (isPublishedInput? canConnectDirectlyWithoutSpecializationTo(internalPort, eventOnlyConnection) :
97  internalPort->canConnectDirectlyWithoutSpecializationTo(this, eventOnlyConnection));
98 }
99 
116 {
117  VuoRendererPort *portToSpecialize = NULL;
118  string specializedTypeName = "";
119 
120  return this->isCompatibleAliasWithSpecializationForInternalPort(internalPort, eventOnlyConnection, &portToSpecialize, specializedTypeName);
121 }
122 
135  bool eventOnlyConnection,
136  VuoRendererPort **portToSpecialize,
137  string &specializedTypeName)
138 {
139  *portToSpecialize = NULL;
140  specializedTypeName = "";
141 
142  if (this->isCompatibleAliasWithoutSpecializationForInternalPort(internalPort, eventOnlyConnection))
143  return true;
144 
145  // Temporarily disallow direct cable connections between published inputs and published outputs.
146  // @todo: Allow for https://b33p.net/kosada/node/7756 .
147  if (dynamic_cast<VuoRendererPublishedPort *>(internalPort))
148  return false;
149 
150  bool isPublishedInput = !getInput();
151  return (isPublishedInput? canConnectDirectlyWithSpecializationTo(internalPort, eventOnlyConnection, portToSpecialize, specializedTypeName) :
152  internalPort->canConnectDirectlyWithSpecializationTo(this, eventOnlyConnection, portToSpecialize, specializedTypeName));
153 }
154 
168 bool VuoRendererPublishedPort::canBeMergedWith(VuoPublishedPort *otherExternalPort, bool mergeWillAddData)
169 {
170  bool thisIsPublishedInput = !getInput();
171 
172  // For these two externally visible published ports to be eligible for merging, they must have the same type.
173  if (!otherExternalPort->hasCompiler() ||
174  (static_cast<VuoCompilerPort *>(otherExternalPort->getCompiler())->getDataVuoType() != this->getDataType()))
175  return false;
176 
177  // If they are input published ports and their types match, go ahead and merge them.
178  if (thisIsPublishedInput)
179  return true;
180 
181  // If they are output published ports and their types match, make sure they will
182  // have no more than one connected data-carrying cable between the two of them.
183  if (!mergeWillAddData)
184  return true;
185 
186  foreach (VuoCable *connectedCable, getBase()->getConnectedCables(true))
187  {
188  if (connectedCable->getRenderer()->effectivelyCarriesData())
189  return false;
190  }
191 
192  return true;
193 }
194 
200 {
201  return compositionViewportPos;
202 }
203 
209 {
210  this->compositionViewportPos = pos;
211 }
212 
218 {
219  this->isActive = active;
220 }
221 
227 {
228  return this->isActive;
229 }
230 
235 {
236  this->permanent = permanent;
237 }
238 
243 {
244  return permanent;
245 }
246 
251 {
252  return QPainterPath();
253 }