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 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 
34 #include <pcb_line.h>
35 
36 namespace PCAD2KICAD {
37 
38 PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
39  aBoard )
40 {
41  m_width = 0;
42  m_toX = 0;
43  m_toY = 0;
44  m_objType = wxT( 'L' );
45 }
46 
47 
49 {
50 }
51 
52 
53 void PCB_LINE::Parse( XNODE* aNode,
54  int aLayer,
55  const wxString& aDefaultMeasurementUnit,
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  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
72  &m_positionX, &m_positionY, aActualConversion );
73 
74  if( lNode )
75  lNode = lNode->GetNext();
76 
77  if( lNode )
78  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
79  &m_toX, &m_toY, aActualConversion );
80 
81  lNode = FindNode( aNode, wxT( "width" ) );
82 
83  if( lNode )
84  SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &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 
99 void PCB_LINE::SetPosOffset( int aX_offs, int aY_offs )
100 {
101  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 {
120  {
121  EDGE_MODULE* segment = new EDGE_MODULE( aModule, S_SEGMENT );
122  aModule->Add( segment );
123 
124  segment->m_Start0 = wxPoint( m_positionX, m_positionY );
125  segment->m_End0 = wxPoint( m_toX, m_toY );
126 
127  segment->SetWidth( m_width );
128  segment->SetLayer( m_KiCadLayer );
129 
130  segment->SetDrawCoord();
131  }
132 }
133 
134 
136 {
137  if( IsCopperLayer( m_KiCadLayer ) )
138  {
139  TRACK* track = new TRACK( m_board );
140  m_board->Add( track );
141 
143  track->SetEnd( wxPoint( m_toX, m_toY ) );
144 
145  track->SetWidth( m_width );
146 
147  track->SetLayer( m_KiCadLayer );
148  track->SetNetCode( m_netCode );
149  }
150  else
151  {
152  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
153  m_board->Add( dseg, ADD_MODE::APPEND );
154 
155  dseg->SetLayer( m_KiCadLayer );
157  dseg->SetEnd( wxPoint( m_toX, m_toY ) );
158  dseg->SetWidth( m_width );
159  }
160 }
161 
162 } // namespace PCAD2KICAD
PCB_LINE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_line.cpp:38
void AddToBoard() override
Definition: pcb_line.cpp:135
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:107
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:485
void SetWidth(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
virtual void Flip() override
Definition: pcb_line.cpp:108
usual segment : line with rounded ends
PCB_LAYER_ID GetKiCadLayer()
Definition: pcb_component.h:73
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
wxPoint m_End0
End point, relative to module origin, orient 0.
void SetWidth(int aWidth)
Definition: class_track.h:104
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.
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
Definition: pcb_line.cpp:53
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
void SetStart(const wxPoint &aStart)
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetNext() const
Definition: xnode.h:68
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:101
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
The common library.
void SetEnd(const wxPoint &aEnd)
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
int GetNetCode(wxString aNetName)
Definition: pcb_component.h:74
void AddToModule(MODULE *aModule) override
Definition: pcb_line.cpp:117
wxPoint m_Start0
Start point or center, relative to module origin, orient 0.
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:99
void SetWidth(int aWidth)