KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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/string.h>
29#include <string>
30#include <vector>
31
32#include <math/vector2d.h>
33#include <sch_edit_frame.h>
34#include <sch_line.h>
35
36#include <ee_tool_base.h>
37
38class TOOL_EVENT;
39
41class SCH_LABEL;
42class SCH_EDIT_FRAME;
44
45
48{
50 bool flipX;
51 bool flipY;
53
55 wxString net_name;
56
59};
60
61
63{
67};
68
73class SCH_LINE_WIRE_BUS_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
74{
75public:
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 IsDrawingLineWireOrBus( const SELECTION& aSelection );
87
91 int AddJunctionsIfNeeded( SCH_COMMIT* aCommit, EE_SELECTION* aSelection );
92
96 int TrimOverLappingWires( SCH_COMMIT* aCommit, EE_SELECTION* aSelection );
97
98private:
99 int doDrawSegments( const TOOL_EVENT& aTool, int aType, bool aQuitOnDraw );
100
101 SCH_LINE* startSegments( int aType, const VECTOR2D& aPos, SCH_LINE* aSegment = nullptr );
102
107
115 SCH_LINE* doUnfoldBus( const wxString& aNet,
116 const std::optional<VECTOR2I>& aPos = std::nullopt );
117
118 void finishSegments();
119
124 void simplifyWireList();
125
127 void setTransitions() override;
128
135 const SCH_SHEET_PIN* getSheetPin( const VECTOR2I& aPosition );
136
148 void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, VECTOR2I& aPosition,
149 LINE_MODE mode, bool posture );
150
151private:
152 bool m_inDrawingTool; // Reentrancy guard
153
155 std::vector<SCH_LINE*> m_wires; // Lines being drawn
156};
157
158#endif /* SCH_LINE_WIRE_BUS_TOOL_H */
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:48
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(SCH_COMMIT *aCommit, EE_SELECTION *aSelection)
Handle the addition of junctions to a selection of objects.
int UnfoldBus(const TOOL_EVENT &aEvent)
int doDrawSegments(const TOOL_EVENT &aTool, int aType, bool aQuitOnDraw)
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.
SCH_LINE * doUnfoldBus(const wxString &aNet, const std::optional< VECTOR2I > &aPos=std::nullopt)
Unfold the given bus from the given position.
SCH_LINE * getBusForUnfolding()
Choose a bus to unfold based on the current tool selection.
std::vector< SCH_LINE * > m_wires
int TrimOverLappingWires(SCH_COMMIT *aCommit, EE_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
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...
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
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:167
LINE_MODE
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:353
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.