X-Git-Url: https://i11git.iti.kit.edu/anon-gitweb/?p=Misc%2Fipe.git;a=blobdiff_plain;f=ipelets%2Fgraph%2Fgraph.lua;h=c2cf500491f9c27549530bdbedded39ab78a5f4f;hp=52eb1880c761459c196e03ee405e863d179463c1;hb=0e832d397ff6f7025a0a25d1305ac3d743fb3a88;hpb=b58d153b0959a8ae0ff61c3869bd6e6f83686f9a diff --git a/ipelets/graph/graph.lua b/ipelets/graph/graph.lua index 52eb188..c2cf500 100644 --- a/ipelets/graph/graph.lua +++ b/ipelets/graph/graph.lua @@ -6,6 +6,7 @@ label = "Graph" about = [[ Some features making it easier to work with graphs. ]] local deactivateGraphMode = false +local moveInvisibleObjects = false function toggleGraphMode () if deactivateGraphMode then @@ -15,6 +16,14 @@ function toggleGraphMode () end end +function toggleMoveInvisible () + if moveInvisibleObjects then + moveInvisibleObjects = false + else + moveInvisibleObjects = true + end +end + local editing = false local currMarkId = nil @@ -111,7 +120,7 @@ function _G.EDITTOOL:key(code, modifiers, text) undo = _G.revertOriginal,} t.redo = function (t, doc) p:transform(currMarkId, ipe.Translation(newPos-oldPos)) - moveEndpoints(oldPos, newPos, p) + moveEndpoints(oldPos, newPos, p, self.model) end self.model:register(t) end @@ -119,34 +128,44 @@ end -- function moving all endpoints and intermediate points in polylines -- to newPos, if the squared distance to oldPos is at most sqEps local sqEps = 1 -function moveEndpoints(oldPos, newPos, p) +function moveEndpoints(oldPos, newPos, p, model) + -- print(model.vno) for i, obj, sel, layer in p:objects() do - if obj:type() == "path" then - local shape = obj:shape() - for _, subPath in ipairs(shape) do - if (subPath["type"] == "curve") then - for _,seg in ipairs(subPath) do - if (seg["type"] == "segment") then - for j, point in ipairs(seg) do - -- print(j, point, oldPos) - if (obj:matrix() * point - oldPos):sqLen() < sqEps then - seg[j] = obj:matrix():inverse() * newPos - -- print("test", seg[j]) - end - end - elseif (seg["type"] == "spline") then - if (obj:matrix() * seg[1] - oldPos):sqLen() < sqEps then - seg[1] = obj:matrix():inverse() * newPos - end - if (obj:matrix() * seg[#seg] - oldPos):sqLen() < sqEps then - seg[#seg] = obj:matrix():inverse() * newPos - end + -- do nothing if the object is invisible and invisible objects + -- should not be moved + if not p:visible(model.vno, layer) and + not moveInvisibleObjects then + goto continue + end + -- do nothing if it is not a path + if obj:type() ~= "path" then + goto continue + end + local shape = obj:shape() + for _, subPath in ipairs(shape) do + if (subPath["type"] == "curve") then + for _,seg in ipairs(subPath) do + if (seg["type"] == "segment") then + for j, point in ipairs(seg) do + -- print(j, point, oldPos) + if (obj:matrix() * point - oldPos):sqLen() < sqEps then + seg[j] = obj:matrix():inverse() * newPos + -- print("test", seg[j]) + end + end + elseif (seg["type"] == "spline") then + if (obj:matrix() * seg[1] - oldPos):sqLen() < sqEps then + seg[1] = obj:matrix():inverse() * newPos + end + if (obj:matrix() * seg[#seg] - oldPos):sqLen() < sqEps then + seg[#seg] = obj:matrix():inverse() * newPos end end end - obj:setShape(shape) end + obj:setShape(shape) end + ::continue:: end end @@ -221,7 +240,7 @@ function getString(model, string) end function shorten(model, num) - num = num - 1 + num = num - 2 local lenTarget = 0 local lenSource = 0 -- local str = ipeui.getString(model.ui, "Enter length") @@ -269,6 +288,7 @@ end methods = { { label = "toggle graph mode", run=toggleGraphMode }, + { label = "toggle move invisible", run=toggleMoveInvisible }, { label = "shorten target", run=shorten }, { label = "shorten source", run=shorten }, { label = "shorten both", run=shorten },