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.

570 lines
15 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-2017 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_unlocked = false;
  52. // Set text thickness to a default value
  53. SetThickness( Millimeter2iu( 0.15 ) );
  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::Rotate( const wxPoint& aRotCentre, double aAngle )
  96. {
  97. // Used in footprint edition
  98. // Note also in module editor, m_Pos0 = m_Pos
  99. wxPoint pt = GetTextPos();
  100. RotatePoint( &pt, aRotCentre, aAngle );
  101. SetTextPos( pt );
  102. SetTextAngle( GetTextAngle() + aAngle );
  103. SetLocalCoord();
  104. }
  105. void TEXTE_MODULE::Flip( const wxPoint& aCentre )
  106. {
  107. // flipping the footprint is relative to the X axis
  108. SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
  109. SetTextAngle( -GetTextAngle() );
  110. SetLayer( FlipLayer( GetLayer() ) );
  111. SetMirrored( IsBackLayer( GetLayer() ) );
  112. SetLocalCoord();
  113. }
  114. bool TEXTE_MODULE::IsParentFlipped() const
  115. {
  116. if( GetParent() && GetParent()->GetLayer() == B_Cu )
  117. return true;
  118. return false;
  119. }
  120. void TEXTE_MODULE::Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis )
  121. {
  122. // Used in modedit, to transform the footprint
  123. // the mirror is around the Y axis or X axis if aMirrorAroundXAxis = true
  124. // the position is mirrored, but the text itself is not mirrored
  125. if( aMirrorAroundXAxis )
  126. SetTextY( ::Mirror( GetTextPos().y, aCentre.y ) );
  127. else
  128. SetTextX( ::Mirror( GetTextPos().x, aCentre.x ) );
  129. SetLocalCoord();
  130. }
  131. void TEXTE_MODULE::Move( const wxPoint& aMoveVector )
  132. {
  133. Offset( aMoveVector );
  134. SetLocalCoord();
  135. }
  136. int TEXTE_MODULE::GetLength() const
  137. {
  138. return m_Text.Len();
  139. }
  140. void TEXTE_MODULE::SetDrawCoord()
  141. {
  142. const MODULE* module = static_cast<const MODULE*>( m_Parent );
  143. SetTextPos( m_Pos0 );
  144. if( module )
  145. {
  146. double angle = module->GetOrientation();
  147. wxPoint pt = GetTextPos();
  148. RotatePoint( &pt, angle );
  149. SetTextPos( pt );
  150. Offset( module->GetPosition() );
  151. }
  152. }
  153. void TEXTE_MODULE::SetLocalCoord()
  154. {
  155. const MODULE* module = static_cast<const MODULE*>( m_Parent );
  156. if( module )
  157. {
  158. m_Pos0 = GetTextPos() - module->GetPosition();
  159. double angle = module->GetOrientation();
  160. RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
  161. }
  162. else
  163. {
  164. m_Pos0 = GetTextPos();
  165. }
  166. }
  167. const EDA_RECT TEXTE_MODULE::GetBoundingBox() const
  168. {
  169. double angle = GetDrawRotation();
  170. EDA_RECT text_area = GetTextBox( -1, -1 );
  171. if( angle )
  172. text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
  173. return text_area;
  174. }
  175. void TEXTE_MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
  176. const wxPoint& aOffset )
  177. {
  178. if( aPanel == NULL )
  179. return;
  180. /* parent must *not* be NULL (a footprint text without a footprint
  181. parent has no sense) */
  182. wxASSERT( m_Parent );
  183. BOARD* brd = GetBoard( );
  184. auto frame = static_cast<PCB_BASE_FRAME*> ( aPanel->GetParent() );
  185. auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
  186. PCB_LAYER_ID text_layer = GetLayer();
  187. if( !brd->IsLayerVisible( m_Layer )
  188. || ( IsFrontLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_FR ) )
  189. || ( IsBackLayer( text_layer ) && !brd->IsElementVisible( LAYER_MOD_TEXT_BK ) ) )
  190. return;
  191. if( !brd->IsElementVisible( LAYER_MOD_REFERENCES ) && GetText() == wxT( "%R" ) )
  192. return;
  193. if( !brd->IsElementVisible( LAYER_MOD_VALUES ) && GetText() == wxT( "%V" ) )
  194. return;
  195. // Invisible texts are still drawn (not plotted) in LAYER_MOD_TEXT_INVISIBLE
  196. // Just because we must have to edit them (at least to make them visible)
  197. if( !IsVisible() )
  198. {
  199. if( !brd->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) )
  200. return;
  201. color = frame->Settings().Colors().GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
  202. }
  203. auto displ_opts = (PCB_DISPLAY_OPTIONS*)( aPanel->GetDisplayOptions() );
  204. // shade text if high contrast mode is active
  205. if( ( aDrawMode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay )
  206. {
  207. PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) aPanel->GetScreen() )->m_Active_Layer;
  208. if( !IsOnLayer( curr_layer ) )
  209. color = COLOR4D( DARKDARKGRAY );
  210. }
  211. // Draw mode compensation for the width
  212. int width = GetThickness();
  213. if( displ_opts && displ_opts->m_DisplayModTextFill == SKETCH )
  214. width = -width;
  215. GRSetDrawMode( aDC, aDrawMode );
  216. wxPoint pos = GetTextPos() - aOffset;
  217. // Draw the text anchor point
  218. if( brd->IsElementVisible( LAYER_ANCHOR ) )
  219. {
  220. COLOR4D anchor_color = frame->Settings().Colors().GetItemColor( LAYER_ANCHOR );
  221. GRDrawAnchor( aPanel->GetClipBox(), aDC, pos.x, pos.y, DIM_ANCRE_TEXTE, anchor_color );
  222. }
  223. // Draw the text proper, with the right attributes
  224. wxSize size = GetTextSize();
  225. double orient = GetDrawRotation();
  226. // If the text is mirrored : negate size.x (mirror / Y axis)
  227. if( IsMirrored() )
  228. size.x = -size.x;
  229. DrawGraphicText( aPanel->GetClipBox(), aDC, pos, color, GetShownText(), orient,
  230. size, GetHorizJustify(), GetVertJustify(),
  231. width, IsItalic(), IsBold() );
  232. // Enable these line to draw the bounding box (debug test purpose only)
  233. #if 0
  234. {
  235. EDA_RECT BoundaryBox = GetBoundingBox();
  236. GRRect( aPanel->GetClipBox(), aDC, BoundaryBox, 0, BROWN );
  237. }
  238. #endif
  239. }
  240. void TEXTE_MODULE::DrawUmbilical( EDA_DRAW_PANEL* aPanel,
  241. wxDC* aDC,
  242. GR_DRAWMODE aDrawMode,
  243. const wxPoint& aOffset )
  244. {
  245. MODULE* parent = static_cast<MODULE*>( GetParent() );
  246. if( !parent )
  247. return;
  248. GRSetDrawMode( aDC, GR_XOR );
  249. GRLine( aPanel->GetClipBox(), aDC,
  250. parent->GetPosition(), GetTextPos() + aOffset,
  251. 0, UMBILICAL_COLOR);
  252. }
  253. double TEXTE_MODULE::GetDrawRotation() const
  254. {
  255. MODULE* module = (MODULE*) m_Parent;
  256. double rotation = GetTextAngle();
  257. if( module )
  258. rotation += module->GetOrientation();
  259. if( m_unlocked )
  260. {
  261. NORMALIZE_ANGLE_POS( rotation );
  262. }
  263. else
  264. {
  265. // Keep angle between -90 .. 90 deg. Otherwise the text is not easy to read
  266. while( rotation > 900 )
  267. rotation -= 1800;
  268. while( rotation < -900 )
  269. rotation += 1800;
  270. }
  271. return rotation;
  272. }
  273. // see class_text_mod.h
  274. void TEXTE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
  275. {
  276. MODULE* module = (MODULE*) m_Parent;
  277. if( module == NULL ) // Happens in modedit, and for new texts
  278. return;
  279. wxString msg, Line;
  280. static const wxString text_type_msg[3] =
  281. {
  282. _( "Ref." ), _( "Value" ), _( "Text" )
  283. };
  284. Line = module->GetReference();
  285. aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), Line, DARKCYAN ) );
  286. Line = GetShownText();
  287. aList.push_back( MSG_PANEL_ITEM( _( "Text" ), Line, BROWN ) );
  288. wxASSERT( m_Type >= TEXT_is_REFERENCE && m_Type <= TEXT_is_DIVERS );
  289. aList.push_back( MSG_PANEL_ITEM( _( "Type" ), text_type_msg[m_Type], DARKGREEN ) );
  290. if( !IsVisible() )
  291. msg = _( "No" );
  292. else
  293. msg = _( "Yes" );
  294. aList.push_back( MSG_PANEL_ITEM( _( "Display" ), msg, DARKGREEN ) );
  295. // Display text layer
  296. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), DARKGREEN ) );
  297. if( IsMirrored() )
  298. msg = _( "Yes" );
  299. else
  300. msg = _( "No" );
  301. aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
  302. msg.Printf( wxT( "%.1f" ), GetTextAngleDegrees() );
  303. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
  304. msg = ::CoordinateToString( GetThickness() );
  305. aList.push_back( MSG_PANEL_ITEM( _( "Thickness" ), msg, DARKGREEN ) );
  306. msg = ::CoordinateToString( GetTextWidth() );
  307. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, RED ) );
  308. msg = ::CoordinateToString( GetTextHeight() );
  309. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, RED ) );
  310. }
  311. wxString TEXTE_MODULE::GetSelectMenuText() const
  312. {
  313. wxString text;
  314. const wxChar *reference = GetChars( static_cast<MODULE*>( GetParent() )->GetReference() );
  315. switch( m_Type )
  316. {
  317. case TEXT_is_REFERENCE:
  318. text.Printf( _( "Reference %s" ), reference );
  319. break;
  320. case TEXT_is_VALUE:
  321. text.Printf( _( "Value %s of %s" ), GetChars( GetShownText() ), reference );
  322. break;
  323. default: // wrap this one in quotes:
  324. text.Printf( _( "Text \"%s\" on %s of %s" ), GetChars( ShortenedShownText() ),
  325. GetChars( GetLayerName() ), reference );
  326. break;
  327. }
  328. return text;
  329. }
  330. BITMAP_DEF TEXTE_MODULE::GetMenuImage() const
  331. {
  332. return footprint_text_xpm;
  333. }
  334. EDA_ITEM* TEXTE_MODULE::Clone() const
  335. {
  336. return new TEXTE_MODULE( *this );
  337. }
  338. const BOX2I TEXTE_MODULE::ViewBBox() const
  339. {
  340. double angle = GetDrawRotation();
  341. EDA_RECT text_area = GetTextBox( -1, -1 );
  342. if( angle )
  343. text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle );
  344. return BOX2I( text_area.GetPosition(), text_area.GetSize() );
  345. }
  346. void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
  347. {
  348. if( IsVisible() )
  349. aLayers[0] = GetLayer();
  350. else
  351. aLayers[0] = LAYER_MOD_TEXT_INVISIBLE;
  352. aCount = 1;
  353. }
  354. unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  355. {
  356. const int HIDE = std::numeric_limits<unsigned int>::max();
  357. if( !aView )
  358. return 0;
  359. // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but
  360. // should only render if its native layer is visible.
  361. if( !aView->IsLayerVisible( GetLayer() ) )
  362. return HIDE;
  363. // Handle Render tab switches
  364. if( ( m_Type == TEXT_is_VALUE || m_Text == wxT( "%V" ) )
  365. && !aView->IsLayerVisible( LAYER_MOD_VALUES ) )
  366. return HIDE;
  367. if( ( m_Type == TEXT_is_REFERENCE || m_Text == wxT( "%R" ) )
  368. && !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) )
  369. return HIDE;
  370. if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
  371. return HIDE;
  372. if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
  373. return HIDE;
  374. if( IsFrontLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) )
  375. return HIDE;
  376. if( IsBackLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) )
  377. return HIDE;
  378. // Other layers are shown without any conditions
  379. return 0;
  380. }
  381. wxString TEXTE_MODULE::GetShownText() const
  382. {
  383. /* First order optimization: no % means that no processing is
  384. * needed; just hope that RVO and copy constructor implementation
  385. * avoid to copy the whole block; anyway it should be better than
  386. * rebuild the string one character at a time...
  387. * Also it seems wise to only expand macros in user text (but there
  388. * is no technical reason, probably) */
  389. if( (m_Type != TEXT_is_DIVERS) || (wxString::npos == m_Text.find('%')) )
  390. return m_Text;
  391. wxString newbuf;
  392. const MODULE *module = static_cast<MODULE*>( GetParent() );
  393. for( wxString::const_iterator it = m_Text.begin(); it != m_Text.end(); ++it )
  394. {
  395. // Process '%' and copy everything else
  396. if( *it != '%' )
  397. newbuf.append(*it);
  398. else
  399. {
  400. /* Look at the next character (if is it there) and append
  401. * its expansion */
  402. ++it;
  403. if( it != m_Text.end() )
  404. {
  405. switch( char(*it) )
  406. {
  407. case '%':
  408. newbuf.append( '%' );
  409. break;
  410. case 'R':
  411. if( module )
  412. newbuf.append( module->GetReference() );
  413. break;
  414. case 'V':
  415. if( module )
  416. newbuf.append( module->GetValue() );
  417. break;
  418. default:
  419. newbuf.append( '?' );
  420. break;
  421. }
  422. }
  423. else
  424. break; // The string is over and we can't ++ anymore
  425. }
  426. }
  427. return newbuf;
  428. }