Permalink
Browse files

Keep functions after operations on LuaCustomEntity

  • Loading branch information...
feragon committed Jul 7, 2017
1 parent 9d09b9d commit d9a68be03fee4022a2726a70e79b54d2db297383
@@ -10,6 +10,13 @@ LuaCustomEntity::LuaCustomEntity(const lc::builder::CustomEntityBuilder& builder
_nearestPoint(builder.nearestPointFunction()) {
}
LuaCustomEntity::LuaCustomEntity(Insert_CSPtr insert, LuaCustomEntity_CSPtr customEntity, bool sameID) :
CustomEntity(insert, sameID),
_snapPoints(customEntity->_snapPoints),
_nearestPoint(customEntity->_nearestPoint) {
}
std::vector<EntityCoordinate> LuaCustomEntity::snapPoints(const geo::Coordinate& coord,
const SimpleSnapConstrain& simpleSnapConstrain,
double minDistanceToSnap,
@@ -25,3 +32,37 @@ geo::Coordinate LuaCustomEntity::nearestPointOnPath(const geo::Coordinate& coord
auto nearestPointDupl = _nearestPoint;
return nearestPointDupl.call<geo::Coordinate>(coord);
}
CADEntity_CSPtr LuaCustomEntity::modifyInsert(CADEntity_CSPtr insert) const {
auto i = std::dynamic_pointer_cast<const Insert>(insert);
if(!i) {
return shared_from_this();
}
return std::make_shared<LuaCustomEntity>(i, std::static_pointer_cast<const LuaCustomEntity>(shared_from_this()), true);
}
CADEntity_CSPtr LuaCustomEntity::move(const geo::Coordinate& offset) const {
return modifyInsert(Insert::move(offset));
}
CADEntity_CSPtr LuaCustomEntity::copy(const geo::Coordinate& offset) const {
return modifyInsert(Insert::copy(offset));
}
CADEntity_CSPtr LuaCustomEntity::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
return modifyInsert(Insert::rotate(rotation_center, rotation_angle));
}
CADEntity_CSPtr LuaCustomEntity::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
return modifyInsert(Insert::scale(scale_center, scale_factor));
}
CADEntity_CSPtr LuaCustomEntity::mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const {
return modifyInsert(Insert::mirror(axis1, axis2));
}
CADEntity_CSPtr LuaCustomEntity::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) const {
return modifyInsert(Insert::modify(layer, metaInfo));
}
@@ -10,13 +10,28 @@ namespace lc {
public:
LuaCustomEntity(const builder::CustomEntityBuilder& builder);
/**
* @brief Constructor used in operations which only affect the insert
* @param customEntity Custom entity to copy functions from
* @param insert Insert to copy data from, should be an instance of Insert
*/
LuaCustomEntity(Insert_CSPtr insert, LuaCustomEntity_CSPtr customEntity, bool sameID = false);
virtual std::vector<EntityCoordinate> snapPoints(const geo::Coordinate& coord,
const SimpleSnapConstrain& simpleSnapConstrain,
double minDistanceToSnap,
int maxNumberOfSnapPoints) const override;
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate& coord) 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;
CADEntity_CSPtr rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const override;
CADEntity_CSPtr scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const override;
CADEntity_CSPtr mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const override;
CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) const override;
private:
LuaIntf::LuaRef _snapPoints;
LuaIntf::LuaRef _nearestPoint;
@@ -2,4 +2,8 @@
lc::entity::CustomEntity::CustomEntity(const lc::builder::InsertBuilder& builder) : Insert(builder) {
}
}
lc::entity::CustomEntity::CustomEntity(lc::entity::Insert_CSPtr insert, bool sameID) : Insert(insert, sameID) {
}
@@ -7,13 +7,21 @@ namespace lc {
class CustomEntity : public Insert {
public:
CustomEntity(const builder::InsertBuilder& builder);
CustomEntity(Insert_CSPtr insert, bool sameID = false);
virtual std::vector<EntityCoordinate> snapPoints(const geo::Coordinate& coord,
const SimpleSnapConstrain& simpleSnapConstrain,
double minDistanceToSnap,
int maxNumberOfSnapPoints) const override = 0;
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate& coord) 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;
virtual CADEntity_CSPtr scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const override = 0;
virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const override = 0;
virtual CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) const override = 0;
};
}
}

0 comments on commit d9a68be

Please sign in to comment.