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 <developer@lura.sk>
5  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
6  * Copyright (C) 2012-2020 KiCad Developers, see CHANGELOG.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 
38 namespace PCAD2KICAD {
39 
40 PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
41  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 
55 void PCB_LINE::Parse( XNODE* aNode,
56  int aLayer,
57  const wxString& aDefaultMeasurementUnit,
58  const wxString& aActualConversion )
59 {
60  XNODE* lNode;
61  wxString propValue;
62 
63  m_PCadLayer = aLayer;
65  m_positionX = 0;
66  m_positionY = 0;
67  m_ToX = 0;
68  m_ToY = 0;
69  m_Width = 0;
70  lNode = FindNode( aNode, wxT( "pt" ) );
71 
72  if( lNode )
73  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
74  &m_positionX, &m_positionY, aActualConversion );
75 
76  if( lNode )
77  lNode = lNode->GetNext();
78 
79  if( lNode )
80  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
81  &m_ToX, &m_ToY, aActualConversion );
82 
83  lNode = FindNode( aNode, wxT( "width" ) );
84 
85  if( lNode )
86  SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_Width, aActualConversion );
87 
88  lNode = FindNode( aNode, wxT( "netNameRef" ) );
89 
90  if( lNode )
91  {
92  lNode->GetAttribute( wxT( "Name" ), &propValue );
93  propValue.Trim( false );
94  propValue.Trim( true );
95  m_net = propValue;
97  }
98 }
99 
100 
101 void PCB_LINE::SetPosOffset( int aX_offs, int aY_offs )
102 {
103  PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
104 
105  m_ToX += aX_offs;
106  m_ToY += aY_offs;
107 }
108 
109 
111 {
113 
114  m_ToX = -m_ToX;
116 }
117 
118 
120 {
122  {
123  FP_SHAPE* segment = new FP_SHAPE( aFootprint, PCB_SHAPE_TYPE::SEGMENT );
124  aFootprint->Add( segment );
125 
126  segment->m_Start0 = wxPoint( m_positionX, m_positionY );
127  segment->m_End0 = wxPoint( m_ToX, m_ToY );
128 
129  segment->SetWidth( m_Width );
130  segment->SetLayer( m_KiCadLayer );
131 
132  segment->SetDrawCoord();
133  }
134 }
135 
136 
138 {
139  if( IsCopperLayer( m_KiCadLayer ) )
140  {
141  PCB_TRACK* track = new PCB_TRACK( m_board );
142  m_board->Add( track );
143 
144  track->SetPosition( wxPoint( m_positionX, m_positionY ) );
145  track->SetEnd( wxPoint( m_ToX, m_ToY ) );
146 
147  track->SetWidth( m_Width );
148 
149  track->SetLayer( m_KiCadLayer );
150  track->SetNetCode( m_netCode );
151  }
152  else
153  {
154  PCB_SHAPE* segment = new PCB_SHAPE( m_board );
155  m_board->Add( segment, ADD_MODE::APPEND );
156 
157  segment->SetLayer( m_KiCadLayer );
158  segment->SetStart( wxPoint( m_positionX, m_positionY ) );
159  segment->SetEnd( wxPoint( m_ToX, m_ToY ) );
160  segment->SetWidth( m_Width );
161  }
162 }
163 
164 } // namespace PCAD2KICAD
PCB_LINE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_line.cpp:40
void AddToBoard() override
Definition: pcb_line.cpp:137
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetEnd(const wxPoint &aEnd)
Definition: pcb_track.h:104
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:521
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetWidth(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
virtual void Flip() override
Definition: pcb_line.cpp:110
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_line.cpp:119
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Test whether a layer is a non copper layer.
virtual void SetPosOffset(int aX_offs, int aY_offs)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:606
int GetNetCode(wxString aNetName) const
Definition: pcb_component.h:57
wxPoint m_End0
End point, relative to footprint origin, orient 0.
Definition: fp_shape.h:161
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
Definition: pcb_line.cpp:55
wxPoint m_Start0
Start point or center, relative to footprint origin, orient 0.
Definition: fp_shape.h:160
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:82
void SetPosition(const wxPoint &aPos) override
Definition: pcb_track.h:97
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
Hold an XML or S-expression element.
Definition: xnode.h:43
void SetWidth(int aWidth)
Definition: pcb_track.h:101
XNODE * GetNext() const
Definition: xnode.h:67
void SetStart(const wxPoint &aStart)
Definition: pcb_shape.h:127
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
usual segment : line with rounded ends
void SetWidth(int aWidth)
Definition: pcb_shape.h:96
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
The common library.
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:472
void SetEnd(const wxPoint &aEnd)
Definition: pcb_shape.h:137
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:101