2#include <Process/ProcessList.hpp>
4#include <Scenario/Commands/Scenario/PasteAnchors.hpp>
5#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
6#include <Scenario/Process/ScenarioModel.hpp>
8#include <score/application/GUIApplicationContext.hpp>
9#include <score/document/DocumentContext.hpp>
10#include <score/document/DocumentInterface.hpp>
11#include <score/model/EntitySerialization.hpp>
12#include <score/model/path/PathSerialization.hpp>
13#include <score/plugins/SerializableHelpers.hpp>
14#include <score/tools/IdentifierGeneration.hpp>
16#include <ossia/detail/flat_map.hpp>
17#include <ossia/detail/hash_map.hpp>
22std::vector<Process::CableData>
23cableDataFromCablesJson(
const rapidjson::Document::ConstArray& arr);
24std::vector<Process::CableData>
25cableDataFromCablesJson(
const rapidjson::Document::Array& arr);
28template <
typename CopiedObjects,
typename ParentObject>
31 std::vector<CopiedObjects*>& intervals,
40 for(CopiedObjects* interval : intervals)
42 id_map[interval->id()] = interval_ids[i];
47 auto& doc = score::IDocument::modelDelegate<ScenarioDocumentModel>(ctx.document);
48 auto cable_ids = getStrongIdRange<Process::Cable>(cables.size(), doc.cables);
54 auto& source_vec = cd.source.unsafePath().vec();
55 auto& sink_vec = cd.sink.unsafePath().vec();
56 SCORE_ASSERT(!source_vec.empty());
57 SCORE_ASSERT(!sink_vec.empty());
58 int32_t source_itv_id = source_vec.front().id();
59 int32_t sink_itv_id = sink_vec.front().id();
61 for(CopiedObjects* interval : intervals)
63 auto id = interval->id().val();
64 if(
id == source_itv_id)
65 source_itv_id = id_map.at(interval->id()).val();
67 sink_itv_id = id_map.at(interval->id()).val();
71 sink_vec.front() =
ObjectIdentifier{sink_vec.front().objectName(), sink_itv_id};
74 source_vec.begin(), p.unsafePath().vec().begin(), p.unsafePath().vec().end());
76 sink_vec.begin(), p.unsafePath().vec().begin(), p.unsafePath().vec().end());
78 cable_map.insert({cable_ids[i], std::move(cd)});
82 for(CopiedObjects* interval : intervals)
84 const auto ports = interval->template findChildren<Process::Port*>();
87 while(!port->cables().empty())
89 port->removeCable(port->cables().back());
110 const auto& json_arr = obj[
"Intervals"].GetArray();
111 intervals.reserve(json_arr.Size());
112 for(
const auto& element : json_arr)
119 const auto& json_arr = obj[
"TimeNodes"].GetArray();
120 timesyncs.reserve(json_arr.Size());
121 for(
const auto& element : json_arr)
123 timesyncs.emplace_back(
128 const auto& json_arr = obj[
"Events"].GetArray();
129 events.reserve(json_arr.Size());
130 for(
const auto& element : json_arr)
136 const auto& json_arr = obj[
"States"].GetArray();
137 states.reserve(json_arr.Size());
138 for(
const auto& element : json_arr)
145 const auto& json_arr = obj[
"Cables"].GetArray();
146 cables = cableDataFromCablesJson(json_arr);
150 interval_ids = getStrongIdRange2<IntervalModel>(
151 intervals.size(), scenario.intervals, intervals);
152 timesync_ids = getStrongIdRange2<TimeSyncModel>(
153 timesyncs.size(), scenario.timeSyncs, timesyncs);
154 event_ids = getStrongIdRange2<EventModel>(events.size(), scenario.events, events);
155 state_ids = getStrongIdRange2<StateModel>(states.size(), scenario.states, states);
157 remapAnchors(obj, scenario, ctx);
167 if(
auto it = obj.FindMember(
"Origin"); it != obj.MemberEnd())
171 const auto here = score::IDocument::unsafe_path(scenario);
172 auto pair = [&](
auto& models,
auto& ids) {
173 for(std::size_t i = 0; i < models.size(); i++)
175 auto from = origin.vec();
176 from.emplace_back(models[i]->objectName(), models[i]->id());
177 auto to = here.vec();
178 to.emplace_back(models[i]->objectName(), ids[i]);
182 pair(intervals, interval_ids);
183 pair(timesyncs, timesync_ids);
184 pair(events, event_ids);
185 pair(states, state_ids);
188 for(
auto o : intervals)
190 for(
auto o : timesyncs)
198 std::vector<TimeSyncModel*> timesyncs;
199 std::vector<IntervalModel*> intervals;
200 std::vector<EventModel*> events;
201 std::vector<StateModel*> states;
202 std::vector<Process::CableData> cables;
204 std::vector<Id<IntervalModel>> interval_ids;
205 std::vector<Id<TimeSyncModel>> timesync_ids;
206 std::vector<Id<EventModel>> event_ids;
207 std::vector<Id<StateModel>> state_ids;
213 const rapidjson::Value::ConstArray& sourceProcesses,
223 const auto& json_arr = sourceProcesses;
224 processes.reserve(json_arr.Size());
226 for(
const auto& element : json_arr)
229 auto proc = deserialize_interface(
233 processes.emplace_back(proc);
241 processes_ids = getStrongIdRange2<Process::ProcessModel>(
242 processes.size(), parent.
processes, processes);
253 if(
auto it = copy.FindMember(
"ProcessPaths");
254 it != copy.MemberEnd() && it->value.IsArray())
256 const auto& arr = it->value.GetArray();
257 const auto here = score::IDocument::unsafe_path(parent);
258 for(std::size_t i = 0; i < processes.size(); i++)
260 if(
sources[i] >= (
int)arr.Size())
264 auto to = here.vec();
265 to.emplace_back(processes[i]->objectName(), processes_ids[i]);
266 paths.moved.emplace_back(std::move(from),
ObjectPath{std::move(to)});
269 else if(
auto it = copy.FindMember(
"ProcessesParent"); it != copy.MemberEnd())
273 const auto here = score::IDocument::unsafe_path(parent);
274 for(std::size_t i = 0; i < processes.size(); i++)
276 auto from = parentPath.vec();
277 from.emplace_back(processes[i]->objectName(), processes[i]->
id());
278 auto to = here.vec();
279 to.emplace_back(processes[i]->objectName(), processes_ids[i]);
284 for(
auto proc : processes)
288 std::vector<Process::ProcessModel*> processes;
289 std::vector<Id<Process::ProcessModel>> processes_ids;
Definition JSONVisitor.hpp:423
The ObjectIdentifier class.
Definition ObjectIdentifier.hpp:21
The ObjectPath class.
Definition ObjectPath.hpp:37
The Path class is a typesafe wrapper around ObjectPath.
Definition Path.hpp:52
Definition ProcessList.hpp:10
Definition EventModel.hpp:36
Definition IntervalModel.hpp:50
score::EntityMap< Process::ProcessModel, true > processes
Definition IntervalModel.hpp:62
The core hierarchical and temporal process of score.
Definition ScenarioModel.hpp:37
Definition StateModel.hpp:62
Definition TimeSyncModel.hpp:34
The id_base_t class.
Definition Identifier.hpp:59
Main plug-in of score.
Definition ConnectionsList.hpp:22
bool copiedFromHere(const rapidjson::Value ©, const score::DocumentContext &ctx)
Compares the copy's "OriginDocument" key with score::IDocument::copyOrigin()
Definition PasteAnchors.cpp:26
void remapCopiedAnchors(QObject &root, const CopiedPaths &paths)
Definition PasteAnchors.cpp:84
Definition JSONVisitor.hpp:372
Definition CableData.hpp:18
Paths of the copied objects and of their copies.
Definition PasteAnchors.hpp:24
Definition ScenarioPaste.hpp:211
std::vector< int > sources
Index of each process in the copied array.
Definition ScenarioPaste.hpp:291
Definition ScenarioPaste.hpp:99
Definition DocumentContext.hpp:18