# # Copyright (c) 2003 by Benja Fallenstein # # This file is part of Gzz. # # Gzz is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Gzz is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General # Public License along with Gzz; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # import gzz, java import jarray from test.tools.gfx import getvs from com.hp.hpl.mesa.rdf import jena model = jena.mem.ModelMem() p = model.createProperty("http://fenfire.org/2003/02/test#", "test-property") r = model.createResource() s = model.createResource() t = model.createResource() u = model.createResource() v = model.createResource() w = model.createResource() nodes, dirs = {}, {} class NodeView(gzz.loom.NodeView): def render(self, vs, cs, node, dir): nodes[node] = cs dirs[node] = dir class Cmp(java.util.Comparator): def compare(self, r1, r2): return [t,r,s,v,u,w].index(r1) - [t,r,s,v,u,w].index(r2) view = gzz.loom.SimpleView(NodeView()) def testNullRotation(): r.addProperty(p, s) r.addProperty(p, t) vs = getvs() cursor = gzz.loom.Cursor(Cmp()) cursor.set(r) view.render(vs, 0, cursor) cs_r, cs_s, cs_t, cs_u, cs_v = [vs.matcher.getCS(0, x) for x in (r,s,t,u,v)] assert cs_u == cs_v == -1 pr, ps, pt = [vs.coords.transformPoint(cs, 0, 0, None) for cs in [cs_r, cs_s, cs_t]] assert pr.y == pt.y < ps.y assert ps.x == pt.x > pr.x def testSimple(): r.addProperty(p, s) r.addProperty(p, t) r.addProperty(p, u) r.addProperty(p, v) w.addProperty(p, r) vs = getvs() cursor = gzz.loom.Cursor(Cmp(), r, 1, s) assert cursor.rotation == 0 view.render(vs, 0, cursor) cs_r, cs_s, cs_t, cs_u, cs_v, cs_w = \ [vs.matcher.getCS(0, x) for x in (r,s,t,u,v,w)] pr, ps, pt, pu, pv, pw = \ [vs.coords.transformPoint(cs, 0, 0, None) for cs in [cs_r, cs_s, cs_t, cs_u, cs_v, cs_w]] arr = jarray.zeros(2, 'f') vs.coords.getSqSize(cs_r, arr) w_r, h_r = arr middle_x, middle_y = vs.size.width/2, vs.size.height/2 assert abs(pr.x+w_r/2-middle_x) < 3 assert abs(pr.y+h_r/2-middle_y) < 3 # s,t,u,v should be same size and on a single vertical line assert ps.x == pt.x == pu.x == pv.x > pr.x > pw.x # s and w should be the same height as r, # while t is above and v,u are below assert pt.y < pw.y == pr.y == ps.y < pv.y < pu.y # distances on both sides should be equal # this works only if all nodes are same size... XXX assert (ps.x - pr.x) == (pr.x - pw.x) # Test that SimpleView calls its NodeView # with all the correct parameters. assert nodes[r] == cs_r assert nodes[s] == cs_s assert nodes[t] == cs_t assert nodes[u] == cs_u assert nodes[v] == cs_v assert nodes[w] == cs_w assert dirs[r] == 0 assert dirs[s] == dirs[t] == dirs[u] == dirs[v] == 1 assert dirs[w] == -1