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 <richio.h>
39 #include <class_drawpanel.h>
40 #include <macros.h>
41 #include <wxPcbStruct.h>
42 #include <msgpanel.h>
43 #include <base_units.h>
44 #include <bitmaps.h>
45 
46 #include <class_board.h>
47 #include <class_pcb_text.h>
48 
49 
51  BOARD_ITEM( parent, PCB_TEXT_T ),
52  EDA_TEXT()
53 {
54  SetMultilineAllowed( true );
55 }
56 
57 
59 {
60 }
61 
62 
63 void TEXTE_PCB::SetTextAngle( double aAngle )
64 {
66 }
67 
68 
69 void TEXTE_PCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
70  GR_DRAWMODE DrawMode, const wxPoint& offset )
71 {
72  wxASSERT( panel );
73 
74  if( !panel )
75  return;
76 
77  BOARD* brd = GetBoard();
78 
79  if( brd->IsLayerVisible( m_Layer ) == false )
80  return;
81 
82  auto frame = static_cast<PCB_EDIT_FRAME*> ( panel->GetParent() );
83  auto color = frame->Settings().Colors().GetLayerColor( m_Layer );
84 
85  EDA_DRAW_MODE_T fillmode = FILLED;
86  PCB_DISPLAY_OPTIONS* displ_opts = nullptr;
87 
88  if( panel )
89  {
90  displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
91  }
92 
93  if( displ_opts && displ_opts->m_DisplayDrawItemsFill == SKETCH )
94  fillmode = SKETCH;
95 
96  // shade text if high contrast mode is active
97  if( ( DrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
98  {
99  PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
100 
101  if( !IsOnLayer( curr_layer ) )
103  }
104 
105  COLOR4D anchor_color = COLOR4D::UNSPECIFIED;
106 
107  if( brd->IsElementVisible( LAYER_ANCHOR ) )
108  anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
109 
110  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
111  EDA_TEXT::Draw( clipbox, DC, offset, color,
112  DrawMode, fillmode, anchor_color );
113 
114  // Enable these line to draw the bounding box (debug tests purposes only)
115 #if 0
116  {
117  EDA_RECT BoundaryBox = GetBoundingBox();
118  GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
119  }
120 #endif
121 }
122 
123 
124 void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
125 {
126  wxString msg;
127 
128  wxCHECK_RET( m_Parent != NULL, wxT( "TEXTE_PCB::GetMsgPanelInfo() m_Parent is NULL." ) );
129 
130  if( m_Parent->Type() == PCB_DIMENSION_T )
131  aList.push_back( MSG_PANEL_ITEM( _( "Dimension" ), GetShownText(), DARKGREEN ) );
132  else
133  aList.push_back( MSG_PANEL_ITEM( _( "PCB Text" ), GetShownText(), DARKGREEN ) );
134 
135  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BLUE ) );
136 
137  if( !IsMirrored() )
138  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "No" ), DARKGREEN ) );
139  else
140  aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
141 
142  msg.Printf( wxT( "%.1f" ), GetTextAngle() / 10.0 );
143  aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
144 
146  aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, MAGENTA ) );
147 
149  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
150 
152  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
153 }
154 
155 
157 {
158  EDA_RECT rect = GetTextBox( -1, -1 );
159 
160  if( GetTextAngle() )
161  rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() );
162 
163  return rect;
164 }
165 
166 
167 void TEXTE_PCB::Rotate( const wxPoint& aRotCentre, double aAngle )
168 {
169  wxPoint pt = GetTextPos();
170  RotatePoint( &pt, aRotCentre, aAngle );
171  SetTextPos( pt );
172 
173  SetTextAngle( GetTextAngle() + aAngle );
174 }
175 
176 
177 void TEXTE_PCB::Flip( const wxPoint& aCentre )
178 {
179  SetTextY( aCentre.y - ( GetTextPos().y - aCentre.y ) );
180 
181  int copperLayerCount = GetBoard()->GetCopperLayerCount();
182 
183  SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
184  SetMirrored( !IsMirrored() );
185 }
186 
187 
189 {
190  wxString text;
191 
192  text.Printf( _( "Pcb Text \"%s\" on %s"),
194 
195  return text;
196 }
197 
198 
200 {
201  return text_xpm;
202 }
203 
204 
206 {
207  return new TEXTE_PCB( *this );
208 }
209 
211 {
212  assert( aImage->Type() == PCB_TEXT_T );
213 
214  std::swap( *((TEXTE_PCB*) this), *((TEXTE_PCB*) aImage) );
215 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition: colors.h:57
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
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:212
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:182
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:79
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.
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
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:445
int GetTextWidth() const
Definition: eda_text.h:218
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: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:92
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
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
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
PCB_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:1076
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:102
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.
EDA_RECT * GetClipBox()
Definition: colors.h:60
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
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:187
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
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:169
bool IsMirrored() const
Definition: eda_text.h:179
Class EDA_RECT handles the component boundary box.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
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.
static const char * text_xpm[]
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:181
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.
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:279
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:451
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62