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 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 #include <wx/config.h>
32 
33 #include <common.h>
34 
35 #include <pcb_text.h>
36 
37 namespace PCAD2KICAD {
38 
39 PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
40  aBoard )
41 {
42  m_objType = wxT( 'T' );
43 }
44 
45 
47 {
48 }
49 
50 
51 void PCB_TEXT::Parse( XNODE* aNode,
52  int aLayer,
53  wxString aDefaultMeasurementUnit,
54  wxString aActualConversion )
55 {
56  XNODE* lNode;
57  wxString str;
58 
59  m_PCadLayer = aLayer;
61  m_positionX = 0;
62  m_positionY = 0;
63  m_name.mirror = 0; // Normal, not mirrored
64  lNode = FindNode( aNode, wxT( "pt" ) );
65 
66  if( lNode )
67  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
68  &m_positionX, &m_positionY, aActualConversion );
69 
70  lNode = FindNode( aNode, wxT( "rotation" ) );
71 
72  if( lNode )
73  {
74  str = lNode->GetNodeContent();
75  str.Trim( false );
76  m_rotation = StrToInt1Units( str );
77  }
78 
79  aNode->GetAttribute( wxT( "Name" ), &m_name.text );
80  m_name.text.Replace( "\r", "" );
81 
82  str = FindNodeGetContent( aNode, wxT( "justify" ) );
84 
85  str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
86 
87  if( str == wxT( "True" ) )
88  m_name.mirror = 1;
89 
90  lNode = FindNode( aNode, wxT( "textStyleRef" ) );
91 
92  if( lNode )
93  SetFontProperty( lNode, &m_name, aDefaultMeasurementUnit, aActualConversion );
94 }
95 
96 
97 void PCB_TEXT::AddToModule( MODULE* aModule )
98 {
99 }
100 
101 
103 {
107 
108  TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
109  m_board->Add( pcbtxt, ADD_APPEND );
110 
111  pcbtxt->SetText( m_name.text );
112 
113  if( m_name.isTrueType )
115  else
117 
118  pcbtxt->SetItalic( m_name.isItalic );
120  pcbtxt->SetTextAngle( m_name.textRotation );
121 
122  SetTextJustify( pcbtxt, m_name.justify );
124  m_name.textPositionY ) );
125 
126  pcbtxt->SetMirrored( m_name.mirror );
127  pcbtxt->SetTimeStamp( 0 );
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 SetMirrored(bool isMirrored)
Definition: eda_text.h:178
void SetTextAngle(double aAngle)
virtual void Parse(XNODE *aNode, int aLayer, wxString aDefaultMeasurementUnit, wxString aActualConversion)
Definition: pcb_text.cpp:51
void AddToBoard() override
Definition: pcb_text.cpp:102
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
int StrToInt1Units(wxString aStr)
TTEXT_JUSTIFY GetJustifyIdentificator(wxString aJustify)
void SetItalic(bool isItalic)
Definition: eda_text.h:169
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
void SetTextSizeFromTrueTypeFontHeight(EDA_TEXT *aText, int aTextHeight)
PCB_LAYER_ID GetKiCadLayer()
Definition: pcb_component.h:73
wxString FindNodeGetContent(XNODE *aChild, wxString aTag)
void AddToModule(MODULE *aModule) override
Definition: pcb_text.cpp:97
PCB_TEXT(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_text.cpp:39
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
void SetPosition(wxString aStr, wxString aDefaultMeasurementUnit, int *aX, int *aY, wxString aActualConversion)
void SetFontProperty(XNODE *aNode, TTEXTVALUE *aTextValue, wxString aDefaultMeasurementUnit, wxString aActualConversion)
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
void SetTextJustify(EDA_TEXT *aText, TTEXT_JUSTIFY aJustify)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
The common library.
XNODE * FindNode(XNODE *aChild, wxString aTag)
void SetTextSizeFromStrokeFontHeight(EDA_TEXT *aText, int aTextHeight)
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:230
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141