Vuo 2.4.4
Loading...
Searching...
No Matches
VuoCommandUnpublishPort.cc
Go to the documentation of this file.
1
11
12#include "VuoCable.hh"
13#include "VuoCommandCommon.hh"
15#include "VuoEditorWindow.hh"
16#include "VuoPublishedPort.hh"
18#include "VuoRendererPort.hh"
19#include "VuoStringUtilities.hh"
20
25 : VuoCommandCommon(window)
26{
27 VuoPublishedPort *explicitExternalPort = externalPort;
28 bool isPublishedInput = !externalPort->getRenderer()->getInput();
29
30 vector<pair<VuoPort *, VuoPublishedPort *> > internalExternalPortCombinations;
31 foreach (VuoCable *cable, externalPort->getConnectedCables(true))
32 {
33 VuoPort *internalPort = (isPublishedInput? cable->getToPort() : cable->getFromPort());
34 internalExternalPortCombinations.push_back(make_pair(internalPort, externalPort));
35 }
36
37 initialize(explicitExternalPort, isPublishedInput, internalExternalPortCombinations, window);
38}
39
44 : VuoCommandCommon(window)
45{
46 VuoPublishedPort *explicitExternalPort = NULL;
47 bool isPublishedInput = internalPort->getRenderer()->getInput();
48
49 vector<pair<VuoPort *, VuoPublishedPort *> > internalExternalPortCombinations;
50 foreach (VuoRendererPublishedPort *externalPort, internalPort->getRenderer()->getPublishedPorts())
51 internalExternalPortCombinations.push_back(make_pair(internalPort, dynamic_cast<VuoPublishedPort *>(externalPort->getBase())));
52
53 initialize(explicitExternalPort, isPublishedInput, internalExternalPortCombinations, window);
54}
55
59void VuoCommandUnpublishPort::initialize(VuoPublishedPort *explicitExternalPort,
60 bool isPublishedInput,
61 vector<pair<VuoPort *, VuoPublishedPort *> > internalExternalPortCombinations,
62 VuoEditorWindow *window)
63{
64 setText(QApplication::translate("VuoEditorWindow", "Delete"));
65 this->window = window;
66 this->revertedSnapshot = window->getComposition()->takeSnapshot();
67
68 // Start of command content.
69 vector<string> portNames;
70 {
71 if (explicitExternalPort && explicitExternalPort->getConnectedCables(true).empty() &&
72 !explicitExternalPort->isProtocolPort())
73 {
74 window->getComposition()->removePublishedPort(explicitExternalPort, isPublishedInput);
75 portNames.push_back(explicitExternalPort->getClass()->getName());
76 }
77
78 for (vector<pair<VuoPort *, VuoPublishedPort *> >::iterator i = internalExternalPortCombinations.begin(); i != internalExternalPortCombinations.end(); ++i)
79 {
80 bool unpublishIsolatedExternalPort = !(*i).second->isProtocolPort();
81 VuoCommandCommon::unpublishInternalExternalPortCombination((*i).first, (*i).second, window->getComposition(), unpublishIsolatedExternalPort);
82 portNames.push_back((*i).second->getClass()->getName());
83 }
84 }
85 // End of command content.
86
87 this->updatedSnapshot = window->getComposition()->takeSnapshot();
88
89 setDescription("Unpublish %s port '%s'",
90 isPublishedInput ? "input" : "output",
91 VuoStringUtilities::join(portNames, ", ").c_str());
92}
93
101
106{
108
109 window->resetCompositionWithSnapshot(revertedSnapshot);
110 window->coalesceSnapshots(updatedSnapshot, revertedSnapshot);
111}
112
117{
119
120 window->resetCompositionWithSnapshot(updatedSnapshot);
121 window->coalesceSnapshots(revertedSnapshot, updatedSnapshot);
122}