Tue, 15 Mar 2022 18:56:02 +0200
Add missing svg icon
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 | ||
3 | 19 | #pragma once |
12 | 20 | #include "libraries.h" |
3 | 21 | #include "model.h" |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
22 | #include "polygoncache.h" |
3 | 23 | |
5 | 24 | class DocumentManager : public QObject |
3 | 25 | { |
5 | 26 | Q_OBJECT |
3 | 27 | public: |
147 | 28 | enum OpenType |
29 | { | |
148 | 30 | /** |
31 | * Document was opened manually by the user | |
32 | */ | |
147 | 33 | ManuallyOpened, |
148 | 34 | /** |
35 | * Document was opened automatically in order to resolve subfile references | |
36 | */ | |
147 | 37 | AutomaticallyOpened, |
38 | }; | |
21 | 39 | DocumentManager(QObject* parent = nullptr); |
148 | 40 | ModelId newModel(); |
41 | Model* findDependencyByName(const ModelId modelId, const QString& name); | |
42 | Model* getModelById(ModelId modelId); | |
43 | std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
5
diff
changeset
|
44 | QString makeNewModelName(); |
148 | 45 | void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream); |
46 | void loadDependenciesForModel(const ModelId modelId, | |
23
3387a84ddaba
fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
47 | const QString& path, |
12 | 48 | const LibraryManager& libraries, |
49 | QTextStream& errorStream); | |
148 | 50 | void closeDocument(const ModelId modelId); |
51 | const QString* modelPath(ModelId modelId) const; | |
52 | void setModelPath( | |
53 | const ModelId modelId, | |
54 | const QString& newPath, | |
55 | const LibraryManager &libraries, | |
56 | QTextStream &errorStream); | |
57 | bool saveModel(const ModelId modelId, QTextStream& errors); | |
58 | 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
|
59 | PolygonCache* getPolygonCacheForModel(ModelId modelId); |
3 | 60 | private: |
147 | 61 | struct ModelInfo |
62 | { | |
63 | std::unique_ptr<Model> model; | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
64 | ModelId id; |
148 | 65 | QString path; |
147 | 66 | OpenType opentype; |
148 | 67 | std::map<QString, ModelId> dependencies = {}; |
147 | 68 | }; |
148 | 69 | struct LoadDepedenciesBag; |
70 | int modelIdCounter = 0; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
5
diff
changeset
|
71 | int untitledNameCounter = 0; |
148 | 72 | std::map<ModelId, ModelInfo> openModels; |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
73 | std::map<ModelId, PolygonCache> polygonCaches; |
148 | 74 | void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag); |
75 | void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model); | |
76 | void updateDependencies(ModelInfo* model); | |
77 | void prune(); | |
78 | bool isReferencedByAnything(const ModelId modelId) const; | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
148
diff
changeset
|
79 | void makePolygonCacheForModel(const ModelId modelId); |
3 | 80 | }; |
147 | 81 | |
82 | QString pathToName(const QFileInfo& path); |