mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
First attempt at ripping out agnostic code into ifcopenshell.api namespace. See #1399.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"context": None,
|
||||
"subcontext": None,
|
||||
"target_view": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
parent = [
|
||||
c
|
||||
for c in self.file.by_type("IfcGeometricRepresentationContext")
|
||||
if c.ContextType == self.settings["context"]
|
||||
]
|
||||
if not parent:
|
||||
self.create_origin()
|
||||
if self.settings["context"] == "Plan":
|
||||
context = self.file.createIfcGeometricRepresentationContext(None, "Plan", 2, 1.0e-05, self.origin)
|
||||
else:
|
||||
context = self.file.createIfcGeometricRepresentationContext(None, "Model", 3, 1.0e-05, self.origin)
|
||||
project = self.file.by_type("IfcProject")[0]
|
||||
if project.RepresentationContexts:
|
||||
contexts = list(project.RepresentationContexts)
|
||||
else:
|
||||
contexts = []
|
||||
contexts.append(context)
|
||||
project.RepresentationContexts = contexts
|
||||
return context
|
||||
parent = parent[0]
|
||||
return self.file.create_entity("IfcGeometricRepresentationSubContext", **{
|
||||
"ContextIdentifier": self.settings["subcontext"],
|
||||
"ContextType": self.settings["context"],
|
||||
"ParentContext": parent,
|
||||
"TargetView": self.settings["target_view"],
|
||||
})
|
||||
|
||||
def create_origin(self):
|
||||
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)),
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
class Data:
|
||||
is_loaded = False
|
||||
contexts = {}
|
||||
|
||||
@classmethod
|
||||
def purge(cls):
|
||||
cls.is_loaded = False
|
||||
cls.contexts = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls, file):
|
||||
if not file:
|
||||
return
|
||||
cls.contexts = {}
|
||||
for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
|
||||
subcontexts = {}
|
||||
for subcontext in context.HasSubContexts:
|
||||
subcontexts[int(subcontext.id())] = {
|
||||
"ContextType": subcontext.ContextType,
|
||||
"ContextIdentifier": subcontext.ContextIdentifier,
|
||||
"TargetView": subcontext.TargetView,
|
||||
}
|
||||
cls.contexts[int(context.id())] = {
|
||||
"ContextType": context.ContextType,
|
||||
"HasSubContexts": subcontexts
|
||||
}
|
||||
cls.is_loaded = True
|
||||
@@ -0,0 +1,12 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"context": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
# TODO: this is a light remove only
|
||||
for subcontext in self.settings["context"].HasSubContexts:
|
||||
self.file.remove(subcontext)
|
||||
self.file.remove(self.settings["context"])
|
||||
Reference in New Issue
Block a user