Horizon
tool_place_junction.hpp
1 #pragma once
2 #include "core/tool.hpp"
3 #include <forward_list>
4 
5 namespace horizon {
6 
7 
8 class ToolPlaceJunctionBase : public virtual ToolBase {
9 public:
10  using ToolBase::ToolBase;
11  ToolResponse begin(const ToolArgs &args) override;
12  ToolResponse update(const ToolArgs &args) override;
13  bool can_begin() override;
14  std::set<InToolActionID> get_actions() const override
15  {
16  using I = InToolActionID;
17  return {
18  I::LMB,
19  I::CANCEL,
20  I::RMB,
21  };
22  }
23 
24  virtual ~ToolPlaceJunctionBase()
25  {
26  }
27 
28 protected:
29  virtual class Junction *get_junction() = 0;
30  std::forward_list<Junction *> junctions_placed;
31 
32  virtual void insert_junction() = 0;
33  virtual bool junction_placed()
34  {
35  return false;
36  }
37  void create_junction(const Coordi &c);
38  virtual void create_attached()
39  {
40  }
41  virtual void delete_attached()
42  {
43  }
44  virtual bool update_attached(const ToolArgs &args)
45  {
46  return false;
47  }
48  virtual bool begin_attached()
49  {
50  return true;
51  }
52  virtual void finish()
53  {
54  }
55 };
56 
57 template <typename T> class ToolPlaceJunctionT : public ToolPlaceJunctionBase {
58 public:
59  using ToolPlaceJunctionBase::ToolPlaceJunctionBase;
60 
61 protected:
62  T *temp = nullptr;
63 
64  Junction *get_junction() override
65  {
66  return temp;
67  };
68 };
69 
70 class ToolPlaceJunction : public ToolPlaceJunctionT<Junction> {
71 public:
73 
74 protected:
75  void insert_junction() override;
76 };
77 
78 } // namespace horizon
A Junction is a point in 2D-Space.
Definition: junction.hpp:20
This is what a Tool receives when the user did something.
Definition: tool_pub.hpp:23
Common interface for all Tools.
Definition: tool_pub.hpp:94
Definition: tool_place_junction.hpp:8
bool can_begin() override
Definition: tool_place_junction.cpp:9
ToolResponse begin(const ToolArgs &args) override
Gets called right after the constructor has finished.
Definition: tool_place_junction.cpp:14
ToolResponse update(const ToolArgs &args) override
Gets called whenever the user generated some sort of input.
Definition: tool_place_junction.cpp:45
Definition: tool_place_junction.hpp:57
Definition: tool_place_junction.hpp:70
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: tool_pub.hpp:40