NDEVR
API Documentation
FactoryModelFilters.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/DesignObjectLookup.h>
4#include <NDEVR/Deployment.h>
5#include <NDEVR/StationModel.h>
6#include <NDEVR/ModelIterator.h>
7#include <NDEVR/Set.h>
8namespace NDEVR
9{
19 {
20 public:
26 template<class t_type>
27 static void SortModelsByName(Buffer<t_type>& models)
28 {
29 std::sort(models.begin(), models.end(), [](t_type& a, t_type& b)
30 {
31 return String::AlphaNumericCompare(a.displayNamePath().translation(), b.displayNamePath().translation());
32 });
33 }
34
42 static Buffer<Model> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<String>& types)
43 {
44 RLock lock(lookup->readLock());
45 Buffer<Model> models;
46 for (UUID id : models_to_check)
47 {
48 Model model = lookup->model(id);
49 if (model.isValid())
50 {
51 if (model.exportIgnored())
52 continue;
53 if (types.size() == 0)
54 {
55 models.add(model);
56 }
57 else
58 {
59 for (const String& type : types)
60 {
61 if (model.is<NDPN::type>(type))
62 models.add(model);
63 else
64 models.addAll(model.getDescendantsByType(type));
65 }
66 }
67 }
68 }
69 for (uint04 i = models.size() - 1; IsValid(i); i--)
70 {
71 if (models[i].exportIgnored())
72 models.removeIndex(i);
73 }
74 return models;
75 }
76
85 static Buffer<Model> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<StringView>& types)
86 {
87 RLock lock(lookup->readLock());
88 Buffer<Model> models;
89 for (UUID id : models_to_check)
90 {
91 Model model = lookup->model(id);
92 if (model.isValid())
93 {
94 if (model.exportIgnored())
95 continue;
96 if (types.size() == 0)
97 {
98 models.add(model);
99 }
100 else
101 {
102 for (const StringView& type : types)
103 {
104 if (model.is<NDPN::type>(type))
105 models.add(model);
106 else
107 models.addAll(model.getDescendantsByType(type));
108 }
109 }
110 }
111 }
112 for (uint04 i = models.size() - 1; IsValid(i); i--)
113 {
114 if (models[i].exportIgnored())
115 models.removeIndex(i);
116 }
117 return models;
118 }
119
126 template<class t_type>
127 static Buffer<t_type> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup)
128 {
129 RLock lock(lookup->readLock());
130 Buffer<t_type> models;
131 for (UUID id : models_to_check)
132 {
133 Model model = lookup->model(id);
134 if (model.isValid())
135 {
136 if (model.exportIgnored())
137 continue;
138 if (model.is<NDPN::type>(t_type::TypeName()))
139 models.add(t_type(model));
140 else
141 models.addAll(model.getTypeDescendants<t_type>(t_type::TypeName()));
142 }
143 }
144 return models;
145 }
146#if NDEVR_DEPLOYMENT
156 static Buffer<Deployment> FilterDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
157 {
158 RLock lock(lookup->readLock());
159 Buffer<Deployment> models;
160 for (UUID id : models_to_check)
161 {
162 Model model = lookup->model(id);
163 if (model.isValid())
164 {
165 if (model.is<NDPN::type>(Deployment::TypeName()))
166 models.add(Deployment(model));
167 else
168 models.addAll(model.getTypeDescendants<Deployment>(Deployment::TypeName()));
169 }
170 }
171 models.removeAllUnordered([allow_planned](Deployment& deployment)
172 {
173 if (deployment.recordCount() == 0)
174 return true;
175 return !allow_planned && deployment.isPlanned();
176 });
177 if (sort)
178 {
179 SortModelsByName(models);
180 }
181 return models;
182 }
183#endif
184#if NDEVR_STATION_MODEL && NDEVR_DEPLOYMENT
194 static Buffer<StationModel> FilterStationDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
195 {
196 Buffer<Deployment> deployments = FilterDeploymentModels(models_to_check, lookup, false, allow_planned);
197 Dictionary<UUID, StationModel> stations;
198 for (const Deployment& deployment : deployments)
199 {
200 StationModel station = deployment.getStation();
201 if (station.isValid() && !stations.hasKey(station.get<NDPO::guid>()))
202 stations.add(station.get<NDPO::guid>(), station);
203
204 }
205 Buffer<StationModel> models = stations.values();
206 if (sort)
207 SortModelsByName(models);
208 return models;
209 }
210#endif
221 {
222 RLock lock(lookup->readLock());
223 Buffer<Model> all_models;
224 BasicModelIterator iter([&all_models, type](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
225 {
226 if (!m.exportIgnored() && geo.getGeometryType() == type)
227 all_models.add(m);
229 });
230 iter.model_filter = [](const Model& m)
231 {
232 return !m.exportIgnored() && !m.isApplicationOwned();
233 };
234 for (uint04 i = 0; i < models_to_check.size(); i++)
235 {
236 Model model = lookup->model(models_to_check[i]);
237 if (model.isValid())
238 iter.parseAll(model);
239 }
240 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
241 {
242 if (model.isApplicationOwned() || model.exportIgnored())
243 return true;
244 Buffer<Model> children = model.getChildren();
245 for (const Model& child : children)
246 {
247 if (child.isApplicationOwned() || child.exportIgnored())
248 continue;
249 if (!all_set.hasValue(child))
250 return false;
251 }
252 return true;
253 });
254 }
255
264 static Buffer<Model> FilterGeometryModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<GeometryType>& types)
265 {
266 RLock lock(lookup->readLock());
267 Buffer<Model> all_models;
268 BasicModelIterator iter([&all_models, types](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
269 {
270 if (!m.exportIgnored() && types.contains(geo.getGeometryType()))
271 all_models.add(m);
273 });
274 iter.model_filter = [](const Model& m)
275 {
276 return !m.exportIgnored() && !m.isApplicationOwned();
277 };
278 for (uint04 i = 0; i < models_to_check.size(); i++)
279 {
280 Model model = lookup->model(models_to_check[i]);
281 if (model.isValid())
282 iter.parseAll(model);
283 }
284 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
285 {
286 if (model.isApplicationOwned() || model.exportIgnored())
287 return true;
288 Buffer<Model> children = model.getChildren();
289 for (const Model& child : children)
290 {
291 if (child.isApplicationOwned() || child.exportIgnored())
292 continue;
293 if (!all_set.hasValue(child))
294 return false;
295 }
296 return true;
297 });
298 }
299 };
300}
Provides cross-platform DLL export/import macros for the IOFactory module.
#define NDEVR_FACTORY_API
GCC/Clang symbol visibility — marks symbols as visible in the shared library.
Definition DLLInfo.h:92
A convenience subclass of ModelIterator that delegates processing to user-supplied std::function call...
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void removeAllUnordered(const t_type &object)
Removes all unordered described by object.
Definition Buffer.hpp:679
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:190
A core class where all Design Objects including models, materials, and geometries are stored.
RLock readLock() const
Acquires a shared read lock on the design object store.
Model model(const UUID &id, bool allow_deleted=false) const
Retrieves a model by its UUID.
bool isValid() const
Checks whether this design object has a valid index into the database.
bool is(t_property_type property, const StringView &value) const
Checks whether a string property matches the given StringView value.
Provides easy filtering tools for factories that are only able to export certain types of models or g...
static Buffer< Model > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< String > &types)
Filters models by one or more type name strings, returning only models (or their descendants) that ma...
static void SortModelsByName(Buffer< t_type > &models)
Sorts a buffer of models alphabetically by their display name path using alphanumeric comparison.
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< GeometryType > &types)
Filters models to find those containing geometry matching any of the specified types.
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, GeometryType type)
Filters models to find those containing geometry of a specific type.
static Buffer< t_type > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup)
Filters models by a compile-time type, returning only models (or their descendants) whose type name m...
static Buffer< Model > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< StringView > &types)
Filters models by one or more type name string views, returning only models (or their descendants) th...
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
GeometryType getGeometryType() const
Retrieves the geometry type identifier.
std::function< bool(const Model &)> model_filter
Optional filter predicate for model processing. Returns true to include.
ParseResult
The result returned by process functions to control iteration flow.
@ e_continue_parsing
Continue normal traversal to sibling and child nodes.
A core class that represents a node on model hierarchy.
Definition Model.h:292
bool isApplicationOwned() const
Checks whether this model is owned by the application (not user-created).
static ModelBuffer ReduceToRoots(const ModelBuffer &children, const std::function< bool(const Model &, const Set< Model > &)> &filter)
Reduces a collection of models to only root-level models (removing any that are descendants of others...
Buffer< t_type > getTypeDescendants(const StringView &type) const
Recursively searches descendants for models of a specific type, cast to a derived type.
Definition Model.h:802
ModelBuffer getDescendantsByType(const StringView &type, uint04 max_count=Constant< uint04 >::Max) const
Recursively searches all descendants for models matching the given type.
ModelBuffer getChildren() const
Returns a buffer containing all direct children of this model.
bool exportIgnored() const
Checks whether this model is excluded from export operations.
Used to lock a particular variable for reading.
Definition RWLock.h:157
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
bool hasValue(const t_value &key) const
Checks whether the Set contains the given value.
Definition Set.h:96
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
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
GeometryType
Describes the high-level geometric topology of a Geometry object.