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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <macros.h>
21#include <pcb_field.h>
22#include <pcb_text.h>
23#include <pcb_textbox.h>
24#include <pcb_tablecell.h>
25#include <drc/drc_engine.h>
26#include <drc/drc_item.h>
27#include <drc/drc_rule.h>
29#include <drc/drc_rtree.h>
30#include <footprint.h>
31
32
33/*
34 Text mirroring tests.
35 Errors generated:
36 - DRCE_MIRRORED_TEXT_ON_FRONT_LAYER
37 - DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER
38*/
39
41{
42public:
45
47
48 virtual bool Run() override;
49
50 virtual const wxString GetName() const override { return wxT( "text_mirroring" ); };
51};
52
53
55{
56 if( m_drcEngine->IsErrorLimitExceeded( DRCE_MIRRORED_TEXT_ON_FRONT_LAYER )
57 && m_drcEngine->IsErrorLimitExceeded( DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER ) )
58 {
59 REPORT_AUX( wxT( "Text mirroring violations ignored. Tests not run." ) );
60 return true; // continue with other tests
61 }
62
63 if( !reportPhase( _( "Checking text mirroring..." ) ) )
64 return false; // DRC cancelled
65
66 LSET topLayers( { F_Cu, F_SilkS, F_Mask, F_Fab } );
67 LSET bottomLayers( { B_Cu, B_SilkS, B_Mask, B_Fab } );
68
69 auto checkTextMirroring =
70 [&]( BOARD_ITEM* item, EDA_TEXT* text, bool isMirrored, int errorCode )
71 {
72 if( m_drcEngine->IsErrorLimitExceeded( errorCode ) )
73 return;
74
75 bool layerMatch = ( isMirrored && topLayers.Contains( item->GetLayer() ) )
76 || ( !isMirrored && bottomLayers.Contains( item->GetLayer() ) );
77
78 if( layerMatch && text->IsMirrored() == isMirrored )
79 {
80 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( errorCode );
81 drcItem->SetItems( item );
82
83 reportViolation( drcItem, item->GetPosition(), item->GetLayer() );
84 }
85 };
86
87 const int progressDelta = 500;
88 int count = 0;
89 int progressIndex = 0;
90
91 static const std::vector<KICAD_T> itemTypes = {
95 };
96
97 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
98 [&]( BOARD_ITEM* item ) -> bool
99 {
100 ++count;
101 return true;
102 } );
103
104 forEachGeometryItem( itemTypes, topLayers | bottomLayers,
105 [&]( BOARD_ITEM* item ) -> bool
106 {
107 if( !reportProgress( progressIndex++, count, progressDelta ) )
108 return false;
109
110 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item ) )
111 {
112 if( !text->IsVisible()
113 || !m_drcEngine->GetBoard()->IsLayerEnabled( item->GetLayer() )
114 || !m_drcEngine->GetBoard()->IsLayerVisible( item->GetLayer() ) )
115 {
116 return true;
117 }
118
119 checkTextMirroring( item, text, true, DRCE_MIRRORED_TEXT_ON_FRONT_LAYER );
120 checkTextMirroring( item, text, false, DRCE_NONMIRRORED_TEXT_ON_BACK_LAYER );
121 }
122
123 return true;
124 } );
125
126 return !m_drcEngine->IsCancelled();
127}
128
129
130namespace detail
131{
133}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:417
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).
virtual bool reportPhase(const wxString &aStageName)
int forEachGeometryItem(const std::vector< KICAD_T > &aTypes, const LSET &aLayers, const std::function< bool(BOARD_ITEM *)> &aFunc)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:89
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:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
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:86
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:88
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:93