src/documentmanager.h

Thu, 09 Jun 2022 11:51:42 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Jun 2022 11:51:42 +0300
changeset 209
c93e4a1eaadb
parent 193
b4beff48bb7a
child 212
27259810da6d
permissions
-rw-r--r--

remove more dead code

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2020 Teemu Piippo
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include "libraries.h"
#include "model.h"
#include "polygoncache.h"

class DocumentManager : public QObject
{
	Q_OBJECT
public:
	enum OpenType
	{
		/**
		  * Document was opened manually by the user
		  */
		ManuallyOpened,
		/**
		  * Document was opened automatically in order to resolve subfile references
		  */
		AutomaticallyOpened,
	};
    DocumentManager(QObject* parent = nullptr);
	ModelId newModel();
	Model* findDependencyByName(const ModelId modelId, const QString& name);
	Model* getModelById(ModelId modelId);
	std::optional<ModelId> openModel(const QString& path, QTextStream& errorStream, const OpenType openType);
	QString makeNewModelName();
	void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream);
	void loadDependenciesForModel(const ModelId modelId,
		const QString& path,
		const LibraryManager& libraries,
		QTextStream& errorStream);
	void closeDocument(const ModelId modelId);
	const QString* modelPath(ModelId modelId) const;
	void setModelPath(
			const ModelId modelId,
			const QString& newPath,
			const LibraryManager &libraries,
			QTextStream &errorStream);
	bool saveModel(const ModelId modelId, QTextStream& errors);
	std::optional<ModelId> findIdForModel(const Model* model) const;
	PolygonCache* getPolygonCacheForModel(ModelId modelId);
private:
	struct ModelInfo
	{
		std::unique_ptr<Model> model;
		ModelId id;
		QString path;
		OpenType opentype;
		std::map<QString, ModelId> dependencies = {};
	};
	struct LoadDepedenciesBag;
	int modelIdCounter = 0;
	int untitledNameCounter = 0;
	std::map<ModelId, ModelInfo> openModels;
	std::map<ModelId, PolygonCache> polygonCaches;
	void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag);
	void collectReferences(QSet<QString> &referenced, const QString& name, const Model* model);
	void updateDependencies(ModelInfo* model);
	void prune();
	Q_SLOT void modelModified();
	bool isReferencedByAnything(const ModelId modelId) const;
	void makePolygonCacheForModel(const ModelId modelId);
};

QString pathToName(const QFileInfo& path);

mercurial