forked from ndeutschmann/qgraf-xml-drawer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathline.py
72 lines (67 loc) · 1.99 KB
/
line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import re
from vertex import *
class Line:
def __init__(self):
self.vertices = []
self.open = False
def __getitem__(self,index):
return self.vertices[index]
def __setitem__(self,index,value):
self.vertices[index]=value
def additem(self,v):
if re.search('[a-zA-Z]',v.fields[0]):
self.vertices.insert(0,v)
self.open = True
elif re.search('[a-zA-Z]',v.fields[1]):
self.vertices.append(v)
self.open = True
else:
(next,prev)=(str(int(v.fields[1])+1),str(int(v.fields[0])-1))
i = 0
found = False
for w in self.vertices:
if next == w.fields[0]:
self.vertices.insert(i,v)
found = True
break
if prev == w.fields[1]:
self.vertices.insert(i+1,v)
found = True
break
i=i+1
if not found:
self.vertices.append(v)
def __iter__(self):
return iter(self.vertices)
def __len__(self):
len(self.vertices)
def __contains__(self,v):
print ""
print "trying to see if"
print v.fields
print "is connected to"
for w in self.vertices:
print w.fields
contained = False
for w in self.vertices:
try:
if int(v.fields[0])-1 == int(w.fields[1]):
contained = True
break
except ValueError:
pass
try:
if int(v.fields[1])+1 == int(w.fields[0]):
contained = True
break
except ValueError:
pass
return contained
#v in self.vertices
def __add__(self,line2):
nline = Line()
for v in self:
nline.additem(v)
for v in line2:
nline.additem(v)
return nline