Skip to content

Commit 1584fca

Browse files
committed
Distinguish events from parent
1 parent 930521c commit 1584fca

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

src/Interface/Application/NetworkEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ namespace Gui {
264264
size_t childCount() const { return childrenNetworks_.size(); }
265265
void killChild(const QString& name);
266266
void sendItemsToParent();
267+
bool containsModule(const std::string& moduleId) const;
267268

268269
using ConnectorFunc = std::function<void(NetworkEditor*)>;
269270
static void setConnectorFunc(ConnectorFunc func) { connectorFunc_ = func; }

src/Interface/Application/NetworkEditorControllerGuiProxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace Gui {
7474
SCIRun::Dataflow::Networks::NetworkGlobalSettings& getSettings();
7575
boost::shared_ptr<SCIRun::Dataflow::Engine::DisableDynamicPortSwitch> createDynamicPortSwitch();
7676
boost::shared_ptr<NetworkEditorControllerGuiProxy> withSubnet(NetworkEditor* subnet) const;
77+
NetworkEditor* activeNetwork() const { return editor_; }
7778
Q_SIGNALS:
7879
void moduleAdded(const std::string& name, SCIRun::Dataflow::Networks::ModuleHandle module, const SCIRun::Dataflow::Engine::ModuleCounter& count);
7980
void moduleRemoved(const SCIRun::Dataflow::Networks::ModuleId& id);

src/Interface/Application/Subnetworks.cc

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void SubnetModule::execute()
383383
{
384384
}
385385

386-
void SubnetModule::setStateDefaults()
386+
void SubnetModule::setStateDefaults()
387387
{
388388
auto state = get_state();
389389

@@ -777,25 +777,52 @@ SubnetModuleConnector::SubnetModuleConnector(NetworkEditor* parent) :
777777
{
778778
connect(parent, SIGNAL(connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId&)),
779779
this, SLOT(connectionDeletedFromParent()));
780+
781+
connect(parent_->getNetworkEditorController().get(), SIGNAL(moduleAdded(const std::string&, SCIRun::Dataflow::Networks::ModuleHandle, const SCIRun::Dataflow::Engine::ModuleCounter&)),
782+
this, SLOT(moduleAddedToSubnet(const std::string&, SCIRun::Dataflow::Networks::ModuleHandle)));
780783
}
781784

782-
void SubnetModuleConnector::setSubnet(NetworkEditor* subnet)
783-
{
784-
subnet_ = subnet;
785+
void SubnetModuleConnector::setSubnet(NetworkEditor* subnet)
786+
{
787+
subnet_ = subnet;
785788

786789
connect(subnet_->getNetworkEditorController().get(), SIGNAL(moduleAdded(const std::string&, SCIRun::Dataflow::Networks::ModuleHandle, const SCIRun::Dataflow::Engine::ModuleCounter&)),
787790
this, SLOT(moduleAddedToSubnet(const std::string&, SCIRun::Dataflow::Networks::ModuleHandle)));
788791
}
789792

793+
bool SubnetModuleConnector::signalFromParent(QObject* sender) const
794+
{
795+
return qobject_cast<NetworkEditorControllerGuiProxy*>(sender)->activeNetwork() == parent_;
796+
}
797+
798+
bool SubnetModuleConnector::signalFromSubnet(QObject* sender) const
799+
{
800+
return qobject_cast<NetworkEditorControllerGuiProxy*>(sender)->activeNetwork() == subnet_;
801+
}
802+
790803
void SubnetModuleConnector::moduleAddedToSubnet(const std::string& s, ModuleHandle module)
791804
{
792-
qDebug() << __FUNCTION__;
793-
qDebug() << "was:" << module_->underlyingModules_.size();
794-
module_->underlyingModules_.push_back(module);
795-
qDebug() << "now:" << module_->underlyingModules_.size() << "added" << s.c_str();
805+
//qDebug() << __FUNCTION__ << sender() << signalFromSubnet(sender()) << signalFromParent(sender());
806+
if (signalFromSubnet(sender()) && subnet_->containsModule(module->get_id().id_))
807+
{
808+
qDebug() << "was:" << module_->underlyingModules_.size();
809+
module_->underlyingModules_.push_back(module);
810+
qDebug() << "now:" << module_->underlyingModules_.size() << "added" << s.c_str();
811+
}
812+
}
813+
814+
bool NetworkEditor::containsModule(const std::string& id) const
815+
{
816+
Q_FOREACH(QGraphicsItem* item, scene_->items())
817+
{
818+
auto module = getModule(item);
819+
if (module && module->getModuleId() == id)
820+
return true;
821+
}
822+
return false;
796823
}
797824

798825
void SubnetModuleConnector::connectionDeletedFromParent()
799826
{
800827
qDebug() << __FUNCTION__;
801-
}
828+
}

src/Interface/Application/Subnetworks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ namespace SCIRun
7777
NetworkEditor* parent_;
7878
NetworkEditor* subnet_;
7979
SubnetModule* module_;
80+
bool signalFromParent(QObject* sender) const;
81+
bool signalFromSubnet(QObject* sender) const;
8082
};
8183

8284
class SubnetModule : public Dataflow::Networks::Module

0 commit comments

Comments
 (0)