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 ) :
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 
55 void 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 
100 void 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 
125  segment->SetStart0( wxPoint( m_positionX, m_positionY ) );
126  segment->SetEnd0( wxPoint( m_ToX, m_ToY ) );
127 
128  segment->SetWidth( m_Width );
129  segment->SetLayer( m_KiCadLayer );
130 
131  segment->SetDrawCoord();
132  }
133 }
134 
135 
137 {
138  if( IsCopperLayer( m_KiCadLayer ) )
139  {
140  PCB_TRACK* track = new PCB_TRACK( m_board );
141  m_board->Add( track );
142 
143  track->SetPosition( wxPoint( m_positionX, m_positionY ) );
144  track->SetEnd( wxPoint( 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 );
154  m_board->Add( segment, ADD_MODE::APPEND );
155 
156  segment->SetLayer( m_KiCadLayer );
157  segment->SetStart( wxPoint( m_positionX, m_positionY ) );
158  segment->SetEnd( wxPoint( m_ToX, m_ToY ) );
159  segment->SetWidth( m_Width );
160  }
161 }
162 
163 } // namespace PCAD2KICAD
PCB_LINE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_line.cpp:40
void AddToBoard() override
Definition: pcb_line.cpp:136
void SetEnd0(const wxPoint &aPoint)
Definition: fp_shape.h:114
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, 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
usual segment : line with rounded ends
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void Flip() override
Definition: pcb_line.cpp:109
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcb_line.cpp:55
int GetNetCode(const wxString &aNetName) const
Definition: pcb_component.h:58
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_line.cpp:118
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:607
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Test whether a layer is a non copper layer.
Definition: layer_ids.h:798
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:82
void SetStart0(const wxPoint &aPoint)
Definition: fp_shape.h:111
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:787
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
void SetWidth(int aWidth)
Definition: pcb_shape.h:96
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
The common library.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Removes an item from the container.
Definition: footprint.cpp:513
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetEnd(const wxPoint &aEnd)
Definition: pcb_shape.h:137
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:100