LCOV - code coverage report
Current view: top level - OdbDesignLib/FileModel/Design - MatrixFile.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 67.4 % 276 186
Test Date: 2026-11-19 04:56:22 Functions: 83.3 % 12 10
Legend: Lines: hit not hit

            Line data    Source code
       1              : //
       2              : // Created by nmill on 10/13/2023.
       3              : //
       4              : 
       5              : #include "MatrixFile.h"
       6              : #include <fstream>
       7              : #include "str_utils.h"
       8              : #include <string>
       9              : #include "../../Constants.h"
      10              : #include <sstream>
      11              : #include "../parse_error.h"
      12              : #include <Logger.h>
      13              : #include "../invalid_odb_error.h"
      14              : #include "enums.pb.h"
      15              : #include "../../enums.h"
      16              : #include "../OdbFile.h"
      17              : #include <memory>
      18              : #include <ostream>
      19              : #include "../../Text/Utf8Sanitizer.h"
      20              : 
      21              : namespace Odb::Lib::FileModel::Design
      22              : {
      23           97 :     MatrixFile::~MatrixFile()
      24              :     {
      25           97 :         m_layerRecords.clear();
      26           97 :         m_stepRecords.clear();
      27           97 :     }
      28              : 
      29            4 :     const MatrixFile::LayerRecord::Vector& MatrixFile::GetLayerRecords() const
      30              :     { 
      31            4 :         return m_layerRecords;
      32              :     }
      33              : 
      34            3 :     const MatrixFile::StepRecord::Vector& MatrixFile::GetStepRecords() const
      35              :     { 
      36            3 :         return m_stepRecords;
      37              :     }
      38              : 
      39           93 :     bool MatrixFile::Parse(std::filesystem::path path)
      40              :         {
      41           93 :         std::ifstream matrixFile;
      42           93 :         int lineNumber = 0;
      43           93 :         std::string line;
      44              : 
      45              :         try
      46              :         {
      47           93 :             if (!OdbFile::Parse(path)) return false;
      48              : 
      49           93 :             auto matrixFilePath = path / "matrix";
      50           93 :             if (!std::filesystem::exists(matrixFilePath))
      51              :             {
      52            0 :                 auto message = "matrix/matrix file does not exist: [" + matrixFilePath.string() + "]";
      53            0 :                 throw invalid_odb_error(message.c_str());
      54            0 :             }
      55              : 
      56           93 :             matrixFile.open(matrixFilePath, std::ios::in);
      57           93 :             if (!matrixFile.is_open())
      58              :             {
      59            0 :                 auto message = "unable to open matrix/matrix file: [" + matrixFilePath.string() + "]";
      60            0 :                 throw invalid_odb_error(message.c_str());
      61            0 :             }
      62              : 
      63           93 :             std::shared_ptr<StepRecord> pCurrentStepRecord;
      64           93 :             std::shared_ptr<LayerRecord> pCurrentLayerRecord;
      65           93 :             bool openBraceFound = false;
      66              : 
      67        48663 :             while (std::getline(matrixFile, line))
      68              :             {
      69        48570 :                 lineNumber++;
      70              :                 // trim whitespace from beginning and end of line
      71        48570 :                 Utils::str_trim(line);
      72        48570 :                 if (!line.empty())
      73              :                 {
      74        45432 :                     std::stringstream lineStream(line);
      75        45432 :                     if (line.find(Constants::COMMENT_TOKEN) == 0)
      76              :                     {
      77              :                         // comment line
      78              :                     }
      79        45432 :                     else if (line.find(StepRecord::RECORD_TOKEN) == 0)
      80              :                     {
      81           93 :                         std::string token;
      82           93 :                         if (!(lineStream >> token))
      83              :                         {
      84            0 :                             throw_parse_error(m_path, line, token, lineNumber);
      85              :                         }
      86              : 
      87              :                         // any existing previous step record
      88           93 :                         if (token != StepRecord::RECORD_TOKEN || pCurrentStepRecord != nullptr)
      89              :                         {
      90            0 :                             throw_parse_error(m_path, line, token, lineNumber);
      91              :                         }
      92              : 
      93              :                         // open a new STEP array record
      94           93 :                         pCurrentStepRecord = std::make_shared<StepRecord>();
      95              : 
      96           93 :                         if (lineStream >> token)
      97              :                         {
      98              :                             // open brace is at the end on the same line
      99           93 :                             if (token == Constants::ARRAY_RECORD_OPEN_TOKEN)
     100              :                             {
     101           93 :                                 openBraceFound = true;
     102              :                             }
     103              :                         }
     104           93 :                     }
     105        45339 :                     else if (line.find(LayerRecord::RECORD_TOKEN) == 0)
     106              :                     {
     107         2979 :                         std::string token;
     108         2979 :                         if (!(lineStream >> token))
     109              :                         {
     110            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     111              :                         }
     112              : 
     113              :                         // any existing previous layer record
     114         2979 :                         if (token != LayerRecord::RECORD_TOKEN || pCurrentLayerRecord != nullptr)
     115              :                         {
     116            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     117              :                         }
     118              : 
     119              :                         // open a new LAYER array record
     120         2979 :                         pCurrentLayerRecord = std::make_shared<LayerRecord>();
     121              : 
     122         2979 :                         if (lineStream >> token)
     123              :                         {
     124              :                             // open brace is on same line
     125         2979 :                             if (token == Constants::ARRAY_RECORD_OPEN_TOKEN)
     126              :                             {
     127         2979 :                                 openBraceFound = true;
     128              :                             }
     129              :                         }
     130         2979 :                     }
     131        42360 :                     else if (line.find(Constants::ARRAY_RECORD_OPEN_TOKEN) == 0)
     132              :                     {
     133              :                         // TODO: how to determine if you are opening a step or layer array record?
     134              :                         // (maybe a boolean flag? stepArrayOpen = true/false)
     135              :                         
     136              :                         // no current opening of a layer or step array record found yet
     137            0 :                         if (pCurrentStepRecord == nullptr && pCurrentLayerRecord == nullptr)
     138              :                         {
     139            0 :                             throw_parse_error(m_path, line, "", lineNumber);
     140              :                         }
     141              : 
     142              :                         // found another open brace while still parsing after the previous record's open brace
     143            0 :                         if (openBraceFound)
     144              :                         {
     145            0 :                             throw_parse_error(m_path, line, "", lineNumber);
     146              :                         }
     147              : 
     148            0 :                         openBraceFound = true;
     149              : 
     150              :                         // TODO: finish any existing previous layer or step record
     151              :                         // (same code as finding a close brace on an empty line)
     152              : 
     153              :                         // open a new LAYER array record
     154              :                         //pCurrentLayerRecord = std::make_shared<LayerRecord>();
     155              :                     }
     156        42360 :                     else if (line.find(Constants::ARRAY_RECORD_CLOSE_TOKEN) == 0)
     157              :                     {
     158         3072 :                         if (pCurrentStepRecord != nullptr && openBraceFound)
     159              :                         {
     160           93 :                             m_stepRecords.push_back(pCurrentStepRecord);
     161           93 :                             pCurrentStepRecord.reset();
     162           93 :                             openBraceFound = false;
     163              :                         }
     164         2979 :                         else if (pCurrentLayerRecord != nullptr && openBraceFound)
     165              :                         {
     166         2979 :                             m_layerRecords.push_back(pCurrentLayerRecord);
     167         2979 :                             pCurrentLayerRecord.reset();
     168         2979 :                             openBraceFound = false;
     169              :                         }
     170              :                         else
     171              :                         {
     172              :                             // found a close brace but aren't currently parsing a step or layer array record
     173            0 :                             throw_parse_error(m_path, line, "", lineNumber);
     174              :                         }
     175              :                     }
     176              :                     else
     177              :                     {
     178              :                         // it should be a name-value pair line (i.e. element of a step or layer array)
     179        39288 :                         std::string attribute;
     180        39288 :                         std::string value;
     181              : 
     182        39288 :                         if (!std::getline(lineStream, attribute, '='))
     183              :                         {
     184            0 :                             throw_parse_error(m_path, line, attribute, lineNumber);
     185              :                         }
     186              : 
     187        39288 :                         if (std::getline(lineStream, value))
     188              :                         {
     189        22398 :                             Utils::str_trim(attribute);
     190        22398 :                             Utils::str_trim(value);
     191              : 
     192        22398 :                             if (pCurrentStepRecord != nullptr && openBraceFound)
     193              :                             {
     194          279 :                                 if (attribute == StepRecord::COLUMN_KEY || attribute == "col")
     195              :                                 {
     196           93 :                                     pCurrentStepRecord->column = std::stoi(value);
     197              :                                 }
     198          186 :                                 else if (attribute == StepRecord::NAME_KEY || attribute == "name")
     199              :                                 {
     200           93 :                                     pCurrentStepRecord->name = value;
     201              :                                 }
     202           93 :                                 else if (attribute == StepRecord::ID_KEY || attribute == "id")
     203              :                                 {
     204           93 :                                     pCurrentStepRecord->id = static_cast<unsigned int>(std::stoul(value));
     205              :                                 }
     206              :                                 else
     207              :                                 {
     208            0 :                                     throw_parse_error(m_path, line, attribute, lineNumber);
     209              :                                 }
     210              :                             }
     211        22119 :                             else if (pCurrentLayerRecord != nullptr && openBraceFound)
     212              :                             {
     213        22119 :                                 if (attribute == "ROW" || attribute == "row")
     214              :                                 {
     215         2979 :                                     pCurrentLayerRecord->row = std::stoi(value);
     216              :                                 }
     217        19140 :                                 else if (attribute == "NAME" || attribute == "name")
     218              :                                 {
     219         2979 :                                     pCurrentLayerRecord->name = value;
     220              :                                 }
     221        16161 :                                 else if (attribute == "ID" || attribute == "id")
     222              :                                 {
     223         2979 :                                     pCurrentLayerRecord->id = (unsigned int)std::stoul(value);
     224              :                                 }
     225        13182 :                                 else if (attribute == "TYPE" || attribute == "type")
     226              :                                 {                                    
     227         2979 :                                     if (LayerRecord::typeMap.contains(value))
     228              :                                     {
     229         2979 :                                         pCurrentLayerRecord->type = LayerRecord::typeMap.getValue(value);
     230              :                                     }                                        
     231              :                                     else
     232              :                                     {
     233            0 :                                         throw_parse_error(m_path, line, attribute, lineNumber);
     234              :                                     }
     235              :                                 }
     236        10203 :                                 else if (attribute == LayerRecord::CONTEXT_KEY || attribute == "context")
     237              :                                 {
     238         2979 :                                     if (LayerRecord::contextMap.contains(value))
     239              :                                     {
     240         2979 :                                                                                 pCurrentLayerRecord->context = LayerRecord::contextMap.getValue(value);
     241              :                                                                         }
     242              :                                     else
     243              :                                     {
     244            0 :                                                                                 throw_parse_error(m_path, line, attribute, lineNumber);
     245              :                                                                         }
     246              :                                 }
     247         7224 :                                 else if (attribute == "OLD_NAME" || attribute == "old_name")
     248              :                                 {
     249            0 :                                     pCurrentLayerRecord->oldName = value;
     250              :                                 }
     251         7224 :                                 else if (attribute == LayerRecord::POLARITY_KEY || attribute == "polarity")
     252              :                                 {
     253         2979 :                                     if (LayerRecord::polarityMap.contains(value))
     254              :                                     {
     255         2979 :                                                                                 pCurrentLayerRecord->polarity = LayerRecord::polarityMap.getValue(value);
     256              :                                                                         }
     257              :                                     else
     258              :                                     {
     259            0 :                                         throw_parse_error(m_path, line, attribute, lineNumber);
     260              :                                     }                                   
     261              :                                 }
     262         4245 :                                 else if (attribute == LayerRecord::DIELECTRIC_TYPE_KEY || attribute == "dielectric_type")
     263              :                                 {
     264          420 :                                     if (LayerRecord::dielectricTypeMap.contains(value))
     265              :                                     {
     266          420 :                                                                                 pCurrentLayerRecord->dielectricType = LayerRecord::dielectricTypeMap.getValue(value);
     267              :                                                                         }
     268              :                                     else
     269              :                                     {
     270            0 :                                                                                 throw_parse_error(m_path, line, attribute, lineNumber);
     271              :                                                                         }
     272              :                                 }
     273         3825 :                                 else if (attribute == "DIELECTRIC_NAME" || attribute == "dielectric_name")
     274              :                                 {
     275            0 :                                     pCurrentLayerRecord->dielectricName = value;
     276              :                                 }
     277         3825 :                                 else if (attribute == LayerRecord::FORM_KEY || attribute == "form")
     278              :                                 {
     279            0 :                                     if (LayerRecord::formMap.contains(value))
     280              :                                     {
     281            0 :                                                                                 pCurrentLayerRecord->form = LayerRecord::formMap.getValue(value);
     282              :                                                                         }
     283              :                                     else
     284              :                                     {
     285            0 :                                                                                 throw_parse_error(m_path, line, attribute, lineNumber);
     286              :                                                                         }
     287              :                                 }
     288         3825 :                                 else if (attribute == "CU_TOP" || attribute == "cu_top")
     289              :                                 {
     290            0 :                                     pCurrentLayerRecord->cuTop = std::stoul(value);
     291              :                                 }
     292         3825 :                                 else if (attribute == "CU_TOP" || attribute == "cu_top")
     293              :                                 {
     294            0 :                                     pCurrentLayerRecord->cuTop = std::stoul(value);
     295              :                                 }
     296         3825 :                                 else if (attribute == "CU_BOTTOM" || attribute == "cu_bottom")
     297              :                                 {
     298            0 :                                     pCurrentLayerRecord->cuBottom = std::stoul(value);
     299              :                                 }
     300         3825 :                                 else if (attribute == "REF" || attribute == "ref")
     301              :                                 {
     302            0 :                                     pCurrentLayerRecord->ref = std::stoul(value);
     303              :                                 }
     304         3825 :                                 else if (attribute == "START_NAME" || attribute == "start_name")
     305              :                                 {
     306          291 :                                     pCurrentLayerRecord->startName = value;
     307              :                                 }
     308         3534 :                                 else if (attribute == "END_NAME" || attribute == "end_name")
     309              :                                 {
     310          291 :                                     pCurrentLayerRecord->endName = value;
     311              :                                 }
     312         3243 :                                 else if (attribute == "ADD_TYPE" || attribute == "add_type")
     313              :                                 {
     314          264 :                                     pCurrentLayerRecord->addType = value;
     315              :                                 }
     316         2979 :                                 else if (attribute == "COLOR" || attribute == "color")
     317              :                                 {
     318         2979 :                                     if (!pCurrentLayerRecord->color.from_string(value))
     319              :                                     {
     320            0 :                                         throw_parse_error(m_path, line, value, lineNumber);
     321              :                                     }
     322              :                                 }
     323              :                                 else
     324              :                                 {
     325            0 :                                     throw_parse_error(m_path, line, attribute, lineNumber);
     326              :                                 }
     327              :                             }
     328              :                             else
     329              :                             {
     330              :                                 // found a name-value pair but aren't currently parsing a step or layer array record
     331              :                                 //return false;
     332            0 :                                 throw_parse_error(m_path, line, attribute, lineNumber);                                
     333              :                             }
     334              :                         }
     335        16890 :                         else if (!attributeValueIsOptional(attribute))
     336              :                         {
     337            0 :                             logwarn("matrix/matrix file: no value for non-optional attribute: " + attribute);
     338              :                         }                        
     339        39288 :                     }
     340        45432 :                 }
     341              :             }
     342              : 
     343           93 :             matrixFile.close();
     344           93 :         }
     345            0 :         catch (parse_error& pe)
     346              :         {
     347            0 :             auto m = pe.toString("Parse Error:");
     348            0 :             logerror(m);
     349              :             // cleanup file
     350            0 :             matrixFile.close();
     351            0 :             throw pe;
     352            0 :         }
     353            0 :         catch (invalid_odb_error& ioe)
     354              :         {
     355            0 :             parse_info pi(m_path, line, lineNumber);
     356            0 :             const auto m = pi.toString();
     357            0 :             logexception_msg(ioe, m);
     358              :             // cleanup file
     359            0 :             matrixFile.close();
     360            0 :             throw ioe;
     361            0 :         }
     362              : 
     363           93 :         return true;
     364           93 :         }
     365              : 
     366           96 :     std::unique_ptr<Odb::Lib::Protobuf::MatrixFile> Odb::Lib::FileModel::Design::MatrixFile::to_protobuf() const
     367              :     {
     368           96 :         std::unique_ptr<Odb::Lib::Protobuf::MatrixFile> pMatrixFileMessage(new Odb::Lib::Protobuf::MatrixFile);
     369          188 :         for (const auto& stepRecord : m_stepRecords)
     370              :         {
     371           92 :             auto pStepRecordMessage = pMatrixFileMessage->add_steps();
     372           92 :             pStepRecordMessage->CopyFrom(*stepRecord->to_protobuf());
     373              :         }
     374         2811 :         for (const auto& layerRecord : m_layerRecords)
     375              :         {
     376         2715 :             auto pLayerRecordMessage = pMatrixFileMessage->add_layers();
     377         2715 :             pLayerRecordMessage->CopyFrom(*layerRecord->to_protobuf());
     378              :         }
     379           96 :                 return pMatrixFileMessage;
     380              :         
     381            0 :     }
     382              : 
     383            8 :     void Odb::Lib::FileModel::Design::MatrixFile::from_protobuf(const Odb::Lib::Protobuf::MatrixFile& message)
     384              :     {
     385           14 :         for (const auto& stepRecord : message.steps())
     386              :         {
     387            6 :                         auto pStepRecord = std::make_shared<StepRecord>();
     388            6 :                         pStepRecord->from_protobuf(stepRecord);
     389            6 :                         m_stepRecords.push_back(pStepRecord);
     390            6 :                 }
     391          215 :         for (const auto& layerRecord : message.layers())
     392              :         {
     393          207 :                         auto pLayerRecord = std::make_shared<LayerRecord>();
     394          207 :                         pLayerRecord->from_protobuf(layerRecord);
     395          207 :                         m_layerRecords.push_back(pLayerRecord);
     396          207 :                 }
     397            8 :     }
     398              : 
     399            0 :     bool MatrixFile::Save(std::ostream& os)
     400              :     {
     401            0 :         for (const auto& stepRecord : m_stepRecords)
     402              :         {
     403            0 :                         os << StepRecord::RECORD_TOKEN << " " << Constants::ARRAY_RECORD_OPEN_TOKEN << std::endl;
     404              : 
     405            0 :                         os << '\t' << StepRecord::COLUMN_KEY << "=" << stepRecord->column << std::endl;
     406            0 :             os << '\t' << StepRecord::NAME_KEY << "=" << stepRecord->name << std::endl;
     407            0 :             os << '\t' << StepRecord::ID_KEY << "=" << stepRecord->id << std::endl;
     408              : 
     409            0 :                         os << Constants::ARRAY_RECORD_CLOSE_TOKEN << std::endl;
     410            0 :             os << std::endl;
     411              :                 }        
     412              : 
     413            0 :         for (const auto& layerRecord : m_layerRecords)
     414              :         {
     415            0 :             os << LayerRecord::RECORD_TOKEN << " " << Constants::ARRAY_RECORD_OPEN_TOKEN << std::endl;
     416              : 
     417            0 :             os << '\t' << LayerRecord::ROW_KEY << "=" << layerRecord->row << std::endl;
     418            0 :             os << '\t' << LayerRecord::CONTEXT_KEY << "=" << LayerRecord::contextMap.getValue(layerRecord->context) << std::endl;
     419            0 :             os << '\t' << LayerRecord::TYPE_KEY << "=" << LayerRecord::typeMap.getValue(layerRecord->type) << std::endl;
     420            0 :             os << '\t' << LayerRecord::NAME_KEY << "=" << layerRecord->name << std::endl;                      
     421            0 :             os << '\t' << LayerRecord::POLARITY_KEY << "=" << LayerRecord::polarityMap.getValue(layerRecord->polarity) << std::endl;
     422            0 :             os << '\t' << LayerRecord::FORM_KEY << "=" << LayerRecord::formMap.getValue(layerRecord->form) << std::endl;
     423            0 :             os << '\t' << LayerRecord::DIELECTRIC_TYPE_KEY << "=" << LayerRecord::dielectricTypeMap.getValue(layerRecord->dielectricType) << std::endl;
     424            0 :             os << '\t' << LayerRecord::DIELECTRIC_NAME_KEY << "=" << layerRecord->dielectricName << std::endl;            
     425            0 :             os << '\t' << LayerRecord::CU_TOP_KEY << "=";
     426            0 :             if (layerRecord->cuTop != (unsigned int)-1)
     427              :             {
     428            0 :                 os << layerRecord->cuTop;
     429              :             }    
     430            0 :             os << std::endl;
     431            0 :             os << '\t' << LayerRecord::CU_BOTTOM_KEY << "=";
     432            0 :             if (layerRecord->cuBottom != (unsigned int)-1)
     433              :             {
     434            0 :                                 os << layerRecord->cuBottom;
     435              :                         }
     436            0 :             os << std::endl;
     437            0 :             os << '\t' << LayerRecord::REF_KEY << "=";
     438            0 :             if (layerRecord->ref != (unsigned int)-1)
     439              :             {
     440            0 :                 os << layerRecord->ref;
     441              :             }
     442            0 :             os << std::endl;
     443            0 :             os << '\t' << LayerRecord::START_NAME_KEY << "=" << layerRecord->startName << std::endl;
     444            0 :             os << '\t' << LayerRecord::END_NAME_KEY << "=" << layerRecord->endName << std::endl;
     445            0 :             os << '\t' << LayerRecord::OLD_NAME_KEY << "=" << layerRecord->oldName << std::endl;
     446            0 :             os << '\t' << LayerRecord::ADD_TYPE_KEY << "=" << layerRecord->addType << std::endl;
     447            0 :             os << '\t' << LayerRecord::COLOR_KEY << "=" << layerRecord->color.to_string() << std::endl;
     448            0 :             os << '\t' << LayerRecord::ID_KEY << "=" << layerRecord->id << std::endl;
     449              :             
     450            0 :             os << Constants::ARRAY_RECORD_CLOSE_TOKEN << std::endl;            
     451            0 :             os << std::endl;
     452              :         }
     453              : 
     454            0 :         return true;
     455              :     }
     456              :     
     457           92 :     std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::StepRecord> Odb::Lib::FileModel::Design::MatrixFile::StepRecord::to_protobuf() const
     458              :     {
     459           92 :                 std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::StepRecord> pStepRecordMessage(new Odb::Lib::Protobuf::MatrixFile::StepRecord);
     460           92 :                 pStepRecordMessage->set_column(column);
     461          184 :                 pStepRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
     462           92 :                 pStepRecordMessage->set_id(id);
     463           92 :                 return pStepRecordMessage;
     464            0 :         }
     465              : 
     466            6 :     void Odb::Lib::FileModel::Design::MatrixFile::StepRecord::from_protobuf(const Odb::Lib::Protobuf::MatrixFile::StepRecord& message)
     467              :     {
     468            6 :         column = message.column();
     469            6 :         name = message.name();
     470            6 :         id = message.id();
     471            6 :     }
     472              : 
     473         2742 :     std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::LayerRecord> Odb::Lib::FileModel::Design::MatrixFile::LayerRecord::to_protobuf() const
     474              :     {
     475         2742 :         std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::LayerRecord> pLayerRecordMessage(new Odb::Lib::Protobuf::MatrixFile::LayerRecord);
     476         5484 :         pLayerRecordMessage->set_addtype(Odb::Lib::Text::ToUtf8(addType));
     477         2742 :         pLayerRecordMessage->set_context(static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Context>(context));
     478         2742 :         pLayerRecordMessage->set_cubottom(cuBottom);
     479         2742 :         pLayerRecordMessage->set_cutop(cuTop);
     480         5484 :         pLayerRecordMessage->set_dielectricname(Odb::Lib::Text::ToUtf8(dielectricName));
     481         2742 :         pLayerRecordMessage->set_dielectrictype(static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::DielectricType>(dielectricType));
     482         5484 :         pLayerRecordMessage->set_endname(Odb::Lib::Text::ToUtf8(endName));
     483         2742 :         pLayerRecordMessage->set_form(static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Form>(form));
     484         2742 :         pLayerRecordMessage->set_id(id);
     485         5484 :         pLayerRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
     486         5484 :         pLayerRecordMessage->set_oldname(Odb::Lib::Text::ToUtf8(oldName));
     487         2742 :         pLayerRecordMessage->set_polarity(static_cast<Odb::Lib::Protobuf::Polarity>(polarity));
     488         2742 :         pLayerRecordMessage->set_ref(ref);
     489         2742 :         pLayerRecordMessage->set_row(row);
     490         5484 :         pLayerRecordMessage->set_startname(Odb::Lib::Text::ToUtf8(startName));
     491         2742 :         pLayerRecordMessage->set_type(static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Type>(type));
     492         2742 :         pLayerRecordMessage->mutable_color()->set_red(color.red);
     493         2742 :         pLayerRecordMessage->mutable_color()->set_green(color.green);
     494         2742 :         pLayerRecordMessage->mutable_color()->set_blue(color.blue);
     495         2742 :         pLayerRecordMessage->mutable_color()->set_nopreference(color.noPreference);
     496              : 
     497         2742 :         return pLayerRecordMessage;
     498            0 :     }       
     499              : 
     500          234 :     void Odb::Lib::FileModel::Design::MatrixFile::LayerRecord::from_protobuf(const Odb::Lib::Protobuf::MatrixFile::LayerRecord& message)
     501              :     {
     502          234 :         addType = message.addtype();
     503          234 :                 context = static_cast<Context>(message.context());
     504          234 :                 cuBottom = message.cubottom();
     505          234 :                 cuTop = message.cutop();
     506          234 :                 dielectricName = message.dielectricname();
     507          234 :                 dielectricType = static_cast<DielectricType>(message.dielectrictype());
     508          234 :                 endName = message.endname();
     509          234 :                 form = static_cast<Form>(message.form());
     510          234 :                 id = message.id();
     511          234 :                 name = message.name();
     512          234 :                 oldName = message.oldname();
     513          234 :                 polarity = static_cast<Polarity>(message.polarity());
     514          234 :                 ref = message.ref();
     515          234 :                 row = message.row();
     516          234 :                 startName = message.startname();
     517          234 :                 type = static_cast<Type>(message.type());
     518          234 :         if (message.has_color())
     519              :         {
     520          234 :             color.red = static_cast<decltype(color.red)>(message.color().red());
     521          234 :             color.green = static_cast<decltype(color.green)>(message.color().green());
     522          234 :             color.blue = static_cast<decltype(color.blue)>(message.color().blue());
     523          234 :             color.noPreference = message.color().nopreference();
     524              :         }
     525              :         // color unset: keep the parsed/default no-preference color rather
     526              :         // than overwriting it with an empty message's zeros
     527          234 :     }   
     528              : }
        

Generated by: LCOV version 2.0-1