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/Commands/Interval/AddLayerInNewSlot.hpp>
12#include <Scenario/Commands/Interval/AddProcessToInterval.hpp>
13#include <Scenario/Commands/Interval/ResizeInterval.hpp>
14#include <Scenario/Commands/Metadata/ChangeElementName.hpp>
15#include <Scenario/Commands/Scenario/ScenarioPasteElements.hpp>
16#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
17#include <Scenario/Process/ScenarioModel.hpp>
18#include <Scenario/Process/ScenarioPresenter.hpp>
20#include <Dataflow/Commands/CableHelpers.hpp>
22#include <score/document/DocumentContext.hpp>
24#include <ossia/detail/thread.hpp>
25#include <ossia/network/value/value_traits.hpp>
32DropScenario::DropScenario()
35 m_acceptableSuffixes.push_back(
"scenario");
38bool DropScenario::drop(
39 const ScenarioPresenter& pres, QPointF pos,
const QMimeData& mime)
43 const auto& doc = pres.context().context;
44 auto& sm = pres.model();
45 auto path = mime.urls().first().toLocalFile();
46 if(QFile f{path}; QFileInfo{f}.suffix() ==
"scenario" && f.open(QIODevice::ReadOnly))
50 sm, readJson(f.readAll()), pres.toScenarioPoint(pos)));
58DropScoreInScenario::DropScoreInScenario()
60 m_acceptableSuffixes.push_back(
"score");
61 m_acceptableSuffixes.push_back(
"scorebin");
64bool DropScoreInScenario::drop(
65 const ScenarioPresenter& pres, QPointF pos,
const QMimeData& mime)
69 const auto& doc = pres.context().context;
70 auto& sm = pres.model();
71 auto path = mime.urls().first().toLocalFile();
72 if(QFile f{path}; QFileInfo{f}.suffix() ==
"score" && f.open(QIODevice::ReadOnly))
74 rapidjson::Document res;
77 auto obj = readJson(f.readAll());
78 auto& docobj = obj[
"Document"];
82 res.AddMember(
"Cables", docobj[
"Cables"], res.GetAllocator());
83 for(
auto& c : res[
"Cables"].GetArray())
85 auto source = c[
"Source"].GetArray();
86 source.Erase(source.Begin());
87 source.Erase(source.Begin());
88 auto sink = c[
"Sink"].GetArray();
89 sink.Erase(sink.Begin());
90 sink.Erase(sink.Begin());
93 auto& scenar = docobj[
"BaseScenario"];
96 rapidjson::Value arr(rapidjson::kArrayType);
97 arr.PushBack(scenar[
"Constraint"], obj.GetAllocator());
98 res.AddMember(
"Intervals", arr, res.GetAllocator());
101 rapidjson::Value arr(rapidjson::kArrayType);
102 arr.PushBack(scenar[
"StartState"], obj.GetAllocator());
103 arr.PushBack(scenar[
"EndState"], obj.GetAllocator());
104 res.AddMember(
"States", arr, res.GetAllocator());
107 rapidjson::Value arr(rapidjson::kArrayType);
108 arr.PushBack(scenar[
"StartEvent"], obj.GetAllocator());
109 arr.PushBack(scenar[
"EndEvent"], obj.GetAllocator());
110 res.AddMember(
"Events", arr, res.GetAllocator());
113 rapidjson::Value arr(rapidjson::kArrayType);
114 arr.PushBack(scenar[
"StartTimeNode"], obj.GetAllocator());
115 arr.PushBack(scenar[
"EndTimeNode"], obj.GetAllocator());
116 res.AddMember(
"TimeNodes", arr, res.GetAllocator());
121 sm, res, pres.toScenarioPoint(pos)));
129static void getAddressesRecursively(
131 std::vector<Device::FullAddressSettings>& addresses)
138 if(ossia::is_numeric(addr.value) || ossia::is_array(addr.value))
142 as.address = curAddr;
143 addresses.push_back(std::move(as));
148 for(
auto& child : node)
153 newAddr.path.append(addr.name);
154 getAddressesRecursively(child, newAddr, addresses);
158bool AutomationDropHandler::drop(
160 const QMimeData& mime)
163 if(mime.formats().contains(score::mime::nodelist()))
166 Device::FreeNodeList nl = des.deserialize();
170 std::vector<Device::FullAddressSettings> addresses;
173 getAddressesRecursively(np.second, np.first, addresses);
176 if(addresses.empty())
179 CreateCurvesFromAddresses({&cst}, addresses, ctx.commandStack);
189bool DropScoreInInterval::drop(
191 const QMimeData& mime)
195 auto path = mime.urls().first().toLocalFile();
196 if(QFile f{path}; QFileInfo{f}.suffix() ==
"score" && f.open(QIODevice::ReadOnly))
198 auto obj = readJson(f.readAll());
199 auto& docobj = obj[
"Document"];
200 auto& scenar = docobj[
"BaseScenario"];
201 auto& itv = scenar[
"Constraint"];
204 for(
auto& json : itv[
"Processes"].GetArray())
206 m.loadProcessInSlot(interval, json);
212 {
"Scenario::ScenarioDocumentModel", 1},
213 {
"Scenario::BaseScenario", 0},
214 {
"Scenario::IntervalModel", 0}};
215 auto new_path = score::IDocument::path(interval).unsafePath();
216 auto cables = Dataflow::serializedCablesFromCableJson(
217 old_path, docobj[
"Cables"].GetArray());
220 = score::IDocument::get<Scenario::ScenarioDocumentModel>(doc.document);
221 for(
auto& c : cables)
223 c.first = getStrongId(document.cables);
225 m.loadCables(new_path, cables);
229 m.showRack(interval);
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
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
Definition AddressSettings.hpp:24
Definition AddressSettings.hpp:49
Definition AddressSettings.hpp:62
Definition MimeVisitor.hpp:9
The Address struct.
Definition Address.hpp:58
Definition DocumentContext.hpp:18