From 8bb3c35908e44d65f64fac7d5b27aeeca07f9c96 Mon Sep 17 00:00:00 2001 From: Nathan Miller Date: Sat, 11 May 2024 15:29:32 -0700 Subject: [PATCH] default to not include FileArchive member in Design and add support for 'include_filarchive' query param --- OdbDesignLib/ProductModel/Design.cpp | 20 ++++++++++++-- OdbDesignLib/ProductModel/Design.h | 24 ++++++++++------- .../Controllers/DesignsController.cpp | 27 +++++++++++-------- .../Controllers/DesignsController.h | 2 +- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/OdbDesignLib/ProductModel/Design.cpp b/OdbDesignLib/ProductModel/Design.cpp index 0477f560..bc82e73f 100644 --- a/OdbDesignLib/ProductModel/Design.cpp +++ b/OdbDesignLib/ProductModel/Design.cpp @@ -1,8 +1,11 @@ -#include +#include "Design.h" #include "Design.h" #include "Package.h" #include "Logger.h" #include "../enums.h" +#include "Part.h" +#include +#include "Net.h" namespace Odb::Lib::ProductModel @@ -128,6 +131,11 @@ namespace Odb::Lib::ProductModel //if (! BuildNoneNet()) return false; //if (! BreakSinglePinNets()) return false; + if (CLIP_FILEMODEL_AFTER_BUILD) + { + ClipFileModel(); + } + return true; } @@ -136,13 +144,21 @@ namespace Odb::Lib::ProductModel return m_pFileModel; } + void Design::ClipFileModel() + { + m_pFileModel = nullptr; + } + std::unique_ptr Design::to_protobuf() const { auto pDesignMsg = std::make_unique(); pDesignMsg->set_name(m_name); pDesignMsg->set_productmodel(m_productModel); - pDesignMsg->mutable_filemodel()->CopyFrom(*m_pFileModel->to_protobuf()); + if (m_pFileModel != nullptr) + { + pDesignMsg->mutable_filemodel()->CopyFrom(*m_pFileModel->to_protobuf()); + } for (const auto& pNet : m_nets) { diff --git a/OdbDesignLib/ProductModel/Design.h b/OdbDesignLib/ProductModel/Design.h index ab552113..4fa24277 100644 --- a/OdbDesignLib/ProductModel/Design.h +++ b/OdbDesignLib/ProductModel/Design.h @@ -5,18 +5,21 @@ #include #include "Net.h" #include "Component.h" -#include "../FileModel/Design/FileArchive.h" -#include "Via.h" #include "Package.h" #include "Part.h" -//#include "../FileModel/Design/StepDirectory.h" #include "../ProtoBuf/design.pb.h" #include "../IProtoBuffable.h" +#include +#include +#include "../FileModel/Design/StepDirectory.h" +#include "../FileModel/Design/EdaDataFile.h" +#include "../FileModel/Design/ComponentsFile.h" +#include "../FileModel/Design/FileArchive.h" namespace Odb::Lib::ProductModel { - class ODBDESIGN_EXPORT Design : public IProtoBuffable + class ODBDESIGN_EXPORT Design : public IProtoBuffable { public: Design(); @@ -45,10 +48,11 @@ namespace Odb::Lib::ProductModel bool Build(std::shared_ptr pFileModel); std::shared_ptr GetFileModel() const; + void ClipFileModel(); // Inherited via IProtoBuffable - std::unique_ptr to_protobuf() const override; - void from_protobuf(const Odb::Lib::Protobuf::ProductModel::Design& message) override; + std::unique_ptr to_protobuf() const override; + void from_protobuf(const Protobuf::ProductModel::Design& message) override; typedef std::vector> Vector; typedef std::map> StringMap; @@ -74,13 +78,13 @@ namespace Odb::Lib::ProductModel bool BuildNets(); bool BuildPackages(); bool BuildAllParts(); - bool BuildParts(const Odb::Lib::FileModel::Design::ComponentsFile* pComponentsFile); + bool BuildParts(const FileModel::Design::ComponentsFile* pComponentsFile); bool BuildAllComponents(); - bool BuildComponents(const Odb::Lib::FileModel::Design::ComponentsFile* pComponentsFile); + bool BuildComponents(const FileModel::Design::ComponentsFile* pComponentsFile); bool BuildVias(); bool BuildPlacementsFromComponentsFiles(); - bool BuildPlacementsFromComponentsFile(const Odb::Lib::FileModel::Design::ComponentsFile* pComponentsFile); + bool BuildPlacementsFromComponentsFile(const FileModel::Design::ComponentsFile* pComponentsFile); bool BuildPlacementsFromEdaDataFile(); @@ -93,5 +97,7 @@ namespace Odb::Lib::ProductModel constexpr inline static const char* NONE_NET_NAME = "$NONE$"; + constexpr inline static bool CLIP_FILEMODEL_AFTER_BUILD = false; + }; } diff --git a/OdbDesignServer/Controllers/DesignsController.cpp b/OdbDesignServer/Controllers/DesignsController.cpp index cc9157f0..3f918ff5 100644 --- a/OdbDesignServer/Controllers/DesignsController.cpp +++ b/OdbDesignServer/Controllers/DesignsController.cpp @@ -161,26 +161,31 @@ namespace Odb::App::Server if (designNameDecoded.empty()) { return crow::response(crow::status::BAD_REQUEST, "design name not specified"); + } + + auto pDesign = m_serverApp.designs().GetDesign(designNameDecoded); + if (pDesign == nullptr) + { + std::stringstream ss; + ss << "design: \"" << designNameDecoded << "\" not found"; + return crow::response(crow::status::NOT_FOUND, ss.str()); } // TODO: use excludeFileArchive - bool excludeFileArchive = false; - auto szExcludeFileArchive = req.url_params.get(kszExcludeFileArchiveQueryParamName); - if (szExcludeFileArchive != nullptr) + bool includeFileArchive = false; + auto szIncludeFileArchive = req.url_params.get(kszIncludeFileArchiveQueryParamName); + if (szIncludeFileArchive != nullptr) { - if (std::strcmp(szExcludeFileArchive, "true") == 0 || - std::strcmp(szExcludeFileArchive, "yes") == 0) + if (std::strcmp(szIncludeFileArchive, "true") == 0 || + std::strcmp(szIncludeFileArchive, "yes") == 0) { - excludeFileArchive = true; + includeFileArchive = true; } } - auto pDesign = m_serverApp.designs().GetDesign(designNameDecoded); - if (pDesign == nullptr) + if (!includeFileArchive) { - std::stringstream ss; - ss << "design: \"" << designNameDecoded << "\" not found"; - return crow::response(crow::status::NOT_FOUND, ss.str()); + pDesign->ClipFileModel(); } return crow::response(JsonCrowReturnable(*pDesign)); diff --git a/OdbDesignServer/Controllers/DesignsController.h b/OdbDesignServer/Controllers/DesignsController.h index 42b30262..6561379d 100644 --- a/OdbDesignServer/Controllers/DesignsController.h +++ b/OdbDesignServer/Controllers/DesignsController.h @@ -13,7 +13,7 @@ namespace Odb::App::Server // Inherited via RouteController void register_routes() override; - constexpr inline static const char* kszExcludeFileArchiveQueryParamName = "exclude_filearchive"; + constexpr inline static const char* kszIncludeFileArchiveQueryParamName = "include_filearchive"; private: