/
Team8
/
kittycad
Обзор
Документация
Войти
/
Team8
/
kittycad
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/gui/tools/assembly/solid_clone.cpp
215 строк
5 KB
levovix
fix;
10 янв 2026, 21:53
10 янв 2026, 21:53
eb2e123
Код
Авторство
О чём код?
#include "./solid_clone.h" #include <QVBoxLayout> #include <QLabel> #include <QPushButton> #include <QFormLayout> #include "data/assembly/assembly.h" #include "data/document.h" #include "data/assembly/solid_clone.h" #include "data/sketch/sketch.h" #include "gui/document_view.h" #include "gui/edits/point3_edit.h" #include "gui/edits/scene_segment_select.h" SolidCloneToolPanel::SolidCloneToolPanel(SolidCloneTool* tool, QWidget* parent): ToolPanel(parent), m_tool(tool) { initUi(); } SolidCloneToolPanel::~SolidCloneToolPanel() {} void SolidCloneToolPanel::initUi() { auto layout = ToolPanel::newFormLayout(this); auto jig = m_tool->m_jig.lock(); m_solid_select = new SceneSegmentSelect(m_tool->m_docView->m_sceneTracer, m_tool->m_docView, this); m_position = new Point3Edit(this); m_rotation = new Point3Edit(this); m_scale = new Point3Edit(this); if (m_tool->m_activatedFromModelTree) { layout->addRow(newObjectNameEdit(m_tool->m_jig.lock().get())); } m_solid_select->filter = [this](VSN::SceneSegment* segment) -> bool { return segment == nullptr || segment != m_tool->m_jig.lock()->visual; }; { auto edit = m_solid_select; layout->addRow(tr("Target solid:"), edit); if (jig->targetSolid != nullptr) { edit->setValue(jig->targetSolid->visual); } connect( edit, &SceneSegmentSelect::valueChanged, this, [this, edit](VSN::SceneSegment* const& v) { auto jig = m_tool->m_jig.lock(); jig->targetSolid = edit->associatedObject().expired() ? nullptr : std::dynamic_pointer_cast<data::Solid>(edit->associatedObject().lock()); jig->markDependencyChanged(jig->targetSolid); } ); } #if 0 // todo m_origin = new Point3Edit(this); { auto edit = m_origin; layout->addRow(tr("Origin:"), edit); edit->setDocView(m_tool->m_docView); edit->setPoint(Point3(jig->origin.x, jig->origin.y, jig->origin.z)); connect(edit, &Point3Edit::pointChanged, this, [this, edit](Point3 v) { auto jig = m_tool->m_jig.lock(); jig->origin = v; jig->markPropertyChanged(); }); } #endif { auto edit = m_position; layout->addRow(tr("Position:"), edit); edit->setDocView(m_tool->m_docView); edit->setPoint(Point3(jig->position.x, jig->position.y, jig->position.z)); connect(edit, &Point3Edit::pointChanged, this, [this, edit](Point3 v) { auto jig = m_tool->m_jig.lock(); jig->position = v; jig->markPropertyChanged(); }); } { auto edit = m_rotation; layout->addRow(tr("Rotation (in degrees):"), edit); edit->setDocView(m_tool->m_docView); edit->setPoint(Point3(jig->rotation.x, jig->rotation.y, jig->rotation.z) * ((double)180 / M_PI)); connect(edit, &Point3Edit::pointChanged, this, [this, edit](Point3 v) { auto jig = m_tool->m_jig.lock(); jig->rotation = v * (M_PI / (double)180); jig->markPropertyChanged(); }); } { auto edit = m_scale; layout->addRow(tr("Scale:"), edit); edit->setDocView(m_tool->m_docView); edit->setPoint(Point3(jig->scale.x, jig->scale.y, jig->scale.z)); connect(edit, &Point3Edit::pointChanged, this, [this, edit](Point3 v) { auto jig = m_tool->m_jig.lock(); jig->scale = v; jig->markPropertyChanged(); }); } connect(m_solid_select, &SceneSegmentSelect::interactiveEntryAccepted, this, [this]() { auto jig = m_tool->m_jig.lock(); m_solid_select->setInteractiveEntry(false); }, Qt::QueuedConnection); connect(m_origin, &Point3Edit::interactiveEntryAccepted, this, [this]() { m_origin->setInteractiveEntry(false); }, Qt::QueuedConnection); connect(m_position, &Point3Edit::interactiveEntryAccepted, this, [this]() { m_position->setInteractiveEntry(false); }, Qt::QueuedConnection); connect(m_rotation, &Point3Edit::interactiveEntryAccepted, this, [this]() { m_rotation->setInteractiveEntry(false); }, Qt::QueuedConnection); connect(m_scale, &Point3Edit::interactiveEntryAccepted, this, [this]() { m_scale->setInteractiveEntry(false); }, Qt::QueuedConnection); if (!m_tool->m_activatedFromModelTree) { m_solid_select->setInteractiveEntry(true); } if (!m_tool->m_activatedFromModelTree) { layout->addRow(newStandardButtons(m_tool)); } } SolidCloneTool::SolidCloneTool(QWidget* parent) : Tool(parent) {} SolidCloneTool::~SolidCloneTool() {} void SolidCloneTool::activated(DocumentView *docView) { m_docView = docView; start(); assert(m_panel == nullptr); m_panel = new SolidCloneToolPanel(this, (QWidget*)parent()); ((QWidget*)parent())->layout()->addWidget(m_panel); } void SolidCloneTool::deactivated() { if (m_panel != nullptr) { delete m_panel; m_panel = nullptr; } Tool::deactivated(); } void SolidCloneTool::createJig() { auto jig = create<data::SolidClone>(m_docView->document()); m_jig = m_jigRef = jig; } void SolidCloneTool::deteachFromJig() { if (!m_jig.expired()) { if (m_jig.lock()->tool == this) { m_jig.lock()->tool = nullptr; } } m_jig.reset(); m_jigRef.reset(); } void SolidCloneTool::start() { if (m_jig.expired()) { createJig(); } } void SolidCloneTool::finish() { if (m_jigRef != nullptr && m_jigRef->targetSolid != nullptr) { auto assembly = m_docView->document()->getOrCreateActiveAssembly(); assembly->addChild(m_jigRef); m_jigRef->targetSolid->usedBy.push_back(m_jigRef); } deactivated(); }