mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Separate serialize into "save" and "save as" with file selection
This commit is contained in:
@@ -22,7 +22,7 @@ import blenderbim.tool as tool
|
||||
import blenderbim.core.brick as core
|
||||
import blenderbim.bim.handler
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
|
||||
from blenderbim.tool.brick import BrickStore
|
||||
|
||||
class Operator:
|
||||
def execute(self, context):
|
||||
@@ -207,6 +207,26 @@ class RedoBrick(bpy.types.Operator, Operator):
|
||||
class SerializeBrick(bpy.types.Operator, Operator):
|
||||
bl_idname = "bim.serialize_brick"
|
||||
bl_label = "Serialize Brick"
|
||||
filter_glob: bpy.props.StringProperty(default="*.ttl", options={"HIDDEN"})
|
||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||
should_save_as: bpy.props.BoolProperty(name="Should Save As", default=False, options={"HIDDEN"})
|
||||
|
||||
def invoke(self, context, event):
|
||||
if self.should_save_as or not BrickStore.path:
|
||||
WindowManager = context.window_manager
|
||||
WindowManager.fileselect_add(self)
|
||||
return {"RUNNING_MODAL"}
|
||||
else:
|
||||
return self.execute(context)
|
||||
|
||||
def _execute(self, context):
|
||||
core.serialize_brick(tool.Brick)
|
||||
if self.should_save_as or not BrickStore.path:
|
||||
BrickStore.path = self.filepath
|
||||
core.serialize_brick(tool.Brick)
|
||||
return {"FINISHED"}
|
||||
|
||||
@classmethod
|
||||
def description(cls, context, properties):
|
||||
if properties.should_save_as:
|
||||
return "Save Brick project to a selected file"
|
||||
return "Save the Brick project"
|
||||
@@ -20,7 +20,7 @@ import blenderbim.tool as tool
|
||||
from bpy.types import Panel, UIList
|
||||
from blenderbim.bim.helper import prop_with_search
|
||||
from blenderbim.bim.module.brick.data import BrickschemaData, BrickschemaReferencesData
|
||||
|
||||
from blenderbim.tool.brick import BrickStore
|
||||
|
||||
class BIM_PT_brickschema(Panel):
|
||||
bl_label = "Brickschema Project"
|
||||
@@ -41,6 +41,10 @@ class BIM_PT_brickschema(Panel):
|
||||
row.operator("bim.load_brick_project", text="Load Project")
|
||||
return
|
||||
|
||||
if BrickStore.path:
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=BrickStore.path, icon='FILEBROWSER')
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
if len(self.props.brick_breadcrumbs):
|
||||
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
|
||||
@@ -63,7 +67,10 @@ class BIM_PT_brickschema(Panel):
|
||||
row.operator("bim.redo_brick", icon="LOOP_FORWARDS")
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.serialize_brick")
|
||||
op = row.operator("bim.serialize_brick", icon="EXPORT", text="Save")
|
||||
op.should_save_as = False
|
||||
op = row.operator("bim.serialize_brick", icon="FILE_TICK", text="Save As")
|
||||
op.should_save_as = True
|
||||
|
||||
self.layout.template_list("BIM_UL_bricks", "", self.props, "bricks", self.props, "active_brick_index")
|
||||
|
||||
|
||||
@@ -118,5 +118,5 @@ def redo_brick(brick):
|
||||
brick.redo_brick()
|
||||
brick.run_refresh_brick_viewer()
|
||||
|
||||
def serialize_brick(brick, file_name="BlenderBIMSerializeTest.ttl"):
|
||||
brick.serialize_brick(file_name)
|
||||
def serialize_brick(brick):
|
||||
brick.serialize_brick()
|
||||
@@ -332,12 +332,10 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
BrickStore.graph.redo()
|
||||
|
||||
@classmethod
|
||||
def serialize_brick(cls, file_name):
|
||||
#temporary file path, could either be user selected for "save as" or use the BrickStore.path for simply "save"
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
dest = os.path.join(cwd, "..", "bim", "schema", file_name)
|
||||
BrickStore.get_project().serialize(destination=dest, format="turtle")
|
||||
|
||||
def serialize_brick(cls):
|
||||
print(BrickStore.path)
|
||||
BrickStore.get_project().serialize(destination=BrickStore.path, format="turtle")
|
||||
|
||||
class BrickStore:
|
||||
schema = None # this is now a os path
|
||||
path = None # file path if the project was loaded in
|
||||
|
||||
Reference in New Issue
Block a user