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 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_text.h>
23
24#include <common.h>
25#include <board.h>
26#include <pcb_text.h>
27#include <xnode.h>
28
29#include <wx/string.h>
30
31namespace PCAD2KICAD {
32
33PCAD_TEXT::PCAD_TEXT( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
34 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
35{
36 m_ObjType = wxT( 'T' );
37}
38
39
43
44
45void PCAD_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
46 const wxString& aActualConversion )
47{
48 XNODE* lNode;
49 wxString str;
50
51 m_PCadLayer = aLayer;
53 m_PositionX = 0;
54 m_PositionY = 0;
55 m_Name.mirror = 0; // Normal, not mirrored
56 lNode = FindNode( aNode, wxT( "pt" ) );
57
58 if( lNode )
59 {
60 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
61 aActualConversion );
62 }
63
64 lNode = FindNode( aNode, wxT( "rotation" ) );
65
66 if( lNode )
67 {
68 str = lNode->GetNodeContent();
69 str.Trim( false );
71 }
72
73 aNode->GetAttribute( wxT( "Name" ), &m_Name.text );
74 m_Name.text.Replace( wxT( "\r" ), wxT( "" ) );
75
76 str = FindNodeGetContent( aNode, wxT( "justify" ) );
77 m_Name.justify = GetJustifyIdentificator( str );
78
79 str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
80
81 if( str.IsSameAs( wxT( "True" ), false ) )
82 m_Name.mirror = 1;
83
84 lNode = FindNode( aNode, wxT( "textStyleRef" ) );
85
86 if( lNode )
87 SetFontProperty( lNode, &m_Name, aDefaultUnits, aActualConversion );
88}
89
90
92{
93 m_Name.textPositionX = m_PositionX;
94 m_Name.textPositionY = m_PositionY;
95 m_Name.textRotation = m_Rotation;
96
97 ::PCB_TEXT* pcbtxt = new ::PCB_TEXT( m_board );
98 m_board->Add( pcbtxt, ADD_MODE::APPEND );
99
100 pcbtxt->SetText( m_Name.text );
101
102 if( m_Name.isTrueType )
103 SetTextSizeFromTrueTypeFontHeight( pcbtxt, m_Name.textHeight );
104 else
105 SetTextSizeFromStrokeFontHeight( pcbtxt, m_Name.textHeight );
106
107 pcbtxt->SetItalic( m_Name.isItalic );
108 pcbtxt->SetTextThickness( m_Name.textstrokeWidth );
109
110 SetTextJustify( pcbtxt, m_Name.justify );
111 pcbtxt->SetTextPos( VECTOR2I( m_Name.textPositionX, m_Name.textPositionY ) );
112
113 pcbtxt->SetMirrored( m_Name.mirror );
114
115 if( pcbtxt->IsMirrored() )
116 pcbtxt->SetTextAngle( ANGLE_360 - m_Name.textRotation );
117 else
118 pcbtxt->SetTextAngle( m_Name.textRotation );
119
120 pcbtxt->SetLayer( m_KiCadLayer );
121}
122
123
124// void PCAD_TEXT::SetPosOffset( int aX_offs, int aY_offs )
125// {
126// PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
127
128// m_Name.textPositionX += aX_offs;
129// m_Name.textPositionY += aY_offs;
130// }
131
132} // namespace PCAD2KICAD
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:313
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:576
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:388
bool IsMirrored() const
Definition eda_text.h:211
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:265
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:302
PCAD_PCB_COMPONENT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
PCAD_TEXT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition pcad_text.cpp:33
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition pcad_text.cpp:45
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition pcad_text.cpp:91
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:495
void SetTextAngle(const EDA_ANGLE &aAngle) override
Definition pcb_text.cpp:552
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
The common library.
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:417
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:683