|
| 1 | +############################################################################### |
| 2 | +# # |
| 3 | +# This file is part of IfcOpenShell. # |
| 4 | +# # |
| 5 | +# IfcOpenShell is free software: you can redistribute it and/or modify # |
| 6 | +# it under the terms of the Lesser GNU General Public License as published by # |
| 7 | +# the Free Software Foundation, either version 3.0 of the License, or # |
| 8 | +# (at your option) any later version. # |
| 9 | +# # |
| 10 | +# IfcOpenShell is distributed in the hope that it will be useful, # |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 13 | +# Lesser GNU General Public License for more details. # |
| 14 | +# # |
| 15 | +# You should have received a copy of the Lesser GNU General Public License # |
| 16 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
| 17 | +# # |
| 18 | +############################################################################### |
| 19 | + |
| 20 | +import time |
| 21 | +import uuid |
| 22 | + |
| 23 | +from .file import file |
| 24 | +from .guid import compress |
| 25 | +from . import main |
| 26 | + |
| 27 | +# A quick way to setup an 'empty' IFC file, taken from: |
| 28 | +# http://academy.ifcopenshell.org/creating-a-simple-wall-with-property-set-and-quantity-information/ |
| 29 | +TEMPLATE = """ISO-10303-21; |
| 30 | +HEADER; |
| 31 | +FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1'); |
| 32 | +FILE_NAME('%(filename)s','%(timestring)s',('%(creator)s'),('%(organization)s'),'%(application)s','%(application)s',''); |
| 33 | +FILE_SCHEMA(('%(schema_identifier)s')); |
| 34 | +ENDSEC; |
| 35 | +DATA; |
| 36 | +#1=IFCPERSON($,$,'%(creator)s',$,$,$,$,$); |
| 37 | +#2=IFCORGANIZATION($,'%(organization)s',$,$,$); |
| 38 | +#3=IFCPERSONANDORGANIZATION(#1,#2,$); |
| 39 | +#4=IFCAPPLICATION(#2,'%(application_version)s','%(application)s',''); |
| 40 | +#5=IFCOWNERHISTORY(#3,#4,$,.ADDED.,$,#3,#4,%(timestamp)s); |
| 41 | +#6=IFCDIRECTION((1.,0.,0.)); |
| 42 | +#7=IFCDIRECTION((0.,0.,1.)); |
| 43 | +#8=IFCCARTESIANPOINT((0.,0.,0.)); |
| 44 | +#9=IFCAXIS2PLACEMENT3D(#8,#7,#6); |
| 45 | +#10=IFCDIRECTION((0.,1.,0.)); |
| 46 | +#11=IFCGEOMETRICREPRESENTATIONCONTEXT($,'Model',3,1.E-05,#9,#10); |
| 47 | +#12=IFCDIMENSIONALEXPONENTS(0,0,0,0,0,0,0); |
| 48 | +#13=IFCSIUNIT(*,.LENGTHUNIT.,$,.METRE.); |
| 49 | +#14=IFCSIUNIT(*,.AREAUNIT.,$,.SQUARE_METRE.); |
| 50 | +#15=IFCSIUNIT(*,.VOLUMEUNIT.,$,.CUBIC_METRE.); |
| 51 | +#16=IFCSIUNIT(*,.PLANEANGLEUNIT.,$,.RADIAN.); |
| 52 | +#17=IFCMEASUREWITHUNIT(IFCPLANEANGLEMEASURE(0.017453292519943295),#16); |
| 53 | +#18=IFCCONVERSIONBASEDUNIT(#12,.PLANEANGLEUNIT.,'DEGREE',#17); |
| 54 | +#19=IFCUNITASSIGNMENT((#13,#14,#15,#18)); |
| 55 | +#20=IFCPROJECT('%(project_globalid)s',#5,'%(project_name)s',$,$,$,$,(#11),#19); |
| 56 | +ENDSEC; |
| 57 | +END-ISO-10303-21; |
| 58 | +""" |
| 59 | + |
| 60 | +DEFAULTS = { |
| 61 | + "application": lambda d: 'IfcOpenShell-%s' % main.version, |
| 62 | + "application_version": lambda d: main.version, |
| 63 | + "project_globalid": lambda d: compress(uuid.uuid4().hex), |
| 64 | + "schema_identifier": lambda d: main.schema_identifier, |
| 65 | + "timestamp": lambda d: time.time(), |
| 66 | + "timestring": lambda d: time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(d.get('timestamp') or time.time())) |
| 67 | +} |
| 68 | + |
| 69 | +def create(filename=None, timestring=None, organization=None, creator=None,\ |
| 70 | + schema_identifier=None, application_version=None, timestamp=None,\ |
| 71 | + application=None, project_globalid=None, project_name=None): |
| 72 | + |
| 73 | + d = dict(locals()) |
| 74 | + def _(): |
| 75 | + for var, value in d.items(): |
| 76 | + if value is None: |
| 77 | + yield var, DEFAULTS.get(var, lambda *args: '')(d) |
| 78 | + d.update(dict(_())) |
| 79 | + |
| 80 | + return file.from_string(TEMPLATE % d) |
0 commit comments