41 std::ifstream matrixFile;
49 auto matrixFilePath = path /
"matrix";
50 if (!std::filesystem::exists(matrixFilePath))
52 auto message =
"matrix/matrix file does not exist: [" + matrixFilePath.string() +
"]";
56 matrixFile.open(matrixFilePath, std::ios::in);
57 if (!matrixFile.is_open())
59 auto message =
"unable to open matrix/matrix file: [" + matrixFilePath.string() +
"]";
63 std::shared_ptr<StepRecord> pCurrentStepRecord;
64 std::shared_ptr<LayerRecord> pCurrentLayerRecord;
65 bool openBraceFound =
false;
67 while (std::getline(matrixFile, line))
74 std::stringstream lineStream(line);
82 if (!(lineStream >> token))
94 pCurrentStepRecord = std::make_shared<StepRecord>();
96 if (lineStream >> token)
101 openBraceFound =
true;
108 if (!(lineStream >> token))
120 pCurrentLayerRecord = std::make_shared<LayerRecord>();
122 if (lineStream >> token)
127 openBraceFound =
true;
137 if (pCurrentStepRecord ==
nullptr && pCurrentLayerRecord ==
nullptr)
148 openBraceFound =
true;
158 if (pCurrentStepRecord !=
nullptr && openBraceFound)
160 m_stepRecords.push_back(pCurrentStepRecord);
161 pCurrentStepRecord.reset();
162 openBraceFound =
false;
164 else if (pCurrentLayerRecord !=
nullptr && openBraceFound)
166 m_layerRecords.push_back(pCurrentLayerRecord);
167 pCurrentLayerRecord.reset();
168 openBraceFound =
false;
179 std::string attribute;
182 if (!std::getline(lineStream, attribute,
'='))
187 if (std::getline(lineStream, value))
192 if (pCurrentStepRecord !=
nullptr && openBraceFound)
196 pCurrentStepRecord->column = std::stoi(value);
200 pCurrentStepRecord->name = value;
204 pCurrentStepRecord->id =
static_cast<unsigned int>(std::stoul(value));
211 else if (pCurrentLayerRecord !=
nullptr && openBraceFound)
213 if (attribute ==
"ROW" || attribute ==
"row")
215 pCurrentLayerRecord->row = std::stoi(value);
217 else if (attribute ==
"NAME" || attribute ==
"name")
219 pCurrentLayerRecord->name = value;
221 else if (attribute ==
"ID" || attribute ==
"id")
223 pCurrentLayerRecord->id = (
unsigned int)std::stoul(value);
225 else if (attribute ==
"TYPE" || attribute ==
"type")
247 else if (attribute ==
"OLD_NAME" || attribute ==
"old_name")
249 pCurrentLayerRecord->oldName = value;
273 else if (attribute ==
"DIELECTRIC_NAME" || attribute ==
"dielectric_name")
275 pCurrentLayerRecord->dielectricName = value;
288 else if (attribute ==
"CU_TOP" || attribute ==
"cu_top")
290 pCurrentLayerRecord->cuTop = std::stoul(value);
292 else if (attribute ==
"CU_TOP" || attribute ==
"cu_top")
294 pCurrentLayerRecord->cuTop = std::stoul(value);
296 else if (attribute ==
"CU_BOTTOM" || attribute ==
"cu_bottom")
298 pCurrentLayerRecord->cuBottom = std::stoul(value);
300 else if (attribute ==
"REF" || attribute ==
"ref")
302 pCurrentLayerRecord->ref = std::stoul(value);
304 else if (attribute ==
"START_NAME" || attribute ==
"start_name")
306 pCurrentLayerRecord->startName = value;
308 else if (attribute ==
"END_NAME" || attribute ==
"end_name")
310 pCurrentLayerRecord->endName = value;
312 else if (attribute ==
"ADD_TYPE" || attribute ==
"add_type")
314 pCurrentLayerRecord->addType = value;
316 else if (attribute ==
"COLOR" || attribute ==
"color")
318 if (!pCurrentLayerRecord->color.from_string(value))
337 logwarn(
"matrix/matrix file: no value for non-optional attribute: " + attribute);
347 auto m = pe.
toString(
"Parse Error:");
401 for (
const auto& stepRecord : m_stepRecords)
413 for (
const auto& layerRecord : m_layerRecords)
426 if (layerRecord->cuTop != (
unsigned int)-1)
428 os << layerRecord->cuTop;
432 if (layerRecord->cuBottom != (
unsigned int)-1)
434 os << layerRecord->cuBottom;
438 if (layerRecord->ref != (
unsigned int)-1)
440 os << layerRecord->ref;
475 std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::LayerRecord> pLayerRecordMessage(
new Odb::Lib::Protobuf::MatrixFile::LayerRecord);
477 pLayerRecordMessage->set_context(
static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Context
>(context));
478 pLayerRecordMessage->set_cubottom(cuBottom);
479 pLayerRecordMessage->set_cutop(cuTop);
481 pLayerRecordMessage->set_dielectrictype(
static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::DielectricType
>(dielectricType));
483 pLayerRecordMessage->set_form(
static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Form
>(form));
484 pLayerRecordMessage->set_id(
id);
487 pLayerRecordMessage->set_polarity(
static_cast<Odb::Lib::Protobuf::Polarity
>(polarity));
488 pLayerRecordMessage->set_ref(ref);
489 pLayerRecordMessage->set_row(row);
491 pLayerRecordMessage->set_type(
static_cast<Odb::Lib::Protobuf::MatrixFile::LayerRecord::Type
>(type));
492 pLayerRecordMessage->mutable_color()->set_red(color.red);
493 pLayerRecordMessage->mutable_color()->set_green(color.green);
494 pLayerRecordMessage->mutable_color()->set_blue(color.blue);
495 pLayerRecordMessage->mutable_color()->set_nopreference(color.noPreference);
497 return pLayerRecordMessage;
502 addType = message.addtype();
503 context =
static_cast<Context>(message.context());
504 cuBottom = message.cubottom();
505 cuTop = message.cutop();
506 dielectricName = message.dielectricname();
507 dielectricType =
static_cast<DielectricType>(message.dielectrictype());
508 endName = message.endname();
509 form =
static_cast<Form>(message.form());
511 name = message.name();
512 oldName = message.oldname();
513 polarity =
static_cast<Polarity>(message.polarity());
516 startName = message.startname();
517 type =
static_cast<Type>(message.type());
518 if (message.has_color())
520 color.red =
static_cast<decltype(color.red)
>(message.color().red());
521 color.green =
static_cast<decltype(color.green)
>(message.color().green());
522 color.blue =
static_cast<decltype(color.blue)
>(message.color().blue());
523 color.noPreference = message.color().nopreference();
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.