Permalink
Browse files

Add custom entity storage

  • Loading branch information...
feragon committed Jun 26, 2017
1 parent 61b0239 commit 5edfa909581682735cd5d059575406d427cc0eb2
@@ -13,6 +13,7 @@
#include <cad/operations/builderops.h>
#include <cad/operations/builder.h>
#include <cad/operations/layerops.h>
#include <cad/meta/customentitystorage.h>
#include "lclua.h"
using namespace LuaIntf;
@@ -439,5 +440,27 @@ void LCLua::importLCKernel() {
const Layer_CSPtr,
const Layer_CSPtr
))
.endClass();
.endClass()
.beginExtendClass<Block, DocumentMetaType>("Block")
.addConstructor(LUA_SP(Block_SPtr), LUA_ARGS(
std::string,
geo::Coordinate
))
.addFunction("base", &Block::base)
.endClass()
.beginExtendClass<CustomEntityStorage, Block>("CustomEntityStorage")
.addConstructor(LUA_SP(CustomEntityStorage_SPtr), LUA_ARGS(
const std::string&,
const std::string&,
const geo::Coordinate&
))
.addFunction("pluginName", &CustomEntityStorage::pluginName)
.addFunction("entityName", &CustomEntityStorage::entityName)
.addFunction("param", &CustomEntityStorage::param)
.addFunction("setParam", &CustomEntityStorage::setParam)
.endClass()
;
}
View
@@ -71,6 +71,7 @@ cad/builders/point.cpp
cad/builders/insert.cpp
cad/builders/layer.cpp
cad/builders/linepattern.cpp
cad/meta/customentitystorage.cpp
)
# HEADER FILES
@@ -163,6 +164,7 @@ cad/primitive/insert.h
cad/builders/insert.h
cad/builders/layer.h
cad/builders/linepattern.h
cad/meta/customentitystorage.h
)
# LOG4CXX
@@ -0,0 +1,33 @@
#include "customentitystorage.h"
using namespace lc;
//TODO: get a real ID
CustomEntityStorage::CustomEntityStorage(const std::string& pluginName, const std::string& entityName, const geo::Coordinate& base) :
Block("LC_" + std::to_string(rand()), base),
_pluginName(pluginName),
_entityName(entityName) {
}
const std::string& CustomEntityStorage::pluginName() const {
return _pluginName;
}
const std::string& CustomEntityStorage::entityName() const {
return _entityName;
}
void CustomEntityStorage::setParam(const std::string& param, const std::string& value) {
_params[param] = value;
}
std::string CustomEntityStorage::param(const std::string& param) const {
try {
return _params.at(param);
}
catch (std::out_of_range& e) {
return "";
}
}
@@ -0,0 +1,28 @@
#pragma once
#include "block.h"
namespace lc {
/**
* @brief Class for storage of components of custom entities
* Child of Block for compatibility with other CAD software
*/
class CustomEntityStorage : public Block {
public:
CustomEntityStorage(const std::string& pluginName, const std::string& entityName, const geo::Coordinate& base);
const std::string& pluginName() const;
const std::string& entityName() const;
void setParam(const std::string& param, const std::string& value);
std::string param(const std::string& param) const;
private:
std::string _pluginName;
std::string _entityName;
std::map<std::string, std::string> _params;
};
DECLARE_SHORT_SHARED_PTR(CustomEntityStorage);
}
View
@@ -31,7 +31,7 @@ FIND_PACKAGE ( Threads REQUIRED )
set(src
main.cpp
lckernel/primitive/entitytest.cpp
lckernel/builders/buildertest.cpp
lckernel/builders/buildertest.cpp
lckernel/math/code.cpp
lckernel/math/testmath.cpp
lckernel/operations/buildertest.cpp
@@ -41,6 +41,7 @@ lckernel/functions/testintersect.cpp
lckernel/math/testmatrices.cpp
lckernel/geometry/beziertest.cpp
lcviewernoqt/testselection.cpp
lckernel/meta/customentitystorage.cpp
)
set(hdrs
@@ -0,0 +1,28 @@
#include <gtest/gtest.h>
#include <memory>
#include <cad/meta/customentitystorage.h>
using namespace lc;
TEST(CustomEntityStorageTest, Creation) {
auto plugin = "Plugin Name";
auto entity = "Entity Name";
geo::Coordinate base(10, 20, 0);
auto ces = std::make_shared<CustomEntityStorage>(plugin, entity, base);
EXPECT_EQ(plugin, ces->pluginName());
EXPECT_EQ(entity, ces->entityName());
}
TEST(CustomEntityStorageTest, Params) {
auto paramName = "Existing param";
auto paramValue = "Param value";
auto ces = std::make_shared<CustomEntityStorage>("Plugin", "Entity", geo::Coordinate());
EXPECT_EQ("", ces->param(paramName));
ces->setParam(paramName, paramValue);
EXPECT_EQ(paramValue, ces->param(paramName));
}

0 comments on commit 5edfa90

Please sign in to comment.