Skip to content

models

DMF 实体类型枚举和图层结构。

图层使用 dimine_python_sdk.models.types.LayerInfo 作为基类。 实体使用 dimine_python_sdk.models.types 的共享类型: Point, Line, Shell, TextInfo

DmfEntityType

Bases: IntEnum

DMF 实体类型枚举,与 C++ EntityType 一致

Source code in dimine_python_sdk\lib\file\models.py
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 DmfEntityType(IntEnum):
    """DMF 实体类型枚举,与 C++ EntityType 一致"""

    UNKNOWN = -1
    POINT = 0
    LINE = 1
    POLYLINE = 2
    SHELL = 3
    TEXT = 4
    ARC = 5
    CIRCLE = 6
    ELLIPSE = 7
    SPLINE = 8
    POLYGON = 9
    ANNOTATION = 10
    SPHERE = 11
    UGRID = 12
    WORKPLANE = 13
    NET_NODE = 15
    NET_EDGE = 16
    MODEL = 17
    COMPLEX = 18
    POLYLINE_2D = 19
    LWPOLYLINE = 20
    BLOCK = 21
    MBLOCK = 22
    HATCH = 23
    MESH = 34
    CUSTOM_START = 100

DmfLayer

Bases: LayerInfo

DMF 图层,继承自 LayerInfo,附加实体列表和插入方法

Source code in dimine_python_sdk\lib\file\models.py
 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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class DmfLayer(LayerInfo):
    """DMF 图层,继承自 ``LayerInfo``,附加实体列表和插入方法"""

    model_config = {"arbitrary_types_allowed": True, "frozen": False}

    entities: List[DmfEntity] = Field(default_factory=list, description="实体列表")

    @property
    def entity_count(self) -> int:
        """实体数量(与 ``entities`` 实时同步)"""
        return len(self.entities)

    # ------------------------------------------------------------------
    # 实体插入(直接操作内存模型)
    # ------------------------------------------------------------------

    def insert_point(self, position: np.ndarray, *, name: str = "") -> None:
        """向本图层插入点实体"""
        from dimine_python_sdk.lib.file._adapter import DmfInsertError

        pt = np.asarray(position, dtype=np.float64).ravel()
        if pt.shape[0] < 3:
            raise DmfInsertError(f"点坐标至少需要3个分量,当前: {pt.shape[0]}")
        self.entities.append(Point(feature=name, geometry=pt[:3].astype(np.float32)))

    def insert_line(self, start: np.ndarray, end: np.ndarray, *, name: str = "") -> None:
        """向本图层插入直线"""
        from dimine_python_sdk.lib.file._adapter import DmfInsertError

        s = np.asarray(start, dtype=np.float64).ravel()
        e = np.asarray(end, dtype=np.float64).ravel()
        if s.shape[0] < 3 or e.shape[0] < 3:
            raise DmfInsertError("线端点至少需要3个分量")

        coords = np.array([s[:3], e[:3]], dtype=np.float32)
        self.entities.append(Line(feature=name, geometry=coords))

    def insert_polyline(self, points: np.ndarray, *, name: str = "") -> None:
        """向本图层插入多段线"""
        from dimine_python_sdk.lib.file._adapter import DmfInsertError

        pts = np.asarray(points, dtype=np.float64)
        if pts.ndim == 1:
            pts = pts.reshape(1, -1)
        if pts.shape[1] < 3:
            raise DmfInsertError(f"多段线顶点至少需要3个分量,当前: {pts.shape[1]}")

        coords = pts[:, :3].astype(np.float32)
        self.entities.append(Line(feature=name, geometry=coords))

    def insert_shell(self, points: np.ndarray, faces: np.ndarray, *, name: str = "") -> None:
        """向本图层插入三维实体(Shell)"""
        from dimine_python_sdk.lib.file._adapter import DmfInsertError

        pts = np.asarray(points, dtype=np.float64)
        if pts.ndim == 1:
            pts = pts.reshape(1, -1)
        if pts.shape[1] < 3:
            raise DmfInsertError(f"Shell 顶点至少需要3个分量,当前: {pts.shape[1]}")

        fcs = np.asarray(faces, dtype=np.int32)
        if fcs.ndim == 1:
            fcs = fcs.reshape(1, -1)

        tin = TINGeometry(points=pts[:, :3], faces=fcs)
        self.entities.append(Shell(feature=name, geometry=tin))

    def insert_text(self, position: np.ndarray, text: str, *, name: str = "") -> None:
        """向本图层插入文本标注"""
        from dimine_python_sdk.lib.file._adapter import DmfInsertError

        pos = np.asarray(position, dtype=np.float64).ravel()
        if pos.shape[0] < 3:
            raise DmfInsertError(f"文本位置至少需要3个分量,当前: {pos.shape[0]}")

        self.entities.append(TextInfo(feature=name, text=text, position=pos[:3].tolist()))

entity_count property

实体数量(与 entities 实时同步)

insert_line(start, end, *, name='')

向本图层插入直线

Source code in dimine_python_sdk\lib\file\models.py
85
86
87
88
89
90
91
92
93
94
95
def insert_line(self, start: np.ndarray, end: np.ndarray, *, name: str = "") -> None:
    """向本图层插入直线"""
    from dimine_python_sdk.lib.file._adapter import DmfInsertError

    s = np.asarray(start, dtype=np.float64).ravel()
    e = np.asarray(end, dtype=np.float64).ravel()
    if s.shape[0] < 3 or e.shape[0] < 3:
        raise DmfInsertError("线端点至少需要3个分量")

    coords = np.array([s[:3], e[:3]], dtype=np.float32)
    self.entities.append(Line(feature=name, geometry=coords))

insert_point(position, *, name='')

向本图层插入点实体

Source code in dimine_python_sdk\lib\file\models.py
76
77
78
79
80
81
82
83
def insert_point(self, position: np.ndarray, *, name: str = "") -> None:
    """向本图层插入点实体"""
    from dimine_python_sdk.lib.file._adapter import DmfInsertError

    pt = np.asarray(position, dtype=np.float64).ravel()
    if pt.shape[0] < 3:
        raise DmfInsertError(f"点坐标至少需要3个分量,当前: {pt.shape[0]}")
    self.entities.append(Point(feature=name, geometry=pt[:3].astype(np.float32)))

insert_polyline(points, *, name='')

向本图层插入多段线

Source code in dimine_python_sdk\lib\file\models.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
def insert_polyline(self, points: np.ndarray, *, name: str = "") -> None:
    """向本图层插入多段线"""
    from dimine_python_sdk.lib.file._adapter import DmfInsertError

    pts = np.asarray(points, dtype=np.float64)
    if pts.ndim == 1:
        pts = pts.reshape(1, -1)
    if pts.shape[1] < 3:
        raise DmfInsertError(f"多段线顶点至少需要3个分量,当前: {pts.shape[1]}")

    coords = pts[:, :3].astype(np.float32)
    self.entities.append(Line(feature=name, geometry=coords))

insert_shell(points, faces, *, name='')

向本图层插入三维实体(Shell)

Source code in dimine_python_sdk\lib\file\models.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def insert_shell(self, points: np.ndarray, faces: np.ndarray, *, name: str = "") -> None:
    """向本图层插入三维实体(Shell)"""
    from dimine_python_sdk.lib.file._adapter import DmfInsertError

    pts = np.asarray(points, dtype=np.float64)
    if pts.ndim == 1:
        pts = pts.reshape(1, -1)
    if pts.shape[1] < 3:
        raise DmfInsertError(f"Shell 顶点至少需要3个分量,当前: {pts.shape[1]}")

    fcs = np.asarray(faces, dtype=np.int32)
    if fcs.ndim == 1:
        fcs = fcs.reshape(1, -1)

    tin = TINGeometry(points=pts[:, :3], faces=fcs)
    self.entities.append(Shell(feature=name, geometry=tin))

insert_text(position, text, *, name='')

向本图层插入文本标注

Source code in dimine_python_sdk\lib\file\models.py
127
128
129
130
131
132
133
134
135
def insert_text(self, position: np.ndarray, text: str, *, name: str = "") -> None:
    """向本图层插入文本标注"""
    from dimine_python_sdk.lib.file._adapter import DmfInsertError

    pos = np.asarray(position, dtype=np.float64).ravel()
    if pos.shape[0] < 3:
        raise DmfInsertError(f"文本位置至少需要3个分量,当前: {pos.shape[0]}")

    self.entities.append(TextInfo(feature=name, text=text, position=pos[:3].tolist()))