2022-01-19 12:18:33 +11:00
|
|
|
# IfcOpenShell - IFC toolkit and geometry engine
|
|
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# This file is part of IfcOpenShell.
|
|
|
|
|
#
|
|
|
|
|
# IfcOpenShell is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# IfcOpenShell is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 20:28:52 +11:00
|
|
|
class Usecase:
|
2021-03-27 19:14:32 +11:00
|
|
|
def __init__(self, file, **settings):
|
2021-01-02 20:28:52 +11:00
|
|
|
self.file = file
|
|
|
|
|
self.settings = {
|
2021-09-30 18:28:50 +10:00
|
|
|
"context_type": None,
|
|
|
|
|
"parent": None,
|
|
|
|
|
"context_identifier": None,
|
2021-01-02 20:28:52 +11:00
|
|
|
"target_view": None,
|
|
|
|
|
}
|
|
|
|
|
for key, value in settings.items():
|
|
|
|
|
self.settings[key] = value
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
2021-09-30 18:28:50 +10:00
|
|
|
if not self.settings["parent"]:
|
|
|
|
|
if self.settings["context_type"] == "Plan":
|
|
|
|
|
self.create_2d_origin()
|
2021-01-05 21:15:52 +11:00
|
|
|
context = self.file.createIfcGeometricRepresentationContext(None, "Plan", 2, 1.0e-05, self.origin)
|
|
|
|
|
else:
|
2021-09-30 18:28:50 +10:00
|
|
|
self.create_3d_origin()
|
|
|
|
|
context = self.file.createIfcGeometricRepresentationContext(
|
|
|
|
|
None, self.settings["context_type"], 3, 1.0e-05, self.origin
|
|
|
|
|
)
|
2021-04-11 21:56:45 +10:00
|
|
|
|
2021-09-30 18:28:50 +10:00
|
|
|
project = self.file.by_type("IfcProject")[0]
|
2021-04-11 21:56:45 +10:00
|
|
|
|
2021-01-05 21:15:52 +11:00
|
|
|
if project.RepresentationContexts:
|
|
|
|
|
contexts = list(project.RepresentationContexts)
|
|
|
|
|
else:
|
|
|
|
|
contexts = []
|
|
|
|
|
contexts.append(context)
|
|
|
|
|
project.RepresentationContexts = contexts
|
|
|
|
|
return context
|
2021-09-09 21:27:23 +10:00
|
|
|
return self.file.create_entity(
|
|
|
|
|
"IfcGeometricRepresentationSubContext",
|
|
|
|
|
**{
|
2021-09-30 18:28:50 +10:00
|
|
|
"ContextIdentifier": self.settings["context_identifier"],
|
|
|
|
|
"ContextType": self.settings["context_type"],
|
|
|
|
|
"ParentContext": self.settings["parent"],
|
2021-09-09 21:27:23 +10:00
|
|
|
"TargetView": self.settings["target_view"],
|
|
|
|
|
}
|
|
|
|
|
)
|
2021-01-02 20:28:52 +11:00
|
|
|
|
2021-09-30 18:28:50 +10:00
|
|
|
def create_3d_origin(self):
|
2021-01-02 20:28:52 +11:00
|
|
|
self.origin = self.file.createIfcAxis2Placement3D(
|
|
|
|
|
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
|
|
|
|
|
self.file.createIfcDirection((0.0, 0.0, 1.0)),
|
|
|
|
|
self.file.createIfcDirection((1.0, 0.0, 0.0)),
|
|
|
|
|
)
|
2021-09-30 18:28:50 +10:00
|
|
|
|
|
|
|
|
def create_2d_origin(self):
|
|
|
|
|
self.origin = self.file.createIfcAxis2Placement2D(
|
|
|
|
|
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
|
|
|
|
|
self.file.createIfcDirection((1.0, 0.0, 0.0)),
|
|
|
|
|
)
|