Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,87 @@ | |||
CircleOperations = {} | |||
CircleOperations.__index = CircleOperations | |||
|
|||
setmetatable(CircleOperations, { | |||
__index = Operations, | |||
__call = function (o, ...) | |||
local self = setmetatable({}, o) | |||
self:_init(...) | |||
return self | |||
end, | |||
}) | |||
|
|||
function CircleOperations:_init(id) | |||
Operations._init(self, id) | |||
|
|||
self.center = nil | |||
self.circle = nil | |||
self.circle_id = ID():id() | |||
|
|||
event.register('point', self) | |||
|
|||
message("Click on center") | |||
end | |||
|
|||
function CircleOperations:onEvent(eventName, ...) | |||
if(Operations.forMe(self) == false) then | |||
return | |||
end | |||
|
|||
if(eventName == "point") then | |||
self:newPoint(...) | |||
elseif(eventName == "mouseMove") then | |||
self:createTempCircle(...) | |||
elseif(eventName == "number") then | |||
self:createCircle(...) | |||
end | |||
end | |||
|
|||
function CircleOperations:newPoint(point) | |||
if(self.center == nil) then | |||
self.center = point | |||
self.circle = self:getCircle(point, 0) | |||
|
|||
active_widget():tempEntities():addEntity(self.circle) | |||
|
|||
event.register('mouseMove', self) | |||
event.register('number', self) | |||
|
|||
message("Click on second point or enter the radius") | |||
else | |||
self:createCircle(point) | |||
end | |||
end | |||
|
|||
function CircleOperations:getCircle(center, radius) | |||
if(type(radius) == "userdata") then | |||
radius = center:distanceTo(radius) | |||
end | |||
|
|||
local d = active_widget():document() | |||
local layer = d:layerByName("0") | |||
local c = Circle(center, radius, layer) | |||
c:setId(self.circle_id) | |||
|
|||
return c | |||
end | |||
|
|||
function CircleOperations:createTempCircle(point) | |||
active_widget():tempEntities():removeEntity(self.circle) | |||
|
|||
self.circle = self:getCircle(self.center, point) | |||
|
|||
active_widget():tempEntities():addEntity(self.circle) | |||
end | |||
|
|||
function CircleOperations:createCircle(point) | |||
active_widget():tempEntities():removeEntity(self.circle) | |||
|
|||
local b = Builder(active_widget():document()) | |||
local c = self:getCircle(self.center, point) | |||
b:append(c) | |||
b:execute() | |||
|
|||
event.delete('mouseMove', self) | |||
event.delete('number', self) | |||
event.delete('point', self) | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,7 @@ | |||
function create_line() | function create_line() | ||
op[active_widget().id] = LineOperations(active_widget().id) | op[active_widget().id] = LineOperations(active_widget().id) | ||
end | |||
|
|||
function create_circle() | |||
op[active_widget().id] = CircleOperations(active_widget().id) | |||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,20 +1,31 @@ | |||
local iconSize = qt.QSize(24, 24) | local iconSize = qt.QSize(24, 24) | ||
|
|
||
local function create_button(name, icon) | |||
local button = qt.QPushButton(qt.QString(name)) | |||
button:setFlat(true) | |||
|
|||
if(icon ~= nil) then | |||
button:setIcon(qt.QIcon(qt.QString(icon))) | |||
button:setIconSize(iconSize) | |||
end | |||
|
|||
return button | |||
end | |||
|
|||
function add_toolbar() | function add_toolbar() | ||
toolbar = lc.Toolbar(mainWindow) | toolbar = lc.Toolbar(mainWindow) | ||
mainWindow:addDockWidget(4, toolbar) | mainWindow:addDockWidget(4, toolbar) | ||
|
|
||
local quickAccess = lc.ToolbarTab() | local quickAccess = lc.ToolbarTab() | ||
local testGroup = quickAccess:addGroup("Creation") | local creationGroup = quickAccess:addGroup("Creation") | ||
|
|||
local lineButton = qt.QPushButton(qt.QString("")) | |||
lineButton:setFlat(true) | |||
lineButton:setIcon(qt.QIcon(qt.QString(":/icons/linesnormal.png"))) | |||
lineButton:setIconSize(iconSize) | |||
|
|||
quickAccess:addButton(testGroup, lineButton,0,0,1,1) | |||
|
|
||
local lineButton = create_button("", ":/icons/linesnormal.png") | |||
quickAccess:addButton(creationGroup, lineButton, 0, 0, 1, 1) | |||
luaInterface:luaConnect(lineButton, "pressed()", create_line) | luaInterface:luaConnect(lineButton, "pressed()", create_line) | ||
|
|
||
local circleButton = create_button("", ":/icons/circle.svg") | |||
quickAccess:addButton(creationGroup, circleButton, 1, 0, 1, 1) | |||
luaInterface:luaConnect(circleButton, "pressed()", create_circle) | |||
|
|||
toolbar:addTab("Quick Access", quickAccess) | toolbar:addTab("Quick Access", quickAccess) | ||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters