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 #include <wx/config.h>
32 
33 #include <common.h>
34 
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  wxString aDefaultMeasurementUnit,
57  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  EDGE_MODULE* segment = new EDGE_MODULE( aModule, S_SEGMENT );
123  aModule->GraphicalItems().PushBack( 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->m_Track.Append( track );
142 
143  track->SetTimeStamp( m_timestamp );
144 
146  track->SetEnd( wxPoint( m_toX, m_toY ) );
147 
148  track->SetWidth( m_width );
149 
150  track->SetLayer( m_KiCadLayer );
151  track->SetNetCode( m_netCode );
152  }
153  else
154  {
155  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
156  m_board->Add( dseg, ADD_APPEND );
157 
158  dseg->SetTimeStamp( m_timestamp );
159  dseg->SetLayer( m_KiCadLayer );
161  dseg->SetEnd( wxPoint( m_toX, m_toY ) );
162  dseg->SetWidth( m_width );
163  }
164 }
165 
166 } // namespace PCAD2KICAD
void SetWidth(wxString aStr, wxString aDefaultMeasurementUnit, int *aWidth, wxString aActualConversion)
PCB_LINE(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_line.cpp:39
void AddToBoard() override
Definition: pcb_line.cpp:136
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:116
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
virtual void Flip() override
Definition: pcb_line.cpp:109
usual segment : line with rounded ends
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
wxPoint m_End0
void SetWidth(int aWidth)
Definition: class_track.h:113
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
virtual void SetPosOffset(int aX_offs, int aY_offs)
virtual void Parse(XNODE *aNode, int aLayer, wxString aDefaultMeasurementUnit, wxString aActualConversion)
Definition: pcb_line.cpp:54
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
void SetPosition(wxString aStr, wxString aDefaultMeasurementUnit, int *aX, int *aY, wxString aActualConversion)
void SetStart(const wxPoint &aStart)
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID FlipLayer(LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:444
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:110
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
The common library.
void SetEnd(const wxPoint &aEnd)
XNODE * FindNode(XNODE *aChild, wxString aTag)
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
int GetNetCode(wxString aNetName)
Definition: pcb_component.h:75
DLIST< TRACK > m_Track
Definition: class_board.h:244
void AddToModule(MODULE *aModule) override
Definition: pcb_line.cpp:118
wxPoint m_Start0
XNODE * GetNext() const
Definition: xnode.h:68
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_line.cpp:100
void SetWidth(int aWidth)