Skip to content

Commit 4d77bf2

Browse files
committed
Working on secondary connection adding
1 parent 56c1614 commit 4d77bf2

File tree

13 files changed

+50
-9
lines changed

13 files changed

+50
-9
lines changed

src/Dataflow/Engine/Controller/NetworkEditorController.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ NetworkEditorController::NetworkEditorController(ModuleFactoryHandle mf, ModuleS
8484
#endif
8585
}
8686

87-
NetworkEditorController::NetworkEditorController(SCIRun::Dataflow::Networks::NetworkHandle network, ExecutionStrategyFactoryHandle executorFactory, NetworkEditorSerializationManager* nesm)
87+
NetworkEditorController::NetworkEditorController(NetworkHandle network, ExecutionStrategyFactoryHandle executorFactory, NetworkEditorSerializationManager* nesm)
8888
: theNetwork_(network), executorFactory_(executorFactory), serializationManager_(nesm),
8989
signalSwitch_(true)
9090
{
@@ -314,14 +314,19 @@ ModuleHandle NetworkEditorController::connectNewModule(const PortDescriptionInte
314314
if (portToConnectUponInsertion)
315315
{
316316
std::cout << "I CAN REQUEST ANOTHER CONNECTION HERE: first port is output, second is " << portToConnectUponInsertion->isInput() << std::endl;
317-
auto fromPort = std::find_if(newMod->outputPorts().begin(), newMod->outputPorts().end(), [portToConnectUponInsertion](OutputPortHandle out) { return out->get_typename() == portToConnectUponInsertion->get_typename(); });
318-
if (fromPort != newMod->outputPorts().end())
317+
auto oports = newMod->outputPorts();
318+
auto fromPort = std::find_if(oports.begin(), oports.end(), [portToConnectUponInsertion](OutputPortHandle out) { return out->get_typename() == portToConnectUponInsertion->get_typename(); });
319+
if (fromPort != oports.end())
320+
{
321+
//removeConnection(*portToConnectUponInsertion->firstConnectionId());
319322
requestConnection(fromPort->get(), portToConnectUponInsertion);
323+
}
320324
}
321325
return newMod;
322326
}
323327
}
324328
}
329+
return newMod;
325330
}
326331

327332
void NetworkEditorController::printNetwork() const
@@ -349,7 +354,7 @@ boost::optional<ConnectionId> NetworkEditorController::requestConnection(const P
349354
PortConnectionDeterminer q;
350355
if (q.canBeConnected(*from, *to))
351356
{
352-
ConnectionId id = theNetwork_->connect(ConnectionOutputPort(theNetwork_->lookupModule(desc.out_.moduleId_), desc.out_.portId_),
357+
auto id = theNetwork_->connect(ConnectionOutputPort(theNetwork_->lookupModule(desc.out_.moduleId_), desc.out_.portId_),
353358
ConnectionInputPort(theNetwork_->lookupModule(desc.in_.moduleId_), desc.in_.portId_));
354359
if (!id.id_.empty())
355360
connectionAdded_(desc);

src/Dataflow/Network/ConnectionId.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ bool SCIRun::Dataflow::Networks::operator!=(const ConnectionDescription& lhs, co
7777
return !(lhs == rhs);
7878
}
7979

80+
std::ostream& SCIRun::Dataflow::Networks::operator<<(std::ostream& o, const ConnectionId& cid)
81+
{
82+
return o << cid.id_;
83+
}
8084

8185
/*static*/ ConnectionId ConnectionId::create(const ConnectionDescription& desc)
8286
{

src/Dataflow/Network/ConnectionId.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace Networks {
8484
SCISHARE bool operator!=(const IncomingConnectionDescription& lhs, const IncomingConnectionDescription& rhs);
8585
SCISHARE bool operator==(const ConnectionDescription& lhs, const ConnectionDescription& rhs);
8686
SCISHARE bool operator!=(const ConnectionDescription& lhs, const ConnectionDescription& rhs);
87+
SCISHARE std::ostream& operator<<(std::ostream& o, const ConnectionId& cid);
8788

8889
struct SCISHARE OrderedByConnectionId
8990
{

src/Dataflow/Network/ModuleDescription.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ModuleId::ModuleId(const std::string& nameIdStr)
9494
if (!regex_match(id_, what, r))
9595
THROW_INVALID_ARGUMENT("Invalid Module Id: " + nameIdStr);
9696
name_ = std::string(what[1]);
97-
idNumber_ = boost::lexical_cast<int>((std::string)what[2]);
97+
idNumber_ = boost::lexical_cast<int>(static_cast<std::string>(what[2]));
9898
}
9999

100100
void ModuleId::setIdString()

src/Dataflow/Network/Network.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ConnectionId Network::connect(const ConnectionOutputPort& out, const ConnectionI
131131

132132
bool Network::disconnect(const ConnectionId& id)
133133
{
134-
Connections::iterator loc = connections_.find(id);
134+
auto loc = connections_.find(id);
135135
if (loc != connections_.end())
136136
{
137137
connections_.erase(loc);

src/Dataflow/Network/Port.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ const Connection* Port::connection(size_t i) const
7373
return connections_[i];
7474
}
7575

76+
boost::optional<ConnectionId> Port::firstConnectionId() const
77+
{
78+
return !connections_.empty() ? connections_[0]->id_ : boost::optional<ConnectionId>();
79+
}
80+
7681
void Port::setIndex(size_t index)
7782
{
7883
index_ = index;

src/Dataflow/Network/Port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class SCISHARE Port : virtual public PortInterface, boost::noncopyable
7474
virtual size_t getIndex() const override;
7575
virtual void setIndex(size_t index) override;
7676

77+
virtual boost::optional<ConnectionId> firstConnectionId() const override;
78+
7779
/// @todo:
7880
// light interface
7981

src/Dataflow/Network/PortInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace Networks {
5656
virtual bool isDynamic() const = 0;
5757
virtual ModuleId getUnderlyingModuleId() const = 0;
5858
virtual size_t getIndex() const = 0;
59+
virtual boost::optional<ConnectionId> firstConnectionId() const = 0;
5960
};
6061

6162
class SCISHARE PortInterface : public PortDescriptionInterface

src/Dataflow/Network/Tests/MockPorts.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <Dataflow/Network/PortInterface.h>
3333
#include <Dataflow/Network/DataflowInterfaces.h>
34+
#include <Dataflow/Network/ConnectionId.h>
3435
#include <boost/optional/optional_io.hpp>
3536
#include <gmock/gmock.h>
3637

@@ -50,6 +51,7 @@ namespace SCIRun {
5051
MOCK_CONST_METHOD0(getUnderlyingModuleId, ModuleId());
5152
MOCK_CONST_METHOD0(getIndex, size_t());
5253
MOCK_CONST_METHOD0(id, PortId());
54+
MOCK_CONST_METHOD0(firstConnectionId, boost::optional<ConnectionId>());
5355
};
5456

5557
typedef boost::shared_ptr<MockPortDescription> MockPortDescriptionPtr;
@@ -75,6 +77,7 @@ namespace SCIRun {
7577
MOCK_CONST_METHOD0(hasChanged, bool());
7678
MOCK_METHOD1(setIndex, void(size_t));
7779
MOCK_METHOD1(connectDataOnPortHasChanged, boost::signals2::connection(const DataOnPortHasChangedSignalType::slot_type&));
80+
MOCK_CONST_METHOD0(firstConnectionId, boost::optional<ConnectionId>());
7881
};
7982

8083
typedef boost::shared_ptr<MockInputPort> MockInputPortPtr;
@@ -101,6 +104,7 @@ namespace SCIRun {
101104
MOCK_CONST_METHOD0(getPortDataDescriber, PortDataDescriber());
102105
MOCK_METHOD1(connectConnectionFeedbackListener, boost::signals2::connection(const ConnectionFeedbackSignalType::slot_type&));
103106
MOCK_METHOD1(sendConnectionFeedback, void(const Core::Datatypes::ModuleFeedback&));
107+
MOCK_CONST_METHOD0(firstConnectionId, boost::optional<ConnectionId>());
104108
};
105109

106110
typedef boost::shared_ptr<MockOutputPort> MockOutputPortPtr;

src/Interface/Application/Connection.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ void ConnectionLine::destroyConnection()
318318
drawer_.reset();
319319
Q_EMIT deleted(id_);
320320
//GuiLogger::Instance().log("Connection deleted.");
321+
qDebug() << "Connection deleted.";
321322
HasNotes::destroy();
322323
NoteDisplayHelper::destroy();
323324
destroyed_ = true;

0 commit comments

Comments
 (0)