KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sch_binary_model.h
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, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <array>
23#include <cstddef>
24#include <cstdint>
25#include <limits>
26#include <optional>
27#include <utility>
28#include <vector>
29
31#include <wx/string.h>
32
33namespace PADS_SCH_BINARY
34{
35
37{
38 wxString file;
39 uint16_t version = 0;
40 wxString objectClass;
41 int controller = -1;
42 size_t recordIndex = 0;
43 size_t absoluteOffset = 0;
44 size_t length = 0;
45 int sheet = -1;
46
47 bool operator==( const SOURCE_PROVENANCE& ) const = default;
48};
49
50
58
59
61{
62 std::vector<uint8_t> raw;
63 wxString text;
66 uint32_t codePage = 65001;
67 wxString codePageName = wxS( "UTF-8" );
68
69 bool operator==( const SOURCE_STRING& ) const = default;
70};
71
72
80
81
89
90
99
100
102{
103 PARSER_DIAGNOSTIC() = default;
104 PARSER_DIAGNOSTIC( SEVERITY aSeverity, SOURCE_PROVENANCE aSource, wxString aMessage,
105 std::optional<DIAGNOSTIC_PROPERTY_IDENTITY> aProperty = std::nullopt ) :
106 severity( aSeverity ),
107 source( std::move( aSource ) ),
108 message( std::move( aMessage ) ),
109 property( std::move( aProperty ) )
110 {
111 }
112
115 wxString message;
116 std::optional<DIAGNOSTIC_PROPERTY_IDENTITY> property;
117
118 bool operator==( const PARSER_DIAGNOSTIC& ) const = default;
119};
120
121std::optional<DIAGNOSTIC_PROPERTY_KEY> DiagnosticPropertyKey( const PARSER_DIAGNOSTIC& aDiagnostic );
122
123wxString FormatParserError( const SOURCE_PROVENANCE& aSource, const wxString& aMessage );
124
125
135
137 const wxString& aMessage );
138PARSER_DIAGNOSTIC MakePropertyDiagnostic( SEVERITY aSeverity, const SOURCE_PROVENANCE& aSource, const wxString& aName,
139 PROPERTY_DISPOSITION aDisposition, const wxString& aMessage );
140
141
142template <typename Tag, typename ValueType = uint32_t>
144{
145public:
146 constexpr CONTROLLER_ID() = default;
147 explicit constexpr CONTROLLER_ID( ValueType aValue ) :
148 m_value( aValue )
149 {
150 }
151
152 constexpr ValueType Value() const { return m_value; }
153 constexpr bool IsValid() const { return m_value != INVALID; }
154
155 auto operator<=>( const CONTROLLER_ID& ) const = default;
156
157private:
158 static constexpr ValueType INVALID = std::numeric_limits<ValueType>::max();
159 ValueType m_value = INVALID;
160};
161
162
163struct SHEET_ID_TAG;
164struct DEFINITION_ID_TAG;
165struct PIN_ID_TAG;
166struct FIELD_ID_TAG;
167struct PART_TYPE_ID_TAG;
168struct GATE_ID_TAG;
169struct PLACEMENT_ID_TAG;
170struct NET_ID_TAG;
171struct BUS_ID_TAG;
172struct IMAGE_ID_TAG;
173
184
185enum class FIELD_ID_DOMAIN : uint8_t
186{
187 SHEET = 1,
191};
192
193constexpr uint32_t FIELD_ID_MAX_ORDINAL = ( 1U << 29 ) - 1;
194
195constexpr FIELD_ID MakeFieldId( FIELD_ID_DOMAIN aDomain, uint32_t aOwner, uint32_t aOrdinal )
196{
197 if( aOrdinal > FIELD_ID_MAX_ORDINAL )
198 return FIELD_ID();
199
200 return FIELD_ID( ( static_cast<uint64_t>( aDomain ) << 61 ) | ( static_cast<uint64_t>( aOwner ) << 29 )
201 | aOrdinal );
202}
203
204template <typename Id>
206{
207 Id id;
209
210 bool operator==( const CONTROLLER_REFERENCE& ) const = default;
211};
212
219
220// PADS source coordinates remain signed integer half-mils. Angles are tenths of a degree,
221// normalized to [0, 3600). Conversion to KiCad units belongs to the schematic builder.
222constexpr int64_t NormalizeCoordinate( int64_t aCoordinate )
223{
224 return aCoordinate;
225}
226
227constexpr int NormalizeAngle( int aAngle )
228{
229 int normalized = aAngle % 3600;
230 return normalized < 0 ? normalized + 3600 : normalized;
231}
232
233
235{
236 int64_t x = 0;
237 int64_t y = 0;
239
240 bool operator==( const SOURCE_POINT& ) const = default;
241};
242
243
245{
246 PIN_REFERENCE() = default;
248 id( aId ),
249 source( std::move( aSource ) )
250 {
251 }
252
255
256 bool operator==( const PIN_REFERENCE& ) const = default;
257};
258
259
272
273
282
283
290
291
298
299
306
307
324
325
340
341
357
358
368
369
390
391
400
401
403{
407 std::vector<MODEL_GRAPHIC> graphics;
408
409 bool operator==( const MODEL_WORKSHEET& ) const = default;
410};
411
412
446
447
449{
453 std::vector<MODEL_GRAPHIC> graphics;
454 std::vector<MODEL_PIN_DEFINITION> pins;
455 std::vector<MODEL_FIELD> fields;
456 std::vector<SOURCE_PROPERTY> properties;
457
458 bool operator==( const MODEL_SYMBOL_DEFINITION& ) const = default;
459};
460
461
473
474
487
488
490{
494 uint32_t unit = 1;
495 std::vector<PIN_REFERENCE> pins;
496 std::vector<MODEL_GATE_PIN> logicalPins;
497 std::vector<DEFINITION_REFERENCE> alternateDefinitions;
498 std::vector<DEFINITION_REFERENCE> decalGroupMembers;
499 std::vector<MODEL_CONNECTOR_PIN> connectorPins;
500 std::vector<SOURCE_PROPERTY> properties;
501
502 bool operator==( const MODEL_GATE& ) const = default;
503};
504
505
514
515
517{
521 std::vector<MODEL_GATE> gates;
522 std::vector<MODEL_FIELD> fields;
523 std::vector<SOURCE_PROPERTY> properties;
524 std::vector<MODEL_SIGNAL_PIN> signalPins;
525
526 bool operator==( const MODEL_PART_TYPE& ) const = default;
527};
528
529
531{
533 size_t index = 0;
536 std::optional<SHEET_REFERENCE> parent;
538 int64_t defaultLineWidth = 0;
539 int64_t defaultBusWidth = 0;
541 std::vector<MODEL_GRAPHIC> border;
542 std::vector<MODEL_FIELD> titleBlockFields;
543 std::vector<SOURCE_PROPERTY> properties;
544
545 bool operator==( const MODEL_SHEET& ) const = default;
546};
547
548
550{
555 std::optional<GATE_REFERENCE> gate;
557 std::vector<PLACED_PIN_REFERENCE> pins;
558 uint32_t unit = 1;
561 int angle = 0;
562 bool mirrored = false;
563 uint16_t mirrorFlags = 0;
565 bool referenceVisible = true;
566 bool partTypeVisible = true;
567 bool pinNamesVisible = true;
568 bool pinNumbersVisible = true;
569 std::vector<MODEL_FIELD> fields;
570 std::vector<SOURCE_PROPERTY> properties;
571
572 bool operator==( const MODEL_PLACEMENT& ) const = default;
573};
574
575
582
583
585{
588 std::optional<PLACEMENT_REFERENCE> placement;
589 std::optional<PIN_REFERENCE> pin;
591 std::vector<SOURCE_PROPERTY> properties;
592
593 bool operator==( const MODEL_CONNECTION_ENDPOINT& ) const = default;
594};
595
596
598{
600 std::vector<MODEL_CONNECTION_ENDPOINT> endpoints;
601 std::vector<SOURCE_POINT> vertices;
602 std::vector<SOURCE_PROPERTY> properties;
603
604 bool operator==( const MODEL_CONNECTION& ) const = default;
605};
606
607
609{
614 std::vector<MODEL_CONNECTION> connections;
615 std::vector<SOURCE_PROPERTY> properties;
616
617 bool operator==( const MODEL_NET& ) const = default;
618};
619
620
622{
626 std::vector<SOURCE_PROPERTY> properties;
627
628 bool operator==( const MODEL_BUS_ENTRY& ) const = default;
629};
630
631
633{
638 std::vector<SOURCE_POINT> vertices;
639 std::vector<MODEL_BUS_ENTRY> entries;
640 std::vector<SOURCE_STRING> aliases;
641 std::vector<SOURCE_STRING> declaredMembers;
642 std::vector<NET_REFERENCE> memberNets;
643 std::vector<SOURCE_PROPERTY> properties;
644
645 bool operator==( const MODEL_BUS& ) const = default;
646};
647
648
659
660
677
678
680{
684 std::vector<SOURCE_PROPERTY> properties;
685
686 bool operator==( const MODEL_JUNCTION& ) const = default;
687};
688
689
702
703
711
712
714{
719 wxString streamName;
720 std::array<int32_t, 4> extent{};
721 std::array<int32_t, 4> databaseBox{};
724 bool mirrorHorizontal = false;
725 bool mirrorVertical = false;
726 uint32_t flags = 0;
727 std::vector<uint8_t> data;
728 std::vector<SOURCE_PROPERTY> properties;
729
730 bool operator==( const MODEL_EMBEDDED_IMAGE& ) const = default;
731};
732
733
742
743
745{
746 uint16_t version = 0;
747 uint16_t subversion = 0;
750 std::vector<MODEL_SHEET> sheets;
751 std::vector<MODEL_SYMBOL_DEFINITION> definitions;
752 std::vector<MODEL_PART_TYPE> partTypes;
753 std::vector<MODEL_PLACEMENT> placements;
754 std::vector<MODEL_NET> nets;
755 std::vector<MODEL_BUS> buses;
756 std::vector<MODEL_LABEL> labels;
757 std::vector<MODEL_JUNCTION> junctions;
758 std::vector<MODEL_TEXT> texts;
759 std::vector<MODEL_PAGE_GRAPHIC> graphics;
760 std::vector<MODEL_WORKSHEET> worksheets;
761 std::vector<MODEL_EMBEDDED_IMAGE> images;
762 std::vector<PRESERVED_CONTROLLER_PAYLOAD> preservedControllerPayloads;
763 std::vector<PARSER_DIAGNOSTIC> diagnostics;
764
765 void ValidateOrThrow() const;
766
767 bool operator==( const PADS_SCH_MODEL& ) const = default;
768};
769
770} // namespace PADS_SCH_BINARY
static std::optional< VECTOR2D > normalized(const VECTOR2D &aVec)
constexpr ValueType Value() const
constexpr CONTROLLER_ID(ValueType aValue)
auto operator<=>(const CONTROLLER_ID &) const =default
constexpr CONTROLLER_ID()=default
constexpr int64_t NormalizeCoordinate(int64_t aCoordinate)
CONTROLLER_REFERENCE< PART_TYPE_ID > PART_TYPE_REFERENCE
CONTROLLER_REFERENCE< DEFINITION_ID > DEFINITION_REFERENCE
constexpr int NormalizeAngle(int aAngle)
CONTROLLER_ID< NET_ID_TAG > NET_ID
CONTROLLER_ID< IMAGE_ID_TAG > IMAGE_ID
CONTROLLER_ID< DEFINITION_ID_TAG > DEFINITION_ID
CONTROLLER_REFERENCE< PLACEMENT_ID > PLACEMENT_REFERENCE
CONTROLLER_REFERENCE< SHEET_ID > SHEET_REFERENCE
CONTROLLER_ID< SHEET_ID_TAG > SHEET_ID
constexpr uint32_t FIELD_ID_MAX_ORDINAL
CONTROLLER_ID< PIN_ID_TAG > PIN_ID
CONTROLLER_ID< FIELD_ID_TAG, uint64_t > FIELD_ID
constexpr FIELD_ID MakeFieldId(FIELD_ID_DOMAIN aDomain, uint32_t aOwner, uint32_t aOrdinal)
CONTROLLER_ID< PART_TYPE_ID_TAG > PART_TYPE_ID
wxString FormatParserError(const SOURCE_PROVENANCE &aSource, const wxString &aMessage)
CONTROLLER_ID< PLACEMENT_ID_TAG > PLACEMENT_ID
CONTROLLER_ID< GATE_ID_TAG > GATE_ID
CONTROLLER_REFERENCE< NET_ID > NET_REFERENCE
CONTROLLER_REFERENCE< GATE_ID > GATE_REFERENCE
std::optional< DIAGNOSTIC_PROPERTY_KEY > DiagnosticPropertyKey(const PARSER_DIAGNOSTIC &aDiagnostic)
PARSER_DIAGNOSTIC MakePropertyDiagnostic(SEVERITY aSeverity, const SOURCE_PROPERTY &aProperty, const wxString &aMessage)
CONTROLLER_ID< BUS_ID_TAG > BUS_ID
STL namespace.
SEVERITY
@ RPT_SEVERITY_UNDEFINED
bool operator==(const CONTROLLER_REFERENCE &) const =default
std::vector< SOURCE_PROPERTY > properties
bool operator==(const DESIGN_SETTINGS &) const =default
bool operator==(const DIAGNOSTIC_PROPERTY_IDENTITY &) const =default
bool operator==(const DIAGNOSTIC_PROPERTY_KEY &) const =default
bool operator<(const DIAGNOSTIC_PROPERTY_KEY &aOther) const
bool operator==(const MODEL_BUS_ENTRY &) const =default
SOURCE_PROVENANCE source
NET_REFERENCE memberNet
std::vector< SOURCE_PROPERTY > properties
SOURCE_POINT position
std::vector< SOURCE_PROPERTY > properties
std::vector< MODEL_BUS_ENTRY > entries
std::vector< SOURCE_STRING > declaredMembers
std::vector< SOURCE_STRING > aliases
std::vector< NET_REFERENCE > memberNets
bool operator==(const MODEL_BUS &) const =default
std::vector< SOURCE_POINT > vertices
bool operator==(const MODEL_CONNECTION_ENDPOINT &) const =default
std::optional< PLACEMENT_REFERENCE > placement
std::vector< MODEL_CONNECTION_ENDPOINT > endpoints
bool operator==(const MODEL_CONNECTION &) const =default
std::vector< SOURCE_PROPERTY > properties
std::vector< SOURCE_POINT > vertices
bool operator==(const MODEL_CONNECTOR_PIN &) const =default
std::vector< SOURCE_PROPERTY > properties
bool operator==(const MODEL_EMBEDDED_IMAGE &) const =default
MODEL_TEXT_PRESENTATION presentation
std::vector< SOURCE_PROPERTY > properties
bool operator==(const MODEL_FIELD &) const =default
bool operator==(const MODEL_GATE_PIN &) const =default
std::vector< DEFINITION_REFERENCE > decalGroupMembers
std::vector< MODEL_CONNECTOR_PIN > connectorPins
std::vector< SOURCE_PROPERTY > properties
std::vector< PIN_REFERENCE > pins
bool operator==(const MODEL_GATE &) const =default
std::vector< MODEL_GATE_PIN > logicalPins
std::vector< DEFINITION_REFERENCE > alternateDefinitions
std::vector< SOURCE_PROPERTY > properties
bool operator==(const MODEL_GRAPHIC &) const =default
std::vector< SOURCE_POINT > points
bool operator==(const MODEL_JUNCTION &) const =default
std::vector< SOURCE_PROPERTY > properties
MODEL_TEXT_PRESENTATION presentation
bool operator==(const MODEL_LABEL &) const =default
std::vector< SOURCE_PROPERTY > properties
std::vector< SHEET_REFERENCE > linkedSheets
std::vector< MODEL_CONNECTION > connections
std::vector< SOURCE_PROPERTY > properties
bool operator==(const MODEL_NET &) const =default
bool operator==(const MODEL_PAGE_GRAPHIC &) const =default
std::vector< MODEL_SIGNAL_PIN > signalPins
bool operator==(const MODEL_PART_TYPE &) const =default
std::vector< SOURCE_PROPERTY > properties
std::vector< SOURCE_PROPERTY > properties
bool operator==(const MODEL_PIN_DEFINITION &) const =default
bool operator==(const MODEL_PLACEMENT &) const =default
std::vector< PLACED_PIN_REFERENCE > pins
std::vector< SOURCE_PROPERTY > properties
std::optional< GATE_REFERENCE > gate
std::optional< SHEET_REFERENCE > parent
bool operator==(const MODEL_SHEET &) const =default
std::vector< SOURCE_PROPERTY > properties
std::vector< MODEL_FIELD > titleBlockFields
std::vector< MODEL_GRAPHIC > border
bool operator==(const MODEL_SIGNAL_PIN &) const =default
bool operator==(const MODEL_SYMBOL_DEFINITION &) const =default
std::vector< MODEL_PIN_DEFINITION > pins
bool operator==(const MODEL_TEXT_PRESENTATION &) const =default
std::vector< SOURCE_PROPERTY > properties
MODEL_TEXT_PRESENTATION presentation
bool operator==(const MODEL_TEXT &) const =default
std::vector< MODEL_GRAPHIC > graphics
bool operator==(const MODEL_WORKSHEET &) const =default
std::vector< MODEL_SYMBOL_DEFINITION > definitions
std::vector< MODEL_JUNCTION > junctions
std::vector< MODEL_PAGE_GRAPHIC > graphics
std::vector< PRESERVED_CONTROLLER_PAYLOAD > preservedControllerPayloads
std::vector< MODEL_WORKSHEET > worksheets
std::vector< MODEL_LABEL > labels
std::vector< MODEL_EMBEDDED_IMAGE > images
std::vector< MODEL_PART_TYPE > partTypes
std::vector< MODEL_SHEET > sheets
bool operator==(const PADS_SCH_MODEL &) const =default
std::vector< MODEL_PLACEMENT > placements
std::vector< PARSER_DIAGNOSTIC > diagnostics
PARSER_DIAGNOSTIC(SEVERITY aSeverity, SOURCE_PROVENANCE aSource, wxString aMessage, std::optional< DIAGNOSTIC_PROPERTY_IDENTITY > aProperty=std::nullopt)
std::optional< DIAGNOSTIC_PROPERTY_IDENTITY > property
bool operator==(const PARSER_DIAGNOSTIC &) const =default
bool operator==(const PIN_REFERENCE &) const =default
PIN_REFERENCE(PIN_ID aId, SOURCE_PROVENANCE aSource)
bool operator==(const PLACED_PIN_REFERENCE &) const =default
bool operator==(const PRESERVED_CONTROLLER_PAYLOAD &) const =default
bool operator==(const SOURCE_POINT &) const =default
bool operator==(const SOURCE_PROPERTY &) const =default
bool operator==(const SOURCE_PROVENANCE &) const =default
bool operator==(const SOURCE_STRING &) const =default