3#include "AutomationDropHandler.hpp"
5#include <Device/Node/NodeListMimeSerialization.hpp>
7#include <Process/ProcessMimeSerialization.hpp>
9#include <Scenario/Commands/Cohesion/CreateCurves.hpp>
10#include <Scenario/Commands/CommandAPI.hpp>
11#include <Scenario/Document/ScenarioEditor.hpp>
12#include <Scenario/Commands/Scenario/PasteAnchors.hpp>
13#include <Scenario/Commands/Interval/AddLayerInNewSlot.hpp>
14#include <Scenario/Commands/Interval/AddProcessToInterval.hpp>
15#include <Scenario/Commands/Interval/ResizeInterval.hpp>
16#include <Scenario/Commands/Metadata/ChangeElementName.hpp>
17#include <Scenario/Commands/Scenario/ScenarioPasteElements.hpp>
18#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
19#include <Scenario/Process/ScenarioModel.hpp>
20#include <Scenario/Process/ScenarioPresenter.hpp>
22#include <Dataflow/Commands/CableHelpers.hpp>
24#include <score/document/DocumentContext.hpp>
26#include <ossia/detail/thread.hpp>
27#include <ossia/network/value/value_traits.hpp>
34DropScenario::DropScenario()
37 m_acceptableSuffixes.push_back(
"scenario");
40bool DropScenario::drop(
41 const ScenarioPresenter& pres, QPointF pos,
const QMimeData& mime)
45 const auto& doc = pres.context().context;
46 auto& sm = pres.model();
47 auto path = mime.urls().first().toLocalFile();
48 if(QFile f{path}; QFileInfo{f}.suffix() ==
"scenario" && f.open(QIODevice::ReadOnly))
52 sm, readJson(f.readAll()), pres.toScenarioPoint(pos)));
60DropScoreInScenario::DropScoreInScenario()
62 m_acceptableSuffixes.push_back(
"score");
63 m_acceptableSuffixes.push_back(
"scorebin");
66bool DropScoreInScenario::drop(
67 const ScenarioPresenter& pres, QPointF pos,
const QMimeData& mime)
71 const auto& doc = pres.context().context;
72 auto& sm = pres.model();
73 auto path = mime.urls().first().toLocalFile();
74 if(QFile f{path}; QFileInfo{f}.suffix() ==
"score" && f.open(QIODevice::ReadOnly))
76 rapidjson::Document res;
79 auto obj = readJson(f.readAll());
80 auto& docobj = obj[
"Document"];
84 res.AddMember(
"Cables", docobj[
"Cables"], res.GetAllocator());
85 for(
auto& c : res[
"Cables"].GetArray())
87 auto source = c[
"Source"].GetArray();
88 source.Erase(source.Begin());
89 source.Erase(source.Begin());
90 auto sink = c[
"Sink"].GetArray();
91 sink.Erase(sink.Begin());
92 sink.Erase(sink.Begin());
95 auto& scenar = docobj[
"BaseScenario"];
98 rapidjson::Value arr(rapidjson::kArrayType);
99 arr.PushBack(scenar[
"Constraint"], obj.GetAllocator());
100 res.AddMember(
"Intervals", arr, res.GetAllocator());
103 rapidjson::Value arr(rapidjson::kArrayType);
104 arr.PushBack(scenar[
"StartState"], obj.GetAllocator());
105 arr.PushBack(scenar[
"EndState"], obj.GetAllocator());
106 res.AddMember(
"States", arr, res.GetAllocator());
109 rapidjson::Value arr(rapidjson::kArrayType);
110 arr.PushBack(scenar[
"StartEvent"], obj.GetAllocator());
111 arr.PushBack(scenar[
"EndEvent"], obj.GetAllocator());
112 res.AddMember(
"Events", arr, res.GetAllocator());
115 rapidjson::Value arr(rapidjson::kArrayType);
116 arr.PushBack(scenar[
"StartTimeNode"], obj.GetAllocator());
117 arr.PushBack(scenar[
"EndTimeNode"], obj.GetAllocator());
118 res.AddMember(
"TimeNodes", arr, res.GetAllocator());
123 auto& alloc = res.GetAllocator();
124 rapidjson::Value origin(rapidjson::kArrayType);
125 auto id = [&](
const char* name,
int i) {
126 rapidjson::Value v(rapidjson::kObjectType);
127 v.AddMember(
"ObjectName", rapidjson::StringRef(name), alloc);
128 v.AddMember(
"ObjectId", i, alloc);
129 origin.PushBack(v, alloc);
131 id(
"Scenario::ScenarioDocumentModel", 1);
132 id(
"Scenario::BaseScenario", 0);
133 res.AddMember(
"Origin", origin, alloc);
138 sm, res, pres.toScenarioPoint(pos)));
146static void getAddressesRecursively(
148 std::vector<Device::FullAddressSettings>& addresses)
155 if(ossia::is_numeric(addr.value) || ossia::is_array(addr.value))
159 as.address = curAddr;
160 addresses.push_back(std::move(as));
165 for(
auto& child : node)
170 newAddr.path.append(addr.name);
171 getAddressesRecursively(child, newAddr, addresses);
175bool AutomationDropHandler::drop(
177 const QMimeData& mime)
180 if(mime.hasFormat(score::mime::nodelist()))
183 Device::FreeNodeList nl = des.deserialize();
187 std::vector<Device::FullAddressSettings> addresses;
190 getAddressesRecursively(np.second, np.first, addresses);
193 if(addresses.empty())
196 CreateCurvesFromAddresses({&cst}, addresses, ctx.commandStack);
206bool DropScoreInInterval::drop(
208 const QMimeData& mime)
212 auto path = mime.urls().first().toLocalFile();
213 if(QFile f{path}; QFileInfo{f}.suffix() ==
"score" && f.open(QIODevice::ReadOnly))
215 auto obj = readJson(f.readAll());
216 auto& docobj = obj[
"Document"];
217 auto& scenar = docobj[
"BaseScenario"];
218 auto& itv = scenar[
"Constraint"];
222 {
"Scenario::ScenarioDocumentModel", 1},
223 {
"Scenario::BaseScenario", 0},
224 {
"Scenario::IntervalModel", 0}};
227 std::vector<std::pair<int32_t, int32_t>> proc_id_map;
228 std::vector<ObjectPath> pasted;
230 rapidjson::Document copy;
232 auto& alloc = copy.GetAllocator();
233 copy.AddMember(
"Processes", rapidjson::Value(itv[
"Processes"], alloc), alloc);
236 const auto parent = readJson(r.toByteArray());
237 copy.AddMember(
"ProcessesParent", rapidjson::Value(parent, alloc), alloc);
243 auto new_path = score::IDocument::path(interval).unsafePath();
244 auto cables = Dataflow::serializedCablesFromCableJson(
245 old_path, docobj[
"Cables"].GetArray());
248 = score::IDocument::get<Scenario::ScenarioDocumentModel>(doc.document);
249 for(
auto& c : cables)
251 c.first = getStrongId(document.cables);
254 auto& vec = path.vec();
257 for(
auto& [old_id, new_id] : proc_id_map)
258 if(vec.front().id() == old_id)
264 remap(c.second.source.unsafePath());
265 remap(c.second.sink.unsafePath());
267 m.loadCables(new_path, cables);
270 m.submit(
new Command::FollowPasted{std::move(pasted)});
273 m.showRack(interval);
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
Definition JSONVisitor.hpp:52
void readFrom(const score::Entity< T > &obj)
Definition EntitySerialization.hpp:7
The ObjectIdentifier class.
Definition ObjectIdentifier.hpp:21
The ObjectPath class.
Definition ObjectPath.hpp:37
Definition CommandAPI.hpp:28
Definition ScenarioPasteElements.hpp:26
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
std::vector< ObjectPath > loadCopiedProcesses(Scenario::Command::Macro &m, const Scenario::IntervalModel &interval, const rapidjson::Value ©, std::vector< std::pair< int32_t, int32_t > > &proc_id_map, const score::DocumentContext &ctx)
Definition ScenarioEditor.cpp:66
Definition AddressSettings.hpp:24
Definition AddressSettings.hpp:49
Definition AddressSettings.hpp:62
Definition MimeVisitor.hpp:9
The Address struct.
Definition Address.hpp:81
Definition DocumentContext.hpp:18