NDEVR
API Documentation
TransitIncidentManager.h
1#pragma once
2#include "NDEVR/Headers/QTModelManager.h"
3#include "IOFactory/Headers/NDVFactory.h"
4#include "Design/Headers/ContactInfo.h"
5#include "Base/Headers/FileResource.h"
6namespace NDEVR
7{
8
11 {
12 public:
16 : m_bus_cache_location(FileResource::PathToProgramDynamicResources().appendPath("Bus_Cache.ndv"))
17 , m_driver_cache_location(FileResource::PathToProgramDynamicResources().appendPath("Driver_Cache.ndv"))
19 {}
20
23 {
24 return m_manager;
25 }
26
37
40 {
41 return m_manager->getQTObject(officerRootID());
42 }
43
46 {
47 return m_manager->getQTObject(witnessRootID());
48 }
49
55
58 {
59 return m_manager->getQTObject(vehicleRootID());
60 }
61
67
73
79
81 void setActiveBus(const UUID& id)
82 {
83 WLock lock(m_manager->writeLock());
84 Model model = m_manager->model(id);
85 Model active_bus = m_manager->model(activeBusID());
86 if (!active_bus.isValid())
87 {
88 Scene scene(_t("Active Bus"));
89 scene.set<NDPC::e_translatable_name>(_t("Active Bus"));
90 Model active_bus = scene.createChild();
91 active_bus.set<NDPO::guid>(activeBusID());
92 WLock lock = m_manager->writeLock();
93 m_manager->addScene(scene);
94 active_bus = scene;
95 }
96 active_bus.copyFrom(model, true);
97 active_bus.set<NDPO::uncompressed_data>(String(id));
98 }
99
101 void setActiveDriver(const UUID& id)
102 {
103 WLock lock(m_manager->writeLock());
104 Model model = m_manager->model(id);
105 if (!m_manager->model(activeDriverID()))
106 {
107 Scene scene(_t("Active Driver"));
108 scene.set<NDPC::e_translatable_name>(_t("Active Driver"));
109 Model active_driver = scene.createChild();
110 active_driver.set<NDPO::guid>(activeDriverID());
111 WLock lock = m_manager->writeLock();
112 m_manager->addScene(scene);
113 }
114 auto active_driver = m_manager->model(activeDriverID());
115 active_driver.copyFrom(model, true);
116 active_driver.set<NDPO::uncompressed_data>(String(id));
117 }
118
123
128
131 {
132 return m_manager->activeProject().appendUUID("active_driver");
133 }
134
137 {
138 return m_manager->activeProject().appendUUID("active_bus");
139 }
140
143 {
144 return m_manager->activeProject().appendUUID("active_address");
145 }
146
149 {
150 return m_manager->activeProject().appendUUID("witness_root");
151 }
152
155 {
156 return m_manager->activeProject().appendUUID("officer_root");
157 }
158
161 {
162 return m_manager->activeProject().appendUUID("pedestrain_root");
163 }
164
167 {
168 return m_manager->activeProject().appendUUID("involved_vehicles_root");
169 }
170 protected:
176
181
185 UUID readCache(const File& file, const StringView& root_name)
186 {
187 if (file.exists())
188 {
190 FactoryParameters params(request);
191 params.options.center_model = false;
192 params.options.tree_is_visible = false;
193 params.options.application_locked = true;
194 params.options.generate_trees = false;
195 params.lookup = m_manager;
197 lib_assert(params.models.size() == 1, "Unexpected bus cache size");
198 if(params.models.size() >= 1)
199 return params.models[0];
200 }
201 Scene root = Scene(TranslatedString(root_name));
202 root.set<NDPO::tree_visible>(false);
203 WLock lock = m_manager->writeLock();
204 m_manager->addScene(root);
205 return root.get<NDPO::guid>();
206 }
207
210 void saveCache(const File& file, const UUID& root)
211 {
213 FactoryParameters params(request);
214 params.lookup = m_manager;
215 params.models = { root };
217 }
218
220 {
221 if (!m_manager->scene(officerRootID()))
222 {
223 Scene third_parties(_t("Officers"));
224 third_parties.set<NDPO::icon>("user+shadow+s:0.5+ox:0.5+oy:0.5+visible");
225 third_parties.set<NDPO::guid>(officerRootID());
226 WLock lock = m_manager->writeLock();
227 m_manager->addScene(third_parties);
228 }
229 }
230
232 {
233 if (!m_manager->scene(witnessRootID()))
234 {
235 Scene third_parties(_t("Witnesses"));
236 third_parties.set<NDPO::icon>("user+shadow+s:0.5+ox:0.5+oy:0.5+visible");
237 third_parties.set<NDPO::guid>(witnessRootID());
238 WLock lock = m_manager->writeLock();
239 m_manager->addScene(third_parties);
240 }
241 }
242
244 {
245 if (!m_manager->scene(pedestrianRootID()))
246 {
247 Scene third_parties(_t("Pedestrians"));
248 third_parties.set<NDPO::icon>("user+shadow+s:0.5+ox:0.5+oy:0.5+visible");
249 third_parties.set<NDPO::guid>(pedestrianRootID());
250 WLock lock = m_manager->writeLock();
251 m_manager->addScene(third_parties);
252 }
253 }
254
256 {
257 if (!m_manager->scene(vehicleRootID()))
258 {
259 Scene third_parties(_t("Vehicles"));
260 third_parties.set<NDPO::icon>("steering_wheel+shadow+s:0.5+ox:0.5+oy:0.5+visible");
261 third_parties.set<NDPO::guid>(vehicleRootID());
262 WLock lock = m_manager->writeLock();
263 m_manager->addScene(third_parties);
264 }
265 }
266
268 {
269 if (!m_manager->scene(activeAddressID()))
270 {
271 Scene third_parties(_t("Address"));
272 third_parties.set<NDPO::guid>(activeAddressID());
273 PhysicalAddressModel accident_address(third_parties);
274 m_manager->addModel(accident_address);
275 }
276 }
277 protected:
278 UUID m_bus_cache_root = Constant<UUID>::Invalid;
279 UUID m_driver_cache_root = Constant<UUID>::Invalid;
285 };
286}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
void set(t_property_type property, const t_type &value)
Sets a property value in the database.
bool isValid() const
Checks whether this design object has a valid index into the database.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
bool generate_trees
Whether to generate spatial tree structures for the imported data.
bool application_locked
Whether the imported data should be locked from user editing.
bool center_model
Whether to translate the model so its center is at the origin.
bool tree_is_visible
Whether the imported model tree is initially visible.
Contains methods for getting information about particular OS directories or static program file direc...
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A core class that represents a node on model hierarchy.
Definition Model.h:292
Model createChild()
Creates a new child model and appends it to this model's child list.
void copyFrom(const Model &model, bool deep_copy, bool copy_ids=false, bool recursive=true, bool keep_root_properties=false)
Copies data from another model into this model.
virtual bool readFile(FactoryParameters &params) override
Reads an NDV file and populates the factory parameters with the resulting model data.
virtual bool writeFile(FactoryParameters &params) override
Writes model data to an NDV file as described by the factory parameters.
static FileFormat NDVFormat()
Returns the FileFormat descriptor for the NDV file format.
static NDVFactory & DefaultFactory()
Returns the singleton NDVFactory instance.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Scene.h:52
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
UUID activeAddressID() const
Returns the UUID for the active address scene node.
File m_bus_cache_location
File path to the bus cache on disk.
void createVehicleRoot()
Creates the involved vehicles root scene node if it does not already exist.
DynamicPointer< QTDesignObject > busCache()
Returns the root design object for the bus cache.
void createPedestrainRoot()
Creates the pedestrian root scene node if it does not already exist.
void saveBusCache()
Persists the bus cache to disk.
UUID witnessRootID() const
Returns the UUID for the witness root scene node.
DynamicPointer< QTDesignObject > incidentAddress()
Returns the design object for the incident address.
void createAddressRoot()
Creates the incident address root scene node if it does not already exist.
TransitIncidentManager(QTModelManager *manager)
Constructs the TransitIncidentManager.
DynamicPointer< QTDesignObject > vehicleRoot()
Returns the root design object for involved vehicles.
void createOfficerRoot()
Creates the officer root scene node if it does not already exist.
UUID officerRootID() const
Returns the UUID for the officer root scene node.
void saveCache(const File &file, const UUID &root)
Writes a scene tree to a cache file on disk.
void createBussesRoot()
Loads or creates the bus cache root from disk.
void createDriverRoot()
Loads or creates the driver cache root from disk.
void setupProject()
Initializes all root scene nodes required for an incident project.
UUID readCache(const File &file, const StringView &root_name)
Reads a cache file from disk, or creates a new root scene if the file does not exist.
DynamicPointer< QTDesignObject > witnessRoot()
Returns the root design object for witnesses.
void setActiveBus(const UUID &id)
Sets the active bus for the current incident by copying it from the cache.
UUID vehicleRootID() const
Returns the UUID for the involved vehicles root scene node.
UUID activeDriverID() const
Returns the UUID for the active driver scene node.
DynamicPointer< QTDesignObject > officerRoot()
Returns the root design object for officers.
void createWitnessRoot()
Creates the witness root scene node if it does not already exist.
UUID activeBusID() const
Returns the UUID for the active bus scene node.
File m_driver_cache_location
File path to the driver cache on disk.
Buffer< UUID > m_drivers
Cached list of driver UUIDs.
Buffer< UUID > m_bus_routes
Cached list of bus route UUIDs.
void setActiveDriver(const UUID &id)
Sets the active driver for the current incident by copying from the cache.
UUID pedestrianRootID() const
Returns the UUID for the pedestrian root scene node.
QTModelManager * manager() const
Returns the model manager.
DynamicPointer< QTDesignObject > driverCache()
Returns the root design object for the driver cache.
UUID m_bus_cache_root
UUID of the bus cache root scene.
DynamicPointer< QTDesignObject > pedestrianRoot()
Returns the root design object for pedestrians.
UUID m_driver_cache_root
UUID of the driver cache root scene.
QTModelManager * m_manager
The model manager used for data access.
void saveDriverCache()
Persists the driver cache to disk.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
@ guid
A 128-bit globally unique identifier for the object.
@ tree_visible
Whether the object is visible in the design tree view.
@ uncompressed_data
Uncompressed binary data storage.
@ file
The source file path associated with this object.
@ icon
Icon identifier for the object.
A container of input information that is to be filled with output information by an IOFactory.
Definition IOFactory.h:105
FactoryOptions options
All read/write options including special parameters.
Definition IOFactory.h:185
Buffer< UUID > models
UUIDs of models created or targeted by the operation.
Definition IOFactory.h:188
DesignObjectLookup * lookup
The design object lookup used to resolve models and objects.
Definition IOFactory.h:190
A FileRequest bundles format data as well as a particular file.
Definition FileFormat.h:101