g214/graphics/models.py

168 lines
8.2 KiB
Python

# coding=utf-8
from __future__ import unicode_literals
from bokeh.embed import components
from bokeh.models import Label
from bokeh.plotting import figure
class SectionalPlan:
def __init__(self, title=u"", height=4, shoulder=15, foot=20, box=5, nature=15, left_foot_height=20,
left_shoulder_height=20, center_height=20, right_shoulder_height=20, right_foot_height=20,
nature_height=20):
self.x_center = 0
self.x_left_shoulder = - (shoulder / 2)
self.x_left_foot = - (foot / 2)
self.x_left_foot1 = self.x_left_foot - 5
self.x_right_shoulder = (shoulder / 2)
self.x_right_foot = (foot / 2)
self.x_right_foot1 = self.x_right_foot + 5
self.x_box = self.x_right_foot + box
self.x_nature = self.x_right_foot + box + nature
self.height = height
self.left_foot_height = left_foot_height
self.left_shoulder_height = left_shoulder_height
self.center_height = center_height
self.right_shoulder_height = right_shoulder_height
self.right_foot_height = right_foot_height
self.nature_height = nature_height
self.plot = figure(x_range=[self.x_left_foot1 - 1, self.x_nature + 1],
y_range=[-self.center_height - 5, self.height + 5],
width=950,
height=500)
self.plot.title.text = title
self.plot.title.align = "center"
self.plot.title.text_font_size = "25px"
def road_lines(self):
x = [self.x_left_foot1, self.x_left_foot, self.x_left_shoulder, self.x_center, self.x_right_shoulder,
self.x_right_foot, self.x_right_foot1]
y = [0, 0, self.height, self.height, self.height, 0, 0]
x1 = [self.x_left_foot1, self.x_left_foot + 1, self.x_left_shoulder + 1, self.x_center,
self.x_right_shoulder - 1, self.x_right_foot - 1, self.x_right_foot1]
y1 = [-1, -1, self.height - 1, self.height - 1, self.height - 1, -1, -1]
self.plot.line(x, y, line_width=4)
self.plot.line(x1, y1, line_width=4)
def components(self):
return components(self.plot)
def drilling(self):
self.plot.line([self.x_left_foot, self.x_left_foot],
[0, -self.left_foot_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_left_foot, y=-self.left_foot_height, x_offset=-30, y_offset=-20, text=u"左坡脚孔",
render_mode='css')
self.plot.add_layout(label)
self.plot.line([self.x_left_shoulder, self.x_left_shoulder],
[self.height, -self.left_shoulder_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_left_shoulder, y=-self.left_shoulder_height, x_offset=-30, y_offset=-40, text=u"左路肩孔",
render_mode='css')
self.plot.add_layout(label)
self.plot.line([self.x_center, self.x_center],
[self.height, -self.center_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_center, y=-self.center_height, x_offset=-24, y_offset=-20, text=u"中心孔",
render_mode='css')
self.plot.add_layout(label)
self.plot.line([self.x_right_shoulder, self.x_right_shoulder],
[self.height, -self.right_shoulder_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_right_shoulder, y=-self.right_shoulder_height, x_offset=-30, y_offset=-40, text=u"右路肩孔",
render_mode='css')
self.plot.add_layout(label)
self.plot.line([self.x_right_foot, self.x_right_foot],
[0, -self.right_foot_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_right_foot, y=-self.right_foot_height, x_offset=-30, y_offset=-20, text=u"右坡脚孔",
render_mode='css')
self.plot.add_layout(label)
self.plot.line([self.x_nature, self.x_nature],
[0, -self.nature_height],
line_dash='dashed', line_width=4, color="gray")
label = Label(x=self.x_nature, y=-self.nature_height, x_offset=-40, y_offset=-20, text=u"自然孔",
render_mode='css')
self.plot.add_layout(label)
def line_box(self):
self.plot.rect(self.x_box, 1, 1.5, 2, fill_color='white', line_width=4)
label = Label(x=self.x_box, y=1, x_offset=-20, y_offset=18, text=u"集线箱", render_mode='css')
self.plot.add_layout(label)
class FloorPlan:
def __init__(self, title=u"", width=20, shoulder=15, foot=20, box=5, nature=15):
self.x_left = - (width / 2)
self.x_center = 0
self.x_right = width / 2
self.y_center = 0
self.y_shoulder = shoulder / 2
self.y_foot = foot / 2
self.y_box = -(self.y_foot + box)
self.y_nature = self.y_box - nature
self.plot = figure(x_range=[self.x_left - 1, self.x_right + 1],
y_range=[self.y_nature - 5, self.y_foot + 5],
width=950,
height=500)
self.plot.title.text = title
self.plot.title.align = "center"
self.plot.title.text_font_size = "25px"
def road_lines(self):
x = [
[self.x_left, self.x_center, self.x_right],
[self.x_left, self.x_center, self.x_right],
[self.x_left, self.x_center, self.x_right],
[self.x_left, self.x_center, self.x_right]
]
y = [
[self.y_foot, self.y_foot, self.y_foot],
[self.y_shoulder, self.y_shoulder, self.y_shoulder],
[-self.y_shoulder, -self.y_shoulder, -self.y_shoulder],
[-self.y_foot, -self.y_foot, -self.y_foot]
]
self.plot.multi_line(x, y, line_width=10)
def components(self):
return components(self.plot)
def line_box(self):
self.plot.rect(self.x_center, self.y_box, 2, 2, fill_color='white', line_width=4)
label = Label(x=self.x_center, y=self.y_box, x_offset=40, y_offset=-6, text=u"集线箱", render_mode='css')
self.plot.add_layout(label)
def drilling(self):
self.plot.circle_cross(self.x_center, self.y_foot + 1, size=10, color="#FB8072", fill_alpha=0.2, line_width=2)
label = Label(x=self.x_center, y=self.y_foot + 1, x_offset=10, y_offset=10, text=u"左坡角孔", render_mode='css')
self.plot.add_layout(label)
self.plot.circle_cross(self.x_center, self.y_shoulder, size=10, color="#FB8072", fill_alpha=0.2, line_width=2)
label = Label(x=self.x_center, y=self.y_shoulder, x_offset=10, y_offset=-22, text=u"左路肩孔", render_mode='css')
self.plot.add_layout(label)
self.plot.circle_cross(self.x_center, self.y_center, size=10, color="#FB8072", fill_alpha=0.2, line_width=2)
label = Label(x=self.x_center, y=self.y_center, x_offset=10, y_offset=-22, text=u"中心孔", render_mode='css')
self.plot.add_layout(label)
self.plot.circle_cross(self.x_center, -self.y_shoulder, size=10, color="#FB8072", fill_alpha=0.2, line_width=2)
label = Label(x=self.x_center, y=-self.y_shoulder, x_offset=10, y_offset=6, text=u"右路肩孔", render_mode='css')
self.plot.add_layout(label)
self.plot.circle_cross(self.x_center, -(self.y_foot + 1), size=10, color="#FB8072", fill_alpha=0.2,
line_width=2)
label = Label(x=self.x_center, y=-(self.y_foot + 1), x_offset=10, y_offset=-15, text=u"右坡角孔", render_mode='css')
self.plot.add_layout(label)
self.plot.circle_cross(self.x_center, self.y_nature, size=10, color="#FB8072", fill_alpha=0.2, line_width=2)
label = Label(x=self.x_center, y=self.y_nature, x_offset=10, y_offset=3, text=u"天然孔", render_mode='css')
self.plot.add_layout(label)
def link(self):
self.plot.line([self.x_center, self.x_center, self.x_center, self.x_center, self.x_center],
[self.y_foot + 1, self.y_shoulder, -self.y_shoulder, -self.y_foot, self.y_nature],
line_dash='dashed')