SPH
NodePage.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Color.h"
4 #include "gui/objects/Point.h"
7 #include "run/Node.h"
8 #include <map>
9 #include <wx/panel.h>
10 
11 class wxPropertyGrid;
12 class wxPGProperty;
13 class wxGraphicsContext;
14 class wxAuiManager;
15 class wxAuiPaneInfo;
16 
18 
19 class NodeEditor;
20 class RenderPane;
21 class Config;
22 
23 struct VisNode {
26 
27  VisNode() = default;
28 
30  : node(node)
31  , position(position) {}
32 
33  static constexpr Size SIZE_X = 160;
34 
35  Pixel size() const {
36  return Pixel(SIZE_X, max<int>(60 + node->getSlotCnt() * 25, 80));
37  }
38 };
39 
40 struct NodeSlot {
42  Size index = 0;
43 
44  static constexpr Size RESULT_SLOT = -1;
45 
46  Pixel position() const;
47 
48  bool operator==(const NodeSlot& other) const {
49  return vis == other.vis && index == other.index;
50  }
51  bool operator!=(const NodeSlot& other) const {
52  return !(*this == other);
53  }
54 };
55 
57 
59 public:
60  virtual void startRun(SharedPtr<INode> node,
61  const RunSettings& settings,
62  const std::string& name) const = 0;
63 
64  virtual void markUnsaved(bool addToUndo) const = 0;
65 };
66 
67 class NodeManager {
68 private:
69  NodeEditor* editor;
70 
71  BatchManager batch;
72 
73  NodeMap nodes;
74 
75  RunSettings globals = EMPTY_SETTINGS;
76 
78 
79  WeakPtr<JobNode> activeNode;
80 
81 public:
83 
84  VisNode* addNode(const SharedPtr<JobNode>& node);
85 
86  VisNode* addNode(const SharedPtr<JobNode>& node, const Pixel position);
87 
88  void addNodes(JobNode& node);
89 
90  void cloneHierarchy(JobNode& node);
91 
92  void layoutNodes(JobNode& node, const Pixel position);
93 
94  const NodeMap& getNodes() const {
95  return nodes;
96  }
97 
98  void deleteNode(JobNode& node);
99 
100  void deleteTree(JobNode& node);
101 
102  void deleteAll();
103 
105 
107 
108  void save(Config& config);
109 
110  void load(Config& config);
111 
112  void startRun(JobNode& node);
113 
114  void startBatch(JobNode& node);
115 
116  void startScript(const Path& file);
117 
118  void startAll();
119 
121 
123 
124  void showBatchDialog();
125 
126  RenderPane* createRenderPreview(wxWindow* parent, JobNode& node);
127 
128  void selectRun();
129 
131 };
132 
133 class NodeWindow;
134 
135 class NodeEditor : public wxPanel {
136 private:
137  SharedPtr<NodeManager> nodeMgr;
138 
140 
141  NodeWindow* nodeWindow;
142 
143  struct {
145  Pixel offset = Pixel(0, 0);
146 
148  float zoom = 1.f;
149 
151 
153  VisNode* selected = nullptr;
154 
156  VisNode* activated = nullptr;
157 
160 
162 
163  } state;
164 
165 public:
167 
169  nodeMgr = mgr;
170  }
171 
172  Pixel offset() const {
173  return state.offset;
174  }
175 
176  Pixel transform(const Pixel position) const {
177  return (position - state.offset) / state.zoom;
178  }
179 
180  void activate(VisNode* vis) {
181  state.activated = vis;
182  }
183 
185  state.mousePosition = NOTHING;
186  }
187 
188  void save(Config& config);
189 
190  void load(Config& config);
191 
192 private:
193  void paintCurves(wxGraphicsContext* gc, const Rgba& background, const VisNode& node);
194 
195  void paintNode(wxGraphicsContext* gc, const Rgba& background, const VisNode& node);
196 
197  wxColour getSlotColor(const NodeSlot& slot, const Rgba& background);
198 
199  void onPaint(wxPaintEvent& evt);
200 
201  void onMouseMotion(wxMouseEvent& evt);
202 
203  void onMouseWheel(wxMouseEvent& evt);
204 
205  void onLeftDown(wxMouseEvent& evt);
206 
207  void onLeftUp(wxMouseEvent& evt);
208 
209  void onRightUp(wxMouseEvent& evt);
210 
211  void onDoubleClick(wxMouseEvent& evt);
212 };
213 
215 
216 class NodeWindow : public wxPanel {
217 public:
218  enum PanelId {
221  };
222 
223 private:
224  SharedPtr<NodeManager> nodeMgr;
225 
227  VirtualSettings settings;
228 
229  NodeEditor* nodeEditor;
230 
232  PropertyEntryMap propertyEntryMap;
233 
234  wxPropertyGrid* grid;
235  RenderPane* renderPane = nullptr;
237 
239 
240 public:
241  NodeWindow(wxWindow* parent, SharedPtr<INodeManagerCallbacks> callbacks);
242 
243  ~NodeWindow();
244 
245  void showPanel(const PanelId id);
246 
247  void selectNode(const JobNode& node);
248 
249  void clearGrid();
250 
251  void showGlobals();
252 
253  void showBatchDialog();
254 
255  void selectRun();
256 
257  void startScript(const Path& file);
258 
259  void save(Config& config);
260 
261  void load(Config& config);
262 
263  void addNode(const SharedPtr<JobNode>& node);
264 
265  void addNodes(JobNode& node);
266 
268 
269  void createRenderPreview(JobNode& node);
270 
271  void reset();
272 
274 
275 private:
276  void updateProperties();
277 
278  void updateEnabled(wxPropertyGrid* grid);
279 };
280 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
const NothingType NOTHING
Definition: Optional.h:16
Key-value associative container.
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Provides functionality for reading and writing configuration files.
Definition: Config.h:272
virtual void startRun(SharedPtr< INode > node, const RunSettings &settings, const std::string &name) const =0
virtual void markUnsaved(bool addToUndo) const =0
Building block of a simulation hierarchy.
Definition: Node.h:88
Size getSlotCnt() const
Returns the number of provider slots of this node.
Definition: Node.cpp:132
void setNodeMgr(SharedPtr< NodeManager > mgr)
Definition: NodePage.h:168
float zoom
Zoom of the panel.
Definition: NodePage.h:148
VisNode * selected
Node currently selected by mouse (clicked, dragged, etc.)
Definition: NodePage.h:153
Pixel offset() const
Definition: NodePage.h:172
Pixel transform(const Pixel position) const
Definition: NodePage.h:176
VisNode * activated
Last double-clicked node.
Definition: NodePage.h:156
void invalidateMousePosition()
Definition: NodePage.h:184
NodeEditor(NodeWindow *parent, SharedPtr< INodeManagerCallbacks > callbacks)
Definition: NodePage.cpp:652
void save(Config &config)
Definition: NodePage.cpp:903
NodeSlot lastSlot
Definition: NodePage.h:161
Pixel offset
Translation of the panel.
Definition: NodePage.h:145
void load(Config &config)
Definition: NodePage.cpp:909
void activate(VisNode *vis)
Definition: NodePage.h:180
Optional< Pixel > mousePosition
Definition: NodePage.h:150
Optional< NodeSlot > connectingSlot
Source slot when connecting.
Definition: NodePage.h:159
const NodeMap & getNodes() const
Definition: NodePage.h:94
Array< SharedPtr< JobNode > > getRootNodes() const
Definition: NodePage.cpp:547
void startRun(JobNode &node)
Definition: NodePage.cpp:441
void showBatchDialog()
Definition: NodePage.cpp:597
void deleteAll()
Definition: NodePage.cpp:194
void load(Config &config)
Definition: NodePage.cpp:383
void startBatch(JobNode &node)
Definition: NodePage.cpp:477
UniqueNameManager makeUniqueNameManager() const
Definition: NodePage.cpp:587
VirtualSettings getGlobalSettings()
Definition: NodePage.cpp:559
void addNodes(JobNode &node)
Definition: NodePage.cpp:92
VisNode * getSelectedNode(const Pixel position)
Definition: NodePage.cpp:200
void deleteNode(JobNode &node)
Definition: NodePage.cpp:174
void startScript(const Path &file)
Definition: NodePage.cpp:509
void startAll()
Definition: NodePage.cpp:525
void layoutNodes(JobNode &node, const Pixel position)
Definition: NodePage.cpp:124
NodeManager(NodeEditor *editor, SharedPtr< INodeManagerCallbacks > callbacks)
Definition: NodePage.cpp:55
void selectRun()
Definition: NodePage.cpp:614
RenderPane * createRenderPreview(wxWindow *parent, JobNode &node)
Definition: NodePage.cpp:610
NodeSlot getSlotAtPosition(const Pixel position)
Definition: NodePage.cpp:213
void cloneHierarchy(JobNode &node)
Definition: NodePage.cpp:100
VisNode * addNode(const SharedPtr< JobNode > &node)
Definition: NodePage.cpp:87
void save(Config &config)
Definition: NodePage.cpp:285
void deleteTree(JobNode &node)
Definition: NodePage.cpp:185
@ ID_PROPERTIES
Definition: NodePage.h:219
void selectNode(const JobNode &node)
Definition: NodePage.cpp:1743
SharedPtr< JobNode > createNode(AutoPtr< IJob > &&job)
Definition: NodePage.cpp:1799
void clearGrid()
Definition: NodePage.cpp:1750
void addNode(const SharedPtr< JobNode > &node)
Definition: NodePage.cpp:1790
void load(Config &config)
Definition: NodePage.cpp:1785
UniqueNameManager makeUniqueNameManager() const
Definition: NodePage.cpp:1853
void addNodes(JobNode &node)
Definition: NodePage.cpp:1794
void showPanel(const PanelId id)
Definition: NodePage.cpp:1738
void save(Config &config)
Definition: NodePage.cpp:1778
void selectRun()
Definition: NodePage.cpp:1765
NodeWindow(wxWindow *parent, SharedPtr< INodeManagerCallbacks > callbacks)
Definition: NodePage.cpp:1511
void createRenderPreview(JobNode &node)
Definition: NodePage.cpp:1805
void reset()
Definition: NodePage.cpp:1773
void startScript(const Path &file)
Definition: NodePage.cpp:1769
void showBatchDialog()
Definition: NodePage.cpp:1761
void showGlobals()
Definition: NodePage.cpp:1756
Object representing a path on a filesystem.
Definition: Path.h:17
Definition: Color.h:8
Holds a map of virtual entries, associated with a unique name.
const EmptySettingsTag EMPTY_SETTINGS
Definition: Settings.h:32
Simple 2D vector with integer coordinates. Provides conversion from and to wxPoint.
Vector position(const Float a, const Float e, const Float u)
Computes the position on the elliptic trajectory.
Definition: TwoBody.cpp:82
bool operator!=(const NodeSlot &other) const
Definition: NodePage.h:51
Size index
Definition: NodePage.h:42
Pixel position() const
Definition: NodePage.cpp:677
RawPtr< const VisNode > vis
Definition: NodePage.h:41
bool operator==(const NodeSlot &other) const
Definition: NodePage.h:48
static constexpr Size RESULT_SLOT
Definition: NodePage.h:44
Definition: Point.h:101
Base class for all polymorphic objects.
Definition: Object.h:88
RawPtr< JobNode > node
Definition: NodePage.h:24
VisNode(RawPtr< JobNode > node, Pixel position)
Definition: NodePage.h:29
VisNode()=default
Pixel size() const
Definition: NodePage.h:35
static constexpr Size SIZE_X
Definition: NodePage.h:33
Pixel position
Definition: NodePage.h:25