载入中...
搜索中...
未找到
ArchSpaceTarget.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5#include <utility>
6
8namespace {
9
10const EditorValue* field(const EditorValue& value, const char* key) {
11 const auto* object = value.getIf<EditorValue::Object>();
12 if (!object) return nullptr;
13 const auto it = object->find(key);
14 return it == object->end() ? nullptr : &it->second;
15}
16
17bool readNumber(const EditorValue* value, double& out) {
18 if (!value) return false;
19 if (const auto* real = value->getIf<double>()) {
20 out = *real;
21 return std::isfinite(out);
22 }
23 if (const auto* integer = value->getIf<std::int64_t>()) {
24 out = static_cast<double>(*integer);
25 return true;
26 }
27 return false;
28}
29
30EditorValue vec2Value(const archspace::Vec2& v) { return EditorValue::Array{v.x, v.z}; }
31
32EditorValue vec3Value(const archspace::Vec3& v) { return EditorValue::Array{v.x, v.y, v.z}; }
33
34bool parseVec2(const EditorValue& value, archspace::Vec2& out) {
35 const auto* array = value.getIf<EditorValue::Array>();
36 if (!array || array->size() != 2) return false;
37 return readNumber(&(*array)[0], out.x) && readNumber(&(*array)[1], out.z);
38}
39
40bool parseVec3(const EditorValue& value, archspace::Vec3& out) {
41 const auto* array = value.getIf<EditorValue::Array>();
42 if (!array || array->size() != 3) return false;
43 return readNumber(&(*array)[0], out.x) && readNumber(&(*array)[1], out.y) && readNumber(&(*array)[2], out.z);
44}
45
46EditorValue nodeValue(const archspace::Node& node) {
48 for (const auto& child : node.children) children.push_back(child);
49 EditorValue::Array polygon;
50 for (const auto& p : node.polygon) polygon.push_back(vec2Value(p));
52 {"id", node.id},
53 {"kind", std::string(archspace::nodeKindName(node.kind))},
54 {"parentId", node.parentId},
55 {"name", node.name},
56 {"children", std::move(children)},
57 {"elevation", node.elevation},
58 {"height", node.height},
59 {"start", vec2Value(node.start)},
60 {"end", vec2Value(node.end)},
61 {"thickness", node.thickness},
62 {"polygon", std::move(polygon)},
63 {"slabThickness", node.slabThickness},
64 {"position", vec3Value(node.position)},
65 {"yawDegrees", node.yawDegrees},
66 {"catalogId", node.catalogId},
67 {"openingKind", std::string(archspace::openingKindName(node.openingKind))},
68 {"t", node.t},
69 {"width", node.width},
70 {"openingHeight", node.openingHeight},
71 {"sill", node.sill},
72 {"regionAId", node.regionAId},
73 {"regionBId", node.regionBId},
74 {"passageMask", static_cast<std::int64_t>(node.passageMask)},
75 {"portalPosition", vec3Value(node.portalPosition)},
76 };
77}
78
79Result<archspace::Node> parseNode(const EditorValue& value) {
80 archspace::Node node;
81 const auto* id = field(value, "id");
82 const auto* kind = field(value, "kind");
83 const auto* parentId = field(value, "parentId");
84 const auto* name = field(value, "name");
85 const auto* ids = id ? id->getIf<std::string>() : nullptr;
86 const auto* kinds = kind ? kind->getIf<std::string>() : nullptr;
87 const auto* parents = parentId ? parentId->getIf<std::string>() : nullptr;
88 const auto* names = name ? name->getIf<std::string>() : nullptr;
89 if (!ids || ids->empty() || !kinds || !parents || !names)
90 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.node"),
91 "ArchSpace node identity is invalid");
92 auto parsedKind = archspace::parseNodeKind(*kinds);
93 if (!parsedKind.ok())
94 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.kind"),
95 "ArchSpace node kind is unknown");
96 node.kind = parsedKind.value();
97 node.id = *ids;
98 node.parentId = *parents;
99 node.name = *names;
100 if (const auto* children = field(value, "children")) {
101 const auto* array = children->getIf<EditorValue::Array>();
102 if (!array)
103 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.children"),
104 "ArchSpace children must be an array");
105 for (const auto& child : *array) {
106 const auto* text = child.getIf<std::string>();
107 if (!text)
108 return eve::editing::failed<archspace::Node>(
109 EditorStatus::Rejected, RuleId("editor.archspace.children"), "ArchSpace child id must be a string");
110 node.children.push_back(*text);
111 }
112 }
113 readNumber(field(value, "elevation"), node.elevation);
114 readNumber(field(value, "height"), node.height);
115 if (const auto* start = field(value, "start"); start && !parseVec2(*start, node.start))
116 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.wall"),
117 "ArchSpace wall start is invalid");
118 if (const auto* end = field(value, "end"); end && !parseVec2(*end, node.end))
119 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.wall"),
120 "ArchSpace wall end is invalid");
121 readNumber(field(value, "thickness"), node.thickness);
122 if (const auto* polygon = field(value, "polygon")) {
123 const auto* array = polygon->getIf<EditorValue::Array>();
124 if (!array)
125 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.polygon"),
126 "ArchSpace polygon must be an array");
127 for (const auto& point : *array) {
128 archspace::Vec2 v;
129 if (!parseVec2(point, v))
130 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.polygon"),
131 "ArchSpace polygon point is invalid");
132 node.polygon.push_back(v);
133 }
134 }
135 readNumber(field(value, "slabThickness"), node.slabThickness);
136 if (const auto* position = field(value, "position"); position && !parseVec3(*position, node.position))
137 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.item"),
138 "ArchSpace item position is invalid");
139 readNumber(field(value, "yawDegrees"), node.yawDegrees);
140 if (const auto* catalog = field(value, "catalogId")) {
141 const auto* text = catalog->getIf<std::string>();
142 if (!text)
143 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.item"),
144 "ArchSpace catalog id must be a string");
145 node.catalogId = *text;
146 }
147 if (const auto* opening = field(value, "openingKind")) {
148 const auto* text = opening->getIf<std::string>();
149 if (!text)
150 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.opening"),
151 "ArchSpace opening kind must be a string");
153 if (!kind.ok())
154 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.opening"),
155 "ArchSpace opening kind is invalid");
156 node.openingKind = kind.value();
157 }
158 readNumber(field(value, "t"), node.t);
159 readNumber(field(value, "width"), node.width);
160 readNumber(field(value, "openingHeight"), node.openingHeight);
161 readNumber(field(value, "sill"), node.sill);
162 if (const auto* regionA = field(value, "regionAId")) {
163 const auto* text = regionA->getIf<std::string>();
164 if (!text)
165 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.portal"),
166 "ArchSpace regionAId must be a string");
167 node.regionAId = *text;
168 }
169 if (const auto* regionB = field(value, "regionBId")) {
170 const auto* text = regionB->getIf<std::string>();
171 if (!text)
172 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.portal"),
173 "ArchSpace regionBId must be a string");
174 node.regionBId = *text;
175 }
176 if (const auto* mask = field(value, "passageMask")) {
177 double value = 0.0;
178 if (!readNumber(mask, value) || value < 0.0 || value > 255.0)
179 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.portal"),
180 "ArchSpace passageMask is invalid");
181 node.passageMask = static_cast<archspace::PassageMask>(value);
182 }
183 if (const auto* portalPosition = field(value, "portalPosition");
184 portalPosition && !parseVec3(*portalPosition, node.portalPosition))
185 return eve::editing::failed<archspace::Node>(EditorStatus::Rejected, RuleId("editor.archspace.portal"),
186 "ArchSpace portalPosition is invalid");
187 return eve::editing::applied<archspace::Node>(std::move(node));
188}
189
191 double minimum = -1e9, double maximum = 1e9) {
193 d.path = PropertyPath(std::move(path));
194 d.displayNameKey = "editor.archspace." + d.path.value();
195 d.category = category;
196 d.type = type;
197 d.defaultValue = std::move(defaultValue);
198 d.flags = PropertyFlag::EditorOnly;
199 d.numeric.minimum = minimum;
200 d.numeric.maximum = maximum;
201 return d;
202}
203
204bool hasErrors(const std::vector<EditorDiagnostic>& values) {
205 return std::any_of(values.begin(), values.end(),
206 [](const auto& d) { return d.severity() == DiagnosticSeverity::Error; });
207}
208
209} // namespace
210
212
214 return {TargetId(id_),
215 "archspace-document",
217 false,
219}
220
222 if (capability == propertyCapabilityId()) return static_cast<IPropertyProvider*>(this);
224 return static_cast<IEditingSnapshotProvider*>(this);
225 return nullptr;
226}
227
229 return EditorValue::Object{{"schemaId", std::string("eve.archspace.document")},
230 {"schemaVersion", int64_t{1}},
231 {"content", contentValue()}};
232}
233
234bool ArchSpaceDocumentTarget::matches(const SelectionSnapshot& selection) const {
235 if (selection.items.empty()) return false;
236 for (const auto& item : selection.items) {
237 if (item.target != TargetId(id_) || !document_.find(item.item.value())) return false;
238 }
239 return true;
240}
241
242const archspace::Node* ArchSpaceDocumentTarget::selectedNode(const SelectionSnapshot& selection) const {
243 if (selection.items.size() != 1 || selection.items.front().target != TargetId(id_)) return nullptr;
244 return document_.find(selection.items.front().item.value());
245}
246
248 if (!matches(selection))
250 eve::DiagnosticCode::InvalidArgument, "ArchSpace selection mismatch", "editor.archspace.selection"));
252}
253
256 const archspace::Node* node = selectedNode(selection);
257 if (!node) return schema;
258 schema.typeId = std::string("archspace.") + archspace::nodeKindName(node->kind);
259 schema.properties.push_back(prop("name", PropertyType::String, node->name, "common"));
260 switch (node->kind) {
262 schema.properties.push_back(prop("elevation", PropertyType::Float, node->elevation, "level"));
263 schema.properties.push_back(prop("height", PropertyType::Float, node->height, "level", 0.1, 1000));
264 break;
266 schema.properties.push_back(prop("thickness", PropertyType::Float, node->thickness, "wall", 0.01, 10));
267 schema.properties.push_back(prop("height", PropertyType::Float, node->height, "wall", 0.1, 1000));
268 break;
270 schema.properties.push_back(prop("catalogId", PropertyType::String, node->catalogId, "item"));
271 schema.properties.push_back(prop("yawDegrees", PropertyType::Float, node->yawDegrees, "item"));
272 break;
274 schema.properties.push_back(prop("t", PropertyType::Float, node->t, "opening", 0, 1));
275 schema.properties.push_back(prop("width", PropertyType::Float, node->width, "opening", 0.01, 20));
276 schema.properties.push_back(
277 prop("openingHeight", PropertyType::Float, node->openingHeight, "opening", 0.01, 20));
278 schema.properties.push_back(prop("sill", PropertyType::Float, node->sill, "opening", 0, 20));
279 break;
280 default: break;
281 }
282 return schema;
283}
284
286 const archspace::Node* node = selectedNode(selection);
287 if (!node || !schema(selection).find(path)) return {};
288 if (path == PropertyPath("name")) return {PropertyReadState::Value, node->name, {}};
289 if (path == PropertyPath("elevation")) return {PropertyReadState::Value, node->elevation, {}};
290 if (path == PropertyPath("height")) return {PropertyReadState::Value, node->height, {}};
291 if (path == PropertyPath("thickness")) return {PropertyReadState::Value, node->thickness, {}};
292 if (path == PropertyPath("catalogId")) return {PropertyReadState::Value, node->catalogId, {}};
293 if (path == PropertyPath("yawDegrees")) return {PropertyReadState::Value, node->yawDegrees, {}};
294 if (path == PropertyPath("t")) return {PropertyReadState::Value, node->t, {}};
295 if (path == PropertyPath("width")) return {PropertyReadState::Value, node->width, {}};
296 if (path == PropertyPath("openingHeight")) return {PropertyReadState::Value, node->openingHeight, {}};
297 if (path == PropertyPath("sill")) return {PropertyReadState::Value, node->sill, {}};
298 return {};
299}
300
301EditorValue ArchSpaceDocumentTarget::contentValue() const {
303 for (const auto& [id, node] : document_.nodes()) {
304 (void)id;
305 nodes.push_back(nodeValue(node));
306 }
307 return EditorValue::Object{{"rootId", document_.rootId()},
308 {"topology", std::string(archspace::topologyKindName(document_.topology()))},
309 {"nodes", std::move(nodes)}};
310}
311
312Result<DomainOperation> ArchSpaceDocumentTarget::replacement(EditorValue content, std::string property) const {
314 op.type = "archspace.document.replace.v1";
315 op.inverseType = op.type;
316 op.target = TargetId(id_);
317 op.payload = std::move(content);
318 op.inverse = contentValue();
319 op.hasInverse = true;
320 if (!property.empty()) op.affectedProperties.push_back(property);
321 op.mergeKey = "archspace:" + id_ + ":" + (property.empty() ? "structure" : property);
322 return eve::editing::applied<DomainOperation>(std::move(op));
323}
324
325Result<void> ArchSpaceDocumentTarget::installContent(const EditorValue& content) {
326 const auto* rootIdValue = field(content, "rootId");
327 const auto* nodesValue = field(content, "nodes");
328 const auto* rootId = rootIdValue ? rootIdValue->getIf<std::string>() : nullptr;
329 const auto* nodes = nodesValue ? nodesValue->getIf<EditorValue::Array>() : nullptr;
330 if (!rootId || !nodes || !content.isWithinLimits(12, 250000, 32 * 1024 * 1024))
331 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.payload"),
332 "ArchSpace document payload is invalid or exceeds limits");
333 if (nodes->size() > 100000)
334 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.budget"),
335 "ArchSpace document exceeds 100000 nodes");
336
337 archspace::Document candidate;
338 if (const auto* topologyValue = field(content, "topology")) {
339 const auto* text = topologyValue->getIf<std::string>();
340 if (!text)
341 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.topology"),
342 "ArchSpace topology must be a string");
343 auto parsedTopology = archspace::parseTopologyKind(*text);
344 if (!parsedTopology.ok())
345 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.topology"),
346 "ArchSpace topology is unknown");
347 auto applied = candidate.setTopology(parsedTopology.value());
348 if (!applied.ok()) return applied;
349 }
350 if (rootId->empty() && nodes->empty()) {
351 document_ = std::move(candidate);
352 return eve::editing::applied<void>();
353 }
354 // Insert sites first, then remaining nodes in dependency-friendly passes.
355 std::vector<archspace::Node> parsed;
356 parsed.reserve(nodes->size());
357 for (const auto& value : *nodes) {
358 auto node = parseNode(value);
359 if (!node.ok())
360 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.node"),
361 "ArchSpace document contains an invalid node");
362 parsed.push_back(std::move(node.value()));
363 }
364 std::sort(parsed.begin(), parsed.end(), [](const archspace::Node& a, const archspace::Node& b) {
365 return static_cast<int>(a.kind) < static_cast<int>(b.kind);
366 });
367 for (auto& node : parsed) {
368 node.children.clear(); // re-linked by insert()
369 auto inserted = candidate.insert(std::move(node));
370 if (!inserted.ok())
371 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.insert"),
372 "ArchSpace document failed hierarchical insert");
373 }
374 if (candidate.rootId() != *rootId)
375 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.root"),
376 "ArchSpace root id does not match document content");
377 if (!candidate.diagnostics().empty())
378 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.invalid"),
379 "ArchSpace document validation failed");
380 document_ = std::move(candidate);
381 return eve::editing::applied<void>();
382}
383
384std::vector<EditorDiagnostic> ArchSpaceDocumentTarget::validate() const {
385 std::vector<EditorDiagnostic> out;
386 for (const auto& line : document_.diagnostics()) {
388 RuleId("editor.archspace.validate"), DiagnosticSeverity::Error,
389 line));
390 }
391 if (document_.nodeCount() > 100000) {
393 RuleId("editor.archspace.budget"), DiagnosticSeverity::Error,
394 "ArchSpace document exceeds 100000 nodes"));
395 }
396 return out;
397}
398
400 const PropertyPath& path, const EditorValue& value,
401 PropertySetMode mode) const {
402 if (mode == PropertySetMode::Reset) return makeReset(selection, path);
403 const auto descriptor = schema(selection).find(path);
404 const archspace::Node* node = selectedNode(selection);
405 if (!descriptor || !node || mode != PropertySetMode::Absolute)
406 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.set"),
407 "ArchSpace property requires a matching absolute edit");
408 auto checked = validatePropertyValue(*descriptor, value);
409 if (!checked.ok())
410 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.value"),
411 "ArchSpace property value is invalid");
412 archspace::Document candidate = document_;
413 archspace::Node* editable = candidate.findMutable(node->id);
414 if (!editable)
415 return eve::editing::failed<DomainOperation>(EditorStatus::NotFound, RuleId("editor.archspace.node"),
416 "ArchSpace node is missing");
417 if (path == PropertyPath("name")) {
418 const auto* text = value.getIf<std::string>();
419 if (!text)
420 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.name"),
421 "Name must be string");
422 editable->name = *text;
423 } else if (path == PropertyPath("catalogId")) {
424 const auto* text = value.getIf<std::string>();
425 if (!text)
426 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.catalog"),
427 "Catalog id must be string");
428 editable->catalogId = *text;
429 } else {
430 double number = 0.0;
431 if (!readNumber(&value, number))
432 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.number"),
433 "ArchSpace property requires a number");
434 if (path == PropertyPath("elevation"))
435 editable->elevation = number;
436 else if (path == PropertyPath("height"))
437 editable->height = number;
438 else if (path == PropertyPath("thickness"))
439 editable->thickness = number;
440 else if (path == PropertyPath("yawDegrees"))
441 editable->yawDegrees = number;
442 else if (path == PropertyPath("t"))
443 editable->t = number;
444 else if (path == PropertyPath("width"))
445 editable->width = number;
446 else if (path == PropertyPath("openingHeight"))
447 editable->openingHeight = number;
448 else if (path == PropertyPath("sill"))
449 editable->sill = number;
450 else
451 return eve::editing::failed<DomainOperation>(EditorStatus::Unsupported, RuleId("editor.archspace.property"),
452 "Unsupported ArchSpace property");
453 }
454 auto replaced = candidate.replace(*editable);
455 if (!replaced.ok())
456 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.invalid"),
457 "ArchSpace property update failed validation");
458 ArchSpaceDocumentTarget staged(id_);
459 staged.document_ = std::move(candidate);
460 if (hasErrors(staged.validate()))
461 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.invalid"),
462 "ArchSpace property update failed validation");
463 return replacement(staged.contentValue(), path.value());
464}
465
467 const PropertyPath& path) const {
468 const auto descriptor = schema(selection).find(path);
469 if (!descriptor)
470 return eve::editing::failed<DomainOperation>(EditorStatus::Unsupported, RuleId("editor.archspace.property"),
471 "Unknown ArchSpace property");
472 return makeSet(selection, path, descriptor->defaultValue, PropertySetMode::Absolute);
473}
474
476 const std::string& buildingId,
477 const std::string& levelId,
478 double levelHeight) const {
479 archspace::Document candidate = document_;
480 auto boot = candidate.bootstrap(siteId, buildingId, levelId, levelHeight);
481 if (!boot.ok())
482 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.bootstrap"),
483 "ArchSpace bootstrap requires an empty document and unique ids");
484 ArchSpaceDocumentTarget staged(id_);
485 staged.document_ = std::move(candidate);
486 return replacement(staged.contentValue());
487}
488
490 const std::string& levelId, const std::string& roomId, std::string roomName, double originX, double originZ,
491 double sizeX, double sizeZ, double wallHeight, double wallThickness, double slabThickness) const {
492 if (!(std::isfinite(originX) && std::isfinite(originZ) && std::isfinite(sizeX) && std::isfinite(sizeZ)) ||
493 sizeX <= 1e-6 || sizeZ <= 1e-6)
494 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.room"),
495 "ArchSpace room size must be finite and positive");
496 std::vector<archspace::Vec2> polygon = {
497 {originX, originZ},
498 {originX + sizeX, originZ},
499 {originX + sizeX, originZ + sizeZ},
500 {originX, originZ + sizeZ},
501 };
502 archspace::Document candidate = document_;
503 auto created = candidate.createRoom(levelId, roomId, std::move(roomName), std::move(polygon), wallHeight,
504 wallThickness, slabThickness);
505 if (!created.ok())
506 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.room"),
507 "ArchSpace room could not be created under the given level");
508 ArchSpaceDocumentTarget staged(id_);
509 staged.document_ = std::move(candidate);
510 return replacement(staged.contentValue());
511}
512
514 const std::string& wallId, std::string wallName,
516 double height, double thickness) const {
517 archspace::Document candidate = document_;
518 auto created = candidate.createWall(levelId, wallId, std::move(wallName), start, end, height, thickness);
519 if (!created.ok())
520 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.wall"),
521 "ArchSpace wall could not be created under the given level");
522 ArchSpaceDocumentTarget staged(id_);
523 staged.document_ = std::move(candidate);
524 return replacement(staged.contentValue());
525}
526
528 const std::string& openingId,
530 double width, double height,
531 double sill) const {
532 archspace::Document candidate = document_;
533 auto created = candidate.createOpening(wallId, openingId, openingId, kind, t, width, height, sill);
534 if (!created.ok())
535 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.opening"),
536 "ArchSpace opening insert failed validation");
537 ArchSpaceDocumentTarget staged(id_);
538 staged.document_ = std::move(candidate);
539 return replacement(staged.contentValue());
540}
541
543 const std::string& itemId, std::string catalogId,
545 double yawDegrees) const {
546 archspace::Document candidate = document_;
547 auto placed =
548 candidate.placeItem(levelId, itemId, itemId, std::move(catalogId), position, yawDegrees);
549 if (!placed.ok())
550 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.archspace.item"),
551 "ArchSpace item insert failed validation");
552 ArchSpaceDocumentTarget staged(id_);
553 staged.document_ = std::move(candidate);
554 return replacement(staged.contentValue());
555}
556
558 archspace::Document candidate = document_;
559 auto erased = candidate.eraseCascade(id.value());
560 if (!erased.ok())
561 return eve::editing::failed<DomainOperation>(EditorStatus::NotFound, RuleId("editor.archspace.delete"),
562 "ArchSpace node was not found");
563 ArchSpaceDocumentTarget staged(id_);
564 staged.document_ = std::move(candidate);
565 return replacement(staged.contentValue());
566}
567
569 if (operation.target != TargetId(id_) || operation.type != "archspace.document.replace.v1")
570 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.operation"),
571 "ArchSpace operation mismatch");
572 ArchSpaceDocumentTarget candidate(id_);
573 auto installed = candidate.installContent(operation.payload);
574 if (!installed.ok()) return installed;
575 if (hasErrors(candidate.validate()))
576 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.archspace.invalid"),
577 "ArchSpace document validation failed");
578 document_ = std::move(candidate.document_);
579 bumpRevision();
580 widenDirty(0, 0);
581 return eve::editing::applied<void>();
582}
583
584std::unique_ptr<IDomainOperationTarget> ArchSpaceDocumentTarget::cloneDomainState() const {
585 return std::make_unique<ArchSpaceDocumentTarget>(*this);
586}
587
588Result<void> ArchSpaceDocumentTarget::commitDomainState(std::unique_ptr<IDomainOperationTarget> candidate) {
589 auto* typed = dynamic_cast<ArchSpaceDocumentTarget*>(candidate.get());
590 if (!typed || typed->id_ != id_)
591 return eve::editing::failed<void>(EditorStatus::Conflict, RuleId("editor.archspace.candidate"),
592 "ArchSpace candidate mismatch");
593 *this = *typed;
594 return eve::editing::applied<void>();
595}
596
598 const auto* schemaIdValue = field(snapshot, "schemaId");
599 const auto* versionValue = field(snapshot, "schemaVersion");
600 const auto* content = field(snapshot, "content");
601 const auto* schemaId = schemaIdValue ? schemaIdValue->getIf<std::string>() : nullptr;
602 const auto* version = versionValue ? versionValue->getIf<std::int64_t>() : nullptr;
603 if (!schemaId || *schemaId != "eve.archspace.document" || !version || *version != 1 || !content)
604 return eve::editing::failed<void>(EditorStatus::Unsupported, RuleId("editor.archspace.snapshot"),
605 "Unsupported ArchSpace snapshot");
607 op.target = TargetId(id_);
608 op.type = "archspace.document.replace.v1";
609 op.payload = *content;
610 auto result = applyDomainOperation(op);
611 if (result.ok()) clearDirtyRegion();
612 return result;
613}
614
617 snapshot.status = EditorStatus::Applied;
618 snapshot.target = id_;
619 snapshot.targetRevision = revisionValue();
620 for (const auto& [id, node] : document_.nodes()) {
621 (void)id;
622 if (node.kind == archspace::NodeKind::Wall) {
623 EditorGizmoPrimitive primitive;
624 primitive.id = node.id;
625 primitive.kind = "segment";
626 primitive.position = {node.start.x,
627 document_.find(node.parentId) ? document_.find(node.parentId)->elevation : 0.0,
628 node.start.z};
629 primitive.direction = {node.end.x - node.start.x, 0.0, node.end.z - node.start.z};
630 primitive.length = std::sqrt(primitive.direction[0] * primitive.direction[0] +
631 primitive.direction[2] * primitive.direction[2]);
632 primitive.color = {0.2, 0.7, 1.0, 0.9};
633 snapshot.primitives.push_back(std::move(primitive));
634 } else if (node.kind == archspace::NodeKind::Zone && !node.polygon.empty()) {
635 double minX = node.polygon.front().x, maxX = minX, minZ = node.polygon.front().z, maxZ = minZ;
636 for (const auto& p : node.polygon) {
637 minX = std::min(minX, p.x);
638 maxX = std::max(maxX, p.x);
639 minZ = std::min(minZ, p.z);
640 maxZ = std::max(maxZ, p.z);
641 }
642 EditorGizmoPrimitive primitive;
643 primitive.id = node.id;
644 primitive.kind = "area";
645 primitive.dashed = true;
646 primitive.position = {(minX + maxX) * 0.5, 0.02, (minZ + maxZ) * 0.5};
647 primitive.size = {maxX - minX, 0.01, maxZ - minZ};
648 primitive.color = {0.8, 0.2, 1.0, 0.25};
649 snapshot.primitives.push_back(std::move(primitive));
650 } else if (node.kind == archspace::NodeKind::Item) {
651 EditorGizmoPrimitive primitive;
652 primitive.id = node.id;
653 primitive.kind = "point";
654 primitive.position = {node.position.x, node.position.y, node.position.z};
655 primitive.radius = 0.15;
656 primitive.color = {1.0, 0.8, 0.2, 0.9};
657 primitive.text = node.catalogId;
658 snapshot.primitives.push_back(std::move(primitive));
659 } else if (node.kind == archspace::NodeKind::Opening) {
660 const archspace::Node* wall = document_.find(node.parentId);
661 if (!wall) continue;
662 EditorGizmoPrimitive primitive;
663 primitive.id = node.id;
664 primitive.kind = "point";
665 primitive.position = {wall->start.x + (wall->end.x - wall->start.x) * node.t,
666 node.sill + node.openingHeight * 0.5,
667 wall->start.z + (wall->end.z - wall->start.z) * node.t};
668 primitive.radius = 0.12;
669 primitive.color = {0.2, 1.0, 0.4, 0.9};
670 primitive.text = archspace::openingKindName(node.openingKind);
671 snapshot.primitives.push_back(std::move(primitive));
672 } else if (node.kind == archspace::NodeKind::Portal) {
673 EditorGizmoPrimitive primitive;
674 primitive.id = node.id;
675 primitive.kind = "point";
676 primitive.position = {node.portalPosition.x, node.portalPosition.y, node.portalPosition.z};
677 primitive.radius = 0.14;
678 primitive.color = {1.0, 0.4, 0.1, 0.9};
679 primitive.text = "portal";
680 snapshot.primitives.push_back(std::move(primitive));
681 }
682 }
683 return eve::editing::applied<EditorGizmoSnapshot>(std::move(snapshot));
684}
685
686} // namespace eve::archspace_editing
ActionParameterOperation operation
Duration start
LogicalId itemId
std::string descriptor
int mask
bool applied
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::uint64_t parentId
float maximum[3]
float minimum[3]
float v
std::uint32_t height
std::uint32_t width
std::array< float, 3 > position
float thickness
std::map< std::string, Node > nodes
std::string id
Poco::JSON::Object::Ptr result
Snapshot snapshot
double defaultValue
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::string path
Definition PlayHost.cpp:111
std::set< std::string > values
Object::Ptr value
float d
float t
const RoadNode * node
double number
int created
unsigned line
std::string text
ScriptStructure out
size_t end
std::string kind
bool placed
int children
Definition TreeMesh.cpp:432
const char * category
glm::vec3 point
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
Authoritative ArchSpace document (Pascal-like node graph).
eve::Result< void > createWall(const std::string &levelId, const std::string &wallId, std::string wallName, Vec2 start, Vec2 end, double height, double thickness)
Insert a single wall under an existing level.
eve::Result< void > eraseCascade(const std::string &id)
Delete a node and every descendant. Root deletion clears the document.
Node * findMutable(const std::string &id)
Borrow a mutable node by id. @ownership Non-owning pointer into this document's node map; do not free...
eve::Result< void > placeItem(const std::string &levelId, const std::string &itemId, std::string itemName, std::string catalogId, Vec3 position, double yawDegrees=0.0)
Place a catalog item on an existing level.
eve::Result< void > bootstrap(const std::string &siteId, const std::string &buildingId, const std::string &levelId, double levelHeight=3.0)
Create site → building → level skeleton when the document is empty.
const Node * find(const std::string &id) const
Borrow a node by id. @ownership Non-owning pointer into this document's node map; do not free....
std::vector< std::string > diagnostics() const
Collect structural and geometric diagnostics as human-readable lines.
eve::Result< void > replace(Node node)
Replace authored fields while preserving id, kind, parent and children.
const std::unordered_map< std::string, Node > & nodes() const noexcept
const std::string & rootId() const noexcept
Root id.
TopologyKind topology() const noexcept
Topology dialect for authoring helpers and SpaceQuery.
eve::Result< void > createOpening(const std::string &wallId, const std::string &openingId, std::string openingName, OpeningKind kind, double t, double width, double height, double sill=0.0)
Insert a door/window opening on an existing wall.
eve::Result< void > createRoom(const std::string &levelId, const std::string &roomId, std::string roomName, std::vector< Vec2 > polygon, double wallHeight, double wallThickness, double slabThickness)
Create a closed room: perimeter walls + slab + zone under an existing level.
std::size_t nodeCount() const noexcept
Node count.
Revisioned ArchSpace document target for Inspector, tools and automation.
EditorValue snapshotValue() const override
Snapshot value.
Result< DomainOperation > makeBootstrap(const std::string &siteId, const std::string &buildingId, const std::string &levelId, double levelHeight=3.0) const
Plan site→building→level creation on an empty document.
ArchSpaceDocumentTarget(std::string id)
Arch space document target.
Result< DomainOperation > makeCreateWall(const std::string &levelId, const std::string &wallId, std::string wallName, archspace::Vec2 start, archspace::Vec2 end, double height=3.0, double thickness=0.2) const
Plan a single wall under a level.
Result< void > applyDomainOperation(const DomainOperation &operation) override
Applies domain operation.
Result< DomainOperation > makeDeleteNode(const ObjectId &id) const
Plan cascading deletion of one node.
TargetDescriptor describe() const override
Describe.
static CapabilityId propertyCapabilityId()
Capability identity published by describe() for Inspector property editing.
Result< void > loadSnapshot(const EditorValue &snapshot)
Loads snapshot.
Result< void > commitDomainState(std::unique_ptr< IDomainOperationTarget > candidate) override
Commits domain state.
eve::Result< eve::Revision > currentRevision(const SelectionSnapshot &selection) const override
Current revision.
void * queryCapability(const CapabilityId &capability) override
Query Inspector property capability. @ownership Borrowed from this target; callers must not delete it...
PropertyReadResult read(const SelectionSnapshot &selection, const PropertyPath &path) const override
Reads .
Result< DomainOperation > makeCreateOpening(const std::string &wallId, const std::string &openingId, archspace::OpeningKind kind, double t, double width, double height, double sill=0.0) const
Plan a door/window opening on an existing wall.
Result< DomainOperation > makeSet(const SelectionSnapshot &selection, const PropertyPath &path, const EditorValue &value, PropertySetMode mode) const override
Make set.
std::unique_ptr< IDomainOperationTarget > cloneDomainState() const override
Clones domain state.
std::vector< EditorDiagnostic > validate() const
Validate.
Result< DomainOperation > makeReset(const SelectionSnapshot &selection, const PropertyPath &path) const override
Make reset.
Result< DomainOperation > makePlaceItem(const std::string &levelId, const std::string &itemId, std::string catalogId, archspace::Vec3 position, double yawDegrees=0.0) const
Plan a catalog item placement on a level.
PropertySchema schema(const SelectionSnapshot &selection) const override
Schema.
Result< EditorGizmoSnapshot > gizmo() const
Build a revision-bound overlay for walls, zones, items and openings.
Result< DomainOperation > makeCreateRectRoom(const std::string &levelId, const std::string &roomId, std::string roomName, double originX, double originZ, double sizeX, double sizeZ, double wallHeight=3.0, double wallThickness=0.2, double slabThickness=0.2) const
Plan a rectangular room (four walls + slab + zone) under a level.
void bumpRevision()
Advance the revision without touching the dirty region.
Revision revisionValue() const noexcept
Return the revision as the shared protocol revision type.
void widenDirty()
Mark an unknown area dirty without advancing the revision.
eve::OptionalRef< C > capability()
Query a capability through its interface-owned stable identity.
virtual void clearDirtyRegion()=0
Clears dirty region.
Optional capability exposing a deterministic, persistence-safe editing snapshot.
static CapabilityId editingCapabilityId()
Stable capability identity shared by every editable domain target.
UI-independent property access for an immutable selection snapshot.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
std::vector< Value > Array
std::map< std::string, Value > Object
const T * getIf() const
Return an immediately borrowed typed value.
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
editing::PropertyDescriptor PropertyDescriptor
editing::DomainOperation DomainOperation
editing::Value EditorValue
editing::PropertyPath PropertyPath
editing::TargetId TargetId
editing::PropertyType PropertyType
editing::SelectionSnapshot SelectionSnapshot
std::uint8_t PassageMask
Bitmask of PassageMode values.
eve::Result< TopologyKind > parseTopologyKind(const std::string &text) noexcept
Parse a topology kind wire name.
OpeningKind
Opening semantic used by doors and windows hosted on walls.
eve::Result< NodeKind > parseNodeKind(const std::string &text) noexcept
Parse a node kind wire name.
@ Portal
Level-hosted portal connecting two regions (dungeon/cave or free openings).
const char * openingKindName(OpeningKind kind) noexcept
Stable wire name for an opening kind. @ownership Non-owning pointer to a static string literal; do no...
const char * topologyKindName(TopologyKind kind) noexcept
Stable wire name for a topology kind. @ownership Non-owning pointer to a static string literal; do no...
const char * nodeKindName(NodeKind kind) noexcept
Stable wire name for a node kind. @ownership Non-owning pointer to a static string literal; do not fr...
eve::Result< OpeningKind > parseOpeningKind(const std::string &text) noexcept
Parse an opening kind wire name.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
EVENGINE_API_PLATFORM bool hasErrors(const std::vector< DnutDiagnostic > &diagnostics)
Return whether any diagnostic is an error.
PropertySetMode
PropertySetMode public API.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
eve::Result< double > readNumber(const eve::Value::Object &object, std::string_view name)
Reads a required finite number.
One authored architectural node. Only fields for the active kind are meaningful.
Metres on the level XZ plane.
Metres in world/level space.
DomainOperation public API.
Renderer-neutral wire primitive for authoring viewport overlays.
std::array< double, 3 > size
std::array< double, 3 > direction
std::array< double, 3 > position
std::array< double, 4 > color
Immutable revision-tagged overlay snapshot consumed by any viewport renderer.
PropertyReadResult public API.
EVENGINE_API_PLATFORM public API.
std::vector< PropertyDescriptor > properties
PropertyDescriptorLookup find(const PropertyPath &path) const
Finds find.
SelectionSnapshot public API.
std::vector< SelectionItem > items
Stable discovery metadata exposed by every editable target.