Horizon
core.hpp
1 #pragma once
2 #include "canvas/selectables.hpp"
3 #include "common/object_descr.hpp"
4 #include "nlohmann/json_fwd.hpp"
5 #include <gdk/gdkkeysyms.h>
6 #include <deque>
7 #include <memory>
8 #include <sigc++/sigc++.h>
9 #include "tool_pub.hpp"
10 #include "document/document.hpp"
11 #include "util/placement.hpp"
12 
13 namespace horizon {
14 
15 enum class ToolID;
16 
42 class Core : public virtual Document {
43 public:
44  class Block *get_block() override
45  {
46  return nullptr;
47  }
48 
49  class Rules *get_rules() override
50  {
51  return nullptr;
52  }
53 
54  class GridSettings *get_grid_settings() override
55  {
56  return nullptr;
57  }
58 
59  class IPool &get_pool() override
60  {
61  return m_pool;
62  }
63  class IPool &get_pool_caching() override
64  {
65  return m_pool_caching;
66  }
67  virtual ObjectType get_object_type() const = 0;
68 
73  virtual void rebuild(bool from_undo = false);
74  ToolResponse tool_begin(ToolID tool_id, const ToolArgs &args, class ImpInterface *imp, bool transient = false);
75  ToolResponse tool_update(const ToolArgs &args);
76  std::pair<bool, bool> tool_can_begin(ToolID tool_id, const std::set<SelectableRef> &selection);
77  void save();
78  void autosave();
79  virtual void delete_autosave() = 0;
80 
81  void undo();
82  void redo();
83 
84  bool can_undo() const;
85  bool can_redo() const;
86 
87  inline bool tool_is_active()
88  {
89  return tool != nullptr;
90  }
91 
92  virtual bool set_property(ObjectType type, const UUID &uu, ObjectProperty::ID property,
93  const class PropertyValue &value);
94  virtual bool get_property(ObjectType type, const UUID &uu, ObjectProperty::ID property, class PropertyValue &value);
95  virtual bool get_property_meta(ObjectType type, const UUID &uu, ObjectProperty::ID property,
96  class PropertyMeta &meta);
97 
98  void set_property_begin();
99  void set_property_commit();
100  bool get_property_transaction() const;
101 
106  virtual json get_meta();
107 
108  virtual void update_rules()
109  {
110  }
111 
112  virtual std::pair<Coordi, Coordi> get_bbox() = 0;
113 
114  virtual ~Core()
115  {
116  }
117  std::set<SelectableRef> &get_tool_selection();
118  std::set<InToolActionID> get_tool_actions() const;
119 
120  bool get_needs_save() const;
121  void set_needs_save();
122 
123  virtual const std::string &get_filename() const = 0;
124 
125  typedef sigc::signal<void, ToolID> type_signal_tool_changed;
126  type_signal_tool_changed signal_tool_changed()
127  {
128  return s_signal_tool_changed;
129  }
130  typedef sigc::signal<void> type_signal_rebuilt;
131  type_signal_rebuilt signal_rebuilt()
132  {
133  return s_signal_rebuilt;
134  }
140  type_signal_rebuilt signal_save()
141  {
142  return s_signal_save;
143  }
144 
145  type_signal_rebuilt signal_modified()
146  {
147  return s_signal_modified;
148  }
149 
150  type_signal_rebuilt signal_can_undo_redo()
151  {
152  return s_signal_can_undo_redo;
153  }
154 
155  typedef sigc::signal<void, bool> type_signal_needs_save;
156  type_signal_needs_save signal_needs_save()
157  {
158  return s_signal_needs_save;
159  }
160 
161  typedef sigc::signal<json, ToolID> type_signal_load_tool_settings;
162  type_signal_load_tool_settings signal_load_tool_settings()
163  {
164  return s_signal_load_tool_settings;
165  }
166 
167  typedef sigc::signal<void, ToolID, json> type_signal_save_tool_settings;
168  type_signal_save_tool_settings signal_save_tool_settings()
169  {
170  return s_signal_save_tool_settings;
171  }
172 
173  virtual void reload_pool()
174  {
175  }
176 
177 protected:
178  Core(class IPool &pool, IPool *m_pool_caching);
179  class IPool &m_pool;
180  class IPool &m_pool_caching;
181 
182  std::unique_ptr<ToolBase> tool = nullptr;
183  type_signal_tool_changed s_signal_tool_changed;
184  type_signal_rebuilt s_signal_rebuilt;
185  type_signal_rebuilt s_signal_save;
186  type_signal_rebuilt s_signal_modified;
187  type_signal_rebuilt s_signal_can_undo_redo;
188  type_signal_needs_save s_signal_needs_save;
189  type_signal_load_tool_settings s_signal_load_tool_settings;
190  type_signal_save_tool_settings s_signal_save_tool_settings;
191  bool needs_save = false;
192  void set_needs_save(bool v);
193 
194  class HistoryItem {
195  public:
196  // Symbol sym;
197  // HistoryItem(const Symbol &s): sym(s) {}
198  std::string comment;
199  virtual ~HistoryItem()
200  {
201  }
202  };
203  std::deque<std::unique_ptr<HistoryItem>> history;
204  int history_current = -1;
205  virtual void history_push() = 0;
206  virtual void history_load(unsigned int i) = 0;
207  void history_clear();
208  void history_trim();
209 
210  bool property_transaction = false;
211 
212  void layers_to_meta(class PropertyMeta &meta);
213  void get_placement(const Placement &placement, class PropertyValue &value, ObjectProperty::ID property);
214  void set_placement(Placement &placement, const class PropertyValue &value, ObjectProperty::ID property);
215 
216  virtual void save(const std::string &suffix) = 0;
217  static const std::string autosave_suffix;
218  json get_meta_from_file(const std::string &filename);
219 
220 private:
221  std::unique_ptr<ToolBase> create_tool(ToolID tool_id);
222  std::set<SelectableRef> tool_selection;
223  void maybe_end_tool(const ToolResponse &r);
224 };
225 } // namespace horizon
A block is one level of hierarchy in the netlist.
Definition: block.hpp:26
Definition: core.hpp:194
Where Tools and and documents meet.
Definition: core.hpp:42
virtual json get_meta()
Definition: core.cpp:226
type_signal_rebuilt signal_save()
Gets emitted right before saving.
Definition: core.hpp:140
virtual void rebuild(bool from_undo=false)
Expands the non-working document.
Definition: core.cpp:141
Definition: document.hpp:5
Definition: grid_settings.hpp:9
Definition: ipool.hpp:14
Definition: imp_interface.hpp:12
Definition: placement.hpp:8
Definition: core_properties.hpp:90
Definition: core_properties.hpp:7
Definition: rules.hpp:49
This is what a Tool receives when the user did something.
Definition: tool_pub.hpp:23
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: tool_pub.hpp:40
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:170