Skip to content

Commit

Permalink
merge to development (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 authored Nov 23, 2023
2 parents 6f2c557 + 726b38b commit d723dd2
Show file tree
Hide file tree
Showing 42 changed files with 12,819 additions and 2,249 deletions.
5 changes: 3 additions & 2 deletions OdbDesignLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#

add_library(OdbDesign SHARED
"odbdesign_export.h" "FileModel/Design/ComponentLayerDirectory.cpp" "FileModel/Design/ComponentLayerDirectory.h" "FileModel/Design/EdaDataFile.cpp" "FileModel/Design/EdaDataFile.h" "FileModel/Design/LayerDirectory.cpp" "FileModel/Design/LayerDirectory.h" "FileModel/Design/NetlistFile.cpp" "FileModel/Design/NetlistFile.h" "FileModel/Design/FileArchive.cpp" "FileModel/Design/FileArchive.h" "FileModel/Design/StepDirectory.cpp" "FileModel/Design/StepDirectory.h" "ProductModel/Net.h" "ProductModel/Net.cpp" "ProductModel/Component.h" "ProductModel/Component.cpp" "ProductModel/Pin.h" "ProductModel/Pin.cpp" "ProductModel/PinConnection.h" "ProductModel/PinConnection.cpp" "ProductModel/Package.h" "ProductModel/Package.cpp" "ProductModel/Part.h" "ProductModel/Part.cpp" "ProductModel/Via.h" "ProductModel/Via.cpp" "ProductModel/Design.h" "ProductModel/Design.cpp" "OdbDesign.h" "App/DesignCache.h" "App/DesignCache.cpp" "win.h" "IProtoBuffable.h" "crow_win.h" "FileModel/OdbFile.h" "FileModel/OdbFile.cpp" "FileModel/OdbFileRecord.h" "FileModel/OdbFileRecord.cpp" "App/IOdbApp.h" "App/IOdbApp.cpp" "App/OdbAppBase.h" "App/OdbAppBase.cpp" "App/RouteController.h" "App/RouteController.cpp" "App/IOdbServerApp.h" "App/OdbServerAppBase.h" "App/OdbServerAppBase.cpp" "App/IOdbServerApp.cpp"
"odbdesign_export.h" "FileModel/Design/ComponentsFile.cpp" "FileModel/Design/ComponentsFile.h" "FileModel/Design/EdaDataFile.cpp" "FileModel/Design/EdaDataFile.h" "FileModel/Design/LayerDirectory.cpp" "FileModel/Design/LayerDirectory.h" "FileModel/Design/NetlistFile.cpp" "FileModel/Design/NetlistFile.h" "FileModel/Design/FileArchive.cpp" "FileModel/Design/FileArchive.h" "FileModel/Design/StepDirectory.cpp" "FileModel/Design/StepDirectory.h" "ProductModel/Net.h" "ProductModel/Net.cpp" "ProductModel/Component.h" "ProductModel/Component.cpp" "ProductModel/Pin.h" "ProductModel/Pin.cpp" "ProductModel/PinConnection.h" "ProductModel/PinConnection.cpp" "ProductModel/Package.h" "ProductModel/Package.cpp" "ProductModel/Part.h" "ProductModel/Part.cpp" "ProductModel/Via.h" "ProductModel/Via.cpp" "ProductModel/Design.h" "ProductModel/Design.cpp" "OdbDesign.h" "App/DesignCache.h" "App/DesignCache.cpp" "win.h" "IProtoBuffable.h" "crow_win.h" "FileModel/OdbFile.h" "FileModel/OdbFile.cpp" "FileModel/OdbFileRecord.h" "FileModel/OdbFileRecord.cpp" "App/IOdbApp.h" "App/IOdbApp.cpp" "App/OdbAppBase.h" "App/OdbAppBase.cpp" "App/RouteController.h" "App/RouteController.cpp" "App/IOdbServerApp.h" "App/OdbServerAppBase.h" "App/OdbServerAppBase.cpp" "App/IOdbServerApp.cpp"
FileModel/Design/MatrixFile.cpp
FileModel/Design/MatrixFile.h
FileModel/Design/MiscInfoFile.cpp
Expand All @@ -21,7 +21,8 @@ add_library(OdbDesign SHARED
"ProtoBuf/miscinfofile.pb.h" "ProtoBuf/miscinfofile.pb.cc"
"ProtoBuf/standardfontsfile.pb.h" "ProtoBuf/standardfontsfile.pb.cc"
"ProtoBuf/stepdirectory.pb.h" "ProtoBuf/stepdirectory.pb.cc"
"FileModel/parse_error.h" "FileModel/parse_info.h" "FileModel/parse_info.cpp" "FileModel/parse_error.cpp" "FileModel/invalid_odb_error.h" "FileModel/invalid_odb_error.cpp")
"ProtoBuf/enums.pb.h" "ProtoBuf/enums.pb.cc"
"FileModel/parse_error.h" "FileModel/parse_info.h" "FileModel/parse_info.cpp" "FileModel/parse_error.cpp" "FileModel/invalid_odb_error.h" "FileModel/invalid_odb_error.cpp" "ProtoBuf/common.pb.h" "ProtoBuf/common.pb.cc" "ProtoBuf/componentsfile.pb.h" "ProtoBuf/componentsfile.pb.cc" "FileModel/Design/PropertyRecord.h" "FileModel/Design/PropertyRecord.cpp")

# disable warning C4250: inheritance by dominance
target_compile_options(OdbDesign PUBLIC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ComponentLayerDirectory.h"
#include "ComponentsFile.h"
#include <fstream>
#include <sstream>
#include <filesystem>
Expand All @@ -15,65 +15,90 @@ using namespace std::filesystem;

namespace Odb::Lib::FileModel::Design
{
ComponentLayerDirectory::ComponentLayerDirectory(std::filesystem::path path, BoardSide side)
: LayerDirectory(path), m_id(0)
, m_side(side)
ComponentsFile::ComponentsFile()
: m_id((unsigned int)-1)
, m_side(BoardSide::Neither)
{
}

ComponentLayerDirectory::~ComponentLayerDirectory()
ComponentsFile::~ComponentsFile()
{
m_attributeNames.clear();
m_attributeTextValues.clear();
m_componentRecords.clear();
m_componentRecordsByName.clear();
}

std::string ComponentLayerDirectory::GetUnits() const
std::string ComponentsFile::GetUnits() const
{
return m_units;
}

BoardSide ComponentLayerDirectory::GetSide() const
BoardSide ComponentsFile::GetSide() const
{
return m_side;
}

const ComponentLayerDirectory::ComponentRecord::Vector& ComponentLayerDirectory::GetComponentRecords() const
std::filesystem::path ComponentsFile::GetPath()
{
return m_path;
}

std::filesystem::path ComponentsFile::GetDirectory()
{
return m_directory;
}

const ComponentsFile::ComponentRecord::Vector& ComponentsFile::GetComponentRecords() const
{
return m_componentRecords;
}

const ComponentLayerDirectory::ComponentRecord::StringMap& ComponentLayerDirectory::GetComponentRecordsByName() const
const ComponentsFile::ComponentRecord::StringMap& ComponentsFile::GetComponentRecordsByName() const
{
return m_componentRecordsByName;
}

const std::vector<std::string>& ComponentLayerDirectory::GetAttributeNames() const
const std::vector<std::string>& ComponentsFile::GetAttributeNames() const
{
return m_attributeNames;
}

const std::vector<std::string>& ComponentLayerDirectory::GetAttributeTextValues() const
const std::vector<std::string>& ComponentsFile::GetAttributeTextValues() const
{
return m_attributeTextValues;
}

ComponentLayerDirectory::ComponentRecord::~ComponentRecord()
ComponentsFile::ComponentRecord::~ComponentRecord()
{
m_toeprintRecords.clear();
m_propertyRecords.clear();
}

bool ComponentLayerDirectory::Parse()
bool ComponentsFile::Parse(std::filesystem::path directory)
{
std::ifstream componentsFile;
int lineNumber = 0;
std::string line;

try
{
if (!LayerDirectory::Parse()) return false;
m_directory = directory;

auto layerName = m_directory.filename().string();
if (layerName == TOP_COMPONENTS_LAYER_NAME ||
layerName == BOTTOM_COMPONENTS_LAYER_NAME)
{
m_side = layerName == TOP_COMPONENTS_LAYER_NAME ?
BoardSide::Top :
BoardSide::Bottom;
}

if (m_side == BoardSide::Neither)
{
// not a components layer
return true;
}

loginfo("checking for extraction...");

Expand All @@ -82,28 +107,30 @@ namespace Odb::Lib::FileModel::Design
{
loginfo("trying components file: [" + componentsFilename + "]...");

componentsFilePath = Utils::ArchiveExtractor::getUncompressedFilePath(m_path, componentsFilename);
componentsFilePath = Utils::ArchiveExtractor::getUncompressedFilePath(m_directory, componentsFilename);
if (exists(componentsFilePath) && is_regular_file(componentsFilePath))
{
loginfo("found components file: [" + componentsFilePath.string() + "]");
break;
}
}
}

m_path = componentsFilePath;

loginfo("any extraction complete, parsing data...");

if (!std::filesystem::exists(componentsFilePath))
if (!std::filesystem::exists(m_path))
{
auto message = "components file does not exist: [" + m_path.string() + "]";
throw invalid_odb_error(message.c_str());
}
else if (!std::filesystem::is_regular_file(componentsFilePath))
else if (!std::filesystem::is_regular_file(m_path))
{
auto message = "components is not a file: [" + m_path.string() + "]";
throw invalid_odb_error(message.c_str());
}

componentsFile.open(componentsFilePath.string(), std::ios::in);
componentsFile.open(m_path.string(), std::ios::in);
if (!componentsFile.is_open())
{
auto message = "unable to open components file: [" + m_path.string() + "]";
Expand Down Expand Up @@ -235,7 +262,7 @@ namespace Odb::Lib::FileModel::Design
//pCurrentComponentRecord->id = std::stoul(token);

}
else if (line.find(ComponentRecord::PropertyRecord::RECORD_TOKEN) == 0)
else if (line.find(PropertyRecord::RECORD_TOKEN) == 0)
{
// component property record line
std::string token;
Expand All @@ -244,12 +271,12 @@ namespace Odb::Lib::FileModel::Design
throw_parse_error(m_path, line, token, lineNumber);
}

if (token != ComponentRecord::PropertyRecord::RECORD_TOKEN)
if (token != PropertyRecord::RECORD_TOKEN)
{
throw_parse_error(m_path, line, token, lineNumber);
}

auto pPropertyRecord = std::make_shared<ComponentRecord::PropertyRecord>();
auto pPropertyRecord = std::make_shared<PropertyRecord>();

if (!(lineStream >> pPropertyRecord->name))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#pragma once

#include "LayerDirectory.h"
#include <vector>
#include <string>
#include <map>
#include <memory>
#include <filesystem>
#include <vector>
#include "../../odbdesign_export.h"
#include "../../enums.h"
#include "../../IProtoBuffable.h"
#include "PropertyRecord.h"


namespace Odb::Lib::FileModel::Design
{
class ODBDESIGN_EXPORT ComponentLayerDirectory : public LayerDirectory
class ODBDESIGN_EXPORT ComponentsFile
{
public:
ComponentLayerDirectory(std::filesystem::path path, BoardSide side);
~ComponentLayerDirectory();
ComponentsFile();
~ComponentsFile();

bool Parse() override;
bool Parse(std::filesystem::path directory);

std::string GetUnits() const;
BoardSide GetSide() const;
std::filesystem::path GetPath();
std::filesystem::path GetDirectory();

struct ComponentRecord
{
Expand All @@ -37,26 +44,11 @@ namespace Odb::Lib::FileModel::Design
unsigned int index;

// constants
inline static const std::string RECORD_TOKEN = "CMP";
constexpr inline static const char* RECORD_TOKEN = "CMP";

// typedefs
typedef std::map<std::string, std::shared_ptr<ComponentRecord>> StringMap;
typedef std::vector<std::shared_ptr<ComponentRecord>> Vector;

struct PropertyRecord
{
// data members
std::string name;
std::string value;
std::vector<float> floatValues;

// constants
inline static const std::string RECORD_TOKEN = "PRP";

// typedefs
typedef std::map<std::string, std::shared_ptr<PropertyRecord>> StringMap;
typedef std::vector<std::shared_ptr<PropertyRecord>> Vector;
};
typedef std::vector<std::shared_ptr<ComponentRecord>> Vector;

struct ToeprintRecord
{
Expand All @@ -71,7 +63,7 @@ namespace Odb::Lib::FileModel::Design
std::string name; // pin name

// constants
inline static const std::string RECORD_TOKEN = "TOP";
constexpr inline static const char* RECORD_TOKEN = "TOP";

// typedefs
typedef std::map<std::string, std::shared_ptr<ToeprintRecord>> StringMap;
Expand All @@ -80,17 +72,23 @@ namespace Odb::Lib::FileModel::Design

PropertyRecord::Vector m_propertyRecords;
ToeprintRecord::Vector m_toeprintRecords;
};
}; // ComponentRecord

const ComponentRecord::Vector& GetComponentRecords() const;
const ComponentRecord::StringMap& GetComponentRecordsByName() const;
const std::vector<std::string>& GetAttributeNames() const;
const std::vector<std::string>& GetAttributeTextValues() const;

constexpr inline static const char* TOP_COMPONENTS_LAYER_NAME = "comp_+_top";
constexpr inline static const char* BOTTOM_COMPONENTS_LAYER_NAME = "comp_+_bot";

private:
std::string m_units;
unsigned int m_id;
BoardSide m_side;
std::string m_name;
std::filesystem::path m_path;
std::filesystem::path m_directory;

std::vector<std::string> m_attributeNames;
std::vector<std::string> m_attributeTextValues;
Expand All @@ -108,20 +106,20 @@ namespace Odb::Lib::FileModel::Design
"components3"
};

inline static const char* UNITS_TOKEN = "UNITS";
inline static const char* ID_TOKEN = "ID";
inline static const char* ATTRIBUTE_NAME_TOKEN = "@";
inline static const char* ATTRIBUTE_VALUE_TOKEN = "&";
inline static const char* COMMENT_TOKEN = "#";
constexpr inline static const char* UNITS_TOKEN = "UNITS";
constexpr inline static const char* ID_TOKEN = "ID";
constexpr inline static const char* ATTRIBUTE_NAME_TOKEN = "@";
constexpr inline static const char* ATTRIBUTE_VALUE_TOKEN = "&";
constexpr inline static const char* COMMENT_TOKEN = "#";

// TODO: deal with BOM DATA section lines later
inline static const char* BOM_DESCR_RECORD_TOKEN_CPN = "CPN";
inline static const char* BOM_DESCR_RECORD_TOKEN_PKG = "PKG";
inline static const char* BOM_DESCR_RECORD_TOKEN_IPN = "IPN";
inline static const char* BOM_DESCR_RECORD_TOKEN_DSC = "DSC";
inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_VND = "VPL_VND";
inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_MPN = "VPL_MPN";
inline static const char* BOM_DESCR_RECORD_TOKEN_VND = "VND";
inline static const char* BOM_DESCR_RECORD_TOKEN_MPN = "MPN";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_CPN = "CPN";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_PKG = "PKG";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_IPN = "IPN";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_DSC = "DSC";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_VND = "VPL_VND";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_MPN = "VPL_MPN";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VND = "VND";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_MPN = "MPN";
};
}
Loading

0 comments on commit d723dd2

Please sign in to comment.