KiCad PCB EDA Suite
pcb_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-2020 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/pcb_line.h>
27
28#include <board.h>
29#include <common.h>
30#include <footprint.h>
31#include <fp_shape.h>
32#include <pcb_shape.h>
33#include <pcb_track.h>
34#include <xnode.h>
35
36#include <wx/string.h>
37
38namespace PCAD2KICAD {
39
40PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
41 PCB_COMPONENT( aCallbacks, aBoard )
42{
43 m_Width = 0;
44 m_ToX = 0;
45 m_ToY = 0;
46 m_objType = wxT( 'L' );
47}
48
49
51{
52}
53
54
55void PCB_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
56 const wxString& aActualConversion )
57{
58 XNODE* lNode;
59 wxString propValue;
60
61 m_PCadLayer = aLayer;
63 m_positionX = 0;
64 m_positionY = 0;
65 m_ToX = 0;
66 m_ToY = 0;
67 m_Width = 0;
68 lNode = FindNode( aNode, wxT( "pt" ) );
69
70 if( lNode )
71 {
72 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
73 aActualConversion );
74 }
75
76 if( lNode )
77 lNode = lNode->GetNext();
78
79 if( lNode )
80 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_ToX, &m_ToY, aActualConversion );
81
82 lNode = FindNode( aNode, wxT( "width" ) );
83
84 if( lNode )
85 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Width, aActualConversion );
86
87 lNode = FindNode( aNode, wxT( "netNameRef" ) );
88
89 if( lNode )
90 {
91 lNode->GetAttribute( wxT( "Name" ), &propValue );
92 propValue.Trim( false );
93 propValue.Trim( true );
94 m_net = propValue;
96 }
97}
98
99
100void PCB_LINE::SetPosOffset( int aX_offs, int aY_offs )
101{
102 PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
103
104 m_ToX += aX_offs;
105 m_ToY += aY_offs;
106}
107
108
110{
112
113 m_ToX = -m_ToX;
115}
116
117
119{
121 {
122 FP_SHAPE* segment = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT );
123 aFootprint->Add( segment );
124
126 segment->SetEnd0( VECTOR2I( m_ToX, m_ToY ) );
127
129 segment->SetLayer( m_KiCadLayer );
130
131 segment->SetDrawCoord();
132 }
133}
134
135
137{
139 {
140 PCB_TRACK* track = new PCB_TRACK( m_board );
141 m_board->Add( track );
142
144 track->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
145
146 track->SetWidth( m_Width );
147
148 track->SetLayer( m_KiCadLayer );
149 track->SetNetCode( m_netCode );
150 }
151 else
152 {
153 PCB_SHAPE* segment = new PCB_SHAPE( m_board, SHAPE_T::SEGMENT );
154 m_board->Add( segment, ADD_MODE::APPEND );
155
156 segment->SetLayer( m_KiCadLayer );
158 segment->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
160 }
161}
162
163} // 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:214
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:711
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:149
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:561
void SetEnd0(const VECTOR2I &aPoint)
Definition: fp_shape.h:94
void SetStart0(const VECTOR2I &aPoint)
Definition: fp_shape.h:91
virtual void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:80
int GetNetCode(const wxString &aNetName) const
Definition: pcb_component.h:58
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
virtual void SetPosOffset(int aX_offs, int aY_offs)
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcb_line.cpp:55
PCB_LINE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_line.cpp:40
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:100
virtual void Flip() override
Definition: pcb_line.cpp:109
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_line.cpp:118
void AddToBoard() override
Definition: pcb_line.cpp:136
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:72
void SetWidth(int aWidth)
Definition: pcb_track.h:105
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:108
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_track.h:101
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
Hold an XML or S-expression element.
Definition: xnode.h:44
XNODE * GetNext() const
Definition: xnode.h:67
The common library.
bool IsNonCopperLayer(int aLayerId)
Test whether a layer is a non copper layer.
Definition: layer_ids.h:836
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:825
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:544
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< int > VECTOR2I
Definition: vector2d.h:618