Exemple #1
0
 def _get_label_locations(self):
   self.center = Point()
   self.center.x = 0.0
   self.center.y = 0.5 * self.height
   self.bottom = None
   self.top = None
   self.left = Point(self.center.x - (0.5 * self.width), self.center.y)
   self.right = Point(self.center.x + (0.5 * self.width), self.center.y)
 def _rotate(self, old):
   # 'old' coordinates are relative to the center of rotation
   # 'new' coordinates are absolute
   new = Point()
   new.x = self.center_of_rotation.x + (old.x * cos(self._angle_radians)) - (old.y * sin(self._angle_radians))
   new.y = self.center_of_rotation.y + (old.x * sin(self._angle_radians)) + (old.y * cos(self._angle_radians))
   old.x = new.x
   old.y = new.y
Exemple #3
0
    def _get_label_locations(self):
        self.center = Point()
        self.center.x = 0.5 * self.length
        self.center.y = 0.0

        self.bottom = Point(self.center.x, self.center.y - 0.5 * self.width)
        self.top = Point(self.center.x, self.center.y + 0.5 * self.width)
        self.left = None
        self.right = None
 def _rotate(self, old):
     # 'old' coordinates are relative to the center of rotation
     # 'new' coordinates are absolute
     new = Point()
     new.x = self.center_of_rotation.x + (old.x * cos(
         self._angle_radians)) - (old.y * sin(self._angle_radians))
     new.y = self.center_of_rotation.y + (old.x * sin(
         self._angle_radians)) + (old.y * cos(self._angle_radians))
     old.x = new.x
     old.y = new.y
Exemple #5
0
  def __init__(self, width, height, center_of_rotation, flow_channel_percent = 0.75, **kwargs):

    self.height = height
    self.width = width
    self.flow_channel_percent = flow_channel_percent

    super(CoreChannel, self).__init__(center_of_rotation, **kwargs)

    # define list of points outlining the shape of the component
    self._points.append( Point(self.left.x + (flow_channel_percent * self.width), self.graph.nodes['inlet'].y) )
    self._points.append( Point(self.left.x, self._points[-1].y) )
    self._points.append( Point(self._points[-1].x, self.graph.nodes['outlet'].y) )
    self._points.append( Point(self._points[0].x, self._points[-1].y) )
    self._points.append( Point(self._points[0].x, self._points[0].y) )
    # Heat Structure
    self._points.append( Point(self._points[0].x, self._points[-2].y) )
    self._points.append( Point(self.right.x, self._points[-1].y) )
    self._points.append( Point(self.right.x, self._points[0].y) )

    # define connections between points
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
    # Heat Structure
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
    self._connections.append( 'lineto' )
Exemple #6
0
    def rotate(self, angle):
        '''
    positional argument:
      angle (number in degrees)
    '''
        self.center_of_rotation = Point(self.nodes[self.anchor].x,
                                        self.nodes[self.anchor].y)
        self.angle = angle
        self._get_angle_in_radians()

        for edge in self.edges.values():
            if edge.angle == None:
                edge.get_angle(self.nodes[edge.tail], self.nodes[edge.head])
            edge.angle += self.angle
            edge.label_angle += self.angle
            edge._get_angle_in_radians()

        for node in self.nodes.values():
            # move node and its center of rotation
            old_rel_location = node - self.center_of_rotation
            new_rel_location = node - self.center_of_rotation
            self._rotate(new_rel_location)
            new_rel_location -= self.center_of_rotation
            displacement = new_rel_location - old_rel_location
            node.move(displacement)

            # determine new node angle
            node.angle += self.angle
            node._get_angle_in_radians()
Exemple #7
0
  def _guess_label_coordinates(self):
    self._reflect_label_location()
    self._label_coordinates = Point(self.center.x, self.center.y)

    if self.label_location == 'top':
      if self.top is None:
        self._invalid_label_location_error('top')
      else:
        self._label_coordinates.y = self.top.y

    elif self.label_location == 'bottom':
      if self.bottom is None:
        self._invalid_label_location_error('bottom')
      else:
        self._label_coordinates.y = self.bottom.y

    elif self.label_location == 'left':
      if self.left is None:
        self._invalid_label_location_error('left')
      else:
        self._label_coordinates.x = self.left.x

    elif self.label_location == 'right':
      if self.right is None:
        self._invalid_label_location_error('right')
      else:
        self._label_coordinates.x = self.right.x

    self._rotate(self._label_coordinates)
Exemple #8
0
    def __init__(self, length, width, center_of_rotation, **kwargs):
        self.length = length
        self.width = width

        super(Pipe, self).__init__(center_of_rotation, **kwargs)

        # define list of points outlining the custom shape
        self._points.append(Point())
        self._points.append(Point(self.graph.nodes['inlet'].x, self.top.y))
        self._points.append(
            Point(self.graph.nodes['outlet'].x, self._points[1].y))
        self._points.append(Point(self.graph.nodes['outlet'].x, self.bottom.y))
        self._points.append(Point(self.graph.nodes['inlet'].x, self.bottom.y))

        # define connections between points
        self._connections.append('lineto')
        self._connections.append('lineto')
        self._connections.append('lineto')
        self._connections.append('lineto')
        self._connections.append('lineto')
Exemple #9
0
 def test_instantiation(self):
   label = BasicLabel(Point(), angle = 0.0, ll = 'center', ls = 'test', fs = 14)
   self.assertEqual(label.center_of_rotation.x, 0.0)
   self.assertEqual(label.center_of_rotation.y, 0.0)
   self.assertEqual(label.angle, 0.0)
   self.assertEqual(label.label_location, 'center')
   self.assertEqual(label.label_string, 'test')
   self.assertEqual(label.label_angle, 0.0)
   self.assertEqual(label.label_pad, 1.0)
   self.assertEqual(label.font_size, 14)
   self.assertEqual(label.reflect, None)
Exemple #10
0
 def __init__(self, junction_edges, **kwargs):
     self.junction_edges = junction_edges
     self.label_edge_number = process_label_edge_number(0, kwargs)
     self.labeled_edge = self.junction_edges[self.label_edge_number]
     self.label_location = process_label_location('top', kwargs)
     self.label_shift = process_label_shift(0.0, kwargs)
     self.name = process_name(None, kwargs)
     super(Junction, self).__init__(Point(0.0, 0.0),
                                    ll=self.label_location,
                                    **kwargs)
     self.label_string = self.name
     self.reflect = process_reflect(None, kwargs)
     self.angle = None
Exemple #11
0
    def draw(self, tail_coords, head_coords, node_radius, **kwargs):
        self.edge_width = process_width(self.edge_width, kwargs)
        self.head_width_to_edge_width = process_head_width_to_width(
            self.head_width_to_edge_width, kwargs)
        self.head_length_to_head_width = process_head_length_to_head_width(
            self.head_length_to_head_width, kwargs)
        self.overhang = process_overhang(self.overhang, kwargs)
        self.alpha = process_alpha(self.alpha, kwargs)
        self.face_color = process_face_color(self.face_color, kwargs)

        if self.angle == None:
            self.get_angle(tail_coords, head_coords)

        node_delta = Point(node_radius * cos(self._angle_radians),
                           node_radius * sin(self._angle_radians))

        if tail_coords.draw_bool:
            tail_delta = Point(node_delta.x, node_delta.y)
        else:
            tail_delta = Point()

        head_delta = Point(-1.0 * node_delta.x, -1.0 * node_delta.y)

        if self.directional:
            head_width = self.head_width_to_edge_width * self.edge_width
            head_length = self.head_length_to_head_width * head_width
            if not head_coords.draw_bool:
                head_delta = Point()

        else:
            head_width = 0.0
            head_length = 0.0
            if not head_coords.draw_bool:
                head_delta = Point(
                    0.5 * self.edge_width * cos(self._angle_radians),
                    0.5 * self.edge_width * sin(self._angle_radians))

        tail_coords = tail_coords + tail_delta
        head_coords = head_coords + head_delta

        delta = head_coords - tail_coords

        if self.draw_bool:
            patch = FancyArrow(tail_coords.x,
                               tail_coords.y,
                               delta.x,
                               delta.y,
                               width=self.edge_width,
                               length_includes_head=True,
                               head_width=head_width,
                               head_length=head_length,
                               shape='full',
                               overhang=self.overhang,
                               head_starts_at_zero=False,
                               fc=self.face_color,
                               alpha=self.alpha)
            return patch
        else:
            return None
Exemple #12
0
    def __init__(self, x=0.0, y=0.0, **kwargs):
        self.radius = process_radius(0.05, kwargs)
        self.line_width = process_line_width(1.5, kwargs)
        self.face_color = process_face_color((1.0, 1.0, 1.0), kwargs)
        self.alpha = process_alpha(1.0, kwargs)
        self.edge_color = process_edge_color((0.0, 0.0, 0.0), kwargs)

        Label.__init__(self, Point(x, y), **kwargs)
        super(Node, self).__init__(x, y)

        self.draw_bool = process_draw(True, kwargs)
        self.draw_label_bool = process_draw_label(True, kwargs)

        self._instances[id(self)] = self
Exemple #13
0
  def __init__(self, width, center_of_rotation, **kwargs):
    aspect_ratio = 1.0 / 3.0
    self.width = width
    self.height = aspect_ratio * self.width

    super(SteamDome, self).__init__(center_of_rotation, **kwargs)

    displacement = self.height * 4.0 * (math.sqrt(2.0) - 1.0) / 3.0
    # define list of points outlining the custom shape
    self._points.append( Point(self.graph.nodes['inlet'].x, self.graph.nodes['inlet'].y) )
    self._points.append( Point(self.left.x, self._points[-1].y) )
    self._points.append( Point(self.left.x, self._points[-1].y + displacement) )
    self._points.append( Point(self.top.x - displacement, self.top.y) )
    self._points.append( Point(self.top.x, self.top.y) )
    self._points.append( Point(self.top.x + displacement, self.top.y) )
    self._points.append( Point(self.right.x, self._points[2].y) )
    self._points.append( Point(self.right.x, self.graph.nodes['inlet'].y) )

    self._connections.append( 'lineto' )
    self._connections.append( 'CURVE4' )
    self._connections.append( 'CuRvE4' )
    self._connections.append( 'lineto' )
Exemple #14
0
  def _get_actual_label_position(self, label_dimensions):
    self._label_coordinates = Point(self.center.x, self.center.y)

    if self.label_location == 'bottom' or self.label_location == 'top':
      # calculate padding
      padding = abs( 0.5 * cos((pi * self.label_angle) / 180.0) )
      padding = (self.label_pad + padding) * label_dimensions.height
      padding += abs( 0.5 * label_dimensions.width * sin((pi * self.label_angle) / 180.0) )
      if self.reflect == 'x':
        padding *= -1.0
        self.label_angle *= -1.0
      elif self.reflect == 'y':
        self.label_angle *= -1.0

      # determine label coordinates
      if self.label_location == 'bottom':
        self._label_coordinates.y = self.bottom.y - padding
      else:
        self._label_coordinates.y = self.top.y + padding

    elif self.label_location == 'left' or self.label_location == 'right':
      # claculate padding
      padding = abs( 0.5 * sin((pi * self.label_angle) / 180.0) )
      padding = (self.label_pad + padding) * label_dimensions.height
      padding += abs( 0.5 * label_dimensions.width * cos((pi * self.label_angle) / 180.0) )
      if self.reflect == 'y':
        padding *= -1.0
        self.label_angle *= -1.0
      elif self.reflect == 'x':
        self.label_angle *= -1.0

      # determine label coordinates
      if self.label_location == 'left':
        self._label_coordinates.x = self.left.x - padding
      else:
        self._label_coordinates.x = self.right.x + padding

    self._rotate(self._label_coordinates)
Exemple #15
0
    def _get_actual_label_position(self, label_dimensions):
        self._label_coordinates = Point(self.center.x, self.center.y)

        if self.label_location == 'bottom' or self.label_location == 'top':

            if self.reflect == 'x':
                self.label_angle *= -1.0
            elif self.reflect == 'y':
                self.label_angle *= -1.0

            # calculate padding
            padding_angle = (pi * (self.angle - self.label_angle)) / 180.0
            padding = abs(0.5 * cos(padding_angle))
            padding = (self.label_pad + padding) * label_dimensions.height
            padding += abs(0.5 * label_dimensions.width * sin(padding_angle))

            # determine label coordinates
            if self.label_location == 'top':
                self._label_coordinates.y = self.bottom.y - padding
            else:
                self._label_coordinates.y = self.top.y + padding

        self._rotate(self._label_coordinates)
Exemple #16
0
    def __init__(self, tail, head, **kwargs):
        self.tail = tail
        self.head = head
        self.directional = process_directional(True, kwargs)

        if self.tail == self.head:
            sys.exit('Error: Cannot connect a node to itself. (' +
                     str(self.tail) + ' -/-> ' + str(self.head) + ')')

        if self.directional:
            self.string_connector = " --> "
        else:
            self.string_connector = " --- "

        self.label_location = process_label_location('top', kwargs)
        self.label_shift = process_label_shift(0.0, kwargs)
        super(Edge, self).__init__(Point(0.0, 0.0),
                                   ll=self.label_location,
                                   **kwargs)

        self.reflect = process_reflect(None, kwargs)
        self.angle = None

        # Arrow property processing option
        self.edge_width = process_width(0.025, kwargs)
        self.head_width_to_edge_width = process_head_width_to_width(
            3.0, kwargs)
        self.head_length_to_head_width = process_head_length_to_head_width(
            2.0, kwargs)
        self.overhang = process_overhang(0.0, kwargs)
        self.alpha = process_alpha(1.0, kwargs)
        self.face_color = process_face_color((0.0, 0.0, 0.0), kwargs)

        self.draw_bool = process_draw(True, kwargs)
        self.draw_label_bool = process_draw_label(True, kwargs)

        self._instances[id(self)] = self
Exemple #17
0
 def test_tuple(self):
     point = Point(3, 5)
     tmp_tuple = point.to_tuple()
     self.assertTrue(isinstance(tmp_tuple, tuple))
     self.assertEqual(tmp_tuple[0], 3)
     self.assertEqual(tmp_tuple[1], 5)
Exemple #18
0
 def _get_label_locations(self):
     self.center = Point()
     self.left = Point(self.center.x - self.radius, self.center.y)
     self.right = Point(self.center.x + self.radius, self.center.y)
     self.top = Point(self.center.x, self.center.y + self.radius)
     self.bottom = Point(self.center.x, self.center.y - self.radius)
Exemple #19
0
from schematics import ExampleDebugger
command_line_parser = ExampleDebugger('Simple pipe reflected.')
command_line_parser.parse()

from schematics import Point
from schematics import Canvas
from schematics import Pipe
from schematics import Component

CAN = Canvas(border_thickness = 0.05, grid = True)

print(Component.stats)

CAN.add_component( Pipe(5, 1.0, Point(0.0, 0.0) , label_location = 'center', label_pad = 1.0, name = 'Not reflected', angle = 0.0, label_angle = 0.0) )

CAN.add_component( Pipe(5, 1.0, Point(0.0, 0.0) , label_location = 'bottom', label_pad = 1.0, name = 'Bottom label \n relfect_x', angle = 0.0, label_angle = 0.0, reflect = 'x') )

CAN.add_component( Pipe(5, 1.0, Point(0.0, -2.0) , label_location = 'center', label_pad = 1.0, name = 'Not reflected', angle = 0.0, label_angle = 0.0) )

CAN.add_component( Pipe(5, 1.0, Point(0.0, -2.0) , label_location = 'top', label_pad = 1.0, name = 'Top label \n relfect_x', angle = 0.0, label_angle = 0.0, reflect = 'x') )

print(Component.stats)

CAN.draw(save_file = 'test.pdf', display = True, print_information = False)
Exemple #20
0
command_line_parser = ExampleDebugger('Simple core channel.')
command_line_parser.parse()

from schematics import Point
from schematics import Canvas
from schematics import CoreChannel
from schematics import Component

CAN = Canvas(border_thickness=0.05, grid=False)

print(Component.stats)

CAN.add_component(
    CoreChannel(1.0,
                3.0,
                Point(-3.0, 0.0),
                label_location='left',
                name='left \nreflect_y',
                label_pad=0.25,
                angle=0.0,
                reflect='y',
                face_color=(0.6875, .1953, 0.1875, 1.0)))
CAN.add_component(
    CoreChannel(1.0,
                3.0,
                Point(0.0, 0.0),
                label_location='center',
                name='center',
                label_pad=0.25,
                angle=0.0,
                face_color=(0.5, 0.2266, 0.5703, 1.0)))
Exemple #21
0
 def test_copy(self):
     point = Point(3, 5)
     tmp_point = deepcopy(point)
     self.assertEqual(tmp_point, point)
     self.assertIsNot(tmp_point, point)
Exemple #22
0
from schematics import CoreChannel
from schematics import Point

tmi = System('tmi')

spacing = 0.2
core_channel_width = 0.5
core_channel_height = 2.0
pipe_width = 0.4

# Core
x = 1.5 * (- core_channel_width - spacing)
y = 0.0
CH1 = CoreChannel(
        core_channel_width, core_channel_height,
        Point(x, y),
        name = 'CH1',
        label_angle = 90.0
     )
tmi.add_component(CH1)

x += core_channel_width + spacing
CH2 = CoreChannel(
        core_channel_width, core_channel_height,
        Point(x, y),
        name = 'CH2',
        label_angle = 90.0
      )
tmi.add_component(CH2)

x += core_channel_width + spacing
Exemple #23
0
command_line_parser = ExampleDebugger('Simple Pipe.')
command_line_parser.parse()

from schematics import Point
from schematics import Canvas
from schematics import Pipe
from schematics import Component

CAN = Canvas(border_thickness=0.05, grid=True)

print(Component.stats)

CAN.add_component(
    Pipe(0.75,
         0.3,
         Point(1.0, 1.0),
         name='Component',
         a=0.0,
         ll='bottom',
         lp=1.0,
         la=0.0,
         fs=10))

# CAN.add_component( Pipe(0.75, 0.3, Point(-1.0, -1.0), name = '-90 degrees', a = -90.0,
#                         ll = 'top', lp = 1.0, la = 0.0
#                        )
#                  )
#
# CAN.add_component( Pipe(0.75, 0.3, Point(0.0, -1.0), name = '-45 degrees', a = -45.0,
#                         ll = 'top', lp = 1.0, la = 0.0
#                        )
Exemple #24
0
from schematics import ExampleDebugger
command_line_parser = ExampleDebugger('A simple system.')
command_line_parser.parse()

from schematics import Canvas
from schematics import System
from schematics import Pipe
from schematics import Point

simple = System('simple')

simple.add_component(
    Pipe(1.0,
         0.5,
         Point(),
         name='Pipe 1',
         angle=0.0,
         label_location='center',
         label_pad=0.0,
         label_angle=0.0))

simple.add_component(
    Pipe(1.0,
         0.5,
         Point(1.5, 0.5),
         name='Pipe 2',
         angle=90.0,
         label_location='center',
         label_pad=0.0,
         label_angle=0.0))
Exemple #25
0
 def test_addition(self):
     point = Point(3, 5)
     tmp_point = point + point
     self.assertEqual(tmp_point.x, 6)
     self.assertEqual(tmp_point.y, 10)
Exemple #26
0
 def _get_label_locations(self):
     self.center = Point()
     self.top = Point()
     self.bottom = Point()
     self.left = None
     self.right = None
Exemple #27
0
 def test_subtraction(self):
     point = Point(3, 5)
     tmp_point = point - point
     self.assertEqual(tmp_point.x, 0)
     self.assertEqual(tmp_point.y, 0)
Exemple #28
0
from __future__ import print_function
from schematics import ExampleDebugger
command_line_parser = ExampleDebugger('Display color palettes.')
command_line_parser.parse()

from schematics import Point
from schematics import Canvas
from schematics import Pipe
from schematics import Component

CAN = Canvas(border_thickness=0.05, grid=False)

print(Component.stats)
# Reds
CAN.add_component(
    Pipe(1.0, 1.0, Point(-3.0, 3.0), face_color=(0.597659, 0.0, 0.0)))
CAN.add_component(
    Pipe(1.0, 1.0, Point(-1.5, 3.0), face_color=(0.67578, 0.19531, 0.19531)))
CAN.add_component(
    Pipe(1.0, 1.0, Point(0.0, 3.0), face_color=(0.71484, 0.2968, 0.2968)))
CAN.add_component(
    Pipe(1.0, 1.0, Point(1.5, 3.0), face_color=(0.7539, 0.3984, 0.3984)))
CAN.add_component(
    Pipe(1.0, 1.0, Point(3.0, 3.0), face_color=(0.796875, 0.49609, 0.49609)))
CAN.add_component(
    Pipe(1.0, 1.0, Point(4.5, 3.0), face_color=(0.8359, 0.5976, 0.5976)))

# Oranges
CAN.add_component(
    Pipe(1.0, 1.0, Point(-3.0, 1.5), face_color=(0.82, 0.36, 0.01)))
CAN.add_component(
Exemple #29
0
 def test_inequality(self):
     point = Point(3, 5)
     tmp_point = Point()
     self.assertNotEqual(tmp_point, point)
Exemple #30
0
from schematics import ExampleDebugger
command_line_parser = ExampleDebugger('A simple system.')
command_line_parser.parse()

from schematics import Canvas
from schematics import System
from schematics import Pipe
from schematics import Point

simple = System('simple')

simple.add_component(
  Pipe(
    1.0, 0.5, Point(), name = 'Pipe 1', angle = 0.0,
    label_location = 'center', label_pad = 0.0, label_angle = 0.0
  )
)

simple.add_component(
  Pipe(
    1.0, 0.5, Point(2.0, 1.0), name = 'Pipe 2', angle = 0.0,
    label_location = 'center', label_pad = 0.0, label_angle = 0.0
  )
)

simple.add_component(
  Pipe(
    1.0, 0.5, Point(4.0, 0.0), name = 'Pipe 3', angle = 0.0,
    label_location = 'center', label_pad = 0.0, label_angle = 0.0
  )
)
Exemple #31
0
 def test_attributes(self):
     point = Point(3, 5)
     self.assertEqual(point.x, 3)
     self.assertEqual(point.y, 5)