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, 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 <sch_tool_base.h>
37
38class TOOL_EVENT;
39
41class SCH_LABEL;
42class SCH_EDIT_FRAME;
44
45
60
61
68
72
73class SCH_LINE_WIRE_BUS_TOOL : public SCH_TOOL_BASE<SCH_EDIT_FRAME>
74{
75public:
78
80 bool Init() override;
81
91 void BreakSegment( SCH_COMMIT* aCommit, SCH_LINE* aSegment, const VECTOR2I& aPoint, SCH_LINE** aNewSegment,
92 SCH_SCREEN* aScreen );
93
103 bool BreakSegments( SCH_COMMIT* aCommit, const VECTOR2I& aPoint, SCH_SCREEN* aScreen );
104
113 bool BreakSegmentsOnJunctions( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen );
114
115 int DrawSegments( const TOOL_EVENT& aEvent );
116 int UnfoldBus( const TOOL_EVENT& aEvent );
117
118 // SELECTION_CONDITIONs:
119 static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
120
124 int AddJunctionsIfNeeded( SCH_COMMIT* aCommit, SCH_SELECTION* aSelection );
125
126 SCH_JUNCTION* AddJunction( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen, const VECTOR2I& aPos );
127
131 int TrimOverLappingWires( SCH_COMMIT* aCommit, SCH_SELECTION* aSelection );
132
133private:
134 int doDrawSegments( const TOOL_EVENT& aTool, SCH_COMMIT& aCommit, int aType,
135 bool aQuitOnDraw );
136
137 SCH_LINE* startSegments( SCH_COMMIT& aCommit, int aType, const VECTOR2D& aPos,
138 SCH_LINE* aSegment = nullptr );
139
144
152 SCH_LINE* doUnfoldBus( SCH_COMMIT& aCommit, const wxString& aNet,
153 const std::optional<VECTOR2I>& aPos = std::nullopt );
154
155 void finishSegments( SCH_COMMIT& aCommit );
156
161 void simplifyWireList();
162
164 void setTransitions() override;
165
172 const SCH_SHEET_PIN* getSheetPin( const VECTOR2I& aPosition );
173
185 void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, VECTOR2I& aPosition,
186 LINE_MODE mode, bool posture );
187
188private:
189 bool m_inDrawingTool; // Reentrancy guard
190
192 std::vector<SCH_LINE*> m_wires; // Lines being drawn
193};
194
195#endif /* SCH_LINE_WIRE_BUS_TOOL_H */
Class for a wire to bus entry.
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
This method is meant to be overridden in order to specify handlers for 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:42
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:171
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:448
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:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694