54 #include <ApplicationServices/ApplicationServices.h>
55 #include <objc/objc-runtime.h>
58 const qreal VuoEditorComposition::nodeMoveRate = 15;
59 const qreal VuoEditorComposition::nodeMoveRateMultiplier = 4;
61 const qreal VuoEditorComposition::showEventsModeUpdateInterval = 1000/20.;
62 const int VuoEditorComposition::initialChangeNodeSuggestionCount = 10;
73 VuoEditorComposition_Pro();
76 this->window = window;
78 inputEditorManager = NULL;
79 activeProtocol = NULL;
81 runningComposition = NULL;
82 runningCompositionActiveDriver = NULL;
83 runningCompositionLibraries = NULL;
84 stopRequested =
false;
85 duplicateOnNextMouseMove =
false;
86 duplicationDragInProgress =
false;
87 duplicationCancelled =
false;
88 cursorPosBeforeDuplicationDragMove = QPointF(0,0);
89 cableInProgress = NULL;
90 cableInProgressWasNew =
false;
91 cableInProgressShouldBeWireless =
false;
92 portWithDragInitiated = NULL;
93 cableWithYankInitiated = NULL;
94 menuSelectionInProgress =
false;
95 previousNearbyItem = NULL;
96 dragStickinessDisabled =
false;
97 ignoreApplicationStateChangeEvents =
false;
98 popoverEventsEnabled =
true;
99 runCompositionQueue = dispatch_queue_create(
"org.vuo.editor.run", NULL);
100 activePortPopoversQueue = dispatch_queue_create(
"org.vuo.editor.popovers", NULL);
102 errorMarkingUpdatesEnabled =
true;
103 triggerPortToRefire =
"";
105 contextMenuDeleteSelected =
new QAction(NULL);
106 contextMenuHideSelectedCables =
new QAction(NULL);
107 contextMenuRenameSelected =
new QAction(NULL);
108 contextMenuRefactorSelected =
new QAction(NULL);
109 contextMenuPublishPort =
new QAction(NULL);
110 contextMenuDeleteCables =
new QAction(NULL);
111 contextMenuHideCables =
new QAction(NULL);
112 contextMenuUnhideCables =
new QAction(NULL);
113 contextMenuFireEvent =
new QAction(NULL);
114 contextMenuAddInputPort =
new QAction(NULL);
115 contextMenuRemoveInputPort =
new QAction(NULL);
116 contextMenuSetPortConstant =
new QAction(NULL);
117 contextMenuEditSelectedComments =
new QAction(NULL);
119 contextMenuChangeNode = NULL;
121 contextMenuFireEvent->setText(tr(
"Fire Event"));
122 contextMenuHideSelectedCables->setText(tr(
"Hide"));
123 contextMenuRenameSelected->setText(tr(
"Rename…"));
124 contextMenuRefactorSelected->setText(tr(
"Package as Subcomposition"));
125 contextMenuAddInputPort->setText(tr(
"Add Input Port"));
126 contextMenuRemoveInputPort->setText(tr(
"Remove Input Port"));
127 contextMenuSetPortConstant->setText(tr(
"Edit Value…"));
128 contextMenuEditSelectedComments->setText(tr(
"Edit…"));
135 connect(contextMenuDeleteCables, &QAction::triggered,
this, &VuoEditorComposition::deleteConnectedCables);
136 connect(contextMenuHideCables, &QAction::triggered,
this, &VuoEditorComposition::hideConnectedCables);
137 connect(contextMenuUnhideCables, &QAction::triggered,
this, &VuoEditorComposition::unhideConnectedCables);
138 connect(contextMenuFireEvent, &QAction::triggered,
this,
static_cast<void (
VuoEditorComposition::*)()
>(&VuoEditorComposition::fireTriggerPortEvent));
139 connect(contextMenuAddInputPort, &QAction::triggered,
this, &VuoEditorComposition::addInputPort);
140 connect(contextMenuRemoveInputPort, &QAction::triggered,
this, &VuoEditorComposition::removeInputPort);
141 connect(contextMenuEditSelectedComments, &QAction::triggered,
this, &VuoEditorComposition::editSelectedComments);
146 connect(contextMenuSetPortConstant, &QAction::triggered,
this, &VuoEditorComposition::setPortConstant, Qt::QueuedConnection);
151 QSignalMapper *contextMenuThrottlingMapper =
new QSignalMapper(
this);
152 connect(contextMenuThrottlingMapper,
static_cast<void (QSignalMapper::*)(
int)
>(&QSignalMapper::mapped),
this, &VuoEditorComposition::setTriggerThrottling);
154 QList<QPair<QString, enum VuoPortClass::EventThrottling> > throttlingNamesAndIndices;
158 for (QList<QPair<QString, enum VuoPortClass::EventThrottling> >::iterator i = throttlingNamesAndIndices.begin(); i != throttlingNamesAndIndices.end(); ++i)
160 QString name = i->first;
162 QAction *action =
new QAction(name,
this);
164 contextMenuThrottlingActions.append(action);
166 contextMenuThrottlingMapper->setMapping(action, index);
167 connect(action, &QAction::triggered, contextMenuThrottlingMapper,
static_cast<void (QSignalMapper::*)()
>(&QSignalMapper::map));
184 QSignalMapper *contextMenuTintsMapper =
new QSignalMapper(
this);
187 QList<QPair<QString, enum VuoNode::TintColor> > tintNamesAndIndices;
188 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Yellow"), VuoNode::TintYellow));
189 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Tangerine"), VuoNode::TintTangerine));
190 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Orange"), VuoNode::TintOrange));
191 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Magenta"), VuoNode::TintMagenta));
192 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Violet"), VuoNode::TintViolet));
193 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Blue"), VuoNode::TintBlue));
194 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Cyan"), VuoNode::TintCyan));
195 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Green"), VuoNode::TintGreen));
196 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"Lime"), VuoNode::TintLime));
197 tintNamesAndIndices.append(QPair<QString, enum VuoNode::TintColor>(tr(
"None"), VuoNode::TintNone));
199 for (QList<QPair<QString, enum VuoNode::TintColor> >::iterator i = tintNamesAndIndices.begin(); i != tintNamesAndIndices.end(); ++i)
201 QString name = i->first;
203 QAction *action =
new QAction(name,
this);
207 QColor fill(0,0,0,0);
209 if (index != VuoNode::TintNone)
219 p.drawEllipse(3, 3, 10, 10);
221 action->setIcon(*icon);
225 contextMenuTintActions.append(action);
227 contextMenuTintsMapper->setMapping(action, index);
228 connect(action, &QAction::triggered, contextMenuTintsMapper,
static_cast<void (QSignalMapper::*)()
>(&QSignalMapper::map));
233 this->refreshComponentAlphaLevelTimer =
new QTimer(
this);
234 this->refreshComponentAlphaLevelTimer->setObjectName(
"VuoEditorComposition::refreshComponentAlphaLevelTimer");
235 refreshComponentAlphaLevelTimer->setInterval(showEventsModeUpdateInterval);
237 setShowEventsMode(
false);
253 connect(static_cast<VuoEditor *>(qApp), &VuoEditor::focusChanged,
this, &VuoEditorComposition::updatePopoversForActiveWindowChange, Qt::QueuedConnection);
255 setPopoversHideOnDeactivate(
true);
258 setPopoversHideOnDeactivate(
false);
261 populateNodeAndPortIdentifierMappings();
269 this->compiler = compiler;
277 this->moduleManager = moduleManager;
286 return moduleManager;
296 this->inputEditorManager = inputEditorManager;
306 return this->inputEditorManager;
321 setCustomConstantsForNewNode(rn);
337 __block
bool isAllowed =
true;
340 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyIfInstalledAsSubcomposition(
this, ^
void (
VuoEditorComposition *currComposition,
string compositionPath) {
342 bool nodeIsThisComposition = (compositionModuleKey == nodeClass->
getBase()->
getClassName());
345 auto iter = std::find_if(dependencies.begin(), dependencies.end(), [=](
const string &d){
return d == compositionModuleKey; });
346 bool nodeContainsThisComposition = (iter != dependencies.end());
348 isAllowed = ! (nodeIsThisComposition || nodeContainsThisComposition);
356 nodeClass->
newNode(modelNode) :
357 compiler->
createNode(nodeClass, title, x, y));
375 vector<string> inputPortClassNames;
376 vector<string> outputPortClassNames;
381 inputPortClassNames.push_back(portClass->
getName());
384 outputPortClassNames.push_back(portClass->
getName());
388 dummyNodeClass->
newNode(modelNode) :
397 void VuoEditorComposition::setCustomConstantsForNewNode(
VuoRendererNode *newNode)
405 QString currentYear = QString::number(QDateTime::currentDateTime().date().year());
429 disablePortPopovers(rn);
451 map<VuoCable *, VuoPort *> cablesToTransferFromPort;
452 map<VuoCable *, VuoPort *> cablesToTransferToPort;
453 set<VuoCable *> cablesToRemove;
457 vector<VuoRendererNode *> collapsedTypecasts;
459 for (vector<VuoPort *>::iterator inputPort = oldInputPorts.begin(); inputPort != oldInputPorts.end(); ++inputPort)
465 collapsedTypecasts.push_back(typecastNode);
473 for (vector<VuoRendererNode *>::iterator i = collapsedTypecasts.begin(); i != collapsedTypecasts.end(); ++i)
481 for (map<VuoCable *, VuoPort *>::iterator i = cablesToTransferFromPort.begin(); i != cablesToTransferFromPort.end(); ++i)
482 i->first->getRenderer()->setFrom(newNode, i->second);
483 for (map<VuoCable *, VuoPort *>::iterator i = cablesToTransferToPort.begin(); i != cablesToTransferToPort.end(); ++i)
484 i->first->getRenderer()->setTo(newNode, i->second);
485 foreach (
VuoCable *cable, cablesToRemove)
500 VuoType *oldDataType = static_cast<VuoCompilerPort *>(oldInputPort->getCompiler())->getDataVuoType();
501 VuoType *newDataType = static_cast<VuoCompilerPort *>(newInputPort->
getCompiler())->getDataVuoType();
502 if (! (oldDataType == newDataType && oldDataType && ! dynamic_cast<VuoGenericType *>(oldDataType)) )
506 string oldConstantValue;
508 oldConstantValue = oldInputPort->getRenderer()->getConstantAsString();
510 oldConstantValue = oldInputPort->getRawInitialValue();
519 for (vector<VuoRendererNode *>::iterator i = collapsedTypecasts.begin(); i != collapsedTypecasts.end(); ++i)
532 disablePortPopovers(oldNode);
549 registerNodeID(newNode);
598 set<VuoRendererNode *> &createdNodes,
599 set<VuoRendererCable *> &createdCables)
613 foreach (QGraphicsItem *component, addedComponents)
616 if (rn && !createButDoNotAdd)
620 return addedComponents;
631 set<string> selectedNodeIDs;
638 set<string> selectedCommentIDs;
645 set<string> selectedCableIDs;
655 foreach (QGraphicsItem *item, items())
657 if (dynamic_cast<VuoRendererNode *>(item))
659 string currentNodeID = (dynamic_cast<VuoRendererNode *>(item)->getBase()->hasCompiler()?
660 dynamic_cast<VuoRendererNode *>(item)->getBase()->getCompiler()->getGraphvizIdentifier() :
662 if (!currentNodeID.empty() && (selectedNodeIDs.find(currentNodeID) != selectedNodeIDs.end()))
663 item->setSelected(
true);
666 if (dynamic_cast<VuoRendererComment *>(item))
668 string currentCommentID = (dynamic_cast<VuoRendererComment *>(item)->getBase()->hasCompiler()?
669 dynamic_cast<VuoRendererComment *>(item)->getBase()->getCompiler()->getGraphvizIdentifier() :
671 if (!currentCommentID.empty() && (selectedCommentIDs.find(currentCommentID) != selectedCommentIDs.end()))
672 item->setSelected(
true);
675 else if (dynamic_cast<VuoRendererCable *>(item))
677 string currentCableID = (dynamic_cast<VuoRendererCable *>(item)->getBase()->hasCompiler()?
678 dynamic_cast<VuoRendererCable *>(item)->getBase()->getCompiler()->getGraphvizDeclaration() :
680 if (!currentCableID.empty() && (selectedCableIDs.find(currentCableID) != selectedCableIDs.end()))
681 item->setSelected(
true);
704 if ((portName ==
"expression") &&
724 if (commandDescription.empty())
727 commandDescription =
"Reset";
729 commandDescription =
"Delete";
732 QList<QGraphicsItem *> selectedCompositionComponents = selectedItems();
741 if (commandDescription.empty())
742 commandDescription =
"Delete";
744 QList<QGraphicsItem *> selectedNodes;
746 selectedNodes.append(node);
780 nodeWithGraphvizIdentifier.clear();
781 portWithStaticIdentifier.clear();
782 staticIdentifierForPort.clear();
788 void VuoEditorComposition::insertNode()
790 QAction *sender = (QAction *)QObject::sender();
791 QPair<QPointF, QString> pair = sender->data().value<QPair<QPointF, QString> >();
793 QList<QGraphicsItem *> newNodes;
800 newNodes.append(newNode);
808 void VuoEditorComposition::insertComment()
810 QAction *sender = (QAction *)QObject::sender();
811 QPointF scenePos = sender->data().value<QPointF>();
819 void VuoEditorComposition::insertSubcomposition()
821 QAction *sender = (QAction *)QObject::sender();
822 QPointF scenePos = sender->data().value<QPointF>();
833 QAction *sender = (QAction *)QObject::sender();
848 void VuoEditorComposition::deleteConnectedCables()
850 QAction *sender = (QAction *)QObject::sender();
853 QList<QGraphicsItem *> cablesToRemove;
884 void VuoEditorComposition::hideConnectedCables()
886 QAction *sender = (QAction *)QObject::sender();
888 set<VuoRendererCable *> cablesToHide;
919 void VuoEditorComposition::unhideConnectedCables()
921 QAction *sender = (QAction *)QObject::sender();
923 set<VuoRendererCable *> cablesToUnhide;
952 void VuoEditorComposition::fireTriggerPortEvent()
954 QAction *sender = (QAction *)QObject::sender();
956 fireTriggerPortEvent(port->
getBase());
972 if (triggerPortToRefire.empty() ||
973 (portWithStaticIdentifier.find(triggerPortToRefire) == portWithStaticIdentifier.end()))
976 return portWithStaticIdentifier[triggerPortToRefire];
985 if (portID != this->triggerPortToRefire)
987 this->triggerPortToRefire = portID;
996 void VuoEditorComposition::setPortConstant()
998 QAction *sender = (QAction *)QObject::sender();
1009 void VuoEditorComposition::setPortConstantToValue(
VuoRendererPort *port,
string value)
1019 void VuoEditorComposition::specializeGenericPortType()
1021 QAction *sender = (QAction *)QObject::sender();
1022 QList<QVariant> portAndSpecializedType= sender->data().toList();
1024 QString specializedTypeName = portAndSpecializedType[1].toString();
1031 if (port && !dynamic_cast<VuoGenericType *>(port->
getDataType()))
1036 emit
specializePort(port, specializedTypeName.toUtf8().constData());
1043 void VuoEditorComposition::unspecializePortType()
1045 QAction *sender = (QAction *)QObject::sender();
1049 if (port && dynamic_cast<VuoGenericType *>(port->
getDataType()))
1067 map<VuoPort *, VuoNode *> nodeForPort;
1068 map<VuoPort *, set<VuoCable *> > cablesForPort;
1070 for (set<VuoNode *>::iterator i = nodes.begin(); i != nodes.end(); ++i)
1075 vector<VuoPort *> ports;
1076 ports.insert(ports.end(), inputPorts.begin(), inputPorts.end());
1077 ports.insert(ports.end(), outputPorts.begin(), outputPorts.end());
1079 for (vector<VuoPort *>::iterator j = ports.begin(); j != ports.end(); ++j)
1083 nodeForPort[port] = node;
1085 cablesForPort[port].insert(cables.begin(), cables.end());
1091 portToUnspecialize,
true);
1092 map<VuoNode *, set<VuoPort *> > portsToUnspecializeForNode;
1093 for (
VuoPort *connectedPort : connectedPotentiallyGenericPorts)
1095 VuoNode *node = nodeForPort[connectedPort];
1099 if (isPortCurrentlyRevertible(connectedPort->getRenderer()))
1100 portsToUnspecializeForNode[node].insert(connectedPort);
1103 for (map<
VuoNode *, set<VuoPort *> >::iterator i = portsToUnspecializeForNode.begin(); i != portsToUnspecializeForNode.end(); ++i)
1106 set<VuoPort *> ports = i->second;
1109 set<VuoPortClass *> portClasses;
1110 for (set<VuoPort *>::iterator j = ports.begin(); j != ports.end(); ++j)
1111 portClasses.insert((*j)->getClass());
1114 nodesToReplace[node] = unspecializedNodeClassName;
1118 for (set<VuoPort *>::iterator j = ports.begin(); j != ports.end(); ++j)
1121 set<VuoCable *> connectedCables = cablesForPort[port];
1122 for (set<VuoCable *>::iterator k = connectedCables.begin(); k != connectedCables.end(); ++k)
1126 bool areEndsCompatible =
false;
1129 areEndsCompatible =
true;
1134 if (portOnOtherEnd && isPortCurrentlyRevertible(portOnOtherEnd->
getRenderer()))
1136 VuoNode *nodeOnOtherEnd = nodeForPort[portOnOtherEnd];
1139 if (specializedNodeClassOnOtherEnd)
1142 if (! typeOnOtherEnd || dynamic_cast<VuoGenericType *>(typeOnOtherEnd))
1143 areEndsCompatible =
true;
1148 if (! areEndsCompatible && (cable != cableInProgress))
1149 cablesToDelete.insert(cable);
1158 void VuoEditorComposition::fireTriggerPortEvent(
VuoPort *port)
1166 string runningTriggerPortIdentifier =
"";
1167 bool isTriggerPort =
false;
1168 if (dynamic_cast<VuoCompilerTriggerPort *>(port->
getCompiler()))
1174 runningTriggerPortIdentifier = staticIdentifierForPort[port];
1175 isTriggerPort =
true;
1193 runningTriggerPortIdentifier.c_str());
1196 bool manuallyFirableInputPortChanged = (oldManuallyFirableInputPort != newManuallyFirableInputPort);
1199 auto fireIfRunning = ^void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier)
1201 dispatch_async(topLevelComposition->runCompositionQueue, ^{
1202 if (topLevelComposition->isRunningThreadUnsafe())
1204 topLevelComposition->runner->fireTriggerPortEvent(thisCompositionIdentifier, runningTriggerPortIdentifier);
1209 if (! (this->showEventsMode && isTriggerPort) )
1210 this->animatePort(port->getRenderer());
1215 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, ^
void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier) {
1216 if (
this == topLevelComposition || ! manuallyFirableInputPortChanged)
1220 if (! newSnapshot.empty() && manuallyFirableInputPortChanged)
1221 updateRunningComposition(oldSnapshot, newSnapshot);
1223 fireIfRunning(topLevelComposition, thisCompositionIdentifier);
1229 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyIfInstalledAsSubcomposition(
this, ^
void (
VuoEditorComposition *currComposition,
string compositionPath) {
1231 moduleManager->doNextTimeNodeClassIsLoaded(nodeClassName, ^{
1232 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, ^
void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier) {
1233 fireIfRunning(topLevelComposition, thisCompositionIdentifier);
1237 if (! newSnapshot.empty())
1238 updateRunningComposition(oldSnapshot, newSnapshot);
1243 setTriggerPortToRefire(port);
1249 void VuoEditorComposition::setTriggerThrottling(
int eventThrottling)
1251 QSignalMapper *signalMapper = (QSignalMapper *)QObject::sender();
1252 QAction *sender = (QAction *)signalMapper->mapping(eventThrottling);
1261 void VuoEditorComposition::addInputPort()
1263 QAction *sender = (QAction *)QObject::sender();
1272 void VuoEditorComposition::removeInputPort()
1274 QAction *sender = (QAction *)QObject::sender();
1283 void VuoEditorComposition::swapNode()
1285 QAction *sender = (QAction *)QObject::sender();
1286 QList<QVariant> nodeAndReplacementType= sender->data().toList();
1287 VuoRendererNode *node = static_cast<VuoRendererNode *>(nodeAndReplacementType[0].value<void *>());
1288 QString newNodeClassName = nodeAndReplacementType[1].toString();
1308 for (set<VuoRendererNode *>::iterator i = selectedNodes.begin(); i != selectedNodes.end(); ++i)
1310 if (!dynamic_cast<VuoRendererInputAttachment *>(*i))
1318 void VuoEditorComposition::editSelectedComments()
1322 for (set<VuoRendererComment *>::iterator i = selectedComments.begin(); i != selectedComments.end(); ++i)
1331 set<VuoRendererCable *> internalCables;
1333 for (QList<QGraphicsItem *>::iterator i = subcompositionComponents.begin(); i != subcompositionComponents.end(); ++i)
1335 QGraphicsItem *compositionComponent = *i;
1336 VuoRendererNode *rn = dynamic_cast<VuoRendererNode *>(compositionComponent);
1340 for (set<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
1342 VuoNode *fromNode = (*cable)->getFromNode();
1343 VuoNode *toNode = (*cable)->getToNode();
1345 if (fromNode && toNode && subcompositionComponents.contains(fromNode->
getRenderer()) && subcompositionComponents.contains(toNode->
getRenderer()))
1346 internalCables.insert((*cable)->getRenderer());
1351 return internalCables;
1359 return cableInProgress;
1368 return cableInProgressWasNew;
1376 return menuSelectionInProgress;
1384 QList<QGraphicsItem *> compositionComponents = items();
1385 for (QList<QGraphicsItem *>::iterator i = compositionComponents.begin(); i != compositionComponents.end(); ++i)
1387 QGraphicsItem *compositionComponent = *i;
1389 VuoRendererCable *rc = dynamic_cast<VuoRendererCable *>(compositionComponent);
1391 compositionComponent->setSelected(
true);
1400 QList<QGraphicsItem *> compositionComponents = items();
1401 for (QList<QGraphicsItem *>::iterator i = compositionComponents.begin(); i != compositionComponents.end(); ++i)
1403 QGraphicsItem *compositionComponent = *i;
1404 VuoRendererComment *rcomment = dynamic_cast<VuoRendererComment *>(compositionComponent);
1406 rcomment->setSelected(
true);
1415 QList<QGraphicsItem *> compositionComponents = items();
1416 for (QList<QGraphicsItem *>::iterator i = compositionComponents.begin(); i != compositionComponents.end(); ++i)
1418 QGraphicsItem *compositionComponent = *i;
1419 compositionComponent->setSelected(
false);
1426 void VuoEditorComposition::openSelectedEditableNodes()
1431 QString actionText, sourcePath;
1444 moveItemsBy(selectedNodes, selectedComments, dx, dy,
false);
1450 void VuoEditorComposition::moveNodesBy(set<VuoRendererNode *> nodes, qreal dx, qreal dy,
bool movedByDragging)
1452 set<VuoRendererComment *> comments;
1453 moveItemsBy(nodes, comments, dx, dy, movedByDragging);
1459 void VuoEditorComposition::moveCommentsBy(set<VuoRendererComment *> comments, qreal dx, qreal dy,
bool movedByDragging)
1461 set<VuoRendererNode *> nodes;
1462 moveItemsBy(nodes, comments, dx, dy, movedByDragging);
1468 void VuoEditorComposition::moveItemsBy(set<VuoRendererNode *> nodes, set<VuoRendererComment *> comments, qreal dx, qreal dy,
bool movedByDragging)
1470 emit
itemsMoved(nodes, comments, dx, dy, movedByDragging);
1472 for (set<VuoRendererNode *>::iterator it = nodes.begin(); it != nodes.end(); ++it)
1473 (*it)->updateConnectedCableGeometry();
1479 void VuoEditorComposition::resizeCommentBy(
VuoRendererComment *comment, qreal dx, qreal dy)
1489 QList<QGraphicsItem *> selectedCompositionComponents = selectedItems();
1490 set<VuoRendererNode *> selectedNodes;
1491 for (QList<QGraphicsItem *>::iterator i = selectedCompositionComponents.begin(); i != selectedCompositionComponents.end(); ++i)
1493 QGraphicsItem *compositionComponent = *i;
1494 VuoRendererNode *rn = dynamic_cast<VuoRendererNode *>(compositionComponent);
1496 selectedNodes.insert(rn);
1499 return selectedNodes;
1507 QList<QGraphicsItem *> selectedCompositionComponents = selectedItems();
1508 set<VuoRendererComment *> selectedComments;
1509 for (QList<QGraphicsItem *>::iterator i = selectedCompositionComponents.begin(); i != selectedCompositionComponents.end(); ++i)
1511 QGraphicsItem *compositionComponent = *i;
1514 selectedComments.insert(rc);
1517 return selectedComments;
1525 QList<QGraphicsItem *> selectedCompositionComponents = selectedItems();
1526 set<VuoRendererCable *> selectedCables;
1527 for (QList<QGraphicsItem *>::iterator i = selectedCompositionComponents.begin(); i != selectedCompositionComponents.end(); ++i)
1529 QGraphicsItem *compositionComponent = *i;
1530 VuoRendererCable *rc = dynamic_cast<VuoRendererCable *>(compositionComponent);
1532 selectedCables.insert(rc);
1535 return selectedCables;
1543 const QMimeData *mimeData =
event->mimeData();
1544 bool disablePortHoverHighlighting =
true;
1547 if (mimeData->hasFormat(
"text/uri-list"))
1549 QList<QUrl> urls = mimeData->urls();
1552 VuoRendererPort *portAtDropLocation = dynamic_cast<VuoRendererPort *>(nearbyItem);
1553 if (portAtDropLocation)
1555 if ((urls.size() == 1) && portAtDropLocation->isConstant() &&
1556 (portAtDropLocation->getDataType()->getModuleKey() ==
"VuoText"))
1557 disablePortHoverHighlighting =
false;
1559 event->setDropAction(Qt::IgnoreAction);
1563 bool dragIncludesDroppableFile =
false;
1564 foreach (QUrl url, urls)
1578 if (isSupportedDragNDropFile)
1580 dragIncludesDroppableFile =
true;
1585 if (!dragIncludesDroppableFile)
1586 event->setDropAction(Qt::IgnoreAction);
1593 else if (mimeData->hasFormat(
"text/plain") || mimeData->hasFormat(
"text/scsv"))
1594 event->acceptProposedAction();
1598 event->setDropAction(Qt::IgnoreAction);
1602 updateHoverHighlighting(event->scenePos(), disablePortHoverHighlighting);
1610 event->acceptProposedAction();
1626 const QMimeData *mimeData =
event->mimeData();
1629 if (mimeData->hasFormat(
"text/uri-list"))
1637 if (topCompositionPath.empty())
1639 QDir compositionDir(QDir(topCompositionPath.c_str()).canonicalPath());
1644 QList<QGraphicsItem *> newNodes;
1645 QList<QUrl> urls = mimeData->urls();
1648 VuoRendererPort *portAtDropLocation = dynamic_cast<VuoRendererPort *>(nearbyItem);
1649 if (portAtDropLocation)
1651 if ((urls.size() == 1) && portAtDropLocation->isConstant() &&
1652 (portAtDropLocation->getDataType()->getModuleKey() ==
"VuoText"))
1654 QString filePath = (useAbsoluteFilePaths? urls[0].path() : compositionDir.relativeFilePath(urls[0].path()));
1655 string constantValue =
"\"" + string(filePath.toUtf8().constData()) +
"\"";
1666 const int ySpacingForNewNodes = 11;
1667 int yOffsetForPreviousNewNode = -1 * ySpacingForNewNodes;
1669 foreach (QUrl url, urls)
1671 QStringList targetNodeClassNames;
1674 targetNodeClassNames +=
"vuo.image.fetch";
1678 targetNodeClassNames +=
"vuo.video.play";
1680 targetNodeClassNames +=
"vuo.video.decodeImage";
1683 targetNodeClassNames +=
"vuo.scene.fetch";
1685 targetNodeClassNames +=
"vuo.audio.file.play";
1687 targetNodeClassNames +=
"vuo.image.project.dome";
1689 targetNodeClassNames +=
"vuo.rss.fetch";
1691 targetNodeClassNames +=
"vuo.tree.fetch.json";
1693 targetNodeClassNames +=
"vuo.tree.fetch.xml";
1695 targetNodeClassNames +=
"vuo.table.fetch";
1697 targetNodeClassNames +=
"vuo.data.fetch";
1699 targetNodeClassNames +=
"vuo.app.launch";
1701 targetNodeClassNames +=
"vuo.file.list";
1703 QString selectedNodeClassName =
"";
1704 if (targetNodeClassNames.size() == 1)
1705 selectedNodeClassName = targetNodeClassNames[0];
1706 else if (targetNodeClassNames.size() > 1)
1708 QMenu nodeMenu(views()[0]->viewport());
1709 nodeMenu.setSeparatorsCollapsible(
false);
1711 foreach (QString nodeClassName, targetNodeClassNames)
1714 string nodeTitle = (nodeClass? nodeClass->
getBase()->
getDefaultTitle() : nodeClassName.toUtf8().constData());
1716 QAction *nodeAction = nodeMenu.addAction(tr(
"Insert \"%1\" Node").arg(nodeTitle.c_str()));
1717 nodeAction->setData(nodeClassName);
1720 menuSelectionInProgress =
true;
1721 QAction *selectedNode = nodeMenu.exec(QCursor::pos());
1722 menuSelectionInProgress =
false;
1724 selectedNodeClassName = (selectedNode? selectedNode->data().toString().toUtf8().constData() :
"");
1727 if (!selectedNodeClassName.isEmpty())
1730 event->scenePos().x(),
1731 event->scenePos().y() + yOffsetForPreviousNewNode + ySpacingForNewNodes);
1740 QString filePath = (useAbsoluteFilePaths? url.path() : compositionDir.relativeFilePath(url.path()));
1743 newNodes.append(newNode);
1745 yOffsetForPreviousNewNode += newNode->
boundingRect().height();
1746 yOffsetForPreviousNewNode += ySpacingForNewNodes;
1752 if (newNodes.size() > 0)
1764 else if (mimeData->hasFormat(
"text/scsv"))
1766 event->setDropAction(Qt::CopyAction);
1769 QByteArray scsvData =
event->mimeData()->data(
"text/scsv");
1770 QString scsvText = QString::fromUtf8(scsvData);
1771 QStringList nodeClassNames = scsvText.split(
';');
1776 int snapDelta = nextYPos - startPos.y();
1778 QList<QGraphicsItem *> newNodes;
1779 for (QStringList::iterator i = nodeClassNames.begin(); i != nodeClassNames.end(); ++i)
1787 int prevYPos = nextYPos;
1790 if (nextYPos <= prevYPos+newNode->boundingRect().height())
1793 newNodes.append((QGraphicsItem *)newNode);
1801 else if (mimeData->hasFormat(
"text/plain"))
1803 event->setDropAction(Qt::CopyAction);
1806 QList<QGraphicsItem *> newNodes;
1807 QStringList dropItems =
event->mimeData()->text().split(
'\n');
1808 QString nodeClassName = dropItems[0];
1812 QPoint hotSpot = (dropItems.size() >= 3? QPoint(dropItems[1].toInt(), dropItems[2].toInt()) : QPoint(0,0));
1814 event->scenePos().x()-hotSpot.x()+1,
1817 newNodes.append(newNode);
1832 if (dynamic_cast<VuoRendererPort *>(nearbyItem))
1834 QGraphicsScene::sendEvent(nearbyItem, event);
1839 QGraphicsScene::mouseDoubleClickEvent(event);
1847 QPointF scenePos =
event->scenePos();
1850 if (event->button() == Qt::LeftButton)
1855 if (duplicationCancelled)
1857 QGraphicsItem *itemClickedDirectly = itemAt(scenePos, views()[0]->transform());
1858 if (dynamic_cast<VuoRendererNode *>(itemClickedDirectly) ||
1859 dynamic_cast<VuoRendererCable *>(itemClickedDirectly) ||
1860 dynamic_cast<VuoRendererComment *>(itemClickedDirectly)
1863 duplicationCancelled =
false;
1864 correctForCancelledDuplication(event);
1875 mousePressEventNonLeftButton(event);
1884 bool eventHandled =
false;
1889 VuoRendererPort *currentPort = dynamic_cast<VuoRendererPort *>(nearbyItem);
1892 VuoRendererCable *currentCable = dynamic_cast<VuoRendererCable *>(nearbyItem);
1898 cableYankedDirectly = currentCable;
1906 if ((event->modifiers() & Qt::ControlModifier) && (currentPort->
getInput() || isTriggerPort))
1907 fireTriggerPortEvent(currentPort->
getBase());
1911 portWithDragInitiated = currentPort;
1912 cableWithYankInitiated = cableYankedDirectly;
1916 eventHandled =
true;
1923 duplicateOnNextMouseMove =
true;
1924 duplicationDragInProgress =
true;
1930 QGraphicsScene::mousePressEvent(event);
1931 eventHandled =
true;
1935 if (dynamic_cast<VuoRendererCable *>(nearbyItem))
1937 if (event->modifiers() & Qt::ControlModifier)
1938 nearbyItem->setSelected(! nearbyItem->isSelected());
1943 nearbyItem->setSelected(
true);
1947 eventHandled =
true;
1952 QGraphicsScene::mousePressEvent(event);
1959 void VuoEditorComposition::mousePressEventNonLeftButton(QGraphicsSceneMouseEvent *event)
1968 if (event->button() == Qt::RightButton)
1970 QGraphicsSceneContextMenuEvent
contextMenuEvent(QEvent::GraphicsSceneContextMenu);
1979 QGraphicsScene::mousePressEvent(event);
1990 void VuoEditorComposition::correctForCancelledDuplication(QGraphicsSceneMouseEvent *event)
1994 QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
1995 pressEvent.setScenePos(event->scenePos());
1996 pressEvent.setButton(Qt::LeftButton);
1997 QApplication::sendEvent(
this, &pressEvent);
1999 QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
2000 releaseEvent.setScenePos(event->scenePos());
2001 releaseEvent.setButton(Qt::LeftButton);
2002 QApplication::sendEvent(
this, &releaseEvent);
2014 Qt::KeyboardModifiers modifiers =
event->modifiers();
2015 bool optionKeyPressed = (modifiers & Qt::AltModifier);
2016 bool shiftKeyPressed = (modifiers & Qt::ShiftModifier);
2027 bool creatingNewCable =
false;
2028 bool disconnectingExistingCable =
false;
2029 bool duplicatingExistingCable =
false;
2043 fromPort = fixedPort;
2044 fromNode = fixedNode;
2045 creatingNewCable =
true;
2057 creatingNewCable =
true;
2064 if (optionKeyPressed)
2066 duplicatingExistingCable =
true;
2070 disconnectingExistingCable =
true;
2078 if (creatingNewCable)
2091 cableInProgressWasNew =
true;
2092 cableInProgressShouldBeWireless =
false;
2099 highlightEligibleEndpointsForCable(cableInProgress);
2104 else if (disconnectingExistingCable)
2107 if (cableYankedDirectly)
2108 cableInProgress = cableYankedDirectly->
getBase();
2114 cableInProgressWasNew =
false;
2125 highlightEligibleEndpointsForCable(cableInProgress);
2127 cableInProgress->
getRenderer()->setSelected(
true);
2130 else if (duplicatingExistingCable)
2134 if (cableYankedDirectly)
2135 cableToDuplicate = cableYankedDirectly->
getBase();
2152 cableInProgressWasNew =
true;
2153 cableInProgressShouldBeWireless = cableToDuplicate->
hasCompiler() &&
2161 highlightEligibleEndpointsForCable(cableInProgress);
2163 cableInProgress->
getRenderer()->setSelected(
true);
2168 cableInProgress->
getRenderer()->setCacheMode(QGraphicsItem::NoCache);
2181 if (event->button() == Qt::LeftButton)
2183 portWithDragInitiated = NULL;
2184 cableWithYankInitiated = NULL;
2185 duplicateOnNextMouseMove =
false;
2186 duplicationDragInProgress =
false;
2187 dragStickinessDisabled =
false;
2194 bool cableDragEnding = cableInProgress;
2195 if (cableDragEnding)
2196 concludeCableDrag(event);
2208 if ((event->modifiers() == Qt::NoModifier) &&
2209 (QLineF(event->screenPos(),
event->buttonDownScreenPos(Qt::LeftButton)).length() < QApplication::startDragDistance()))
2216 enablePopoverForNode(typecastNode);
2221 enableInactivePopoverForPort(port);
2227 if (!cableDragEnding && !node)
2231 if (!cableDragEnding)
2232 QGraphicsScene::mouseReleaseEvent(event);
2238 QGraphicsScene::mouseReleaseEvent(event);
2248 void VuoEditorComposition::concludeCableDrag(QGraphicsSceneMouseEvent *event)
2256 concludePublishedCableDrag(event);
2260 if (hasFeedbackErrors())
2278 bool completedCableConnection =
false;
2281 VuoCable *dataCableToDisplace = NULL;
2285 string typecastToInsert =
"";
2289 string specializedTypeName =
"";
2306 bool draggingPreviouslyPublishedCable = (!cableInProgressWasNew &&
2307 (dynamic_cast<VuoRendererPublishedPort *>(fixedPort) ||
2308 ((cableInProgress->
getToPort() == NULL) &&
2311 if (fixedPort && targetPort)
2319 if (recreatingSameConnection)
2329 bool preexistingCableWithMatchingDataCarryingStatus = (preexistingCable?
2331 cableInProgressExpectedToCarryData) :
2337 if (preexistingCable && !preexistingCableWithMatchingDataCarryingStatus &&
2348 if (!preexistingCableWithMatchingDataCarryingStatus &&
2350 selectBridgingSolution(fixedPort, targetPort,
true, &portToSpecialize, specializedTypeName, typecastToInsert)))
2361 targetPort = adjustedTargetPort;
2365 if (cableInProgressExpectedToCarryData &&
2367 (*typecastOutPort->
getConnectedCables(
true).begin())->getRenderer()->effectivelyCarriesData())
2368 typecastNodeToDelete = uncollapsedTypecast;
2373 if (preexistingCable)
2374 cableToReplace = preexistingCable;
2378 if (cableInProgressExpectedToCarryData)
2382 for (vector<VuoCable *>::iterator cable = previousConnectedCables.begin(); (! dataCableToDisplace) && (cable != previousConnectedCables.end()); ++cable)
2383 if ((((*cable)->getRenderer()->effectivelyCarriesData()) && (*cable) != cableToReplace))
2384 dataCableToDisplace = *cable;
2391 if (publishedDataConnections.size() > 0)
2392 portToUnpublish = targetPort;
2396 completedCableConnection =
true;
2400 else if (!preexistingCableWithMatchingDataCarryingStatus &&
2402 selectBridgingSolution(targetPort, fixedPort,
false, &portToSpecialize, specializedTypeName, typecastToInsert)))
2405 completedCableConnection =
true;
2410 if (completedCableConnection)
2414 if (draggingPreviouslyPublishedCable)
2433 cableInProgressCopy->
setFrom(cableInProgressFromNode, cableInProgressFromPort);
2434 cableInProgressCopy->
setTo(cableInProgressToNode, cableInProgressToPort);
2441 cableInProgress = cableInProgressCopy;
2442 cableInProgressWasNew =
true;
2446 pair<VuoRendererCable *, VuoRendererCable *> cableArgs = std::make_pair((dataCableToDisplace? dataCableToDisplace->
getRenderer() : NULL),
2447 (cableToReplace? cableToReplace->
getRenderer() : NULL));
2448 pair<string, string> typeArgs = std::make_pair(typecastToInsert, specializedTypeName);
2449 pair<VuoRendererPort *, VuoRendererPort *> portArgs = std::make_pair(portToUnpublish, portToSpecialize);
2454 typecastNodeToDelete,
2461 if (cableInProgress)
2465 cableInProgress = NULL;
2479 void VuoEditorComposition::concludePublishedCableDrag(QGraphicsSceneMouseEvent *event)
2489 string typecastToInsert =
"";
2493 string specializedTypeName =
"";
2510 if (internalInputPort)
2513 forceEventOnlyPublication =
true;
2519 if (internalInputPort &&
2525 internalInputPort->
getBase()) &&
2528 if (recreatingSameConnection)
2536 ||
selectBridgingSolution(publishedInputPort, internalInputPort,
true, &portToSpecialize, specializedTypeName, typecastToInsert))
2541 bool cableToReplaceHasMatchingDataCarryingStatus = (cableToReplace?
2543 cableInProgressExpectedToCarryData) :
2548 if (cableToReplace && cableToReplaceHasMatchingDataCarryingStatus)
2554 else if (cableToReplace && !cableToReplaceHasMatchingDataCarryingStatus &&
2570 if (cableToReplace && !cableToReplaceHasMatchingDataCarryingStatus)
2572 QList<QGraphicsItem *> removedComponents;
2573 removedComponents.append(cableToReplace->
getRenderer());
2582 if (typecastPort && typecastPort->scene())
2590 if (cableInProgressExpectedToCarryData &&
2592 (*typecastOutPort->
getConnectedCables(
true).begin())->getRenderer()->effectivelyCarriesData())
2594 QList<QGraphicsItem *> removedComponents;
2595 removedComponents.append(uncollapsedTypecast);
2601 dynamic_cast<VuoPublishedPort *>(publishedInputPort->
getBase()),
2602 forceEventOnlyPublication,
2603 (portToSpecialize? portToSpecialize->
getBase() : NULL),
2604 specializedTypeName,
2630 if (internalOutputPort)
2633 forceEventOnlyPublication =
true;
2639 if (internalOutputPort &&
2640 publishedOutputPort)
2646 ||
selectBridgingSolution(internalOutputPort, publishedOutputPort,
false, &portToSpecialize, specializedTypeName, typecastToInsert))
2649 dynamic_cast<VuoPublishedPort *>(publishedOutputPort->
getBase()),
2650 forceEventOnlyPublication,
2651 portToSpecialize? portToSpecialize->
getBase() : NULL,
2652 specializedTypeName,
2671 if (! cableInProgress)
2674 if (cableInProgressWasNew)
2678 QList<QGraphicsItem *> removedComponents;
2679 removedComponents.append(cableInProgress->
getRenderer());
2683 cableInProgress = NULL;
2696 cableInProgress->
getRenderer()->setCacheMode(QGraphicsItem::NoCache);
2701 cableInProgress = NULL;
2703 else if (cableInProgress)
2718 bool leftMouseButtonPressed = (
event->buttons() & Qt::LeftButton);
2734 if (cableInProgress || (! leftMouseButtonPressed))
2735 updateHoverHighlighting(event->scenePos());
2739 if (leftMouseButtonPressed)
2742 if ((! dragStickinessDisabled) && (QLineF(event->screenPos(),
event->buttonDownScreenPos(Qt::LeftButton)).length() < QApplication::startDragDistance()))
2746 dragStickinessDisabled =
true;
2750 if (portWithDragInitiated || cableWithYankInitiated)
2752 initiateCableDrag(portWithDragInitiated, cableWithYankInitiated, event);
2753 portWithDragInitiated = NULL;
2754 cableWithYankInitiated = NULL;
2759 if (cableInProgress)
2769 else if (duplicationDragInProgress)
2771 if (duplicateOnNextMouseMove)
2774 duplicateOnNextMouseMove =
false;
2781 QPointF delta = newPos - cursorPosBeforeDuplicationDragMove;
2783 cursorPosBeforeDuplicationDragMove = newPos;
2787 QGraphicsScene::mouseMoveEvent(event);
2792 QGraphicsScene::mouseMoveEvent(event);
2800 void VuoEditorComposition::updateHoverHighlighting(QPointF scenePos,
bool disablePortHoverHighlighting)
2812 bool hoveringOverNodeHeader =
false;
2813 if (cableInProgress)
2822 hoveringOverNodeHeader =
true;
2828 if (! hoveringOverNodeHeader)
2831 if (dynamic_cast<VuoRendererNode *>(item) && !makeListDrawer)
2834 node = dynamic_cast<VuoRendererNode *>(item);
2839 if (item != previousNearbyItem)
2841 VuoRendererPort *previousPort = dynamic_cast<VuoRendererPort *>(previousNearbyItem);
2842 VuoRendererNode *previousNode = dynamic_cast<VuoRendererNode *>(previousNearbyItem);
2847 if (previousNearbyItem)
2855 if (! cableInProgress)
2861 else if (typecastPort && !disablePortHoverHighlighting)
2863 else if (port && !disablePortHoverHighlighting)
2866 if (!cableInProgress)
2877 if (cableInProgress)
2880 cableInProgress->getFromPort()->getRenderer() :
2881 cableInProgress->getToPort()->getRenderer());
2883 QList< QPair<VuoRendererPort *, bool> > updatedPorts;
2884 if (hoveringOverNodeHeader)
2885 updatedPorts.append( QPair<VuoRendererPort *, bool>(port,
true) );
2886 if (previousNode && previousPort)
2887 updatedPorts.append( QPair<VuoRendererPort *, bool>(previousPort, !cableInProgress->getRenderer()->effectivelyCarriesData()) );
2889 QPair<VuoRendererPort *, bool> p;
2890 foreach (p, updatedPorts)
2895 if (typecastParentPort)
2896 updatedPort = typecastParentPort;
2898 updateEligibilityHighlightingForPort(updatedPort, fixedPort, p.second);
2901 updateEligibilityHighlightingForNode(potentialDrawer);
2908 if (targetPort || previousTargetPort)
2910 if (cableInProgress)
2911 cableInProgress->getRenderer()->setFloatingEndpointAboveEventPort(targetPort && (!targetPort->
getDataType() || hoveringOverNodeHeader));
2916 previousNearbyItem = item;
2924 else if (port && !disablePortHoverHighlighting)
2927 if (!cableInProgress)
2933 else if (makeListDrawer)
2943 if (previousNearbyItem)
2945 VuoRendererCable *cable = dynamic_cast<VuoRendererCable *>(previousNearbyItem);
2946 VuoRendererPort *port = dynamic_cast<VuoRendererPort *>(previousNearbyItem);
2948 VuoRendererNode *node = dynamic_cast<VuoRendererNode *>(previousNearbyItem);
2961 else if (typecastPort)
2970 previousNearbyItem = NULL;
2979 if ((event->key() != Qt::Key_Alt) && (event->key() != Qt::Key_Shift) && (event->key() != Qt::Key_Escape))
2982 Qt::KeyboardModifiers modifiers =
event->modifiers();
2983 qreal adjustedNodeMoveRate = nodeMoveRate;
2984 if (modifiers & Qt::ShiftModifier)
2986 adjustedNodeMoveRate *= nodeMoveRateMultiplier;
2989 switch (event->key()) {
2990 case Qt::Key_Backspace:
2995 case Qt::Key_Delete:
3007 if (modifiers & Qt::ControlModifier)
3008 openSelectedEditableNodes();
3025 if (cableInProgress)
3027 cableInProgress->getRenderer()->updateGeometry();
3028 cableInProgress->getCompiler()->setAlwaysEventOnly(
true);
3029 highlightEligibleEndpointsForCable(cableInProgress);
3031 VuoRendererPort *hoveredPort = dynamic_cast<VuoRendererPort *>(previousNearbyItem);
3039 case Qt::Key_Return:
3042 QGraphicsScene::keyPressEvent(event);
3044 if (!event->isAccepted())
3051 if (selectedComments.empty() && !selectedNodes.empty())
3058 case Qt::Key_Escape:
3060 if (duplicateOnNextMouseMove || duplicationDragInProgress)
3064 duplicateOnNextMouseMove =
false;
3065 duplicationDragInProgress =
false;
3066 duplicationCancelled =
true;
3068 else if (cableInProgress)
3077 QGraphicsScene::keyPressEvent(event);
3088 switch (event->key()) {
3091 if (cableInProgress)
3093 cableInProgress->getRenderer()->updateGeometry();
3094 cableInProgress->getCompiler()->setAlwaysEventOnly(
false);
3095 highlightEligibleEndpointsForCable(cableInProgress);
3097 VuoRendererPort *hoveredPort = dynamic_cast<VuoRendererPort *>(previousNearbyItem);
3107 QGraphicsScene::keyReleaseEvent(event);
3116 void VuoEditorComposition::addActionToMenuAndMapper(QMenu *menu, QSignalMapper *mapper, QString name,
int index)
3118 QAction *action =
new QAction(name,
this);
3119 menu->addAction(action);
3120 mapper->setMapping(action, index);
3121 connect(action, &QAction::triggered, mapper,
static_cast<void (QSignalMapper::*)()
>(&QSignalMapper::map));
3133 contextMenu.setSeparatorsCollapsible(
false);
3138 QAction *insertNodeSection =
new QAction(tr(
"Insert Node"), NULL);
3139 insertNodeSection->setEnabled(
false);
3140 contextMenu.addAction(insertNodeSection);
3142 QString spacer(
" ");
3146 QMenu *shareMenu =
new QMenu(&contextMenu);
3147 shareMenu->setSeparatorsCollapsible(
false);
3148 shareMenu->setTitle(spacer + tr(
"Share"));
3149 contextMenu.addMenu(shareMenu);
3152 QAction *action =
new QAction(tr(
"Share Value"), NULL);
3153 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.data.share"))));
3154 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3155 shareMenu->addAction(action);
3159 QAction *action =
new QAction(tr(
"Share List"), NULL);
3160 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.data.share.list"))));
3161 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3162 shareMenu->addAction(action);
3166 QAction *action =
new QAction(tr(
"Share Event"), NULL);
3167 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.event.share"))));
3168 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3169 shareMenu->addAction(action);
3175 QMenu *holdMenu =
new QMenu(&contextMenu);
3176 holdMenu->setSeparatorsCollapsible(
false);
3177 holdMenu->setTitle(spacer + tr(
"Hold"));
3178 contextMenu.addMenu(holdMenu);
3181 QAction *action =
new QAction(tr(
"Hold Value"), NULL);
3182 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.data.hold2"))));
3183 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3184 holdMenu->addAction(action);
3188 QAction *action =
new QAction(tr(
"Hold List"), NULL);
3189 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.data.hold.list2"))));
3190 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3191 holdMenu->addAction(action);
3197 QMenu *allowMenu =
new QMenu(&contextMenu);
3198 allowMenu->setSeparatorsCollapsible(
false);
3199 allowMenu->setTitle(spacer + tr(
"Allow"));
3200 contextMenu.addMenu(allowMenu);
3203 QAction *action =
new QAction(tr(
"Allow First Event"), NULL);
3204 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.event.allowFirst"))));
3205 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3206 allowMenu->addAction(action);
3210 QAction *action =
new QAction(tr(
"Allow First Value"), NULL);
3211 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.event.allowFirstValue"))));
3212 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3213 allowMenu->addAction(action);
3217 QAction *action =
new QAction(tr(
"Allow Periodic Events"), NULL);
3218 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.time.allowPeriodic"))));
3219 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3220 allowMenu->addAction(action);
3224 QAction *action =
new QAction(tr(
"Allow Changes"), NULL);
3225 action->setData(qVariantFromValue(qMakePair(event->scenePos(), QStringLiteral(
"vuo.event.allowChanges2"))));
3226 connect(action, &QAction::triggered,
this, &VuoEditorComposition::insertNode);
3227 allowMenu->addAction(action);
3231 contextMenu.addSeparator();
3233 QAction *contextMenuInsertComment =
new QAction(NULL);
3234 contextMenuInsertComment->setText(tr(
"Insert Comment"));
3235 contextMenuInsertComment->setData(qVariantFromValue(event->scenePos()));
3236 connect(contextMenuInsertComment, &QAction::triggered,
this, &VuoEditorComposition::insertComment);
3237 contextMenu.addAction(contextMenuInsertComment);
3239 QAction *contextMenuInsertSubcomposition =
new QAction(NULL);
3240 contextMenuInsertSubcomposition->setText(tr(
"Insert Subcomposition"));
3241 contextMenuInsertSubcomposition->setData(qVariantFromValue(event->scenePos()));
3242 connect(contextMenuInsertSubcomposition, &QAction::triggered,
this, &VuoEditorComposition::insertSubcomposition);
3243 contextMenu.addAction(contextMenuInsertSubcomposition);
3248 QAction *contextMenuDeleteSelectedSnapshot =
new QAction(NULL);
3251 if (dynamic_cast<VuoRendererPort *>(item))
3255 if (port->
isConstant() && inputEditorManager)
3259 if (inputEditorLoadedForPortDataType)
3261 contextMenuSetPortConstant->setData(qVariantFromValue((
void *)port));
3262 contextMenu.addAction(contextMenuSetPortConstant);
3264 inputEditorLoadedForPortDataType->deleteLater();
3270 contextMenuPublishPort->setText(tr(
"Publish Port"));
3271 contextMenuPublishPort->setData(qVariantFromValue((
void *)port));
3272 contextMenu.addAction(contextMenuPublishPort);
3277 vector<VuoRendererPublishedPort *> externalPublishedPorts = port->
getPublishedPorts();
3278 bool hasExternalPublishedPortWithMultipleInternalPorts =
false;
3279 bool hasExternalPublishedPortBelongingToActiveProtocol =
false;
3283 hasExternalPublishedPortWithMultipleInternalPorts =
true;
3285 if (dynamic_cast<VuoPublishedPort *>(externalPort->
getBase())->isProtocolPort())
3286 hasExternalPublishedPortBelongingToActiveProtocol =
true;
3293 if (!hasExternalPublishedPortWithMultipleInternalPorts &&!hasExternalPublishedPortBelongingToActiveProtocol)
3295 contextMenuPublishPort->setText(tr(
"Delete Published Port"));
3296 contextMenuPublishPort->setData(qVariantFromValue((
void *)port));
3297 contextMenu.addAction(contextMenuPublishPort);
3301 bool isTriggerPort = dynamic_cast<VuoCompilerTriggerPort *>(port->
getBase()->
getCompiler());
3302 if (isTriggerPort || port->
getInput())
3304 __block
bool isTopLevelCompositionRunning =
false;
3305 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, ^
void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier)
3307 isTopLevelCompositionRunning = topLevelComposition->
isRunning();
3310 if (isTopLevelCompositionRunning)
3312 contextMenuFireEvent->setData(qVariantFromValue((
void *)port));
3313 contextMenu.addAction(contextMenuFireEvent);
3319 QMenu *contextMenuThrottling =
new QMenu(&contextMenu);
3320 contextMenuThrottling->setSeparatorsCollapsible(
false);
3321 contextMenuThrottling->setTitle(tr(
"Set Event Throttling"));
3323 foreach (QAction *action, contextMenuThrottlingActions)
3325 contextMenuThrottling->addAction(action);
3326 action->setData(qVariantFromValue((
void *)port));
3327 action->setCheckable(
true);
3328 action->setChecked( i++ == port->getBase()->getEventThrottling() );
3330 contextMenu.addMenu(contextMenuThrottling);
3335 if (genericDataType || isPortCurrentlyRevertible(port))
3337 QMenu *contextMenuSpecializeGenericType =
new QMenu(&contextMenu);
3338 contextMenuSpecializeGenericType->setSeparatorsCollapsible(
false);
3339 contextMenuSpecializeGenericType->setTitle(tr(
"Set Data Type"));
3340 contextMenuSpecializeGenericType->setToolTipsVisible(
true);
3342 QAction *unspecializeAction = contextMenuSpecializeGenericType->addAction(tr(
"Generic"));
3347 contextMenuSpecializeGenericType->addSeparator();
3349 unspecializeAction->setData(qVariantFromValue((
void *)port));
3350 unspecializeAction->setCheckable(
true);
3351 unspecializeAction->setChecked(genericDataType);
3353 contextMenu.addMenu(contextMenuSpecializeGenericType);
3356 set<string> compatibleTypes;
3357 set<string> compatibleTypesInIsolation;
3360 if (genericDataType)
3362 VuoCompilerPortClass *portClass = static_cast<VuoCompilerPortClass *>(port->getBase()->getClass()->getCompiler());
3363 genericTypeFromPortClass = static_cast<VuoGenericType *>(portClass->
getDataVuoType());
3368 compatibleTypes = set<string>(compatibleTypesVector.begin(), compatibleTypesVector.end());
3374 compatibleTypes.insert(compatibleTypeNames.begin(), compatibleTypeNames.end());
3379 else if (isPortCurrentlyRevertible(port))
3381 map<VuoNode *, string> nodesToReplace;
3382 set<VuoCable *> cablesToDelete;
3384 if (cablesToDelete.size() >= 1)
3390 port->getUnderlyingParentNode()->getBase()->getNodeClass()->getCompiler());
3391 genericTypeFromPortClass = dynamic_cast<VuoGenericType *>( specializedNodeClass->
getOriginalPortType(port->getBase()->getClass()) );
3392 compatibleTypes = getRespecializationOptionsForPortInNetwork(port);
3396 if (genericTypeFromPortClass)
3408 if (genericHostPortDataType)
3409 genericTypeFromPortClass = static_cast<VuoGenericType *>(portClass->
getDataVuoType());
3410 else if (isPortCurrentlyRevertible(hostPort->
getRenderer()))
3414 genericTypeFromPortClass = dynamic_cast<VuoGenericType *>( specializedNodeClass->
getOriginalPortType(portClass->
getBase()) );
3420 vector<string> compatibleTypesInIsolationVector;
3421 if (genericTypeFromPortClass)
3428 foreach (
string type, compatibleTypesInIsolationVector)
3435 const int maxTypeCountForFlatMenuDisplay = 10;
3436 if (compatibleTypesInIsolation.size() <= maxTypeCountForFlatMenuDisplay)
3438 QList<QAction *> actions =
getCompatibleTypesForMenu(port, compatibleTypesInIsolation, compatibleTypes,
false,
"", contextMenuSpecializeGenericType);
3446 QList<QAction *> actions =
getCompatibleTypesForMenu(port, compatibleTypesInIsolation, compatibleTypes,
true,
"", contextMenuSpecializeGenericType);
3451 QList<QAction *> allNodeSetActionsToAdd;
3452 for (map<
string, set<VuoCompilerType *> >::iterator i = loadedTypesForNodeSet.begin(); i != loadedTypesForNodeSet.end(); ++i)
3454 string nodeSetName = i->first;
3455 if (!nodeSetName.empty())
3456 allNodeSetActionsToAdd +=
getCompatibleTypesForMenu(port, compatibleTypesInIsolation, compatibleTypes,
true, nodeSetName, contextMenuSpecializeGenericType);
3459 if ((contextMenuSpecializeGenericType->actions().size() > 0) && (allNodeSetActionsToAdd.size() > 0))
3460 contextMenuSpecializeGenericType->addSeparator();
3465 foreach (QAction *action, contextMenuSpecializeGenericType->actions())
3467 QMenu *specializeSubmenu = action->menu();
3468 if (specializeSubmenu)
3470 foreach (QAction *specializeSubaction, specializeSubmenu->actions())
3471 connect(specializeSubaction, &QAction::triggered,
this, &VuoEditorComposition::specializeGenericPortType);
3473 else if (action == unspecializeAction)
3474 connect(action, &QAction::triggered,
this, &VuoEditorComposition::unspecializePortType);
3476 connect(action, &QAction::triggered,
this, &VuoEditorComposition::specializeGenericPortType);
3483 int numVisibleDirectlyConnectedCables = 0;
3484 int numHidableDirectlyConnectedCables = 0;
3485 int numUnhidableDirectlyConnectedCables = 0;
3491 numVisibleDirectlyConnectedCables++;
3493 numHidableDirectlyConnectedCables++;
3497 numUnhidableDirectlyConnectedCables++;
3500 int numVisibleChildPortConnectedCables = 0;
3501 int numHidableChildPortConnectedCables = 0;
3502 int numUnhidableChildPortConnectedCables = 0;
3512 numVisibleChildPortConnectedCables++;
3515 numHidableChildPortConnectedCables++;
3518 numUnhidableChildPortConnectedCables++;
3523 int numVisibleConnectedCables = numVisibleDirectlyConnectedCables + numVisibleChildPortConnectedCables;
3526 int numHidableConnectedCables = numHidableDirectlyConnectedCables + numHidableChildPortConnectedCables;
3529 int numUnhidableConnectedCables = numUnhidableDirectlyConnectedCables + numUnhidableChildPortConnectedCables;
3533 if (numHidableConnectedCables >= 1)
3538 int numApparentlyHidableConnectedCables = numVisibleConnectedCables + numUnhidableConnectedCables;
3539 contextMenuHideCables->setText(numApparentlyHidableConnectedCables > 1?
"Hide Cables" :
"Hide Cable");
3540 contextMenuHideCables->setData(qVariantFromValue((
void *)port));
3541 contextMenu.addAction(contextMenuHideCables);
3544 if (numUnhidableConnectedCables >= 1)
3546 int numApparentlyUnhidableConnectedCables = numVisibleConnectedCables + numUnhidableConnectedCables;
3547 contextMenuUnhideCables->setText(numApparentlyUnhidableConnectedCables > 1?
"Unhide Cables" :
"Unhide Cable");
3548 contextMenuUnhideCables->setData(qVariantFromValue((
void *)port));
3549 contextMenu.addAction(contextMenuUnhideCables);
3553 if (numVisibleConnectedCables >= 1)
3555 contextMenuDeleteCables->setText(numVisibleConnectedCables > 1?
"Delete Cables" :
"Delete Cable");
3556 contextMenuDeleteCables->setData(qVariantFromValue((
void *)port));
3557 contextMenu.addAction(contextMenuDeleteCables);
3564 if (! item->isSelected())
3567 item->setSelected(
true);
3570 QList<QGraphicsItem *> selectedComponents = selectedItems();
3571 bool onlyCommentsSelected =
true;
3572 bool onlyCablesSelected =
true;
3573 bool selectionContainsMissingNode =
false;
3574 foreach (QGraphicsItem *item, selectedComponents)
3576 if (!dynamic_cast<VuoRendererComment *>(item))
3577 onlyCommentsSelected =
false;
3579 if (!dynamic_cast<VuoRendererCable *>(item))
3580 onlyCablesSelected =
false;
3582 if (dynamic_cast<VuoRendererNode *>(item) && !dynamic_cast<VuoRendererNode *>(item)->
getBase()->hasCompiler())
3583 selectionContainsMissingNode =
true;
3586 contextMenuDeleteSelectedSnapshot->setText(contextMenuDeleteSelected->text());
3594 if (onlyCommentsSelected)
3595 contextMenu.addAction(contextMenuEditSelectedComments);
3600 contextMenu.addSeparator();
3603 contextMenu.addAction(contextMenuRefactorSelected);
3605 contextMenu.addSeparator();
3608 contextMenu.addAction(contextMenuDeleteSelectedSnapshot);
3618 contextMenu.addAction(contextMenuHideSelectedCables);
3621 contextMenu.addAction(contextMenuDeleteSelectedSnapshot);
3625 else if (dynamic_cast<VuoRendererNode *>(item))
3630 if (dynamic_cast<VuoRendererInputDrawer *>(node) &&
3634 if (dynamic_cast<VuoRendererInputListDrawer *>(node))
3636 contextMenuAddInputPort->setData(qVariantFromValue((
void *)node));
3637 contextMenuRemoveInputPort->setData(qVariantFromValue((
void *)node));
3640 contextMenuRemoveInputPort->setEnabled(listItemCount >= 1);
3642 contextMenu.addAction(contextMenuAddInputPort);
3643 contextMenu.addAction(contextMenuRemoveInputPort);
3645 contextMenu.addSeparator();
3649 contextMenu.addAction(contextMenuDeleteSelectedSnapshot);
3656 if (nodeClass->
hasCompiler() && dynamic_cast<VuoCompilerSpecializedNodeClass *>(nodeClass->
getCompiler()))
3658 string originalGenericNodeClassName = dynamic_cast<VuoCompilerSpecializedNodeClass *>(nodeClass->
getCompiler())->getOriginalGenericNodeClassName();
3660 if (originalGenericNodeClass)
3661 nodeClass = originalGenericNodeClass->
getBase();
3664 QString actionText, sourcePath;
3668 int numSelectedNonAttachmentNodes = 0;
3669 QList<QGraphicsItem *> selectedComponents = selectedItems();
3670 foreach (QGraphicsItem *item, selectedComponents)
3672 if (dynamic_cast<VuoRendererNode *>(item) && !dynamic_cast<VuoRendererInputAttachment *>(item))
3673 numSelectedNonAttachmentNodes++;
3676 if ((numSelectedNonAttachmentNodes == 1) && nodeClassIsEditable)
3679 QAction *editAction =
new QAction(NULL);
3680 editAction->setText(actionText);
3681 editAction->setData(qVariantFromValue(node));
3684 contextMenu.addAction(editAction);
3685 contextMenu.addSeparator();
3690 contextMenu.addAction(contextMenuRenameSelected);
3695 contextMenu.addSeparator();
3698 if (numSelectedNonAttachmentNodes == 1)
3700 if (contextMenuChangeNode)
3701 contextMenuChangeNode->deleteLater();
3704 contextMenuChangeNode->setSeparatorsCollapsible(
false);
3705 contextMenuChangeNode->setTitle(tr(
"Change To"));
3708 if (!contextMenuChangeNode->actions().isEmpty())
3709 contextMenu.addMenu(contextMenuChangeNode);
3713 if (!selectionContainsMissingNode)
3714 contextMenu.addAction(contextMenuRefactorSelected);
3716 if ((numSelectedNonAttachmentNodes == 1) && (nodeClassIsEditable || nodeClassIs3rdParty))
3720 if (!modulePath.isEmpty())
3722 QString enclosingDirUrl =
"file://" + QFileInfo(modulePath).dir().absolutePath();
3723 QAction *openEnclosingFolderAction =
new QAction(NULL);
3724 openEnclosingFolderAction->setText(
"Show in Finder");
3725 openEnclosingFolderAction->setData(qVariantFromValue(enclosingDirUrl));
3727 contextMenu.addAction(openEnclosingFolderAction);
3731 if (!contextMenu.actions().empty() && !contextMenu.actions().last()->isSeparator())
3732 contextMenu.addSeparator();
3735 contextMenu.addAction(contextMenuDeleteSelectedSnapshot);
3741 if (!contextMenu.actions().isEmpty())
3746 menuSelectionInProgress =
true;
3747 contextMenu.exec(event->screenPos());
3748 menuSelectionInProgress =
false;
3751 delete contextMenuDeleteSelectedSnapshot;
3759 QAction *sender = (QAction *)QObject::sender();
3771 vector<string> typeOptions;
3773 map<string, VuoCompilerType *> loadedTypes = compiler->
getTypes();
3774 for (map<string, VuoCompilerType *>::iterator i = loadedTypes.begin(); i != loadedTypes.end(); ++i)
3779 (i->first !=
"VuoMathExpressionList"))
3781 typeOptions.push_back(i->first);
3793 set<string> VuoEditorComposition::getRespecializationOptionsForPortInNetwork(
VuoRendererPort *port)
3796 return set<string>();
3803 vector<string> compatibleInnerTypeNames;
3804 vector<string> compatibleTypeNames;
3805 for (
VuoPort *connectedPort : connectedGenericPorts)
3810 if (specializedNodeClass)
3813 genericTypeFromPortClass = dynamic_cast<VuoGenericType *>( specializedNodeClass->
getOriginalPortType(portClass) );
3818 vector<string> innermostCompatibleTypeNamesForPort;
3819 for (vector<string>::iterator k = compatibleTypeNamesForPort.begin(); k != compatibleTypeNamesForPort.end(); ++k)
3822 if (! innermostCompatibleTypeNamesForPort.empty())
3824 if (compatibleInnerTypeNames.empty())
3825 compatibleInnerTypeNames = innermostCompatibleTypeNamesForPort;
3828 for (
int k = compatibleInnerTypeNames.size() - 1; k >= 0; --k)
3829 if (find(innermostCompatibleTypeNamesForPort.begin(), innermostCompatibleTypeNamesForPort.end(), compatibleInnerTypeNames[k]) ==
3830 innermostCompatibleTypeNamesForPort.end())
3831 compatibleInnerTypeNames.erase(compatibleInnerTypeNames.begin() + k);
3840 string typeNameForPort = genericTypeFromPortClass->
getModuleKey();
3844 for (vector<string>::iterator k = compatibleInnerTypeNames.begin(); k != compatibleInnerTypeNames.end(); ++k)
3845 compatibleTypeNames.push_back(prefix + *k);
3847 if (compatibleTypeNames.empty())
3857 return set<string>(compatibleTypeNames.begin(), compatibleTypeNames.end());
3880 set<string> compatibleTypesInIsolation,
3881 set<string> compatibleTypesInContext,
3882 bool limitToNodeSet,
3886 QList<QAction *> actionsToAddToMenu;
3888 map<string, VuoCompilerType *> allTypes = compiler->
getTypes();
3890 QList<VuoCompilerType *> compatibleTypesForNodeSetDisplay;
3891 foreach (
string typeName, compatibleTypesInIsolation)
3894 if ((!limitToNodeSet || (loadedTypesForNodeSet[nodeSetName].find(type) != loadedTypesForNodeSet[nodeSetName].end())) &&
3897 (typeName !=
"VuoUrl" && typeName !=
"VuoList_VuoUrl"
3899 && typeName !=
"VuoInteraction" && typeName !=
"VuoList_VuoInteraction"
3900 && typeName !=
"VuoInteractionType" && typeName !=
"VuoList_VuoInteractionType"
3901 && typeName !=
"VuoUuid" && typeName !=
"VuoList_VuoUuid"
3903 && typeName !=
"VuoIconPosition" && typeName !=
"VuoList_VuoIconPosition"
3904 && typeName !=
"VuoWindowProperty" && typeName !=
"VuoList_VuoWindowProperty"
3905 && typeName !=
"VuoWindowReference" && typeName !=
"VuoList_VuoWindowReference"))
3906 compatibleTypesForNodeSetDisplay.append(type);
3909 if (!compatibleTypesForNodeSetDisplay.isEmpty())
3911 QMenu *contextMenuNodeSetTypes = NULL;
3912 QList<QAction *> actionsToAddToNodeSetSubmenu;
3913 bool enabledContentAdded =
false;
3916 if (!nodeSetName.empty())
3918 contextMenuNodeSetTypes =
new QMenu(menu);
3919 contextMenuNodeSetTypes->setSeparatorsCollapsible(
false);
3921 contextMenuNodeSetTypes->setToolTipsVisible(
true);
3922 actionsToAddToMenu.append(contextMenuNodeSetTypes->menuAction());
3928 QList<QVariant> portAndSpecializedType;
3929 portAndSpecializedType.append(qVariantFromValue((
void *)genericPort));
3930 portAndSpecializedType.append(typeName.c_str());
3932 QAction *specializeAction;
3936 if (!nodeSetName.empty())
3938 specializeAction =
new QAction(typeTitle, contextMenuNodeSetTypes);
3939 actionsToAddToNodeSetSubmenu.append(specializeAction);
3945 specializeAction =
new QAction(typeTitle, menu);
3946 actionsToAddToMenu.append(specializeAction);
3949 specializeAction->setData(QVariant(portAndSpecializedType));
3950 specializeAction->setCheckable(
true);
3951 specializeAction->setChecked(genericPort && (genericPort->getDataType()->getModuleKey() == type->
getBase()->
getModuleKey()));
3953 if (compatibleTypesInContext.find(typeName) == compatibleTypesInContext.end())
3955 specializeAction->setEnabled(
false);
3957 specializeAction->setToolTip(tr(
"To change to this type, disconnect the cable from this port and from this node's other ports of the same type."));
3960 enabledContentAdded =
true;
3963 if (contextMenuNodeSetTypes)
3967 if (!enabledContentAdded)
3968 contextMenuNodeSetTypes->setEnabled(
false);
3972 QList<QAction *> actionListWithPromotions = promoteSingletonsFromSubmenus(actionsToAddToMenu);
3973 return actionListWithPromotions;
3980 QList<QAction *> VuoEditorComposition::promoteSingletonsFromSubmenus(QList<QAction *> actionList)
3982 QList<QAction *> modifiedActionList;
3983 foreach (QAction *action, actionList)
3985 if (action->menu() && (action->menu()->actions().size() == 1))
3987 QAction *singleSubaction = action->menu()->actions().first();
3988 action->menu()->removeAction(singleSubaction);
3989 modifiedActionList.append(singleSubaction);
3992 modifiedActionList.append(action);
3995 return modifiedActionList;
4003 std::sort(actionList.begin(), actionList.end(), nodeSetMenuActionLessThan);
4004 foreach (QAction *action, actionList)
4005 menu->addAction(action);
4011 void VuoEditorComposition::updatePopoversForActiveWindowChange(QWidget *old, QWidget *now)
4024 void VuoEditorComposition::updatePopoversForApplicationStateChange(
bool active)
4026 if (ignoreApplicationStateChangeEvents)
4030 if (activeWindow && (activeWindow->
getComposition() ==
this) && (!activeWindow->isMinimized()))
4044 return findNearbyComponent(scenePos, VuoEditorComposition::targetTypePort, limitPortCollisionRange);
4052 QGraphicsItem *item =
findNearbyComponent(scenePos, VuoEditorComposition::targetTypeNodeHeader);
4053 return dynamic_cast<VuoRendererNode *>(item);
4070 bool limitPortCollisionRange)
4076 bool ignoreComments;
4080 case VuoEditorComposition::targetTypePort:
4082 ignoreCables =
true;
4084 ignorePorts =
false;
4085 ignoreComments =
true;
4088 case VuoEditorComposition::targetTypeNodeHeader:
4090 ignoreCables =
true;
4093 ignoreComments =
true;
4098 ignoreCables =
false;
4099 ignoreNodes =
false;
4100 ignorePorts =
false;
4101 ignoreComments =
false;
4109 QGraphicsItem *topmostItemUnderCursor = itemAt(scenePos, views()[0]->transform());
4110 if (topmostItemUnderCursor && (!topmostItemUnderCursor->isEnabled()))
4111 topmostItemUnderCursor = NULL;
4115 QRectF searchRect(scenePos.x()-0.5*rectLength, scenePos.y()-0.5*rectLength, rectLength, rectLength);
4116 QList<QGraphicsItem *> itemsInRange = items(searchRect);
4117 for (QList<QGraphicsItem *>::iterator i = itemsInRange.begin(); i != itemsInRange.end(); ++i)
4119 if (!(*i)->isEnabled())
4126 bool makeListDragHandle =
4129 if (makeListDragHandle &&
4130 ((! topmostItemUnderCursor) ||
4131 (topmostItemUnderCursor == makeListDrawer) ||
4132 (topmostItemUnderCursor->zValue() < makeListDrawer->zValue())))
4134 return makeListDrawer;
4145 ((! topmostItemUnderCursor) ||
4146 (topmostItemUnderCursor == port) ||
4148 (topmostItemUnderCursor->zValue() < port->zValue()))
4150 ((! limitPortCollisionRange) ||
4164 ((! topmostItemUnderCursor) ||
4165 (topmostItemUnderCursor == cable) ||
4166 (topmostItemUnderCursor->zValue() < cable->zValue())))
4173 if (! ignoreComments)
4176 if (!comment && dynamic_cast<VuoRendererComment *>((*i)->parentItem()))
4177 comment = dynamic_cast<VuoRendererComment *>((*i)->parentItem());
4180 ((! topmostItemUnderCursor) ||
4181 (topmostItemUnderCursor == (*i)) ||
4182 (topmostItemUnderCursor->zValue() < (*i)->zValue())))
4189 if (targetType == VuoEditorComposition::targetTypeNodeHeader)
4192 if (node && ! dynamic_cast<VuoRendererInputDrawer *>(node))
4195 headerRect = node->mapToScene(headerRect).
boundingRect();
4196 if (headerRect.intersects(searchRect) && scenePos.y() <= headerRect.bottom())
4207 if (dynamic_cast<VuoRendererNode *>(topmostItemUnderCursor))
4208 return topmostItemUnderCursor;
4212 if (dynamic_cast<VuoRendererPort *>(topmostItemUnderCursor))
4213 return ((
VuoRendererPort *)(topmostItemUnderCursor))->getRenderedParentNode();
4230 if (! cableInProgress)
4233 VuoPort *fromPort = cableInProgress->getFromPort();
4234 VuoPort *toPort = cableInProgress->getToPort();
4235 VuoPort *fixedPort = (fromPort? fromPort: toPort);
4237 if (dynamic_cast<VuoRendererPort *>(fixedPort->
getRenderer())->getUnderlyingParentNode() == node)
4250 vector<VuoRendererPort *> portList;
4265 if (portList.size() > firstPortIndex)
4267 targetPort = portList[firstPortIndex];
4273 for (
int i = firstPortIndex; i < portList.size(); ++i)
4277 firstPortWithoutWall = portList[i];
4281 if (firstPortWithoutWall)
4282 targetPort = firstPortWithoutWall;
4291 if (portList.size() > firstPortIndex)
4292 targetPort = portList[firstPortIndex];
4313 QRectF boundingRect;
4314 foreach (QGraphicsItem *item, items())
4318 boundingRect |= item->sceneBoundingRect();
4321 return boundingRect;
4330 QRectF boundingRect;
4332 foreach (QGraphicsItem *item, selectedItems())
4336 boundingRect |= item->sceneBoundingRect();
4339 return boundingRect;
4348 QRectF boundingRect;
4350 foreach (QGraphicsItem *item, selectedItems())
4354 boundingRect |= item->mapToScene(item->childrenBoundingRect()).boundingRect();
4364 boundingRect |= drawer->mapToScene(drawer->childrenBoundingRect()).boundingRect();
4369 return boundingRect;
4378 VuoPort *port = portWithStaticIdentifier[portID];
4405 if (dynamic_cast<VuoCompilerInputEventPort *>(port))
4409 if (updateInRunningComposition)
4414 else if (dynamic_cast<VuoCompilerPublishedPort *>(port))
4416 dynamic_cast<VuoCompilerPublishedPort *>(port)->setInitialValue(newValue);
4418 if (updateInRunningComposition)
4444 if (!errorMarkingUpdatesEnabled)
4447 errorMarkingUpdatesEnabled =
false;
4464 set<VuoCompilerCable *> potentialCables;
4466 if (targetPort && cableInProgress)
4472 if (cableInProgress->getFromNode())
4474 fromNode = cableInProgress->getFromNode();
4475 fromPort = cableInProgress->getFromPort();
4477 toPort = targetPort->
getBase();
4482 fromPort = targetPort->
getBase();
4483 toNode = cableInProgress->getToNode();
4484 toPort = cableInProgress->getToPort();
4489 potentialCable->
setAlwaysEventOnly(! cableInProgress->getRenderer()->effectivelyCarriesData() ||
4490 cableInProgress->getRenderer()->isFloatingEndpointAboveEventPort());
4494 potentialCables.insert(potentialCable);
4505 VUserLog(
"%s: Showing error popover: %s",
4513 set<VuoRendererNode *> nodesToMark;
4514 set<VuoRendererCable *> cablesToMark;
4516 set<VuoNode *> problemNodes = issue.
getNodes();
4517 foreach (
VuoNode *node, problemNodes)
4521 set<VuoCable *> problemCables = issue.
getCables();
4522 foreach (
VuoCable *cable, problemCables)
4524 VuoCable *cableToMark = (cable->
getCompiler() == potentialCable ? cableInProgress : cable);
4530 errorMark->addMarkedComponents(nodesToMark, cablesToMark);
4533 errorPopovers.insert(errorPopover);
4537 QRectF viewportRect = views()[0]->mapToScene(views()[0]->viewport()->rect()).boundingRect();
4541 if (targetPort && cableInProgress && nodesToMark.find(targetPort->
getRenderedParentNode()) != nodesToMark.end())
4545 else if (! nodesToMark.empty())
4548 qreal topY = viewportRect.bottom();
4554 QPointF scenePos = node->scenePos();
4555 if (viewportRect.contains(scenePos) && (scenePos.y() < topY))
4557 topmostVisibleNode = node;
4558 topY = scenePos.y();
4562 if (topmostVisibleNode)
4563 nearbyNode = topmostVisibleNode;
4572 VUserLog(
"Warning: no nearby node (no marked nodes).");
4577 const QPoint offsetFromNode(0,10);
4578 QPoint popoverTopLeftInScene = (nearbyNode?
4579 (nearbyNode->scenePos().toPoint() +
4582 QPoint(viewportRect.center().x() - 0.5*errorPopover->sizeHint().width(),
4583 viewportRect.center().y() - 0.5*errorPopover->sizeHint().height()));
4587 const int margin = 5;
4588 popoverTopLeftInScene = (QPoint(fmin(popoverTopLeftInScene.x(), viewportRect.bottomRight().x() - errorPopover->sizeHint().width() - margin),
4589 fmin(popoverTopLeftInScene.y(), viewportRect.bottomRight().y() - errorPopover->sizeHint().height() - margin)));
4591 popoverTopLeftInScene = (QPoint(fmax(popoverTopLeftInScene.x(), viewportRect.topLeft().x() + margin),
4592 fmax(popoverTopLeftInScene.y(), viewportRect.topLeft().y() + margin)));
4594 QPoint popoverTopLeftInView = views()[0]->mapFromScene(popoverTopLeftInScene);
4595 QPoint popoverTopLeftGlobal = views()[0]->mapToGlobal(popoverTopLeftInView);
4597 errorPopover->move(popoverTopLeftGlobal);
4598 errorPopover->show();
4606 delete potentialCable;
4608 errorMarkingUpdatesEnabled =
true;
4614 bool VuoEditorComposition::hasFeedbackErrors(
void)
4616 return this->errorMark;
4624 if (hasFeedbackErrors())
4633 void VuoEditorComposition::buildComposition(
string compositionSnapshot,
const set<string> &dependenciesUninstalled)
4639 if (! dependenciesUninstalled.empty())
4641 vector<string> dependenciesRemovedVec(dependenciesUninstalled.begin(), dependenciesUninstalled.end());
4643 throw VuoException(
"Some modules that the composition needs were uninstalled: " + dependenciesStr);
4646 delete runningComposition;
4647 runningComposition = NULL;
4651 if (runningCompositionActiveDriver)
4655 string dir, file, ext;
4657 linkedCompositionPath = dir + file +
".dylib";
4662 compiler->
compileComposition(runningComposition, compiledCompositionPath,
true, issues);
4666 remove(compiledCompositionPath.c_str());
4672 delete runningComposition;
4673 runningComposition = NULL;
4685 bool VuoEditorComposition::isRunningThreadUnsafe(
void)
4687 return runner != NULL && ! stopRequested && ! runner->
isStopped();
4697 __block
bool running;
4698 dispatch_sync(runCompositionQueue, ^{
4699 running = isRunningThreadUnsafe();
4725 if (matchingComposition->showEventsMode)
4729 stopRequested =
false;
4730 dispatch_async(runCompositionQueue, ^{
4735 buildComposition(compositionSnapshot);
4749 if (matchingComposition->showEventsMode)
4750 this->runner->subscribeToEventTelemetry(matchingCompositionIdentifier);
4752 dispatch_sync(activePortPopoversQueue, ^{
4753 for (
auto i : matchingComposition->activePortPopovers)
4755 string portID = i.first;
4756 updateDataInPortPopoverFromRunningTopLevelComposition(matchingComposition, matchingCompositionIdentifier, portID);
4777 stopRequested =
true;
4778 dispatch_async(runCompositionQueue, ^{
4787 linkedCompositionPath =
"";
4788 runningCompositionLibraries = NULL;
4790 delete runningComposition;
4791 runningComposition = NULL;
4801 if (matchingComposition->showEventsMode)
4804 dispatch_sync(activePortPopoversQueue, ^{
4805 for (
auto i : matchingComposition->activePortPopovers)
4807 VuoPortPopover *popover = i.second;
4808 popover->setCompositionRunning(false);
4831 dispatch_async(runCompositionQueue, ^{
4832 if (isRunningThreadUnsafe())
4841 string oldBuiltCompositionSnapshot = oldCompositionSnapshot;
4843 if (previouslyActiveDriver)
4850 buildComposition(newCompositionSnapshot, dependenciesUninstalled);
4852 string compositionDiff = diffInfo->
diff(oldBuiltCompositionSnapshot, runningComposition, compiler);
4855 catch (exception &e)
4857 VUserLog(
"Composition stopped itself: %s", e.what());
4862 VUserLog(
"Composition stopped itself.");
4868 dispatch_async(dispatch_get_main_queue(), ^{
4887 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyIfInstalledAsSubcomposition(
this, reloadSubcompositionIfUnsaved);
4896 VuoPort *port = portWithStaticIdentifier[runningPortID];
4905 if (
this == topLevelComposition)
4907 dispatch_async(runCompositionQueue, ^{
4908 if (isRunningThreadUnsafe())
4910 json_object *constantObject = json_tokener_parse(constant.c_str());
4911 runner->
setInputPortValue(thisCompositionIdentifier, runningPortID, constantObject);
4916 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this,
updateRunningComposition);
4919 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyIfInstalledAsSubcomposition(
this, ^(
VuoEditorComposition *currComposition,
string subcompositionPath)
4921 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToAllOtherTopLevelCompositions(
this, ^(
VuoEditorComposition *topLevelComposition)
4938 string constant = dynamic_cast<VuoCompilerPublishedPort *>(port->
getCompiler())->getInitialValue();
4947 map<VuoPort *, string>::iterator i = staticIdentifierForPort.find(port->
getBase());
4948 if (i == staticIdentifierForPort.end())
4950 string runningPortIdentifier = i->second;
4955 if (
this == topLevelComposition)
4957 dispatch_async(runCompositionQueue, ^{
4958 if (isRunningThreadUnsafe())
4960 json_object *constantObject = json_tokener_parse(constant.c_str());
4961 runner->
setInputPortValue(thisCompositionIdentifier, runningPortIdentifier, constantObject);
4966 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this,
updateRunningComposition);
4969 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyIfInstalledAsSubcomposition(
this, ^(
VuoEditorComposition *currComposition,
string subcompositionPath)
4971 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToAllOtherTopLevelCompositions(
this, ^(
VuoEditorComposition *topLevelComposition)
4984 dispatch_async(runCompositionQueue, ^{
4985 if (isRunningThreadUnsafe())
4987 json_object *constantObject = json_tokener_parse(constant.c_str());
4989 foreach (
string subcompositionIdentifier, subcompositionIdentifiers)
4991 runner->
setInputPortValue(subcompositionIdentifier, portIdentifier, constantObject);
5002 dispatch_async(runCompositionQueue, ^{
5003 if (isRunningThreadUnsafe())
5008 json_object *constantObject = json_tokener_parse(constant.c_str());
5009 map<VuoRunner::Port *, json_object *> m;
5010 m[publishedPort] = constantObject;
5023 return contextMenuDeleteSelected;
5033 QMenu *contextMenuTints =
new QMenu(parent);
5034 contextMenuTints->setSeparatorsCollapsible(
false);
5035 contextMenuTints->setTitle(tr(
"Tint"));
5036 foreach (QAction *tintAction, contextMenuTintActions)
5037 contextMenuTints->addAction(tintAction);
5038 contextMenuTints->insertSeparator(contextMenuTintActions.last());
5040 return contextMenuTints;
5046 void VuoEditorComposition::expandChangeNodeMenu()
5048 QAction *sender = (QAction *)QObject::sender();
5049 VuoRendererNode *node = static_cast<VuoRendererNode *>(sender->data().value<
void *>());
5053 int currentMatchesListed = contextMenuChangeNode->actions().size()-1;
5054 if (currentMatchesListed <= initialChangeNodeSuggestionCount)
5057 int verticalSpacePerItem = 21;
5061 int targetMatches = availableVerticalSpace/verticalSpacePerItem - 2;
5070 contextMenuChangeNode->exec();
5085 map<string, VuoCompilerNodeClass *> nodeClassesMap = compiler->
getNodeClasses();
5086 vector<VuoCompilerNodeClass *> loadedNodeClasses;
5087 for (map<string, VuoCompilerNodeClass *>::iterator i = nodeClassesMap.begin(); i != nodeClassesMap.end(); ++i)
5088 loadedNodeClasses.push_back(i->second);
5091 vector<string> bestMatches;
5092 map<string, double> matchScores;
5093 matchScores[
""] = 0;
5095 int targetMatchCount = (matchLimit > 0? matchLimit : loadedNodeClasses.size());
5096 for (
int i = 0; i < targetMatchCount; ++i)
5097 bestMatches.push_back(
"");
5100 bool overflow =
false;
5103 string originalGenericNodeClassName;
5104 if (nodeClass->
hasCompiler() && dynamic_cast<VuoCompilerSpecializedNodeClass *>(nodeClass->
getCompiler()))
5105 originalGenericNodeClassName = dynamic_cast<VuoCompilerSpecializedNodeClass *>(nodeClass->
getCompiler())->getOriginalGenericNodeClassName();
5107 originalGenericNodeClassName = nodeClass->
getClassName();
5112 if (loadedNodeClassName == originalGenericNodeClassName)
5115 bool canSwapNondestructively = canSwapWithoutBreakingCables(node, loadedNodeClass->
getBase());
5116 double matchScore = (canSwapNondestructively? calculateNodeSimilarity(nodeClass, loadedNodeClass->
getBase()) : 0);
5117 int highestIndexWithCompetitiveScore = -1;
5118 for (
int i = targetMatchCount-1; (i >= 0) && (highestIndexWithCompetitiveScore == -1); --i)
5119 if (matchScore <= matchScores[bestMatches[i] ])
5120 highestIndexWithCompetitiveScore = i;
5122 if (highestIndexWithCompetitiveScore < targetMatchCount-1)
5124 if (matchScores[bestMatches[targetMatchCount-1] ] > 0)
5127 for (
int j = targetMatchCount-2; j > highestIndexWithCompetitiveScore; --j)
5128 bestMatches[j+1] = bestMatches[j];
5130 bestMatches[highestIndexWithCompetitiveScore+1] = loadedNodeClassName;
5131 matchScores[loadedNodeClassName] = matchScore;
5135 for (
int i = 0; i < targetMatchCount; ++i)
5137 if (matchScores[bestMatches[i] ] > 0)
5142 matchDisplayText += QString(
" (%1)").arg(bestMatches[i].c_str());
5144 QAction *changeAction = menu->addAction(matchDisplayText);
5146 QList<QVariant> currentNodeAndNewClass;
5147 currentNodeAndNewClass.append(qVariantFromValue((
void *)node));
5148 currentNodeAndNewClass.append(bestMatches[i].c_str());
5149 changeAction->setData(QVariant(currentNodeAndNewClass));
5150 connect(changeAction, &QAction::triggered,
this, &VuoEditorComposition::swapNode);
5157 QAction *showMoreAction = menu->addAction(tr(
"More…"));
5158 showMoreAction->setData(qVariantFromValue(static_cast<void *>(node)));
5159 connect(showMoreAction, &QAction::triggered,
this, &VuoEditorComposition::expandChangeNodeMenu);
5170 map<string, int> requiredInputs;
5171 bool inputEventSourceRequired =
false;
5174 bool hasDrawerWithNoIncomingCables =
false;
5175 bool hasDrawerWithNoIncomingDataCables =
false;
5182 hasDrawerWithNoIncomingCables =
true;
5183 hasDrawerWithNoIncomingDataCables =
true;
5184 vector<VuoRendererPort *> childPorts = inputDrawer->
getDrawerPorts();
5188 hasDrawerWithNoIncomingCables =
false;
5190 hasDrawerWithNoIncomingDataCables =
false;
5195 if (!hasDrawerWithNoIncomingDataCables)
5196 requiredInputs[typeKey] = ((requiredInputs.find(typeKey) == requiredInputs.end())? 1 : requiredInputs[typeKey]+1);
5200 if (hasIncomingCables && !hasDrawerWithNoIncomingCables)
5201 inputEventSourceRequired =
true;
5205 map<string, int> requiredOutputs;
5206 bool outputEventSourceRequired =
false;
5212 requiredOutputs[typeKey] = ((requiredOutputs.find(typeKey) == requiredOutputs.end())? 1 : requiredOutputs[typeKey]+1);
5216 outputEventSourceRequired =
true;
5220 bool inputEventSourceAvailable =
false;
5221 map<string, int> availableInputs;
5225 static_cast<VuoCompilerPortClass *>(inputPortClass->
getCompiler())->getDataVuoType() : NULL);
5229 availableInputs[typeKey] = ((availableInputs.find(typeKey) == availableInputs.end())? 1 : availableInputs[typeKey]+1);
5234 inputEventSourceAvailable =
true;
5237 bool outputEventSourceAvailable =
false;
5238 map<string, int> availableOutputs;
5242 static_cast<VuoCompilerPortClass *>(outputPortClass->
getCompiler())->getDataVuoType() : NULL);
5246 availableOutputs[typeKey] = ((availableOutputs.find(typeKey) == availableOutputs.end())? 1 : availableOutputs[typeKey]+1);
5251 outputEventSourceAvailable =
true;
5254 for (std::map<string,int>::iterator it=requiredInputs.begin(); it!=requiredInputs.end(); ++it)
5256 string typeKey = it->first;
5257 int typeRequiredCount = it->second;
5258 if (availableInputs[typeKey] < typeRequiredCount)
5263 for (std::map<string,int>::iterator it=requiredOutputs.begin(); it!=requiredOutputs.end(); ++it)
5265 string typeKey = it->first;
5266 int typeRequiredCount = it->second;
5267 if (availableOutputs[typeKey] < typeRequiredCount)
5271 if (inputEventSourceRequired && !inputEventSourceAvailable)
5274 if (outputEventSourceRequired && !outputEventSourceAvailable)
5284 bool VuoEditorComposition::isPortCurrentlyRevertible(
VuoRendererPort *port)
5290 if (!specializedNodeClass)
5295 if (!originalGenericType)
5304 if (hostPort && (!isPortCurrentlyRevertible(hostPort->
getRenderer())))
5331 string publishedPortName = ((! name.empty())?
5342 bool performedMerge =
false;
5345 publishedPort = (isPublishedInput ?
5349 if (publishedPort && dynamic_cast<VuoRendererPublishedPort *>(publishedPort->
getRenderer())->canAccommodateInternalPort(port->
getRenderer(), forceEventOnlyPublication))
5351 if (isPublishedInput && portType && type && !forceEventOnlyPublication)
5359 performedMerge =
true;
5366 if (! performedMerge)
5369 if (isPublishedInput && type)
5379 dynamic_cast<VuoRendererPublishedPort *>(publishedPort->
getRenderer()) :
5384 if (! existingPublishedCable)
5390 if (mergePerformed != NULL)
5391 *mergePerformed = performedMerge;
5393 return rendererPublishedPort;
5405 if (creatingPublishedInputCable)
5408 VuoPort *fromPort = externalPort;
5411 VuoPort *toPort = internalPort;
5418 publishedCable->
setFrom(fromNode, fromPort);
5425 VuoPort *fromPort = internalPort;
5428 VuoPort *toPort = externalPort;
5435 publishedCable->
setTo(toNode, toPort);
5438 if (forceEventOnlyPublication)
5441 return publishedCable;
5457 vector<VuoPublishedPort *> publishedPortsToAdd;
5458 map<VuoPublishedPort *, string> publishedPortsToRename;
5461 VuoProtocol *previousActiveProtocol = this->activeProtocol;
5462 bool removingPreviousProtocol = previousActiveProtocol && (previousActiveProtocol != protocol);
5464 bool portChangesMadeDuringProtocolRemoval =
false;
5465 if (removingPreviousProtocol)
5468 if (portChangesMadeDuringProtocolRemoval && !useUndoStack)
5470 VUserLog(
"Warning: Unexpected combination: Removing protocol ports, but useUndoStack=false");
5471 useUndoStack =
true;
5475 this->activeProtocol = protocol;
5480 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end(); ++i)
5482 string portName = i->first;
5483 string portType = i->second;
5485 bool compositionHadCompatiblePort =
false;
5487 if (preexistingPublishedPort)
5489 VuoType *preexistingType = static_cast<VuoCompilerPortClass *>(preexistingPublishedPort->
getClass()->
getCompiler())->getDataVuoType();
5491 bool portTypesMatch = ((preexistingType && (preexistingType->
getModuleKey() == portType)) ||
5492 (!preexistingType && (portType ==
"")));
5495 compositionHadCompatiblePort =
true;
5500 compositionHadCompatiblePort =
false;
5505 if (!compositionHadCompatiblePort)
5514 publishedPortsToAdd.push_back(publishedPort);
5521 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end(); ++i)
5523 string portName = i->first;
5524 string portType = i->second;
5526 bool compositionHadCompatiblePort =
false;
5528 if (preexistingPublishedPort)
5530 VuoType *preexistingType = static_cast<VuoCompilerPortClass *>(preexistingPublishedPort->
getClass()->
getCompiler())->getDataVuoType();
5531 bool portTypesMatch = ((preexistingType && (preexistingType->
getModuleKey() == portType)) ||
5532 (!preexistingType && (portType ==
"")));
5535 compositionHadCompatiblePort =
true;
5540 compositionHadCompatiblePort =
false;
5545 if (!compositionHadCompatiblePort)
5554 publishedPortsToAdd.push_back(publishedPort);
5562 bool undoStackMacroBegunAlready = (removingPreviousProtocol && portChangesMadeDuringProtocolRemoval);
5563 if (!publishedPortsToRename.empty() || !publishedPortsToAdd.empty() || undoStackMacroBegunAlready)
5565 set<VuoPublishedPort *> publishedPortsToRemove;
5566 bool beginUndoStackMacro = !undoStackMacroBegunAlready;
5567 bool endUndoStackMacro =
true;
5568 emit
protocolPortChangesRequested(publishedPortsToRename, publishedPortsToRemove, publishedPortsToAdd, beginUndoStackMacro, endUndoStackMacro);
5582 string VuoEditorComposition::getNonProtocolVariantForPortName(
string portName)
5584 string modifiedPortName = portName;
5585 if (modifiedPortName.length() > 0)
5586 modifiedPortName[0] = toupper(modifiedPortName[0]);
5587 modifiedPortName =
"some" + modifiedPortName;
5589 return modifiedPortName;
5613 set<VuoPublishedPort *> publishedPortsToRemove;
5614 map<VuoPublishedPort *, string> publishedPortsToRename;
5617 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end(); ++i)
5619 string portName = i->first;
5620 string portType = i->second;
5623 if (preexistingPublishedPort)
5625 bool portCompatibleAcrossProtocolTransition =
false;
5626 if (replacementProtocol)
5629 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end() && !portCompatibleAcrossProtocolTransition; ++i)
5631 string replacementPortName = i->first;
5632 string replacementPortType = i->second;
5634 if ((portName == replacementPortName) && (portType == replacementPortType))
5635 portCompatibleAcrossProtocolTransition =
true;
5640 publishedPortsToRemove.insert(preexistingPublishedPort);
5641 else if (!portCompatibleAcrossProtocolTransition)
5647 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end(); ++i)
5649 string portName = i->first;
5650 string portType = i->second;
5653 if (preexistingPublishedPort)
5655 bool portCompatibleAcrossProtocolTransition =
false;
5656 if (replacementProtocol)
5659 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end() && !portCompatibleAcrossProtocolTransition; ++i)
5661 string replacementPortName = i->first;
5662 string replacementPortType = i->second;
5664 if ((portName == replacementPortName) && (portType == replacementPortType))
5665 portCompatibleAcrossProtocolTransition =
true;
5670 publishedPortsToRemove.insert(preexistingPublishedPort);
5671 else if (!portCompatibleAcrossProtocolTransition)
5678 if (!publishedPortsToRemove.empty())
5679 publishedPortsToRename.clear();
5681 bool portChangesRequired = (!publishedPortsToRename.empty() || !publishedPortsToRemove.empty());
5682 if (portChangesRequired)
5684 vector<VuoPublishedPort *> publishedPortsToAdd;
5685 bool beginUndoStackMacro =
true;
5686 bool endUndoStackMacro = !replacementProtocol;
5687 emit
protocolPortChangesRequested(publishedPortsToRename, publishedPortsToRemove, publishedPortsToAdd, beginUndoStackMacro, endUndoStackMacro);
5692 return portChangesRequired;
5703 if ((activeProtocol != protocol) || !activeProtocol)
5706 activeProtocol = NULL;
5709 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end(); ++i)
5711 string portName = i->first;
5712 string portType = i->second;
5715 if (preexistingPublishedPort)
5720 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end(); ++i)
5722 string portName = i->first;
5723 string portType = i->second;
5726 if (preexistingPublishedPort)
5739 return activeProtocol;
5748 if (!activeProtocol)
5751 return static_cast<VuoEditor *>(qApp)->getBuiltInDriverForProtocol(activeProtocol);
5762 portWithStaticIdentifier[staticPortIdentifier] = publishedPort;
5763 staticIdentifierForPort[publishedPort] = staticPortIdentifier;
5786 return removalResult;
5796 if (dynamic_cast<VuoPublishedPort *>(publishedPort->
getBase())->isProtocolPort())
5802 portWithStaticIdentifier[staticPortIdentifier] = publishedPort->
getBase();
5803 staticIdentifierForPort[publishedPort->
getBase()] = staticPortIdentifier;
5815 void VuoEditorComposition::highlightEligibleEndpointsForCable(
VuoCable *cable)
5828 highlightInternalPortsConnectableToPort(fixedPort, cable->
getRenderer());
5840 QList<QGraphicsItem *> compositionComponents = items();
5841 for (QList<QGraphicsItem *>::iterator i = compositionComponents.begin(); i != compositionComponents.end(); ++i)
5843 QGraphicsItem *compositionComponent = *i;
5844 VuoRendererNode *rn = dynamic_cast<VuoRendererNode *>(compositionComponent);
5849 for(vector<VuoPort *>::iterator inputPort = inputPorts.begin(); inputPort != inputPorts.end(); ++inputPort)
5850 updateEligibilityHighlightingForPort((*inputPort)->getRenderer(), port, !cable->
effectivelyCarriesData());
5854 for(vector<VuoPort *>::iterator outputPort = outputPorts.begin(); outputPort != outputPorts.end(); ++outputPort)
5855 updateEligibilityHighlightingForPort((*outputPort)->getRenderer(), port, !cable->
effectivelyCarriesData());
5859 VuoRendererCable *rc = dynamic_cast<VuoRendererCable *>(compositionComponent);
5860 if (rc && rc != cable)
5862 QGraphicsItem::CacheMode normalCacheMode = rc->cacheMode();
5863 rc->setCacheMode(QGraphicsItem::NoCache);
5880 rc->setCacheMode(normalCacheMode);
5885 for (QList<QGraphicsItem *>::iterator i = compositionComponents.begin(); i != compositionComponents.end(); ++i)
5886 updateEligibilityHighlightingForNode(dynamic_cast<VuoRendererNode *>(*i));
5893 void VuoEditorComposition::updateEligibilityHighlightingForPort(
VuoRendererPort *portToHighlight,
5895 bool eventOnlyConnection)
5897 QGraphicsItem::CacheMode normalCacheMode = portToHighlight->cacheMode();
5898 portToHighlight->setCacheMode(QGraphicsItem::NoCache);
5906 if (typecastPortToHighlight)
5909 portToHighlight->setCacheMode(normalCacheMode);
5911 if (typecastPortToHighlight)
5912 updateEligibilityHighlightingForPort(typecastPortToHighlight->
getChildPort(), fixedPort, eventOnlyConnection);
5928 VuoRendererPublishedPort *externalPublishedPortToHighlight = dynamic_cast<VuoRendererPublishedPort *>(portToHighlight);
5932 bool forwardConnection;
5935 fromPort = fixedPort;
5936 toPort = portToHighlight;
5937 forwardConnection =
true;
5941 fromPort = portToHighlight;
5943 forwardConnection =
false;
5946 bool directConnectionPossible;
5950 if (fixedExternalPublishedPort && externalPublishedPortToHighlight)
5951 directConnectionPossible =
false;
5952 else if (fixedExternalPublishedPort && !externalPublishedPortToHighlight)
5954 else if (!fixedExternalPublishedPort && externalPublishedPortToHighlight)
5960 if (directConnectionPossible)
5964 else if (fixedPort == portToHighlight)
5987 bool VuoEditorComposition::canConnectDirectlyWithRespecializationNondestructively(
VuoRendererPort *fromPort,
5989 bool eventOnlyConnection,
5990 bool forwardConnection)
5993 string respecializedTypeName =
"";
5995 return canConnectDirectlyWithRespecializationNondestructively(fromPort,
5997 eventOnlyConnection,
5999 &portToRespecialize,
6000 respecializedTypeName);
6013 bool VuoEditorComposition::canConnectDirectlyWithRespecializationNondestructively(
VuoRendererPort *fromPort,
6015 bool eventOnlyConnection,
6016 bool forwardConnection,
6018 string &respecializedTypeName)
6020 *portToRespecialize = NULL;
6021 respecializedTypeName =
"";
6023 bool canConnectWithRespecialization = canConnectDirectlyWithRespecialization(fromPort,
6025 eventOnlyConnection,
6028 respecializedTypeName);
6029 if (!canConnectWithRespecialization)
6032 if (canConnectWithRespecialization && !portToRespecialize)
6035 bool nondestructive = portCanBeUnspecializedNondestructively((*portToRespecialize)->getBase());
6036 if (!nondestructive)
6038 *portToRespecialize = NULL;
6039 respecializedTypeName =
"";
6041 return nondestructive;
6049 bool VuoEditorComposition::portCanBeUnspecializedNondestructively(
VuoPort *portToUnspecialize)
6051 map<VuoNode *, string> nodesToReplace;
6052 set<VuoCable *> cablesToDelete;
6057 if (cablesToDelete.empty())
6060 else if ((cablesToDelete.size() == 1) && ((*(cablesToDelete.begin()))->getToPort() == portToUnspecialize))
6085 bool VuoEditorComposition::canConnectDirectlyWithRespecialization(
VuoRendererPort *fromPort,
6087 bool eventOnlyConnection,
6088 bool forwardConnection,
6090 string &respecializedTypeName)
6094 *portToRespecialize = NULL;
6095 respecializedTypeName =
"";
6105 bool fromPortIsEnabledOutput = (fromPort && fromPort->
getOutput() && fromPort->isEnabled());
6106 bool toPortIsEnabledInput = (toPort && toPort->
getInput() && toPort->isEnabled());
6108 if (!(fromPortIsEnabledOutput && toPortIsEnabledInput))
6114 if (!(currentFromDataType && currentToDataType))
6121 VuoGenericType *currentFromGenericType = dynamic_cast<VuoGenericType *>(currentFromDataType);
6122 VuoGenericType *currentToGenericType = dynamic_cast<VuoGenericType *>(currentToDataType);
6129 if (fromSpecializedNodeClass)
6132 originalFromGenericType = dynamic_cast<VuoGenericType *>( fromSpecializedNodeClass->
getOriginalPortType(portClass) );
6141 if (toSpecializedNodeClass)
6144 originalToGenericType = dynamic_cast<VuoGenericType *>( toSpecializedNodeClass->
getOriginalPortType(portClass) );
6150 bool fromPortIsGeneric = currentFromGenericType;
6151 bool fromPortIsSpecialized = originalFromGenericType && !currentFromGenericType && isPortCurrentlyRevertible(fromPort);
6152 bool fromPortIsStatic = (!fromPortIsGeneric && !fromPortIsSpecialized);
6154 bool toPortIsGeneric = currentToGenericType;
6155 bool toPortIsSpecialized = originalToGenericType && !currentToGenericType && isPortCurrentlyRevertible(toPort);
6156 bool toPortIsStatic = (!toPortIsGeneric && !toPortIsSpecialized);
6159 set<string> compatibleTypes;
6160 string specializedType =
"";
6164 if ((fromPortIsStatic && toPortIsSpecialized) || (fromPortIsSpecialized && toPortIsStatic))
6168 portToTryToRespecialize = (fromPortIsSpecialized? fromPort : toPort);
6172 else if ((fromPortIsSpecialized || toPortIsSpecialized) && !fromPortIsStatic && !toPortIsStatic)
6175 bool dragSourceIsGeneric = (forwardConnection? fromPortIsGeneric : toPortIsGeneric);
6177 VuoRendererPort *dragDestination = (forwardConnection? toPort : fromPort);
6178 bool dragDestinationIsGeneric = (forwardConnection? toPortIsGeneric : fromPortIsGeneric);
6195 if (!dragSourceIsGeneric && !dragDestinationIsGeneric)
6198 portToTryToRespecialize = dragDestination;
6206 if (portToTryToRespecialize)
6207 compatibleTypes = getRespecializationOptionsForPortInNetwork(portToTryToRespecialize);
6209 bool portsAreCompatible = (compatibleTypes.find(specializedType) != compatibleTypes.end());
6211 if (portsAreCompatible)
6213 *portToRespecialize = portToTryToRespecialize;
6214 respecializedTypeName = specializedType;
6217 return portsAreCompatible;
6226 void VuoEditorComposition::updateEligibilityHighlightingForNode(
VuoRendererNode *node)
6241 QGraphicsItem::CacheMode normalCacheMode = drawer->cacheMode();
6242 drawer->setCacheMode(QGraphicsItem::NoCache);
6247 drawer->setCacheMode(normalCacheMode);
6256 QGraphicsItem::CacheMode normalCacheMode = hostPort->cacheMode();
6257 hostPort->setCacheMode(QGraphicsItem::NoCache);
6262 hostPort->setCacheMode(normalCacheMode);
6296 bool toPortIsDragDestination,
6298 string &specializedTypeName,
6299 string &typecastToInsert)
6301 *portToSpecialize = NULL;
6302 specializedTypeName =
"";
6304 map<string, VuoRendererPort *> portToSpecializeForTypecast;
6305 map<string, string> specializedTypeNameForTypecast;
6307 vector<string> candidateTypecasts =
findBridgingSolutions(fromPort, toPort, toPortIsDragDestination, portToSpecializeForTypecast, specializedTypeNameForTypecast);
6308 bool solutionSelected = selectBridgingSolutionFromOptions(candidateTypecasts, portToSpecializeForTypecast, specializedTypeNameForTypecast, typecastToInsert);
6310 if (!solutionSelected)
6313 if (portToSpecializeForTypecast.find(typecastToInsert) != portToSpecializeForTypecast.end())
6314 *portToSpecialize = portToSpecializeForTypecast[typecastToInsert];
6315 if (specializedTypeNameForTypecast.find(typecastToInsert) != specializedTypeNameForTypecast.end())
6316 specializedTypeName = specializedTypeNameForTypecast[typecastToInsert];
6339 bool VuoEditorComposition::selectBridgingSolutionFromOptions(vector<string> suitableTypecasts,
6340 map<string, VuoRendererPort *> portToSpecializeForTypecast,
6341 map<string, string> specializedTypeNameForTypecast,
6342 string &selectedTypecast)
6344 if (suitableTypecasts.empty())
6346 selectedTypecast =
"";
6350 else if (suitableTypecasts.size() == 1)
6352 selectedTypecast = suitableTypecasts[0];
6357 return promptForBridgingSelectionFromOptions(suitableTypecasts, portToSpecializeForTypecast, specializedTypeNameForTypecast, selectedTypecast);
6367 bool fromPortIsEnabledOutput = (fromPort && fromPort->
getOutput() && fromPort->isEnabled());
6368 bool toPortIsEnabledInput = (toPort && toPort->
getInput() && toPort->isEnabled());
6370 if (!(fromPortIsEnabledOutput && toPortIsEnabledInput &&
6377 VuoType *inType = (candidateFromType? candidateFromType : static_cast<VuoCompilerPortClass *>(fromPort->
getBase()->
getClass()->
getCompiler())->getDataVuoType());
6390 if (toNodeUsesIndex)
6416 bool toPortIsDragDestination)
6418 map<string, VuoRendererPort *> portToSpecializeForTypecast;
6419 map<string, string> specializedTypeNameForTypecast;
6420 return findBridgingSolutions(fromPort, toPort, toPortIsDragDestination, portToSpecializeForTypecast, specializedTypeNameForTypecast);
6434 bool toPortIsDragDestination,
6435 map<string, VuoRendererPort *> &portToSpecializeForTypecast,
6436 map<string, string> &specializedTypeNameForTypecast)
6438 portToSpecializeForTypecast.clear();
6439 specializedTypeNameForTypecast.clear();
6440 vector<string> suitableTypecasts;
6444 if (dynamic_cast<VuoRendererPublishedPort *>(fromPort) && dynamic_cast<VuoRendererPublishedPort *>(toPort))
6445 return suitableTypecasts;
6450 string specializedTypeName =
"";
6453 suitableTypecasts.push_back(
"");
6454 portToSpecializeForTypecast[
""] = portToSpecialize;
6455 specializedTypeNameForTypecast[
""] = specializedTypeName;
6457 return suitableTypecasts;
6464 if (!(currentFromDataType && currentToDataType))
6465 return suitableTypecasts;
6469 return suitableTypecasts;
6471 VuoGenericType *currentFromGenericType = dynamic_cast<VuoGenericType *>(currentFromDataType);
6472 VuoGenericType *currentToGenericType = dynamic_cast<VuoGenericType *>(currentToDataType);
6479 if (fromSpecializedNodeClass)
6482 originalFromGenericType = dynamic_cast<VuoGenericType *>( fromSpecializedNodeClass->
getOriginalPortType(portClass) );
6491 if (toSpecializedNodeClass)
6494 originalToGenericType = dynamic_cast<VuoGenericType *>( toSpecializedNodeClass->
getOriginalPortType(portClass) );
6502 bool fromPortIsGeneric = currentFromGenericType;
6503 bool fromPortIsSpecialized = originalFromGenericType && !currentFromGenericType && isPortCurrentlyRevertible(fromPort);
6504 bool fromPortIsStatic = (!fromPortIsGeneric && !fromPortIsSpecialized);
6506 bool toPortIsGeneric = currentToGenericType;
6507 bool toPortIsSpecialized = originalToGenericType && !currentToGenericType && isPortCurrentlyRevertible(toPort);
6508 bool toPortIsStatic = (!toPortIsGeneric && !toPortIsSpecialized);
6511 if (fromPortIsGeneric && toPortIsGeneric)
6512 return suitableTypecasts;
6515 else if (fromPortIsStatic && toPortIsStatic)
6517 if (portsPassSanityCheckToTypeconvert(fromPort, toPort))
6519 return suitableTypecasts;
6524 bool specializeToPort =
true;
6525 if (toPortIsGeneric)
6526 specializeToPort =
true;
6527 else if (fromPortIsGeneric)
6528 specializeToPort =
false;
6529 else if (fromPortIsSpecialized && toPortIsStatic)
6530 specializeToPort =
false;
6531 else if (fromPortIsStatic && toPortIsSpecialized)
6532 specializeToPort =
true;
6533 else if (fromPortIsSpecialized && toPortIsSpecialized)
6534 specializeToPort = toPortIsDragDestination;
6538 set<string> compatibleTypes;
6539 if (specializeToPort && (toPortIsGeneric || (toPortIsSpecialized && portCanBeUnspecializedNondestructively(toPort->
getBase()))))
6540 compatibleTypes = getRespecializationOptionsForPortInNetwork(toPort);
6541 else if (!specializeToPort && (fromPortIsGeneric || (fromPortIsSpecialized && portCanBeUnspecializedNondestructively(fromPort->
getBase()))))
6542 compatibleTypes = getRespecializationOptionsForPortInNetwork(fromPort);
6548 foreach (
string compatibleTypeName, compatibleTypes)
6551 VuoType *candidateFromType = specializeToPort? currentFromDataType : compatibleSpecializedType->
getBase();
6552 VuoType *candidateToType = specializeToPort? compatibleSpecializedType->
getBase() : currentToDataType;
6554 if (compatibleSpecializedType && portsPassSanityCheckToTypeconvert(fromPort,
6560 if (candidateFromType == candidateToType)
6562 suitableTypecasts.push_back(
"");
6563 portToSpecializeForTypecast[
""] = specializeToPort? toPort : fromPort;
6564 specializedTypeNameForTypecast[
""] = compatibleSpecializedType->
getBase()->
getModuleKey();
6568 foreach (
string typecast, suitableTypecastsForCurrentTypes)
6570 suitableTypecasts.push_back(typecast);
6571 portToSpecializeForTypecast[typecast] = specializeToPort? toPort : fromPort;
6572 specializedTypeNameForTypecast[typecast] = compatibleSpecializedType->
getBase()->
getModuleKey();
6577 return suitableTypecasts;
6592 bool VuoEditorComposition::promptForBridgingSelectionFromOptions(vector<string> suitableTypecasts,
6593 map<string, VuoRendererPort *> portToSpecializeForTypecast,
6594 map<string, string> specializedTypeNameForTypecast,
6595 string &selectedTypecast)
6597 QMenu typecastMenu(views()[0]->viewport());
6598 typecastMenu.setSeparatorsCollapsible(
false);
6599 QString spacer(
" ");
6602 set <pair<VuoRendererPort *, string> > specializationDetails;
6603 vector<string> typeconversionOptionsRequiringNoSpecialization;
6604 foreach (
string typecastClassName, suitableTypecasts)
6606 VuoRendererPort *portToSpecialize = portToSpecializeForTypecast[typecastClassName];
6607 string specializedTypeName = specializedTypeNameForTypecast[typecastClassName];
6608 specializationDetails.insert(std::make_pair(portToSpecialize,
6609 specializedTypeName));
6611 bool portAlreadyHasTargetType = (!portToSpecialize || (portToSpecialize->
getDataType() && (portToSpecialize->
getDataType()->
getModuleKey() == specializedTypeName)));
6612 if (portAlreadyHasTargetType)
6613 typeconversionOptionsRequiringNoSpecialization.push_back(typecastClassName);
6619 if ((std::find(suitableTypecasts.begin(), suitableTypecasts.end(),
"") != suitableTypecasts.end()))
6621 QString menuText = getDisplayTextForSpecializationOption(portToSpecializeForTypecast[
""], specializedTypeNameForTypecast[
""]);
6622 QAction *typecastAction = typecastMenu.addAction(menuText);
6623 typecastAction->setData(QVariant(
""));
6627 bool includingTypeconvertWithNoSpecializationHeader =
false;
6628 if (typeconversionOptionsRequiringNoSpecialization.size() >= 1)
6630 if (typecastMenu.actions().size() >= 1)
6631 typecastMenu.addSeparator();
6633 VuoRendererPort *portToSpecialize = portToSpecializeForTypecast[typeconversionOptionsRequiringNoSpecialization[0] ];
6634 string specializedTypeName = specializedTypeNameForTypecast[typeconversionOptionsRequiringNoSpecialization[0] ];
6636 if (portToSpecialize && !specializedTypeName.empty())
6638 QString menuText = getDisplayTextForSpecializationOption(portToSpecialize, specializedTypeName);
6639 QAction *typecastAction = typecastMenu.addAction(menuText);
6640 typecastAction->setEnabled(
false);
6641 includingTypeconvertWithNoSpecializationHeader =
true;
6645 foreach (
string typecastClassName, typeconversionOptionsRequiringNoSpecialization)
6651 typecastAction->setData(QVariant(typecastClassName.c_str()));
6656 for (set<pair<VuoRendererPort *, string> >::iterator i = specializationDetails.begin(); i != specializationDetails.end(); ++i)
6659 string specializedTypeName = i->second;
6662 if ((std::find(suitableTypecasts.begin(), suitableTypecasts.end(),
"") != suitableTypecasts.end()) &&
6663 (portToSpecializeForTypecast[
""] == portToSpecialize) &&
6664 (specializedTypeNameForTypecast[
""] == specializedTypeName))
6670 bool portAlreadyHasTargetType = (!portToSpecialize || (portToSpecialize->
getDataType() && (portToSpecialize->
getDataType()->
getModuleKey() == specializedTypeName)));
6671 if (portAlreadyHasTargetType)
6676 if (typecastMenu.actions().size() >= 1)
6677 typecastMenu.addSeparator();
6679 QString menuText = getDisplayTextForSpecializationOption(portToSpecialize, specializedTypeName);
6680 QAction *typecastAction = typecastMenu.addAction(menuText);
6681 typecastAction->setEnabled(
false);
6684 foreach (
string typecastClassName, suitableTypecasts)
6686 if ((portToSpecializeForTypecast[typecastClassName] == portToSpecialize) &&
6687 (specializedTypeNameForTypecast[typecastClassName] == specializedTypeName))
6693 typecastAction->setData(QVariant(typecastClassName.c_str()));
6699 menuSelectionInProgress =
true;
6700 QAction *selectedTypecastAction = typecastMenu.exec(QCursor::pos());
6701 menuSelectionInProgress =
false;
6703 selectedTypecast = (selectedTypecastAction? selectedTypecastAction->data().toString().toUtf8().constData() :
"");
6704 return selectedTypecastAction;
6710 QString VuoEditorComposition::getDisplayTextForSpecializationOption(
VuoRendererPort *portToSpecialize,
string specializedTypeName)
6712 if (!portToSpecialize || specializedTypeName.empty())
6715 bool isInput = portToSpecialize && portToSpecialize->
getInput();
6716 QString typeDisplayName = compiler->
getType(specializedTypeName)?
6718 specializedTypeName.c_str();
6720 bool portAlreadyHasTargetType = (!portToSpecialize || (portToSpecialize->
getDataType() && (portToSpecialize->
getDataType()->
getModuleKey() == specializedTypeName)));
6722 QString displayText;
6723 if (portAlreadyHasTargetType)
6728 displayText = tr(
"Keep Input Port as %1");
6733 displayText = tr(
"Keep Output Port as %1");
6741 displayText = tr(
"Change Input Port to %1");
6746 displayText = tr(
"Change Output Port to %1");
6750 return displayText.arg(typeDisplayName);
6764 string runningPortIdentifier = staticIdentifierForPort[port];
6769 dispatch_sync(topLevelComposition->runCompositionQueue, ^{
6770 if (topLevelComposition->isRunningThreadUnsafe())
6772 portValue = isInput ?
6773 topLevelComposition->runner->getInputPortValue(thisCompositionIdentifier, runningPortIdentifier) :
6774 topLevelComposition->runner->getOutputPortValue(thisCompositionIdentifier, runningPortIdentifier);
6778 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, getPortValue);
6786 string VuoEditorComposition::getIdentifierForRunningPort(
VuoPort *runningPort)
6788 return static_cast<VuoCompilerPort *>(runningPort->
getCompiler())->getIdentifier();
6802 if (dynamic_cast<VuoPublishedPort *>(staticPort))
6803 return dynamic_cast<VuoPublishedPort *>(staticPort)->getClass()->getName();
6809 string nodeIdentifier =
"";
6819 if (staticPort->
hasCompiler() && !nodeIdentifier.empty())
6821 dynamic_cast<VuoCompilerPort *>(staticPort->
getCompiler())->setNodeIdentifier(nodeIdentifier);
6822 return static_cast<VuoCompilerPort *>(staticPort->
getCompiler())->getIdentifier();
6833 return portWithStaticIdentifier[portID];
6845 if (dynamic_cast<VuoRendererPublishedPort *>(port->
getRenderer()))
6859 if (candidateInputPort == port)
6863 if (candidateOutputPort == port)
6879 map<string, VuoPortPopover *>::iterator popover = activePortPopovers.find(portID);
6880 if (popover != activePortPopovers.end())
6881 return popover->second;
6894 void VuoEditorComposition::enableInactivePopoverForPort(
VuoRendererPort *rp)
6896 string portID = staticIdentifierForPort[rp->
getBase()];
6897 bool popoverJustClosedAtLastEvent = portsWithPopoversClosedAtLastEvent.find(portID) != portsWithPopoversClosedAtLastEvent.end();
6898 if (!popoverJustClosedAtLastEvent)
6907 if (!popoverEventsEnabled)
6911 string portID = staticIdentifierForPort[port];
6913 VUserLog(
"%s: Open popover for %s",
6917 dispatch_sync(runCompositionQueue, ^{
6919 dispatch_sync(activePortPopoversQueue, ^{
6921 if (activePortPopovers.find(portID) == activePortPopovers.end())
6929 VUserLog(
"%s: Detach popover for %s",
6942 const int cutoffMargin = 16;
6943 QRectF viewportRect = views()[0]->mapToScene(views()[0]->viewport()->rect()).
boundingRect();
6944 if (portLeftInScene.x() + popover->size().width() + cutoffMargin > viewportRect.right())
6945 portLeftInScene = QPoint(viewportRect.right() - popover->size().width() - cutoffMargin, portLeftInScene.y());
6946 if (portLeftInScene.y() + popover->size().height() + cutoffMargin > viewportRect.bottom())
6947 portLeftInScene = QPoint(portLeftInScene.x(), viewportRect.bottom() - popover->size().height() - cutoffMargin);
6949 QPoint popoverLeftInView = views()[0]->mapFromScene(portLeftInScene);
6951 const QPoint offset = QPoint(12, 6);
6953 QPoint popoverTopLeft = popoverLeftInView + offset;
6954 popover->move(popoverTopLeft);
6957 activePortPopovers[portID] = popover;
6959 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
6973 if (popoverEventsEnabled && !dynamic_cast<VuoRendererInputDrawer *>(rn))
6986 VUserLog(
"%s: Close popover for %s",
6991 map<string, VuoPortPopover *>::iterator i = activePortPopovers.find(portID);
6992 if (i != activePortPopovers.end())
6994 popover = i->second;
6995 activePortPopovers.erase(i);
7004 VuoPort *port = portWithStaticIdentifier[portID];
7010 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
7011 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, ^
void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier)
7013 dispatch_async(topLevelComposition->runCompositionQueue, ^{
7014 if (topLevelComposition->isRunningThreadUnsafe())
7017 topLevelComposition->runner->unsubscribeFromInputPortTelemetry(thisCompositionIdentifier, portID) :
7018 topLevelComposition->runner->unsubscribeFromOutputPortTelemetry(thisCompositionIdentifier, portID));
7028 void VuoEditorComposition::disablePopoverForPortThreadSafe(
string portID)
7030 dispatch_sync(activePortPopoversQueue, ^{
7040 disablePortPopovers();
7051 errorPopover->hide();
7052 errorPopover->deleteLater();
7055 errorPopovers.clear();
7064 dispatch_sync(activePortPopoversQueue, ^{
7065 map<string, VuoPortPopover *> popoversToDisable = activePortPopovers;
7066 for (map<string, VuoPortPopover *>::iterator i = popoversToDisable.begin(); i != popoversToDisable.end(); ++i)
7068 string portID = i->first;
7069 VuoPort *port = portWithStaticIdentifier[portID];
7081 dispatch_sync(activePortPopoversQueue, ^{
7082 map<string, VuoPortPopover *> popoversToDisable = activePortPopovers;
7083 for (map<string, VuoPortPopover *>::iterator i = popoversToDisable.begin(); i != popoversToDisable.end(); ++i)
7085 string portID = i->first;
7086 VuoPort *port = portWithStaticIdentifier[portID];
7099 if (recordWhichPopoversClosed)
7100 portsWithPopoversClosedAtLastEvent.clear();
7102 dispatch_sync(activePortPopoversQueue, ^{
7103 map<string, VuoPortPopover *> popoversToDisable = activePortPopovers;
7104 for (map<string, VuoPortPopover *>::iterator i = popoversToDisable.begin(); i != popoversToDisable.end(); ++i)
7106 string portID = i->first;
7107 VuoPort *port = portWithStaticIdentifier[portID];
7114 portsWithPopoversClosedAtLastEvent.insert(portID);
7126 moveDetachedPortPopoversBy(dx, dy);
7127 moveErrorPopoversBy(dx, dy);
7133 void VuoEditorComposition::moveErrorPopoversBy(
int dx,
int dy)
7136 errorPopover->move(errorPopover->pos().x()+dx, errorPopover->pos().y()+dy);
7142 void VuoEditorComposition::moveDetachedPortPopoversBy(
int dx,
int dy)
7144 dispatch_sync(activePortPopoversQueue, ^{
7145 map<string, VuoPortPopover *> portPopovers = activePortPopovers;
7146 for (map<string, VuoPortPopover *>::iterator i = portPopovers.begin(); i != portPopovers.end(); ++i)
7150 popover->move(popover->pos().x()+dx, popover->pos().y()+dy);
7158 void VuoEditorComposition::setPopoversHideOnDeactivate(
bool shouldHide)
7160 dispatch_sync(activePortPopoversQueue, ^{
7161 auto portPopovers = activePortPopovers;
7162 for (
auto i : portPopovers)
7168 objc_msgSend(nsWindow, sel_getUid(
"setHidesOnDeactivate:"), shouldHide);
7180 dispatch_sync(activePortPopoversQueue, ^{
7181 for (map<string, VuoPortPopover *>::iterator i = activePortPopovers.begin(); i != activePortPopovers.end(); ++i)
7183 string portID = i->first;
7184 VuoPort *port = portWithStaticIdentifier[portID];
7188 QMetaObject::invokeMethod(popover,
"updateTextAndResize", Qt::QueuedConnection);
7205 string popoverCompositionIdentifier,
7208 VuoPort *port = popoverComposition->portWithStaticIdentifier[portID];
7216 dispatch_async(popoverComposition->activePortPopoversQueue, ^{
7217 VuoPortPopover *popover = popoverComposition->getActivePopoverForPort(portID);
7220 QMetaObject::invokeMethod(popover,
"updateCachedDataValue", Qt::QueuedConnection, Q_ARG(QString, portSummary.c_str()));
7221 QMetaObject::invokeMethod(popover,
"setCompositionRunning", Qt::QueuedConnection, Q_ARG(bool, true), Q_ARG(bool, false));
7235 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, ^
void (
VuoEditorComposition *topLevelComposition,
string thisCompositionIdentifier)
7237 dispatch_sync(topLevelComposition->runCompositionQueue, ^{
7238 if (topLevelComposition->isRunningThreadUnsafe())
7239 topLevelComposition->updateDataInPortPopoverFromRunningTopLevelComposition(this, thisCompositionIdentifier, portID);
7249 bool receivedEvent,
bool receivedData,
string dataSummary)
7253 dispatch_sync(matchingComposition->activePortPopoversQueue, ^{
7254 VuoPortPopover *popover = matchingComposition->getActivePopoverForPort(portIdentifier);
7258 if (receivedEvent && receivedData)
7259 QMetaObject::invokeMethod(popover,
"updateLastEventTimeAndCachedDataValue", Qt::QueuedConnection, Q_ARG(QString, dataSummary.c_str()));
7260 else if (receivedEvent)
7261 QMetaObject::invokeMethod(popover,
"updateLastEventTime", Qt::QueuedConnection);
7262 else if (receivedData)
7263 QMetaObject::invokeMethod(popover,
"updateCachedDataValue", Qt::QueuedConnection, Q_ARG(QString, dataSummary.c_str()));
7267 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedCompositionWithIdentifier(
this, compositionIdentifier, updatePortDisplay);
7275 bool sentEvent,
bool sentData,
string dataSummary)
7279 dispatch_sync(matchingComposition->activePortPopoversQueue, ^{
7280 VuoPort *port = matchingComposition->portWithStaticIdentifier[portIdentifier];
7281 VuoPortPopover *popover = matchingComposition->getActivePopoverForPort(portIdentifier);
7285 if (sentEvent && sentData)
7286 QMetaObject::invokeMethod(popover,
"updateLastEventTimeAndCachedDataValue", Qt::QueuedConnection, Q_ARG(QString, dataSummary.c_str()));
7288 QMetaObject::invokeMethod(popover,
"updateLastEventTime", Qt::QueuedConnection);
7290 QMetaObject::invokeMethod(popover,
"updateCachedDataValue", Qt::QueuedConnection, Q_ARG(QString, dataSummary.c_str()));
7293 if (matchingComposition->showEventsMode && sentEvent)
7295 if (port && dynamic_cast<VuoCompilerTriggerPort *>(port->getCompiler()) && port->hasRenderer())
7297 port->getRenderer()->setFiredEvent();
7298 matchingComposition->animatePort(port->getRenderer());
7303 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedCompositionWithIdentifier(
this, compositionIdentifier, updatePortDisplay);
7314 dispatch_async(matchingComposition->runCompositionQueue, ^{
7315 if (matchingComposition->isRunningThreadUnsafe())
7317 dispatch_sync(matchingComposition->activePortPopoversQueue, ^{
7318 VuoPortPopover *popover = matchingComposition->getActivePopoverForPort(portIdentifier);
7320 QMetaObject::invokeMethod(popover,
"incrementDroppedEventCount", Qt::QueuedConnection);
7325 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedCompositionWithIdentifier(
this, compositionIdentifier, updatePortDisplay);
7336 if (matchingComposition->showEventsMode)
7338 dispatch_async(this->runCompositionQueue, ^{
7339 if (this->isRunningThreadUnsafe())
7341 map<string, VuoNode *>::iterator i = matchingComposition->nodeWithGraphvizIdentifier.find(nodeIdentifier);
7342 if (i != nodeWithGraphvizIdentifier.end())
7344 VuoNode *nodeInBaseComposition = i->second;
7352 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedCompositionWithIdentifier(
this, compositionIdentifier, updateNodeDisplay);
7363 if (matchingComposition->showEventsMode)
7365 dispatch_async(this->runCompositionQueue, ^{
7366 if (this->isRunningThreadUnsafe())
7368 map<string, VuoNode *>::iterator i = matchingComposition->nodeWithGraphvizIdentifier.find(nodeIdentifier);
7369 if (i != nodeWithGraphvizIdentifier.end())
7371 VuoNode *nodeInBaseComposition = i->second;
7379 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedCompositionWithIdentifier(
this, compositionIdentifier, updateNodeDisplay);
7408 return showEventsMode;
7416 this->showEventsMode = showEventsMode;
7424 dispatch_sync(topLevelComposition->runCompositionQueue, ^{
7425 if (topLevelComposition->isRunningThreadUnsafe())
7426 topLevelComposition->runner->subscribeToEventTelemetry(thisCompositionIdentifier);
7429 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, subscribe);
7437 dispatch_sync(topLevelComposition->runCompositionQueue, ^{
7438 if (topLevelComposition->isRunningThreadUnsafe())
7439 topLevelComposition->runner->unsubscribeFromEventTelemetry(thisCompositionIdentifier);
7442 static_cast<VuoEditor *>(qApp)->getSubcompositionRouter()->applyToLinkedTopLevelComposition(
this, unsubscribe);
7478 QGraphicsItemAnimation * VuoEditorComposition::setUpAnimationForPort(QGraphicsItemAnimation *animation,
VuoRendererPort *port)
7486 animatedPort->setZValue(VuoRendererItem::triggerAnimationZValue);
7489 animation->setItem(animatedPort);
7490 animation->setScaleAt(0.0, 1, 1);
7491 animation->setScaleAt(0.999, 3, 3);
7492 animation->setScaleAt(1.0, 1, 1);
7494 QTimeLine *animationTimeline = animation->timeLine();
7495 animationTimeline->setFrameRange(0, 100);
7496 animationTimeline->setUpdateInterval(showEventsModeUpdateInterval);
7497 animationTimeline->setCurveShape(QTimeLine::LinearCurve);
7499 preparedAnimations.insert(animation);
7500 animationForTimeline[animation->timeLine()] = animation;
7502 connect(animationTimeline, &QTimeLine::valueChanged,
this, &VuoEditorComposition::updatePortAnimation);
7503 connect(animationTimeline, &QTimeLine::finished,
this, &VuoEditorComposition::endPortAnimation);
7513 dispatch_async(dispatch_get_main_queue(), ^{
7514 QGraphicsItemAnimation *animation = getAvailableAnimationForPort(port);
7520 if (animation->timeLine()->state() == QTimeLine::Running)
7521 animation->timeLine()->setCurrentTime(0);
7525 animatedPort->setPos(port->pos());
7526 animatedPort->setVisible(
true);
7527 animation->timeLine()->start();
7536 QGraphicsItemAnimation * VuoEditorComposition::getAvailableAnimationForPort(
VuoRendererPort *port)
7538 vector<QGraphicsItemAnimation *> animations = port->
getAnimations();
7540 QGraphicsItemAnimation *mostAdvancedAnimation = NULL;
7541 qreal maxPercentAdvanced = -1;
7543 for (
int i = 0; i < animations.size(); ++i)
7545 QGraphicsItemAnimation *animation = animations[i];
7546 bool animationPrepared = (preparedAnimations.find(animation) != preparedAnimations.end());
7547 bool animationRunning = (animation->timeLine()->state() == QTimeLine::Running);
7549 if (! animationPrepared)
7550 return setUpAnimationForPort(animation, port);
7552 else if (! animationRunning)
7557 qreal percentAdvanced = animation->timeLine()->currentValue();
7558 if (percentAdvanced > maxPercentAdvanced)
7560 mostAdvancedAnimation = animation;
7561 maxPercentAdvanced = percentAdvanced;
7567 return (maxPercentAdvanced >= 0.5? mostAdvancedAnimation : NULL);
7575 void VuoEditorComposition::updatePortAnimation(qreal value)
7577 QTimeLine *animationTimeline = (QTimeLine *)sender();
7578 QGraphicsItemAnimation *animation = animationForTimeline[animationTimeline];
7580 const qreal multiplier = 1000.;
7588 void VuoEditorComposition::endPortAnimation(
void)
7590 QTimeLine *animationTimeline = (QTimeLine *)sender();
7591 QGraphicsItemAnimation *animation = animationForTimeline[animationTimeline];
7593 animatedPort->setVisible(
false);
7599 void VuoEditorComposition::setDisableDragStickiness(
bool disable)
7601 this->dragStickinessDisabled = disable;
7609 this->ignoreApplicationStateChangeEvents = ignore;
7619 this->popoverEventsEnabled = enable;
7628 nodeWithGraphvizIdentifier.clear();
7629 portWithStaticIdentifier.clear();
7630 staticIdentifierForPort.clear();
7633 registerNodeID(node);
7638 portWithStaticIdentifier[staticPortIdentifier] = publishedPort;
7639 staticIdentifierForPort[publishedPort] = staticPortIdentifier;
7642 foreach (
VuoPort *publishedPort,
getBase()->getPublishedOutputPorts())
7645 portWithStaticIdentifier[staticPortIdentifier] = publishedPort;
7646 staticIdentifierForPort[publishedPort] = staticPortIdentifier;
7653 void VuoEditorComposition::registerNodeID(
VuoNode *node)
7661 portWithStaticIdentifier[staticPortIdentifier] = port;
7662 staticIdentifierForPort[port] = staticPortIdentifier;
7668 portWithStaticIdentifier[staticPortIdentifier] = port;
7669 staticIdentifierForPort[port] = staticPortIdentifier;
7679 refreshComponentAlphaLevelTimer->start();
7687 refreshComponentAlphaLevelTimer->stop();
7710 if (!activeProtocol)
7717 if (!
getBase()->getCompiler()->getCachedGraph()->mayEventsReachPublishedOutputPorts())
7719 QString errorHeadline = tr(
"<b>This composition doesn't send any images to <code>outputImage</code>.</b>");
7720 QString errorDetails = tr(
"<p>To export, your composition should use the data and events from the published input ports "
7721 "to output a stream of images through the <code>outputImage</code> published output port.</p>");
7723 if (isExportingMovie)
7724 errorDetails.append(
"<p>Alternatively, you can record a realtime movie by running the composition and selecting File > Start Recording.</p>");
7727 QMessageBox messageBox(window);
7728 messageBox.setWindowFlags(Qt::Sheet);
7729 messageBox.setWindowModality(Qt::WindowModal);
7731 messageBox.setTextFormat(Qt::RichText);
7733 messageBox.setStandardButtons(QMessageBox::Help | QMessageBox::Ok);
7734 messageBox.setButtonText(QMessageBox::Help, tr(
"Open an Example"));
7735 messageBox.setButtonText(QMessageBox::Ok, tr(
"OK"));
7736 messageBox.setDefaultButton(QMessageBox::Ok);
7738 messageBox.setText(errorHeadline);
7739 messageBox.setInformativeText(
"<style>p{" + fonts->
getCSS(fonts->
dialogBodyFont()) +
"}</style>" + errorDetails);
7741 if (messageBox.exec() == QMessageBox::Help)
7743 map<QString, QString> examples = static_cast<VuoEditor *>(qApp)->getExampleCompositionsForProtocol(activeProtocol);
7744 map<QString, QString>::iterator i = examples.begin();
7745 if (i != examples.end())
7775 string dir, file, ext;
7789 if (! customizedName.empty())
7790 return QString::fromStdString(customizedName);
7808 string fileNameContentPart = (fileNameParts.size() >= 2 && fileNameParts[fileNameParts.size()-1] ==
"vuo"?
7809 fileNameParts[fileNameParts.size()-2] :
7810 (fileNameParts.size() >= 1? fileNameParts[fileNameParts.size()-1] :
""));
7813 if (QRegExp(
"\\s").indexIn(fileNameContentPart.c_str()) != -1)
7815 string formattedName = fileNameContentPart;
7816 if (formattedName.size() >= 1)
7817 formattedName[0] = toupper(formattedName[0]);
7819 return QString(formattedName.c_str());
7833 QStringList wordsInName = nodeSetName.split(QRegularExpression(
"\\."));
7834 if (wordsInName.size() < 2 || wordsInName[0] !=
"vuo")
7840 map<QString, QString> wordsToReformat;
7841 wordsToReformat[
"artnet"] =
"Art-Net";
7842 wordsToReformat[
"bcf2000"] =
"BCF2000";
7843 wordsToReformat[
"hid"] =
"HID";
7844 wordsToReformat[
"midi"] =
"MIDI";
7845 wordsToReformat[
"osc"] =
"OSC";
7846 wordsToReformat[
"rss"] =
"RSS";
7847 wordsToReformat[
"ui"] =
"UI";
7848 wordsToReformat[
"url"] =
"URL";
7850 QString nodeSetDisplayName =
"";
7851 for (
int i = 1; i < wordsInName.size(); ++i)
7853 QString currentWord = wordsInName[i];
7854 if (currentWord.size() >= 1)
7856 if (wordsToReformat.find(currentWord.toLower()) != wordsToReformat.end())
7857 currentWord = wordsToReformat.at(currentWord.toLower());
7859 currentWord[0] = currentWord[0].toUpper();
7861 nodeSetDisplayName += currentWord;
7863 if (i < wordsInName.size()-1)
7864 nodeSetDisplayName +=
" ";
7867 return nodeSetDisplayName;
7880 string formattedTypeName =
"";
7888 formattedTypeName =
"List of " + formattedInnerTypeName +
" elements";
7894 return formattedTypeName.c_str();
7913 return "Transform2D";
7915 return "Transform3D";
7923 bool VuoEditorComposition::nodeSetMenuActionLessThan(QAction *action1, QAction *action2)
7925 QString item1Text = action1->text();
7926 QString item2Text = action2->text();
7929 const QString listPrefix =
"List of ";
7930 const QString builtInTypePrefix =
"Vuo";
7932 if (item1Text.startsWith(listPrefix))
7934 item1Text.remove(0, listPrefix.length());
7935 if (item1Text.startsWith(builtInTypePrefix))
7936 item1Text.remove(0, builtInTypePrefix.length());
7939 if (item2Text.startsWith(listPrefix))
7941 item2Text.remove(0, listPrefix.length());
7942 if (item2Text.startsWith(builtInTypePrefix))
7943 item2Text.remove(0, builtInTypePrefix.length());
7947 return (item1Text.compare(item2Text, Qt::CaseInsensitive) < 0);
7954 bool VuoEditorComposition::itemHigherOnCanvas(QGraphicsItem *item1, QGraphicsItem *item2)
7956 qreal item1Y = item1->scenePos().y();
7957 qreal item2Y = item2->scenePos().y();
7959 qreal item1X = item1->scenePos().x();
7960 qreal item2X = item2->scenePos().x();
7962 if (item1Y == item2Y)
7963 return (item1X < item2X);
7965 return item1Y < item2Y;
7977 vector<string> node1Keywords = node1->
getKeywords();
7978 vector<string> node2Keywords = node2->
getKeywords();
7990 node1Keywords.push_back(nodeTitleToken.toLower().toUtf8().constData());
7994 node2Keywords.push_back(nodeTitleToken.toLower().toUtf8().constData());
7996 set<string> node1KeywordSet(node1Keywords.begin(), node1Keywords.end());
7997 set<string> node2KeywordSet(node2Keywords.begin(), node2Keywords.end());
7999 set<string> nodeKeywordsIntersection;
8000 std::set_intersection(node1KeywordSet.begin(), node1KeywordSet.end(),
8001 node2KeywordSet.begin(), node2KeywordSet.end(),
8002 std::inserter(nodeKeywordsIntersection, nodeKeywordsIntersection.end()));
8004 set<string> nodeKeywordsUnion = node1KeywordSet;
8005 nodeKeywordsUnion.insert(node2KeywordSet.begin(), node2KeywordSet.end());
8008 if (nodeKeywordsUnion.size() == 0)
8012 double nodeSimilarity = nodeKeywordsIntersection.size()/(1.0*nodeKeywordsUnion.size());
8014 return nodeSimilarity;
8033 VuoEditorComposition::~VuoEditorComposition()
8035 dispatch_sync(runCompositionQueue, ^{});
8036 dispatch_release(runCompositionQueue);
8038 preparedAnimations.clear();
8039 animationForTimeline.clear();
8065 vector<VuoRendererPort *> sortedPortsToPublish;
8066 foreach (
string portID, portsToPublish)
8070 sortedPortsToPublish.push_back(port->
getRenderer());
8072 std::sort(sortedPortsToPublish.begin(), sortedPortsToPublish.end(), itemHigherOnCanvas);
8074 map<string, string> publishedPortNames;
8081 string publishedPortName = (!specializedPublishedPortName.empty()?
8082 specializedPublishedPortName :
8091 return publishedPortNames;
8119 void VuoEditorComposition::repositionPopover()
8121 VuoPortPopover *popover = static_cast<VuoPortPopover *>(QObject::sender());
8124 const int cutoffMargin = 16;
8125 if (popover->pos().x()+popover->size().width()+cutoffMargin > views()[0]->viewport()->rect().right())
8126 popover->move(QPoint(views()[0]->viewport()->rect().right()-popover->size().width()-cutoffMargin, popover->pos().y()));
8128 if (popover->pos().y()+popover->size().height()+cutoffMargin > views()[0]->viewport()->rect().bottom())
8129 popover->move(QPoint(popover->pos().x(), views()[0]->viewport()->rect().bottom()-popover->size().height()-cutoffMargin));