KiCad PCB EDA Suite
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 <developer@lura.sk>
5  * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
6  * Copyright (C) 2012-2020 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 
32 #include <common.h>
33 
34 #include <pcb_text.h>
35 
36 namespace PCAD2KICAD {
37 
38 PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
39  aBoard )
40 {
41  m_objType = wxT( 'T' );
42 }
43 
44 
46 {
47 }
48 
49 
50 void PCB_TEXT::Parse( XNODE* aNode,
51  int aLayer,
52  const wxString& aDefaultMeasurementUnit,
53  const wxString& aActualConversion )
54 {
55  XNODE* lNode;
56  wxString str;
57 
58  m_PCadLayer = aLayer;
60  m_positionX = 0;
61  m_positionY = 0;
62  m_name.mirror = 0; // Normal, not mirrored
63  lNode = FindNode( aNode, wxT( "pt" ) );
64 
65  if( lNode )
66  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
67  &m_positionX, &m_positionY, aActualConversion );
68 
69  lNode = FindNode( aNode, wxT( "rotation" ) );
70 
71  if( lNode )
72  {
73  str = lNode->GetNodeContent();
74  str.Trim( false );
75  m_rotation = StrToInt1Units( str );
76  }
77 
78  aNode->GetAttribute( wxT( "Name" ), &m_name.text );
79  m_name.text.Replace( "\r", "" );
80 
81  str = FindNodeGetContent( aNode, wxT( "justify" ) );
83 
84  str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
85 
86  if( str == wxT( "True" ) )
87  m_name.mirror = 1;
88 
89  lNode = FindNode( aNode, wxT( "textStyleRef" ) );
90 
91  if( lNode )
92  SetFontProperty( lNode, &m_name, aDefaultMeasurementUnit, aActualConversion );
93 }
94 
95 
96 void PCB_TEXT::AddToModule( MODULE* aModule )
97 {
98 }
99 
100 
102 {
106 
107  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
108  m_board->Add( pcbtxt, ADD_MODE::APPEND );
109 
110  pcbtxt->SetText( m_name.text );
111 
112  if( m_name.isTrueType )
114  else
116 
117  pcbtxt->SetItalic( m_name.isItalic );
119 
120  SetTextJustify( pcbtxt, m_name.justify );
122  m_name.textPositionY ) );
123 
124  pcbtxt->SetMirrored( m_name.mirror );
125 
126  if( pcbtxt->IsMirrored() )
127  pcbtxt->SetTextAngle( 3600.0 - m_name.textRotation );
128  else
129  pcbtxt->SetTextAngle( m_name.textRotation );
130 
131  pcbtxt->SetLayer( m_KiCadLayer );
132 }
133 
134 
135 // void PCB_TEXT::SetPosOffset( int aX_offs, int aY_offs )
136 // {
137 // PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
138 
139 // m_name.textPositionX += aX_offs;
140 // m_name.textPositionY += aY_offs;
141 // }
142 
143 } // namespace PCAD2KICAD
void SetMirrored(bool isMirrored)
Definition: eda_text.h:188
void SetTextAngle(double aAngle) override
bool IsMirrored() const
Definition: eda_text.h:189
void AddToBoard() override
Definition: pcb_text.cpp:101
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetItalic(bool isItalic)
Definition: eda_text.h:179
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:247
void SetTextSizeFromTrueTypeFontHeight(EDA_TEXT *aText, int aTextHeight)
PCB_LAYER_ID GetKiCadLayer()
Definition: pcb_component.h:73
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
Definition: pcb_text.cpp:50
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
void AddToModule(MODULE *aModule) override
Definition: pcb_text.cpp:96
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
PCB_TEXT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_text.cpp:38
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
void SetTextJustify(EDA_TEXT *aText, TTEXT_JUSTIFY aJustify)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
TTEXT_JUSTIFY GetJustifyIdentificator(const wxString &aJustify)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
The common library.
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.h:158
void SetTextSizeFromStrokeFontHeight(EDA_TEXT *aText, int aTextHeight)
int StrToInt1Units(const wxString &aStr)