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.

199 lines
6.5 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-2022 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 FOOTPRINT;
  30. class MSG_PANEL_ITEM;
  31. class PCB_BASE_FRAME;
  32. class SHAPE;
  33. class FP_TEXT : public BOARD_ITEM, public EDA_TEXT
  34. {
  35. public:
  36. /**
  37. * Footprint text type: there must be only one (and only one) for each of the reference
  38. * value texts in one footprint; others could be added for the user (DIVERS is French for
  39. * 'others'). Reference and value always live on silkscreen (on the footprint side); other
  40. * texts are planned to go on whatever layer the user wants.
  41. */
  42. enum TEXT_TYPE
  43. {
  44. TEXT_is_REFERENCE = 0,
  45. TEXT_is_VALUE = 1,
  46. TEXT_is_DIVERS = 2
  47. };
  48. FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS );
  49. // Do not create a copy constructor & operator=.
  50. // The ones generated by the compiler are adequate.
  51. ~FP_TEXT();
  52. static inline bool ClassOf( const EDA_ITEM* aItem )
  53. {
  54. return aItem && aItem->Type() == PCB_FP_TEXT_T;
  55. }
  56. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
  57. {
  58. if( BOARD_ITEM::IsType( aScanTypes ) )
  59. return true;
  60. for( KICAD_T scanType : aScanTypes )
  61. {
  62. if( scanType == PCB_LOCATE_TEXT_T )
  63. return true;
  64. }
  65. return false;
  66. }
  67. wxString GetParentAsString() const;
  68. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  69. {
  70. return BOARD_ITEM::Matches( GetShownText(), aSearchData );
  71. }
  72. virtual VECTOR2I GetPosition() const override
  73. {
  74. return EDA_TEXT::GetTextPos();
  75. }
  76. virtual void SetPosition( const VECTOR2I& aPos ) override
  77. {
  78. EDA_TEXT::SetTextPos( aPos );
  79. SetLocalCoord();
  80. }
  81. /**
  82. * Called when rotating the parent footprint.
  83. */
  84. void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation );
  85. void Rotate( const VECTOR2I& aOffset, const EDA_ANGLE& aAngle ) override;
  86. /// Flip entity during footprint flip
  87. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  88. bool IsParentFlipped() const;
  89. /**
  90. * Mirror text position. Do not mirror the text itself, or change its layer.
  91. */
  92. void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
  93. void Move( const VECTOR2I& aMoveVector ) override;
  94. /// @deprecated it seems (but the type is used to 'protect' reference and value from deletion,
  95. /// and for identification)
  96. void SetType( TEXT_TYPE aType ) { m_Type = aType; }
  97. TEXT_TYPE GetType() const { return m_Type; }
  98. // The Pos0 accessors are for footprint-relative coordinates.
  99. void SetPos0( const VECTOR2I& aPos ) { m_Pos0 = aPos; SetDrawCoord(); }
  100. const VECTOR2I& GetPos0() const { return m_Pos0; }
  101. int GetLength() const; // text length
  102. /**
  103. * @return the text rotation for drawings and plotting the footprint rotation is taken
  104. * in account.
  105. */
  106. virtual EDA_ANGLE GetDrawRotation() const override;
  107. // Virtual function
  108. const BOX2I GetBoundingBox() const override;
  109. ///< Set absolute coordinates.
  110. void SetDrawCoord();
  111. ///< Set relative coordinates.
  112. void SetLocalCoord();
  113. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  114. bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
  115. bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
  116. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
  117. {
  118. return TextHitTest( aPosition, aAccuracy );
  119. }
  120. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
  121. {
  122. return TextHitTest( aRect, aContained, aAccuracy );
  123. }
  124. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  125. int aError, ERROR_LOC aErrorLoc,
  126. bool aIgnoreLineWidth ) const override;
  127. void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  128. int aError, ERROR_LOC aErrorLoc ) const;
  129. // @copydoc BOARD_ITEM::GetEffectiveShape
  130. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  131. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  132. wxString GetClass() const override
  133. {
  134. return wxT( "FP_TEXT" );
  135. }
  136. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  137. BITMAPS GetMenuImage() const override;
  138. EDA_ITEM* Clone() const override;
  139. virtual wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
  140. virtual const BOX2I ViewBBox() const override;
  141. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  142. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  143. #if defined(DEBUG)
  144. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  145. #endif
  146. private:
  147. TEXT_TYPE m_Type; ///< 0=ref, 1=val, etc.
  148. VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0.
  149. ///< text coordinate ref point is the text center
  150. };
  151. #endif // FP_TEXT_H