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 <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 
26 #include <wx/wx.h>
27 
28 #include <common.h>
29 #include <pcb_text.h>
30 #include <plugins/pcad/pcb_text.h>
31 
32 namespace PCAD2KICAD {
33 
34 PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
35  PCB_COMPONENT( aCallbacks, aBoard )
36 {
37  m_objType = wxT( 'T' );
38 }
39 
40 
42 {
43 }
44 
45 
46 void PCB_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultMeasurementUnit,
47  const wxString& aActualConversion )
48 {
49  XNODE* lNode;
50  wxString str;
51 
52  m_PCadLayer = aLayer;
54  m_positionX = 0;
55  m_positionY = 0;
56  m_name.mirror = 0; // Normal, not mirrored
57  lNode = FindNode( aNode, wxT( "pt" ) );
58 
59  if( lNode )
60  {
61  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_positionX, &m_positionY,
62  aActualConversion );
63  }
64 
65  lNode = FindNode( aNode, wxT( "rotation" ) );
66 
67  if( lNode )
68  {
69  str = lNode->GetNodeContent();
70  str.Trim( false );
71  m_rotation = StrToInt1Units( str );
72  }
73 
74  aNode->GetAttribute( wxT( "Name" ), &m_name.text );
75  m_name.text.Replace( "\r", "" );
76 
77  str = FindNodeGetContent( aNode, wxT( "justify" ) );
79 
80  str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
81 
82  if( str == wxT( "True" ) )
83  m_name.mirror = 1;
84 
85  lNode = FindNode( aNode, wxT( "textStyleRef" ) );
86 
87  if( lNode )
88  SetFontProperty( lNode, &m_name, aDefaultMeasurementUnit, aActualConversion );
89 }
90 
91 
93 {
94 }
95 
96 
98 {
102 
103  ::PCB_TEXT* pcbtxt = new ::PCB_TEXT( m_board );
104  m_board->Add( pcbtxt, ADD_MODE::APPEND );
105 
106  pcbtxt->SetText( m_name.text );
107 
108  if( m_name.isTrueType )
110  else
112 
113  pcbtxt->SetItalic( m_name.isItalic );
114  pcbtxt->SetTextThickness( m_name.textstrokeWidth );
115 
116  SetTextJustify( pcbtxt, m_name.justify );
117  pcbtxt->SetTextPos( wxPoint( m_name.textPositionX, m_name.textPositionY ) );
118 
119  pcbtxt->SetMirrored( m_name.mirror );
120 
121  if( pcbtxt->IsMirrored() )
122  pcbtxt->SetTextAngle( 3600.0 - m_name.textRotation );
123  else
124  pcbtxt->SetTextAngle( m_name.textRotation );
125 
126  pcbtxt->SetLayer( m_KiCadLayer );
127 }
128 
129 
130 // void PCB_TEXT::SetPosOffset( int aX_offs, int aY_offs )
131 // {
132 // PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
133 
134 // m_name.textPositionX += aX_offs;
135 // m_name.textPositionY += aY_offs;
136 // }
137 
138 } // namespace PCAD2KICAD
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void AddToFootprint(FOOTPRINT *aFootprint) override
void SetTextSizeFromTrueTypeFontHeight(EDA_TEXT *aText, int aTextHeight)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
PCB_TEXT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:70
Hold an XML or S-expression element.
Definition: xnode.h:43
void SetTextJustify(EDA_TEXT *aText, TTEXT_JUSTIFY aJustify)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
TTEXT_JUSTIFY GetJustifyIdentificator(const wxString &aJustify)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
The common library.
void SetTextSizeFromStrokeFontHeight(EDA_TEXT *aText, int aTextHeight)
int StrToInt1Units(const wxString &aStr)