/
Team8
/
kittycad
Обзор
Документация
Войти
/
Team8
/
kittycad
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/data/solids/thread.cpp
166 строк
4 KB
levovix
progress: FlangeCoupling template - full assembly
10 янв 2026, 05:49
10 янв 2026, 05:49
166f225
Код
Авторство
О чём код?
#include "./thread.h" #include <cur_line_segment.h> #include <action_curve.h> #include <action_curve3d.h> #include <action_solid.h> #include <surf_plane.h> #include <QPainterPath> #include <QPainter> #include "graphics/drawable.h" struct DrawableThread : public Drawable { DrawableThread(data::Thread* self) : self(self) {} data::Thread* self; void draw(data::DrawContext& ctx) override; ref<Drawable> clone() override; }; data::Thread::Thread() {} data::Thread::~Thread() {} void data::Thread::buildSolid() { assert(m_propertyChanged || m_dependencyChanged); solid = nullptr; spiralSolid = nullptr; m_propertyChanged = false; m_dependencyChanged = false; markVisualChanged(); if (targetSolid == nullptr || targetSolid->solid == nullptr) { return; } if (drawables.size() == 0) { drawables.push_back(ref(new DrawableThread{this})); } // todo: обрезка targetSolid при isHole==false // todo: параметры резьбы по ГОСТ double D = diameter * 1.1; double d = diameter * 0.95; // если поставить 1 - зависает намертво double P = (D - d); EvolutionValues values; auto names = MbSNameMaker(ct_ElementarySolid, MbSNameMaker::i_SideNone, 0); auto cNames = PArray<MbSNameMaker>(0, 1, false); MbCurve3D* spiral{}; MbLineSegment spiralLaw{Point2{0, d/2}, {length - P, d/2}}; SpiralCurve( MbPlacement3D{origin + axis * P/2, axis}, d/2, P*1.5, spiralLaw, false, spiral ); if (simple) { solid = targetSolid->solid; spiralWireframePoints.clear(); int steps = 1000; for (int i = 0; i < steps; ++i) { double param = spiral->GetTMin() + ((double)i / steps) * spiral->GetParamLength(); Point3 p = spiral->PointOn(param); spiralWireframePoints.push_back(p); } } else { spiralCurve = nullptr; std::array profilePoints = { Point2{d/2, -P/2}, Point2{D/2, 0}, Point2{d/2, P/2}, }; std::vector<SPtr<MbContour>> profileContours = { SPtr(new MbContour(std::vector<SPtr<MbCurve>>{ SPtr(new MbLineSegment{profilePoints[0], profilePoints[1]}), SPtr(new MbLineSegment{profilePoints[1], profilePoints[2]}), SPtr(new MbLineSegment{profilePoints[2], profilePoints[0]}), }, false)), }; auto yAxis = MbPlacement3D(Point3{}, axis).GetAxisY(); auto plane = c3d::SurfaceSPtr(new MbPlane(MbPlacement3D{ yAxis, axis, origin + axis * P/2, })); MbSweptData x; auto sweptData = MbSweptData(*plane, profileContours); MbEvolutionShellParams params{ sweptData, *spiral, values, names, cNames, names, }; if (EvolutionShell(params, spiralSolid) != rt_Success) { solid = nullptr; spiralSolid = nullptr; return; } MbBooleanOperationParams booleanParams{bo_Union, true, names}; if (auto code = ::BooleanResult( targetSolid->solid, cm_Copy, spiralSolid, cm_Copy, booleanParams, solid ); code != rt_Success) { solid = spiralSolid; return; } } // todo: рисовать резьбу вручную через полигоны, если она условная } std::string_view data::Thread::iconName() const { return "tool_thread"; } inline void DrawableThread::draw(data::DrawContext& ctx) { if (self->simple && self->spiralWireframePoints.size() != 0) { ctx.p->setPen(QPen(QBrush("#c2e571"), 1)); ctx.p->setBrush(Qt::NoBrush); auto startP = self->spiralWireframePoints[0]; startP.Transform(transform); QPainterPath path(ctx.point_worldToQScreen(startP)); for (int i = 1; i < self->spiralWireframePoints.size(); ++i) { auto p = self->spiralWireframePoints[i]; p.Transform(transform); path.lineTo(ctx.point_worldToQScreen(p)); } ctx.p->drawPath(path); } } ref<Drawable> DrawableThread::clone() { auto v = new DrawableThread(self); v->transform = transform; return ref(v); }