LCOV - code coverage report
Current view: top level - OdbDesignLib/FileModel/Design - MatrixFile.h (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 100.0 % 5 5
Test Date: 2026-11-21 03:51:50 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : //
       4              : // Created by nmill on 10/13/2023.
       5              : //
       6              : 
       7              : #include "../OdbFile.h"
       8              : #include <filesystem>
       9              : #include <vector>
      10              : #include <memory>
      11              : #include "RgbColor.h"
      12              : #include "../../enums.h"
      13              : #include "../../IProtoBuffable.h"
      14              : #include "matrixfile.pb.h"
      15              : #include "../IStreamSaveable.h"
      16              : #include "EnumMap.h"
      17              : #include <string>
      18              : #include <iostream>
      19              : #include "../../odbdesign_export.h"
      20              : 
      21              : 
      22              : namespace Odb::Lib::FileModel::Design
      23              : {
      24              :     class ODBDESIGN_EXPORT MatrixFile : public OdbFile, public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile>, public IStreamSaveable
      25              :     {
      26              :     public:
      27              :         ~MatrixFile();
      28              : 
      29              :         struct StepRecord : public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile::StepRecord>
      30              :         {
      31              :             unsigned int column = 0;
      32              :             unsigned int id = (unsigned int)-1;
      33              :             std::string name;
      34              : 
      35              :             typedef std::vector<std::shared_ptr<StepRecord>> Vector;
      36              : 
      37              :             inline static const char* RECORD_TOKEN = "STEP";
      38              :             inline static const char* COLUMN_KEY = "COL";
      39              :             inline static const char* NAME_KEY = "NAME";
      40              :             inline static const char* ID_KEY = "ID";
      41              : 
      42              :             // Inherited via IProtoBuffable
      43              :             std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::StepRecord> to_protobuf() const override;
      44              :             void from_protobuf(const Odb::Lib::Protobuf::MatrixFile::StepRecord& message) override;
      45              :         };
      46              : 
      47              :         struct LayerRecord : public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile::LayerRecord>
      48              :         {
      49              :             enum class Type
      50              :             {
      51              :                 Signal,
      52              :                 PowerGround,
      53              :                 Dielectric,
      54              :                 Mixed,
      55              :                 SolderMask,
      56              :                 SolderPaste,
      57              :                 SilkScreen,
      58              :                 Drill,
      59              :                 Rout,
      60              :                 Document,
      61              :                 Component,
      62              :                 Mask,
      63              :                 ConductivePaste,
      64              :             };
      65              : 
      66              :             enum class Context
      67              :             {
      68              :                 Board,
      69              :                 Misc
      70              :             };
      71              : 
      72              :             enum class DielectricType
      73              :             {
      74              :                 NotSet,
      75              :                 None,
      76              :                 Prepreg,
      77              :                 Core
      78              :             };
      79              : 
      80              :             enum class Form
      81              :             {
      82              :                 NotSet,
      83              :                 Rigid,
      84              :                 Flex
      85              :             };
      86              : 
      87              :             typedef std::vector<std::shared_ptr<LayerRecord>> Vector;
      88              : 
      89              :             int row = 0;
      90              :             Context context = Context::Board;
      91              :             Type type = Type::Signal;
      92              :             std::string name;
      93              :             Polarity polarity = Polarity::Positive;
      94              :             DielectricType dielectricType = DielectricType::NotSet;
      95              :             std::string dielectricName;
      96              :             Form form = Form::NotSet;
      97              :             unsigned int cuTop = (unsigned int)-1;
      98              :             unsigned int cuBottom = (unsigned int)-1;
      99              :             unsigned int ref = (unsigned int)-1;
     100              :             std::string startName;
     101              :             std::string endName;
     102              :             std::string oldName;
     103              :             std::string addType;
     104              :             RgbColor color{ "0" };
     105              :             unsigned int id = (unsigned int)-1;
     106              : 
     107              :             inline static const char* RECORD_TOKEN = "LAYER";
     108              : 
     109              :             inline static const char* ROW_KEY = "ROW";
     110              :             inline static const char* CONTEXT_KEY = "CONTEXT";
     111              :             inline static const char* TYPE_KEY = "TYPE";
     112              :             inline static const char* NAME_KEY = "NAME";
     113              :             inline static const char* POLARITY_KEY = "POLARITY";
     114              :             inline static const char* DIELECTRIC_TYPE_KEY = "DIELECTRIC_TYPE";
     115              :             inline static const char* DIELECTRIC_NAME_KEY = "DIELECTRIC_NAME";
     116              :             inline static const char* FORM_KEY = "FORM";
     117              :             inline static const char* CU_TOP_KEY = "CU_TOP";
     118              :             inline static const char* CU_BOTTOM_KEY = "CU_BOTTOM";
     119              :             inline static const char* REF_KEY = "REF";
     120              :             inline static const char* START_NAME_KEY = "START_NAME";
     121              :             inline static const char* END_NAME_KEY = "END_NAME";
     122              :             inline static const char* OLD_NAME_KEY = "OLD_NAME";
     123              :             inline static const char* ADD_TYPE_KEY = "ADD_TYPE";
     124              :             inline static const char* COLOR_KEY = "COLOR";
     125              :             inline static const char* ID_KEY = "ID";
     126              : 
     127              :             // Inherited via IProtoBuffable
     128              :             std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::LayerRecord> to_protobuf() const override;
     129              :             void from_protobuf(const Odb::Lib::Protobuf::MatrixFile::LayerRecord& message) override;
     130              : 
     131              :             inline static const Utils::EnumMap<Type> typeMap {
     132              :                 {
     133              :                                     "SIGNAL",
     134              :                                     "POWER_GROUND",
     135              :                                     "DIELECTRIC",
     136              :                                     "MIXED",
     137              :                     "SOLDER_MASK",
     138              :                     "SOLDER_PASTE",
     139              :                     "SILK_SCREEN",
     140              :                                     "DRILL",
     141              :                                     "ROUT",
     142              :                                     "DOCUMENT",
     143              :                                     "COMPONENT",
     144              :                                     "MASK",
     145              :                                     "CONDUCTIVE_PASTE"
     146              :                 }
     147              :             };
     148              : 
     149              :             inline static const Utils::EnumMap<Context> contextMap{
     150              :                {
     151              :                    "BOARD",
     152              :                    "MISC"
     153              :                }
     154              :             };
     155              : 
     156              :             inline static const Utils::EnumMap<DielectricType> dielectricTypeMap{
     157              :                 {
     158              :                     "",
     159              :                     "NONE",
     160              :                     "PREPREG",
     161              :                     "CORE"
     162              :                 }
     163              :             };
     164              : 
     165              :             inline static const Utils::EnumMap<Form> formMap{
     166              :                 {
     167              :                     "",
     168              :                     "RIGID",
     169              :                     "FLEX"
     170              :                 }
     171              :             };
     172              : 
     173              :             inline static const Utils::EnumMap<Polarity> polarityMap{
     174              :                 {
     175              :                                         "POSITIVE",
     176              :                                         "NEGATIVE"
     177              :                                 }
     178              :                         };
     179              :         };
     180              : 
     181              :         const LayerRecord::Vector& GetLayerRecords() const;
     182              :         const StepRecord::Vector& GetStepRecords() const;
     183              : 
     184              :         // Inherited via OdbFile
     185              :         bool Parse(std::filesystem::path path) override;
     186              :         // Inherited via IStreamSaveable
     187              :         bool Save(std::ostream& os) override;
     188              : 
     189        16350 :         static inline bool attributeValueIsOptional(const std::string& attribute)
     190              :         {
     191       110893 :             for (const auto& optionalAttribute : OPTIONAL_ATTRIBUTES)
     192              :             {
     193       110890 :                 if (attribute == optionalAttribute)
     194              :                 {
     195        16347 :                     return true;
     196              :                 }
     197              :             }
     198            3 :             return false;
     199              :         }
     200              : 
     201              :         // Inherited via IProtoBuffable
     202              :         std::unique_ptr<Odb::Lib::Protobuf::MatrixFile> to_protobuf() const override;
     203              :         void from_protobuf(const Odb::Lib::Protobuf::MatrixFile& message) override;
     204              : 
     205              :     private:
     206              :         LayerRecord::Vector m_layerRecords;
     207              :         StepRecord::Vector m_stepRecords;
     208              : 
     209              :         constexpr inline static const char* OPTIONAL_ATTRIBUTES[] =
     210              :         {
     211              :             "OLD_NAME",
     212              :             "old_name",
     213              :             "START_NAME",
     214              :             "start_name",
     215              :             "END_NAME",
     216              :             "end_name",
     217              :             "ADD_TYPE",
     218              :             "ID",
     219              :             "DIELECTRIC_TYPE",
     220              :             "DIELECTRIC_NAME",
     221              :             "FORM",
     222              :             "CU_TOP",
     223              :             "CU_BOTTOM",
     224              :             "REF",
     225              :             "COLOR",
     226              :         };      
     227              :     };
     228              : }
     229              : 
        

Generated by: LCOV version 2.0-1