Permalink
Browse files

Improve Lua custom entity functionsm, refactor of builders, and preve…

…nt Lua modifying the document during an operation
  • Loading branch information...
feragon committed Jul 17, 2017
1 parent b2ad53c commit 4dafdfe37b18ebde91e6ec24dde7e33612b675bb
@@ -116,38 +116,38 @@ void DXFimpl::endBlock() {
void DXFimpl::addLine(const DRW_Line& data) {
lc::builder::LineBuilder builder;
builder.setMetaInfo(getMetaInfo(data))
->setBlock(_currentBlock)
->setLayer(_document->layerByName(data.layer))
->setStart(coord(data.basePoint))
->setEnd(coord(data.secPoint));
builder.setMetaInfo(getMetaInfo(data));
builder.setBlock(_currentBlock);
builder.setLayer(_document->layerByName(data.layer));
builder.setStart(coord(data.basePoint));
builder.setEnd(coord(data.secPoint));
_entityBuilder->appendEntity(builder.build());
}
void DXFimpl::addCircle(const DRW_Circle& data) {
lc::builder::CircleBuilder builder;
builder.setMetaInfo(getMetaInfo(data))
->setLayer(_document->layerByName(data.layer))
->setCenter(coord(data.basePoint))
->setRadius(data.radious)
->setBlock(_currentBlock);
builder.setMetaInfo(getMetaInfo(data));
builder.setLayer(_document->layerByName(data.layer));
builder.setCenter(coord(data.basePoint));
builder.setRadius(data.radious);
builder.setBlock(_currentBlock);
_entityBuilder->appendEntity(builder.build());
}
void DXFimpl::addArc(const DRW_Arc& data) {
lc::builder::ArcBuilder builder;
builder.setMetaInfo(getMetaInfo(data))
->setLayer(_document->layerByName(data.layer))
->setBlock(_currentBlock)
->setCenter(coord(data.basePoint))
->setRadius(data.radious)
->setStartAngle(data.staangle)
->setEndAngle(data.endangle)
->setIsCCW((bool) data.isccw);
builder.setMetaInfo(getMetaInfo(data));
builder.setLayer(_document->layerByName(data.layer));
builder.setBlock(_currentBlock);
builder.setCenter(coord(data.basePoint));
builder.setRadius(data.radious);
builder.setStartAngle(data.staangle);
builder.setEndAngle(data.endangle);
builder.setIsCCW((bool) data.isccw);
_entityBuilder->appendEntity(builder.build());
}
@@ -556,12 +556,12 @@ void DXFimpl::linkImage(const DRW_ImageDef *data) {
void DXFimpl::addInsert(const DRW_Insert& data) {
lc::builder::InsertBuilder builder;
builder.setMetaInfo(getMetaInfo(data))
->setBlock(_currentBlock)
->setLayer(_document->layerByName(data.layer))
->setCoordinate(coord(data.basePoint))
->setDisplayBlock(_blocks[data.name])
->setDocument(_document);
builder.setMetaInfo(getMetaInfo(data));
builder.setBlock(_currentBlock);
builder.setLayer(_document->layerByName(data.layer));
builder.setCoordinate(coord(data.basePoint));
builder.setDisplayBlock(_blocks[data.name]);
builder.setDocument(_document);
_entityBuilder->appendEntity(builder.build());
}
@@ -56,4 +56,3 @@ void CustomEntityBuilder::setNewDragPointsFunction(const LuaIntf::LuaRef& setDra
_newDragPointsFunction = setDragPointsFunction;
}
@@ -506,19 +506,19 @@ void LCLua::importLCKernel() {
))
.endClass()
//ArcBuilder is used here because it needs a template
//This doesn't cause RTTI problems in Lua
.beginClass<builder::CADEntityBuilder<builder::ArcBuilder>>("CADEntityBuilder")
.addFunction("layer", &builder::CADEntityBuilder<builder::ArcBuilder>::layer)
.addFunction("setLayer", &builder::CADEntityBuilder<builder::ArcBuilder>::setLayer)
.addFunction("metaInfo", &builder::CADEntityBuilder<builder::ArcBuilder>::metaInfo)
.addFunction("setMetaInfo", &builder::CADEntityBuilder<builder::ArcBuilder>::setMetaInfo)
.addFunction("block", &builder::CADEntityBuilder<builder::ArcBuilder>::block)
.addFunction("setBlock", &builder::CADEntityBuilder<builder::ArcBuilder>::setBlock)
.addFunction("checkValues", &builder::CADEntityBuilder<builder::ArcBuilder>::checkValues)
.endClass()
.beginExtendClass<builder::ArcBuilder, builder::CADEntityBuilder<builder::ArcBuilder>>("ArcBuilder")
.beginClass<builder::CADEntityBuilder>("CADEntityBuilder")
.addFunction("layer", &builder::CADEntityBuilder::layer)
.addFunction("setLayer", &builder::CADEntityBuilder::setLayer)
.addFunction("metaInfo", &builder::CADEntityBuilder::metaInfo)
.addFunction("setMetaInfo", &builder::CADEntityBuilder::setMetaInfo)
.addFunction("block", &builder::CADEntityBuilder::block)
.addFunction("setBlock", &builder::CADEntityBuilder::setBlock)
.addFunction("id", &builder::CADEntityBuilder::id)
.addFunction("setID", &builder::CADEntityBuilder::setID)
.addFunction("checkValues", &builder::CADEntityBuilder::checkValues)
.endClass()
.beginExtendClass<builder::ArcBuilder, builder::CADEntityBuilder>("ArcBuilder")
.addConstructor(LUA_ARGS())
.addFunction("center", &builder::ArcBuilder::center)
.addFunction("setCenter", &builder::ArcBuilder::setCenter)
@@ -533,7 +533,7 @@ void LCLua::importLCKernel() {
.addFunction("build", &builder::ArcBuilder::build)
.endClass()
.beginExtendClass<builder::CircleBuilder, builder::CADEntityBuilder<builder::ArcBuilder>>("CircleBuilder")
.beginExtendClass<builder::CircleBuilder, builder::CADEntityBuilder>("CircleBuilder")
.addConstructor(LUA_ARGS())
.addFunction("center", &builder::CircleBuilder::center)
.addFunction("setCenter", &builder::CircleBuilder::setCenter)
@@ -542,14 +542,15 @@ void LCLua::importLCKernel() {
.addFunction("build", &builder::CircleBuilder::build)
.endClass()
.beginExtendClass<builder::InsertBuilder, builder::CADEntityBuilder<builder::ArcBuilder>>("InsertBuilder")
.beginExtendClass<builder::InsertBuilder, builder::CADEntityBuilder>("InsertBuilder")
.addConstructor(LUA_ARGS())
.addFunction("displayBlock", &builder::InsertBuilder::displayBlock)
.addFunction("setDisplayBlock", &builder::InsertBuilder::setDisplayBlock)
.addFunction("coordinate", &builder::InsertBuilder::coordinate)
.addFunction("setCoordinate", &builder::InsertBuilder::setCoordinate)
.addFunction("document", &builder::InsertBuilder::document)
.addFunction("setDocument", &builder::InsertBuilder::setDocument)
.addFunction("copy", &builder::InsertBuilder::copy)
.addFunction("build", &builder::InsertBuilder::build)
.endClass()
@@ -568,7 +569,7 @@ void LCLua::importLCKernel() {
.addFunction("build", &builder::LayerBuilder::build)
.endClass()
.beginExtendClass<builder::LineBuilder, builder::CADEntityBuilder<builder::ArcBuilder>>("LineBuilder")
.beginExtendClass<builder::LineBuilder, builder::CADEntityBuilder>("LineBuilder")
.addConstructor(LUA_ARGS())
.addFunction("start", &builder::LineBuilder::start)
.addFunction("setStart", &builder::LineBuilder::setStart)
@@ -590,7 +591,7 @@ void LCLua::importLCKernel() {
.addFunction("build", &builder::LinePatternBuilder::build)
.endClass()
.beginExtendClass<builder::PointBuilder, builder::CADEntityBuilder<builder::ArcBuilder>>("PointBuilder")
.beginExtendClass<builder::PointBuilder, builder::CADEntityBuilder>("PointBuilder")
.addConstructor(LUA_ARGS())
.addFunction("coordinate", &builder::PointBuilder::coordinate)
.addFunction("setCoordinate", &builder::PointBuilder::setCoordinate)
View
@@ -76,7 +76,7 @@ cad/operations/builder.cpp
cad/primitive/customentity.cpp
cad/interface/snapconstrain.cpp
cad/dochelpers/documentlist.cpp
)
)
# HEADER FILES
set(lckernel_hdrs
@@ -174,7 +174,7 @@ cad/base/visitor.h
cad/primitive/customentity.h
cad/events/newwaitingcustomentityevent.h
cad/dochelpers/documentlist.h
)
)
# LOG4CXX
find_package(Log4CXX 1.10 REQUIRED)
@@ -1,4 +1,5 @@
#include "cadentity.h"
#include <cad/builders/cadentity.h>
using namespace lc;
using namespace entity;
@@ -17,6 +18,13 @@ CADEntity::CADEntity(CADEntity_CSPtr cadEntity, bool sameID)
: ID(sameID ? cadEntity->id() : 0), _layer(cadEntity->_layer), _metaInfo(cadEntity->_metaInfo), _block(cadEntity->_block) {
}
CADEntity::CADEntity(const lc::builder::CADEntityBuilder& builder) :
ID(builder.id()),
_layer(builder.layer()),
_metaInfo(builder.metaInfo()),
_block(builder.block()) {
}
Layer_CSPtr CADEntity::layer() const {
return _layer;
}
@@ -1,7 +1,6 @@
#pragma once
#include <cad/meta/block.h>
#include <cad/builders/cadentity.h>
#include "cad/const.h"
#include "cad/base/id.h"
#include "cad/base/metainfo.h"
@@ -11,13 +10,15 @@
#include "cad/geometry/geoarea.h"
namespace lc {
namespace builder {
class CADEntityBuilder;
}
namespace entity {
/**
*Class that all CAD entities must inherit
*
*/
class CADEntity : public ID, virtual public Visitable {
template <typename T>
friend class lc::builder::CADEntityBuilder;
public:
@@ -141,13 +142,7 @@ namespace lc {
Block_CSPtr block() const;
protected:
template<typename ReturnType>
CADEntity(const lc::builder::CADEntityBuilder<ReturnType>& builder) :
ID(),
_layer(builder.layer()),
_metaInfo(builder.metaInfo()),
_block(builder.block()) {
}
CADEntity(const lc::builder::CADEntityBuilder& builder);
private:
Layer_CSPtr _layer;
@@ -4,7 +4,7 @@
namespace lc {
namespace builder {
class ArcBuilder : public CADEntityBuilder<ArcBuilder> {
class ArcBuilder : public CADEntityBuilder {
public:
ArcBuilder();
@@ -1,13 +1,9 @@
#pragma once
#include <cad/meta/layer.h>
#include <cad/base/metainfo.h>
#include <cad/meta/block.h>
#include <cad/base/visitor.h>
#include <cad/base/cadentity.h>
namespace lc {
namespace builder {
template<typename T>
class CADEntityBuilder {
public:
/**
@@ -19,6 +15,13 @@ namespace lc {
_block(nullptr) {
}
void copy(entity::CADEntity_CSPtr entity) {
_layer = entity->_layer;
_block = entity->_block;
_metaInfo = entity->_metaInfo;
_id.setID(entity->id());
}
/**
* @brief Get layer
* @return Layer
@@ -31,9 +34,8 @@ namespace lc {
* @brief Set the layer
* @param layer New layer
*/
T* setLayer(const Layer_CSPtr& layer) {
void setLayer(const Layer_CSPtr& layer) {
_layer = layer;
return (T*) this;
}
/**
@@ -48,9 +50,8 @@ namespace lc {
* @brief Set MetaInfo
* @param metaInfo new MetaInfo
*/
T* setMetaInfo(const MetaInfo_CSPtr& metaInfo) {
void setMetaInfo(const MetaInfo_CSPtr& metaInfo) {
_metaInfo = metaInfo;
return (T*) this;
}
/**
@@ -65,9 +66,25 @@ namespace lc {
* @brief Set the Block
* @param block Block
*/
T* setBlock(const Block_CSPtr& block) {
void setBlock(const Block_CSPtr& block) {
_block = block;
return (T*) this;
}
/**
* @brief Get entity ID
* @return Entity ID
*/
const ID_DATATYPE id() const {
return _id.id();
}
/**
* @brief Set entity ID
* @param id Entity ID
*/
void setID(ID_DATATYPE id) {
_id.setID(id);
}
virtual bool checkValues() {
@@ -78,6 +95,7 @@ namespace lc {
Layer_CSPtr _layer;
MetaInfo_CSPtr _metaInfo;
Block_CSPtr _block;
ID _id;
};
}
}
@@ -5,7 +5,7 @@
namespace lc {
namespace builder {
class CircleBuilder : public CADEntityBuilder<CircleBuilder> {
class CircleBuilder : public CADEntityBuilder {
public:
CircleBuilder();
@@ -8,6 +8,16 @@ InsertBuilder::InsertBuilder() :
_displayBlock(nullptr) {
}
InsertBuilder* InsertBuilder::copy(entity::Insert_CSPtr insert) {
CADEntityBuilder::copy(insert);
_displayBlock = insert->_displayBlock;
_document = insert->_document;
_coordinate = insert->_position;
return this;
}
bool InsertBuilder::checkValues() {
return CADEntityBuilder::checkValues() &&
_displayBlock != nullptr &&
@@ -5,9 +5,10 @@
namespace lc {
namespace builder {
class InsertBuilder : public CADEntityBuilder<InsertBuilder> {
class InsertBuilder : public CADEntityBuilder {
public:
InsertBuilder();
InsertBuilder* copy(entity::Insert_CSPtr insert);
const Block_CSPtr& displayBlock() const;
InsertBuilder* setDisplayBlock(const Block_CSPtr& displayBlock);
@@ -5,7 +5,7 @@
namespace lc {
namespace builder {
class LineBuilder;
class LineBuilder : public CADEntityBuilder<LineBuilder> {
class LineBuilder : public CADEntityBuilder {
public:
LineBuilder();
@@ -4,7 +4,7 @@
namespace lc {
namespace builder {
class PointBuilder : public CADEntityBuilder<PointBuilder> {
class PointBuilder : public CADEntityBuilder {
public:
const geo::Coordinate& coordinate() const;
PointBuilder* setCoordinate(const geo::Coordinate& coordinate);
Oops, something went wrong.

0 comments on commit 4dafdfe

Please sign in to comment.