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 <wxstruct.h>
33 #include <gr_basic.h>
34 #include <base_struct.h>
35 #include <drawtxt.h>
36 #include <kicad_string.h>
37 #include <trigo.h>
38 #include <colors_selection.h>
39 #include <richio.h>
40 #include <class_drawpanel.h>
41 #include <macros.h>
42 #include <wxBasePcbFrame.h>
43 #include <msgpanel.h>
44 #include <base_units.h>
45 #include <bitmaps.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::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
71  GR_DRAWMODE DrawMode, const wxPoint& offset )
72 {
73  BOARD* brd = GetBoard();
74 
75  if( brd->IsLayerVisible( m_Layer ) == false )
76  return;
77 
78  COLOR4D color = brd->GetLayerColor( m_Layer );
79 
80  EDA_DRAW_MODE_T fillmode = FILLED;
81  DISPLAY_OPTIONS* displ_opts =
82  panel ? (DISPLAY_OPTIONS*)panel->GetDisplayOptions() : NULL;
83 
84  if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
85  fillmode = SKETCH;
86 
87  // shade text if high contrast mode is active
88  if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
89  {
90  LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
91 
92  if( !IsOnLayer( curr_layer ) )
93  color = COLOR4D( DARKDARKGRAY );
94  }
95 
96  COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
97 
98  if( brd->IsElementVisible( ANCHOR_VISIBLE ) )
99  anchor_color = brd->GetVisibleElementColor( ANCHOR_VISIBLE );
100 
101  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
102  EDA_TEXT::Draw( clipbox, DC, offset, color,
103  DrawMode, fillmode, anchor_color );
104 
105  // Enable these line to draw the bounding box (debug tests purposes only)
106 #if 0
107  {
108  EDA_RECT BoundaryBox = GetBoundingBox();
109  GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
110  }
111 #endif
112 }
113 
114 
115 void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
116 {
117  wxString msg;
118 
119  wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
120 
121  if( m_Parent->Type() == PCB_DIMENSION_T )
122  aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
123  else
124  aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
125 
126  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
127 
128  if( !IsMirrored() )
129  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
130  else
131  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
132 
133  msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
134  aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
135 
137  aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
138 
140  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
141 
143  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
144 }
145 
146 
148 {
149  EDA_RECT rect = GetTextBox( -1, -1 );
150 
151  if( GetTextAngle() )
152  rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
153 
154  return rect;
155 }
156 
157 
158 void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
159 {
160  wxPoint pt = GetTextPos();
161  RotatePoint( &pt, aRotCentre, aAngle );
162  SetTextPos( pt );
163 
164  SetTextAngle( GetTextAngle() + aAngle );
165 }
166 
167 
168 void TEXTE_PCB::Flip( const wxPoint& aCentre )
169 {
170  SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
171 
172  int copperLayerCount = GetBoard()->GetCopperLayerCount();
173 
174  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
175  SetMirrored( !IsMirrored() );
176 }
177 
178 
180 {
181  wxString text;
182 
183  text.Printf( _( "Pcb Text \"%s\" on %s"),
185 
186  return text;
187 }
188 
189 
191 {
192  return add_text_xpm;
193 }
194 
195 
197 {
198  return new TEXTE_PCB( *this );
199 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition: colors.h:57
wxString CoordinateToString(int aValue, bool aConvertToMils)
Function CoordinateToString is a helper to convert the integer coordinate aValue to a string in inche...
Definition: base_units.cpp:117
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void SetTextAngle(double aAngle)
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:168
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:92
PNG memory record (file in memory).
Definition: bitmap_types.h:38
TEXTE_PCB class definition.
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
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...
Class BOARD to handle a board.
Definition: colors.h:61
int GetTextWidth() const
Definition: eda_text.h:218
COLOR4D GetLayerColor(LAYER_ID aLayer) const
Function GetLayerColor gets a layer color for any valid layer, including non-copper ones...
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
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:223
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:104
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
double GetTextAngle() const
Definition: eda_text.h:164
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:154
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:135
virtual bool IsOnLayer(LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
LAYER_ID m_Layer
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
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:115
Classes used in Pcbnew, CvPcb and GerbView.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
Base window classes and related definitions.
EDA_DRAW_MODE_T
Definition: eda_text.h:62
const EDA_RECT GetBoundingBoxRotated(wxPoint aRotCenter, double aAngle)
Function GetBoundingBoxRotated.
bool m_ContrastModeDisplay
Definition: pcbstruct.h:85
bool m_DisplayDrawItemsFill
Definition: pcbstruct.h:84
EDA_RECT * GetClipBox()
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:112
void SetMultilineAllowed(bool aAllow)
Function SetMultiLineAllowed.
Definition: eda_text.h:187
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
bool IsLayerVisible(LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:440
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID FlipLayer(LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:444
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
bool IsMirrored() const
Definition: eda_text.h:179
bool IsElementVisible(int aPCB_VISIBLE) const
Function IsElementVisible tests whether a given element category is visible.
COLOR4D GetVisibleElementColor(int aPCB_VISIBLE)
Function GetVisibleElementColor returns the color of a pcb visible element.
Class EDA_RECT handles the component boundary box.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
int GetTextHeight() const
Definition: eda_text.h:221
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
This file is part of the common libary.
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:182
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
Message panel definition file.
void SetTextY(int aY)
Definition: eda_text.h:227
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:292
T NormalizeAngle360(T Angle)
Normalize angle to be in the -360.0 .. 360.0:
Definition: trigo.h:202
TEXTE_PCB(BOARD_ITEM *parent)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62