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 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 
56  wxString net_name;
57 
60 };
61 
62 
69 class SCH_LINE_WIRE_BUS_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
70 {
71 public:
74 
76  bool Init() override;
77 
78  int DrawSegments( const TOOL_EVENT& aEvent );
79  int UnfoldBus( const TOOL_EVENT& aEvent );
80 
81  // SELECTION_CONDITIONs:
82  static bool IsDrawingLine( const SELECTION& aSelection );
83  static bool IsDrawingWire( const SELECTION& aSelection );
84  static bool IsDrawingBus( const SELECTION& aSelection );
85  static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
86 
90  int AddJunctionsIfNeeded( const TOOL_EVENT& aEvent );
91 
92 private:
93  int doDrawSegments( const std::string& aTool, int aType );
94  SCH_LINE* startSegments( int aType, const VECTOR2D& aPos );
95  SCH_LINE* doUnfoldBus( const wxString& aNet );
96  void finishSegments();
97 
102  void simplifyWireList();
103 
105  void setTransitions() override;
106 
112  const SCH_SHEET_PIN* getSheetPin( const wxPoint& aPosition );
113 
124  void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, wxPoint& aPosition );
125 
126 private:
129 
131  std::vector<SCH_LINE*> m_wires;
132 };
133 
134 #endif /* SCH_LINE_WIRE_BUS_TOOL_H */
static bool IsDrawingWire(const SELECTION &aSelection)
void simplifyWireList()
Iterates over the wire list and removes the null segments and overlapping segments to create a simpli...
bool flipY
True if the bus entry should be flipped in the y-axis.
SCH_LINE * doUnfoldBus(const wxString &aNet)
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
Sets up handlers for various events.
int UnfoldBus(const TOOL_EVENT &aEvent)
const SCH_SHEET_PIN * getSheetPin(const wxPoint &aPosition)
Searches for a sheet pin at a location.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
wxPoint origin
Origin (on the bus) of the unfold.
int doDrawSegments(const std::string &aTool, int aType)
SCH_LINE_DRAWING_TOOL.
TOOL_EVENT.
Definition: tool_event.h:171
Collection of data related to the bus unfolding tool.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
wxString net_name
Net label for the unfolding operation.
void computeBreakPoint(const std::pair< SCH_LINE *, SCH_LINE * > &aSegments, wxPoint &aPosition)
Function ComputeBreakPoint computes the middle coordinate for 2 segments from the start point to aPos...
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.
EE_TOOL_BASE.
Definition: ee_tool_base.h:50
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.