1 /** \file
2  * \brief ScalingLayout scales and calls a secondary layout
3  *
4  * \author Gereon Bartel
5  *
6  * \par License:
7  * This file is part of the Open Graph Drawing Framework (OGDF).
8  *
9  * \par
10  * Copyright (C)<br>
11  * See README.md in the OGDF root directory for details.
12  *
13  * \par
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * Version 2 or 3 as published by the Free Software Foundation;
17  * see the file LICENSE.txt included in the packaging of this file
18  * for details.
19  *
20  * \par
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * \par
27  * You should have received a copy of the GNU General Public
28  * License along with this program; if not, see
29  * http://www.gnu.org/copyleft/gpl.html
30  */
31 
32 #pragma once
33 
34 #include <memory>
35 #include <ogdf/energybased/multilevel_mixer/MultilevelLayoutModule.h>
36 #include <ogdf/energybased/multilevel_mixer/ModularMultilevelMixer.h>
37 #include <ogdf/energybased/multilevel_mixer/MultilevelGraph.h>
38 
39 namespace ogdf {
40 
41 //! Scales a graph layout and calls a secondary layout algorithm.
42 /**
43  * @ingroup gd-multi
44  * For use with ModularMultilevelMixer.
45  */
46 class OGDF_EXPORT ScalingLayout : public MultilevelLayoutModule
47 {
48 public:
49 	/*!
50 	 * \brief To define the relative scale used for a Graph, the ScalingType is applied.
51 	 */
52 	enum class ScalingType {
53 		//! Scales by a factor relative to the drawing.
54 		RelativeToDrawing,
55 		/*!
56 		 * Scales by a factor relative to the avg edge weights
57 		 * to be used in combination with the fixed edge length
58 		 * setting in ModularMultilevelMixer.
59 		 */
60 		RelativeToAvgLength,
61 		//! Scales by a factor relative to the desired Edgelength m_desEdgeLength.
62 		RelativeToDesiredLength,
63 		//! Absolute factor, can be used to scale relative to level size change.
64 		Absolute
65 	};
66 
67 	ScalingLayout();
68 
69 	using MultilevelLayoutModule::call;
70 
71 	/**
72 	 * \brief Computes a layout of graph \p GA.
73 	 *
74 	 * @param GA is the input graph and will also be assigned the layout information.
75 	 */
76 	virtual void call(GraphAttributes &GA) override;
77 
78 	/**
79 	 * \brief Computes a layout of graph \p MLG.
80 	 *
81 	 * @param MLG is the input graph and will also be assigned the layout information.
82 	 */
83 	virtual void call(MultilevelGraph &MLG) override;
84 
85 	/*!
86 	 * \brief Sets the minimum and the maximum scaling factor.
87 	 *
88 	 * @param min sets the minimum
89 	 * @param max sets the maximum
90 	 */
91 	void setScaling(double min, double max);
92 
93 	/*!
94 	 * \brief Sets how often the scaling should be repeated.
95 	 *
96 	 * @param steps is the number of repeats
97 	 */
98 	void setExtraScalingSteps(unsigned int steps);
99 
100 	/*!
101 	 * \brief Sets a LayoutModule that should be applied after scaling.
102 	 *
103 	 * @param layout is the secondary LayoutModule
104 	 */
105 	void setSecondaryLayout(LayoutModule* layout);
106 
107 	/*!
108 	 * \brief Is used to compute the scaling relatively to the level size change when ScalingType st_absolute is used.
109 	 *
110 	 * @param mmm is the ModularMultilevelMixer
111 	 */
112 	void setMMM(ModularMultilevelMixer* mmm);
113 
114 	/*!
115 	 * \brief Sets a ScalingType wich sets the relative scale for the Graph
116 	 *
117 	 * @param type is the ScalingType
118 	 */
119 	void setScalingType(ScalingType type);
120 
121 	/*!
122 	 * \brief Sets how often the LayoutModule should be applied.
123 	 *
124 	 * @param repeats is the number of repeats
125 	 */
126 	void setLayoutRepeats(unsigned int repeats);
127 	//TODO: only a workaround, this should be retrieved from the layout module
128 	//when we have a interface class on top of Layoutmodule that allows this
129 	void setDesiredEdgeLength(double eLength);
130 
131 private:
132 
133 	// Usually a simple force-directed / energy-based Layout should be chosen.
134 	std::unique_ptr<LayoutModule> m_secondaryLayoutModule;
135 
136 	double m_minScaling;
137 	double m_maxScaling;
138 	ModularMultilevelMixer* m_mmm;//!< Used to derive level size ratio if st_absolute
139 	double m_desEdgeLength;
140 
141 	// 0 = scale to maxScaling only
142 	unsigned int m_extraScalingSteps;
143 
144 	unsigned int m_layoutRepeats;
145 
146 	ScalingType m_scalingType;
147 };
148 
149 }
150