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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SCH_LINE_WIRE_BUS_TOOL_H
22#define SCH_LINE_WIRE_BUS_TOOL_H
23
24#include <wx/string.h>
25#include <string>
26#include <vector>
27
28#include <math/vector2d.h>
29#include <sch_edit_frame.h>
30#include <sch_line.h>
31
32#include <sch_tool_base.h>
33
34class TOOL_EVENT;
35
37class SCH_LABEL;
38class SCH_EDIT_FRAME;
40
41
56
57
64
68
69class SCH_LINE_WIRE_BUS_TOOL : public SCH_TOOL_BASE<SCH_EDIT_FRAME>
70{
71public:
74
76 bool Init() override;
77
87 void BreakSegment( SCH_COMMIT* aCommit, SCH_LINE* aSegment, const VECTOR2I& aPoint, SCH_LINE** aNewSegment,
88 SCH_SCREEN* aScreen );
89
99 bool BreakSegments( SCH_COMMIT* aCommit, const VECTOR2I& aPoint, SCH_SCREEN* aScreen );
100
109 bool BreakSegmentsOnJunctions( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen );
110
111 int DrawSegments( const TOOL_EVENT& aEvent );
112 int UnfoldBus( const TOOL_EVENT& aEvent );
113
114 // SELECTION_CONDITIONs:
115 static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
116
120 int AddJunctionsIfNeeded( SCH_COMMIT* aCommit, SCH_SELECTION* aSelection );
121
122 SCH_JUNCTION* AddJunction( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen, const VECTOR2I& aPos );
123
127 int TrimOverLappingWires( SCH_COMMIT* aCommit, SCH_SELECTION* aSelection );
128
129private:
130 int doDrawSegments( const TOOL_EVENT& aTool, SCH_COMMIT& aCommit, int aType,
131 bool aQuitOnDraw );
132
133 SCH_LINE* startSegments( SCH_COMMIT& aCommit, int aType, const VECTOR2D& aPos,
134 SCH_LINE* aSegment = nullptr );
135
140
149 SCH_LINE* doUnfoldBus( SCH_COMMIT& aCommit, const wxString& aNet,
150 const std::optional<VECTOR2I>& aPos = std::nullopt );
151
152 void finishSegments( SCH_COMMIT& aCommit );
153
158 void simplifyWireList();
159
161 void setTransitions() override;
162
169 const SCH_SHEET_PIN* getSheetPin( const VECTOR2I& aPosition );
170
182 void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, VECTOR2I& aPosition,
183 LINE_MODE mode, bool posture );
184
185private:
186 bool m_inDrawingTool; // Reentrancy guard
187
189 std::vector<SCH_LINE*> m_wires; // Lines being drawn
190};
191
192#endif /* SCH_LINE_WIRE_BUS_TOOL_H */
Class for a wire to bus entry.
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
Schematic editor (Eeschema) main window.
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)
bool BreakSegmentsOnJunctions(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen)
Test all junctions and bus entries in the schematic for intersections with wires and buses and breaks...
void setTransitions() override
Set up handlers for various events.
int AddJunctionsIfNeeded(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Handle the addition of junctions to a selection of objects.
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
int UnfoldBus(const TOOL_EVENT &aEvent)
SCH_LINE * startSegments(SCH_COMMIT &aCommit, int aType, const VECTOR2D &aPos, SCH_LINE *aSegment=nullptr)
bool Init() override
Init() is called once upon a registration of the tool.
int TrimOverLappingWires(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
const SCH_SHEET_PIN * getSheetPin(const VECTOR2I &aPosition)
Search for a sheet pin at a location.
SCH_LINE * doUnfoldBus(SCH_COMMIT &aCommit, 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.
bool BreakSegments(SCH_COMMIT *aCommit, const VECTOR2I &aPoint, SCH_SCREEN *aScreen)
Check every wire and bus for a intersection at aPoint and break into two segments at aPoint if an int...
std::vector< SCH_LINE * > m_wires
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
void BreakSegment(SCH_COMMIT *aCommit, SCH_LINE *aSegment, const VECTOR2I &aPoint, SCH_LINE **aNewSegment, SCH_SCREEN *aScreen)
Break a single segment into two at the specified point.
void simplifyWireList()
Iterate over the wire list and removes the null segments and overlapping segments to create a simplif...
int doDrawSegments(const TOOL_EVENT &aTool, SCH_COMMIT &aCommit, int aType, bool aQuitOnDraw)
void finishSegments(SCH_COMMIT &aCommit)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
Define a sheet pin (label) used in sheets to create hierarchical schematics.
SCH_TOOL_BASE(const std::string &aName)
Generic, UI-independent tool event.
Definition tool_event.h:167
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:471
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< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707