KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_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-2023 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/pcad_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
37PCAD_TEXT::PCAD_TEXT( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
38 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
39{
40 m_ObjType = wxT( 'T' );
41}
42
43
45{
46}
47
48
49void PCAD_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{
100
101 ::PCB_TEXT* pcbtxt = new ::PCB_TEXT( m_board );
102 m_board->Add( pcbtxt, ADD_MODE::APPEND );
103
104 pcbtxt->SetText( m_Name.text );
105
106 if( m_Name.isTrueType )
108 else
110
111 pcbtxt->SetItalic( m_Name.isItalic );
113
114 SetTextJustify( pcbtxt, m_Name.justify );
116
117 pcbtxt->SetMirrored( m_Name.mirror );
118
119 if( pcbtxt->IsMirrored() )
121 else
123
124 pcbtxt->SetLayer( m_KiCadLayer );
125}
126
127
128// void PCAD_TEXT::SetPosOffset( int aX_offs, int aY_offs )
129// {
130// PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
131
132// m_Name.textPositionX += aX_offs;
133// m_Name.textPositionY += aY_offs;
134// }
135
136} // namespace PCAD2KICAD
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:1000
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:464
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:297
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:196
bool IsMirrored() const
Definition: eda_text.h:173
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:182
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:204
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition: eda_text.cpp:212
PCB_LAYER_ID GetKiCadLayer() const
PCAD_TEXT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcad_text.cpp:37
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcad_text.cpp:49
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition: pcad_text.cpp:95
Hold an XML or S-expression element.
Definition: xnode.h:43
The common library.
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:407
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< int32_t > VECTOR2I
Definition: vector2d.h:691