decorator in a usable state
authorThomas Bläsius <thomas.blaesius@kit.edu>
Tue, 17 Dec 2013 09:41:07 +0000 (10:41 +0100)
committerThomas Bläsius <thomas.blaesius@kit.edu>
Tue, 17 Dec 2013 09:41:07 +0000 (10:41 +0100)
ipelets/decorator/decorator.lua [new file with mode: 0644]
ipelets/decorator/test.ipe [new file with mode: 0644]

diff --git a/ipelets/decorator/decorator.lua b/ipelets/decorator/decorator.lua
new file mode 100644 (file)
index 0000000..8797c8b
--- /dev/null
@@ -0,0 +1,97 @@
+
+-- return a table of names associated with decorator symbols
+function decorator_names(model)
+   local sheets = model.doc:sheets()
+   local symbols = sheets:allNames("symbol")
+   local res = {}
+   for _, name in pairs(symbols) do
+      if name:find("deco/") == 1 then
+        res[#res + 1] = name
+      end
+   end
+   return res
+end
+
+-- Decorate something given by its bounding box with a given deco
+-- object, which needs to be a path.
+function decorate(model, bbox, deco)
+   if (deco:type() ~= "path") then
+      model.ui:explain("The decoration needs to be a path.")
+      return
+   end
+
+   local shape = deco:shape()
+   for _,path in pairs(shape) do
+      for _,subpath in ipairs(path) do  
+        -- move all points
+        for i,point in ipairs(subpath) do
+           subpath[i] = translation(bbox, point) * point
+        end
+
+        -- for acs, the center must be translated separately
+        if (subpath["type"] == "arc") then
+           local arc = subpath["arc"]
+           local arc_pos = arc:matrix():translation()
+           subpath["arc"] = translation(bbox, arc_pos) * arc
+        end
+      end
+   end
+   -- update model
+   deco:setShape(shape)
+   model:creation("create", deco)
+end
+
+-- The translation matrix that should be applied to a given point when
+-- doing the decoration.
+function translation(bbox, point)
+   local dx = 0
+   local dy = 0
+   if (point.x > 0) then
+      dx = dx + bbox:width()
+   end
+   if (point.y > 0) then
+      dy = dy + bbox:height()
+   end
+   dx = dx + bbox:left()
+   dy = dy + bbox:bottom()
+   return ipe.Translation(dx, dy)
+end
+
+function mainWindow(model)
+   if model.ui.win == nil then
+      return model.ui
+   else
+      return model.ui:win()
+   end
+end
+
+function run_decorator(model)
+   -- get bbox of primary selection
+   local p = model:page()
+   local prim = p:primarySelection()
+   if not prim then
+      model.ui:explain("An object must be selected.")
+      return
+   end
+   local bbox = p:bbox(prim)
+
+   -- create decorator object
+   local dialog = ipeui.Dialog(mainWindow(model), "Select a decorator.")
+   local decorators = decorator_names(model)
+   dialog:add("deco", "combo", decorators, 1, 1, 1, 2)
+   dialog:add("ok", "button", { label="&Ok", action="accept" }, 2, 2)
+   dialog:add("cancel", "button", { label="&Cancel", action="reject" }, 2, 1)
+   local r = dialog:execute()
+   if not r then return end
+   local deco_name = decorators[dialog:get("deco")]
+   local symbol = model.doc:sheets():find("symbol", deco_name)
+   local deco = symbol:clone()
+
+   -- run the decoration
+   decorate(model, bbox, deco)
+end
+
+label = "Decorator"
+methods = {
+  { label = "Decorate", run=run_decorator},
+}
diff --git a/ipelets/decorator/test.ipe b/ipelets/decorator/test.ipe
new file mode 100644 (file)
index 0000000..29da8f1
--- /dev/null
@@ -0,0 +1,318 @@
+<?xml version="1.0"?>
+<!DOCTYPE ipe SYSTEM "ipe.dtd">
+<ipe version="70005" creator="Ipe 7.1.4">
+<info created="D:20131216154906" modified="D:20131217104017"/>
+<preamble>\usepackage[english]{babel}
+\usepackage{blindtext}</preamble>
+<ipestyle name="basic">
+<symbol name="arrow/arc(spx)">
+<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-1 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="arrow/farc(spx)">
+<path stroke="sym-stroke" fill="white" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-1 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="mark/circle(sx)" transformations="translations">
+<path fill="sym-stroke">
+0.6 0 0 0.6 0 0 e
+0.4 0 0 0.4 0 0 e
+</path>
+</symbol>
+<symbol name="mark/disk(sx)" transformations="translations">
+<path fill="sym-stroke">
+0.6 0 0 0.6 0 0 e
+</path>
+</symbol>
+<symbol name="mark/fdisk(sfx)" transformations="translations">
+<group>
+<path fill="sym-fill">
+0.5 0 0 0.5 0 0 e
+</path>
+<path fill="sym-stroke" fillrule="eofill">
+0.6 0 0 0.6 0 0 e
+0.4 0 0 0.4 0 0 e
+</path>
+</group>
+</symbol>
+<symbol name="mark/box(sx)" transformations="translations">
+<path fill="sym-stroke" fillrule="eofill">
+-0.6 -0.6 m
+0.6 -0.6 l
+0.6 0.6 l
+-0.6 0.6 l
+h
+-0.4 -0.4 m
+0.4 -0.4 l
+0.4 0.4 l
+-0.4 0.4 l
+h
+</path>
+</symbol>
+<symbol name="mark/square(sx)" transformations="translations">
+<path fill="sym-stroke">
+-0.6 -0.6 m
+0.6 -0.6 l
+0.6 0.6 l
+-0.6 0.6 l
+h
+</path>
+</symbol>
+<symbol name="mark/fsquare(sfx)" transformations="translations">
+<group>
+<path fill="sym-fill">
+-0.5 -0.5 m
+0.5 -0.5 l
+0.5 0.5 l
+-0.5 0.5 l
+h
+</path>
+<path fill="sym-stroke" fillrule="eofill">
+-0.6 -0.6 m
+0.6 -0.6 l
+0.6 0.6 l
+-0.6 0.6 l
+h
+-0.4 -0.4 m
+0.4 -0.4 l
+0.4 0.4 l
+-0.4 0.4 l
+h
+</path>
+</group>
+</symbol>
+<symbol name="mark/cross(sx)" transformations="translations">
+<group>
+<path fill="sym-stroke">
+-0.43 -0.57 m
+0.57 0.43 l
+0.43 0.57 l
+-0.57 -0.43 l
+h
+</path>
+<path fill="sym-stroke">
+-0.43 0.57 m
+0.57 -0.43 l
+0.43 -0.57 l
+-0.57 0.43 l
+h
+</path>
+</group>
+</symbol>
+<symbol name="arrow/fnormal(spx)">
+<path stroke="sym-stroke" fill="white" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-1 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="arrow/pointed(spx)">
+<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-0.8 0 l
+-1 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="arrow/fpointed(spx)">
+<path stroke="sym-stroke" fill="white" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-0.8 0 l
+-1 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="arrow/linear(spx)">
+<path stroke="sym-stroke" pen="sym-pen">
+-1 0.333 m
+0 0 l
+-1 -0.333 l
+</path>
+</symbol>
+<symbol name="arrow/fdouble(spx)">
+<path stroke="sym-stroke" fill="white" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-1 -0.333 l
+h
+-1 0 m
+-2 0.333 l
+-2 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="arrow/double(spx)">
+<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen">
+0 0 m
+-1 0.333 l
+-1 -0.333 l
+h
+-1 0 m
+-2 0.333 l
+-2 -0.333 l
+h
+</path>
+</symbol>
+<symbol name="top-left">
+<group>
+<path fill="gray">
+-4 4 m
+-4 0 l
+0 0 l
+0 4 l
+h
+</path>
+<path stroke="black">
+-4 0 m
+-4 4 l
+0 4 l
+</path>
+</group>
+</symbol>
+<symbol name="deco/KIT-simple">
+<path stroke="black" fill="lightgray">
+5 1 m
+4 0 0 4 1 1 1 5 a
+-5 5 l
+-5 -1 l
+4 0 0 4 -1 -1 -1 -5 a
+5 -5 l
+h
+</path>
+</symbol>
+<symbol name="deco/box">
+<path stroke="black" fill="lightgray">
+-5 5 m
+-5 -5 l
+5 -5 l
+5 5 l
+h
+</path>
+</symbol>
+<symbol name="deco/box-rounded">
+<path stroke="black" fill="lightgray">
+5 1 m
+4 0 0 4 1 1 1 5 a
+-1 5 l
+4 0 0 4 -1 1 -5 1 a
+-5 -1 l
+4 0 0 4 -1 -1 -1 -5 a
+1 -5 l
+4 0 0 4 1 -1 5 -1 a
+h
+</path>
+</symbol>
+<pen name="heavier" value="0.8"/>
+<pen name="fat" value="1.2"/>
+<pen name="ultrafat" value="2"/>
+<symbolsize name="large" value="5"/>
+<symbolsize name="small" value="2"/>
+<symbolsize name="tiny" value="1.1"/>
+<arrowsize name="large" value="10"/>
+<arrowsize name="small" value="5"/>
+<arrowsize name="tiny" value="3"/>
+<color name="gray" value="0.745"/>
+<color name="lightgray" value="0.827"/>
+<color name="red" value="1 0 0"/>
+<color name="green" value="0 1 0"/>
+<color name="blue" value="0 0 1"/>
+<color name="yellow" value="1 1 0"/>
+<color name="orange" value="1 0.647 0"/>
+<color name="gold" value="1 0.843 0"/>
+<color name="purple" value="0.627 0.125 0.941"/>
+<color name="brown" value="0.647 0.165 0.165"/>
+<color name="navy" value="0 0 0.502"/>
+<color name="pink" value="1 0.753 0.796"/>
+<color name="seagreen" value="0.18 0.545 0.341"/>
+<color name="turquoise" value="0.251 0.878 0.816"/>
+<color name="violet" value="0.933 0.51 0.933"/>
+<color name="darkblue" value="0 0 0.545"/>
+<color name="darkcyan" value="0 0.545 0.545"/>
+<color name="darkgray" value="0.663"/>
+<color name="darkgreen" value="0 0.392 0"/>
+<color name="darkmagenta" value="0.545 0 0.545"/>
+<color name="darkorange" value="1 0.549 0"/>
+<color name="darkred" value="0.545 0 0"/>
+<color name="lightblue" value="0.678 0.847 0.902"/>
+<color name="lightcyan" value="0.878 1 1"/>
+<color name="lightgreen" value="0.565 0.933 0.565"/>
+<color name="lightyellow" value="1 1 0.878"/>
+<dashstyle name="dashed" value="[4] 0"/>
+<dashstyle name="dotted" value="[1 3] 0"/>
+<dashstyle name="dash dotted" value="[4 2 1 2] 0"/>
+<dashstyle name="dash dot dotted" value="[4 2 1 2 1 2] 0"/>
+<textsize name="large" value="\large"/>
+<textsize name="small" value="\small"/>
+<textsize name="tiny" value="\tiny"/>
+<textsize name="Large" value="\Large"/>
+<textsize name="LARGE" value="\LARGE"/>
+<textsize name="huge" value="\huge"/>
+<textsize name="Huge" value="\Huge"/>
+<textsize name="footnote" value="\footnotesize"/>
+<textstyle name="center" begin="\begin{center}" end="\end{center}"/>
+<textstyle name="itemize" begin="\begin{itemize}" end="\end{itemize}"/>
+<textstyle name="item" begin="\begin{itemize}\item{}" end="\end{itemize}"/>
+<gridsize name="4 pts" value="4"/>
+<gridsize name="8 pts (~3 mm)" value="8"/>
+<gridsize name="16 pts (~6 mm)" value="16"/>
+<gridsize name="32 pts (~12 mm)" value="32"/>
+<gridsize name="10 pts (~3.5 mm)" value="10"/>
+<gridsize name="20 pts (~7 mm)" value="20"/>
+<gridsize name="14 pts (~5 mm)" value="14"/>
+<gridsize name="28 pts (~10 mm)" value="28"/>
+<gridsize name="56 pts (~20 mm)" value="56"/>
+<gridsize name="1 pts" value="1"/>
+<anglesize name="90 deg" value="90"/>
+<anglesize name="60 deg" value="60"/>
+<anglesize name="45 deg" value="45"/>
+<anglesize name="30 deg" value="30"/>
+<anglesize name="22.5 deg" value="22.5"/>
+<tiling name="falling" angle="-60" step="4" width="1"/>
+<tiling name="rising" angle="30" step="4" width="1"/>
+</ipestyle>
+<page>
+<layer name="alpha"/>
+<view layers="alpha" active="alpha"/>
+<path layer="alpha" stroke="black" fill="lightgray">
+469 369 m
+4 0 0 4 465 369 465 373 a
+159 373 l
+4 0 0 4 159 369 155 369 a
+155 262.503 l
+4 0 0 4 159 262.503 159 258.503 a
+465 258.503 l
+4 0 0 4 465 262.503 469 262.503 a
+h
+</path>
+<path stroke="black" fill="lightgray">
+139 501 m
+139 386.503 l
+453 386.503 l
+453 501 l
+h
+</path>
+<path stroke="black" fill="lightgray">
+469 625 m
+4 0 0 4 465 625 465 629 a
+155 629 l
+155 518.503 l
+4 0 0 4 159 518.503 159 514.503 a
+469 514.503 l
+h
+</path>
+<text matrix="1 0 0 1 32 112" transformations="translations" pos="128 512" stroke="black" type="minipage" width="304" height="54.687" depth="49.81" valign="top">\blindtext</text>
+<text matrix="1 0 0 1 16 -16" transformations="translations" pos="128 512" stroke="black" type="minipage" width="304" height="54.687" depth="49.81" valign="top">\blindtext</text>
+<text matrix="1 0 0 1 32 -144" transformations="translations" pos="128 512" stroke="black" type="minipage" width="304" height="54.687" depth="49.81" valign="top">\blindtext</text>
+</page>
+</ipe>