/
Team8
/
kittycad
Обзор
Документация
Войти
/
Team8
/
kittycad
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/data/templates/template.cpp
122 строки
4 KB
levovix
fix;
10 янв 2026, 21:53
10 янв 2026, 21:53
eb2e123
Код
Авторство
О чём код?
#include "./template.h" #include "./template_utils.ipp" #include "data/document.h" #include "mb_axis3d.h" #include "vsn_scenecontent.h" #include "vsn_scenesegment.h" data::Template::Template() {} data::Template::~Template() {} void data::Template::buildVisual() { assert(m_visualChanged); m_visualChanged = false; if ((!m_parent.expired()) && m_parent.lock()->visual == nullptr) { m_parent.lock()->markVisualChanged(); m_parent.lock()->buildVisual(); } if (visual == nullptr) { visual = new VSN::SceneSegment( (m_parent.expired() ? document.lock()->sceneContent->GetRootSegment() : m_parent.lock()->visual) ); document.lock()->sceneToData[visual] = weak_from_this(); visual->SetVisible(visible); } } void data::Template::removeChild(ref<C3dObject> const& child) { if (childIndex(child) != -1) { if (m_parent.expired()) { m_parent.lock()->removeChild(asRef(this)); } else if (!document.expired()) { document.lock()->removeChild(asRef(this)); } else { C3dObject::removeChild(child); } } else { C3dObject::removeChild(child); } } data::GeomItemPtr findLatestVersion(data::GeomItemPtr item) { while (true) { if (item.obj.expired()) { break; } auto prevObj = item.obj; for (auto const& user : item.obj.lock()->usedBy) { if (auto userCommand = std::dynamic_pointer_cast<data::SketchOperation>(user.lock())) { item = userCommand->getNewVersion(item); if (prevObj.lock().get() != item.obj.lock().get()) { break; } } } if (item.obj.lock().get() == prevObj.lock().get()) { break; } } return item; } int findAssemblyItem( data::AssemblyItemProperties props, SPtr<MbSolid> const& solid ) { assert(solid != nullptr); // todo: AssemblyItemPtr по геометрическому описанию, который можно было бы установать пользователю на объект if (props.kind == tt_Face) { std::vector<MbVertex*> vertices; solid->GetVertices(vertices); std::vector<MbEdge*> edges; solid->GetEdges(edges); std::vector<MbFace*> faces; solid->GetFaces(faces); for (int faceI = 0; faceI < faces.size(); ++faceI) { auto& face = faces[faceI]; Point3 point; Vec3 normal; if (props.normalWasReversed != nullptr) { *props.normalWasReversed = false; } if (props.planar.has_value() && (*props.planar != face->IsPlanar())) { continue; } if (face->IsPlanar()) { face->Normal(0, 0, normal); face->PointOn(0, 0, point); } else { MbAxis3D axis; face->GetCylinderAxis(axis); point = axis.GetOrigin(); normal = axis.GetAxisZ(); if (props.normal.has_value()) { if (std::abs(normal.x) > props.eps && (normal.x > 0 != (*props.normal).x > 0)) { normal = -normal; if (props.normalWasReversed != nullptr) { *props.normalWasReversed = true; } } else if (std::abs(normal.x) > props.eps && (normal.y > 0 != (*props.normal).y > 0)) { normal = -normal; if (props.normalWasReversed != nullptr) { *props.normalWasReversed = true; } } else if (std::abs(normal.x) > props.eps && (normal.z > 0 != (*props.normal).z > 0)) { normal = -normal; if (props.normalWasReversed != nullptr) { *props.normalWasReversed = true; } } } } if (props.x.has_value() && std::abs(point.x - *props.x) > props.eps) { continue; } if (props.y.has_value() && std::abs(point.y - *props.y) > props.eps) { continue; } if (props.z.has_value() && std::abs(point.z - *props.z) > props.eps) { continue; } if (props.normal.has_value() && !(*props.normal).IsSame(normal, props.eps)) { continue; } return 1 + vertices.size() + edges.size() + faceI; } } return -1; }