You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.9 KiB

Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
  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. #ifndef FP_TEXT_H
  25. #define FP_TEXT_H
  26. #include <eda_text.h>
  27. #include <board_item.h>
  28. class LINE_READER;
  29. class EDA_RECT;
  30. class FOOTPRINT;
  31. class MSG_PANEL_ITEM;
  32. class PCB_BASE_FRAME;
  33. class SHAPE;
  34. class FP_TEXT : public BOARD_ITEM, public EDA_TEXT
  35. {
  36. public:
  37. /**
  38. * Footprint text type: there must be only one (and only one) for each of the reference
  39. * value texts in one footprint; others could be added for the user (DIVERS is French for
  40. * 'others'). Reference and value always live on silkscreen (on the footprint side); other
  41. * texts are planned to go on whatever layer the user wants.
  42. */
  43. enum TEXT_TYPE
  44. {
  45. TEXT_is_REFERENCE = 0,
  46. TEXT_is_VALUE = 1,
  47. TEXT_is_DIVERS = 2
  48. };
  49. FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS );
  50. // Do not create a copy constructor & operator=.
  51. // The ones generated by the compiler are adequate.
  52. ~FP_TEXT();
  53. static inline bool ClassOf( const EDA_ITEM* aItem )
  54. {
  55. return aItem && aItem->Type() == PCB_FP_TEXT_T;
  56. }
  57. bool IsType( const KICAD_T aScanTypes[] ) const override
  58. {
  59. if( BOARD_ITEM::IsType( aScanTypes ) )
  60. return true;
  61. for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
  62. {
  63. if( *p == PCB_LOCATE_TEXT_T )
  64. return true;
  65. }
  66. return false;
  67. }
  68. wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); }
  69. bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override
  70. {
  71. return BOARD_ITEM::Matches( GetShownText(), aSearchData );
  72. }
  73. virtual VECTOR2I GetPosition() const override
  74. {
  75. return EDA_TEXT::GetTextPos();
  76. }
  77. virtual void SetPosition( const VECTOR2I& aPos ) override
  78. {
  79. EDA_TEXT::SetTextPos( aPos );
  80. SetLocalCoord();
  81. }
  82. /**
  83. * Called when rotating the parent footprint.
  84. */
  85. void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation );
  86. /// Rotate text, in footprint editor
  87. /// (for instance in footprint rotation transform)
  88. void Rotate( const VECTOR2I& aOffset, const EDA_ANGLE& aAngle ) override;
  89. /// Flip entity during footprint flip
  90. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  91. bool IsParentFlipped() const;
  92. /// Mirror text position in footprint editing
  93. /// the text itself is not mirrored, and the layer not modified,
  94. /// only position is mirrored.
  95. /// (use Flip to change layer to its paired and mirror the text in fp editor).
  96. void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
  97. /// move text in move transform, in footprint editor
  98. void Move( const VECTOR2I& aMoveVector ) override;
  99. /// @deprecated it seems (but the type is used to 'protect'
  100. // reference and value from deletion, and for identification)
  101. void SetType( TEXT_TYPE aType ) { m_Type = aType; }
  102. TEXT_TYPE GetType() const { return m_Type; }
  103. // The Pos0 accessors are for footprint-relative coordinates.
  104. void SetPos0( const VECTOR2I& aPos ) { m_Pos0 = aPos; SetDrawCoord(); }
  105. const VECTOR2I& GetPos0() const { return m_Pos0; }
  106. int GetLength() const; // text length
  107. /**
  108. * @return the text rotation for drawings and plotting the footprint rotation is taken
  109. * in account.
  110. */
  111. virtual EDA_ANGLE GetDrawRotation() const override;
  112. // Virtual function
  113. const EDA_RECT GetBoundingBox() const override;
  114. ///< Set absolute coordinates.
  115. void SetDrawCoord();
  116. ///< Set relative coordinates.
  117. void SetLocalCoord();
  118. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  119. bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
  120. bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const override;
  121. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
  122. {
  123. return TextHitTest( aPosition, aAccuracy );
  124. }
  125. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
  126. {
  127. return TextHitTest( aRect, aContained, aAccuracy );
  128. }
  129. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, PCB_LAYER_ID aLayer,
  130. int aClearance, int aError, ERROR_LOC aErrorLoc,
  131. bool aIgnoreLineWidth ) const override;
  132. void TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  133. PCB_LAYER_ID aLayer, int aClearanceValue,
  134. int aError, ERROR_LOC aErrorLoc ) const;
  135. // @copydoc BOARD_ITEM::GetEffectiveShape
  136. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  137. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  138. wxString GetClass() const override
  139. {
  140. return wxT( "FP_TEXT" );
  141. }
  142. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  143. BITMAPS GetMenuImage() const override;
  144. EDA_ITEM* Clone() const override;
  145. virtual wxString GetShownText( int aDepth = 0 ) const override;
  146. virtual const BOX2I ViewBBox() const override;
  147. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  148. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  149. #if defined(DEBUG)
  150. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  151. #endif
  152. private:
  153. TEXT_TYPE m_Type; ///< 0=ref, 1=val, etc.
  154. VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0.
  155. ///< text coordinate ref point is the text center
  156. };
  157. #endif // FP_TEXT_H