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 #include <pgm_base.h>
46 
47 #include <class_board.h>
48 #include <class_pcb_text.h>
49 
50 
52  BOARD_ITEM( parent, PCB_TEXT_T ),
53  EDA_TEXT()
54 {
55  SetMultilineAllowed( true );
56 }
57 
58 
60 {
61 }
62 
63 
64 void TEXTE_PCB::SetTextAngle( double aAngle )
65 {
67 }
68 
69 
70 void TEXTE_PCB::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset )
71 {
72  BOARD* brd = GetBoard();
73 
74  if( brd->IsLayerVisible( m_Layer ) == false )
75  return;
76 
77  auto color = Pgm().GetSettingsManager().GetColorSettings()->GetColor( m_Layer );
78  EDA_DRAW_MODE_T fillmode = FILLED;
79  auto& displ_opts = aFrame->GetDisplayOptions();
80 
81  if( displ_opts.m_DisplayDrawItemsFill == SKETCH )
82  fillmode = SKETCH;
83 
84  EDA_TEXT::Print( DC, offset, color, fillmode );
85 }
86 
87 
88 void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
89 {
90  wxString msg;
91 
92  wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
93 
94  if( m_Parent->Type() == PCB_DIMENSION_T )
95  aList.emplace_back( _( "Dimension" ), GetShownText(), DARKGREEN );
96  else
97  aList.emplace_back( _( "PCB Text" ), GetShownText(), DARKGREEN );
98 
99  aList.emplace_back( _( "Layer" ), GetLayerName(), BLUE );
100 
101  if( !IsMirrored() )
102  aList.emplace_back( _( "Mirror" ), _( "No" ), DARKGREEN );
103  else
104  aList.emplace_back( _( "Mirror" ), _( "Yes" ), DARKGREEN );
105 
106  msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
107  aList.emplace_back( _( "Angle" ), msg, DARKGREEN );
108 
109  msg = MessageTextFromValue( aUnits, GetThickness() );
110  aList.emplace_back( _( "Thickness" ), msg, MAGENTA );
111 
112  msg = MessageTextFromValue( aUnits, GetTextWidth() );
113  aList.emplace_back( _( "Width" ), msg, RED );
114 
115  msg = MessageTextFromValue( aUnits, GetTextHeight() );
116  aList.emplace_back( _( "Height" ), msg, RED );
117 }
118 
119 
121 {
122  EDA_RECT rect = GetTextBox( -1, -1 );
123 
124  if( GetTextAngle() )
125  rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
126 
127  return rect;
128 }
129 
130 
131 void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
132 {
133  wxPoint pt = GetTextPos();
134  RotatePoint( &pt, aRotCentre, aAngle );
135  SetTextPos( pt );
136 
137  SetTextAngle( GetTextAngle() + aAngle );
138 }
139 
140 
141 void TEXTE_PCB::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
142 {
143  if( aFlipLeftRight )
144  SetTextX( aCentre.x - ( GetTextPos().x - aCentre.x ) );
145  else
146  SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
147 
148  int copperLayerCount = GetBoard()->GetCopperLayerCount();
149 
150  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
151  SetMirrored( !IsMirrored() );
152 
153  // adjust justified text for mirroring
155  {
157  SetTextX( GetTextPos().x - GetTextBox().GetWidth() );
158  else
159  SetTextX( GetTextPos().x + GetTextBox().GetWidth() );
160  }
161 }
162 
163 
164 wxString TEXTE_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
165 {
166  return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
167 }
168 
169 
171 {
172  return text_xpm;
173 }
174 
175 
177 {
178  return new TEXTE_PCB( *this );
179 }
180 
182 {
183  assert( aImage->Type() == PCB_TEXT_T );
184 
185  std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
186 }
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:184
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:183
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
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,...
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
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
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:100
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.h:180
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
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aUseMils, EDA_DATA_TYPE aType)
Definition: base_units.cpp:127
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:431
int GetTextWidth() const
Definition: eda_text.h:226
see class PGM_BASE
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:163
#define _(s)
Definition: 3d_actions.cpp:33
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:166
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:237
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:212