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.

605 lines
16 KiB

10 years ago
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
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
9 years ago
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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2019 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. /**
  26. * @file class_module.cpp
  27. * @brief TEXT_MODULE class implementation.
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <trigo.h>
  32. #include <class_drawpanel.h>
  33. #include <draw_graphic_text.h>
  34. #include <kicad_string.h>
  35. #include <richio.h>
  36. #include <macros.h>
  37. #include <pcb_edit_frame.h>
  38. #include <msgpanel.h>
  39. #include <base_units.h>
  40. #include <bitmaps.h>
  41. #include <class_board.h>
  42. #include <class_module.h>
  43. #include <view/view.h>
  44. #include <pcbnew.h>
  45. TEXTE_MODULE::TEXTE_MODULE( MODULE* parent, TEXT_TYPE text_type ) :
  46. BOARD_ITEM( parent, PCB_MODULE_TEXT_T ),
  47. EDA_TEXT()
  48. {
  49. MODULE* module = static_cast<MODULE*>( m_Parent );
  50. m_Type = text_type;
  51. m_keepUpright = true;
  52. // Set text thickness to a default value
  53. SetThickness( Millimeter2iu( DEFAULT_TEXT_WIDTH ) );
  54. SetLayer( F_SilkS );
  55. // Set position and give a default layer if a valid parent footprint exists
  56. if( module && ( module->Type() == PCB_MODULE_T ) )
  57. {
  58. SetTextPos( module->GetPosition() );
  59. if( IsBackLayer( module->GetLayer() ) )
  60. {
  61. SetLayer( B_SilkS );
  62. SetMirrored( true );
  63. }
  64. }
  65. SetDrawCoord();
  66. }
  67. TEXTE_MODULE::~TEXTE_MODULE()
  68. {
  69. }
  70. void TEXTE_MODULE::SetTextAngle( double aAngle )
  71. {
  72. EDA_TEXT::SetTextAngle( NormalizeAngle360Min( aAngle ) );
  73. }
  74. bool TEXTE_MODULE::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
  75. {
  76. EDA_RECT rect = GetTextBox( -1 );
  77. wxPoint location = aPoint;
  78. rect.Inflate( aAccuracy );
  79. RotatePoint( &location, GetTextPos(), -GetDrawRotation() );
  80. return rect.Contains( location );
  81. }
  82. bool TEXTE_MODULE::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const
  83. {
  84. EDA_RECT rect = aRect;
  85. rect.Inflate( aAccuracy );
  86. if( aContains )
  87. {
  88. return rect.Contains( GetBoundingBox() );
  89. }
  90. else
  91. {
  92. return rect.Intersects( GetTextBox( -1 ), GetDrawRotation() );
  93. }
  94. }
  95. void TEXTE_MODULE::KeepUpright( double aOldOrientation, double aNewOrientation )
  96. {
  97. if( !IsKeepUpright() )
  98. return;
  99. double currentAngle = GetTextAngle() + aOldOrientation;
  100. double newAngle = GetTextAngle() + aNewOrientation;
  101. NORMALIZE_ANGLE_POS( currentAngle );
  102. NORMALIZE_ANGLE_POS( newAngle );
  103. bool isFlipped = currentAngle >= 1800.0;
  104. bool needsFlipped = newAngle >= 1800.0;
  105. if( isFlipped != needsFlipped )
  106. {
  107. if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
  108. SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
  109. else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
  110. SetHorizJustify(GR_TEXT_HJUSTIFY_LEFT );
  111. SetTextAngle( GetTextAngle() + 1800.0 );
  112. SetDrawCoord();
  113. }
  114. }
  115. void TEXTE_MODULE::Rotate( const wxPoint& aRotCentre, double aAngle )
  116. {
  117. // Used in footprint editing
  118. // Note also in module editor, m_Pos0 = m_Pos
  119. wxPoint pt = GetTextPos();
  120. RotatePoint( &pt, aRotCentre, aAngle );
  121. SetTextPos( pt );
  122. SetTextAngle( GetTextAngle() + aAngle );
  123. SetLocalCoord();
  124. }
  125. void TEXTE_MODULE::Flip( const wxPoint& aCentre )
  126. {
  127. // flipping the footprint is relative to the X axis
  128. SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
  129. SetTextAngle( -GetTextAngle() );
  130. SetLayer( FlipLayer( GetLayer() ) );
  131. SetMirrored( IsBackLayer( GetLayer() ) );
  132. SetLocalCoord();
  133. // adjust justified text for mirroring
  134. if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT || GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
  135. {
  136. if( ( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT ) == IsMirrored() )
  137. SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() );
  138. else
  139. SetHorizJustify( (EDA_TEXT_HJUSTIFY_T)-GetHorizJustify() );
  140. SetDrawCoord();
  141. }
  142. }
  143. bool TEXTE_MODULE::IsParentFlipped() const
  144. {
  145. if( GetParent() && GetParent()->GetLayer() == B_Cu )
  146. return true;
  147. return false;
  148. }
  149. void TEXTE_MODULE::Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis )
  150. {
  151. // Used in modedit, to transform the footprint
  152. // the mirror is around the Y axis or X axis if aMirrorAroundXAxis = true
  153. // the position is mirrored, but the text itself is not mirrored
  154. if( aMirrorAroundXAxis )
  155. SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
  156. else
  157. SetTextX( ::Mirror( GetTextPos().x, aCentre.x ) );
  158. SetLocalCoord();
  159. }
  160. void TEXTE_MODULE::Move( const wxPoint& aMoveVector )
  161. {
  162. Offset( aMoveVector );
  163. SetLocalCoord();
  164. }
  165. int TEXTE_MODULE::GetLength() const
  166. {
  167. return m_Text.Len();
  168. }
  169. void TEXTE_MODULE::SetDrawCoord()
  170. {
  171. const MODULE* module = static_cast<const MODULE*>( m_Parent );
  172. SetTextPos( m_Pos0 );
  173. if( module )
  174. {
  175. double angle = module->GetOrientation();
  176. wxPoint pt = GetTextPos();
  177. RotatePoint( &pt, angle );
  178. SetTextPos( pt );
  179. Offset( module->GetPosition() );
  180. }
  181. }
  182. void TEXTE_MODULE::SetLocalCoord()
  183. {
  184. const MODULE* module = static_cast<const MODULE*>( m_Parent );
  185. if( module )
  186. {
  187. m_Pos0 = GetTextPos() - module->GetPosition();
  188. double angle = module->GetOrientation();
  189. RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
  190. }
  191. else
  192. {
  193. m_Pos0 = GetTextPos();
  194. }
  195. }
  196. const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
  197. {
  198. double angle = GetDrawRotation();
  199. EDA_RECT text_area = GetTextBox( -1, -1 );
  200. if( angle )
  201. text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
  202. return text_area;
  203. }
  204. void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
  205. const wxPoint& aOffset )
  206. {
  207. if( aPanel == NULL )
  208. return;
  209. /* parent must *not* be NULL (a footprint text without a footprint
  210. parent has no sense) */
  211. wxASSERT( m_Parent );
  212. BOARD* brd = GetBoard( );
  213. auto frame = static_cast<PCB_BASE_FRAME*> ( aPanel->GetParent() );
  214. auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
  215. PCB_LAYER_ID text_layer = GetLayer();
  216. if( !brd->IsLayerVisible( m_Layer )
  217. || ( IsFrontLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_FR ) )
  218. || ( IsBackLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_BK ) ) )
  219. return;
  220. if( !brd->IsElementVisible( LAYER_MOD_REFERENCES ) && GetText() == wxT( "%R" ) )
  221. return;
  222. if( !brd->IsElementVisible( LAYER_MOD_VALUES ) && GetText() == wxT( "%V" ) )
  223. return;
  224. // Invisible texts are still drawn (not plotted) in LAYER_MOD_TEXT_INVISIBLE
  225. // Just because we must have to edit them (at least to make them visible)
  226. if( !IsVisible() )
  227. {
  228. if( !brd->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) )
  229. return;
  230. color = frame->Settings().Colors().GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
  231. }
  232. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( aPanel->GetDisplayOptions() );
  233. // shade text if high contrast mode is active
  234. if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
  235. {
  236. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
  237. if( !IsOnLayer( curr_layer ) )
  238. color = COLOR4D( DARKDARKGRAY );
  239. }
  240. // Draw mode compensation for the width
  241. int width = GetThickness();
  242. if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH )
  243. width = -width;
  244. GRSetDrawMode( aDC, aDrawMode );
  245. wxPoint pos = GetTextPos() - aOffset;
  246. // Draw the text anchor point
  247. if( brd->IsElementVisible( LAYER_ANCHOR ) )
  248. {
  249. COLOR4D anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
  250. GRDrawAnchor( aPanel->GetClipBox(), aDC, pos.x, pos.y, DIM_ANCRE_TEXTE, anchor_color );
  251. }
  252. // Draw the text proper, with the right attributes
  253. wxSize size = GetTextSize();
  254. double orient = GetDrawRotation();
  255. // If the text is mirrored : negate size.x (mirror / Y axis)
  256. if( IsMirrored() )
  257. size.x = -size.x;
  258. DrawGraphicText( aPanel->GetClipBox(), aDC, pos, color, GetShownText(), orient,
  259. size, GetHorizJustify(), GetVertJustify(),
  260. width, IsItalic(), IsBold() );
  261. // Enable these line to draw the bounding box (debug test purpose only)
  262. #if 0
  263. {
  264. EDA_RECT BoundaryBox = GetBoundingBox();
  265. GRRect( aPanel->GetClipBox(), aDC, BoundaryBox, 0, BROWN );
  266. }
  267. #endif
  268. }
  269. void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
  270. wxDC* aDC,
  271. GR_DRAWMODE aDrawMode,
  272. const wxPoint& aOffset )
  273. {
  274. MODULE* parent = static_cast<MODULE*>( GetParent() );
  275. if( !parent )
  276. return;
  277. GRSetDrawMode( aDC, GR_XOR );
  278. GRLine( aPanel->GetClipBox(), aDC,
  279. parent->GetPosition(), GetTextPos() + aOffset,
  280. 0, UMBILICAL_COLOR);
  281. }
  282. double TEXTE_MODULE::GetDrawRotation() const
  283. {
  284. MODULE* module = (MODULE*) m_Parent;
  285. double rotation = GetTextAngle();
  286. if( module )
  287. rotation += module->GetOrientation();
  288. if( m_keepUpright )
  289. {
  290. // Keep angle between -90 .. 90 deg. Otherwise the text is not easy to read
  291. while( rotation > 900 )
  292. rotation -= 1800;
  293. while( rotation < -900 )
  294. rotation += 1800;
  295. }
  296. else
  297. {
  298. NORMALIZE_ANGLE_POS( rotation );
  299. }
  300. return rotation;
  301. }
  302. // see class_text_mod.h
  303. void TEXTE_MODULE::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
  304. {
  305. MODULE* module = (MODULE*) m_Parent;
  306. if( module == NULL ) // Happens in modedit, and for new texts
  307. return;
  308. wxString msg, Line;
  309. static const wxString text_type_msg[3] =
  310. {
  311. _( "Ref." ), _( "Value" ), _( "Text" )
  312. };
  313. Line = module->GetReference();
  314. aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), Line, DARKCYAN ) );
  315. Line = GetShownText();
  316. aList.push_back( MSG_PANEL_ITEM( _( "Text" ), Line, BROWN ) );
  317. wxASSERT( m_Type >= TEXT_is_REFERENCE && m_Type <= TEXT_is_DIVERS );
  318. aList.push_back( MSG_PANEL_ITEM( _( "Type" ), text_type_msg[m_Type], DARKGREEN ) );
  319. if( !IsVisible() )
  320. msg = _( "No" );
  321. else
  322. msg = _( "Yes" );
  323. aList.push_back( MSG_PANEL_ITEM( _( "Display" ), msg, DARKGREEN ) );
  324. // Display text layer
  325. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), DARKGREEN ) );
  326. if( IsMirrored() )
  327. msg = _( "Yes" );
  328. else
  329. msg = _( "No" );
  330. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
  331. msg.Printf( wxT( "%.1f" ), GetTextAngleDegrees() );
  332. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
  333. msg = MessageTextFromValue( aUnits, GetThickness(), true );
  334. aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, DARKGREEN ) );
  335. msg = MessageTextFromValue( aUnits, GetTextWidth(), true );
  336. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
  337. msg = MessageTextFromValue( aUnits, GetTextHeight(), true );
  338. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
  339. }
  340. wxString TEXTE_MODULE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  341. {
  342. switch( m_Type )
  343. {
  344. case TEXT_is_REFERENCE:
  345. return wxString::Format( _( "Reference %s" ),
  346. static_cast<MODULE*>( GetParent() )->GetReference() );
  347. case TEXT_is_VALUE:
  348. return wxString::Format( _( "Value %s of %s" ),
  349. GetShownText(),
  350. static_cast<MODULE*>( GetParent() )->GetReference() );
  351. default: // wrap this one in quotes:
  352. return wxString::Format( _( "Text \"%s\" of %s on %s" ),
  353. ShortenedShownText(),
  354. static_cast<MODULE*>( GetParent() )->GetReference(),
  355. GetLayerName() );
  356. }
  357. }
  358. BITMAP_DEF TEXTE_MODULE::GetMenuImage() const
  359. {
  360. return footprint_text_xpm;
  361. }
  362. EDA_ITEM* TEXTE_MODULE::Clone() const
  363. {
  364. return new TEXTE_MODULE( *this );
  365. }
  366. const BOX2I TEXTE_MODULE::ViewBBox() const
  367. {
  368. double angle = GetDrawRotation();
  369. EDA_RECT text_area = GetTextBox( -1, -1 );
  370. if( angle )
  371. text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
  372. return BOX2I( text_area.GetPosition(), text_area.GetSize() );
  373. }
  374. void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
  375. {
  376. if( IsVisible() )
  377. aLayers[0] = GetLayer();
  378. else
  379. aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
  380. aCount = 1;
  381. }
  382. unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  383. {
  384. const int HIDE = std::numeric_limits<unsigned int>::max();
  385. if( !aView )
  386. return 0;
  387. // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but
  388. // should only render if its native layer is visible.
  389. if( !aView->IsLayerVisible( GetLayer() ) )
  390. return HIDE;
  391. // Handle Render tab switches
  392. if( ( m_Type == TEXT_is_VALUE || m_Text == wxT( "%V" ) )
  393. && !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
  394. return HIDE;
  395. if( ( m_Type == TEXT_is_REFERENCE || m_Text == wxT( "%R" ) )
  396. && !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
  397. return HIDE;
  398. if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
  399. return HIDE;
  400. if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
  401. return HIDE;
  402. if( IsFrontLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) )
  403. return HIDE;
  404. if( IsBackLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) )
  405. return HIDE;
  406. // Other layers are shown without any conditions
  407. return 0;
  408. }
  409. wxString TEXTE_MODULE::GetShownText() const
  410. {
  411. /* First order optimization: no % means that no processing is
  412. * needed; just hope that RVO and copy constructor implementation
  413. * avoid to copy the whole block; anyway it should be better than
  414. * rebuild the string one character at a time...
  415. * Also it seems wise to only expand macros in user text (but there
  416. * is no technical reason, probably) */
  417. if( (m_Type != TEXT_is_DIVERS) || (wxString::npos == m_Text.find('%')) )
  418. return m_Text;
  419. wxString newbuf;
  420. const MODULE *module = static_cast<MODULE*>( GetParent() );
  421. for( wxString::const_iterator it = m_Text.begin(); it != m_Text.end(); ++it )
  422. {
  423. // Process '%' and copy everything else
  424. if( *it != '%' )
  425. newbuf.append(*it);
  426. else
  427. {
  428. /* Look at the next character (if is it there) and append
  429. * its expansion */
  430. ++it;
  431. if( it != m_Text.end() )
  432. {
  433. switch( char(*it) )
  434. {
  435. case '%':
  436. newbuf.append( '%' );
  437. break;
  438. case 'R':
  439. if( module )
  440. newbuf.append( module->GetReference() );
  441. break;
  442. case 'V':
  443. if( module )
  444. newbuf.append( module->GetValue() );
  445. break;
  446. default:
  447. newbuf.append( '?' );
  448. break;
  449. }
  450. }
  451. else
  452. break; // The string is over and we can't ++ anymore
  453. }
  454. }
  455. return newbuf;
  456. }