Skip to content

models

Native Layer v2 数据模型

使用标准库 dataclasses 定义 native 层内部传递的数据结构。

NativeEntity dataclass

几何实体数据模型

Source code in dimine_python_sdk\lib\native\models.py
109
110
111
112
113
114
115
116
117
118
@dataclass
class NativeEntity:
    """几何实体数据模型"""

    entity_type: str         # "point" | "line" | "polyline" | "shell" | "text" | ...
    name: str = ""
    geometry: Optional["np.ndarray | NativeTin"] = None
    color: list[int] = field(default_factory=lambda: [0, 0, 0])
    properties: list[NativeProperty] = field(default_factory=list)
    feature_name: str = ""   # 所属要素名称

NativeExtendTable dataclass

Bases: NativeExtendTableMeta

扩展表(含数据)。

继承 NativeExtendTableMeta 的全部元数据字段, 附加加载后的 DataFrame。

__post_init__ 自动完成 field_list ↔ 元数据的双向推导。

Source code in dimine_python_sdk\lib\native\models.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@dataclass
class NativeExtendTable(NativeExtendTableMeta):
    """扩展表(含数据)。

    继承 NativeExtendTableMeta 的全部元数据字段,
    附加加载后的 DataFrame。

    ``__post_init__`` 自动完成 field_list ↔ 元数据的双向推导。
    """

    df: "pd.DataFrame" | None  = None
    """扩展表数据(pd.DataFrame),加载失败时为空 DataFrame"""

    def __post_init__(self):
        # --- table_name 自动推导 ---
        if not self.table_name:
            if self.display_title:
                self.table_name = self.display_title
            elif self.dmt_filename:
                self.table_name = self.dmt_filename.replace(".dmt", "")

        # --- field_list 为空但元数据存在时,自动构造 ---
        if not self.field_list and self.hole_id_column:
            parts = [
                self.hole_id_column or "",
                self.from_column or "",
                self.to_column or "",
                self.display_title or self.table_name or "",
            ]
            self.field_list = ",".join(parts)

        # --- field_list 存在但元数据缺失时,自动解析 ---
        if self.field_list and (self.hole_id_column is None or self.from_column is None):
            field_names = [f.strip() for f in self.field_list.split(",") if f.strip()]
            if self.hole_id_column is None:
                self.hole_id_column = field_names[0] if len(field_names) >= 1 else None
            if self.from_column is None:
                self.from_column = field_names[1] if len(field_names) >= 2 else None
            if self.to_column is None:
                self.to_column = field_names[2] if len(field_names) >= 3 else None
            if self.display_title is None:
                self.display_title = field_names[3] if len(field_names) >= 4 else self.table_name or None

df = None class-attribute instance-attribute

扩展表数据(pd.DataFrame),加载失败时为空 DataFrame

NativeExtendTableMeta dataclass

扩展表元数据。

封装 DMD 引用字典中解析出的扩展表(DMT)信息, 替代裸 dict 传递,提供类型安全和 IDE 自动补全。

Source code in dimine_python_sdk\lib\native\models.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@dataclass
class NativeExtendTableMeta:
    """扩展表元数据。

    封装 DMD 引用字典中解析出的扩展表(DMT)信息,
    替代裸 dict 传递,提供类型安全和 IDE 自动补全。
    """

    dmt_filename: str
    """DMT 文件名(不含路径)"""
    field_list: str = ""
    """原始字段列表字符串,格式:``孔号列,起始深度列,结束深度列,标题`` """
    hole_id_column: str | None = None
    """钻孔编号列名"""
    from_column: str | None = None
    """起始深度列名"""
    to_column: str | None = None
    """结束深度列名"""
    display_title: str | None = None
    """显示标题"""
    table_name: str = ""
    """表名(优先 display_title,回退到 dmt 文件名去后缀)"""

display_title = None class-attribute instance-attribute

显示标题

dmt_filename instance-attribute

DMT 文件名(不含路径)

field_list = '' class-attribute instance-attribute

原始字段列表字符串,格式:孔号列,起始深度列,结束深度列,标题

from_column = None class-attribute instance-attribute

起始深度列名

hole_id_column = None class-attribute instance-attribute

钻孔编号列名

table_name = '' class-attribute instance-attribute

表名(优先 display_title,回退到 dmt 文件名去后缀)

to_column = None class-attribute instance-attribute

结束深度列名

NativeFeature dataclass

DMF 要素定义

Source code in dimine_python_sdk\lib\native\models.py
152
153
154
155
156
157
@dataclass
class NativeFeature:
    """DMF 要素定义"""

    name: str
    properties: list[NativeProperty] = field(default_factory=list)

NativeFieldDef dataclass

字段定义

Attributes:

Name Type Description
name str

字段名称。

type int | str | float

C++ 类型编号(0-22),见 _DM_TYPE_MAP。

type_name str

只读,C++ 类型宏名称,如 "DM_INT"、"DM_DOUBLE"。

python_type type

只读,对应的 Python 类型,如 int、float、str、bool。

Source code in dimine_python_sdk\lib\native\models.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@dataclass
class NativeFieldDef:
    """字段定义

    Attributes:
        name: 字段名称。
        type: C++ 类型编号(0-22),见 _DM_TYPE_MAP。
        type_name: 只读,C++ 类型宏名称,如 "DM_INT"、"DM_DOUBLE"。
        python_type: 只读,对应的 Python 类型,如 int、float、str、bool。
    """

    name: str
    type: int | str | float = "string"

    @property
    def type_name(self) -> str:
        """C++ 类型宏名称,如 'DM_INT'、'DM_DOUBLE'"""
        return _DM_TYPE_TO_NAME.get(int(self.type), f"UNKNOWN({self.type})")

    @property
    def python_type(self) -> type:
        """对应的 Python 类型"""
        return _DM_TYPE_TO_PYTHON.get(int(self.type), object)

python_type property

对应的 Python 类型

type_name property

C++ 类型宏名称,如 'DM_INT'、'DM_DOUBLE'

NativeLayer dataclass

DMF 图层数据模型

Source code in dimine_python_sdk\lib\native\models.py
160
161
162
163
164
165
@dataclass
class NativeLayer:
    """DMF 图层数据模型"""

    name: str
    entities: "list[NativeEntity | NativeText]" = field(default_factory=list)

NativeLithologyModel dataclass

隐式建模岩性实体模型

Source code in dimine_python_sdk\lib\native\models.py
101
102
103
104
105
106
@dataclass
class NativeLithologyModel:
    """隐式建模岩性实体模型"""

    name: str        # 岩性(地层)名称
    tin: NativeTin   # 实体三角网模型

NativeProperty dataclass

属性键值对

Source code in dimine_python_sdk\lib\native\models.py
59
60
61
62
63
64
65
@dataclass
class NativeProperty:
    """属性键值对"""

    name: str
    value: str | int | float | datetime | None = None
    type: PropertyType = "string"

NativeText dataclass

文本实体数据模型(单行文本 / 多行文本共用)

多行文本(mtext)相比单行文本(text)额外支持: oblique(倾斜角)、width(文本框宽度)、direction(文本方向向量)。 同时多行文本无 face2_user 属性,始终为 False。

Source code in dimine_python_sdk\lib\native\models.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@dataclass
class NativeText:
    """文本实体数据模型(单行文本 / 多行文本共用)

    多行文本(mtext)相比单行文本(text)额外支持:
    oblique(倾斜角)、width(文本框宽度)、direction(文本方向向量)。
    同时多行文本无 face2_user 属性,始终为 False。
    """

    position: "np.ndarray"  # shape (3,)
    text: str
    color: list[int] = field(default_factory=lambda: [0, 0, 0])
    """文本颜色 [r, g, b],从 NativeEntityHandle.color 获取"""
    height: float = 20.0
    rotation: float = 0.0
    thickness: float = 0.0
    face2_user: bool = False
    normal: "np.ndarray" = field(
        default_factory=lambda: np.array([0, 0, 1]) if np is not None else [0, 0, 1]
    )
    # ---- 以下为多行文本(mtext)专有字段 ----
    oblique: float = 0.0
    """倾斜角(度),仅多行文本有效"""
    width: float = 0.0
    """文本框宽度,仅多行文本有效"""
    direction: "np.ndarray" = field(
        default_factory=lambda: np.array([1, 0, 0]) if np is not None else [1, 0, 0]
    )
    """文本方向向量 shape (3,),仅多行文本有效"""

color = field(default_factory=(lambda: [0, 0, 0])) class-attribute instance-attribute

文本颜色 [r, g, b],从 NativeEntityHandle.color 获取

direction = field(default_factory=(lambda: np.array([1, 0, 0]) if np is not None else [1, 0, 0])) class-attribute instance-attribute

文本方向向量 shape (3,),仅多行文本有效

oblique = 0.0 class-attribute instance-attribute

倾斜角(度),仅多行文本有效

width = 0.0 class-attribute instance-attribute

文本框宽度,仅多行文本有效

NativeTin dataclass

三角网模型

Source code in dimine_python_sdk\lib\native\models.py
93
94
95
96
97
98
@dataclass
class NativeTin:
    """三角网模型"""

    points: "np.ndarray"  # shape (N, 3)
    faces: "np.ndarray"   # shape (M, 3)