KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_line.cpp
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) 2007, 2008 Lubo Racko <[email protected]>
5 * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <[email protected]>
6 * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <pcad/pcad_line.h>
27
28#include <board.h>
29#include <common.h>
30#include <footprint.h>
31#include <pcb_shape.h>
32#include <pcb_track.h>
33#include <xnode.h>
34
35#include <wx/string.h>
36
37namespace PCAD2KICAD {
38
39PCAD_LINE::PCAD_LINE( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
40 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
41{
42 m_Width = 0;
43 m_ToX = 0;
44 m_ToY = 0;
45 m_ObjType = wxT( 'L' );
46}
47
48
50{
51}
52
53
54void PCAD_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
55 const wxString& aActualConversion )
56{
57 XNODE* lNode;
58 wxString propValue;
59
60 m_PCadLayer = aLayer;
62 m_PositionX = 0;
63 m_PositionY = 0;
64 m_ToX = 0;
65 m_ToY = 0;
66 m_Width = 0;
67 lNode = FindNode( aNode, wxT( "pt" ) );
68
69 if( lNode )
70 {
71 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
72 aActualConversion );
73 }
74
75 if( lNode )
76 lNode = lNode->GetNext();
77
78 if( lNode )
79 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_ToX, &m_ToY, aActualConversion );
80
81 lNode = FindNode( aNode, wxT( "width" ) );
82
83 if( lNode )
84 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Width, aActualConversion );
85
86 lNode = FindNode( aNode, wxT( "netNameRef" ) );
87
88 if( lNode )
89 {
90 lNode->GetAttribute( wxT( "Name" ), &propValue );
91 propValue.Trim( false );
92 propValue.Trim( true );
93 m_Net = propValue;
95 }
96}
97
98
99void PCAD_LINE::SetPosOffset( int aX_offs, int aY_offs )
100{
101 PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
102
103 m_ToX += aX_offs;
104 m_ToY += aY_offs;
105}
106
107
109{
111
112 m_ToX = -m_ToX;
114}
115
116
118{
119 if( IsCopperLayer( m_KiCadLayer ) && !aFootprint )
120 {
121 PCB_TRACK* track = new PCB_TRACK( m_board );
122 m_board->Add( track );
123
125 track->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
126
127 track->SetWidth( m_Width );
128
129 track->SetLayer( m_KiCadLayer );
130 track->SetNetCode( m_NetCode );
131 }
132 else
133 {
134 PCB_SHAPE* segment = new PCB_SHAPE( m_board, SHAPE_T::SEGMENT );
135 m_board->Add( segment, ADD_MODE::APPEND );
136
137 segment->SetLayer( m_KiCadLayer );
139 segment->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
140 segment->SetStroke( STROKE_PARAMS( m_Width, LINE_STYLE::SOLID ) );
141
142 if( aFootprint )
143 {
144 segment->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
145 segment->Move( aFootprint->GetPosition() );
146 }
147 }
148}
149
150} // namespace PCAD2KICAD
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:1003
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
Definition: board.cpp:734
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:141
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:178
EDA_ANGLE GetOrientation() const
Definition: footprint.h:227
VECTOR2I GetPosition() const override
Definition: footprint.h:224
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition: pcad_line.cpp:117
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcad_line.cpp:54
PCAD_LINE(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcad_line.cpp:39
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcad_line.cpp:99
virtual void Flip() override
Definition: pcad_line.cpp:108
virtual void SetPosOffset(int aX_offs, int aY_offs)
PCB_LAYER_ID GetKiCadLayer() const
int GetNetCode(const wxString &aNetName) const
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_shape.cpp:480
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:170
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:387
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:90
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:118
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_track.h:111
virtual void SetWidth(int aWidth)
Definition: pcb_track.h:115
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:66
The common library.
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:531
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691