Permalink
Browse files

Add Layer builder

  • Loading branch information...
feragon committed Jun 20, 2017
1 parent ee9fc84 commit 0a88c44a49f89e311589cf55d9b66c70bfb9c5af
View
@@ -69,6 +69,7 @@ cad/builders/arc.cpp
cad/builders/circle.cpp
cad/builders/point.cpp
cad/builders/insert.cpp
cad/builders/layer.cpp
)
# HEADER FILES
@@ -159,6 +160,7 @@ cad/builders/circle.h
cad/builders/point.h
cad/primitive/insert.h
cad/builders/insert.h
cad/builders/layer.h
)
# LOG4CXX
@@ -0,0 +1,76 @@
#include "layer.h"
#include <cad/meta/layer.h>
using namespace lc;
using namespace builder;
LayerBuilder::LayerBuilder() :
_name(),
_lineWidth(1),
_color(),
_linePattern(nullptr),
_isFrozen(false) {
}
const std::string& LayerBuilder::name() const {
return _name;
}
const MetaLineWidthByValue& LayerBuilder::lineWidth() const {
return _lineWidth;
}
const Color& LayerBuilder::color() const {
return _color;
}
DxfLinePattern_CSPtr LayerBuilder::linePattern() const {
return _linePattern;
}
bool LayerBuilder::isFrozen() const {
return _isFrozen;
}
LayerBuilder* LayerBuilder::setName(const std::string& name) {
_name = name;
return this;
}
LayerBuilder* LayerBuilder::setLineWidth(const MetaLineWidthByValue& lineWidth) {
_lineWidth = lineWidth;
return this;
}
LayerBuilder* LayerBuilder::setColor(const Color& color) {
_color = color;
return this;
}
LayerBuilder* LayerBuilder::setLinePattern(const DxfLinePattern_CSPtr& linePattern) {
_linePattern = linePattern;
return this;
}
LayerBuilder* LayerBuilder::setIsFrozen(bool isFrozen) {
_isFrozen = isFrozen;
return this;
}
Layer_CSPtr LayerBuilder::build() {
if(!checkValues()) {
throw "Missing values";
}
return Layer_CSPtr(new Layer(*this));
}
bool LayerBuilder::checkValues() {
return _name != "";
}
@@ -0,0 +1,40 @@
#pragma once
#include <cad/meta/metalinewidth.h>
#include <cad/meta/color.h>
#include <cad/meta/dxflinepattern.h>
namespace lc {
class Layer;
using Layer_CSPtr = std::shared_ptr<const Layer>;
namespace builder {
class LayerBuilder {
public:
LayerBuilder();
const std::string& name() const;
const MetaLineWidthByValue& lineWidth() const;
const Color& color() const;
DxfLinePattern_CSPtr linePattern() const;
bool isFrozen() const;
LayerBuilder* setName(const std::string& name);
LayerBuilder* setLineWidth(const MetaLineWidthByValue& lineWidth);
LayerBuilder* setColor(const Color& color);
LayerBuilder* setLinePattern(const DxfLinePattern_CSPtr& linepattern);
LayerBuilder* setIsFrozen(bool isFrozen);
Layer_CSPtr build();
private:
bool checkValues();
std::string _name;
MetaLineWidthByValue _lineWidth;
Color _color;
lc::DxfLinePattern_CSPtr _linePattern;
bool _isFrozen;
};
}
}
@@ -49,6 +49,16 @@ Layer::Layer(const std::string name, const Color color) :
assert(!StringHelper::isBlank(name) && "Name cannot be blank"); // Name must be set
}
Layer::Layer(const builder::LayerBuilder& builder) :
EntityMetaType(),
DocumentMetaType(),
_name(builder.name()),
_lineWidth(builder.lineWidth()),
_color(builder.color()),
_linepattern(builder.linePattern()),
_isFrozen(builder.isFrozen()) {
}
Color Layer::color() const {
return _color;
}
@@ -7,10 +7,12 @@
#include "metalinewidth.h"
#include "dxflinepattern.h"
#include "cad/meta/color.h"
#include <cad/builders/layer.h>
namespace lc {
class Layer : public EntityMetaType, public DocumentMetaType {
friend class builder::LayerBuilder;
public:
Layer();
Layer(const std::string name, const MetaLineWidthByValue lineWidth, const Color color);
@@ -43,6 +45,8 @@ namespace lc {
}
private:
Layer(const builder::LayerBuilder& builder);
std::string _name;
MetaLineWidthByValue _lineWidth;
Color _color;
@@ -136,4 +136,26 @@ TEST(BuilderTest, Insert) {
EXPECT_EQ(block, insert->block());
EXPECT_EQ(document, insert->document());
EXPECT_EQ(displayBlock, insert->displayBlock());
}
TEST(BuilderTest, Layer) {
auto builder = lc::builder::LayerBuilder();
auto name = "Test Layer";
auto lp = std::make_shared<const lc::DxfLinePattern>();
auto lw = lc::MetaLineWidthByValue(2);
auto color = lc::Color();
auto layer = builder
.setName(name)
->setLinePattern(lp)
->setLineWidth(lw)
->setColor(color)
->setIsFrozen(true)
->build();
EXPECT_EQ(name, layer->name());
EXPECT_EQ(lp, layer->linePattern());
EXPECT_EQ(lw.width(), layer->lineWidth().width());
EXPECT_TRUE(color == layer->color());
EXPECT_TRUE(layer->isFrozen());
}

0 comments on commit 0a88c44

Please sign in to comment.