src/documentmanager.h

Sun, 03 Jul 2022 13:44:11 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 03 Jul 2022 13:44:11 +0300
changeset 319
9727e545b0bc
parent 264
76a025db4948
child 333
07e65a4c6611
permissions
-rw-r--r--

Extract the triangulation and triangle merging code into a new source file and clean it up somewhat

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
18
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
20 #include "src/libraries.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
21 #include "src/model.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
22 #include "src/polygoncache.h"
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
24 enum OpenType
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 {
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
26 //! \brief Document was opened manually by the user
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
27 ManuallyOpened,
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
28 //! \brief Document was opened automatically in order to resolve subfile references
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
29 AutomaticallyOpened,
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
30 };
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
31
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
32 class DocumentManager : public QObject
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
33 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
34 Q_OBJECT
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 public:
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
36 struct ModelInfo
147
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
37 {
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
38 std::unique_ptr<Model> model;
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
39 ModelId id;
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
40 QString path;
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
41 OpenType opentype;
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
42 std::map<QString, ModelId> dependencies = {};
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
43 PolygonCache polygonCache = {};
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
44 QObject* payload;
147
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
45 };
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
46 using MissingDependencies = std::map<QString, QString>;
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
47 DocumentManager(QObject* parent = nullptr);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
48 auto begin() const { return this->openModels.begin(); }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
49 auto end() const { return this->openModels.end(); }
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
50 ModelId newModel();
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
51 Model* findDependencyByName(const ModelId modelId, const QString& name);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
52 Model* getModelById(ModelId modelId);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
53 std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType);
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 214
diff changeset
54 std::map<QString, QString> loadDependenciesForAllModels(const LibrariesModel &libraries);
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
55 void closeDocument(const ModelId modelId);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
56 const QString* modelPath(ModelId modelId) const;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
57 void setModelPath(
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
58 const ModelId modelId,
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
59 const QString& newPath,
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 214
diff changeset
60 const LibrariesModel &libraries,
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
61 QTextStream &errorStream);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
62 bool saveModel(const ModelId modelId, QTextStream& errors);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
63 std::optional<ModelId> findIdForModel(const Model* model) const;
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
64 PolygonCache* getPolygonCacheForModel(ModelId modelId);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
65 const ModelInfo* find(ModelId modelId) const;
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
66 void setModelPayload(ModelId modelId, QObject* object);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
67 template<typename T>
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
68 T* findPayload(ModelId modelId) const
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
69 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
70 const ModelInfo* info = this->find(modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
71 return info ? qobject_cast<T*>(info->payload) : nullptr;
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 213
diff changeset
72 }
235
7ef03c2b46ab Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
73 Q_SIGNALS:
7ef03c2b46ab Add a basic message log
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
74 void message(const Message& message);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 private:
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
76 int modelIdCounter = 0;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
77 std::map<ModelId, ModelInfo> openModels;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
78 void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
79 void updateDependencies(ModelInfo* model);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
80 void prune();
150
b6cbba6e29a1 extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
81 void makePolygonCacheForModel(const ModelId modelId);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 };
147
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
83
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 193
diff changeset
84 QString errorStringFromMissingDependencies(const DocumentManager::MissingDependencies& missing);
147
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
85 QString pathToName(const QFileInfo& path);

mercurial