Browse Source

If input or output PortWidgets do not exist when adding a CableWidget, delete the CableWidget and remove Cable from Engine.

tags/v2.0.3
Andrew Belt 3 years ago
parent
commit
7317ac5afd
2 changed files with 30 additions and 15 deletions
  1. +15
    -10
      src/app/CableWidget.cpp
  2. +15
    -5
      src/app/RackWidget.cpp

+ 15
- 10
src/app/CableWidget.cpp View File

@@ -166,17 +166,22 @@ void CableWidget::setCable(engine::Cable* cable) {
delete this->cable;
this->cable = NULL;
}
this->cable = cable;
if (cable) {
app::ModuleWidget* outputModule = APP->scene->rack->getModule(cable->outputModule->id);
assert(outputModule);
outputPort = outputModule->getOutput(cable->outputId);
assert(outputPort);

app::ModuleWidget* inputModule = APP->scene->rack->getModule(cable->inputModule->id);
assert(inputModule);
inputPort = inputModule->getInput(cable->inputId);
assert(inputPort);
app::ModuleWidget* outputMw = APP->scene->rack->getModule(cable->outputModule->id);
if (!outputMw)
throw Exception("Cable cannot find output ModuleWidget %lld", cable->outputModule->id);
outputPort = outputMw->getOutput(cable->outputId);
if (!outputPort)
throw Exception("Cable cannot find output port %d", cable->outputId);

app::ModuleWidget* inputMw = APP->scene->rack->getModule(cable->inputModule->id);
if (!inputMw)
throw Exception("Cable cannot find input ModuleWidget %lld", cable->inputModule->id);
inputPort = inputMw->getInput(cable->inputId);
if (!inputPort)
throw Exception("Cable cannot find input port %d", cable->inputId);

this->cable = cable;
}
else {
outputPort = NULL;


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

@@ -395,6 +395,7 @@ void RackWidget::fromJson(json_t* rootJ) {
// Get cable ID
json_t* idJ = json_object_get(cableJ, "id");
int64_t id;
// In <=v0.6, the cable ID was the index in the array.
if (idJ)
id = json_integer_value(idJ);
else
@@ -409,11 +410,20 @@ void RackWidget::fromJson(json_t* rootJ) {

// Create CableWidget
CableWidget* cw = new CableWidget;
cw->setCable(cable);
cw->fromJson(cableJ);
// In <=v1, cable colors were not serialized, so choose one from the available colors.
if (cw->color.a == 0.f) {
cw->color = getNextCableColor();
try {
cw->setCable(cable);
cw->fromJson(cableJ);
// In <=v1, cable colors were not serialized, so choose one from the available colors.
if (cw->color.a == 0.f) {
cw->color = getNextCableColor();
}
}
catch (Exception& e) {
delete cw;
// If creating CableWidget fails, remove Cable from Engine.
APP->engine->removeCable(cable);
delete cable;
continue;
}
addCable(cw);
}


Loading…
Cancel
Save