KiCad PCB EDA Suite
class_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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2015 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 
31 #include <fctsys.h>
32 #include <gr_basic.h>
33 #include <base_struct.h>
34 #include <gr_text.h>
35 #include <kicad_string.h>
36 #include <trigo.h>
37 #include <richio.h>
38 #include <macros.h>
39 #include <pcb_edit_frame.h>
40 #include <msgpanel.h>
41 #include <base_units.h>
42 #include <bitmaps.h>
43 
44 #include <class_board.h>
45 #include <class_pcb_text.h>
46 
47 
49  BOARD_ITEM( parent, PCB_TEXT_T ),
50  EDA_TEXT()
51 {
52  SetMultilineAllowed( true );
53 }
54 
55 
57 {
58 }
59 
60 
61 void TEXTE_PCB::SetTextAngle( double aAngle )
62 {
64 }
65 
66 
67 void TEXTE_PCB::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset )
68 {
69  BOARD* brd = GetBoard();
70 
71  if( brd->IsLayerVisible( m_Layer ) == false )
72  return;
73 
74  auto color = aFrame->Settings().Colors().GetLayerColor( m_Layer );
75  EDA_DRAW_MODE_T fillmode = FILLED;
76  auto& displ_opts = aFrame->GetDisplayOptions();
77 
78  if( displ_opts.m_DisplayDrawItemsFill == SKETCH )
79  fillmode = SKETCH;
80 
81  EDA_TEXT::Print( DC, offset, color, fillmode );
82 }
83 
84 
85 void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
86 {
87  wxString msg;
88 
89  wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
90 
91  if( m_Parent->Type() == PCB_DIMENSION_T )
92  aList.emplace_back( _( "Dimension" ), GetShownText(), DARKGREEN );
93  else
94  aList.emplace_back( _( "PCB Text" ), GetShownText(), DARKGREEN );
95 
96  aList.emplace_back( _( "Layer" ), GetLayerName(), BLUE );
97 
98  if( !IsMirrored() )
99  aList.emplace_back( _( "Mirror" ), _( "No" ), DARKGREEN );
100  else
101  aList.emplace_back( _( "Mirror" ), _( "Yes" ), DARKGREEN );
102 
103  msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
104  aList.emplace_back( _( "Angle" ), msg, DARKGREEN );
105 
106  msg = MessageTextFromValue( aUnits, GetThickness() );
107  aList.emplace_back( _( "Thickness" ), msg, MAGENTA );
108 
109  msg = MessageTextFromValue( aUnits, GetTextWidth() );
110  aList.emplace_back( _( "Width" ), msg, RED );
111 
112  msg = MessageTextFromValue( aUnits, GetTextHeight() );
113  aList.emplace_back( _( "Height" ), msg, RED );
114 }
115 
116 
118 {
119  EDA_RECT rect = GetTextBox( -1, -1 );
120 
121  if( GetTextAngle() )
122  rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
123 
124  return rect;
125 }
126 
127 
128 void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
129 {
130  wxPoint pt = GetTextPos();
131  RotatePoint( &pt, aRotCentre, aAngle );
132  SetTextPos( pt );
133 
134  SetTextAngle( GetTextAngle() + aAngle );
135 }
136 
137 
138 void TEXTE_PCB::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
139 {
140  if( aFlipLeftRight )
141  SetTextX( aCentre.x - ( GetTextPos().x - aCentre.x ) );
142  else
143  SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
144 
145  int copperLayerCount = GetBoard()->GetCopperLayerCount();
146 
147  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
148  SetMirrored( !IsMirrored() );
149 
150  // adjust justified text for mirroring
152  {
154  SetTextX( GetTextPos().x - GetTextBox().GetWidth() );
155  else
156  SetTextX( GetTextPos().x + GetTextBox().GetWidth() );
157  }
158 }
159 
160 
161 wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
162 {
163  return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
164 }
165 
166 
168 {
169  return text_xpm;
170 }
171 
172 
174 {
175  return new TEXTE_PCB( *this );
176 }
177 
179 {
180  assert( aImage->Type() == PCB_TEXT_T );
181 
182  std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
183 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
Definition: colors.h:57
EDA_UNITS
Definition: common.h:72
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
void SetTextAngle(double aAngle)
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:177
bool IsMirrored() const
Definition: eda_text.h:173
PNG memory record (file in memory).
Definition: bitmap_def.h:29
TEXTE_PCB class definition.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Implementation of conversion functions that require both schematic and board internal units.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:127
Definition: colors.h:61
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
int color
Definition: DXF_plotter.cpp:61
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:485
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
const BITMAP_OPAQUE text_xpm[1]
Definition: text.cpp:27
double GetTextAngle() const
Definition: eda_text.h:158
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
This file contains miscellaneous commonly used macros and functions.
int GetTextHeight() const
Definition: eda_text.h:229
void SetTextX(int aX)
Definition: eda_text.h:234
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:109
PCB_LAYER_ID m_Layer
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
#define NULL
PCB_GENERAL_SETTINGS & Settings()
EDA_DRAW_MODE_T
Definition: eda_text.h:59
EDA_RECT GetTextBox(int aLine=-1, int aThickness=-1, bool aInvertY=false, int aMarkupFlags=0) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:184
const EDA_RECT GetBoundingBoxRotated(wxPoint aRotCenter, double aAngle)
Function GetBoundingBoxRotated.
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:163
Definition: colors.h:60
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:99
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:180
COLORS_DESIGN_SETTINGS & Colors()
void Print(wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aDisplay_mode=FILLED)
Print this text object to the device context aDC.
Definition: eda_text.cpp:361
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &offset=ZeroOffset) override
Function Print BOARD_ITEMs have their own color information.
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:449
int GetTextWidth() const
Definition: eda_text.h:226
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
#define _(s)
Definition: 3d_actions.cpp:31
int GetCopperLayerCount() const
Function GetCopperLayerCount.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
virtual wxString GetShownText() const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:129
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
T NormalizeAngle360Min(T Angle)
Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0.
Definition: trigo.h:233
Message panel definition file.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void SetTextY(int aY)
Definition: eda_text.h:235
TEXTE_PCB(BOARD_ITEM *parent)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207