Skip to content

Commit

Permalink
Drag points support in Lua entities
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed Jul 7, 2017
1 parent d9a68be commit bf661b3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lcadluascript/builders/customentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const LuaIntf::LuaRef& CustomEntityBuilder::snapFunction() const {
bool CustomEntityBuilder::checkValues() {
return InsertBuilder::checkValues() &&
_snapFunction.isValid() && _snapFunction.isFunction() &&
_nearestPointFunction.isValid() && _nearestPointFunction.isFunction();
_nearestPointFunction.isValid() && _nearestPointFunction.isFunction() &&
_dragPointsFunction.isValid() && _dragPointsFunction.isFunction();
_newDragPointsFunction.isValid() && _newDragPointsFunction.isFunction();
}

const LuaIntf::LuaRef& CustomEntityBuilder::nearestPointFunction() const {
Expand All @@ -38,4 +40,20 @@ void CustomEntityBuilder::setNearestPointFunction(const LuaIntf::LuaRef& nearest
_nearestPointFunction = nearestPointFunction;
}

const LuaIntf::LuaRef& CustomEntityBuilder::dragPointsFunction() const {
return _dragPointsFunction;
}

void CustomEntityBuilder::setDragPointsFunction(const LuaIntf::LuaRef& dragPointsFunction) {
_dragPointsFunction = dragPointsFunction;
}

const LuaIntf::LuaRef& CustomEntityBuilder::newDragPointsFunction() const {
return _newDragPointsFunction;
}

void CustomEntityBuilder::setNewDragPointsFunction(const LuaIntf::LuaRef& setDragPointsFunction) {
_newDragPointsFunction = setDragPointsFunction;
}


8 changes: 8 additions & 0 deletions lcadluascript/builders/customentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ namespace lc {
const LuaIntf::LuaRef& nearestPointFunction() const;
void setNearestPointFunction(const LuaIntf::LuaRef& nearestPointFunction);

const LuaIntf::LuaRef& dragPointsFunction() const;
void setDragPointsFunction(const LuaIntf::LuaRef& dragPointsFunction);

const LuaIntf::LuaRef& newDragPointsFunction() const;
void setNewDragPointsFunction(const LuaIntf::LuaRef& newDragPointsFunction);

bool checkValues() override;

entity::LuaCustomEntity_CSPtr build();

private:
LuaIntf::LuaRef _snapFunction;
LuaIntf::LuaRef _nearestPointFunction;
LuaIntf::LuaRef _dragPointsFunction;
LuaIntf::LuaRef _newDragPointsFunction;
};
}
}
4 changes: 4 additions & 0 deletions lcadluascript/lckernelbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ void LCLua::importLCKernel() {
.addFunction("setSnapFunction", &builder::CustomEntityBuilder::setSnapFunction)
.addFunction("nearestPointFunction", &builder::CustomEntityBuilder::nearestPointFunction)
.addFunction("setNearestPointFunction", &builder::CustomEntityBuilder::setNearestPointFunction)
.addFunction("dragPointsFunction", &builder::CustomEntityBuilder::dragPointsFunction)
.addFunction("setDragPointsFunction", &builder::CustomEntityBuilder::setDragPointsFunction)
.addFunction("newDragPointsFunction", &builder::CustomEntityBuilder::newDragPointsFunction)
.addFunction("setNewDragPointsFunction", &builder::CustomEntityBuilder::setNewDragPointsFunction)
.addFunction("checkValues", &builder::CustomEntityBuilder::checkValues)
.addFunction("build", &builder::CustomEntityBuilder::build)
.endClass()
Expand Down
1 change: 1 addition & 0 deletions lcadluascript/lclua.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {
namespace LuaIntf {
LUA_USING_SHARED_PTR_TYPE(std::shared_ptr)
LUA_USING_LIST_TYPE(std::vector)
LUA_USING_MAP_TYPE(std::map)
}

namespace lc {
Expand Down
18 changes: 16 additions & 2 deletions lcadluascript/primitive/customentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ using namespace entity;
LuaCustomEntity::LuaCustomEntity(const lc::builder::CustomEntityBuilder& builder) :
CustomEntity(builder),
_snapPoints(builder.snapFunction()),
_nearestPoint(builder.nearestPointFunction()) {
_nearestPoint(builder.nearestPointFunction()),
_dragPoints(builder.dragPointsFunction()),
_newDragPoints(builder.newDragPointsFunction()) {
}

LuaCustomEntity::LuaCustomEntity(Insert_CSPtr insert, LuaCustomEntity_CSPtr customEntity, bool sameID) :
CustomEntity(insert, sameID),
_snapPoints(customEntity->_snapPoints),
_nearestPoint(customEntity->_nearestPoint) {
_nearestPoint(customEntity->_nearestPoint),
_dragPoints(customEntity->_dragPoints),
_newDragPoints(customEntity->_newDragPoints) {

}

Expand Down Expand Up @@ -66,3 +70,13 @@ CADEntity_CSPtr LuaCustomEntity::mirror(const geo::Coordinate& axis1, const geo:
CADEntity_CSPtr LuaCustomEntity::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) const {
return modifyInsert(Insert::modify(layer, metaInfo));
}

std::map<unsigned int, geo::Coordinate> LuaCustomEntity::dragPoints() const {
auto dragPointsDupl = _dragPoints;
return dragPointsDupl.call<std::map<unsigned int, geo::Coordinate>>();
}

CADEntity_CSPtr LuaCustomEntity::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
auto newDragPointsDupl = _newDragPoints;
return newDragPointsDupl.call<CADEntity_CSPtr>(dragPoints);
}
5 changes: 5 additions & 0 deletions lcadluascript/primitive/customentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace lc {

virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate& coord) const override;

std::map<unsigned int, geo::Coordinate> dragPoints() const override;
CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;

CADEntity_CSPtr modifyInsert(CADEntity_CSPtr insert) const;
CADEntity_CSPtr move(const geo::Coordinate& offset) const override;
CADEntity_CSPtr copy(const geo::Coordinate& offset) const override;
Expand All @@ -35,6 +38,8 @@ namespace lc {
private:
LuaIntf::LuaRef _snapPoints;
LuaIntf::LuaRef _nearestPoint;
LuaIntf::LuaRef _dragPoints;
LuaIntf::LuaRef _newDragPoints;
};

DECLARE_SHORT_SHARED_PTR(LuaCustomEntity)
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/customentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace lc {

virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate& coord) const override = 0;

virtual std::map<unsigned int, geo::Coordinate> dragPoints() const override = 0;
virtual CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override = 0;

virtual CADEntity_CSPtr move(const geo::Coordinate& offset) const override = 0;
virtual CADEntity_CSPtr copy(const geo::Coordinate& offset) const override = 0;
virtual CADEntity_CSPtr rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const override = 0;
Expand Down

0 comments on commit bf661b3

Please sign in to comment.