debim 2.0.0rc1__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. debim/__init__.py +21 -0
  2. debim/__main__.py +13 -0
  3. debim/_bin/debim.exe +0 -0
  4. debim/_core.pyd +0 -0
  5. debim/assets.py +312 -0
  6. debim/audit.py +829 -0
  7. debim/benchmark/__init__.py +21 -0
  8. debim/benchmark/cognitive.py +436 -0
  9. debim/boq.py +67 -0
  10. debim/bsdd.py +331 -0
  11. debim/cad2d.py +519 -0
  12. debim/calc_cli.py +323 -0
  13. debim/ci/__init__.py +19 -0
  14. debim/ci/diff_reporter.py +350 -0
  15. debim/civil/__init__.py +26 -0
  16. debim/civil/alignment_sweeper.py +593 -0
  17. debim/civil/gis_ingester.py +540 -0
  18. debim/cli.py +3684 -0
  19. debim/cloud/__init__.py +47 -0
  20. debim/cloud/git_sync.py +264 -0
  21. debim/cloud/runner.py +425 -0
  22. debim/cloud/webhook.py +215 -0
  23. debim/compat.py +196 -0
  24. debim/compiler.py +6141 -0
  25. debim/compliance.py +894 -0
  26. debim/cost.py +1616 -0
  27. debim/derive.py +632 -0
  28. debim/diff/__init__.py +28 -0
  29. debim/diff/aligner.py +94 -0
  30. debim/diff/distance.py +523 -0
  31. debim/diff/heatmap.py +133 -0
  32. debim/diff/viewer_html.py +428 -0
  33. debim/docs/__init__.py +38 -0
  34. debim/docs/exemplar.py +482 -0
  35. debim/docs/generator.py +756 -0
  36. debim/docs/pipeline.py +332 -0
  37. debim/docs/templates/directory.html +1155 -0
  38. debim/docs/thai_specs.py +537 -0
  39. debim/document.py +604 -0
  40. debim/draw/__init__.py +159 -0
  41. debim/draw/dxf.py +588 -0
  42. debim/draw/elevation.py +592 -0
  43. debim/draw/index.py +512 -0
  44. debim/draw/layout.py +514 -0
  45. debim/draw/mep_diagrams.py +821 -0
  46. debim/draw/projection.py +1050 -0
  47. debim/draw/renderer.py +2072 -0
  48. debim/draw/schedule.py +599 -0
  49. debim/draw/section.py +551 -0
  50. debim/draw/structural_details.py +795 -0
  51. debim/draw/styled_dxf.py +335 -0
  52. debim/draw/styles/sheet.css +389 -0
  53. debim/draw/templates/viewer_2d.html +1016 -0
  54. debim/draw/viewer_2d.py +197 -0
  55. debim/earthwork.py +173 -0
  56. debim/engineering/__init__.py +60 -0
  57. debim/engineering/civil.py +142 -0
  58. debim/engineering/datacenter.py +223 -0
  59. debim/engineering/electrical.py +159 -0
  60. debim/engineering/mechanical.py +77 -0
  61. debim/engineering/structural.py +145 -0
  62. debim/flight_recorder.py +120 -0
  63. debim/geometry/__init__.py +25 -0
  64. debim/geometry/drape.py +82 -0
  65. debim/geometry/loft.py +666 -0
  66. debim/geometry/stairs.py +204 -0
  67. debim/geometry/sweep3d.py +267 -0
  68. debim/geometry/tessellation.py +287 -0
  69. debim/geometry2d.py +189 -0
  70. debim/importer.py +2257 -0
  71. debim/ingest.py +299 -0
  72. debim/ir_viewer.py +282 -0
  73. debim/loader.py +864 -0
  74. debim/main.py +13 -0
  75. debim/mcp.py +277 -0
  76. debim/mep/__init__.py +15 -0
  77. debim/mep/penetration.py +273 -0
  78. debim/mep/router.py +422 -0
  79. debim/modular.py +482 -0
  80. debim/progress/__init__.py +21 -0
  81. debim/progress/tracker.py +285 -0
  82. debim/qto.py +3257 -0
  83. debim/resolution/__init__.py +46 -0
  84. debim/resolution/audit.py +243 -0
  85. debim/resolution/cli.py +256 -0
  86. debim/resolution/extractor.py +269 -0
  87. debim/resolution/funnel.py +304 -0
  88. debim/resolution/redline.py +154 -0
  89. debim/resolution/variants.py +316 -0
  90. debim/resolver.py +8708 -0
  91. debim/roof.py +641 -0
  92. debim/rust_bridge.py +162 -0
  93. debim/scaffold.py +175 -0
  94. debim/scan/__init__.py +67 -0
  95. debim/scan/calibrator.py +460 -0
  96. debim/scan/compiler.py +294 -0
  97. debim/scan/opening_detector.py +285 -0
  98. debim/scan/slicer.py +189 -0
  99. debim/scan/wall_extractor.py +499 -0
  100. debim/schedule/__init__.py +51 -0
  101. debim/schedule/builder.py +484 -0
  102. debim/schedule/reporter.py +206 -0
  103. debim/schedule/schema.py +167 -0
  104. debim/schedule/scurve.py +295 -0
  105. debim/schedule/solver.py +279 -0
  106. debim/schedule/viewer_html.py +953 -0
  107. debim/schema.py +5280 -0
  108. debim/schema_registry.py +228 -0
  109. debim/solver.py +1035 -0
  110. debim/spec/__init__.py +43 -0
  111. debim/spec/audit.py +171 -0
  112. debim/spec/builder.py +596 -0
  113. debim/spec/docx_exporter.py +315 -0
  114. debim/spec/registry.py +399 -0
  115. debim/spec/schema.py +144 -0
  116. debim/standards.py +488 -0
  117. debim/standards_client.py +529 -0
  118. debim/sync/__init__.py +25 -0
  119. debim/sync/detector.py +250 -0
  120. debim/sync/patcher.py +203 -0
  121. debim/templates/calc_electrical.yaml +29 -0
  122. debim/templates/calc_structural.yaml +32 -0
  123. debim/templates/dxf_style.yaml +68 -0
  124. debim/templates/formulas.yaml +21 -0
  125. debim/templates/prices.yaml +23 -0
  126. debim/templates/project_house.debim +82 -0
  127. debim/templates/project_radial.debim +59 -0
  128. debim/templates/rules.yaml +12 -0
  129. debim/templates/spec_map.yaml +42 -0
  130. debim/terrain.py +351 -0
  131. debim/version.py +182 -0
  132. debim/viewer.py +4782 -0
  133. debim-2.0.0rc1.dist-info/METADATA +556 -0
  134. debim-2.0.0rc1.dist-info/RECORD +138 -0
  135. debim-2.0.0rc1.dist-info/WHEEL +5 -0
  136. debim-2.0.0rc1.dist-info/entry_points.txt +4 -0
  137. debim-2.0.0rc1.dist-info/licenses/LICENSE +21 -0
  138. debim-2.0.0rc1.dist-info/top_level.txt +1 -0
debim/__init__.py ADDED
@@ -0,0 +1,21 @@
1
+ """
2
+ debim: Minimal Declarative BIM (Building-as-Code)
3
+ """
4
+
5
+ from debim.version import __version__
6
+ from debim.modular import bundle_manifest, split_manifest
7
+ from debim.loader import parse_debim, load_debim_file, resolve_default_manifest_path
8
+ from debim.document import Document, new, readfile, import_ifc
9
+
10
+ __all__ = [
11
+ "__version__",
12
+ "Document",
13
+ "new",
14
+ "readfile",
15
+ "import_ifc",
16
+ "bundle_manifest",
17
+ "split_manifest",
18
+ "parse_debim",
19
+ "load_debim_file",
20
+ "resolve_default_manifest_path",
21
+ ]
debim/__main__.py ADDED
@@ -0,0 +1,13 @@
1
+ """
2
+ Main package entry point for python -m debim.
3
+ """
4
+
5
+ from debim.cli import app
6
+
7
+
8
+ def main():
9
+ app()
10
+
11
+
12
+ if __name__ == "__main__":
13
+ main()
debim/_bin/debim.exe ADDED
Binary file
debim/_core.pyd ADDED
Binary file
debim/assets.py ADDED
@@ -0,0 +1,312 @@
1
+ """
2
+ External 3D Mesh Asset Parser Module (.obj, .gltf, .glb) for debim.
3
+ Extracts 3D vertex coordinates and triangular face indices from external assets.
4
+ """
5
+
6
+ import json
7
+ import math
8
+ import os
9
+ from pathlib import Path
10
+ import struct
11
+ from typing import Any, Dict, List, Optional, Tuple, Union
12
+
13
+ from debim.schema import Dimensions
14
+
15
+
16
+ def _rotate_vertex(
17
+ pt: Tuple[float, float, float], rx_deg: float, ry_deg: float, rz_deg: float
18
+ ) -> Tuple[float, float, float]:
19
+ """Rotate a 3D vertex by Euler angles rx, ry, rz (in degrees)."""
20
+ x, y, z = pt
21
+ rx, ry, rz = math.radians(rx_deg), math.radians(ry_deg), math.radians(rz_deg)
22
+
23
+ # Rotate X
24
+ if abs(rx) > 1e-6:
25
+ cx, sx = math.cos(rx), math.sin(rx)
26
+ y, z = y * cx - z * sx, y * sx + z * cx
27
+
28
+ # Rotate Y
29
+ if abs(ry) > 1e-6:
30
+ cy, sy = math.cos(ry), math.sin(ry)
31
+ x, z = x * cy + z * sy, -x * sy + z * cy
32
+
33
+ # Rotate Z
34
+ if abs(rz) > 1e-6:
35
+ cz, sz = math.cos(rz), math.sin(rz)
36
+ x, y = x * cz - y * sz, x * sz + y * cz
37
+
38
+ return (x, y, z)
39
+
40
+
41
+ def _transform_vertices(
42
+ vertices: List[Tuple[float, float, float]],
43
+ scale: Tuple[float, float, float] = (1.0, 1.0, 1.0),
44
+ rotation_offset: Tuple[float, float, float] = (0.0, 0.0, 0.0),
45
+ ) -> List[Tuple[float, float, float]]:
46
+ """Apply 3D scaling and rotation offset to a list of vertex coordinates."""
47
+ sx, sy, sz = float(scale[0]), float(scale[1]), float(scale[2])
48
+ rx, ry, rz = float(rotation_offset[0]), float(rotation_offset[1]), float(rotation_offset[2])
49
+
50
+ transformed = []
51
+ for x, y, z in vertices:
52
+ # 1. Apply scale
53
+ vx, vy, vz = x * sx, y * sy, z * sz
54
+ # 2. Apply rotation offset
55
+ if abs(rx) > 1e-6 or abs(ry) > 1e-6 or abs(rz) > 1e-6:
56
+ vx, vy, vz = _rotate_vertex((vx, vy, vz), rx, ry, rz)
57
+ transformed.append((round(vx, 6), round(vy, 6), round(vz, 6)))
58
+
59
+ return transformed
60
+
61
+
62
+ def parse_obj_file(filepath: Union[str, Path]) -> Tuple[List[Tuple[float, float, float]], List[Tuple[int, int, int]]]:
63
+ """
64
+ Lightweight pure-Python parser for Wavefront .obj files.
65
+ Returns (vertices, faces_1based).
66
+ """
67
+ path = Path(filepath)
68
+ if not path.exists():
69
+ raise FileNotFoundError(f"OBJ file not found: {path}")
70
+
71
+ vertices: List[Tuple[float, float, float]] = []
72
+ faces: List[Tuple[int, int, int]] = []
73
+
74
+ with open(path, "r", encoding="utf-8", errors="ignore") as f:
75
+ for line in f:
76
+ line = line.strip()
77
+ if not line or line.startswith("#"):
78
+ continue
79
+
80
+ parts = line.split()
81
+ if not parts:
82
+ continue
83
+
84
+ cmd = parts[0].lower()
85
+ if cmd == "v" and len(parts) >= 4:
86
+ try:
87
+ vx, vy, vz = float(parts[1]), float(parts[2]), float(parts[3])
88
+ vertices.append((vx, vy, vz))
89
+ except ValueError:
90
+ continue
91
+
92
+ elif cmd == "f" and len(parts) >= 4:
93
+ # Face indices in OBJ are 1-based (can be v, v/vt, v/vt/vn, or v//vn)
94
+ face_verts = []
95
+ for p in parts[1:]:
96
+ v_idx_str = p.split("/")[0]
97
+ try:
98
+ v_idx = int(v_idx_str)
99
+ if v_idx < 0:
100
+ v_idx = len(vertices) + 1 + v_idx
101
+ face_verts.append(v_idx)
102
+ except ValueError:
103
+ continue
104
+
105
+ if len(face_verts) >= 3:
106
+ # Triangulate fan: (0, 1, 2), (0, 2, 3), ...
107
+ for i in range(1, len(face_verts) - 1):
108
+ faces.append((face_verts[0], face_verts[i], face_verts[i + 1]))
109
+
110
+ return vertices, faces
111
+
112
+
113
+ def parse_gltf_glb_file(
114
+ filepath: Union[str, Path]
115
+ ) -> Tuple[List[Tuple[float, float, float]], List[Tuple[int, int, int]]]:
116
+ """
117
+ Lightweight pure-Python parser for glTF 2.0 (.gltf and .glb) files.
118
+ Extracts POSITION accessor vertices and INDICES accessor faces.
119
+ Returns (vertices, faces_1based).
120
+ """
121
+ path = Path(filepath)
122
+ if not path.exists():
123
+ raise FileNotFoundError(f"glTF/GLB file not found: {path}")
124
+
125
+ is_glb = path.suffix.lower() == ".glb" or path.name.lower().endswith(".glb")
126
+
127
+ gltf_json: Dict[str, Any] = {}
128
+ binary_buffers: List[bytes] = []
129
+
130
+ if is_glb:
131
+ with open(path, "rb") as f:
132
+ data = f.read()
133
+
134
+ if len(data) < 12:
135
+ raise ValueError(f"Invalid GLB file (too short): {path}")
136
+
137
+ magic, version, length = struct.unpack("<4sII", data[:12])
138
+ if magic != b"glTF":
139
+ raise ValueError(f"Invalid GLB magic header in {path}")
140
+
141
+ offset = 12
142
+ while offset + 8 <= len(data):
143
+ chunk_len, chunk_type = struct.unpack("<II", data[offset : offset + 8])
144
+ chunk_data = data[offset + 8 : offset + 8 + chunk_len]
145
+ offset += 8 + chunk_len
146
+
147
+ if chunk_type == 0x4E4F534A: # "JSON"
148
+ gltf_json = json.loads(chunk_data.decode("utf-8"))
149
+ elif chunk_type == 0x004E4942 or chunk_type == 0x204E4942: # "BIN\0" or "BIN"
150
+ binary_buffers.append(chunk_data)
151
+ else:
152
+ with open(path, "r", encoding="utf-8") as f:
153
+ gltf_json = json.load(f)
154
+
155
+ # Load external buffer files if present
156
+ buffers_info = gltf_json.get("buffers", [])
157
+ for b_info in buffers_info:
158
+ uri = b_info.get("uri")
159
+ if uri:
160
+ if uri.startswith("data:application/octet-stream;base64,"):
161
+ import base64
162
+
163
+ b64_str = uri.split(",", 1)[1]
164
+ binary_buffers.append(base64.b64decode(b64_str))
165
+ else:
166
+ buf_path = path.parent / uri
167
+ if buf_path.exists():
168
+ binary_buffers.append(buf_path.read_bytes())
169
+ else:
170
+ binary_buffers.append(b"")
171
+ else:
172
+ binary_buffers.append(b"")
173
+
174
+ buffer_views = gltf_json.get("bufferViews", [])
175
+ accessors = gltf_json.get("accessors", [])
176
+
177
+ def get_buffer_data(bv_index: int) -> bytes:
178
+ if bv_index >= len(buffer_views):
179
+ return b""
180
+ bv = buffer_views[bv_index]
181
+ buf_idx = bv.get("buffer", 0)
182
+ byte_offset = bv.get("byteOffset", 0)
183
+ byte_length = bv.get("byteLength", 0)
184
+
185
+ if buf_idx < len(binary_buffers):
186
+ buf_bytes = binary_buffers[buf_idx]
187
+ return buf_bytes[byte_offset : byte_offset + byte_length]
188
+ return b""
189
+
190
+ all_vertices: List[Tuple[float, float, float]] = []
191
+ all_faces: List[Tuple[int, int, int]] = []
192
+
193
+ meshes = gltf_json.get("meshes", [])
194
+ for mesh in meshes:
195
+ for prim in mesh.get("primitives", []):
196
+ attrs = prim.get("attributes", {})
197
+ pos_acc_idx = attrs.get("POSITION")
198
+ if pos_acc_idx is None or pos_acc_idx >= len(accessors):
199
+ continue
200
+
201
+ pos_acc = accessors[pos_acc_idx]
202
+ pos_bv_idx = pos_acc.get("bufferView")
203
+ if pos_bv_idx is None:
204
+ continue
205
+
206
+ pos_data = get_buffer_data(pos_bv_idx)
207
+ pos_offset = pos_acc.get("byteOffset", 0)
208
+ count = pos_acc.get("count", 0)
209
+
210
+ vertex_offset_base = len(all_vertices)
211
+
212
+ # Unpack float32 (x, y, z)
213
+ for i in range(count):
214
+ idx_off = pos_offset + i * 12
215
+ if idx_off + 12 <= len(pos_data):
216
+ vx, vy, vz = struct.unpack_from("<fff", pos_data, idx_off)
217
+ all_vertices.append((vx, vy, vz))
218
+
219
+ # Unpack indices if present
220
+ indices_acc_idx = prim.get("indices")
221
+ if indices_acc_idx is not None and indices_acc_idx < len(accessors):
222
+ ind_acc = accessors[indices_acc_idx]
223
+ ind_bv_idx = ind_acc.get("bufferView")
224
+ if ind_bv_idx is not None:
225
+ ind_data = get_buffer_data(ind_bv_idx)
226
+ ind_offset = ind_acc.get("byteOffset", 0)
227
+ ind_count = ind_acc.get("count", 0)
228
+ comp_type = ind_acc.get("componentType", 5123) # 5123 = UNSIGNED_SHORT, 5125 = UNSIGNED_INT
229
+
230
+ raw_indices = []
231
+ if comp_type == 5123: # uint16
232
+ for i in range(ind_count):
233
+ if ind_offset + i * 2 + 2 <= len(ind_data):
234
+ idx_val = struct.unpack_from("<H", ind_data, ind_offset + i * 2)[0]
235
+ raw_indices.append(idx_val)
236
+ elif comp_type == 5125: # uint32
237
+ for i in range(ind_count):
238
+ if ind_offset + i * 4 + 4 <= len(ind_data):
239
+ idx_val = struct.unpack_from("<I", ind_data, ind_offset + i * 4)[0]
240
+ raw_indices.append(idx_val)
241
+ elif comp_type == 5121: # uint8
242
+ for i in range(ind_count):
243
+ if ind_offset + i < len(ind_data):
244
+ idx_val = ind_data[ind_offset + i]
245
+ raw_indices.append(idx_val)
246
+
247
+ for i in range(0, len(raw_indices) - 2, 3):
248
+ v1 = vertex_offset_base + raw_indices[i] + 1
249
+ v2 = vertex_offset_base + raw_indices[i + 1] + 1
250
+ v3 = vertex_offset_base + raw_indices[i + 2] + 1
251
+ all_faces.append((v1, v2, v3))
252
+ else:
253
+ # Non-indexed triangles
254
+ for i in range(0, count - 2, 3):
255
+ v1 = vertex_offset_base + i + 1
256
+ v2 = vertex_offset_base + i + 2
257
+ v3 = vertex_offset_base + i + 3
258
+ all_faces.append((v1, v2, v3))
259
+
260
+ return all_vertices, all_faces
261
+
262
+
263
+ def parse_mesh_file(
264
+ filepath: Union[str, Path],
265
+ scale: Tuple[float, float, float] = (1.0, 1.0, 1.0),
266
+ rotation_offset: Tuple[float, float, float] = (0.0, 0.0, 0.0),
267
+ ) -> Tuple[List[Tuple[float, float, float]], List[Tuple[int, int, int]]]:
268
+ """
269
+ Parse external 3D mesh asset (.obj, .gltf, .glb) and return scaled/rotated (vertices, 1-based faces).
270
+ """
271
+ path = Path(filepath)
272
+ ext = path.suffix.lower()
273
+
274
+ if ext == ".obj":
275
+ raw_verts, faces = parse_obj_file(path)
276
+ elif ext in (".gltf", ".glb"):
277
+ raw_verts, faces = parse_gltf_glb_file(path)
278
+ else:
279
+ raise ValueError(f"Unsupported mesh asset format '{ext}'. Supported formats: .obj, .gltf, .glb")
280
+
281
+ transformed_verts = _transform_vertices(raw_verts, scale=scale, rotation_offset=rotation_offset)
282
+ return transformed_verts, faces
283
+
284
+
285
+ def get_mesh_dimensions(
286
+ filepath: Union[str, Path],
287
+ scale: Tuple[float, float, float] = (1.0, 1.0, 1.0),
288
+ rotation_offset: Tuple[float, float, float] = (0.0, 0.0, 0.0),
289
+ ) -> Optional[Dimensions]:
290
+ """
291
+ Calculate bounding box 3D dimensions (width, depth, height) for a mesh asset.
292
+ """
293
+ try:
294
+ verts, _ = parse_mesh_file(filepath, scale=scale, rotation_offset=rotation_offset)
295
+ if not verts:
296
+ return None
297
+
298
+ xs = [v[0] for v in verts]
299
+ ys = [v[1] for v in verts]
300
+ zs = [v[2] for v in verts]
301
+
302
+ w = round(max(xs) - min(xs), 3)
303
+ d = round(max(ys) - min(ys), 3)
304
+ h = round(max(zs) - min(zs), 3)
305
+
306
+ return Dimensions(
307
+ width=max(w, 0.01),
308
+ depth=max(d, 0.01),
309
+ height=max(h, 0.01),
310
+ )
311
+ except Exception:
312
+ return None