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 
30 #include <wx/wx.h>
31 
32 #include <common.h>
33 #include <fp_shape.h>
34 #include <pcb_shape.h>
35 #include <pcb_line.h>
36 
37 namespace PCAD2KICAD {
38 
39 PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
40  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 
54 void PCB_LINE::Parse( XNODE* aNode,
55  int aLayer,
56  const wxString& aDefaultMeasurementUnit,
57  const wxString& aActualConversion )
58 {
59  XNODE* lNode;
60  wxString propValue;
61 
62  m_PCadLayer = aLayer;
64  m_positionX = 0;
65  m_positionY = 0;
66  m_ToX = 0;
67  m_ToY = 0;
68  m_Width = 0;
69  lNode = FindNode( aNode, wxT( "pt" ) );
70 
71  if( lNode )
72  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
73  &m_positionX, &m_positionY, aActualConversion );
74 
75  if( lNode )
76  lNode = lNode->GetNext();
77 
78  if( lNode )
79  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
80  &m_ToX, &m_ToY, aActualConversion );
81 
82  lNode = FindNode( aNode, wxT( "width" ) );
83 
84  if( lNode )
85  SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &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, S_SEGMENT );
123  aFootprint->Add( segment );
124 
125  segment->m_Start0 = wxPoint( m_positionX, m_positionY );
126  segment->m_End0 = 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  TRACK* track = new 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:39
void AddToBoard() override
Definition: pcb_line.cpp:136
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetEnd(const wxPoint &aEnd)
Definition: track.h:112
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)
usual segment : line with rounded ends
Definition: board_item.h:50
virtual void Flip() override
Definition: pcb_line.cpp:109
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_line.cpp:118
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Test whether a layer is a non copper layer.
void SetWidth(int aWidth)
Definition: track.h:109
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:563
int GetNetCode(wxString aNetName) const
Definition: pcb_component.h:71
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:54
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:81
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:70
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:67
void SetStart(const wxPoint &aStart)
Definition: pcb_shape.h:148
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetPosition(const wxPoint &aPos) override
Definition: track.h:105
void SetWidth(int aWidth)
Definition: pcb_shape.h:117
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:467
Definition: track.h:83
void SetEnd(const wxPoint &aEnd)
Definition: pcb_shape.h:159
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:100