src/polygoncache.cpp

changeset 340
e17e07661f4c
parent 338
719b909a7d2b
child 358
ef90ed0a5720
equal deleted inserted replaced
339:4787d05e9c89 340:e17e07661f4c
2 #include "src/documentmanager.h" 2 #include "src/documentmanager.h"
3 #include "src/invert.h" 3 #include "src/invert.h"
4 #include "src/polygoncache.h" 4 #include "src/polygoncache.h"
5 #include "src/parser.h" 5 #include "src/parser.h"
6 6
7 Model* resolve(const QString& name, const ModelId callingModelId, DocumentManager* documents) 7 QTextDocument* resolve(const QString& name, const ModelId callingModelId, DocumentManager* documents)
8 { 8 {
9 return documents->findDependencyByName(callingModelId, name); 9 return documents->findDependencyByName(callingModelId, name);
10 } 10 }
11 11
12 static PolygonElement transformed( 12 static PolygonElement transformed(
17 p = transform * glm::vec4{p, 1}; 17 p = transform * glm::vec4{p, 1};
18 }, element); 18 }, element);
19 return element; 19 return element;
20 } 20 }
21 21
22 PolygonCache* findPolygonCacheForModel(Model* model, DocumentManager* context) 22 PolygonCache* findPolygonCacheForModel(QTextDocument* model, DocumentManager* context)
23 { 23 {
24 std::optional<ModelId> modelId = context->findIdForModel(model); 24 std::optional<ModelId> modelId = context->findIdForModel(model);
25 if (modelId.has_value()) { 25 if (modelId.has_value()) {
26 return context->getPolygonCacheForModel(modelId.value()); 26 return context->getPolygonCacheForModel(modelId.value());
27 } 27 }
72 } 72 }
73 add(polygon); 73 add(polygon);
74 } 74 }
75 } 75 }
76 76
77 static Model* findDependency(const SubfileReference& ref, GetPolygonsContext* context) 77 static QTextDocument* findDependency(const SubfileReference& ref, GetPolygonsContext* context)
78 { 78 {
79 return context->documents->findDependencyByName(context->modelId, ref.name); 79 return context->documents->findDependencyByName(context->modelId, ref.name);
80 } 80 }
81 81
82 template<typename Fn, typename Fn2> 82 template<typename Fn, typename Fn2>
116 }, 116 },
117 [&](const LineType5& line5) { 117 [&](const LineType5& line5) {
118 add({line5.value, line5.value.color}); 118 add({line5.value, line5.value.color});
119 }, 119 },
120 [&add, context, &reserve](const LineType1& line1) { 120 [&add, context, &reserve](const LineType1& line1) {
121 Model* const dependency = findDependency(line1.value, context); 121 QTextDocument* const dependency = findDependency(line1.value, context);
122 if (PolygonCache* cache = (dependency != nullptr) 122 if (PolygonCache* cache = (dependency != nullptr)
123 ? findPolygonCacheForModel(dependency, context->documents) 123 ? findPolygonCacheForModel(dependency, context->documents)
124 : nullptr 124 : nullptr
125 ) { 125 ) {
126 recacheIfNeeded(cache, dependency, context->documents); 126 recacheIfNeeded(cache, dependency, context->documents);
142 context->invertnext = false; 142 context->invertnext = false;
143 } 143 }
144 } 144 }
145 145
146 static std::vector<WithId<PolygonElement>> inlinePolygons( 146 static std::vector<WithId<PolygonElement>> inlinePolygons(
147 const Model* model, 147 const QTextDocument* model,
148 GetPolygonsContext* context) 148 GetPolygonsContext* context)
149 { 149 {
150 Winding winding = NoWinding; 150 Winding winding = NoWinding;
151 std::vector<WithId<PolygonElement>> result; 151 std::vector<WithId<PolygonElement>> result;
152 int i = 0; 152 int i = 0;
167 ++i; 167 ++i;
168 } 168 }
169 return result; 169 return result;
170 } 170 }
171 171
172 void recacheIfNeeded(PolygonCache *cache, Model *model, DocumentManager *documents) 172 void recacheIfNeeded(PolygonCache *cache, QTextDocument *model, DocumentManager *documents)
173 { 173 {
174 if (cache->needRecache) 174 if (cache->needRecache)
175 { 175 {
176 cache->polygons.clear(); 176 cache->polygons.clear();
177 const std::optional<ModelId> modelId = documents->findIdForModel(model); 177 const std::optional<ModelId> modelId = documents->findIdForModel(model);

mercurial