Debian Codegraph @

include/imap.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "inode.h"
5 #include "imapexporter.h"
6 #include "imapformat.h"
7 #include "imapmerge.h"
8 #include "ikeyvaluestore.h"
9 #include <sigc++/signal.h>
10
11 #include <os/fs.h>
12
13 // Registry setting for suppressing the map load progress dialog
14 const char* const RKEY_MAP_SUPPRESS_LOAD_STATUS_DIALOG = "user/ui/map/suppressMapLoadDialog";
15
16 // Whether to load the most recently used map on app startup
17 const char* const RKEY_LOAD_LAST_MAP = "user/ui/map/loadLastMap";
18
19 const char* const LOAD_PREFAB_AT_CMD = "LoadPrefabAt";
20
21 // Namespace forward declaration
22 class INamespace;
23 typedef std::shared_ptr<INamespace> INamespacePtr;
24
25 // see imapfilechangetracker.h
26 class IMapFileChangeTracker;
27
28 // see ientity.h
29 class ITargetManager;
30
31 // see ilayer.h
32 class ILayerManager;
33
34 // see iundo.h
35 class IUndoSystem;
36
37 namespace selection
38 {
39 class ISelectionSetManager;
40 class ISelectionGroupManager;
41 }
42
43 namespace scene
44 {
45
46 /**
47 * greebo: A root node is the top level element of a map.
48 * It also owns the namespace of the corresponding map.
49 */
50 class IMapRootNode :
51 public virtual INode,
52 public virtual IKeyValueStore
53 {
54 public:
55 virtual ~IMapRootNode() {}
56
57 virtual void setName(const std::string& name) = 0;
58
59 /**
60 * greebo: Returns the namespace of this root.
61 */
62 virtual const INamespacePtr& getNamespace() = 0;
63
64 /**
65 * Access the selection group manager of this hierarchy.
66 */
67 virtual selection::ISelectionGroupManager& getSelectionGroupManager() = 0;
68
69 /**
70 * Gives access to the selectionset manager in this scene.
71 */
72 virtual selection::ISelectionSetManager& getSelectionSetManager() = 0;
73
74 /**
75 * Returns the target manager keeping track of all
76 * the named targets in the map.
77 */
78 virtual ITargetManager& getTargetManager() = 0;
79
80 /**
81 * The map root node is holding an implementation of the change tracker
82 * interface, to keep track of whether the map resource on disk is
83 * up to date or not.
84 */
85 virtual IMapFileChangeTracker& getUndoChangeTracker() = 0;
86
87 /**
88 * Provides methods to create and assign layers in this map.
89 */
90 virtual ILayerManager& getLayerManager() = 0;
91
92 // The UndoSystem of this map
93 virtual IUndoSystem& getUndoSystem() = 0;
94
95 // Returns the render system of this map root (may be empty)
96 virtual RenderSystemPtr getRenderSystem() const = 0;
97 };
98 typedef std::shared_ptr<IMapRootNode> IMapRootNodePtr;
99
100 } // namespace scene
101
102 /**
103 * greebo: This is the global interface to the currently
104 * active map file.
105 */
106 class IMap :
107 public RegisterableModule
108 {
109 public:
110 enum MapEvent
111 {
112 MapLoading, // emitted just before a map is starting to be loaded
113 MapLoaded, // emitted when the current map is done loading
114 MapUnloading, // emitted just before a map is unloaded from memory
115 MapUnloaded, // emitted after a map has been unloaded
116 MapSaving, // emitted before a map is about to be saved (changes are possible)
117 MapSaved, // emitted right after a map has been saved
118 MapMergeOperationStarted, // emitted after a merge operation has been started
119 MapMergeOperationAborted, // emitted after a merge operation has been aborted
120 MapMergeOperationFinished, // emitted after a merge operation has been finished
121 };
122
123 typedef sigc::signal<void, MapEvent> MapEventSignal;
124
125 /// Returns the signal that is emitted on various events
126 virtual MapEventSignal signal_mapEvent() const = 0;
127
128 enum class EditMode
129 {
130 Normal,
131 Merge,
132 };
133
134 // The currently active edit mode
135 virtual EditMode getEditMode() = 0;
136
137 // Change the edit mode to the specified value
138 virtual void setEditMode(EditMode mode) = 0;
139
140 // Signal fired when the map edit mode has been changed
141 virtual sigc::signal<void, EditMode>& signal_editModeChanged() = 0;
142
143 /**
144 * Returns the worldspawn node of this map. The worldspawn
145 * node is NOT created if it doesn't exist yet, so this
146 * might return an empty pointer.
147 */
148 virtual const scene::INodePtr& getWorldspawn() = 0;
149
150 /**
151 * This retrieves the worldspawn node of this map.
152 * If no worldspawn can be found, this creates one.
153 * Use this instead of getWorldSpawn() if your code needs
154 * a worldspawn to work with.
155 */
156 virtual const scene::INodePtr& findOrInsertWorldspawn() = 0;
157
158 /**
159 * Returns the root node of this map or NULL if this is an empty map.
160 */
161 virtual scene::IMapRootNodePtr getRoot() = 0;
162
163 /**
164 * Returns the name of the map.
165 */
166 virtual std::string getMapName() const = 0;
167
168 // Returns true if this map is still unnamed (never saved yet)
169 virtual bool isUnnamed() const = 0;
170
171 /**
172 * Signal fired when the name of this map is changing.
173 */
174 virtual sigc::signal<void>& signal_mapNameChanged() = 0;
175
176 // Returns true if the map has unsaved changes.
177 virtual bool isModified() const = 0;
178
179 // Sets the modified status of this map
180 virtual void setModified(bool modifiedFlag) = 0;
181
182 /**
183 * Signal fired when the modified status of this map has changed.
184 */
185 virtual sigc::signal<void>& signal_modifiedChanged() = 0;
186
187 // Signal emitted when an operation affecting the map has been undone
188 virtual sigc::signal<void>& signal_postUndo() = 0;
189
190 // Signal emitted when an operation affecting the map has been redone
191 virtual sigc::signal<void>& signal_postRedo() = 0;
192
193 // Accessor to the undo system of the main scene.
194 // Throws std::runtime_error if no map resource has been loaded.
195 virtual IUndoSystem& getUndoSystem() = 0;
196
197 // Caution: this is upposed to be called on startup, since it doesn't ask the user
198 // whether to save the current map. Use the "NewMap" command for regular purposes.
199 virtual void createNewMap() = 0;
200
201 // Create a MapExporter instance which can be used to export a scene,
202 // including the necessary preparation, info-file handling, etc.
203 // This is mainly a service method for external code, like the gameconnection.
204 virtual map::IMapExporter::Ptr createMapExporter(map::IMapWriter& writer,
205 const scene::IMapRootNodePtr& root, std::ostream& mapStream) = 0;
206
207 // Exports the current selection to the given output stream, using the map's format
208 virtual void exportSelected(std::ostream& out) = 0;
209
210 // Exports the current selection to the given output stream, using the given map format
211 virtual void exportSelected(std::ostream& out, const map::MapFormatPtr& format) = 0;
212
213 // Starts a merge operation which imports differences from the given sourceMap into this one
214 // Will throw exceptions when the given map cannot be found, or this map doesn't have a root
215 virtual void startMergeOperation(const std::string& sourceMap) = 0;
216
217 // Starts a merge operation which imports the changes made to the source map into this one
218 // baseMap defines the path to a map that both the source map and this map started from,
219 // which makes the merge process more precise and enables conflict detection.
220 // Will throw exceptions when the given map cannot be found, or this map doesn't have a root
221 virtual void startMergeOperation(const std::string& sourceMap, const std::string& baseMap) = 0;
222
223 // When called in EditMode::Merge, this will apply the currently active set of actions
224 virtual void finishMergeOperation() = 0;
225
226 // Can be called when in EditMode::Merge, will abort the current merge process
227 virtual void abortMergeOperation() = 0;
228
229 // Returns the currently active merge operation (or an empty reference if no merge is ongoing)
230 virtual scene::merge::IMergeOperation::Ptr getActiveMergeOperation() = 0;
231
232 /* POINTFILE MANAGEMENT */
233
234 /// Functor to receive pointfile paths
235 using PointfileFunctor = std::function<void(const fs::path&)>;
236
237 /// Enumerate pointfiles associated with the current map
238 virtual void forEachPointfile(PointfileFunctor func) const = 0;
239
240 /**
241 * \brief Show the point trace contained in the specified file.
242 *
243 * \param filePath
244 * Filesystem path of the file to parse for point coordinates, or an empty
245 * path to hide any current point trace.
246 *
247 * \exception std::runtime_error
248 * Thrown if filePath is not empty but the file is inaccessible.
249 */
250 virtual void showPointFile(const fs::path& filePath) = 0;
251
252 /// Return true if a point trace is currently visible
253 virtual bool isPointTraceVisible() const = 0;
254 };
255 typedef std::shared_ptr<IMap> IMapPtr;
256
257 const char* const MODULE_MAP("Map");
258
259 // Application-wide Accessor to the currently active map
260 inline IMap& GlobalMapModule()
261 {
262 static module::InstanceReference<IMap> _reference(MODULE_MAP);
263 return _reference;
264 }
265