/
Team8
/
kittycad
Обзор
Документация
Войти
/
Team8
/
kittycad
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/graphics/dimensions.cpp
91 строка
2 KB
levovix
add: drawing linear dimensions for parameters
11 янв 2026, 03:08
11 янв 2026, 03:08
c09faff
Код
Авторство
О чём код?
#include "./dimensions.h" #include "mb_axis3d.h" #include <QPainter> #include <QPainterPath> #include <QVector2D> #include <QApplication> #include "data/c3dobject.h" #include "gui/strings.h" void drawArrow( data::DrawContext& ctx, Point3 point, Vec3 direction, Vec3 normal ) { auto p0 = ctx.point_worldToQScreen(point); auto p1 = ctx.point_worldToQScreen(point - Vec3(direction).Rotate(MbAxis3D(normal), M_PI/8)); auto p2 = ctx.point_worldToQScreen(point - Vec3(direction).Rotate(MbAxis3D(normal), -M_PI/8)); QPainterPath path(p0); path.lineTo(p1); path.lineTo(p2); ctx.p->fillPath(path, ctx.p->brush()); } void drawArrowEnds( data::DrawContext& ctx, Point3 startPoint, Point3 endPoint, bool inner, Vec3 normal, double size ) { drawArrow(ctx, startPoint, (inner ? endPoint - startPoint : startPoint - endPoint).GetNormalized() * size, normal); drawArrow(ctx, endPoint, (inner ? startPoint - endPoint : endPoint - startPoint).GetNormalized() * size, normal); } void drawLinearDim( data::DrawContext& ctx, Point3 startPoint, Point3 endPoint, Vec3 axis, Vec3 offset, std::string_view text_std, double arrowSize ) { ctx.p->setPen(QPen(QBrush("#EB7964"), 1)); ctx.p->setBrush(QBrush("#EB7964")); auto text = toQString(text_std); ctx.p->drawLine( ctx.point_worldToQScreen(startPoint), ctx.point_worldToQScreen(startPoint + offset) ); auto dimline = projectToAxis(endPoint - startPoint, axis); ctx.p->drawLine( ctx.point_worldToQScreen(startPoint + offset), ctx.point_worldToQScreen(startPoint + offset + dimline) ); auto endOffset = -projectToAxis(endPoint - (startPoint + offset), offset); ctx.p->drawLine( ctx.point_worldToQScreen(endPoint), ctx.point_worldToQScreen(endPoint + endOffset) ); ctx.p->drawLine( ctx.point_worldToQScreen(endPoint + endOffset), ctx.point_worldToQScreen(startPoint + offset + dimline) ); auto dimline_p1 = startPoint + offset; auto dimline_p2 = startPoint + offset + dimline; drawArrowEnds(ctx, dimline_p1, dimline_p2, false, crossProduct(offset, dimline), arrowSize); auto textBlockSize = QFontMetrics{QApplication::font()}.boundingRect(text); auto textCoord = ctx.point_worldToQScreen(dimline_p1 + (dimline_p2 - dimline_p1) / 2); ctx.p->translate(textCoord); ctx.p->drawText(-textBlockSize.width() / 2., -4, text); ctx.p->translate(-textCoord); }