Skip to content

path

PathEntity #

Bases: QEntity

A simple entity drawing a path along a list of vertices.

Source code in cogip/entities/path.py
 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
class PathEntity(Qt3DCore.QEntity):
    """
    A simple entity drawing a path along a list of vertices.
    """

    def __init__(self, color: QtGui.QColor = QtCore.Qt.blue, parent: Qt3DCore.QEntity | None = None):
        """
        Class constructor.

        Arguments:
            color: color
            parent: parent entity
        """
        super().__init__(parent)
        self.points = []
        self.color = color
        self.lines: list[LineEntity] = []
        self.lines_pool: list[LineEntity] = []

    def set_points(self, points: list[models.Vertex]):
        """
        Set points of the path.

        Arguments:
            points: list of vertices composing the line
        """
        self.points = points

        if len(self.points) < 2:
            return

        for line in self.lines:
            line.setEnabled(False)
            self.lines_pool.append(line)

        self.lines = []

        start = self.points.pop(0)
        for next in self.points:
            if len(self.lines_pool) == 0:
                self.lines_pool.append(LineEntity(self.color, self))
            line = self.lines_pool.pop()
            line.setEnabled(True)
            line.set_points(start, next)
            self.lines.append(line)
            start = next

__init__(color=QtCore.Qt.blue, parent=None) #

Class constructor.

Parameters:

Name Type Description Default
color QColor

color

blue
parent QEntity | None

parent entity

None
Source code in cogip/entities/path.py
13
14
15
16
17
18
19
20
21
22
23
24
25
def __init__(self, color: QtGui.QColor = QtCore.Qt.blue, parent: Qt3DCore.QEntity | None = None):
    """
    Class constructor.

    Arguments:
        color: color
        parent: parent entity
    """
    super().__init__(parent)
    self.points = []
    self.color = color
    self.lines: list[LineEntity] = []
    self.lines_pool: list[LineEntity] = []

set_points(points) #

Set points of the path.

Parameters:

Name Type Description Default
points list[Vertex]

list of vertices composing the line

required
Source code in cogip/entities/path.py
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
def set_points(self, points: list[models.Vertex]):
    """
    Set points of the path.

    Arguments:
        points: list of vertices composing the line
    """
    self.points = points

    if len(self.points) < 2:
        return

    for line in self.lines:
        line.setEnabled(False)
        self.lines_pool.append(line)

    self.lines = []

    start = self.points.pop(0)
    for next in self.points:
        if len(self.lines_pool) == 0:
            self.lines_pool.append(LineEntity(self.color, self))
        line = self.lines_pool.pop()
        line.setEnabled(True)
        line.set_points(start, next)
        self.lines.append(line)
        start = next