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 <draw_graphic_text.h>
35 #include <kicad_string.h>
36 #include <trigo.h>
37 #include <richio.h>
38 #include <class_drawpanel.h>
39 #include <macros.h>
40 #include <pcb_edit_frame.h>
41 #include <msgpanel.h>
42 #include <base_units.h>
43 #include <bitmaps.h>
44 
45 #include <class_board.h>
46 #include <class_pcb_text.h>
47 
48 
50  BOARD_ITEM( parent, PCB_TEXT_T ),
51  EDA_TEXT()
52 {
53  SetMultilineAllowed( true );
54 }
55 
56 
58 {
59 }
60 
61 
62 void TEXTE_PCB::SetTextAngle( double aAngle )
63 {
65 }
66 
67 
68 void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
69  GR_DRAWMODE DrawMode, const wxPoint& offset )
70 {
71  wxASSERT( panel );
72 
73  if( !panel )
74  return;
75 
76  BOARD* brd = GetBoard();
77 
78  if( brd->IsLayerVisible( m_Layer ) == false )
79  return;
80 
81  auto frame = static_cast<PCB_EDIT_FRAME*>( panel->GetParent() );
82  auto color = frame->Settings().Colors().GetLayerColor( m_Layer );
83 
84  EDA_DRAW_MODE_T fillmode = FILLED;
85  PCB_DISPLAY_OPTIONS* displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
86 
87  if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
88  fillmode = SKETCH;
89 
90  // shade text if high contrast mode is active
91  if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
92  {
93  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
94 
95  if( !IsOnLayer( curr_layer ) )
97  }
98 
99  COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
100 
101  if( brd->IsElementVisible( LAYER_ANCHOR ) )
102  anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
103 
104  EDA_TEXT::Draw( panel->GetClipBox(), DC, offset, color,
105  DrawMode, fillmode, anchor_color );
106 
107  // Enable these line to draw the bounding box (debug tests purposes only)
108 #if 0
109  {
110  EDA_RECT BoundaryBox = GetBoundingBox();
111  GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
112  }
113 #endif
114 }
115 
116 
117 void TEXTE_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
118 {
119  wxString msg;
120 
121  wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
122 
123  if( m_Parent->Type() == PCB_DIMENSION_T )
124  aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
125  else
126  aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
127 
128  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
129 
130  if( !IsMirrored() )
131  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
132  else
133  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
134 
135  msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
136  aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
137 
138  msg = MessageTextFromValue( aUnits, GetThickness() );
139  aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
140 
141  msg = MessageTextFromValue( aUnits, GetTextWidth() );
142  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
143 
144  msg = MessageTextFromValue( aUnits, GetTextHeight() );
145  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
146 }
147 
148 
150 {
151  EDA_RECT rect = GetTextBox( -1, -1 );
152 
153  if( GetTextAngle() )
154  rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
155 
156  return rect;
157 }
158 
159 
160 void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
161 {
162  wxPoint pt = GetTextPos();
163  RotatePoint( &pt, aRotCentre, aAngle );
164  SetTextPos( pt );
165 
166  SetTextAngle( GetTextAngle() + aAngle );
167 }
168 
169 
170 void TEXTE_PCB::Flip( const wxPoint& aCentre )
171 {
172  SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
173 
174  int copperLayerCount = GetBoard()->GetCopperLayerCount();
175 
176  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
177  SetMirrored( !IsMirrored() );
178 }
179 
180 
182 {
183  return wxString::Format( _( "Pcb Text \"%s\" on %s"), ShortenedShownText(), GetLayerName() );
184 }
185 
186 
188 {
189  return text_xpm;
190 }
191 
192 
194 {
195  return new TEXTE_PCB( *this );
196 }
197 
199 {
200  assert( aImage->Type() == PCB_TEXT_T );
201 
202  std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
203 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:191
virtual BASE_SCREEN * GetScreen()=0
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
Definition: colors.h:57
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void SetTextAngle(double aAngle)
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:171
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:80
PNG memory record (file in memory).
Definition: bitmap_types.h:43
TEXTE_PCB class definition.
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
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...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
anchor of items having an anchor point (texts, footprints)
Class BOARD to handle a board.
Definition: colors.h:61
int color
Definition: DXF_plotter.cpp:62
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:472
int GetTextWidth() const
Definition: eda_text.h:231
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
virtual EDA_RECT * GetClipBox()
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
double GetTextAngle() const
Definition: eda_text.h:177
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:167
This file contains miscellaneous commonly used macros and functions.
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:148
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
virtual EDA_DRAW_FRAME * GetParent() const =0
PCB_LAYER_ID m_Layer
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_LAYER_ID
A quick note on layer IDs:
EDA_RECT GetTextBox(int aLine=-1, int aThickness=-1, bool aInvertY=false) const
Function GetTextBox useful in multiline texts to calculate the full text or a line area (for zones fi...
Definition: eda_text.cpp:103
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
EDA_DRAW_MODE_T
Definition: eda_text.h:77
const EDA_RECT GetBoundingBoxRotated(wxPoint aRotCenter, double aAngle)
Function GetBoundingBoxRotated.
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)
Function SetMultiLineAllowed.
Definition: eda_text.h:200
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
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
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
bool IsMirrored() const
Definition: eda_text.h:192
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
int GetTextHeight() const
Definition: eda_text.h:234
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
static const char * text_xpm[]
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Basic classes for most KiCad items.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
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:222
Message panel definition file.
EDA_UNITS_T
Definition: common.h:159
void SetTextY(int aY)
Definition: eda_text.h:240
void Draw(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aDisplay_mode=FILLED, COLOR4D aAnchor_color=COLOR4D::UNSPECIFIED)
Function Draw.
Definition: eda_text.cpp:280
TEXTE_PCB(BOARD_ITEM *parent)
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:457
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62