Skip to content

Commit

Permalink
default to not include FileArchive member in Design and add support f…
Browse files Browse the repository at this point in the history
…or 'include_filarchive' query param
  • Loading branch information
nam20485 committed May 11, 2024
1 parent 38894ff commit 8bb3c35
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
20 changes: 18 additions & 2 deletions OdbDesignLib/ProductModel/Design.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <vector>
#include "Design.h"
#include "Design.h"
#include "Package.h"
#include "Logger.h"
#include "../enums.h"
#include "Part.h"
#include <memory>
#include "Net.h"


namespace Odb::Lib::ProductModel
Expand Down Expand Up @@ -128,6 +131,11 @@ namespace Odb::Lib::ProductModel
//if (! BuildNoneNet()) return false;
//if (! BreakSinglePinNets()) return false;

if (CLIP_FILEMODEL_AFTER_BUILD)
{
ClipFileModel();
}

return true;
}

Expand All @@ -136,13 +144,21 @@ namespace Odb::Lib::ProductModel
return m_pFileModel;
}

void Design::ClipFileModel()
{
m_pFileModel = nullptr;
}

std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Design> Design::to_protobuf() const
{
auto pDesignMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Design>();
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)
{
Expand Down
24 changes: 15 additions & 9 deletions OdbDesignLib/ProductModel/Design.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
#include <memory>
#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 <map>
#include <vector>
#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<Odb::Lib::Protobuf::ProductModel::Design>
class ODBDESIGN_EXPORT Design : public IProtoBuffable<Protobuf::ProductModel::Design>
{
public:
Design();
Expand Down Expand Up @@ -45,10 +48,11 @@ namespace Odb::Lib::ProductModel
bool Build(std::shared_ptr<FileModel::Design::FileArchive> pFileModel);

std::shared_ptr<FileModel::Design::FileArchive> GetFileModel() const;
void ClipFileModel();

// Inherited via IProtoBuffable
std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Design> to_protobuf() const override;
void from_protobuf(const Odb::Lib::Protobuf::ProductModel::Design& message) override;
std::unique_ptr<Protobuf::ProductModel::Design> to_protobuf() const override;
void from_protobuf(const Protobuf::ProductModel::Design& message) override;

typedef std::vector<std::shared_ptr<Design>> Vector;
typedef std::map<std::string, std::shared_ptr<Design>> StringMap;
Expand All @@ -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();

Expand All @@ -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;

};
}
27 changes: 16 additions & 11 deletions OdbDesignServer/Controllers/DesignsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignServer/Controllers/DesignsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 8bb3c35

Please sign in to comment.