"""
-----------------------------------------------------------------------------
This source file is part of OSTIS (Open Semantic Technology for Intelligent Systems)
For the latest info, see http://www.ostis.net
Copyright (c) 2010 OSTIS
OSTIS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OSTIS 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with OSTIS. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------
"""
import arc
import type
import point
import cairo
class Pair(arc.Arc):
def __init__(self,ctx,surface,IDmap):
self.ctx=ctx
self.surface = surface
self.element = None
self.IDmap = IDmap
def init(self,reader):
# tp = reader.get_typeElement()
# print tp;
self.type = type.Type(reader.get_typeElement())
self.points = reader.get_points()
self.ptE = point.Point(reader.get_floatattr('e_x'),reader.get_floatattr('e_y'))
self.ptB = point.Point(reader.get_floatattr('b_x'),reader.get_floatattr('b_y'))
self.width = 6.0
def load(self,reader):
self.preload(reader)
cr = self.ctx
cr.save()
if "orient" == self.type.second:
beg = point.Point(0,0)
if len(self.points)>0:
beg.x, beg.y = self.points[len(self.points)-2]
else:
beg.x = self.ptB.x
beg.y = self.ptB.y
self.drawArrow(beg,self.ptE)
cr.stroke()
self.drawPolyLine(self.points)
cr.restore()
def drawConst(self,ptB,ptE):
cr = self.ctx
cr.save()
cr.set_line_width (self.width/2)
cr.set_source_rgb (1,1,1)
l, angle = self.setOrientation(ptB,ptE)
cr.move_to(0,0)
cr.line_to(l,0)
cr.stroke()
def drawRail(self,ptB,ptE):
cr = self.ctx
cr.set_line_width (self.width/2)
dashes = [ 15, # ink
20, # skip
]
cr.set_dash(dashes, 0)
l, angle = self.setOrientation(ptB,ptE)
cr.set_source_rgb (1,1,1)
cr.move_to(0,0)
cr.line_to(l,0)
cr.stroke()
def drawVar(self,ptB,ptE):
cr = self.ctx
cr.set_line_width (7)
dashes = [ 7, # ink
15, # skip
]
cr.set_dash(dashes, 0)
l, angle = self.setOrientation(ptB,ptE)
cr.set_source_rgb (1,1,1)
cr.move_to(0,0)
cr.line_to(l,0)
cr.stroke()
def drawMeta(self,ptB,ptE):
cr = self.ctx
cr.set_line_width (7)
dashes = [ 3, # ink
7, # skip
3,
20,
]
cr.set_dash(dashes, 0)
cr.set_source_rgb (1,1,1)
l, angle = self.setOrientation(ptB,ptE)
cr.move_to(0,0)
cr.line_to(l,0)
cr.stroke()
def drawRail2(self,ptB,ptE):
cr = self.ctx
cr.set_line_width (self.width/2)
dashes = [ 7, # ink
5, # skip
7,
20,
]
cr.set_dash(dashes, 0)
cr.set_source_rgb (1,1,1)
l, angle = self.setOrientation(ptB,ptE)
cr.move_to(0,0)
cr.line_to(l,0)
cr.stroke()
def drawPolyLine(self,points):
cr = self.ctx
inkM = 0
beg = point.Point(0, 0)
cr.set_line_join (cairo.LINE_JOIN_ROUND)
beg.x, beg.y = points[0]
for i in range(1, len(points)):
end = point.Point(0, 0)
end.x, end.y = points[i]
cr.set_line_width (self.width)
if "const" == self.type.first:
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
cr.save()
self.drawConst(beg,end)
cr.restore()
if "var" == self.type.first:
cr.save()
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
cr.set_line_width(3)
cr.set_source_rgb(1,1,1)
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
self.drawVar(beg,end)
cr.restore()
if "rail" == self.type.first:
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
cr.save()
self.drawRail(beg,end)
cr.restore()
if "meta" == self.type.first:
cr.save()
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
cr.set_line_width(3)
cr.set_source_rgb(1,1,1)
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
self.drawMeta(beg,end)
cr.restore()
if "rail2" == self.type.first:
cr.move_to(beg.x,beg.y)
cr.line_to(end.x,end.y)
cr.stroke()
cr.save()
self.drawRail2(beg,end)
cr.restore()
beg = end
def MaxXY(self):
return point.Point(0,0)