PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/UI/Actions.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
Actions.hpp
1
2#ifndef GYM_PCB_UI_ACTIONS_H
3#define GYM_PCB_UI_ACTIONS_H
4
5#include <future>
6#include <set>
7#include "UserSettings.hpp"
8#include "Object.hpp"
9#include "Track.hpp"
10
11class UIApplication;
12
13class ActionTab;
14class Component;
15class Pin;
16class Net;
17class Connection;
18
19 class ObjectPtrNameLessThan
20{
21public:
23 bool operator()(const Object *L, const Object *R) const
24 {
25 assert(L && R);
26 if (L->getParent() == R->getParent())
27 return L->name() < R->name();
28 if (L->getParent() && R->getParent())
29 return L->getParent()->name() < R->getParent()->name();
30 return !L->getParent();
31 }
32};
33using ComSet = std::set<Component *, ObjectPtrNameLessThan>;
34using PinSet = std::set<Pin *, ObjectPtrNameLessThan>;
35
36
40
42
47 class UIActions
48{
49public:
50 constexpr static const Real MinSegmentLenSq = 1.0;
51public:
52 UIActions(UIApplication&);
53 void setUIElement(ActionTab *);
54 void reset();
55 Connection *getConnection() const { return mSelection.X; }
56 const auto& getSelectionSetC() const { return mSelection.sets.C; }
57 const auto& getSelectionSetP() const { return mSelection.sets.P; }
58 const std::vector<Connection *> *getActiveConnections() const;
59 void deselectAll();
60 void deselect(const Component *);
61 void deselect(const Pin *);
62 void setSelection(Object *);
63 void setSelection(Component *);
64 void setSelection(Pin *);
65 void setSelection(const std::set<Object *>&);
66 void setSelectionLayer(char); // 'V'/'A'/'W'/'T'/'B' for view/all/working/top/bottom
67 char getSelectionLayer() const;
68 void setPreview(bool);
69 void setPreviewTrack(const Track&, bool legal);
70 bool isPreviewing() const;
71 bool isPreviewReady() const;
72 bool isPreviewStale() const;
73 bool isPreviewTrackLegal() const;
74 const Track& getRoutePreview() const;
75 void discardPreview();
76 void setTimeoutMS(uint64_t);
77 void setActiveLayer(uint);
78 uint getActiveLayer() const;
79 void setViaCost(float);
80 bool autoroute(uint64_t timeoutMS);
81 bool connect();
82 bool routeToPoint(const Point_25&);
83 bool addSegmentTo(const Point_25&);
84 bool routeTo(const Point_2&);
85 void setRouteMode(char mode); // 0, '*', or 's' for none, A*, segment
86 char getRouteMode() const;
87 char getLastRouteMode() const;
88 bool routePreview(const Point_2&);
89 bool routeToPointPreview(const Point_25&);
90 bool addSegmentToPreview(const Point_25&);
91 bool unrouteConnection();
92 bool unrouteSegment();
93 bool unrouteSelection();
94 void updateIndicators();
95 void interrupt();
96 void setLockStepping(uint granularity);
97 void nextStep();
98 void setSelectionType(char c); // 'P'/'N'/'C' for pins/nets/components
99 char getSelectionType() const;
100private:
101 ActionTab *mActionTab{0};
102 uint mActiveLayer{0};
103 char mRouteMode{0};
104 char mLastRouteMode{'*'};
105 bool mSnapToGrid{true};
106 bool mPreview{false};
107 bool mPreviewReady{false};
108 bool mPreviewStale{false};
109 bool mPreviewLegal{false};
110 uint mLastPreviewPoint{std::numeric_limits<uint>::max()};
111 Track mPreviewTrack{Point_25(0,0,0)};
112 struct {
113 Component *C{0};
114 Pin *P[2]{0,0};
115 Net *net{0};
116 Connection *X{0};
117 uint8_t P0or1;
118 struct {
119 ComSet C;
120 PinSet P;
121 } sets;
122 char type{'P'};
123 char layer{'V'};
124 } mSelection;
125 float mViaCost{1.0f};
126 void setNetAndConnectionFromPins();
127 void resetLastPreviewPoint();
128 void setPreviewStale();
129 void setSelectionNoNotify(Pin *);
130private:
131 bool _autoroute(PinSet);
132 bool _routeToPoint(Connection *, const Point_25&, const Point_25&);
133 bool _addSegmentTo(Connection *, const Point_25&, const Point_25&);
134 bool _routeToPointPreview(Connection *, const Point_25&, const Point_25&);
135 bool _addSegmentToPreview(Connection *, const Point_25&, const Point_25&);
136 bool _connect(Connection *);
137
138 Point_25 snap(const Connection *, const Point_25&);
139 Point_25 getRouterStartPoint() const;
140private:
141 UIApplication &UIA;
142 std::future<bool> mAsyncRV;
143 uint64_t mTimeoutMS;
144};
145
146inline void UIActions::setUIElement(ActionTab *A)
147{
148 mActionTab = A;
149}
150inline void UIActions::setPreview(bool b)
151{
152 mPreview = b;
153 if (!b)
154 setPreviewStale();
155}
156inline void UIActions::setPreviewTrack(const Track &T, bool legal)
157{
158 mPreviewTrack = T;
159 mPreviewReady = true;
160 mPreviewStale = false;
161 mPreviewLegal = legal;
162}
163inline bool UIActions::isPreviewing() const
164{
165 return mPreview;
166}
167inline bool UIActions::isPreviewReady() const
168{
169 return mPreviewReady;
170}
171inline bool UIActions::isPreviewStale() const
172{
173 return mPreviewStale;
174}
175inline bool UIActions::isPreviewTrackLegal() const
176{
177 return mPreviewLegal;
178}
179inline const Track& UIActions::getRoutePreview() const
180{
181 return mPreviewTrack;
182}
183inline void UIActions::discardPreview()
184{
185 mPreviewTrack.clear();
186 mPreviewReady = false;
187}
188inline void UIActions::setTimeoutMS(uint64_t ms)
189{
190 mTimeoutMS = ms;
191}
192inline char UIActions::getRouteMode() const
193{
194 return mRouteMode;
195}
196inline char UIActions::getLastRouteMode() const
197{
198 return mLastRouteMode;
199}
200inline uint UIActions::getActiveLayer() const
201{
202 return mActiveLayer;
203}
204inline void UIActions::setSelectionLayer(char c)
205{
206 assert(c == 'A' || c == 'V' || c == 'W' || c == 'T' || c == 'B');
207 mSelection.layer = c;
208}
209inline char UIActions::getSelectionLayer() const
210{
211 return mSelection.layer;
212}
213inline void UIActions::setSelectionType(char c)
214{
215 assert(c == 'P' || c == 'N' || c == 'C');
216 mSelection.type = c;
217}
218inline char UIActions::getSelectionType() const
219{
220 return mSelection.type;
221}
222
223inline void UIActions::resetLastPreviewPoint()
224{
225 mLastPreviewPoint = std::numeric_limits<uint>::max();
226}
227
228inline void UIActions::setPreviewStale()
229{
230 mPreviewStale = true;
231 resetLastPreviewPoint();
232}
233
234inline void UIActions::setViaCost(float v)
235{
236 UserSettings::edit().AStarViaCostFactor = mViaCost = v;
237}
238
239#endif // GYM_PCB_UI_ACTIONS_H
ActionTab
Definition ActionTab.hpp:35
Component
Definition Component.hpp:18
Connection
Definition Connection.hpp:17
Net
Definition Net.hpp:19
ObjectPtrNameLessThan
Definition Actions.hpp:20
ObjectPtrNameLessThan::operator()
bool operator()(const Object *L, const Object *R) const
Parent names take precedent, no parent counts as less.
Definition Actions.hpp:23
Object
Definition Object.hpp:12
Pin
Definition Pin.hpp:18
Point_25
Definition Geometry.hpp:131
Track
Definition Track.hpp:21
UIApplication
Definition Application.hpp:41