KiCad PCB EDA Suite
plugins/pcad/pcb_text.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 Alexander Lunev <[email protected]>
6 * Copyright (C) 2012-2020 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, 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_text.h>
27
28#include <common.h>
29#include <board.h>
30#include <pcb_text.h>
31#include <xnode.h>
32
33#include <wx/string.h>
34
35namespace PCAD2KICAD {
36
37PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
38 PCB_COMPONENT( aCallbacks, aBoard )
39{
40 m_objType = wxT( 'T' );
41}
42
43
45{
46}
47
48
49void PCB_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
50 const wxString& aActualConversion )
51{
52 XNODE* lNode;
53 wxString str;
54
55 m_PCadLayer = aLayer;
57 m_positionX = 0;
58 m_positionY = 0;
59 m_name.mirror = 0; // Normal, not mirrored
60 lNode = FindNode( aNode, wxT( "pt" ) );
61
62 if( lNode )
63 {
64 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
65 aActualConversion );
66 }
67
68 lNode = FindNode( aNode, wxT( "rotation" ) );
69
70 if( lNode )
71 {
72 str = lNode->GetNodeContent();
73 str.Trim( false );
75 }
76
77 aNode->GetAttribute( wxT( "Name" ), &m_name.text );
78 m_name.text.Replace( wxT( "\r" ), wxT( "" ) );
79
80 str = FindNodeGetContent( aNode, wxT( "justify" ) );
82
83 str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
84
85 if( str.IsSameAs( wxT( "True" ), false ) )
86 m_name.mirror = 1;
87
88 lNode = FindNode( aNode, wxT( "textStyleRef" ) );
89
90 if( lNode )
91 SetFontProperty( lNode, &m_name, aDefaultUnits, aActualConversion );
92}
93
94
96{
97}
98
99
101{
105
106 ::PCB_TEXT* pcbtxt = new ::PCB_TEXT( m_board );
107 m_board->Add( pcbtxt, ADD_MODE::APPEND );
108
109 pcbtxt->SetText( m_name.text );
110
111 if( m_name.isTrueType )
113 else
115
116 pcbtxt->SetItalic( m_name.isItalic );
118
119 SetTextJustify( pcbtxt, m_name.justify );
121
122 pcbtxt->SetMirrored( m_name.mirror );
123
124 if( pcbtxt->IsMirrored() )
126 else
128
129 pcbtxt->SetLayer( m_KiCadLayer );
130}
131
132
133// void PCB_TEXT::SetPosOffset( int aX_offs, int aY_offs )
134// {
135// PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
136
137// m_name.textPositionX += aX_offs;
138// m_name.textPositionY += aY_offs;
139// }
140
141} // namespace PCAD2KICAD
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:198
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:240
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:684
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:371
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:224
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:185
bool IsMirrored() const
Definition: eda_text.h:140
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
void AddToFootprint(FOOTPRINT *aFootprint) override
PCB_TEXT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Hold an XML or S-expression element.
Definition: xnode.h:44
The common library.
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE & ANGLE_360
Definition: eda_angle.h:429
int StrToInt1Units(const wxString &aStr)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
void SetTextSizeFromStrokeFontHeight(EDA_TEXT *aText, int aTextHeight)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
TTEXT_JUSTIFY GetJustifyIdentificator(const wxString &aJustify)
void SetTextJustify(EDA_TEXT *aText, TTEXT_JUSTIFY aJustify)
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
void SetTextSizeFromTrueTypeFontHeight(EDA_TEXT *aText, int aTextHeight)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:607