API Documentation
Loading...
Searching...
No Matches
FactoryModelFilters.h
Go to the documentation of this file.
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{
10 /**--------------------------------------------------------------------------------------------------
11 \brief Provides easy filtering tools for factories that are only able to export certain types of
12 models or geometries.
13 **/
15 {
16 public:
17 template<class t_type>
18 static void SortModelsByName(Buffer<t_type>& models)
19 {
20 std::sort(models.begin(), models.end(), [](t_type& a, t_type& b)
21 {
22 return String::AlphaNumericCompare(a.displayNamePath().translation(), b.displayNamePath().translation());
23 });
24 }
25 static Buffer<Model> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<String>& types)
26 {
27 RLock lock(lookup->readLock());
28 Buffer<Model> models;
29 for (UUID id : models_to_check)
30 {
31 Model model = lookup->model(id);
32 if (model.isValid())
33 {
34 if (model.exportIgnored())
35 continue;
36 if (types.size() == 0)
37 {
38 models.add(model);
39 }
40 else
41 {
42 for (const String& type : types)
43 {
44 if (model.isOfType(type))
45 models.add(model);
46 else
47 models.addAll(model.getDescendentsByType(type));
48 }
49 }
50 }
51 }
52 for (uint04 i = models.size() - 1; !IsInvalid(i); i--)
53 {
54 if (models[i].exportIgnored())
55 models.removeIndex(i);
56 }
57 return models;
58 }
59 template<class t_type>
60 static Buffer<t_type> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup)
61 {
62 RLock lock(lookup->readLock());
63 Buffer<t_type> models;
64 for (UUID id : models_to_check)
65 {
66 Model model = lookup->model(id);
67 if (model.isValid())
68 {
69 if (model.exportIgnored())
70 continue;
71 if (model.isOfType(t_type::TypeName()))
72 models.add(t_type(model));
73 else
74 models.addAll(model.getTypeDescendents<t_type>(t_type::TypeName()));
75 }
76 }
77 return models;
78 }
79#if NDEVR_DEPLOYMENT
80 static Buffer<Deployment> FilterDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
81 {
82 RLock lock(lookup->readLock());
83 Buffer<Deployment> models;
84 for (UUID id : models_to_check)
85 {
86 Model model = lookup->model(id);
87 if (model.isValid())
88 {
89 if (model.isOfType(Deployment::TypeName()))
90 models.add(Deployment(model));
91 else
92 models.addAll(model.getTypeDescendents<Deployment>(Deployment::TypeName()));
93 }
94 }
95 models.removeAllUnordered([allow_planned](Deployment& deployment)
96 {
97 if (deployment.recordCount() == 0)
98 return true;
99 return !allow_planned && deployment.isPlanned();
100 });
101 if (sort)
102 {
103 SortModelsByName(models);
104 }
105 return models;
106 }
107#endif
108#if NDEVR_STATION_MODEL && NDEVR_DEPLOYMENT
109 static Buffer<StationModel> FilterStationDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
110 {
111 Buffer<Deployment> deployments = FilterDeploymentModels(models_to_check, lookup, false, allow_planned);
112 Dictionary<UUID, StationModel> stations;
113 for (const Deployment& deployment : deployments)
114 {
115 StationModel station = deployment.getStation();
116 if (station.isValid() && !stations.hasKey(station.uuid()))
117 stations.add(station.uuid(), station);
118
119 }
120 Buffer<StationModel> models = stations.values();
121 if (sort)
122 SortModelsByName(models);
123 return models;
124 }
125#endif
127 {
128 RLock lock(lookup->readLock());
129 Buffer<Model> all_models;
130 BasicModelIterator iter([&all_models, type](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
131 {
132 if (!m.exportIgnored() && geo.getGeometryType() == type)
133 all_models.add(m);
134 return BasicModelIterator::ParseResult::e_continue_parsing;
135 });
136 iter.model_filter = [](const Model& m)
137 {
138 return !m.exportIgnored() && !m.isApplicationOwned();
139 };
140 for (uint04 i = 0; i < models_to_check.size(); i++)
141 {
142 Model model = lookup->model(models_to_check[i]);
143 if (model.isValid())
144 iter.parseAll(model);
145 }
146 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
147 {
148 if (model.isApplicationOwned() || model.exportIgnored())
149 return true;
150 Buffer<Model> children = model.getChildren();
151 for (const Model& child : children)
152 {
153 if (child.isApplicationOwned() || child.exportIgnored())
154 continue;
155 if (!all_set.hasValue(child))
156 return false;
157 }
158 return true;
159 });
160 }
161 static Buffer<Model> FilterGeometryModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<GeometryType>& types)
162 {
163 RLock lock(lookup->readLock());
164 Buffer<Model> all_models;
165 BasicModelIterator iter([&all_models, types](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
166 {
167 if (!m.exportIgnored() && types.contains(geo.getGeometryType()))
168 all_models.add(m);
169 return BasicModelIterator::ParseResult::e_continue_parsing;
170 });
171 iter.model_filter = [](const Model& m)
172 {
173 return !m.exportIgnored() && !m.isApplicationOwned();
174 };
175 for (uint04 i = 0; i < models_to_check.size(); i++)
176 {
177 Model model = lookup->model(models_to_check[i]);
178 if (model.isValid())
179 iter.parseAll(model);
180 }
181 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
182 {
183 if (model.isApplicationOwned() || model.exportIgnored())
184 return true;
185 Buffer<Model> children = model.getChildren();
186 for (const Model& child : children)
187 {
188 if (child.isApplicationOwned() || child.exportIgnored())
189 continue;
190 if (!all_set.hasValue(child))
191 return false;
192 }
193 return true;
194 });
195 }
196 };
197}
#define NDEVR_FACTORY_API
Definition DLLInfo.h:57
A class for easily transversing a model heirarchy, applying an optional function at each level.
Definition ModelIterator.h:87
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
bool contains(const t_type &element) const
Definition Buffer.hpp:465
void removeAllUnordered(const t_type &object)
Removes all unordered described by object. This function does not preserve the order of the buffer.
Definition Buffer.hpp:641
constexpr t_index_type size() const
Definition Buffer.hpp:823
void addAll(const Buffer< t_type, t_other_index_type, t_other_memory_allocator, t_other_memory_manager > &buffer)
Definition Buffer.hpp:243
decltype(auto) end()
Definition Buffer.hpp:507
void removeIndex(t_index_type location)
Definition Buffer.hpp:606
decltype(auto) begin()
Definition Buffer.hpp:402
bool isValid() const
Definition DesignObject.h:355
A core class where all Design Objects including models, materials, and geometries are stored....
Definition DesignObjectLookup.h:65
Model model(const UUID &id, bool allow_deleted=false) const
Provides easy filtering tools for factories that are only able to export certain types of models or g...
Definition FactoryModelFilters.h:15
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, GeometryType type)
Definition FactoryModelFilters.h:126
static void SortModelsByName(Buffer< t_type > &models)
Definition FactoryModelFilters.h:18
static Buffer< Model > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< String > &types)
Definition FactoryModelFilters.h:25
static Buffer< t_type > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup)
Definition FactoryModelFilters.h:60
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< GeometryType > &types)
Definition FactoryModelFilters.h:161
A core class within the model heirarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:64
GeometryType getGeometryType() const
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
Buffer< Model, uint04, ObjectAllocator< DESIGN_PRIM > > getDescendentsByType(const String &type, uint04 max_count=Constant< uint04 >::Max) const
Buffer< t_type > getTypeDescendents(const String &type) const
Definition Model.h:302
Buffer< Model, uint04, ObjectAllocator< DESIGN_PRIM > > getChildren() const
bool isApplicationOwned() const
bool exportIgnored() const
bool isOfType(const String &type) const
ParseResult
Definition ModelIterator.h:46
std::function< bool(const Model &)> model_filter
Definition ModelIterator.h:61
Used to lock a particular variable for reading. Any number of readers can be created when no write lo...
Definition RWLock.h:91
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Model.h:51
bool hasValue(const t_value &key) const
Definition Set.h:70
The core String class for the NDEVR API.
Definition String.h:69
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
GeometryType
Definition DesignObjectBase.h:86
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96