@@ -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
204203void 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 }
453461private:
454462 mutable PortRewiringMap map_;
@@ -457,6 +465,8 @@ class SubnetModuleFactory : public Modules::Factory::HardCodedModuleFactory
457465void 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
530541QPixmap 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