Vuo  2.0.3
VuoCommandPublishPort.cc
Go to the documentation of this file.
1 
10 #include "VuoCommandPublishPort.hh"
11 #include "VuoCommandCommon.hh"
12 #include "VuoEditorComposition.hh"
13 #include "VuoEditorWindow.hh"
14 
19  VuoRendererCable *displacedCable,
20  VuoEditorWindow *window,
21  bool forceEventOnlyPublication,
22  string publishedPortName,
23  bool attemptMerge)
24  : VuoCommandCommon(window)
25 {
26  setText(QApplication::translate("VuoEditorWindow", "Publish Port"));
27  this->window = window;
28  this->revertedSnapshot = window->getComposition()->takeSnapshot();
29 
30  // Start of command content.
31  VuoPublishedPort *externalPort = NULL;
32  {
33  // Take inventory of required changes.
34  pair<VuoPort *, VuoPublishedPort *> unpublishedPortCombination;
35  map<VuoRendererCable *, VuoPort *> updatedFromPortForCable;
36  map<VuoRendererCable *, VuoPort *> updatedToPortForCable;
37 
38  VuoPort *internalPort = port;
39  bool displacedCableWasPublishedCable = (displacedCable && displacedCable->getBase()->isPublished());
40 
41  if (displacedCable)
42  {
43  if (displacedCableWasPublishedCable)
44  {
45  bool inputCable = displacedCable->getBase()->isPublishedInputCable();
46  VuoPort *toPort = displacedCable->getBase()->getToPort();
47  VuoPort *fromPort = displacedCable->getBase()->getFromPort();
48 
49  VuoPort *internalPublishedPort = (inputCable? toPort : fromPort);
50  VuoPublishedPort *externalPublishedPort = (inputCable?
51  dynamic_cast<VuoPublishedPort *>(fromPort) :
52  dynamic_cast<VuoPublishedPort *>(toPort));
53 
54  unpublishedPortCombination = make_pair(internalPublishedPort, externalPublishedPort);
55  }
56  else
57  {
58  updatedFromPortForCable[displacedCable] = NULL;
59  updatedToPortForCable[displacedCable] = NULL;
60  }
61  }
62 
63  // Now apply required changes.
64  internalPort->getRenderer()->updateGeometry();
65 
66  // Disconnect the displaced cable, if applicable.
67  if (displacedCable)
68  {
69  if (displacedCableWasPublishedCable)
70  {
71  bool unpublishIsolatedExternalPort = false;
72  VuoCommandCommon::unpublishInternalExternalPortCombination(unpublishedPortCombination.first, unpublishedPortCombination.second, window->getComposition(), unpublishIsolatedExternalPort);
73  }
74  else
75  VuoCommandCommon::updateCable(displacedCable, updatedFromPortForCable[displacedCable], updatedToPortForCable[displacedCable], window->getComposition());
76  }
77 
78  // Case: Publishing the port for the first time.
79  if (! externalPort)
80  externalPort = VuoCommandCommon::publishInternalPort(internalPort, forceEventOnlyPublication, publishedPortName, window->getComposition(), attemptMerge);
81 
82  // Case: Re-doing port publication.
83  else
84  VuoCommandCommon::publishInternalExternalPortCombination(internalPort, externalPort, forceEventOnlyPublication, window->getComposition());
85 
86  // Collapse any typecasts possible.
88  }
89  // End of command content.
90 
91  this->updatedSnapshot = window->getComposition()->takeSnapshot();
92 
93  setDescription("Publish %s port '%s'",
94  port->getRenderer()->getInput() ? "input" : "output",
95  externalPort->getClass()->getName().c_str());
96 }
97 
102 {
104 }
105 
110 {
112 
113  window->resetCompositionWithSnapshot(revertedSnapshot);
114  window->coalesceSnapshots(updatedSnapshot, revertedSnapshot);
115 }
116 
121 {
123 
124  window->resetCompositionWithSnapshot(updatedSnapshot);
125  window->coalesceSnapshots(revertedSnapshot, updatedSnapshot);
126 }
127