Debian Codegraph @

src/Mod/BIM/importers/importGBXML.py

raw symbols SCIP
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 # ***************************************************************************
4 # * *
5 # * Copyright (c) 2015 Yorik van Havre <[email protected]> *
6 # * *
7 # * This file is part of FreeCAD. *
8 # * *
9 # * FreeCAD is free software: you can redistribute it and/or modify it *
10 # * under the terms of the GNU Lesser General Public License as *
11 # * published by the Free Software Foundation, either version 2.1 of the *
12 # * License, or (at your option) any later version. *
13 # * *
14 # * FreeCAD is distributed in the hope that it will be useful, but *
15 # * WITHOUT ANY WARRANTY; without even the implied warranty of *
16 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 # * Lesser General Public License for more details. *
18 # * *
19 # * You should have received a copy of the GNU Lesser General Public *
20 # * License along with FreeCAD. If not, see *
21 # * <https://www.gnu.org/licenses/>. *
22 # * *
23 # ***************************************************************************
24
25 __title__ = "FreeCAD GbXml exporter"
26 __author__ = "Yorik van Havre"
27 __url__ = "https://www.freecad.org"
28
29 ## @package importGBXML
30 # \ingroup ARCH
31 # \brief GBXML file format exporter
32 #
33 # This module provides tools to export GBXML files.
34
35 from builtins import open as pyopen
36
37 import FreeCAD
38 import Draft
39
40 if FreeCAD.GuiUp:
41 from draftutils.translate import translate
42 else:
43 # \cond
44 def translate(ctx, txt):
45 return txt
46
47 # \endcond
48
49
50 def export(objectslist, filename):
51
52 if len(objectslist) != 1:
53 FreeCAD.Console.PrintError(
54 translate("Arch", "This exporter can currently only export one site object") + "\n"
55 )
56 return
57 site = objectslist[0]
58 if Draft.getType(site) != "Site":
59 FreeCAD.Console.PrintError(
60 translate("Arch", "This exporter can currently only export one site object") + "\n"
61 )
62 return
63
64 filestream = pyopen(filename, "wb")
65
66 # header
67 filestream.write('<?xml version="1.0"?>\n')
68 filestream.write(
69 "<!-- Exported by FreeCAD %s -->\n" % FreeCAD.Version()[0]
70 + FreeCAD.Version()[1]
71 + FreeCAD.Version()[2]
72 )
73 filestream.write("<gbXML\n")
74 filestream.write(' xmlns="http://www.gbxml.org/schema"\n')
75 filestream.write(' xmlns:xhtml="http://www.w3.org/1999/xhtml"\n')
76 filestream.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n')
77 filestream.write(' xsi:schemaLocation="http://www.gbxml.org/schema"\n ')
78 filestream.write(' temperatureUnit="C"\n')
79 filestream.write(' lengthUnit="Meters"\n')
80 filestream.write(' areaUnit="SquareMeters"\n')
81 filestream.write(' volumeUnit="CubicMeters"\n')
82 filestream.write(' useSIUnitsForResults="false" >\n')
83 filestream.write("\n")
84
85 # campus
86 filestream.write('<Campus id="%s">\n' % site.Name)
87 filestream.write("<Location>\n")
88 filestream.write(" <ZipcodeOrPostalCode>%s</ZipcodeOrPostalCode>\n" % site.PostalCode)
89 filestream.write(" <Longitude>%f</Longitude>\n" % site.Longitude)
90 filestream.write(" <Latitude>%f</Latitude>\n" % site.Latitude)
91 filestream.write(" <Elevation>%f/Elevation>\n" % site.Elevation.Value)
92 filestream.write(" <Name>%s</Name>\n" % site.Label)
93 # filestream.write( ' <CADModelAzimuth>0</CADModelAzimuth>\n' )
94 # filestream.write( ' <StationId IDType="WMO">53158_2004</StationId>\n' )
95 filestream.write("</Location>\n")
96
97 # buildings
98 for building in site.Group:
99 if Draft.getType(building) == "Building":
100 filestream.write(
101 ' <Building id="$s" buildingType="$s">\n'
102 % (building.Name, building.BuildingType)
103 )
104 filestream.write(" <Area>$f</Area>\n" % str(building.Area.getValueAs("m^2")))
105
106 # spaces
107 for space in Draft.getObjectsOfType(
108 Draft.get_group_contents(building.Group, addgroups=True), "Space"
109 ):
110 if not space.Zone:
111 FreeCAD.Console.PrintError(
112 translate("Arch", "Error: Space '%s' has no Zone. Aborting.") % space.Label
113 + "\n"
114 )
115 return
116 filestream.write(
117 ' <Space id="%s" spaceType="%s" zoneIdRef="%s" conditionType="%f">\n'
118 % (space.Name, space.SpaceType, space.Zone.Name, space.Conditioning)
119 )
120 # filestream.write( ' <CADObjectId>%s</CADObjectId>\n' % space.Name ) # not sure what this is used for?
121 filestream.write(" <Name>%s</Name>\n" % space.Label)
122 filestream.write(" <Description>%s</Description>\n" % space.Description)
123 filestream.write(
124 ' <PeopleNumber unit="NumberOfPeople">%i</PeopleNumber>\n'
125 % space.NumberOfPeople
126 )
127 filestream.write(
128 ' <LightPowerPerArea unit="WattPerSquareMeter">%f</LightPowerPerArea>\n'
129 % space.LightingPower
130 / space.Area.getValueAs("m^2")
131 )
132 filestream.write(
133 ' <EquipPowerPerArea unit="WattPerSquareMeter">%f</EquipPowerPerArea>\n'
134 % space.EquipmentPower
135 / space.Area.getValueAs("m^2")
136 )
137 filestream.write(" <Area>$f</Area>\n" % space.Area.getValueAs("m^2"))
138 filestream.write(
139 " <Volume>$f</Volume>\n"
140 % FreeCAD.Units.Quantity(space.Shape.Volume, FreeCAD.Units.Volume).getValueAs(
141 "m^3"
142 )
143 )
144 filestream.write(' <ShellGeometry id="%s_geometry">\n' % space.Name)
145
146 # shells
147 for solid in space.Shape.Solids:
148 filestream.write(" <ClosedShell>\n")
149 for face in solid.Faces:
150 filestream.write(" <PolyLoop>\n")
151 for v in face.OuterWire.Vertexes:
152 filestream.write(" <CartesianPoint>\n")
153 filestream.write(
154 " <Coordinate>%f</Coordinate>\n"
155 % v.Point.x
156 )
157 filestream.write(
158 " <Coordinate>%f</Coordinate>\n"
159 % v.Point.y
160 )
161 filestream.write(
162 " <Coordinate>%f</Coordinate>\n"
163 % v.Point.z
164 )
165 filestream.write(" </CartesianPoint>\n")
166 filestream.write(" </PolyLoop>\n")
167 filestream.write(" </ClosedShell>\n")
168 filestream.write(" </ShellGeometry>\n")
169 filestream.write(" </Space>\n")
170
171 # surfaces
172 for i, face in enumerate(space.Shape.Faces):
173 filestream.write(
174 ' <SpaceBoundary isSecondLevelBoundary="false" surfaceIdRef="%s_Face%i"\n'
175 % space.Name,
176 i,
177 )
178 filestream.write(" <PlanarGeometry>\n")
179 filestream.write(" <PolyLoop>\n")
180 for v in face.OuterWire.Vertexes:
181 filestream.write(" <CartesianPoint>\n")
182 filestream.write(
183 " <Coordinate>%f</Coordinate>\n" % v.Point.x
184 )
185 filestream.write(
186 " <Coordinate>%f</Coordinate>\n" % v.Point.y
187 )
188 filestream.write(
189 " <Coordinate>%f</Coordinate>\n" % v.Point.z
190 )
191 filestream.write(" </CartesianPoint>\n")
192 filestream.write(" </PolyLoop>\n")
193 filestream.write(" </PlanarGeometry>\n")
194 filestream.write(" </SpaceBoundary>\n")
195
196 filestream.write(" </Space>\n")
197
198 filestream.write(" </Building>\n")
199
200 filestream.write("</Campus>\n")
201
202 filestream.write("</gbXML>")
203
204
205 """
206 <Area>18000.00000</Area>
207 <Space id="sp1_LabandCorridor_Labcorridor" spaceType="LaboratoryOffice" zoneIdRef="z1_LabandCorridor">
208 <Name>Lab corridor</Name>
209 <Description/>
210 <PeopleNumber unit="NumberOfPeople">1.00000</PeopleNumber>
211 <LightPowerPerArea unit="WattPerSquareFoot">1.50000</LightPowerPerArea>
212 <EquipPowerPerArea unit="WattPerSquareFoot">0.00000</EquipPowerPerArea>
213 <Area>800.00000</Area>
214 <Volume>6400.00000</Volume>
215 <ShellGeometry id="geo_sp1_LabandCorridor_Labcorridor">
216 <ClosedShell>
217 <PolyLoop>
218 <CartesianPoint>
219 <Coordinate>0.00000</Coordinate>
220 <Coordinate>1200.00000</Coordinate>
221 <Coordinate>0.00000</Coordinate>
222 </CartesianPoint>
223 <CartesianPoint>
224 <Coordinate>0.00000</Coordinate>
225 <Coordinate>1200.00000</Coordinate>
226 <Coordinate>96.00000</Coordinate>
227 </CartesianPoint>
228 <CartesianPoint>
229 <Coordinate>480.00000</Coordinate>
230 <Coordinate>1200.00000</Coordinate>
231 <Coordinate>96.00000</Coordinate>
232 </CartesianPoint>
233 <CartesianPoint>
234 <Coordinate>480.00000</Coordinate>
235 <Coordinate>1200.00000</Coordinate>
236 <Coordinate>0.00000</Coordinate>
237 </CartesianPoint>
238 </PolyLoop>
239
240 ... repeat
241
242 </ClosedShell>
243 </ShellGeometry>
244
245 <SpaceBoundary isSecondLevelBoundary="false" surfaceIdRef="aim1095">
246 <PlanarGeometry>
247 <PolyLoop>
248 <CartesianPoint>
249 <Coordinate>9.981497</Coordinate>
250 <Coordinate>-31.19363</Coordinate>
251 <Coordinate>0</Coordinate>
252 </CartesianPoint>
253 <CartesianPoint>
254 <Coordinate>9.981497</Coordinate>
255 <Coordinate>-5.193626</Coordinate>
256 <Coordinate>0</Coordinate>
257 </CartesianPoint>
258 <CartesianPoint>
259 <Coordinate>9.981497</Coordinate>
260 <Coordinate>-5.193626</Coordinate>
261 <Coordinate>100</Coordinate>
262 </CartesianPoint>
263 <CartesianPoint>
264 <Coordinate>9.981497</Coordinate>
265 <Coordinate>-31.19363</Coordinate>
266 <Coordinate>100</Coordinate>
267 </CartesianPoint>
268 </PolyLoop>
269 </PlanarGeometry>
270 </SpaceBoundary>
271
272
273
274
275 <CADObjectId>21E2</CADObjectId>
276 </Space>
277
278 ... repeat
279
280 </Building>
281
282
283
284 <Surface id="su1_Floor" surfaceType="UndergroundSlab" constructionIdRef="construction-1">
285 <Name>Floor</Name>
286 <AdjacentSpaceId spaceIdRef="sp1_LabandCorridor_Labcorridor"/>
287 <RectangularGeometry>
288 <Azimuth>90.00</Azimuth>
289 <CartesianPoint>
290 <Coordinate>0.00000</Coordinate>
291 <Coordinate>1320.00000</Coordinate>
292 <Coordinate>0.00000</Coordinate>
293 </CartesianPoint>
294 <Tilt>180.00</Tilt>
295 <Height>480.00000</Height>
296 <Width>240.00000</Width>
297 </RectangularGeometry>
298 <PlanarGeometry>
299 <PolyLoop>
300 <CartesianPoint>
301 <Coordinate>0.00000</Coordinate>
302 <Coordinate>1320.00000</Coordinate>
303 <Coordinate>0.00000</Coordinate>
304 </CartesianPoint>
305 <CartesianPoint>
306 <Coordinate>480.00000</Coordinate>
307 <Coordinate>1320.00000</Coordinate>
308 <Coordinate>0.00000</Coordinate>
309 </CartesianPoint>
310 <CartesianPoint>
311 <Coordinate>960.00000</Coordinate>
312 <Coordinate>1320.00000</Coordinate>
313 <Coordinate>0.00000</Coordinate>
314 </CartesianPoint>
315 <CartesianPoint>
316 <Coordinate>960.00000</Coordinate>
317 <Coordinate>1200.00000</Coordinate>
318 <Coordinate>0.00000</Coordinate>
319 </CartesianPoint>
320 <CartesianPoint>
321 <Coordinate>480.00000</Coordinate>
322 <Coordinate>1200.00000</Coordinate>
323 <Coordinate>0.00000</Coordinate>
324 </CartesianPoint>
325 <CartesianPoint>
326 <Coordinate>0.00000</Coordinate>
327 <Coordinate>1200.00000</Coordinate>
328 <Coordinate>0.00000</Coordinate>
329 </CartesianPoint>
330 </PolyLoop>
331 </PlanarGeometry>
332 </Surface>
333
334
335
336 <Surface id="su44_Surface4" surfaceType="ExteriorWall" constructionIdRef="construction-3">
337 <Name>Surface 4</Name>
338 <AdjacentSpaceId spaceIdRef="sp7_Office_Office6"/>
339 <RectangularGeometry>
340 <Azimuth>180.00</Azimuth>
341 <CartesianPoint>
342 <Coordinate>960.00000</Coordinate>
343 <Coordinate>0.00000</Coordinate>
344 <Coordinate>0.00000</Coordinate>
345 </CartesianPoint>
346 <Tilt>90.00</Tilt>
347 <Height>114.00000</Height>
348 <Width>480.00000</Width>
349 </RectangularGeometry>
350 <PlanarGeometry>
351 <PolyLoop>
352 <CartesianPoint>
353 <Coordinate>960.00000</Coordinate>
354 <Coordinate>0.00000</Coordinate>
355 <Coordinate>0.00000</Coordinate>
356 </CartesianPoint>
357 <CartesianPoint>
358 <Coordinate>1440.00000</Coordinate>
359 <Coordinate>0.00000</Coordinate>
360 <Coordinate>0.00000</Coordinate>
361 </CartesianPoint>
362 <CartesianPoint>
363 <Coordinate>1440.00000</Coordinate>
364 <Coordinate>0.00000</Coordinate>
365 <Coordinate>114.00000</Coordinate>
366 </CartesianPoint>
367 <CartesianPoint>
368 <Coordinate>960.00000</Coordinate>
369 <Coordinate>0.00000</Coordinate>
370 <Coordinate>114.00000</Coordinate>
371 </CartesianPoint>
372 </PolyLoop>
373 </PlanarGeometry>
374 <Opening id="su44-op1_Opening1" openingType="OperableWindow" windowTypeIdRef="windowType-1">
375 <Name>Opening1</Name>
376 <RectangularGeometry>
377 <CartesianPoint>
378 <Coordinate>96.00000</Coordinate>
379 <Coordinate>24.00000</Coordinate>
380 </CartesianPoint>
381 <Height>72.00000</Height>
382 <Width>48.00000</Width>
383 </RectangularGeometry>
384 <PlanarGeometry>
385 <PolyLoop>
386 <CartesianPoint>
387 <Coordinate>1056.00000</Coordinate>
388 <Coordinate>0.00000</Coordinate>
389 <Coordinate>24.00000</Coordinate>
390 </CartesianPoint>
391 <CartesianPoint>
392 <Coordinate>1104.00000</Coordinate>
393 <Coordinate>0.00000</Coordinate>
394 <Coordinate>24.00000</Coordinate>
395 </CartesianPoint>
396 <CartesianPoint>
397 <Coordinate>1104.00000</Coordinate>
398 <Coordinate>0.00000</Coordinate>
399 <Coordinate>96.00000</Coordinate>
400 </CartesianPoint>
401 <CartesianPoint>
402 <Coordinate>1056.00000</Coordinate>
403 <Coordinate>0.00000</Coordinate>
404 <Coordinate>96.00000</Coordinate>
405 </CartesianPoint>
406 </PolyLoop>
407 </PlanarGeometry>
408 </Opening>
409 <Opening id="su44-op2_Opening2" openingType="OperableWindow" windowTypeIdRef="windowType-1">
410 <Name>Opening2</Name>
411 <RectangularGeometry>
412 <CartesianPoint>
413 <Coordinate>216.00000</Coordinate>
414 <Coordinate>24.00000</Coordinate>
415 </CartesianPoint>
416 <Height>72.00000</Height>
417 <Width>48.00000</Width>
418 </RectangularGeometry>
419 <PlanarGeometry>
420 <PolyLoop>
421 <CartesianPoint>
422 <Coordinate>1176.00000</Coordinate>
423 <Coordinate>0.00000</Coordinate>
424 <Coordinate>24.00000</Coordinate>
425 </CartesianPoint>
426 <CartesianPoint>
427 <Coordinate>1224.00000</Coordinate>
428 <Coordinate>0.00000</Coordinate>
429 <Coordinate>24.00000</Coordinate>
430 </CartesianPoint>
431 <CartesianPoint>
432 <Coordinate>1224.00000</Coordinate>
433 <Coordinate>0.00000</Coordinate>
434 <Coordinate>96.00000</Coordinate>
435 </CartesianPoint>
436 <CartesianPoint>
437 <Coordinate>1176.00000</Coordinate>
438 <Coordinate>0.00000</Coordinate>
439 <Coordinate>96.00000</Coordinate>
440 </CartesianPoint>
441 </PolyLoop>
442 </PlanarGeometry>
443 </Opening>
444 <Opening id="su44-op3_Opening3" openingType="OperableWindow" windowTypeIdRef="windowType-1">
445 <Name>Opening3</Name>
446 <RectangularGeometry>
447 <CartesianPoint>
448 <Coordinate>336.00000</Coordinate>
449 <Coordinate>24.00000</Coordinate>
450 </CartesianPoint>
451 <Height>72.00000</Height>
452 <Width>48.00000</Width>
453 </RectangularGeometry>
454 <PlanarGeometry>
455 <PolyLoop>
456 <CartesianPoint>
457 <Coordinate>1296.00000</Coordinate>
458 <Coordinate>0.00000</Coordinate>
459 <Coordinate>24.00000</Coordinate>
460 </CartesianPoint>
461 <CartesianPoint>
462 <Coordinate>1344.00000</Coordinate>
463 <Coordinate>0.00000</Coordinate>
464 <Coordinate>24.00000</Coordinate>
465 </CartesianPoint>
466 <CartesianPoint>
467 <Coordinate>1344.00000</Coordinate>
468 <Coordinate>0.00000</Coordinate>
469 <Coordinate>96.00000</Coordinate>
470 </CartesianPoint>
471 <CartesianPoint>
472 <Coordinate>1296.00000</Coordinate>
473 <Coordinate>0.00000</Coordinate>
474 <Coordinate>96.00000</Coordinate>
475 </CartesianPoint>
476 </PolyLoop>
477 </PlanarGeometry>
478 </Opening>
479 </Surface>
480
481
482 ... repeat
483
484 </Campus>
485
486
487
488 <Construction id="construction-1">
489 <Name>Standard</Name>
490 <Description/>
491 </Construction>
492 <Construction id="construction-2">
493 <Name>Standard</Name>
494 <Description/>
495 </Construction>
496 <Construction id="construction-3">
497 <Name>Standard</Name>
498 <Description/>
499 </Construction>
500 <WindowType id="windowType-1">
501 <Name>Standard</Name>
502 <Description/>
503 </WindowType>
504
505
506
507 <Zone id="z1_LabandCorridor">
508 <Name>Lab and Corridor</Name>
509 <Description/>
510 <AirChangesPerHour>0"</AirChangesPerHour>
511 <FlowPerArea unit="CFMPerSquareFoot">0.00000</FlowPerArea>
512 <FlowPerPerson unit="CFM">0.00000</FlowPerPerson>
513 <OAFlowPerArea unit="CFMPerSquareFoot">2.37037</OAFlowPerArea>
514 <OAFlowPerPerson unit="CFM">812.69841</OAFlowPerPerson>
515 <DesignHeatT>72.00000</DesignHeatT>
516 <DesignCoolT>75.00000</DesignCoolT>
517 </Zone>
518 <Zone id="z2_Office">
519 <Name>Office</Name>
520 <Description/>
521 <AirChangesPerHour>1"</AirChangesPerHour>
522 <FlowPerArea unit="CFMPerSquareFoot">0.13333</FlowPerArea>
523 <FlowPerPerson unit="CFM">20.00000</FlowPerPerson>
524 <OAFlowPerArea unit="CFMPerSquareFoot">0.05333</OAFlowPerArea>
525 <OAFlowPerPerson unit="CFM">8.00000</OAFlowPerPerson>
526 <DesignHeatT>72.00000</DesignHeatT>
527 <DesignCoolT>75.00000</DesignCoolT>
528 </Zone>
529 <Zone id="z3_Warehouse">
530 <Name>Warehouse</Name>
531 <Description/>
532 <AirChangesPerHour>5/32"</AirChangesPerHour>
533 <FlowPerArea unit="CFMPerSquareFoot">0.05000</FlowPerArea>
534 <FlowPerPerson unit="CFM">25.71429</FlowPerPerson>
535 <OAFlowPerArea unit="CFMPerSquareFoot">0.00000</OAFlowPerArea>
536 <OAFlowPerPerson unit="CFM">0.00000</OAFlowPerPerson>
537 <DesignHeatT>60.00000</DesignHeatT>
538 <DesignCoolT>80.00000</DesignCoolT>
539 </Zone>
540
541 <DocumentHistory>
542 <ProgramInfo id="adesk-rvt-1">
543 <CompanyName>Autodesk, Inc.</CompanyName>
544 <ProductName>Autodesk Project Vasari CEA</ProductName>
545 <Version>TP2.0 20110514_1800</Version>
546 <Platform>Microsoft Windows XP</Platform>
547 </ProgramInfo>
548 </DocumentHistory>
549
550 <Results xmlns="" id="sp3_LabandCorridor_Lab1" objectIdRef="sp3_LabandCorridor_Lab1" resultsType="CoolingLoad" unit="BtuPerHour">
551 <ObjectId>sp3_LabandCorridor_Lab1</ObjectId>
552 <Value>5534.837890625</Value>
553 <Description>Space Cooling Roof Cond</Description>
554 <CADObjectId>21E3</CADObjectId>
555 </Results>
556
557 ... repeat
558
559 </gbXML>"""