KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
51
52 virtual bool Run() override;
53
54 virtual const wxString GetName() const override { return wxT( "text_mirroring" ); };
55};
56
57
59{
62 {
63 REPORT_AUX( wxT( "Text mirroring violations ignored. Tests not run." ) );
64 return true; // continue with other tests
65 }
66
67 if( !reportPhase( _( "Checking text mirroring..." ) ) )
68 return false; // DRC cancelled
69
70 LSET topLayers( { F_Cu, F_SilkS, F_Mask, F_Fab } );
71 LSET bottomLayers( { B_Cu, B_SilkS, B_Mask, B_Fab } );
72
73 auto checkTextMirroring =
74 [&]( BOARD_ITEM* item, EDA_TEXT* text, bool isMirrored, int errorCode )
75 {
76 if( m_drcEngine->IsErrorLimitExceeded( errorCode ) )
77 return;
78
79 bool layerMatch = ( isMirrored && topLayers.Contains( item->GetLayer() ) )
80 || ( !isMirrored && bottomLayers.Contains( item->GetLayer() ) );
81
82 if( layerMatch && text->IsMirrored() == isMirrored )
83 {
84 auto drcItem = DRC_ITEM::Create( errorCode );
85
86 drcItem->SetErrorMessage( drcItem->GetErrorText() );
87 drcItem->SetItems( item );
88
89 reportViolation( drcItem, item->GetPosition(), item->GetLayer() );
90 }
91 };
92
93 const int progressDelta = 500;
94 int count = 0;
95 int progressIndex = 0;
96
97 static const std::vector<KICAD_T> itemTypes = {
101 };
102
103 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
104 [&]( BOARD_ITEM* item ) -> bool
105 {
106 ++count;
107 return true;
108 } );
109
110 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
111 [&]( BOARD_ITEM* item ) -> bool
112 {
113 if( !reportProgress( progressIndex++, count, progressDelta ) )
114 return false;
115
116 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item ) )
117 {
118 if( !text->IsVisible()
120 || !m_drcEngine->GetBoard()->IsLayerVisible( item->GetLayer() ) )
121 {
122 return true;
123 }
124
125 checkTextMirroring( item, text, true, DRCE_MIRRORED_TEXT_ON_FRONT_LAYER );
126 checkTextMirroring( item, text, false, DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER );
127 }
128
129 return true;
130 } );
131
132 return !m_drcEngine->IsCancelled();
133}
134
135
136namespace detail
137{
139}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:232
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:95
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 ~DRC_TEST_PROVIDER_TEXT_MIRRORING()=default
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
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:259
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
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 REPORT_AUX(s)
#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