KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_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 <[email protected]>
5 * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <pcad/pcad_line.h>
23
24#include <board.h>
25#include <common.h>
26#include <footprint.h>
27#include <pcb_shape.h>
28#include <pcb_track.h>
29#include <xnode.h>
30
31#include <wx/string.h>
32
33namespace PCAD2KICAD {
34
35PCAD_LINE::PCAD_LINE( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
36 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
37{
38 m_Width = 0;
39 m_ToX = 0;
40 m_ToY = 0;
41 m_ObjType = wxT( 'L' );
42}
43
44
48
49
50void PCAD_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
51 const wxString& aActualConversion )
52{
53 XNODE* lNode;
54 wxString propValue;
55
56 m_PCadLayer = aLayer;
58 m_PositionX = 0;
59 m_PositionY = 0;
60 m_ToX = 0;
61 m_ToY = 0;
62 m_Width = 0;
63 lNode = FindNode( aNode, wxT( "pt" ) );
64
65 if( lNode )
66 {
67 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
68 aActualConversion );
69 }
70
71 if( lNode )
72 lNode = lNode->GetNext();
73
74 if( lNode )
75 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_ToX, &m_ToY, aActualConversion );
76
77 lNode = FindNode( aNode, wxT( "width" ) );
78
79 if( lNode )
80 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Width, aActualConversion );
81
82 lNode = FindNode( aNode, wxT( "netNameRef" ) );
83
84 if( lNode )
85 {
86 lNode->GetAttribute( wxT( "Name" ), &propValue );
87 propValue.Trim( false );
88 propValue.Trim( true );
89 m_Net = propValue;
91 }
92}
93
94
95void PCAD_LINE::SetPosOffset( int aX_offs, int aY_offs )
96{
97 PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
98
99 m_ToX += aX_offs;
100 m_ToY += aY_offs;
101}
102
103
105{
107
108 m_ToX = -m_ToX;
109 m_KiCadLayer = m_board->FlipLayer( m_KiCadLayer );
110}
111
112
114{
115 if( IsCopperLayer( m_KiCadLayer ) && !aFootprint )
116 {
117 PCB_TRACK* track = new PCB_TRACK( m_board );
118 m_board->Add( track );
119
121 track->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
122
123 track->SetWidth( m_Width );
124
125 track->SetLayer( m_KiCadLayer );
126 track->SetNetCode( m_NetCode );
127 }
128 else
129 {
130 PCB_SHAPE* segment = new PCB_SHAPE( m_board, SHAPE_T::SEGMENT );
131 m_board->Add( segment, ADD_MODE::APPEND );
132
133 segment->SetLayer( m_KiCadLayer );
135 segment->SetEnd( VECTOR2I( m_ToX, m_ToY ) );
137
138 if( aFootprint )
139 {
140 segment->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
141 segment->Move( aFootprint->GetPosition() );
142 }
143 }
144}
145
146} // namespace PCAD2KICAD
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
EDA_ANGLE GetOrientation() const
Definition footprint.h:406
VECTOR2I GetPosition() const override
Definition footprint.h:403
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition pcad_line.cpp:50
PCAD_LINE(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition pcad_line.cpp:35
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition pcad_line.cpp:95
virtual void Flip() override
virtual void SetPosOffset(int aX_offs, int aY_offs)
int GetNetCode(const wxString &aNetName) const
PCAD_PCB_COMPONENT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetStart(const VECTOR2I &aStart) override
void SetStroke(const STROKE_PARAMS &aStroke) override
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:89
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_track.h:82
virtual void SetWidth(int aWidth)
Definition pcb_track.h:86
Simple container to manage line stroke parameters.
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
XNODE * GetNext() const
Definition xnode.h:102
The common library.
@ SEGMENT
Definition eda_shape.h:46
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:675
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683