Skip to content

Commit a065668

Browse files
committed
Working on move/unmove
1 parent ae56c0a commit a065668

File tree

13 files changed

+48
-11
lines changed

13 files changed

+48
-11
lines changed

src/Dataflow/Engine/Controller/NetworkEditorController.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,15 @@ void NetworkEditorController::updateModulePositions(const ModulePositions& modul
935935
}
936936
}
937937

938+
bool NetworkEditorController::moveModule(const std::string& id, double x, double y)
939+
{
940+
if (collabs_.serializationManager_)
941+
{
942+
return collabs_.serializationManager_->updateModulePosition(id, x, y);
943+
}
944+
return false;
945+
}
946+
938947
void NetworkEditorController::cleanUpNetwork()
939948
{
940949
auto all = [](ModuleHandle) { return true; };

src/Dataflow/Engine/Controller/NetworkEditorController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ namespace Engine {
112112
Networks::ModuleHandle addModule(const Networks::ModuleLookupInfo& info) override;
113113
Networks::ModuleHandle addModule(const std::string& name);
114114
bool removeModule(const Networks::ModuleId& id);
115+
bool moveModule(const std::string& id, double x, double y);
115116

116117
Networks::ModuleHandle duplicateModule(const Networks::ModuleHandle& module);
117118
Networks::ModuleHandle connectNewModule(const Networks::PortDescriptionInterface* portToConnect, const std::string& newModuleName);

src/Dataflow/Engine/Controller/ProvenanceItemImpl.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ std::string ConnectionRemovedProvenanceItem::name() const
120120
return "Connection Removed: " + id_.id_;
121121
}
122122

123-
ModuleMovedProvenanceItem::ModuleMovedProvenanceItem(const SCIRun::Dataflow::Networks::ModuleId& moduleId, double newX, double newY, NetworkFileHandle state, SharedPointer<NetworkEditorPythonInterface> nedPy)
124-
: ProvenanceItemBase(state, nedPy), moduleId_(moduleId), newX_(newX), newY_(newY)
123+
ModuleMovedProvenanceItem::ModuleMovedProvenanceItem(const SCIRun::Dataflow::Networks::ModuleId& moduleId, double newX, double newY, double oldX, double oldY,
124+
NetworkFileHandle state, SharedPointer<NetworkEditorPythonInterface> nedPy)
125+
: ProvenanceItemBase(state, nedPy), moduleId_(moduleId), newX_(newX), newY_(newY), oldX_(oldX), oldY_(oldY)
125126
{
126127
}
127128

@@ -131,3 +132,13 @@ std::string ModuleMovedProvenanceItem::name() const
131132
ostr << "Module " << moduleId_.id_ << " moved to (" << newX_ << "," << newY_ << ")";
132133
return ostr.str();
133134
}
135+
136+
std::string ModuleMovedProvenanceItem::undoCode() const
137+
{
138+
return fmt::format("scirun_move_module(\"{}\", {}, {})", moduleId_.id_, oldX_, oldY_);
139+
}
140+
141+
std::string ModuleMovedProvenanceItem::redoCode() const
142+
{
143+
return fmt::format("scirun_move_module(\"{}\", {}, {})", moduleId_.id_, newX_, newY_);
144+
}

src/Dataflow/Engine/Controller/ProvenanceItemImpl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ namespace Engine {
101101
class SCISHARE ModuleMovedProvenanceItem : public ProvenanceItemBase
102102
{
103103
public:
104-
ModuleMovedProvenanceItem(const SCIRun::Dataflow::Networks::ModuleId& moduleId, double newX, double newY, Networks::NetworkFileHandle state, SharedPointer<NetworkEditorPythonInterface> nedPy);
104+
ModuleMovedProvenanceItem(const SCIRun::Dataflow::Networks::ModuleId& moduleId, double newX, double newY,
105+
double oldX, double oldY,
106+
Networks::NetworkFileHandle state, SharedPointer<NetworkEditorPythonInterface> nedPy);
105107
std::string name() const override;
106-
std::string undoCode() const override { throw "not implemented"; }
107-
std::string redoCode() const override { throw "not implemented"; }
108+
std::string undoCode() const override;
109+
std::string redoCode() const override;
108110
private:
109111
SCIRun::Dataflow::Networks::ModuleId moduleId_;
110-
double newX_, newY_;
112+
double newX_, newY_, oldX_, oldY_;
111113
};
112114
}
113115
}

src/Dataflow/Engine/Controller/PythonImpl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,4 +662,9 @@ std::string PythonImpl::quit(bool force)
662662
return "Quit after execute enabled.";
663663
}
664664

665+
std::string PythonImpl::moveModule(const std::string& id, double x, double y)
666+
{
667+
return nec_.moveModule(id, x, y) ? "Module moved." : "Module not found.";
668+
}
669+
665670
#endif

src/Dataflow/Engine/Controller/PythonImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace Engine {
6969
void setModuleContext(bool inModule) override { inModule_ = inModule; }
7070
bool isModuleContext() const override { return inModule_; }
7171
std::string mostRecentAddModuleId() const override { return mostRecentAddModuleId_; }
72+
std::string moveModule(const std::string& id, double x, double y) override;
7273
private:
7374
void pythonModuleAddedSlot(const std::string&, Networks::ModuleHandle, ModuleCounter);
7475
void pythonModuleRemovedSlot(const Networks::ModuleId&);

src/Dataflow/Engine/Controller/Tests/ProvenanceItemTests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ProvenanceItemTests : public ::testing::Test
6262
TEST_F(ProvenanceItemTests, CanCreateAddModule)
6363
{
6464
const std::string name = "ComputeSVD";
65-
ModuleAddedProvenanceItem item(name, name + ":0", NetworkFileHandle());
65+
ModuleAddedProvenanceItem item(name, name + ":0", nullptr, nullptr);
6666

6767
EXPECT_EQ("Module Added: " + name, item.name());
6868
EXPECT_EQ("scirun_add_module(\"ComputeSVD\")", item.redoCode());
@@ -72,7 +72,7 @@ TEST_F(ProvenanceItemTests, CanCreateAddModule)
7272
TEST_F(ProvenanceItemTests, CanCreateRemoveModule)
7373
{
7474
const std::string id = "ComputeSVD1";
75-
ModuleRemovedProvenanceItem item((ModuleId(id)), NetworkFileHandle());
75+
ModuleRemovedProvenanceItem item((ModuleId(id)), nullptr, nullptr);
7676

7777
EXPECT_EQ("Module Removed: " + id, item.name());
7878
}

src/Dataflow/Engine/Python/NetworkEditorPythonAPI.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ std::string NetworkEditorPythonAPI::removeModule(const std::string& id)
130130
}
131131
}
132132

133+
std::string NetworkEditorPythonAPI::moveModule(const std::string& id, double x, double y)
134+
{
135+
std::cout << "TODO: move module " << id << " " << x << " " << y << std::endl;
136+
return "move";
137+
}
138+
133139
std::vector<SharedPointer<PyModule>> NetworkEditorPythonAPI::modules()
134140
{
135141
Guard g(pythonLock_);

src/Dataflow/Engine/Python/NetworkEditorPythonAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace SCIRun {
5151
static PyModulePtr addModule(const std::string& name);
5252
static std::vector<PyModulePtr> modules();
5353
static std::string removeModule(const std::string& id);
54+
static std::string moveModule(const std::string& id, double x, double y);
5455
static std::string connect(const std::string& moduleIdFrom, int fromIndex, const std::string& moduleIdTo, int toIndex);
5556
static std::string disconnect(const std::string& moduleIdFrom, int fromIndex, const std::string& moduleIdTo, int toIndex);
5657
static boost::python::object scirun_get_module_state(const std::string& moduleId, const std::string& stateVariable);

src/Dataflow/Engine/Python/NetworkEditorPythonInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ namespace SCIRun
143143
virtual void setModuleContext(bool inModule) = 0;
144144
virtual bool isModuleContext() const = 0;
145145
virtual std::string mostRecentAddModuleId() const = 0;
146+
virtual std::string moveModule(const std::string& id, double x, double y) = 0;
146147
};
147148
}
148149

0 commit comments

Comments
 (0)