2019-05-02 15:01:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-01-26 15:23:37 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-02 15:01:51 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
#ifndef SCH_LINE_WIRE_BUS_TOOL_H
|
|
|
|
#define SCH_LINE_WIRE_BUS_TOOL_H
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_line.h>
|
|
|
|
|
|
|
|
#include <ee_tool_base.h>
|
2019-05-02 15:01:51 +00:00
|
|
|
|
2021-06-06 17:26:26 +00:00
|
|
|
class TOOL_EVENT;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
class SCH_BUS_WIRE_ENTRY;
|
|
|
|
class SCH_LABEL;
|
|
|
|
class SCH_EDIT_FRAME;
|
2019-05-10 17:19:48 +00:00
|
|
|
class EE_SELECTION_TOOL;
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Collection of data related to the bus unfolding tool
|
|
|
|
struct BUS_UNFOLDING_T
|
|
|
|
{
|
|
|
|
bool in_progress; ///< True if bus unfold operation is running
|
2020-07-09 22:51:42 +00:00
|
|
|
bool flipX; ///< True if the bus entry should be flipped in the x-axis
|
|
|
|
bool flipY; ///< True if the bus entry should be flipped in the y-axis
|
2019-05-02 15:01:51 +00:00
|
|
|
bool label_placed; ///< True if user has placed the net label
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I origin; ///< Origin (on the bus) of the unfold
|
2019-05-02 15:01:51 +00:00
|
|
|
wxString net_name; ///< Net label for the unfolding operation
|
|
|
|
|
|
|
|
SCH_BUS_WIRE_ENTRY* entry;
|
|
|
|
SCH_LABEL* label;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-01 23:53:47 +00:00
|
|
|
struct DRAW_SEGMENT_EVENT_PARAMS
|
|
|
|
{
|
|
|
|
SCH_LAYER_ID layer;
|
|
|
|
bool quitOnDraw;
|
2022-01-03 18:39:49 +00:00
|
|
|
SCH_LINE* sourceSegment;
|
2020-10-01 23:53:47 +00:00
|
|
|
};
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
/**
|
2020-04-02 17:03:53 +00:00
|
|
|
* Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
|
2019-05-02 15:01:51 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
class SCH_LINE_WIRE_BUS_TOOL : public EE_TOOL_BASE<SCH_EDIT_FRAME>
|
2019-05-02 15:01:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-16 13:42:40 +00:00
|
|
|
SCH_LINE_WIRE_BUS_TOOL();
|
|
|
|
~SCH_LINE_WIRE_BUS_TOOL();
|
2019-05-02 15:01:51 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
2019-06-18 17:56:40 +00:00
|
|
|
int DrawSegments( const TOOL_EVENT& aEvent );
|
2019-05-05 14:16:29 +00:00
|
|
|
int UnfoldBus( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
// SELECTION_CONDITIONs:
|
|
|
|
static bool IsDrawingLine( const SELECTION& aSelection );
|
|
|
|
static bool IsDrawingWire( const SELECTION& aSelection );
|
|
|
|
static bool IsDrawingBus( const SELECTION& aSelection );
|
|
|
|
static bool IsDrawingLineWireOrBus( const SELECTION& aSelection );
|
|
|
|
|
2019-06-19 03:10:21 +00:00
|
|
|
/**
|
|
|
|
* Handle the addition of junctions to a selection of objects
|
|
|
|
*/
|
|
|
|
int AddJunctionsIfNeeded( const TOOL_EVENT& aEvent );
|
|
|
|
|
2022-02-20 00:49:26 +00:00
|
|
|
/**
|
|
|
|
* Logic to remove wires when overlapping correct items
|
|
|
|
*/
|
|
|
|
int TrimOverLappingWires( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
private:
|
2020-10-01 23:53:47 +00:00
|
|
|
int doDrawSegments( const std::string& aTool, int aType, bool aQuitOnDraw );
|
2022-01-03 18:39:49 +00:00
|
|
|
SCH_LINE* startSegments( int aType, const VECTOR2D& aPos, SCH_LINE* aSegment = nullptr );
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_LINE* doUnfoldBus( const wxString& aNet, const VECTOR2I& aPos = VECTOR2I( 0, 0 ) );
|
2019-05-02 15:01:51 +00:00
|
|
|
void finishSegments();
|
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Iterate over the wire list and removes the null segments and
|
|
|
|
* overlapping segments to create a simplified wire list
|
2019-12-13 14:39:13 +00:00
|
|
|
*/
|
|
|
|
void simplifyWireList();
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Set up handlers for various events.
|
2019-05-02 15:01:51 +00:00
|
|
|
void setTransitions() override;
|
|
|
|
|
2019-12-13 14:39:13 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Search for a sheet pin at a location.
|
|
|
|
*
|
2019-12-13 14:39:13 +00:00
|
|
|
* @param aPosition grid point to search for existing sheet pin
|
|
|
|
* @return Pointer to sheet pin or nullptr on failure
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
const SCH_SHEET_PIN* getSheetPin( const VECTOR2I& aPosition );
|
2019-12-13 14:39:13 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Compute the middle coordinate for 2 segments from the start point to \a aPosition
|
2019-12-13 14:39:13 +00:00
|
|
|
* with the segments kept in the horizontal or vertical axis only.
|
|
|
|
*
|
|
|
|
* @param aSegments A pair of pointers to a #SCH_LINE objects containing the first line
|
|
|
|
* break point to compute.
|
|
|
|
* @param aPosition A reference to a wxPoint object containing the coordinates of the
|
|
|
|
* position used to calculate the line break point.
|
2022-03-22 16:49:38 +00:00
|
|
|
* @param mode LINE_MODE specifying the way to break the line
|
2019-12-13 14:39:13 +00:00
|
|
|
*/
|
2022-03-22 16:49:38 +00:00
|
|
|
void computeBreakPoint( const std::pair<SCH_LINE*, SCH_LINE*>& aSegments, VECTOR2I& aPosition,
|
|
|
|
LINE_MODE mode );
|
2019-12-13 14:39:13 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
private:
|
2022-03-17 15:26:49 +00:00
|
|
|
bool m_inDrawingTool; // Reentrancy guard
|
2019-12-11 13:22:59 +00:00
|
|
|
|
2022-03-17 15:26:49 +00:00
|
|
|
BUS_UNFOLDING_T m_busUnfold;
|
|
|
|
std::vector<SCH_LINE*> m_wires; // Lines being drawn
|
2019-05-02 15:01:51 +00:00
|
|
|
};
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
#endif /* SCH_LINE_WIRE_BUS_TOOL_H */
|