KiCad PCB EDA Suite
sch_line_wire_bus_tool.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019 CERN
5  * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef SCH_LINE_WIRE_BUS_TOOL_H
26 #define SCH_LINE_WIRE_BUS_TOOL_H
27 
28 #include <wx/gdicmn.h>
29 #include <wx/string.h>
30 #include <string>
31 #include <vector>
32 
33 #include <math/vector2d.h>
34 #include <tool/tool_event.h>
35 #include <sch_edit_frame.h>
36 #include <sch_line.h>
37 
38 #include <ee_tool_base.h>
39 
40 
41 class SCH_BUS_WIRE_ENTRY;
42 class SCH_LABEL;
43 class SCH_EDIT_FRAME;
44 class EE_SELECTION_TOOL;
45 
46 
49 {
50  bool in_progress;
51  bool flipX;
52  bool flipY;
53  bool label_placed;
54 
55  wxPoint origin;
56  wxString net_name;
57 
60 };
61 
62 
64 {
66  bool quitOnDraw;
67 };
68 
73 class SCH_LINE_WIRE_BUS_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
74 {
75 public:
78 
80  bool Init() override;
81 
82  int DrawSegments( const TOOL_EVENT& aEvent );
83  int UnfoldBus( const TOOL_EVENT& aEvent );
84 
85  // SELECTION_CONDITIONs:
86  static bool IsDrawingLine( const SELECTION& aSelection );
87  static bool IsDrawingWire( const SELECTION& aSelection );
88  static bool IsDrawingBus( const SELECTION& aSelection );
89  static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
90 
94  int AddJunctionsIfNeeded( const TOOL_EVENT& aEvent );
95 
96 private:
97  int doDrawSegments( const std::string& aTool, int aType, bool aQuitOnDraw );
98  SCH_LINE* startSegments( int aType, const VECTOR2D& aPos );
99  SCH_LINE* doUnfoldBus( const wxString& aNet, wxPoint aPos = wxDefaultPosition );
100  void finishSegments();
101 
106  void simplifyWireList();
107 
109  void setTransitions() override;
110 
117  const SCH_SHEET_PIN* getSheetPin( const wxPoint& aPosition );
118 
128  void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, wxPoint& aPosition );
129 
130 private:
133 
135  std::vector<SCH_LINE*> m_wires;
136 };
137 
138 #endif /* SCH_LINE_WIRE_BUS_TOOL_H */
static bool IsDrawingWire(const SELECTION &aSelection)
void simplifyWireList()
Iterate over the wire list and removes the null segments and overlapping segments to create a simplif...
bool flipY
True if the bus entry should be flipped in the y-axis.
std::vector< SCH_LINE * > m_wires
Storage for the line segments while drawing.
int AddJunctionsIfNeeded(const TOOL_EVENT &aEvent)
Handle the addition of junctions to a selection of objects.
SCH_LINE * startSegments(int aType, const VECTOR2D &aPos)
static bool IsDrawingLine(const SELECTION &aSelection)
Schematic editor (Eeschema) main window.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int UnfoldBus(const TOOL_EVENT &aEvent)
const SCH_SHEET_PIN * getSheetPin(const wxPoint &aPosition)
Search for a sheet pin at a location.
bool Init() override
Init() is called once upon a registration of the tool.
wxPoint origin
Origin (on the bus) of the unfold.
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
SCH_LINE * doUnfoldBus(const wxString &aNet, wxPoint aPos=wxDefaultPosition)
Generic, UI-independent tool event.
Definition: tool_event.h:173
Collection of data related to the bus unfolding tool.
SCH_LAYER_ID
Eeschema drawing layers.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:85
wxString net_name
Net label for the unfolding operation.
int doDrawSegments(const std::string &aTool, int aType, bool aQuitOnDraw)
void computeBreakPoint(const std::pair< SCH_LINE *, SCH_LINE * > &aSegments, wxPoint &aPosition)
Compute the middle coordinate for 2 segments from the start point to aPosition with the segments kept...
SCH_BUS_WIRE_ENTRY * entry
static bool IsDrawingBus(const SELECTION &aSelection)
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
Class for a wire to bus entry.
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:48
bool label_placed
True if user has placed the net label.
bool flipX
True if the bus entry should be flipped in the x-axis.
int DrawSegments(const TOOL_EVENT &aEvent)
BUS_UNFOLDING_T m_busUnfold
Data related to bus unfolding tool.
bool in_progress
True if bus unfold operation is running.