Browse Source

Add RackWidget::getCompleteCablesOnPort(). Use it in PortWidget and ModuleWidget to prevent crashes when incomplete cables exist.

tags/v2.0.0
Andrew Belt 2 years ago
parent
commit
6c81ba466f
4 changed files with 20 additions and 6 deletions
  1. +1
    -0
      include/app/RackWidget.hpp
  2. +2
    -4
      src/app/ModuleWidget.cpp
  3. +2
    -2
      src/app/PortWidget.cpp
  4. +15
    -0
      src/app/RackWidget.cpp

+ 1
- 0
include/app/RackWidget.hpp View File

@@ -120,6 +120,7 @@ struct RackWidget : widget::OpaqueWidget {
std::vector<CableWidget*> getCompleteCables(); std::vector<CableWidget*> getCompleteCables();
/** Returns all cables attached to port, complete or not. */ /** Returns all cables attached to port, complete or not. */
std::vector<CableWidget*> getCablesOnPort(PortWidget* port); std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
std::vector<CableWidget*> getCompleteCablesOnPort(PortWidget* port);
/** Returns but does not advance the next cable color. */ /** Returns but does not advance the next cable color. */
int getNextCableColorId(); int getNextCableColorId();
void setNextCableColorId(int id); void setNextCableColorId(int id);


+ 2
- 4
src/app/ModuleWidget.cpp View File

@@ -743,9 +743,7 @@ void ModuleWidget::randomizeAction() {


void ModuleWidget::appendDisconnectActions(history::ComplexAction* complexAction) { void ModuleWidget::appendDisconnectActions(history::ComplexAction* complexAction) {
for (PortWidget* pw : getPorts()) { for (PortWidget* pw : getPorts()) {
for (CableWidget* cw : APP->scene->rack->getCablesOnPort(pw)) {
if (!cw->isComplete())
continue;
for (CableWidget* cw : APP->scene->rack->getCompleteCablesOnPort(pw)) {
// history::CableRemove // history::CableRemove
history::CableRemove* h = new history::CableRemove; history::CableRemove* h = new history::CableRemove;
h->setCable(cw); h->setCable(cw);
@@ -811,7 +809,7 @@ void ModuleWidget::cloneAction(bool cloneCables) {
if (cloneCables) { if (cloneCables) {
// Clone cables attached to input ports // Clone cables attached to input ports
for (PortWidget* pw : getInputs()) { for (PortWidget* pw : getInputs()) {
for (CableWidget* cw : APP->scene->rack->getCablesOnPort(pw)) {
for (CableWidget* cw : APP->scene->rack->getCompleteCablesOnPort(pw)) {
// Create cable attached to cloned ModuleWidget's input // Create cable attached to cloned ModuleWidget's input
engine::Cable* clonedCable = new engine::Cable; engine::Cable* clonedCable = new engine::Cable;
clonedCable->inputModule = clonedModule; clonedCable->inputModule = clonedModule;


+ 2
- 2
src/app/PortWidget.cpp View File

@@ -50,7 +50,7 @@ struct PortTooltip : ui::Tooltip {
text += string::f("% .3fV", math::normalizeZero(v)); text += string::f("% .3fV", math::normalizeZero(v));
} }
// Connected to // Connected to
std::vector<CableWidget*> cables = APP->scene->rack->getCablesOnPort(portWidget);
std::vector<CableWidget*> cables = APP->scene->rack->getCompleteCablesOnPort(portWidget);
for (auto it = cables.rbegin(); it != cables.rend(); it++) { for (auto it = cables.rbegin(); it != cables.rend(); it++) {
CableWidget* cable = *it; CableWidget* cable = *it;
PortWidget* otherPw = (portWidget->type == engine::Port::INPUT) ? cable->outputPort : cable->inputPort; PortWidget* otherPw = (portWidget->type == engine::Port::INPUT) ? cable->outputPort : cable->inputPort;
@@ -226,7 +226,7 @@ void PortWidget::createContextMenu() {
assert(portInfo); assert(portInfo);
menu->addChild(createMenuLabel(portInfo->getFullName())); menu->addChild(createMenuLabel(portInfo->getFullName()));


std::vector<CableWidget*> cws = APP->scene->rack->getCablesOnPort(this);
std::vector<CableWidget*> cws = APP->scene->rack->getCompleteCablesOnPort(this);
CableWidget* topCw = cws.empty() ? NULL : cws.back(); CableWidget* topCw = cws.empty() ? NULL : cws.back();


menu->addChild(createMenuItem("Delete top cable", RACK_MOD_SHIFT_NAME "+click", menu->addChild(createMenuItem("Delete top cable", RACK_MOD_SHIFT_NAME "+click",


+ 15
- 0
src/app/RackWidget.cpp View File

@@ -1398,6 +1398,21 @@ std::vector<CableWidget*> RackWidget::getCablesOnPort(PortWidget* port) {
return cws; return cws;
} }


std::vector<CableWidget*> RackWidget::getCompleteCablesOnPort(PortWidget* port) {
assert(port);
std::vector<CableWidget*> cws;
for (widget::Widget* w : internal->cableContainer->children) {
CableWidget* cw = dynamic_cast<CableWidget*>(w);
assert(cw);
if (!cw->isComplete())
continue;
if (cw->inputPort == port || cw->outputPort == port) {
cws.push_back(cw);
}
}
return cws;
}



int RackWidget::getNextCableColorId() { int RackWidget::getNextCableColorId() {
return internal->nextCableColorId; return internal->nextCableColorId;


Loading…
Cancel
Save