Permalink
Browse files

Fractal plugin

  • Loading branch information...
feragon committed Jul 23, 2017
1 parent 4f2706a commit 086b38dcde54ac506bcad4265effa5b27cb82047

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,100 @@
FractalTree = {}
FractalTree.__index = FractalTree
setmetatable(FractalTree, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function FractalTree:_init(id)
Operations._init(self, id)
self.angle = nil
self.depth = nil
luaInterface:registerEvent("point", self)
luaInterface:registerEvent("number", self)
message("Enter tree angle")
end
function FractalTree:onEvent(eventName, data)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "number") then
if(self.angle == nil) then
self.angle = data
message("Enter tree depth")
elseif(self.depth == nil) then
self.depth = data
message("Give origin point")
end
elseif(eventName == "point") then
if(self.angle == nil or self.depth == nil) then
return
end
local b = Builder(active_widget():document(), "Fractal tree")
local block = Block("FractalTree_" .. math.random(9999999999), data) --TODO: get proper ID
b:append(AddBlock(active_widget():document(), block))
local eb = EntityBuilder(active_widget():document())
b:append(eb)
createFractalTree(eb, data:x(), data:y(), self.angle, self.depth, active_layer(), active_metaInfo(), block)
local insertBuilder = InsertBuilder()
insertBuilder:setLayer(active_layer())
insertBuilder:setDisplayBlock(block)
insertBuilder:setCoordinate(data)
insertBuilder:setDocument(active_widget():document())
eb:appendEntity(insertBuilder:build())
b:execute()
self:close()
end
end
function createFractalTree(b, x1, y1, angle, depth, layer, metaInfo, block)
if depth == 0 then return end;
local x2 = x1 + (math.cos(math.rad(angle)) * depth * 10.0);
local y2 = y1 + (math.sin(math.rad(angle)) * depth * 10.0);
b:appendEntity(Line(Coord(x1, y1), Coord(x2, y2), layer, metaInfo, block));
createFractalTree(b, x2, y2, angle - 20, depth - 1, layer, metaInfo, block);
createFractalTree(b, x2, y2, angle + 20, depth - 1, layer, metaInfo, block);
end
function FractalTree:close()
if(not self.finished) then
self.finished = true
luaInterface:deleteEvent('number', self)
luaInterface:deleteEvent('point', self)
luaInterface:triggerEvent("operationFinished", nil)
end
end
if(LC_interface == "gui") then
local tab = toolbar:tabByName("Quick Access")
local group = tab:addGroup("Fractal")
local fractalButton = create_button("Fractal tree")
tab:addWidget(group, fractalButton, 0, 0, 1, 1)
luaInterface:luaConnect(fractalButton, "pressed()", function()
new_operation()
luaInterface:setOperation(active_widget().id, FractalTree(active_widget().id))
end)
end
@@ -208,7 +208,8 @@ void LCLua::importLCKernel() {
const geo::Coordinate & start,
const geo::Coordinate & end,
const Layer_CSPtr,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.addProperty("entityType", [](entity::Line*) {
return "line";
@@ -224,7 +225,8 @@ void LCLua::importLCKernel() {
const geo::Coordinate & center,
double radius,
const Layer_CSPtr,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.addProperty("entityType", [](entity::Circle*) {
return "circle";
@@ -243,7 +245,8 @@ void LCLua::importLCKernel() {
const double endAngle,
bool CCW,
const Layer_CSPtr layer,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.addFunction("nearestPointOnEntity", &geo::Arc::nearestPointOnEntity)
@@ -270,7 +273,8 @@ void LCLua::importLCKernel() {
double endAngle,
bool reversed,
const Layer_CSPtr layer,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.endClass()
@@ -292,7 +296,8 @@ void LCLua::importLCKernel() {
const geo::Coordinate&,
const double,
const Layer_CSPtr,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.endClass()
@@ -306,7 +311,9 @@ void LCLua::importLCKernel() {
const geo::Coordinate&,
const double,
const Layer_CSPtr,
const MetaInfo_CSPtr))
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.endClass()
.beginExtendClass<entity::DimLinear, entity::CADEntity>("DimLinear")
@@ -340,7 +347,8 @@ void LCLua::importLCKernel() {
double,
geo::Spline::splineflag,
const Layer_CSPtr,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.endClass()
@@ -362,7 +370,8 @@ void LCLua::importLCKernel() {
bool,
const geo::Coordinate,
const Layer_CSPtr,
const MetaInfo_CSPtr
LuaIntf::_opt<const MetaInfo_CSPtr>,
LuaIntf::_opt<const Block_CSPtr>
))
.addFunction("width", &lc::entity::LWPolyline::width)
.addFunction("elevation", &lc::entity::LWPolyline::elevation)

0 comments on commit 086b38d

Please sign in to comment.