Permalink
Browse files

Add DimRadial

  • Loading branch information...
feragon committed Jun 21, 2016
1 parent 4ca23e6 commit dd459d662248f25ef583a7115c7f5ac51d8736ea
@@ -0,0 +1,124 @@
DimRadialOperations = {}
DimRadialOperations.__index = DimRadialOperations
setmetatable(DimRadialOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function DimRadialOperations:_init(id)
Operations._init(self, id)
self.definitionPoint = nil
self.definitionPoint2 = nil
self.middleOfText = nil
self.text = nil
self.dimRadial_id = ID():id()
self.dimRadial = self:getDimRadial(Coord(0,0), Coord(0,1), Coord(1,1), "<>")
active_widget():tempEntities():addEntity(self.dimRadial)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Click on first definition point")
end
function DimRadialOperations:getDimRadial(defPoint1, defPoint2, middleOfText, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimRadial(defPoint1, middleOfText, 5, 0, 1, 1, text, defPoint2, 1, layer, MetaInfo())
dim:setId(self.dimRadial_id)
return dim
end
function DimRadialOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimRadial(...)
elseif(eventName == "text") then
self:setText(...)
end
end
function DimRadialOperations:newData(data)
if(self.definitionPoint == nil) then
self.definitionPoint = Operations:getCoordinate(data)
message("Click on second definition point")
elseif(self.definitionPoint2 == nil) then
self.definitionPoint2 = Operations:getCoordinate(data)
message("Click on text emplacement")
elseif(self.middleOfText == nil) then
self.middleOfText = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
end
end
function DimRadialOperations:setText(text)
if(text == "") then
self.text = "<>"
else
self.text = text
end
cli_get_text(false)
self:createDimRadial()
end
function DimRadialOperations:createTempDimRadial(point)
local definitionPoint = self.definitionPoint
local definitionPoint2 = self.definitionPoint2
local middleOfText = self.middleOfText
if(definitionPoint == nil) then
definitionPoint = point
elseif(definitionPoint2 == nil) then
definitionPoint2 = point
if(definitionPoint:x() == definitionPoint2:x() and definitionPoint:y() == definitionPoint2:y()) then
definitionPoint2 = definitionPoint2:add(Coord(0.001,0.001))
end
elseif(middleOfText == nil) then
middleOfText = point
end
definitionPoint2 = definitionPoint2 or definitionPoint:add(Coord(10,0))
middleOfText = middleOfText or definitionPoint:add(Coord(5,10))
active_widget():tempEntities():removeEntity(self.dimRadial)
self.dimRadial = self:getDimRadial(definitionPoint, definitionPoint2, middleOfText, "<>")
active_widget():tempEntities():addEntity(self.dimRadial)
end
function DimRadialOperations:createDimRadial()
active_widget():tempEntities():removeEntity(self.dimRadial)
local b = Builder(active_widget():document())
local c = self:getDimRadial(self.definitionPoint, self.definitionPoint2, self.middleOfText, self.text)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
@@ -7,6 +7,7 @@ require 'actions.dimalignedoperations'
require 'actions.dimangularoperations'
require 'actions.dimdiametricoperations'
require 'actions.dimlinearoperations'
require 'actions.dimradialoperations'
Operations = {}
Operations.__index = Operations
@@ -61,6 +61,7 @@ function add_commandline()
add_command("DIMALIGNED", create_dim_aligned)
add_command("DIMDIAMETRIC", create_dim_diametric)
add_command("DIMLINEAR", create_dim_linear)
add_command("DIMRADIAL", create_dim_radial)
event.register("point", setLastPoint)
end
@@ -31,4 +31,8 @@ function create_dim_diametric()
end
function create_dim_linear()
op[active_widget().id] = DimLinearOperations(active_widget().id)
end
function create_dim_radial()
op[active_widget().id] = DimRadialOperations(active_widget().id)
end
View
@@ -78,4 +78,8 @@ function add_toolbar()
local dimLinear = create_button("", ":/icons/dim_linear.svg")
quickAccess:addButton(dimGroup, dimLinear, 1, 1, 1, 1)
luaInterface:luaConnect(dimLinear, "pressed()", create_dim_linear)
local dimRadial = create_button("", ":/icons/dim_radial.svg")
quickAccess:addButton(dimGroup, dimRadial, 2, 0, 1, 1)
luaInterface:luaConnect(dimRadial, "pressed()", create_dim_radial)
end
@@ -210,7 +210,20 @@ void lua_openlckernel(lua_State* L) {
.endClass()
.beginExtendClass<entity::Text, entity::CADEntity>("Text_")
.endClass()
.beginExtendClass<entity::DimRadial, entity::CADEntity>("DimRadial_")
.beginExtendClass<entity::DimRadial, entity::CADEntity>("DimRadial")
.addConstructor(LUA_SP(entity::DimRadial_SPtr), LUA_ARGS(
const geo::Coordinate&,
const geo::Coordinate&,
const TextConst::AttachmentPoint&,
double,
const double,
const TextConst::LineSpacingStyle&,
const std::string&,
const geo::Coordinate&,
const double,
const Layer_CSPtr,
const MetaInfo_CSPtr
))
.endClass()
.beginExtendClass<entity::DimDiametric, entity::CADEntity>("DimDiametric")
.addConstructor(LUA_SP(entity::DimDiametric_SPtr), LUA_ARGS(

0 comments on commit dd459d6

Please sign in to comment.