1 /* 2 * This program source code file is part of KiCad, a free EDA CAD application. 3 * 4 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com 5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, you may find one here: 19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 * or you may search the http://www.gnu.org website for the version 2 license, 21 * or you may write to the Free Software Foundation, Inc., 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 23 */ 24 25 #ifndef FP_TEXT_H 26 #define FP_TEXT_H 27 28 #include <eda_text.h> 29 #include <board_item.h> 30 31 class LINE_READER; 32 class EDA_RECT; 33 class FOOTPRINT; 34 class MSG_PANEL_ITEM; 35 class PCB_BASE_FRAME; 36 class SHAPE; 37 38 39 class FP_TEXT : public BOARD_ITEM, public EDA_TEXT 40 { 41 public: 42 /** 43 * Footprint text type: there must be only one (and only one) for each of the reference 44 * value texts in one footprint; others could be added for the user (DIVERS is French for 45 * 'others'). Reference and value always live on silkscreen (on the footprint side); other 46 * texts are planned to go on whatever layer the user wants. 47 */ 48 enum TEXT_TYPE 49 { 50 TEXT_is_REFERENCE = 0, 51 TEXT_is_VALUE = 1, 52 TEXT_is_DIVERS = 2 53 }; 54 55 FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS ); 56 57 // Do not create a copy constructor & operator=. 58 // The ones generated by the compiler are adequate. 59 60 ~FP_TEXT(); 61 ClassOf(const EDA_ITEM * aItem)62 static inline bool ClassOf( const EDA_ITEM* aItem ) 63 { 64 return aItem && aItem->Type() == PCB_FP_TEXT_T; 65 } 66 IsType(const KICAD_T aScanTypes[])67 bool IsType( const KICAD_T aScanTypes[] ) const override 68 { 69 if( BOARD_ITEM::IsType( aScanTypes ) ) 70 return true; 71 72 for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) 73 { 74 if( *p == PCB_LOCATE_TEXT_T ) 75 return true; 76 } 77 78 return false; 79 } 80 GetParentAsString()81 wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); } 82 Matches(const wxFindReplaceData & aSearchData,void * aAuxData)83 bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override 84 { 85 return BOARD_ITEM::Matches( GetShownText(), aSearchData ); 86 } 87 GetPosition()88 virtual wxPoint GetPosition() const override 89 { 90 return EDA_TEXT::GetTextPos(); 91 } 92 SetPosition(const wxPoint & aPos)93 virtual void SetPosition( const wxPoint& aPos ) override 94 { 95 EDA_TEXT::SetTextPos( aPos ); 96 SetLocalCoord(); 97 } 98 99 void SetTextAngle( double aAngle ) override; 100 101 /** 102 * Called when rotating the parent footprint. 103 */ 104 void KeepUpright( double aOldOrientation, double aNewOrientation ); 105 106 /** 107 * @return force the text rotation to be always between -90 .. 90 deg. Otherwise the text 108 * is not easy to read if false, the text rotation is free. 109 */ IsKeepUpright()110 bool IsKeepUpright() const 111 { 112 return m_keepUpright; 113 } 114 SetKeepUpright(bool aKeepUpright)115 void SetKeepUpright( bool aKeepUpright ) 116 { 117 m_keepUpright = aKeepUpright; 118 } 119 120 /// Rotate text, in footprint editor 121 /// (for instance in footprint rotation transform) 122 void Rotate( const wxPoint& aOffset, double aAngle ) override; 123 124 /// Flip entity during footprint flip 125 void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override; 126 127 bool IsParentFlipped() const; 128 129 /// Mirror text position in footprint editing 130 /// the text itself is not mirrored, and the layer not modified, 131 /// only position is mirrored. 132 /// (use Flip to change layer to its paired and mirror the text in fp editor). 133 void Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis ); 134 135 /// move text in move transform, in footprint editor 136 void Move( const wxPoint& aMoveVector ) override; 137 138 /// @deprecated it seems (but the type is used to 'protect' 139 // reference and value from deletion, and for identification) SetType(TEXT_TYPE aType)140 void SetType( TEXT_TYPE aType ) { m_Type = aType; } GetType()141 TEXT_TYPE GetType() const { return m_Type; } 142 143 /** 144 * Set the text effects from another instance. 145 */ SetEffects(const FP_TEXT & aSrc)146 void SetEffects( const FP_TEXT& aSrc ) 147 { 148 EDA_TEXT::SetEffects( aSrc ); 149 SetLocalCoord(); 150 // SetType( aSrc.GetType() ); 151 } 152 153 /** 154 * Swap the text effects of the two involved instances. 155 */ SwapEffects(FP_TEXT & aTradingPartner)156 void SwapEffects( FP_TEXT& aTradingPartner ) 157 { 158 EDA_TEXT::SwapEffects( aTradingPartner ); 159 SetLocalCoord(); 160 aTradingPartner.SetLocalCoord(); 161 // std::swap( m_Type, aTradingPartner.m_Type ); 162 } 163 164 // The Pos0 accessors are for footprint-relative coordinates. SetPos0(const wxPoint & aPos)165 void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; SetDrawCoord(); } GetPos0()166 const wxPoint& GetPos0() const { return m_Pos0; } 167 168 int GetLength() const; // text length 169 170 /** 171 * @return the text rotation for drawings and plotting the footprint rotation is taken 172 * in account. 173 */ 174 virtual double GetDrawRotation() const override; GetDrawRotationRadians()175 double GetDrawRotationRadians() const { return GetDrawRotation() * M_PI/1800; } 176 177 // Virtual function 178 const EDA_RECT GetBoundingBox() const override; 179 180 ///< Set absolute coordinates. 181 void SetDrawCoord(); 182 183 ///< Set relative coordinates. 184 void SetLocalCoord(); 185 186 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override; 187 188 bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const override; 189 bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const override; 190 HitTest(const wxPoint & aPosition,int aAccuracy)191 bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override 192 { 193 return TextHitTest( aPosition, aAccuracy ); 194 } 195 196 bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override 197 { 198 return TextHitTest( aRect, aContained, aAccuracy ); 199 } 200 201 void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, PCB_LAYER_ID aLayer, 202 int aClearance, int aError, ERROR_LOC aErrorLoc, 203 bool aIgnoreLineWidth ) const override; 204 205 void TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, 206 PCB_LAYER_ID aLayer, int aClearanceValue, 207 int aError, ERROR_LOC aErrorLoc ) const; 208 209 // @copydoc BOARD_ITEM::GetEffectiveShape 210 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override; 211 GetClass()212 wxString GetClass() const override 213 { 214 return wxT( "MTEXT" ); 215 } 216 217 wxString GetSelectMenuText( EDA_UNITS aUnits ) const override; 218 219 BITMAPS GetMenuImage() const override; 220 221 EDA_ITEM* Clone() const override; 222 223 virtual wxString GetShownText( int aDepth = 0 ) const override; 224 225 virtual const BOX2I ViewBBox() const override; 226 227 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; 228 229 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; 230 231 #if defined(DEBUG) Show(int nestLevel,std::ostream & os)232 virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } 233 #endif 234 235 private: 236 /* Note: orientation in 1/10 deg relative to the footprint 237 * Physical orient is m_Orient + m_Parent->m_Orient 238 */ 239 240 TEXT_TYPE m_Type; ///< 0=ref, 1=val, etc. 241 242 wxPoint m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0. 243 ///< text coordinate ref point is the text center 244 245 bool m_keepUpright; ///< if true, keep rotation angle between -90 .. 90 deg. 246 ///< to keep the text more easy to read 247 248 }; 249 250 #endif // FP_TEXT_H 251