-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
dimangularoperations.lua
139 lines (111 loc) · 3.86 KB
/
dimangularoperations.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
DimAngularOperations = {}
DimAngularOperations.__index = DimAngularOperations
setmetatable(DimAngularOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function DimAngularOperations:_init(id)
Operations._init(self, id)
self.centerPoint = nil
self.firstPoint = nil
self.secondPoint = nil
self.text = nil
self.dimAngular_id = ID():id()
self.dimAngular = self:getDimAngular(Coord(0,0), Coord(1,0), Coord(1,1), "<>")
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimAngular)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Click on center point")
end
function DimAngularOperations:getDimAngular(certerPoint, firstPoint, secondPoint, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimAngular.dimAuto(certerPoint, firstPoint, secondPoint, text, layer, MetaInfo())
dim:setId(self.dimAngular_id)
return dim
end
function DimAngularOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimAngular(...)
elseif(eventName == "text") then
self:setText(...)
end
end
function DimAngularOperations:newData(data)
if(self.centerPoint == nil) then
self.centerPoint = Operations:getCoordinate(data)
message("Click on first point")
elseif(self.firstPoint == nil) then
self.firstPoint = Operations:getCoordinate(data)
message("Click on second point")
elseif(self.secondPoint == nil) then
self.secondPoint = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
end
end
function DimAngularOperations:setText(text)
if(text == "") then
self.text = "<>"
else
self.text = text
end
cli_get_text(false)
self:createDimAngular()
end
function DimAngularOperations:createTempDimAngular(point)
local centerPoint = self.centerPoint
local firstPoint = self.firstPoint
local secondPoint = self.secondPoint
if(centerPoint == nil) then
centerPoint = point
elseif(firstPoint == nil) then
firstPoint = point
elseif(secondPoint == nil) then
secondPoint = point
end
firstPoint = firstPoint or centerPoint:add(Coord(-1, 1))
secondPoint = secondPoint or centerPoint:add(Coord(1, 1))
active_widget():tempEntities():removeEntity(self.dimAngular)
self.dimAngular = self:getDimAngular(centerPoint, firstPoint, secondPoint, "<>")
active_widget():tempEntities():addEntity(self.dimAngular)
end
function DimAngularOperations:createDimAngular()
self.finished = true
active_widget():tempEntities():removeEntity(self.dimAngular)
local b = Builder(active_widget():document())
local c = self:getDimAngular(self.centerPoint, self.firstPoint, self.secondPoint, self.text)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
function DimAngularOperations:close()
if(not self.finished) then
if(self.centerPoint ~= nil and self.firstPoint ~= nil and self.secondPoint ~= nil) then
self.text = "<>"
self:createDimAngular()
else
active_widget():tempEntities():removeEntity(self.dimAngular)
self.finished = true
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
end
end