Wed, 25 May 2022 17:56:30 +0300
delete unneeded things
24 | 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 | ||
153
2f79053c2e9a
Renamed modeleditcontext.cpp -> modeleditor.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
152
diff
changeset
|
19 | #include "modeleditor.h" |
89 | 20 | #include "linetypes/triangle.h" |
21 | #include "linetypes/quadrilateral.h" | |
3 | 22 | |
152 | 23 | ModelEditor::ModelEditor(Model& model) : |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
24 | storedModel{model} |
3 | 25 | { |
26 | } | |
27 | ||
152 | 28 | ModelEditor::~ModelEditor() |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
29 | { |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
30 | for (ldraw::id_t id : this->modifiedObjects) |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
31 | { |
152 | 32 | const QModelIndex index = this->model().find(id); |
33 | if (index.isValid()) | |
34 | { | |
35 | Q_EMIT this->objectModified(index.row()); | |
36 | } | |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
37 | } |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
38 | } |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
39 | |
152 | 40 | ldraw::id_t ModelEditor::append(std::unique_ptr<ldraw::Object>&& object) |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
41 | { |
152 | 42 | this->storedModel.append(std::move(object)); |
43 | Q_EMIT this->objectAdded(this->model().size() - 1); | |
44 | return object->id; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
45 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
46 | |
152 | 47 | void ModelEditor::remove(int position) |
76
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
48 | { |
152 | 49 | this->storedModel.remove(position); |
76
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
50 | } |
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
51 | |
152 | 52 | auto ModelEditor::setObjectProperty( |
89 | 53 | const ldraw::id_t id, |
54 | const ldraw::Property property, | |
55 | const QVariant& value) | |
56 | -> ldraw::Object::SetPropertyResult | |
57 | { | |
152 | 58 | ldraw::Object* const object = this->storedModel.findObjectById(id); |
89 | 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 | ||
152 | 71 | void ModelEditor::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value) |
3 | 72 | { |
152 | 73 | ldraw::Object* object = this->storedModel.findObjectById(id); |
76
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
74 | if (object != nullptr) |
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
75 | { |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
76 | object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)}); |
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
77
diff
changeset
|
77 | modifiedObjects.insert(id); |
76
7c4a63a02632
finished splitQuadrilateral theoretically (untested)
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
78 | } |
3 | 79 | } |
26 | 80 | |
152 | 81 | const Model &ModelEditor::model() |
73
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
82 | { |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
83 | return this->storedModel; |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
84 | } |
97df974b5ed5
ldraw::Id is now templated for extra type safety
Teemu Piippo <teemu@hecknology.net>
parents:
35
diff
changeset
|
85 |