Skip to content

Commit c7b59fb

Browse files
authored
Merge pull request #1633 from SCIInstitute/subnet2
Subnet2
2 parents eae7f2a + ace78ef commit c7b59fb

File tree

6 files changed

+78
-51
lines changed

6 files changed

+78
-51
lines changed

src/Interface/Application/Connection.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ void ConnectionLine::trackNodes()
374374
void ConnectionLine::addSubnetCompanion(PortWidget* subnetPort)
375375
{
376376
qDebug() << id().id_.c_str() << "setup companion with" << subnetPort;
377+
//setVisible(false);
378+
ConnectionFactory f(nullptr);
379+
380+
auto out = subnetPort->isInput() ? fromPort_ : subnetPort;
381+
auto in = subnetPort->isInput() ? subnetPort : toPort_;
382+
383+
ConnectionDescription cd{ { out->getUnderlyingModuleId(), out->id() }, { in->getUnderlyingModuleId(), in->id() } };
384+
f.makeFinishedConnection(out, in, ConnectionId::create(cd));
377385
}
378386

379387
void ConnectionLine::setDrawStrategy(ConnectionDrawStrategyPtr cds)

src/Interface/Application/MainWindowCollaborators.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ void NetworkEditorBuilder::connectAll(NetworkEditor* editor)
379379
QObject::connect(mainWindow_->actionSelectAll_, SIGNAL(triggered()), editor, SLOT(selectAll()));
380380
QObject::connect(mainWindow_->actionDelete_, SIGNAL(triggered()), editor, SLOT(del()));
381381
QObject::connect(mainWindow_->actionCleanUpNetwork_, SIGNAL(triggered()), editor, SLOT(cleanUpNetwork()));
382-
QObject::connect(mainWindow_->actionMakeSubnetwork_, SIGNAL(triggered()), editor, SLOT(makeSubnetwork()));
383382
QObject::connect(editor, SIGNAL(zoomLevelChanged(int)), mainWindow_, SLOT(showZoomStatusMessage(int)));
384383
QObject::connect(mainWindow_->actionCut_, SIGNAL(triggered()), editor, SLOT(cut()));
385384
QObject::connect(mainWindow_->actionCopy_, SIGNAL(triggered()), editor, SLOT(copy()));
@@ -393,6 +392,7 @@ void NetworkEditorBuilder::connectAll(NetworkEditor* editor)
393392
QObject::connect(mainWindow_->actionPinAllModuleUIs_, SIGNAL(triggered()), editor, SLOT(pinAllModuleUIs()));
394393
QObject::connect(mainWindow_->actionRestoreAllModuleUIs_, SIGNAL(triggered()), editor, SLOT(restoreAllModuleUIs()));
395394
QObject::connect(mainWindow_->actionHideAllModuleUIs_, SIGNAL(triggered()), editor, SLOT(hideAllModuleUIs()));
395+
QObject::connect(mainWindow_->actionMakeSubnetwork_, SIGNAL(triggered()), editor, SLOT(makeSubnetwork()));
396396
}
397397
// children only
398398
// addDockWidget(Qt::RightDockWidgetArea, subnet);

src/Interface/Application/ModuleWidget.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ void PortWidgetManager::addPort(OutputPortWidget* port)
829829
void PortWidgetManager::addPort(InputPortWidget* port)
830830
{
831831
inputPorts_.push_back(port);
832+
port->setSceneFunc(getScene_);
832833
}
833834

834835
void PortWidgetManager::insertPort(int index, InputPortWidget* port)
@@ -837,6 +838,7 @@ void PortWidgetManager::insertPort(int index, InputPortWidget* port)
837838
inputPorts_.push_back(port);
838839
else
839840
inputPorts_.insert(inputPorts_.begin() + index, port);
841+
port->setSceneFunc(getScene_);
840842
}
841843

842844
void PortWidgetManager::setHighlightPorts(bool on)

src/Interface/Application/NetworkEditor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace SCIRun {
5959
namespace Gui {
6060

6161
class DialogErrorControl;
62-
62+
6363
class CurrentModuleSelection
6464
{
6565
public:
@@ -163,8 +163,8 @@ namespace Gui {
163163
class ModuleWidget;
164164
class NetworkEditorControllerGuiProxy;
165165
class DialogErrorControl;
166-
using PortRewiringMap = std::map<std::string, std::map<std::string, Dataflow::Networks::PortId>>;
167-
using PortRewiringMap2 = std::map<std::string, ConnectionLine*>;
166+
class PortWidget;
167+
using PortRewiringMap = std::map<std::string, ConnectionLine*>;
168168

169169
struct NetworkEditorParameters
170170
{
@@ -413,7 +413,7 @@ namespace Gui {
413413
void setupPortHolder(const std::vector<SharedPointer<SCIRun::Dataflow::Networks::PortDescriptionInterface>>& ports, const QString& name,
414414
std::function<QPointF(const QRectF&)> position);
415415
PortRewiringMap portRewiringMap_;
416-
PortRewiringMap2 portRewiringMap2_;
416+
QSet<QString> currentSubnetNames_;
417417

418418
static NetworkEditor* inEditingContext_;
419419
struct InEditingContext

src/Interface/Application/Port.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,12 @@ void PortWidget::connectToSubnetPort(PortWidget* subnetPort)
482482
auto in = isInput_ ? this : subnetPort;
483483

484484
ConnectionDescription cd { { out->moduleId_, out->portId_ }, { in->moduleId_, in->portId_ } };
485-
connectionFactory_()->makeFinishedConnection(out, in, ConnectionId::create(cd));
485+
if (connectionFactory_ && connectionFactory_())
486+
connectionFactory_()->makeFinishedConnection(out, in, ConnectionId::create(cd));
487+
else
488+
{
489+
qDebug() << "NO CONNECTION FACTORY AVAILABLE!!";
490+
}
486491
//TODO: position provider needs adjustment
487492
//TODO: management of return value?
488493
}
@@ -601,7 +606,7 @@ void PortWidget::forEachPort(Func func, Pred pred)
601606

602607
void PortWidget::makePotentialConnectionLine(PortWidget* other)
603608
{
604-
if (getScene_() != other->getScene_())
609+
if (other && getScene_ && other->getScene_ && getScene_() != other->getScene_())
605610
return;
606611

607612
auto potentials = potentialConnectionsMap_[this];

src/Interface/Application/Subnetworks.cc

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,16 @@ void NetworkEditor::setupPortHolder(const std::vector<SharedPointer<PortDescript
163163

164164
for (const auto& port : ports)
165165
{
166-
auto portRepl = new SubnetOutputPortWidget(QString::fromStdString(port->get_portname()),
166+
auto portRepl = new SubnetOutputPortWidget(QString::fromStdString(port->get_portname()),
167167
to_color(PortColorLookup::toColor(port->get_typename()), 230), port->get_typename());
168168
layout->addWidget(portRepl);
169169

170-
//qDebug() << "port subnet in editor" << QString::fromStdString(port->id().toString()) <<
171-
// portRewiringMap2_[port->id().toString()]->id().id_.c_str();
170+
//qDebug() << "port subnet in editor" << QString::fromStdString(port->id().toString());
171+
//<< portRewiringMap2_[port->id().toString()]->id().id_.c_str();
172172

173-
portRewiringMap2_[port->id().toString()]->addSubnetCompanion(portRepl);
173+
portRewiringMap_[port->id().toString()]->addSubnetCompanion(portRepl);
174174
}
175-
portRewiringMap_.clear();
176-
portRewiringMap2_.clear();
177-
175+
178176
portsBridge->setLayout(layout);
179177

180178
auto proxy = new QGraphicsProxyWidget;
@@ -199,6 +197,7 @@ void NetworkEditor::setupPortHolders(ModuleHandle mod)
199197
{
200198
setupPortHolder(upcast_range<PortDescriptionInterface>(mod->inputPorts()), "Inputs", [](const QRectF& rect) { return rect.topLeft(); });
201199
setupPortHolder(upcast_range<PortDescriptionInterface>(mod->outputPorts()), "Outputs", [](const QRectF& rect) { return rect.bottomLeft() + QPointF(0, -23); });
200+
portRewiringMap_.clear();
202201
}
203202

204203
void NetworkEditor::initializeSubnet(const QString& name, ModuleHandle mod, NetworkEditor* subnet)
@@ -231,31 +230,31 @@ void NetworkEditor::initializeSubnet(const QString& name, ModuleHandle mod, Netw
231230

232231

233232

234-
auto firstMatch = subnet->portRewiringMap_.find(conn->connectedPorts().first->getUnderlyingModuleId().id_);
235-
if (firstMatch != subnet->portRewiringMap_.end())
236-
{
237-
//qDebug() << "found match for conn end--first";
238-
auto portMatch = firstMatch->second.find(conn->connectedPorts().first->id().toString());
239-
if (portMatch != firstMatch->second.end())
240-
{
241-
//qDebug() << "\tand found port match at" << portMatch->second.toString().c_str();
242-
subnet->portRewiringMap2_[portMatch->second.toString()] = conn;
243-
}
244-
}
245-
else
246-
{
247-
auto secondMatch = subnet->portRewiringMap_.find(conn->connectedPorts().second->getUnderlyingModuleId().id_);
248-
if (secondMatch != subnet->portRewiringMap_.end())
249-
{
250-
//qDebug() << "found match for conn end--second";
251-
auto portMatch = secondMatch->second.find(conn->connectedPorts().second->id().toString());
252-
if (portMatch != secondMatch->second.end())
253-
{
254-
//qDebug() << "\tand found port match at" << portMatch->second.toString().c_str();
255-
subnet->portRewiringMap2_[portMatch->second.toString()] = conn;
256-
}
257-
}
258-
}
233+
//auto firstMatch = subnet->portRewiringMap_.find(conn->connectedPorts().first->getUnderlyingModuleId().id_);
234+
//if (firstMatch != subnet->portRewiringMap_.end())
235+
//{
236+
// //qDebug() << "found match for conn end--first";
237+
// auto portMatch = firstMatch->second.find(conn->connectedPorts().first->id().toString());
238+
// if (portMatch != firstMatch->second.end())
239+
// {
240+
// //qDebug() << "\tand found port match at" << portMatch->second.toString().c_str();
241+
// subnet->portRewiringMap2_[portMatch->second.toString()] = conn;
242+
// }
243+
//}
244+
//else
245+
//{
246+
// auto secondMatch = subnet->portRewiringMap_.find(conn->connectedPorts().second->getUnderlyingModuleId().id_);
247+
// if (secondMatch != subnet->portRewiringMap_.end())
248+
// {
249+
// //qDebug() << "found match for conn end--second";
250+
// auto portMatch = secondMatch->second.find(conn->connectedPorts().second->id().toString());
251+
// if (portMatch != secondMatch->second.end())
252+
// {
253+
// //qDebug() << "\tand found port match at" << portMatch->second.toString().c_str();
254+
// subnet->portRewiringMap2_[portMatch->second.toString()] = conn;
255+
// }
256+
// }
257+
//}
259258
}
260259
}
261260
}
@@ -370,13 +369,22 @@ void NetworkEditor::makeSubnetwork()
370369
}
371370

372371
bool ok;
373-
auto name = QInputDialog::getText(nullptr, "Make subnet", "Enter subnet name:", QLineEdit::Normal, "subnet", &ok);
374-
if (!ok || name.isEmpty())
372+
auto name = QInputDialog::getText(nullptr, "Make subnet", "Enter subnet name:", QLineEdit::Normal, "subnet" + QString::number(currentSubnetNames_.size()), &ok);
373+
if (!ok)
374+
return;
375+
376+
if (name.isEmpty())
375377
{
376378
QMessageBox::information(this, "Make subnetwork", "Invalid name.");
377379
return;
378380
}
379381

382+
if (currentSubnetNames_.contains(name))
383+
{
384+
QMessageBox::information(this, "Make subnetwork", "A subnet by that name already exists.");
385+
return;
386+
}
387+
380388
makeSubnetworkFromComponents(name, underlyingModules, includeConnections(items), rect);
381389
}
382390

@@ -409,12 +417,12 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
409417
{
410418
auto portToReplicate = ports.second;
411419
auto id = addSubnetToId(portToReplicate);
412-
413-
//qDebug() << "port being replicated" << id.toString().c_str() <<
414-
// portToReplicate->id().toString().c_str() <<
415-
// portToReplicate->getUnderlyingModuleId().id_.c_str();
416420

417-
map_[portToReplicate->getUnderlyingModuleId().id_][portToReplicate->id().toString()] = id;
421+
qDebug() << "port being replicated" << id.toString().c_str() <<
422+
portToReplicate->id().toString().c_str() <<
423+
portToReplicate->getUnderlyingModuleId().id_.c_str();
424+
425+
map_[id.toString()] = conn;
418426

419427
desc.input_ports_.emplace_back(id, portToReplicate->get_typename(), portToReplicate->isDynamic());
420428
ports.first->setProperty(SUBNET_PORT_ID_TO_FIND, QString::fromStdString(id.toString()));
@@ -423,12 +431,12 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
423431
{
424432
auto portToReplicate = ports.first;
425433
auto id = addSubnetToId(portToReplicate);
426-
434+
427435
//qDebug() << "port being replicated" << id.toString().c_str() <<
428436
// portToReplicate->id().toString().c_str() <<
429437
// portToReplicate->getUnderlyingModuleId().id_.c_str();
430438

431-
map_[portToReplicate->getUnderlyingModuleId().id_][portToReplicate->id().toString()] = id;
439+
map_[id.toString()] = conn;
432440

433441
desc.output_ports_.emplace_back(id, portToReplicate->get_typename(), portToReplicate->isDynamic());
434442
ports.second->setProperty(SUBNET_PORT_ID_TO_FIND, QString::fromStdString(id.toString()));
@@ -448,7 +456,7 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
448456

449457
const PortRewiringMap& getMap() const
450458
{
451-
return map_;
459+
return map_;
452460
}
453461
private:
454462
mutable PortRewiringMap map_;
@@ -457,6 +465,8 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
457465
void NetworkEditor::makeSubnetworkFromComponents(const QString& name, const std::vector<ModuleHandle>& modules,
458466
QList<QGraphicsItem*> items, const QRectF& rect)
459467
{
468+
currentSubnetNames_.insert(name);
469+
460470
SubnetModuleFactory factory;
461471
auto subnetModule = factory.makeSubnet(name, modules, items);
462472
portRewiringMap_ = factory.getMap();
@@ -469,7 +479,8 @@ void NetworkEditor::makeSubnetworkFromComponents(const QString& name, const std:
469479

470480
auto colorize = new QGraphicsDropShadowEffect;
471481
colorize->setColor(QColor(255,182,193,200));
472-
colorize->setOffset(8,8);
482+
colorize->setOffset(10, 6);
483+
colorize->setBlurRadius(30);
473484
proxy->setGraphicsEffect(colorize);
474485

475486
auto pic = grabSubnetPic(rect);
@@ -524,7 +535,7 @@ void NetworkEditor::makeSubnetworkFromComponents(const QString& name, const std:
524535
childrenNetworkItems_[name] = items;
525536

526537
addSubnetChild(name, subnetModule);
527-
qDebug() << "port repl map out of scope";
538+
//qDebug() << "port repl map out of scope";
528539
}
529540

530541
QPixmap NetworkEditor::grabSubnetPic(const QRectF& rect)
@@ -616,5 +627,6 @@ void NetworkEditor::killChild(const QString& name)
616627
subnetIter->second->get()->clear();
617628
subnetIter->second->deleteLater();
618629
childrenNetworks_.erase(subnetIter);
630+
currentSubnetNames_.remove(name);
619631
}
620632
}

0 commit comments

Comments
 (0)