KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
drc_test_provider_text_mirroring.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <macros.h>
25#include <pcb_field.h>
26#include <pcb_text.h>
27#include <pcb_textbox.h>
28#include <pcb_tablecell.h>
29#include <drc/drc_engine.h>
30#include <drc/drc_item.h>
31#include <drc/drc_rule.h>
33#include <drc/drc_rtree.h>
34#include <footprint.h>
35
36
37/*
38 Text mirroring tests.
39 Errors generated:
40 - DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
41 - DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER
42*/
43
45{
46public:
48 {
49 }
50
52 {
53 }
54
55 virtual bool Run() override;
56
57 virtual const wxString GetName() const override
58 {
59 return wxT( "text_mirroring" );
60 };
61
62 virtual const wxString GetDescription() const override
63 {
64 return wxT( "Tests mirrored text on top layer and non-mirrored text on bottom layer" );
65 }
66};
67
68
70{
73 {
74 reportAux( wxT( "Text mirroring violations ignored. Tests not run." ) );
75 return true; // continue with other tests
76 }
77
78 if( !reportPhase( _( "Checking text mirroring..." ) ) )
79 return false; // DRC cancelled
80
81 LSET topLayers( { F_Cu, F_SilkS, F_Mask, F_Fab } );
82 LSET bottomLayers( { B_Cu, B_SilkS, B_Mask, B_Fab } );
83
84 auto checkTextMirroring =
85 [&]( BOARD_ITEM* item, EDA_TEXT* text, bool isMirrored, int errorCode )
86 {
87 if( m_drcEngine->IsErrorLimitExceeded( errorCode ) )
88 return;
89
90 bool layerMatch = ( isMirrored && topLayers.Contains( item->GetLayer() ) )
91 || ( !isMirrored && bottomLayers.Contains( item->GetLayer() ) );
92
93 if( layerMatch && text->IsMirrored() == isMirrored )
94 {
95 auto drcItem = DRC_ITEM::Create( errorCode );
96
97 drcItem->SetErrorMessage( drcItem->GetErrorText() );
98 drcItem->SetItems( item );
99
100 reportViolation( drcItem, item->GetPosition(), item->GetLayer() );
101 }
102 };
103
104 const int progressDelta = 500;
105 int count = 0;
106 int progressIndex = 0;
107
108 static const std::vector<KICAD_T> itemTypes = {
112 };
113
114 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
115 [&]( BOARD_ITEM* item ) -> bool
116 {
117 ++count;
118 return true;
119 } );
120
121 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
122 [&]( BOARD_ITEM* item ) -> bool
123 {
124 if( !reportProgress( progressIndex++, count, progressDelta ) )
125 return false;
126
127 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item ) )
128 {
129 if( !text->IsVisible()
131 || !m_drcEngine->GetBoard()->IsLayerVisible( item->GetLayer() ) )
132 {
133 return true;
134 }
135
136 checkTextMirroring( item, text, true, DRCE_MIRRORED_TEXT_ON_FRONT_LAYER );
137 checkTextMirroring( item, text, false, DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER );
138 }
139
140 return true;
141 } );
142
144
145 return !m_drcEngine->IsCancelled();
146}
147
148
149namespace detail
150{
152}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:235
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:855
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:835
BOARD * GetBoard() const
Definition: drc_engine.h:96
bool IsErrorLimitExceeded(int error_code)
bool IsCancelled() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:393
virtual const wxString GetDescription() const override
virtual const wxString GetName() const override
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out DRC_ITEM and posi...
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, DRC_CUSTOM_MARKER_HANDLER *aCustomHandler=nullptr)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, const LSET &aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
DRC_ENGINE * m_drcEngine
void reportAux(const wxString &aMsg)
virtual void reportRuleStatistics()
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:248
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
@ DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
Definition: drc_item.h:109
@ DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER
Definition: drc_item.h:110
#define _(s)
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ F_Fab
Definition: layer_ids.h:119
@ F_SilkS
Definition: layer_ids.h:100
@ B_SilkS
Definition: layer_ids.h:101
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:118
This file contains miscellaneous commonly used macros and functions.
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition: typeinfo.h:90
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:100