void undo() const override { auto& scenar = m_scenarioPath.find(); auto& globalEvent = scenar.event(m_destinationEventId); Deserializer<DataStream> s{m_serializedEvent}; auto recreatedEvent = new EventModel{s, &scenar}; auto states_in_event = recreatedEvent->states(); // we remove and re-add states in recreated event // to ensure correct parentship between elements. for(auto stateId : states_in_event) { recreatedEvent->removeState(stateId); globalEvent.removeState(stateId); } for(auto stateId : states_in_event) { recreatedEvent->addState(stateId); scenar.states.at(stateId).setEventId(m_movingEventId); } scenar.events.add(recreatedEvent); if(recreatedEvent->timeNode() != globalEvent.timeNode()) { auto& tn = scenar.timeNode(globalEvent.timeNode()); tn.addEvent(m_movingEventId); m_mergeTimeNodesCommand->undo(); } updateEventExtent(m_destinationEventId, scenar); }
void MergeEvents::redo(const score::DocumentContext& ctx) const { auto& scenar = m_scenarioPath.find(ctx); // ScenarioValidityChecker::checkValidity(scenar); auto& movingEvent = scenar.event(m_movingEventId); auto& destinationEvent = scenar.event(m_destinationEventId); auto movingStates = movingEvent.states(); if (movingEvent.timeSync() != destinationEvent.timeSync()) m_mergeTimeSyncsCommand->redo(ctx); for (auto& stateId : movingStates) { movingEvent.removeState(stateId); destinationEvent.addState(stateId); scenar.states.at(stateId).setEventId(m_destinationEventId); } auto& ts = scenar.timeSync(destinationEvent.timeSync()); ts.removeEvent(m_movingEventId); scenar.events.remove(m_movingEventId); updateEventExtent(m_destinationEventId, scenar); // ScenarioValidityChecker::checkValidity(scenar); }
void ScenarioPasteElements::redo(const score::DocumentContext& ctx) const { Scenario::ProcessModel& scenario = m_ts.find(ctx); std::vector<TimeSyncModel*> addedTimeSyncs; addedTimeSyncs.reserve(m_json_timesyncs.size()); std::vector<EventModel*> addedEvents; addedEvents.reserve(m_json_events.size()); for (const auto& timesync : m_json_timesyncs) { auto tn = new TimeSyncModel(JSONObject::Deserializer{timesync}, &scenario); scenario.timeSyncs.add(tn); addedTimeSyncs.push_back(tn); } for (const auto& event : m_json_events) { auto ev = new EventModel(JSONObject::Deserializer{event}, &scenario); scenario.events.add(ev); addedEvents.push_back(ev); } for (const auto& state : m_json_states) { scenario.states.add( new StateModel(JSONObject::Deserializer{state}, &scenario)); } for (const auto& interval : m_json_intervals) { auto cst = new IntervalModel(JSONObject::Deserializer{interval}, &scenario); scenario.intervals.add(cst); } for (const auto& event : addedEvents) { updateEventExtent(event->id(), scenario); } for (const auto& timesync : addedTimeSyncs) { updateTimeSyncExtent(timesync->id(), scenario); } ScenarioDocumentModel& model = score::IDocument::modelDelegate<ScenarioDocumentModel>(ctx.document); for (const auto& cable_id : m_cables.keys()) { const auto& dat = m_cables[cable_id]; auto c = new Process::Cable{cable_id, dat, &model}; Path<Scenario::ScenarioDocumentModel> model_path{model}; model.cables.add(c); auto ext = model_path.extend(cable_id); dat.source.find(ctx).addCable(ext); dat.sink.find(ctx).addCable(ext); } }
void Scenario::Command::MoveNewState::redo() { auto& scenar = m_path.find<ScenarioModel>(); auto& state = scenar.state(m_stateId); state.setHeightPercentage(m_y); updateEventExtent(state.eventId(), scenar); }
void updateConstraintVerticalPos(double y, const Id<ConstraintModel> &id, Scenario::ScenarioModel& s) { auto& cst = s.constraints.at(id); // First make the list of all the constraints to update QSet<ConstraintModel*> constraintsToUpdate; constraintsToUpdate.insert(&cst); QSet<StateModel*> statesToUpdate; StateModel* rec_state = &s.state(cst.startState()); while(rec_state->previousConstraint()) { ConstraintModel* rec_cst = &s.constraints.at(rec_state->previousConstraint()); constraintsToUpdate.insert(rec_cst); statesToUpdate.insert(rec_state); rec_state = &s.states.at(rec_cst->startState()); } statesToUpdate.insert(rec_state); // Add the first state rec_state = &s.state(cst.endState()); while(rec_state->nextConstraint()) { ConstraintModel* rec_cst = &s.constraints.at(rec_state->nextConstraint()); constraintsToUpdate.insert(rec_cst); statesToUpdate.insert(rec_state); rec_state = &s.states.at(rec_cst->endState()); } statesToUpdate.insert(rec_state); // Add the last state // Set the correct height for(auto& constraint : constraintsToUpdate) { constraint->setHeightPercentage(y); } for(auto& state : statesToUpdate) { state->setHeightPercentage(y); updateEventExtent(state->eventId(), s); } }
void redo() const override { auto& scenar = m_scenarioPath.find(); auto& movingEvent = scenar.event(m_movingEventId); auto& destinationEvent = scenar.event(m_destinationEventId); auto movingStates = movingEvent.states(); if(movingEvent.timeNode() != destinationEvent.timeNode()) m_mergeTimeNodesCommand->redo(); for(auto& stateId : movingStates) { movingEvent.removeState(stateId); destinationEvent.addState(stateId); scenar.states.at(stateId).setEventId(m_destinationEventId); } auto& tn = scenar.timeNode(destinationEvent.timeNode()); tn.removeEvent(m_movingEventId); scenar.events.remove(m_movingEventId); updateEventExtent(m_destinationEventId, scenar); }