1 /*
2  *    Copyright 2013 Thomas Schöps
3  *    Copyright 2015 Kai Pastor
4  *
5  *    This file is part of OpenOrienteering.
6  *
7  *    OpenOrienteering is free software: you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation, either version 3 of the License, or
10  *    (at your option) any later version.
11  *
12  *    OpenOrienteering is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef OPENORIENTEERING_TOOL_DISTRIBUTE_POINTS_H
23 #define OPENORIENTEERING_TOOL_DISTRIBUTE_POINTS_H
24 
25 #include <vector>
26 
27 #include <QDialog>
28 #include <QObject>
29 #include <QString>
30 
31 class QDoubleSpinBox;
32 class QCheckBox;
33 class QSpinBox;
34 class QWidget;
35 
36 namespace OpenOrienteering {
37 
38 class PathObject;
39 class PointObject;
40 class PointSymbol;
41 
42 
43 /**
44  * Provides methods to create evenly spaced point objects along a line.
45  *
46  * \todo Integrate implementation of MapEditorController::distributePointsClicked().
47  */
48 class DistributePointsTool
49 {
50 public:
51 	/** Required user input for applying the action. */
52 	struct Settings
53 	{
54 		/** Number of points to create */
55 		int num_points_per_line;
56 
57 		/** If true, points will also be placed at open paths ends,
58 		 *  otherwise only inside for open paths*/
59 		bool points_at_ends;
60 
61 		/** If true, points will be aligned with the path direction if rotatable */
62 		bool rotate_symbols;
63 
64 		/** Additional rotation for rotatable point symbols,
65 		 *  in radians counter-clockwise */
66 		double additional_rotation;
67 
68 		/** Constructor, sets default values. */
SettingsSettings69 		constexpr Settings()
70 		 : num_points_per_line{ 3 }
71 		 , points_at_ends{ true }
72 		 , rotate_symbols{ true }
73 		 , additional_rotation{ 0.0 }
74 		{
75 			// Nothing else
76 		}
77 	};
78 
79 	/**
80 	 * Shows a settings dialog for the tool.
81 	 *
82 	 * If the user presses Ok, returns true and saves the chosen values to
83 	 * settings, otherwise returns false.
84 	 *
85 	 * The settings parameter is also used as initial values for the dialog.
86 	 * The point symbol is used to determine the enabled state of some options.
87 	 */
88 	static bool showSettingsDialog(
89 	        QWidget* parent,
90 	        const PointSymbol* point,
91 	        DistributePointsTool::Settings& settings
92 	);
93 
94 	/**
95 	 * Executes the tool on the path, creating points according to settings.
96 	 *
97 	 * Appends the created objects to the out_objects vector, but does not add
98 	 * them to the map.
99 	 */
100 	static void execute(
101 	        const PathObject* path,
102 	        PointSymbol* point,
103 	        const DistributePointsTool::Settings& settings,
104 	        std::vector<PointObject*>& out_objects
105 	);
106 };
107 
108 
109 
110 /**
111  * Settings dialog for DistributePointsTool
112  */
113 class DistributePointsSettingsDialog : public QDialog
114 {
115 Q_OBJECT
116 public:
117 	/** Creates a new DistributePointsSettingsDialog. */
118 	DistributePointsSettingsDialog(
119 	        QWidget* parent,
120 	        const PointSymbol* point,
121 	        const DistributePointsTool::Settings& settings
122 	);
123 
124 	/** After the dialog finished successfully, returns the entered values. */
125 	void getValues(DistributePointsTool::Settings& settings);
126 
127 private:
128 	QSpinBox* num_points_edit;
129 	QCheckBox* points_at_ends_check;
130 
131 	QCheckBox* rotate_symbols_check;
132 	QDoubleSpinBox* additional_rotation_edit;
133 };
134 
135 
136 }  // namespace OpenOrienteering
137 #endif
138