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{
11 {
12 public:
13 template<class t_type>
14 static void SortModelsByName(Buffer<t_type>& models)
15 {
16 std::sort(models.begin(), models.end(), [](t_type& a, t_type& b)
17 {
18 return String::AlphaNumericCompare(a.displayNamePath().translation(), b.displayNamePath().translation());
19 });
20 }
21 static Buffer<Model> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<String>& types)
22 {
23 RLock lock(lookup->readLock());
24 Buffer<Model> models;
25 for (UUID id : models_to_check)
26 {
27 Model model = lookup->model(id);
28 if (model.isValid())
29 {
30 if (model.exportIgnored())
31 continue;
32 if (types.size() == 0)
33 {
34 models.add(model);
35 }
36 else
37 {
38 for (const String& type : types)
39 {
40 if (model.isOfType(type))
41 models.add(model);
42 else
43 models.addAll(model.getDescendentsByType(type));
44 }
45 }
46 }
47 }
48 for (uint04 i = models.size() - 1; !isNaN(i); i--)
49 {
50 if (models[i].exportIgnored())
51 models.removeIndex(i);
52 }
53 return models;
54 }
55 template<class t_type>
56 static Buffer<t_type> FilterTypeModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup)
57 {
58 RLock lock(lookup->readLock());
59 Buffer<t_type> models;
60 for (UUID id : models_to_check)
61 {
62 Model model = lookup->model(id);
63 if (model.isValid())
64 {
65 if (model.exportIgnored())
66 continue;
67 if (model.isOfType(t_type::TypeName()))
68 models.add(t_type(model));
69 else
70 models.addAll(model.getTypeDescendents<t_type>(t_type::TypeName()));
71 }
72 }
73 return models;
74 }
75#if NDEVR_DEPLOYMENT
76 static Buffer<Deployment> FilterDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
77 {
78 RLock lock(lookup->readLock());
79 Buffer<Deployment> models;
80 for (UUID id : models_to_check)
81 {
82 Model model = lookup->model(id);
83 if (model.isValid())
84 {
85 if (model.isOfType(Deployment::TypeName()))
86 models.add(Deployment(model));
87 else
88 models.addAll(model.getTypeDescendents<Deployment>(Deployment::TypeName()));
89 }
90 }
91 models.removeAllUnordered([allow_planned](Deployment& deployment)
92 {
93 if (deployment.recordCount() == 0)
94 return true;
95 return !allow_planned && deployment.isPlanned();
96 });
97 if (sort)
98 {
99 SortModelsByName(models);
100 }
101 return models;
102 }
103#endif
104#if NDEVR_STATION_MODEL && NDEVR_DEPLOYMENT
105 static Buffer<StationModel> FilterStationDeploymentModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, bool sort, bool allow_planned = false)
106 {
107 Buffer<Deployment> deployments = FilterDeploymentModels(models_to_check, lookup, false, allow_planned);
108 Dictionary<UUID, StationModel> stations;
109 for (const Deployment& deployment : deployments)
110 {
111 StationModel station = deployment.getStation();
112 if (station.isValid() && !stations.hasKey(station.uuid()))
113 stations.add(station.uuid(), station);
114
115 }
116 Buffer<StationModel> models = stations.values();
117 if (sort)
118 SortModelsByName(models);
119 return models;
120 }
121#endif
123 {
124 RLock lock(lookup->readLock());
125 Buffer<Model> all_models;
126 BasicModelIterator iter([&all_models, type](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
127 {
128 if (!m.exportIgnored() && geo.getGeometryType() == type)
129 all_models.add(m);
130 return BasicModelIterator::ParseResult::e_continue_parsing;
131 });
132 iter.model_filter = [](const Model& m)
133 {
134 return !m.exportIgnored() && !m.isApplicationOwned();
135 };
136 for (uint04 i = 0; i < models_to_check.size(); i++)
137 {
138 Model model = lookup->model(models_to_check[i]);
139 if (model.isValid())
140 iter.parseAll(model);
141 }
142 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
143 {
144 if (model.isApplicationOwned() || model.exportIgnored())
145 return true;
146 Buffer<Model> children = model.getChildren();
147 for (const Model& child : children)
148 {
149 if (child.isApplicationOwned() || child.exportIgnored())
150 continue;
151 if (!all_set.hasValue(child))
152 return false;
153 }
154 return true;
155 });
156 }
157 static Buffer<Model> FilterGeometryModels(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const Buffer<GeometryType>& types)
158 {
159 RLock lock(lookup->readLock());
160 Buffer<Model> all_models;
161 BasicModelIterator iter([&all_models, types](const Model& m, Geometry& geo) -> BasicModelIterator::ParseResult
162 {
163 if (!m.exportIgnored() && types.contains(geo.getGeometryType()))
164 all_models.add(m);
165 return BasicModelIterator::ParseResult::e_continue_parsing;
166 });
167 iter.model_filter = [](const Model& m)
168 {
169 return !m.exportIgnored() && !m.isApplicationOwned();
170 };
171 for (uint04 i = 0; i < models_to_check.size(); i++)
172 {
173 Model model = lookup->model(models_to_check[i]);
174 if (model.isValid())
175 iter.parseAll(model);
176 }
177 return Model::ReduceToRoots(all_models, [](const Model& model, const Set<Model>& all_set)->bool
178 {
179 if (model.isApplicationOwned() || model.exportIgnored())
180 return true;
181 Buffer<Model> children = model.getChildren();
182 for (const Model& child : children)
183 {
184 if (child.isApplicationOwned() || child.exportIgnored())
185 continue;
186 if (!all_set.hasValue(child))
187 return false;
188 }
189 return true;
190 });
191 }
192 };
193}
#define NDEVR_FACTORY_API
Definition DLLInfo.h:79
Definition ModelIterator.h:93
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
bool contains(const t_type &element) const
Definition Buffer.hpp:674
void removeAllUnordered(const t_type &object)
Definition Buffer.hpp:1119
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void addAll(const Buffer< t_type, t_other_index_type, t_other_memory_allocator, t_other_memory_manager > &buffer)
Definition Buffer.hpp:248
decltype(auto) end()
Definition Buffer.hpp:746
void removeIndex(t_index_type location)
Definition Buffer.hpp:1037
decltype(auto) begin()
Definition Buffer.hpp:504
bool isValid() const
Definition DesignObject.h:362
Definition DesignObjectLookup.h:61
RLock readLock() const
Definition DesignObjectLookup.cpp:909
Model model(const UUID &id, bool allow_deleted=false) const
Definition DesignObjectLookup.cpp:1683
Definition FactoryModelFilters.h:11
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, GeometryType type)
Definition FactoryModelFilters.h:122
static void SortModelsByName(Buffer< t_type > &models)
Definition FactoryModelFilters.h:14
static Buffer< Model > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< String > &types)
Definition FactoryModelFilters.h:21
static Buffer< t_type > FilterTypeModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup)
Definition FactoryModelFilters.h:56
static Buffer< Model > FilterGeometryModels(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const Buffer< GeometryType > &types)
Definition FactoryModelFilters.h:157
Definition Geometry.h:64
GeometryType getGeometryType() const
Definition Geometry.cpp:1054
Definition Model.h:54
Buffer< t_type > getTypeDescendents(const String &type) const
Definition Model.h:298
Buffer< Model, uint04, ObjectAllocator< DESIGN_PRIM > > getChildren() const
Definition Model.cpp:2733
bool isApplicationOwned() const
Definition Model.cpp:3181
bool exportIgnored() const
Definition Model.cpp:1249
Buffer< Model, uint04, ObjectAllocator< DESIGN_PRIM > > getDescendentsByType(const String &type, uint04 max_count=Constant< uint04 >::Max) const
Definition Model.cpp:2805
bool isOfType(const String &type) const
Definition Model.cpp:3075
ParseResult
Definition ModelIterator.h:42
std::function< bool(const Model &)> model_filter
Definition ModelIterator.h:69
Definition RWLock.h:80
Definition Model.h:51
bool hasValue(const t_value &key) const
Definition Set.h:61
Definition String.h:40
Definition UUID.h:66
Definition ACIColor.h:37
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:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200