src/modeleditor.cpp

changeset 200
ca23936b455b
parent 199
6988973515d2
child 201
5d201ee4a9c3
equal deleted inserted replaced
199:6988973515d2 200:ca23936b455b
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 - 2020 Teemu Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "modeleditor.h"
20 #include "linetypes/triangle.h"
21 #include "linetypes/quadrilateral.h"
22
23 ModelEditor::ModelEditor(Model& model) :
24 storedModel{model}
25 {
26 }
27
28 ModelEditor::~ModelEditor()
29 {
30 for (ldraw::id_t id : this->modifiedObjects)
31 {
32 const QModelIndex index = this->model().find(id);
33 if (index.isValid())
34 {
35 Q_EMIT this->objectModified(index.row());
36 }
37 }
38 }
39
40 ldraw::id_t ModelEditor::append(std::unique_ptr<ldraw::Object>&& object)
41 {
42 this->storedModel.append(std::move(object));
43 Q_EMIT this->objectAdded(this->model().size() - 1);
44 return object->id;
45 }
46
47 void ModelEditor::remove(int position)
48 {
49 this->storedModel.remove(position);
50 }
51
52 auto ModelEditor::setObjectProperty(
53 const ldraw::id_t id,
54 const ldraw::Property property,
55 const QVariant& value)
56 -> ldraw::Object::SetPropertyResult
57 {
58 ldraw::Object* const object = this->storedModel.findObjectById(id);
59 if (object != nullptr)
60 {
61 const ldraw::Object::SetPropertyResult result = object->setProperty(ldraw::PropertyKeyValue{property, value});
62 modifiedObjects.insert(id);
63 return result;
64 }
65 else
66 {
67 return ldraw::Object::SetPropertyResult::PropertyNotHandled;
68 }
69 }
70
71 void ModelEditor::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value)
72 {
73 ldraw::Object* object = this->storedModel.findObjectById(id);
74 if (object != nullptr)
75 {
76 object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)});
77 modifiedObjects.insert(id);
78 }
79 }
80
81 const Model &ModelEditor::model()
82 {
83 return this->storedModel;
84 }
85

mercurial