-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservices.h
283 lines (238 loc) · 7.26 KB
/
services.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
Copyright 2009-2012, Romain Behar <[email protected]>
This file is part of Shrimp 2.
Shrimp 2 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.
Shrimp 2 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 Shrimp 2. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _services_h_
#define _services_h_
#include "shading/preferences.h"
#include "shading/scene.h"
#include "shading/shrimp_public_structures.h"
#include "interfaces/i_system_functions.h"
// Service class used to access all Shrimp functions (used to separate the GUI from the core)
class services
{
i_system_functions* m_system_functions;
general_options& preferences;
void build_xml_documentation();
void build_xml_documentation_block(
const block_tree_node_t& tree_node,
std::string& index,
std::string& content);
public:
// constructor/destructor
services(
i_system_functions* SystemFunctions,
general_options& prefs,
const std::string& block_path);
~services();
i_system_functions* system_function_instance();
// reset to a new scene
void reset_scene();
// load and save scene
bool load(const std::string& Scene)
{
bool result = m_scene->load(Scene);
if (result)
{
m_scene_file = Scene;
}
return result;
}
bool save()
{
if (m_scene_file != "")
{ /* use current scene file */
m_scene->save_as(m_scene_file);
return true;
}
else
{
return false;
}
}
void save_as(const std::string& ShaderFile)
{
m_scene_file = ShaderFile;
m_scene->save_as(ShaderFile);
}
std::string get_scene_name() const
{
return m_scene->name();
}
void set_scene_name(const std::string& Name)
{
m_scene->set_name(Name);
}
std::string get_scene_description() const
{
return m_scene->description();
}
void set_scene_description(const std::string& Description)
{
m_scene->set_description(Description);
}
std::string get_scene_authors() const
{
return m_scene->authors();
}
void set_scene_authors(const std::string& Authors)
{
m_scene->set_authors(Authors);
}
// return block hierarchy
block_tree_node_t get_block_hierarchy();
shrimp::shader_blocks_t get_scene_blocks()
{
return m_scene->get_scene_blocks();
}
std::string get_unique_block_name(const std::string& Name) const
{
return m_scene->get_unique_block_name(Name);
}
shader_block* get_block(const std::string& Name)
{
return m_scene->get_block(Name);
}
void set_block_name(shader_block* Block, const std::string& NewName)
{
m_scene->set_block_name(Block, NewName);
}
void delete_block(const std::string& BlockName)
{
m_scene->delete_block(BlockName);
}
shader_block* add_custom_block(
const std::string& Name = "New block",
const bool RootBlock = false)
{
return m_scene->add_custom_block(Name, RootBlock);
}
shrimp::dag_t get_scene_dag()
{
return m_scene->m_dag;
}
shader_block* get_parent(
const std::string& BlockName,
const std::string& Input,
std::string& ParentOutput) const
{
return m_scene->get_parent(BlockName, Input, ParentOutput);
}
//////////// Actions
shader_block* add_predefined_block(const std::string& BlockName)
{
return m_scene->add_predefined_block(BlockName);
}
void connect(const shrimp::io_t& Input, const shrimp::io_t& Output)
{
m_scene->connect(Input, Output);
}
void disconnect(const shrimp::io_t& IO)
{
m_scene->disconnect(IO);
}
std::string show_code()
{
return m_scene->get_shader_code();
}
void show_preview(const std::string& TempDir)
{
m_scene->show_preview(TempDir);
}
void export_scene(const std::string& Directory)
{
m_scene->export_scene(Directory);
}
//////////// Selection
shrimp::shader_blocks_t get_selected_blocks()
{
return m_block_selection;
}
// returns whether a block is selected
bool is_selected(shader_block* Block);
// returns the size of the selection set
int selection_size();
// clear current selection
void clear_selection();
// toggle block selection state
void set_block_selection(shader_block* Block, const bool Selection);
// block roll
void set_block_rolled_state(shader_block* Block, const bool Rolled);
bool is_rolled(const shader_block* Block) const
{
return m_scene->is_rolled(Block);
}
/////////// Group handling
shrimp::group_set_t group_list()
{
return m_scene->group_list();
}
shrimp::group_set_t get_selected_groups();
void group_selection();
void add_to_group(const std::string& Block, const int Group)
{
m_scene->add_to_group(Block, Group);
}
int get_block_group(const shader_block* Block)
{
return m_scene->get_block_group(Block);
}
void ungroup(const int Group)
{
m_scene->ungroup(Group);
}
const std::string get_group_name(const int Group) const
{
return m_scene->get_group_name(Group);
}
void set_group_name(const int Group, const std::string& Name)
{
m_scene->set_group_name(Group, Name);
}
shrimp::shader_blocks_t get_group_blocks(const int Group)
{
return m_scene->get_group_blocks(Group);
}
void set_group_selection(const int Group, const bool Selection);
bool is_group_selected(const int Group);
int group_selection_size();
////////// Copy/Delete functions
// clear copy/paste buffer
void clear_copy_selection();
void copy_blocks(const std::string& Name, const int Group);
void copy_selected_blocks(shader_block* block);
void copy_selected_groups();
void paste_buffered_blocks();
void paste(shader_block* active_block);
void cut_selection(shader_block* active_block);
void delete_selection();
private:
// paste block
void paste_blocks();
// copy connections of copy/paste operation
void copy_connections();
// currently edited scene and its file name
scene* m_scene;
std::string m_scene_file;
// selection
shrimp::shader_blocks_t m_block_selection;
shrimp::group_set_t m_group_selection;
// copy buffers
typedef std::pair<std::string, shader_block*> copy_block_t;
// first copy_block: original block, second copy_block: new block
typedef std::map<copy_block_t, copy_block_t> shader_blocks_copy_t;
shader_blocks_copy_t m_copy_buffer;
shader_blocks_copy_t m_copy_selection;
shrimp::groups_t m_groups_buffer;
};
#endif // _services_h_