Tue, 01 Mar 2022 17:00:19 +0200
work on edit history
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" |
22 | ||
5 | 23 | class DocumentManager : public QObject |
3 | 24 | { |
5 | 25 | Q_OBJECT |
3 | 26 | public: |
147 | 27 | enum OpenType |
28 | { | |
148 | 29 | /** |
30 | * Document was opened manually by the user | |
31 | */ | |
147 | 32 | ManuallyOpened, |
148 | 33 | /** |
34 | * Document was opened automatically in order to resolve subfile references | |
35 | */ | |
147 | 36 | AutomaticallyOpened, |
37 | }; | |
21 | 38 | DocumentManager(QObject* parent = nullptr); |
148 | 39 | ModelId newModel(); |
40 | Model* findDependencyByName(const ModelId modelId, const QString& name); | |
41 | Model* getModelById(ModelId modelId); | |
42 | 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
|
43 | QString makeNewModelName(); |
148 | 44 | void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream); |
45 | 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
|
46 | const QString& path, |
12 | 47 | const LibraryManager& libraries, |
48 | QTextStream& errorStream); | |
148 | 49 | void closeDocument(const ModelId modelId); |
50 | const QString* modelPath(ModelId modelId) const; | |
51 | void setModelPath( | |
52 | const ModelId modelId, | |
53 | const QString& newPath, | |
54 | const LibraryManager &libraries, | |
55 | QTextStream &errorStream); | |
56 | bool saveModel(const ModelId modelId, QTextStream& errors); | |
57 | std::optional<ModelId> findIdForModel(const Model* model) const; | |
3 | 58 | private: |
147 | 59 | struct ModelInfo |
60 | { | |
61 | std::unique_ptr<Model> model; | |
148 | 62 | QString path; |
147 | 63 | OpenType opentype; |
148 | 64 | std::map<QString, ModelId> dependencies = {}; |
147 | 65 | }; |
148 | 66 | struct LoadDepedenciesBag; |
67 | int modelIdCounter = 0; | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
5
diff
changeset
|
68 | int untitledNameCounter = 0; |
148 | 69 | std::map<ModelId, ModelInfo> openModels; |
70 | void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag); | |
71 | void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model); | |
72 | void updateDependencies(ModelInfo* model); | |
73 | void prune(); | |
74 | bool isReferencedByAnything(const ModelId modelId) const; | |
3 | 75 | }; |
147 | 76 | |
77 | QString pathToName(const QFileInfo& path); |