Permalink
Browse files

Add DimDiametric creation

  • Loading branch information...
feragon committed Jun 20, 2016
1 parent 3849bf0 commit 72ed3de58862ccb55af63b8d3b82da44c716121e
@@ -0,0 +1,115 @@
DimDiametricOperations = {}
DimDiametricOperations.__index = DimDiametricOperations
setmetatable(DimDiametricOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function DimDiametricOperations:_init(id)
Operations._init(self, id)
self.definitionPoint = nil
self.definitionPoint2 = nil
self.text = nil
self.dimDiametric_id = ID():id()
self.dimDiametric = self:getDimDiametric(Coord(0,0), Coord(1,1), "<>")
active_widget():tempEntities():addEntity(self.dimDiametric)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Click on first point")
end
function DimDiametricOperations:getDimDiametric(defPoint1, defPoint2, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimDiametric(defPoint1, 5, 1, 1, text, defPoint2, 1, layer, MetaInfo())
dim:setId(self.dimDiametric_id)
return dim
end
function DimDiametricOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimDiametric(...)
elseif(eventName == "text") then
self:setText(...)
end
end
function DimDiametricOperations:newData(data)
if(self.definitionPoint == nil) then
self.definitionPoint = Operations:getCoordinate(data)
message("Click on second point")
elseif(self.definitionPoint2 == nil) then
self.definitionPoint2 = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
end
end
function DimDiametricOperations:setText(text)
if(text == "") then
self.text = "<>"
else
self.text = text
end
cli_get_text(false)
self:createDimDiametric()
end
function DimDiametricOperations:createTempDimDiametric(point)
local definitionPoint = self.definitionPoint
local definitionPoint2 = self.definitionPoint2
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
end
definitionPoint2 = definitionPoint2 or definitionPoint:add(Coord(10,0))
active_widget():tempEntities():removeEntity(self.dimDiametric)
self.dimDiametric = self:getDimDiametric(definitionPoint, definitionPoint2, "<>")
active_widget():tempEntities():addEntity(self.dimDiametric)
end
function DimDiametricOperations:createDimDiametric()
active_widget():tempEntities():removeEntity(self.dimDiametric)
local b = Builder(active_widget():document())
local c = self:getDimDiametric(self.definitionPoint, self.definitionPoint2, self.text)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
@@ -5,6 +5,7 @@ require 'actions.arcoperations'
require 'actions.ellipseoperations'
require 'actions.dimalignedoperations'
require 'actions.dimangularoperations'
require 'actions.dimdiametricoperations'
Operations = {}
Operations.__index = Operations
@@ -59,6 +59,7 @@ function add_commandline()
add_command("ELLIPSE", create_ellipse)
add_command("ARCELLIPSE", create_arc_ellipse)
add_command("DIMALIGNED", create_dim_aligned)
add_command("DIMDIAMETRIC", create_dim_diametric)
event.register("point", setLastPoint)
end
@@ -24,4 +24,8 @@ end
function create_dim_angular()
op[active_widget().id] = DimAngularOperations(active_widget().id)
end
function create_dim_diametric()
op[active_widget().id] = DimDiametricOperations(active_widget().id)
end
View
@@ -70,4 +70,8 @@ function add_toolbar()
local dimAngular = create_button("", ":/icons/dim_angular.svg")
quickAccess:addButton(dimGroup, dimAngular, 1, 0, 1, 1)
luaInterface:luaConnect(dimAngular, "pressed()", create_dim_angular)
local dimDiametric = create_button("", ":/icons/dim_diametric.svg")
quickAccess:addButton(dimGroup, dimDiametric, 0, 1, 1, 1)
luaInterface:luaConnect(dimDiametric, "pressed()", create_dim_diametric)
end
@@ -212,7 +212,17 @@ void lua_openlckernel(lua_State* L) {
.endClass()
.beginExtendClass<entity::DimRadial, entity::CADEntity>("DimRadial_")
.endClass()
.beginExtendClass<entity::DimDiametric, entity::CADEntity>("DimDiametric_")
.beginExtendClass<entity::DimDiametric, entity::CADEntity>("DimDiametric")
.addConstructor(LUA_SP(entity::DimDiametric_SPtr), LUA_ARGS(
const geo::Coordinate&,
const TextConst::AttachmentPoint&,
const double,
const TextConst::LineSpacingStyle&,
const std::string&,
const geo::Coordinate&,
const double,
const Layer_CSPtr,
const MetaInfo_CSPtr))
.endClass()
.beginExtendClass<entity::DimLinear, entity::CADEntity>("DimLinear_")
.endClass()

0 comments on commit 72ed3de

Please sign in to comment.