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
316
317
319{
321 uint32_t codePage = 1252;
324 int64_t defaultLineWidth = 0;
325 int64_t defaultBusWidth = 0;
326 std::vector<SOURCE_PROPERTY> properties;
327
328 bool operator==( const DESIGN_SETTINGS& ) const = default;
329};
330
331
347
348
358
359
380
381
390
391
393{
397 std::vector<MODEL_GRAPHIC> graphics;
398
399 bool operator==( const MODEL_WORKSHEET& ) const = default;
400};
401
402
436
437
439{
443 std::vector<MODEL_GRAPHIC> graphics;
444 std::vector<MODEL_PIN_DEFINITION> pins;
445 std::vector<MODEL_FIELD> fields;
446 std::vector<SOURCE_PROPERTY> properties;
447
448 bool operator==( const MODEL_SYMBOL_DEFINITION& ) const = default;
449};
450
451
463
464
477
478
480{
484 uint32_t unit = 1;
485 std::vector<PIN_REFERENCE> pins;
486 std::vector<MODEL_GATE_PIN> logicalPins;
487 std::vector<DEFINITION_REFERENCE> alternateDefinitions;
488 std::vector<DEFINITION_REFERENCE> decalGroupMembers;
489 std::vector<MODEL_CONNECTOR_PIN> connectorPins;
490 std::vector<SOURCE_PROPERTY> properties;
491
492 bool operator==( const MODEL_GATE& ) const = default;
493};
494
495
504
505
507{
511 std::vector<MODEL_GATE> gates;
512 std::vector<MODEL_FIELD> fields;
513 std::vector<SOURCE_PROPERTY> properties;
514 std::vector<MODEL_SIGNAL_PIN> signalPins;
515
516 bool operator==( const MODEL_PART_TYPE& ) const = default;
517};
518
519
521{
523 size_t index = 0;
526 std::optional<SHEET_REFERENCE> parent;
528 int64_t defaultLineWidth = 0;
529 int64_t defaultBusWidth = 0;
531 std::vector<MODEL_GRAPHIC> border;
532 std::vector<MODEL_FIELD> titleBlockFields;
533 std::vector<SOURCE_PROPERTY> properties;
534
535 bool operator==( const MODEL_SHEET& ) const = default;
536};
537
538
540{
545 std::optional<GATE_REFERENCE> gate;
547 std::vector<PLACED_PIN_REFERENCE> pins;
548 uint32_t unit = 1;
551 int angle = 0;
552 bool mirrored = false;
553 uint16_t mirrorFlags = 0;
555 bool referenceVisible = true;
556 bool partTypeVisible = true;
557 bool pinNamesVisible = true;
558 bool pinNumbersVisible = true;
559 std::vector<MODEL_FIELD> fields;
560 std::vector<SOURCE_PROPERTY> properties;
561
562 bool operator==( const MODEL_PLACEMENT& ) const = default;
563};
564
565
572
573
575{
578 std::optional<PLACEMENT_REFERENCE> placement;
579 std::optional<PIN_REFERENCE> pin;
581 std::vector<SOURCE_PROPERTY> properties;
582
583 bool operator==( const MODEL_CONNECTION_ENDPOINT& ) const = default;
584};
585
586
588{
590 std::vector<MODEL_CONNECTION_ENDPOINT> endpoints;
591 std::vector<SOURCE_POINT> vertices;
592 std::vector<SOURCE_PROPERTY> properties;
593
594 bool operator==( const MODEL_CONNECTION& ) const = default;
595};
596
597
599{
604 std::vector<MODEL_CONNECTION> connections;
605 std::vector<SOURCE_PROPERTY> properties;
606
607 bool operator==( const MODEL_NET& ) const = default;
608};
609
610
612{
616 std::vector<SOURCE_PROPERTY> properties;
617
618 bool operator==( const MODEL_BUS_ENTRY& ) const = default;
619};
620
621
623{
628 std::vector<SOURCE_POINT> vertices;
629 std::vector<MODEL_BUS_ENTRY> entries;
630 std::vector<SOURCE_STRING> aliases;
631 std::vector<SOURCE_STRING> declaredMembers;
632 std::vector<NET_REFERENCE> memberNets;
633 std::vector<SOURCE_PROPERTY> properties;
634
635 bool operator==( const MODEL_BUS& ) const = default;
636};
637
638
649
650
667
668
670{
674 std::vector<SOURCE_PROPERTY> properties;
675
676 bool operator==( const MODEL_JUNCTION& ) const = default;
677};
678
679
692
693
701
702
704{
709 wxString streamName;
710 std::array<int32_t, 4> extent{};
711 std::array<int32_t, 4> databaseBox{};
714 bool mirrorHorizontal = false;
715 bool mirrorVertical = false;
716 uint32_t flags = 0;
717 std::vector<uint8_t> data;
718 std::vector<SOURCE_PROPERTY> properties;
719
720 bool operator==( const MODEL_EMBEDDED_IMAGE& ) const = default;
721};
722
723
732
733
735{
736 uint16_t version = 0;
737 uint16_t subversion = 0;
740 std::vector<MODEL_SHEET> sheets;
741 std::vector<MODEL_SYMBOL_DEFINITION> definitions;
742 std::vector<MODEL_PART_TYPE> partTypes;
743 std::vector<MODEL_PLACEMENT> placements;
744 std::vector<MODEL_NET> nets;
745 std::vector<MODEL_BUS> buses;
746 std::vector<MODEL_LABEL> labels;
747 std::vector<MODEL_JUNCTION> junctions;
748 std::vector<MODEL_TEXT> texts;
749 std::vector<MODEL_PAGE_GRAPHIC> graphics;
750 std::vector<MODEL_WORKSHEET> worksheets;
751 std::vector<MODEL_EMBEDDED_IMAGE> images;
752 std::vector<PRESERVED_CONTROLLER_PAYLOAD> preservedControllerPayloads;
753 std::vector<PARSER_DIAGNOSTIC> diagnostics;
754
755 void ValidateOrThrow() const;
756
757 bool operator==( const PADS_SCH_MODEL& ) const = default;
758};
759
760} // namespace PADS_SCH_BINARY
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