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 <sch_edit_frame.h>
35#include <sch_line.h>
36
37#include <ee_tool_base.h>
38
39class TOOL_EVENT;
40
42class SCH_LABEL;
43class SCH_EDIT_FRAME;
45
46
49{
51 bool flipX;
52 bool flipY;
54
56 wxString net_name;
57
60};
61
62
64{
68};
69
74class SCH_LINE_WIRE_BUS_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
75{
76public:
79
81 bool Init() override;
82
83 int DrawSegments( const TOOL_EVENT& aEvent );
84 int UnfoldBus( const TOOL_EVENT& aEvent );
85
86 // SELECTION_CONDITIONs:
87 static bool IsDrawingLine( const SELECTION& aSelection );
88 static bool IsDrawingWire( const SELECTION& aSelection );
89 static bool IsDrawingBus( const SELECTION& aSelection );
90 static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
91
95 int AddJunctionsIfNeeded( const TOOL_EVENT& aEvent );
96
100 int TrimOverLappingWires( const TOOL_EVENT& aEvent );
101
102private:
103 int doDrawSegments( const TOOL_EVENT& aTool, int aType, bool aQuitOnDraw );
104 SCH_LINE* startSegments( int aType, const VECTOR2D& aPos, SCH_LINE* aSegment = nullptr );
105 SCH_LINE* doUnfoldBus( const wxString& aNet, const VECTOR2I& aPos = VECTOR2I( 0, 0 ) );
106 void finishSegments();
107
112 void simplifyWireList();
113
115 void setTransitions() override;
116
123 const SCH_SHEET_PIN* getSheetPin( const VECTOR2I& aPosition );
124
136 void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, VECTOR2I& aPosition,
137 LINE_MODE mode, bool posture );
138
139private:
140 bool m_inDrawingTool; // Reentrancy guard
141
143 std::vector<SCH_LINE*> m_wires; // Lines being drawn
144};
145
146#endif /* SCH_LINE_WIRE_BUS_TOOL_H */
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:50
Class for a wire to bus entry.
Schematic editor (Eeschema) main window.
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
void computeBreakPoint(const std::pair< SCH_LINE *, SCH_LINE * > &aSegments, VECTOR2I &aPosition, LINE_MODE mode, bool posture)
Compute the middle coordinate for 2 segments from the start point to aPosition with the segments kept...
int DrawSegments(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int AddJunctionsIfNeeded(const TOOL_EVENT &aEvent)
Handle the addition of junctions to a selection of objects.
int UnfoldBus(const TOOL_EVENT &aEvent)
static bool IsDrawingWire(const SELECTION &aSelection)
int doDrawSegments(const TOOL_EVENT &aTool, int aType, bool aQuitOnDraw)
static bool IsDrawingBus(const SELECTION &aSelection)
bool Init() override
Init() is called once upon a registration of the tool.
const SCH_SHEET_PIN * getSheetPin(const VECTOR2I &aPosition)
Search for a sheet pin at a location.
std::vector< SCH_LINE * > m_wires
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
SCH_LINE * doUnfoldBus(const wxString &aNet, const VECTOR2I &aPos=VECTOR2I(0, 0))
int TrimOverLappingWires(const TOOL_EVENT &aEvent)
Logic to remove wires when overlapping correct items.
SCH_LINE * startSegments(int aType, const VECTOR2D &aPos, SCH_LINE *aSegment=nullptr)
void simplifyWireList()
Iterate over the wire list and removes the null segments and overlapping segments to create a simplif...
static bool IsDrawingLine(const SELECTION &aSelection)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Generic, UI-independent tool event.
Definition: tool_event.h:156
LINE_MODE
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
Collection of data related to the bus unfolding tool.
bool label_placed
True if user has placed the net label.
wxString net_name
Net label for the unfolding operation.
bool flipY
True if the bus entry should be flipped in the y-axis.
SCH_BUS_WIRE_ENTRY * entry
bool flipX
True if the bus entry should be flipped in the x-axis.
VECTOR2I origin
Origin (on the bus) of the unfold.
bool in_progress
True if bus unfold operation is running.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618