2020-03-03 21:34:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Note: this header file is used by the undo-machinery and should not be included elsewhere.
|
|
|
|
|
|
|
|
#ifndef COMMAND_EVENT_H
|
|
|
|
#define COMMAND_EVENT_H
|
|
|
|
|
|
|
|
#include "command_base.h"
|
2021-01-11 15:52:02 +00:00
|
|
|
#include "core/divemode.h"
|
2024-05-25 06:16:57 +00:00
|
|
|
#include "core/event.h"
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
|
|
|
|
namespace Command {
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
// Pointers to events are not stable, so we always store indexes.
|
2020-03-03 21:34:50 +00:00
|
|
|
|
2020-03-04 16:35:02 +00:00
|
|
|
class EventBase : public Base {
|
|
|
|
protected:
|
|
|
|
EventBase(struct dive *d, int dcNr);
|
2020-03-03 21:34:50 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2020-03-04 16:35:02 +00:00
|
|
|
virtual void redoit() = 0;
|
|
|
|
virtual void undoit() = 0;
|
2020-03-03 21:34:50 +00:00
|
|
|
|
|
|
|
// Note: we store dive and the divecomputer-number instead of a pointer to the divecomputer.
|
2024-05-25 06:16:57 +00:00
|
|
|
// Pointers to divecomputers are not stable.
|
2020-03-03 21:34:50 +00:00
|
|
|
struct dive *d;
|
|
|
|
int dcNr;
|
2020-03-05 22:10:44 +00:00
|
|
|
private:
|
|
|
|
void updateDive();
|
2020-03-04 16:35:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AddEventBase : public EventBase {
|
|
|
|
public:
|
2024-05-25 06:16:57 +00:00
|
|
|
AddEventBase(struct dive *d, int dcNr, struct event ev); // Takes ownership of event!
|
2021-01-11 15:52:02 +00:00
|
|
|
protected:
|
2020-03-04 16:35:02 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2021-01-11 15:52:02 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
2020-03-03 21:34:50 +00:00
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
struct event ev; // for redo
|
|
|
|
int idx; // for undo
|
2020-03-03 21:34:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AddEventBookmark : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventBookmark(struct dive *d, int dcNr, int seconds);
|
|
|
|
};
|
|
|
|
|
2020-03-03 21:54:54 +00:00
|
|
|
class AddEventDivemodeSwitch : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
|
|
|
|
};
|
|
|
|
|
2020-03-03 22:31:46 +00:00
|
|
|
class AddEventSetpointChange : public AddEventBase {
|
|
|
|
public:
|
|
|
|
AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
|
2021-01-11 15:52:02 +00:00
|
|
|
private:
|
|
|
|
divemode_t divemode; // Wonderful: this may change the divemode of the dive to CCR
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2020-03-03 22:31:46 +00:00
|
|
|
};
|
|
|
|
|
2020-03-04 17:13:02 +00:00
|
|
|
class RenameEvent : public EventBase {
|
|
|
|
public:
|
2024-05-25 06:16:57 +00:00
|
|
|
RenameEvent(struct dive *d, int dcNr, int idx, const std::string name);
|
2020-03-04 17:13:02 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
int idx; // for undo and redo
|
|
|
|
std::string name; // for undo and redo
|
2020-03-04 17:13:02 +00:00
|
|
|
};
|
|
|
|
|
2020-03-04 17:25:47 +00:00
|
|
|
class RemoveEvent : public EventBase {
|
|
|
|
public:
|
2024-05-25 06:16:57 +00:00
|
|
|
RemoveEvent(struct dive *d, int dcNr, int idx);
|
2020-03-04 17:25:47 +00:00
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2020-03-06 22:20:58 +00:00
|
|
|
void post() const; // Called to fix up dives should a gas-change have happened.
|
2020-03-04 17:25:47 +00:00
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
event ev; // for undo
|
|
|
|
int idx; // for redo
|
|
|
|
int cylinder; // affected cylinder (if removing gas switch). <0: not a gas switch.
|
2020-03-04 17:25:47 +00:00
|
|
|
};
|
|
|
|
|
2020-03-04 20:10:05 +00:00
|
|
|
class AddGasSwitch : public EventBase {
|
|
|
|
public:
|
|
|
|
AddGasSwitch(struct dive *d, int dcNr, int seconds, int tank);
|
|
|
|
private:
|
|
|
|
bool workToBeDone() override;
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
|
|
|
|
|
|
|
std::vector<int> cylinders; // cylinders that are modified
|
2024-05-25 06:16:57 +00:00
|
|
|
std::vector<event> eventsToAdd;
|
|
|
|
std::vector<int> eventsToRemove;
|
2020-03-04 20:10:05 +00:00
|
|
|
};
|
|
|
|
|
2020-03-03 21:34:50 +00:00
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
#endif // COMMAND_EVENT_H
|