Fix #3054. Edit sheet is now implemented for drawings, schedules, and titleblocks.

This commit is contained in:
Dion Moult
2023-04-23 17:49:13 +10:00
parent 7dc17a3653
commit 5b4449eea0
5 changed files with 47 additions and 48 deletions
@@ -33,7 +33,6 @@ classes = (
operator.AddSheet,
operator.AddTextLiteral,
operator.BuildSchedule,
operator.ChangeSheetTitleBlock,
operator.CleanWireframes,
operator.ContractSheet,
operator.CreateDrawing,
@@ -45,6 +44,7 @@ classes = (
operator.DisableEditingText,
operator.DuplicateDrawing,
operator.EditAssignedProduct,
operator.EditSheet,
operator.EditText,
operator.EditTextPopup,
operator.EnableEditingAssignedProduct,
@@ -53,7 +53,6 @@ classes = (
operator.LoadDrawings,
operator.LoadSchedules,
operator.LoadSheets,
operator.SelectAllDrawings,
operator.OpenDrawing,
operator.OpenSchedule,
operator.OpenSheet,
@@ -64,7 +63,7 @@ classes = (
operator.RemoveSchedule,
operator.RemoveSheet,
operator.RemoveTextLiteral,
operator.RenameSheet,
operator.SelectAllDrawings,
operator.ResizeText,
operator.SaveDrawingStyle,
operator.SelectAssignedProduct,
@@ -1148,38 +1148,6 @@ class CreateSheets(bpy.types.Operator, Operator):
open_with_user_command(context.preferences.addons["blenderbim"].preferences.svg_command, svg)
class ChangeSheetTitleBlock(bpy.types.Operator, Operator):
bl_idname = "bim.change_sheet_title_block"
bl_label = "Change Sheet Title Block"
bl_description = "Change the title block of the active sheet"
bl_options = {"REGISTER"}
def _execute(self, context):
scene = context.scene
props = scene.DocProperties
if not len(props.sheets):
return {"CANCELLED"}
titleblock = scene.DocProperties.titleblock
active_sheet = props.sheets[props.active_sheet_index]
sheet = tool.Ifc.get().by_id(active_sheet.ifc_definition_id)
for reference in tool.Drawing.get_document_references(sheet):
description = tool.Drawing.get_reference_description(reference)
if description == "TITLEBLOCK":
tool.Ifc.run(
"document.edit_reference",
reference=reference,
attributes={"Location": tool.Drawing.get_default_titleblock_path(titleblock)},
)
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = scene.BIMProperties.data_dir
sheet_builder.change_titleblock(sheet, titleblock)
class SelectAllDrawings(bpy.types.Operator):
bl_idname = "bim.select_all_drawings"
bl_label = "Select All Drawings"
@@ -1863,9 +1831,9 @@ class LoadSheets(bpy.types.Operator, Operator):
self.report({"ERROR"}, "Some sheets svg files are missing:\n" + "\n".join(sheets_not_found))
class RenameSheet(bpy.types.Operator, Operator):
bl_idname = "bim.rename_sheet"
bl_label = "Rename Sheet"
class EditSheet(bpy.types.Operator, Operator):
bl_idname = "bim.edit_sheet"
bl_label = "Edit Sheet"
bl_options = {"REGISTER", "UNDO"}
identification: bpy.props.StringProperty()
name: bpy.props.StringProperty()
@@ -1873,20 +1841,49 @@ class RenameSheet(bpy.types.Operator, Operator):
def invoke(self, context, event):
self.props = context.scene.DocProperties
sheet = tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id)
self.identification = sheet.Identification
self.name = sheet.Name
if sheet.is_a("IfcDocumentInformation"):
self.document_type = "SHEET"
self.name = sheet.Name
self.identification = sheet.Identification
elif sheet.is_a("IfcDocumentReference") and sheet.Description == "TITLEBLOCK":
self.document_type = "TITLEBLOCK"
else:
self.document_type = "EMBEDDED"
self.identification = sheet.Identification
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
row = self.layout.row()
row.prop(self, "identification", text="Identification")
row = self.layout.row()
row.prop(self, "name", text="Name")
if self.document_type == "SHEET":
row = self.layout.row()
row.prop(self, "identification", text="Identification")
row = self.layout.row()
row.prop(self, "name", text="Name")
elif self.document_type == "TITLEBLOCK":
row = self.layout.row()
row.prop(context.scene.DocProperties, "titleblock", text="Titleblock")
elif self.document_type == "EMBEDDED":
row = self.layout.row()
row.prop(self, "identification", text="Identification")
def _execute(self, context):
self.props = context.scene.DocProperties
sheet = tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id)
core.rename_sheet(tool.Ifc, tool.Drawing, sheet=sheet, identification=self.identification, name=self.name)
if self.document_type == "SHEET":
core.rename_sheet(tool.Ifc, tool.Drawing, sheet=sheet, identification=self.identification, name=self.name)
elif self.document_type == "EMBEDDED":
core.rename_reference(tool.Ifc, reference=sheet, identification=self.identification)
elif self.document_type == "TITLEBLOCK":
titleblock = self.props.titleblock
reference = sheet
sheet = tool.Drawing.get_reference_document(reference)
tool.Ifc.run(
"document.edit_reference",
reference=reference,
attributes={"Location": tool.Drawing.get_default_titleblock_path(titleblock)},
)
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
sheet_builder.change_titleblock(sheet, titleblock)
tool.Drawing.import_sheets()
@@ -344,7 +344,7 @@ class SheetBuilder:
sheet_dir = os.path.dirname(sheet_path)
os.makedirs(sheet_dir, exist_ok=True)
os.makedirs(os.path.join(sheet_dir, "titleblocks"), exist_ok=True)
os.makedirs(os.path.dirname(titleblock_path), exist_ok=True)
if not os.path.exists(titleblock_path):
shutil.copy(ootb_titleblock_path, titleblock_path)
@@ -302,14 +302,13 @@ class BIM_PT_sheets(Panel):
row = self.layout.row(align=True)
row.prop(self.props, "titleblock", text="")
row.operator("bim.add_sheet", text="", icon="ADD")
row.operator("bim.change_sheet_title_block", text="", icon="MODIFIER_DATA")
row.operator("bim.disable_editing_sheets", text="", icon="CANCEL")
if self.props.sheets and self.props.active_sheet_index < len(self.props.sheets):
active_sheet = self.props.sheets[self.props.active_sheet_index]
row = self.layout.row(align=True)
row.alignment = "RIGHT"
row.operator("bim.rename_sheet", icon="GREASEPENCIL", text="")
row.operator("bim.edit_sheet", icon="GREASEPENCIL", text="")
row.operator("bim.open_sheet", icon="URL", text="")
row.operator("bim.add_drawing_to_sheet", icon="IMAGE_PLANE", text="")
row.operator("bim.add_schedule_to_sheet", icon="PRESET_NEW", text="")
@@ -127,6 +127,10 @@ def rename_sheet(ifc, drawing, sheet=None, identification=None, name=None):
drawing.move_file(old_location, ifc.resolve_uri(new_location))
def rename_reference(ifc, reference=None, identification=None):
ifc.run("document.edit_reference", reference=reference, attributes={"Identification": identification})
def load_schedules(drawing):
drawing.import_schedules()
drawing.enable_editing_schedules()