File size: 2,492 Bytes
26f7fa0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
MLSTRUCT-FP - DB - CPOINT

Point component (wall joints).
"""

__all__ = ['Point']

from MLStructFP.db._c import BasePolyComponent
from MLStructFP._types import List, TYPE_CHECKING, NumberType

import matplotlib.pyplot as plt
import plotly.graph_objects as go

if TYPE_CHECKING:
    from MLStructFP.db._floor import Floor


class Point(BasePolyComponent):
    """
    FP Point.
    """
    topo: int  # Topological order
    wall_id: int  # Wall ID

    def __init__(
            self,
            point_id: int,
            wall_id: int,
            floor: 'Floor',
            x: List[float],
            y: List[float],
            topo: int
    ) -> None:
        """
        Constructor.

        :param point_id: ID of the point
        :param wall_id: ID of the wall
        :param floor: Floor object
        :param x: List of coordinates within x-axis
        :param y: List of coordinates within y-axis
        :param topo: Topological order
        """
        BasePolyComponent.__init__(self, point_id, x, y, floor)
        self.topo = topo
        self.wall_id = wall_id
        # noinspection PyProtectedMember
        self.floor._point[point_id] = self

    def __color(self) -> str:
        """
        :return: Color based on topological order
        """
        if self.topo == 1:
            color = '#ff0000'
        elif self.topo == 2:
            color = '#00ff00'
        elif self.topo == 3:
            color = '#0000ff'
        elif self.topo == 4:
            color = '#ff00ff'
        else:
            color = '#00ffff'
        return color

    # noinspection PyUnusedLocal
    def plot_plotly(
            self,
            fig: 'go.Figure',
            dx: NumberType = 0,
            dy: NumberType = 0,
            postname: str = '',
            opacity: NumberType = 0.2,
            color: str = '',
            name: str = '',
            **kwargs
    ) -> None:
        if name != '':
            name = f'{name} '
        super().plot_plotly(fig, dx, dy, opacity, self.__color() if color == '' else color,
                            f'Point {name}ID{self.id}{postname} Wall {self.wall_id} TOPO-{self.topo}', **kwargs)

    def plot_matplotlib(
            self,
            ax: 'plt.Axes',
            linewidth: NumberType = 2.0,
            alpha: NumberType = 1.0,
            color: str = '',
            fill: bool = False
    ) -> None:
        super().plot_matplotlib(ax, linewidth, alpha, self.__color() if color == '' else color, fill)