@@ -126,6 +126,7 @@ void NetworkEditor::addSubnetChild(const QString& name, ModuleHandle mod)
126126 if (it == childrenNetworks_.end ())
127127 {
128128 auto subnet = new NetworkEditor (ctorParams_);
129+ subnet->portRewiringMap_ .swap (portRewiringMap_);
129130 initializeSubnet (name, mod, subnet);
130131 }
131132 else
@@ -159,15 +160,20 @@ void NetworkEditor::setupPortHolder(const std::vector<SharedPointer<PortDescript
159160 layout->setSpacing (4 );
160161 layout->setAlignment (Qt::AlignLeft);
161162 layout->setContentsMargins (5 , 0 , 5 , 0 );
162-
163+
163164 for (const auto & port : ports)
164165 {
165166 auto portRepl = new SubnetOutputPortWidget (QString::fromStdString (port->get_portname ()),
166167 to_color (PortColorLookup::toColor (port->get_typename ()), 230 ), port->get_typename ());
167168 layout->addWidget (portRepl);
168169
169- // qDebug() << "port subnet in editor" << QString::fromStdString(port->id().toString());
170+ // qDebug() << "port subnet in editor" << QString::fromStdString(port->id().toString()) <<
171+ // portRewiringMap2_[port->id().toString()]->id().id_.c_str();
172+
173+ portRewiringMap2_[port->id ().toString ()]->addSubnetCompanion (portRepl);
170174 }
175+ portRewiringMap_.clear ();
176+ portRewiringMap2_.clear ();
171177
172178 portsBridge->setLayout (layout);
173179
@@ -207,16 +213,53 @@ void NetworkEditor::initializeSubnet(const QString& name, ModuleHandle mod, Netw
207213 subnet->scene_ ->addItem (item);
208214 if (qgraphicsitem_cast<ModuleProxyWidget*>(item))
209215 item->setVisible (true );
210- else if (qgraphicsitem_cast<ConnectionLine*>(item))
216+ else
211217 {
212- // item->setVisible(item->data(IS_INTERNAL).toBool());
213- item->setVisible (true );
214- if (item->data (SUBNET_KEY).toInt () == EXTERNAL_SUBNET_CONNECTION)
218+ auto conn = qgraphicsitem_cast<ConnectionLine*>(item);
219+ if (conn)
215220 {
216- auto conn = qgraphicsitem_cast<ConnectionLine*>(item);
217- // qDebug() << "hidden external connection ports" << conn->connectedPorts().first->id().toString().c_str() << conn->connectedPorts().second->id().toString().c_str();
221+ // item->setVisible(item->data(IS_INTERNAL).toBool());
222+ item->setVisible (true );
223+ if (item->data (SUBNET_KEY).toInt () == EXTERNAL_SUBNET_CONNECTION)
224+ {
225+
226+ // qDebug() << "hidden external connection ports" << conn->connectedPorts().first->id().toString().c_str()
227+ // << conn->connectedPorts().first->getUnderlyingModuleId().id_.c_str()
228+ // << conn->connectedPorts().second->id().toString().c_str()
229+ // << conn->connectedPorts().second->getUnderlyingModuleId().id_.c_str()
230+ // ;
231+
232+
233+
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+ }
259+ }
218260 }
219261 }
262+
220263 item->ensureVisible ();
221264 }
222265
@@ -371,6 +414,8 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
371414 // portToReplicate->id().toString().c_str() <<
372415 // portToReplicate->getUnderlyingModuleId().id_.c_str();
373416
417+ map_[portToReplicate->getUnderlyingModuleId ().id_ ][portToReplicate->id ().toString ()] = id;
418+
374419 desc.input_ports_ .emplace_back (id, portToReplicate->get_typename (), portToReplicate->isDynamic ());
375420 ports.first ->setProperty (SUBNET_PORT_ID_TO_FIND, QString::fromStdString (id.toString ()));
376421 }
@@ -383,6 +428,8 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
383428 // portToReplicate->id().toString().c_str() <<
384429 // portToReplicate->getUnderlyingModuleId().id_.c_str();
385430
431+ map_[portToReplicate->getUnderlyingModuleId ().id_ ][portToReplicate->id ().toString ()] = id;
432+
386433 desc.output_ports_ .emplace_back (id, portToReplicate->get_typename (), portToReplicate->isDynamic ());
387434 ports.second ->setProperty (SUBNET_PORT_ID_TO_FIND, QString::fromStdString (id.toString ()));
388435 }
@@ -398,13 +445,21 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
398445
399446 return mod;
400447 }
448+
449+ const PortRewiringMap& getMap () const
450+ {
451+ return map_;
452+ }
453+ private:
454+ mutable PortRewiringMap map_;
401455};
402456
403457void NetworkEditor::makeSubnetworkFromComponents (const QString& name, const std::vector<ModuleHandle>& modules,
404458 QList<QGraphicsItem*> items, const QRectF& rect)
405459{
406- static SubnetModuleFactory factory;
460+ SubnetModuleFactory factory;
407461 auto subnetModule = factory.makeSubnet (name, modules, items);
462+ portRewiringMap_ = factory.getMap ();
408463
409464 auto moduleWidget = new SubnetWidget (this , name, subnetModule, dialogErrorControl_);
410465 auto proxy = setupModuleWidget (moduleWidget);
@@ -469,6 +524,7 @@ void NetworkEditor::makeSubnetworkFromComponents(const QString& name, const std:
469524 childrenNetworkItems_[name] = items;
470525
471526 addSubnetChild (name, subnetModule);
527+ qDebug () << " port repl map out of scope" ;
472528}
473529
474530QPixmap NetworkEditor::grabSubnetPic (const QRectF& rect)
0 commit comments