Fri, 11 Mar 2022 20:19:26 +0200
add grid actions
/* * LDForge: LDraw parts authoring CAD * Copyright (C) 2013 - 2020 Teemu Piippo * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "modeleditor.h" #include "linetypes/triangle.h" #include "linetypes/quadrilateral.h" ModelEditor::ModelEditor(Model& model) : storedModel{model} { } ModelEditor::~ModelEditor() { for (ldraw::id_t id : this->modifiedObjects) { const QModelIndex index = this->model().find(id); if (index.isValid()) { Q_EMIT this->objectModified(index.row()); } } } ldraw::id_t ModelEditor::append(std::unique_ptr<ldraw::Object>&& object) { this->storedModel.append(std::move(object)); Q_EMIT this->objectAdded(this->model().size() - 1); return object->id; } void ModelEditor::remove(int position) { this->storedModel.remove(position); } auto ModelEditor::setObjectProperty( const ldraw::id_t id, const ldraw::Property property, const QVariant& value) -> ldraw::Object::SetPropertyResult { ldraw::Object* const object = this->storedModel.findObjectById(id); if (object != nullptr) { const ldraw::Object::SetPropertyResult result = object->setProperty(ldraw::PropertyKeyValue{property, value}); modifiedObjects.insert(id); return result; } else { return ldraw::Object::SetPropertyResult::PropertyNotHandled; } } void ModelEditor::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value) { ldraw::Object* object = this->storedModel.findObjectById(id); if (object != nullptr) { object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)}); modifiedObjects.insert(id); } } const Model &ModelEditor::model() { return this->storedModel; }