Permalink
Browse files

Add DimAligned creation

  • Loading branch information...
feragon committed Jun 17, 2016
1 parent 7396482 commit a63cbc61fb27b59586953cfd13910ed4f26833a8
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
viewBox="0 0 72.248892 72.248892"
id="svg4295"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="dim_aligned.svg"
inkscape:export-filename="E:\icons\measure.png"
inkscape:export-xdpi="8.4375"
inkscape:export-ydpi="8.4375">
<metadata
id="metadata4325">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4323" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1176"
id="namedview4321"
showgrid="true"
units="px"
inkscape:snap-grids="true"
inkscape:zoom="3.7226562"
inkscape:cx="128"
inkscape:cy="128"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:current-layer="svg4295"
inkscape:object-nodes="true"
inkscape:snap-object-midpoints="false">
<inkscape:grid
type="xygrid"
id="grid4867" />
</sodipodi:namedview>
<g
id="g5916">
<path
inkscape:connector-curvature="0"
id="path4177"
d="M 4.4764637,33.906945 38.343133,67.773615"
style="fill:#00ff7f;fill-rule:evenodd;stroke:#00ff7f;stroke-width:9.03111172;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
id="g5906">
<path
inkscape:connector-curvature="0"
id="path4180"
d="M 62.466533,43.308653 43.308652,62.466534"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:nodetypes="cc" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 29.222463,27.06153 45.187364,43.026431"
id="path4184"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:#00ff7f;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 52.371569,50.210636 -9.978063,-2.793858 7.184206,-7.184205 2.793857,9.978063"
id="path4192"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="path4196"
d="M 22.048176,19.887243 24.842034,29.865306 32.02624,22.6811 22.048176,19.887243"
style="fill:#00ff7f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
sodipodi:nodetypes="cc"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 28.94024,9.7823601 9.7823595,28.940241"
id="path5404"
inkscape:connector-curvature="0" />
<g
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:30.33889008px;line-height:125%;font-family:'Franklin Gothic Medium';-inkscape-font-specification:'Franklin Gothic Medium, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text5984"
transform="translate(13.546668,-6.7733337)">
<path
inkscape:connector-curvature="0"
d="m 45.18112,36.124447 -3.896059,0 -1.614716,-4.814521 -7.777304,0 -1.585088,4.814521 -3.110921,0 6.710701,-20.220989 4.488615,0 6.784772,20.220989 z m -6.488493,-7.732862 -2.947969,-9.021672 -2.947968,9.021672 5.895937,0 z"
id="path4147" />
</g>
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path4776"
d="M 6.7733338,31.608891 40.640003,65.47556"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:4.51555586,4.51555586;stroke-opacity:1;stroke-dashoffset:1.12888896" />
</g>
</g>
</svg>
View
@@ -7,5 +7,6 @@
<file alias="ellipse.svg">icons/ellipse.svg</file>
<file alias="ellipse_axis.svg">icons/ellipse_axis.svg</file>
<file alias="ellipse_arc_axis.svg">icons/ellipse_arc_axis.svg</file>
<file alias="dim_aligned.svg">icons/dim_aligned.svg</file>
</qresource>
</RCC>
@@ -0,0 +1,112 @@
DimAlignedOperations = {}
DimAlignedOperations.__index = DimAlignedOperations
setmetatable(DimAlignedOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function DimAlignedOperations:_init(id, isArc)
Operations._init(self, id)
self.startPoint = nil
self.endPoint = nil
self.textOffset = nil
self.dimAligned_id = ID():id()
self.dimAligned = self:getDimAligned(Coord(0,0), Coord(1,1), 1)
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimAligned)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
message("Click on start point")
end
function DimAlignedOperations:getDimAligned(startPoint, endPoint, textOffset)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimAligned.dimAuto(startPoint, endPoint, textOffset, "<>", layer, MetaInfo())
dim:setId(self.dimAligned_id)
return dim
end
function DimAlignedOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimAligned(...)
end
end
function DimAlignedOperations:newData(data)
if(self.startPoint == nil) then
self.startPoint = Operations:getCoordinate(data)
message("Click on end point")
elseif(self.endPoint == nil) then
self.endPoint = Operations:getCoordinate(data)
self.dimLine = Line(self.startPoint, self.endPoint, Layer("Temp", Color(0,0,0,0)))
message("Give dimension height")
elseif(self.textOffset == nil) then
if(type(data) == "userdata") then
self.textOffset = self.dimLine:nearestPointOnPath(data):distanceTo(data)
else
self.textOffset = data
end
self:createDimAligned()
end
end
function DimAlignedOperations:createTempDimAligned(point)
local startPoint = self.startPoint
local endPoint = self.endPoint
local textOffset = self.textOffset
if(startPoint == nil) then
startPoint = point
elseif(endPoint == nil) then
endPoint = point
if(startPoint:x() == endPoint:x() and startPoint:y() == endPoint:y()) then
endPoint = endPoint:add(Coord(0.001,0.001))
end
elseif(textOffset == nil) then
textOffset = self.dimLine:nearestPointOnPath(point):distanceTo(point)
end
endPoint = endPoint or startPoint:add(Coord(10,0))
textOffset = textOffset or 10
active_widget():tempEntities():removeEntity(self.dimAligned)
self.dimAligned = self:getDimAligned(startPoint, endPoint, textOffset)
active_widget():tempEntities():addEntity(self.dimAligned)
end
function DimAlignedOperations:createDimAligned()
active_widget():tempEntities():removeEntity(self.dimAligned)
local b = Builder(active_widget():document())
local c = self:getDimAligned(self.startPoint, self.endPoint, self.textOffset)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
end
@@ -3,6 +3,7 @@ require 'actions.lineoperations'
require 'actions.circleoperations'
require 'actions.arcoperations'
require 'actions.ellipseoperations'
require 'actions.dimalignedoperations'
Operations = {}
Operations.__index = Operations
@@ -49,6 +49,7 @@ function add_commandline()
add_command("ARC", create_arc)
add_command("ELLIPSE", create_ellipse)
add_command("ARCELLIPSE", create_arc_ellipse)
add_command("DIMALIGNED", create_dim_aligned)
event.register("point", setLastPoint)
end
@@ -16,4 +16,8 @@ end
function create_arc_ellipse()
op[active_widget().id] = EllipseOperations(active_widget().id, true)
end
function create_dim_aligned()
op[active_widget().id] = DimAlignedOperations(active_widget().id)
end
View
@@ -57,4 +57,13 @@ function add_toolbar()
quickAccess:addButton(creationGroup, ellipseButton, 1, 1, 1, 1)
toolbar:addTab("Quick Access", quickAccess)
--
-- Dimensions
--
local dimGroup = quickAccess:addGroup("Dimensions")
local dimAligned = create_button("", ":/icons/dim_aligned.svg")
quickAccess:addButton(dimGroup, dimAligned, 0, 0, 1, 1)
luaInterface:luaConnect(dimAligned, "pressed()", create_dim_aligned)
end
Oops, something went wrong.

0 comments on commit a63cbc6

Please sign in to comment.