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 
35 namespace PCAD2KICAD {
36 
37 PCB_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 
49 void 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 );
74  m_rotation = StrToInt1Units( str );
75  }
76 
77  aNode->GetAttribute( wxT( "Name" ), &m_name.text );
78  m_name.text.Replace( "\r", "" );
79 
80  str = FindNodeGetContent( aNode, wxT( "justify" ) );
82 
83  str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
84 
85  if( str == wxT( "True" ) )
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 );
117  pcbtxt->SetTextThickness( m_name.textstrokeWidth );
118 
119  SetTextJustify( pcbtxt, m_name.justify );
120  pcbtxt->SetTextPos( wxPoint( m_name.textPositionX, m_name.textPositionY ) );
121 
122  pcbtxt->SetMirrored( m_name.mirror );
123 
124  if( pcbtxt->IsMirrored() )
125  pcbtxt->SetTextAngle( 3600.0 - m_name.textRotation );
126  else
127  pcbtxt->SetTextAngle( m_name.textRotation );
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
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, const wxString &aDefaultMeasurementUnit, 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:608
wxString FindNodeGetContent(XNODE *aChild, const wxString &aTag)
PCB_TEXT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
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)
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
int StrToInt1Units(const wxString &aStr)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)