Skip to content

Commit

Permalink
merge to main (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 authored Oct 7, 2023
2 parents 452c25d + 17356df commit 792a3c4
Show file tree
Hide file tree
Showing 42 changed files with 967 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ PyOdbDesignServer/PyOdbDesignLib/
/cmake-build-debug
build/
/vcpkg_installed
/OdbDesignServer/designs/
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(MY_CXX_STANDARD 17)
set(CXX_STANDARD ${MY_CXX_STANDARD})
set(CMAKE_CXX_STANDARD ${MY_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED True)
#set(CXX_STANDARD_REQUIRED True)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand All @@ -23,14 +22,6 @@ endif()

project ("OdbDesign")

#if (false AND MSVC)
# # control where the static and shared libraries are built so that on windows
# # we don't need to tinker with the path to run the executable
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
#endif()

# increase warnings in a compiler-specific manner
if (MSVC)
# warning level 4
Expand All @@ -54,7 +45,12 @@ endif()
add_subdirectory("OdbDesignLib")
add_subdirectory("OdbDesignApp")
add_subdirectory("OdbDesignServer")
add_subdirectory("Utils")

# link to OdbDesign library in both executable targets
target_link_libraries(OdbDesignApp PUBLIC OdbDesign)
target_link_libraries(OdbDesignServer PUBLIC OdbDesign)

target_link_libraries(OdbDesignApp PUBLIC Utils)
target_link_libraries(OdbDesignServer PUBLIC Utils)
target_link_libraries(OdbDesign PUBLIC Utils)
2 changes: 1 addition & 1 deletion OdbDesignApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#

# Add source to this project's executable.
add_executable (OdbDesignApp "OdbDesignApp.cpp" "OdbDesignApp.h" "ExitCode.h")
add_executable (OdbDesignApp "OdbDesignApp.cpp" "OdbDesignApp.h" )

# TODO: Add tests and install targets if needed.
7 changes: 0 additions & 7 deletions OdbDesignApp/ExitCode.h

This file was deleted.

6 changes: 3 additions & 3 deletions OdbDesignApp/OdbDesignApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ int main()
auto success = TestRigidFlexDesign();
if (!success)
{
return (int) ExitCode::UnknownError;
return (int) Utils::ExitCode::UnknownError;
}

//std::cout << "success!" << std::endl;

success = TestSampleDesign();
if (!success)
{
return (int) ExitCode::UnknownError;
return (int) Utils::ExitCode::UnknownError;
}

//std::cout << "success!" << std::endl;

return (int) ExitCode::Success;
return (int) Utils::ExitCode::Success;
}

bool TestSampleDesign()
Expand Down
File renamed without changes.
12 changes: 3 additions & 9 deletions OdbDesignLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CMakeList.txt : CMake project for OdbDesignLib
#

add_library(OdbDesign SHARED "export.h" "ComponentLayerDirectory.cpp" "ComponentLayerDirectory.h" "EdaDataFile.cpp" "EdaDataFile.h" "LayerDirectory.cpp" "LayerDirectory.h" "NetlistFile.cpp" "NetlistFile.h" "FileArchive.cpp" "FileArchive.h" "StepDirectory.cpp" "StepDirectory.h" "string_trim.h" "macros.h" "Net.h" "Net.cpp" "Component.h" "Component.cpp" "Pin.h" "Pin.cpp" "PinConnection.h" "PinConnection.cpp" "Package.h" "Package.cpp" "Part.h" "Part.cpp" "Via.h" "Via.cpp" "Design.h" "Design.cpp" "enums.h" "string_trim.cpp" "ArchiveExtractor.h" "ArchiveExtractor.cpp" "libarchive_extract.h" "libarchive_extract.cpp" "OdbDesign.h")
add_library(OdbDesign SHARED "export.h" "ComponentLayerDirectory.cpp" "ComponentLayerDirectory.h" "EdaDataFile.cpp" "EdaDataFile.h" "LayerDirectory.cpp" "LayerDirectory.h" "NetlistFile.cpp" "NetlistFile.h" "FileArchive.cpp" "FileArchive.h" "StepDirectory.cpp" "StepDirectory.h" "string_trim.h" "macros.h" "Net.h" "Net.cpp" "Component.h" "Component.cpp" "Pin.h" "Pin.cpp" "PinConnection.h" "PinConnection.cpp" "Package.h" "Package.cpp" "Part.h" "Part.cpp" "Via.h" "Via.cpp" "Design.h" "Design.cpp" "BoardSide.h" "string_trim.cpp" "ArchiveExtractor.h" "ArchiveExtractor.cpp" "libarchive_extract.h" "libarchive_extract.cpp" "OdbDesign.h" "DesignCache.h" "DesignCache.cpp" "CrowReturnable.h" "CrowReturnable.cpp")

# required for SWIG
set_property(TARGET OdbDesign PROPERTY POSITION_INDEPENDENT_CODE ON)

# state that anybody linking to us needs to include the current source dir,
Expand All @@ -16,14 +18,6 @@ find_package(LibArchive REQUIRED)
target_include_directories(OdbDesign PRIVATE ${LibArchive_INCLUDE_DIRS})
target_link_libraries(OdbDesign PUBLIC ${LibArchive_LIBRARIES})

# link to Crow
#ADD_DEFINITIONS ("-DCROW_ENABLE_SSL")
#set(CROW_FEATURES ssl compression)
#set(CROW_FEATURES "ssl;compression")
find_package(Crow REQUIRED)
#target_include_directories(OdbDesign PRIVATE Crow::Crow)
target_link_libraries(OdbDesign PUBLIC Crow::Crow)

# Python extension module build settings
if (PYTHON_MODULE_BUILD)
# # run swig to generate wrapper file
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignLib/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <memory>
#include "Pin.h"
#include "Package.h"
#include "enums.h"
#include "BoardSide.h"


namespace Odb::Lib::ProductModel
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignLib/ComponentLayerDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "LayerDirectory.h"
#include <vector>
#include <string>
#include "enums.h"
#include "BoardSide.h"


namespace Odb::Lib::FileModel::Design
Expand Down
1 change: 1 addition & 0 deletions OdbDesignLib/CrowReturnable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "CrowReturnable.h"
19 changes: 19 additions & 0 deletions OdbDesignLib/CrowReturnable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "crow.h"


class CrowReturnable : public crow::returnable
{
CrowReturnable()
: returnable("text/plain")
{}

//
virtual std::string as_string() const = 0;

std::string dump() const override
{
return this->as_string();
}
};
14 changes: 5 additions & 9 deletions OdbDesignLib/Design.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Odb::Lib::ProductModel
{
}

bool Design::Build(std::string designDirectory)
bool Design::Build(std::string path)
{
auto pFileModel = std::make_shared<FileModel::Design::FileArchive>(designDirectory);
auto pFileModel = std::make_shared<FileModel::Design::FileArchive>(path);
if (pFileModel->ParseFileModel())
{
return Build(pFileModel);
Expand All @@ -22,14 +22,10 @@ namespace Odb::Lib::ProductModel
}

bool Design::Build(std::shared_ptr<FileModel::Design::FileArchive> pFileModel)
{
m_pFileModel = pFileModel;
return Build();
}
{
if (pFileModel == nullptr) return false;

bool Design::Build()
{
if (m_pFileModel == nullptr) return false;
m_pFileModel = pFileModel;

if (! BuildNets()) return false;
if (! BuildPackages()) return false;
Expand Down
12 changes: 7 additions & 5 deletions OdbDesignLib/Design.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ namespace Odb::Lib::ProductModel
Design();
~Design();

bool Build(std::string designDirectory);
bool Build(std::shared_ptr<FileModel::Design::FileArchive> pFileModel);
bool Build(std::string path);
bool Build(std::shared_ptr<FileModel::Design::FileArchive> pFileModel);

typedef std::vector<std::shared_ptr<Design>> Vector;
typedef std::map<std::string, std::shared_ptr<Design>> StringMap;

private:
std::string m_productModel;
std::string m_name;

std::string m_designDirectory;
std::string m_path;
std::shared_ptr<FileModel::Design::FileArchive> m_pFileModel;

Net::Vector m_nets;
Expand All @@ -39,8 +42,7 @@ namespace Odb::Lib::ProductModel
Component::StringMap m_componentsByName;

Part::StringMap m_partsByName;

bool Build();

bool BuildNets();
bool BuildPackages();
bool BuildParts();
Expand Down
92 changes: 92 additions & 0 deletions OdbDesignLib/DesignCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "DesignCache.h"
#include <filesystem>


namespace Odb::Lib
{
DesignCache::DesignCache()
: DesignCache(".")
{
}

DesignCache::DesignCache(std::string directory) :
m_directory(directory)
{
}

DesignCache::~DesignCache()
{
m_fileArchivesByName.clear();
m_designsByName.clear();
}

std::shared_ptr<ProductModel::Design> DesignCache::GetDesign(std::string designName)
{
auto findIt = m_designsByName.find(designName);
if (findIt == m_designsByName.end())
{
auto pDesign = LoadDesign(designName);
return pDesign;
}

return m_designsByName[designName];
}

std::shared_ptr<FileModel::Design::FileArchive> DesignCache::GetFileArchive(std::string designName)
{
auto findIt = m_fileArchivesByName.find(designName);
if (findIt == m_fileArchivesByName.end())
{
auto pFileArchive = LoadFileArchive(designName);
return pFileArchive;
}

return m_fileArchivesByName[designName];
}

std::shared_ptr<ProductModel::Design> DesignCache::LoadDesign(std::string designName)
{
std::filesystem::path dir(m_directory);

for (const auto& entry : std::filesystem::directory_iterator(dir))
{
if (entry.is_regular_file())
{
if (entry.path().stem() == designName)
{
auto pDesign = std::make_shared<ProductModel::Design>();
if (pDesign->Build(entry.path().string()))
{
m_designsByName.emplace(designName, pDesign);
return pDesign;
}
}
}
}

return nullptr;
}

std::shared_ptr<FileModel::Design::FileArchive> DesignCache::LoadFileArchive(std::string designName)
{
std::filesystem::path dir(m_directory);

for (const auto& entry : std::filesystem::directory_iterator(dir))
{
if (entry.is_regular_file())
{
if (entry.path().stem() == designName)
{
auto pFileArchive = std::make_shared<FileModel::Design::FileArchive>(entry.path().string());
if (pFileArchive->ParseFileModel())
{
m_fileArchivesByName.emplace(designName, pFileArchive);
return pFileArchive;
}
}
}
}

return nullptr;
}
}
30 changes: 30 additions & 0 deletions OdbDesignLib/DesignCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "FileArchive.h"
#include "Design.h"
#include "export.h"


namespace Odb::Lib
{
class DECLSPEC DesignCache
{
public:
DesignCache();
DesignCache(std::string directory);
~DesignCache();

std::shared_ptr<ProductModel::Design> GetDesign(std::string designName);
std::shared_ptr<FileModel::Design::FileArchive> GetFileArchive(std::string designName);

private:
std::string m_directory;

FileModel::Design::FileArchive::StringMap m_fileArchivesByName;
ProductModel::Design::StringMap m_designsByName;

std::shared_ptr<ProductModel::Design> LoadDesign(std::string designName);
std::shared_ptr<FileModel::Design::FileArchive> LoadFileArchive(std::string designName);

};
}
2 changes: 1 addition & 1 deletion OdbDesignLib/EdaDataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <fstream>
#include <sstream>
#include "string_trim.h"
#include "enums.h"
#include "BoardSide.h"


namespace Odb::Lib::FileModel::Design
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignLib/EdaDataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include <map>
#include "export.h"
#include "enums.h"
#include "BoardSide.h"


namespace Odb::Lib::FileModel::Design
Expand Down
Loading

0 comments on commit 792a3c4

Please sign in to comment.