summaryrefslogtreecommitdiff
path: root/src/graphcoloring/levels/paths/path.hpp
blob: 294b1a2939f75902f39b5374165fc8a574c89cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Leo Tenenbaum
// This file is part of GraphColoring.
//
// GraphColoring 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.
//
// GraphColoring 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 GraphColoring.  If not, see <https://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////

#ifndef GRAPHCOLORING_LEVELS_PATHS_PATH_H_
#define GRAPHCOLORING_LEVELS_PATHS_PATH_H_

#include "gui/window.hpp"
#include "graphcoloring/levels/rules/ruleloader.hpp"

namespace graphcoloring {

class Path {
public:
	Path(gui::Window* window,
		Graph& graph, const RuleLoader& rule_loader,
		const ColorLoader& color_loader);
	virtual ~Path() {}
	void LoadFromDocument(const pugi::xml_document& document);
	void ResetPath();
	bool IsPath() const; // Is there a path in the document?
	std::vector<int> GetPath() const;
	std::set<int> PathEdgeSet() const;
	std::set<int> PathVertexSet() const;
	int LastVertex() const; // -1 if no last vertex
	bool IsMakingPath() const;
	int Points() const;
private:
	enum class Type
	{
		NO_PATH, // There is no path in the document.
		CYCLE,
		PATH
	};
	typedef std::function<int(int)> operation_t;
	static constexpr gui::Color ANY_COLOR = 0;
	void LoadFromNode(pugi::xml_node node);
	void RightClick();
	operation_t LoadOperation(pugi::xml_node node);
	gui::Window* window;
	Graph& graph;
	const RuleLoader& rule_loader;
	const ColorLoader& color_loader;
	Type type = Type::NO_PATH;
	bool is_making_path = false;
	int first_vertex = -1;
	int last_vertex = -1;
	std::vector<int> path;
	int points_starting_value = 0;
	std::map<gui::Color, operation_t> color_operations;

};

} // namespace graphcoloring

#endif // GRAPHCOLORING_LEVELS_PATHS_PATH_H_