mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-05 23:41:44 +00:00
#4532 : You can now store clipping planes to a json file and restore them
The file is stored along the ifc file
This commit is contained in:
@@ -25,6 +25,8 @@ classes = (
|
||||
operator.AppendLibraryElement,
|
||||
operator.AppendLibraryElementByQuery,
|
||||
operator.AssignLibraryDeclaration,
|
||||
operator.BIM_OT_load_clipping_planes,
|
||||
operator.BIM_OT_save_clipping_planes,
|
||||
operator.ChangeLibraryElement,
|
||||
operator.CreateClippingPlane,
|
||||
operator.CreateProject,
|
||||
|
||||
@@ -39,6 +39,8 @@ from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.ui import IFCFileSelector
|
||||
from blenderbim.bim import import_ifc
|
||||
from blenderbim.bim import export_ifc
|
||||
from collections import defaultdict
|
||||
import json
|
||||
from math import radians
|
||||
from pathlib import Path
|
||||
from mathutils import Vector, Matrix
|
||||
@@ -1999,3 +2001,61 @@ class FlipClippingPlane(bpy.types.Operator):
|
||||
obj.rotation_euler[0] += radians(180)
|
||||
context.view_layer.update()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
CLIPPING_PLANES_FILE_NAME = "ClippingPlanes.json" # TODO un-hardcode :=
|
||||
|
||||
|
||||
class BIM_OT_save_clipping_planes(bpy.types.Operator):
|
||||
bl_idname = "bim.save_clipping_planes"
|
||||
bl_label = "Save Clipping Planes"
|
||||
bl_description = "Save Clipping Planes to Disk"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if IfcStore.path:
|
||||
return context.scene.BIMProjectProperties.clipping_planes
|
||||
cls.poll_message_set("Please Save The IFC File")
|
||||
|
||||
def execute(self, context):
|
||||
clipping_planes_to_serialize = defaultdict(dict)
|
||||
clipping_planes = context.scene.BIMProjectProperties.clipping_planes
|
||||
for clipping_plane in clipping_planes:
|
||||
obj = clipping_plane.obj
|
||||
name = obj.name
|
||||
clipping_planes_to_serialize[name]["location"] = obj.location[0:3]
|
||||
clipping_planes_to_serialize[name]["rotation"] = obj.rotation_euler[0:3]
|
||||
with open(Path(IfcStore.path).with_name(CLIPPING_PLANES_FILE_NAME), "w") as file:
|
||||
json.dump(clipping_planes_to_serialize, file, indent=4)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class BIM_OT_load_clipping_planes(bpy.types.Operator):
|
||||
bl_idname = "bim.load_clipping_planes"
|
||||
bl_label = "Load Clipping Planes"
|
||||
bl_description = "Load Clipping Planes from Disk"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if filepath := IfcStore.path:
|
||||
if Path(filepath).with_name(CLIPPING_PLANES_FILE_NAME).exists():
|
||||
return True
|
||||
else:
|
||||
cls.poll_message_set(f"No Clipping Planes File in Folder {filepath}")
|
||||
else:
|
||||
cls.poll_message_set("Please Save The IFC File")
|
||||
|
||||
def execute(self, context):
|
||||
bpy.data.batch_remove(context.scene.BIMProjectProperties.clipping_planes_objs)
|
||||
context.scene.BIMProjectProperties.clipping_planes.clear()
|
||||
with open(Path(IfcStore.path).with_name(CLIPPING_PLANES_FILE_NAME), "r") as file:
|
||||
clipping_planes_dict = json.load(file)
|
||||
for name, values in clipping_planes_dict.items():
|
||||
bpy.ops.bim.create_clipping_plane()
|
||||
obj = context.scene.BIMProjectProperties.clipping_planes_objs[-1]
|
||||
obj.name = name
|
||||
obj.location = values["location"]
|
||||
obj.rotation_euler = values["rotation"]
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -131,6 +131,8 @@ class BIM_PT_section_with_cappings(Panel):
|
||||
box = layout.box()
|
||||
header = box.row(align=True)
|
||||
header.label(text="Clipping Planes")
|
||||
header.operator("bim.save_clipping_planes", text="", icon="EXPORT")
|
||||
header.operator("bim.load_clipping_planes", text="", icon="IMPORT")
|
||||
header.operator("bim.create_clipping_plane", text="", icon="ADD")
|
||||
|
||||
box.template_list(
|
||||
@@ -150,7 +152,7 @@ class BIM_PT_section_with_cappings(Panel):
|
||||
|
||||
class BIM_UL_clipping_plane(bpy.types.UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
if item:
|
||||
if item and item.obj:
|
||||
obj = item.obj
|
||||
row = layout.row(align=True)
|
||||
row.prop(obj, "name", text="", emboss=False)
|
||||
|
||||
Reference in New Issue
Block a user