mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-02 13:04:49 +00:00
Various tweaks and fixes (#1683)
* Use operator's poll method to ensure correct execution * Add utilities to get active collection item * Minor fixes zombie code list comprehensions typos cleanup tooltips, descriptions ensure file extension in folder operator use custom UI List instead of generic one ensure active object stays the same after operator execution use passed context instead of bpy * Jump through hoops to not display empty dynamic enums * Group mesh calculation methods in helper module If not using bmesh, the polygon selection status is updated only when getting out of Edit mode. Using bmesh we can get the values in realtime * Remove unused arg name in dosctring
This commit is contained in:
@@ -60,6 +60,10 @@ class AddDrawing(bpy.types.Operator):
|
||||
bl_label = "Add Drawing"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return IfcStore.get_file()
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
@@ -502,12 +506,14 @@ class AddAnnotation(bpy.types.Operator):
|
||||
obj_name: bpy.props.StringProperty()
|
||||
data_type: bpy.props.StringProperty()
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return IfcStore.get_file() and context.scene.camera
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
if not context.scene.camera:
|
||||
return {"FINISHED"}
|
||||
subcontext = ifcopenshell.util.representation.get_context(
|
||||
IfcStore.get_file(), "Plan", "Annotation", context.scene.camera.data.BIMCameraProperties.target_view
|
||||
)
|
||||
@@ -563,7 +569,7 @@ class OpenSheet(bpy.types.Operator):
|
||||
open_with_user_command(
|
||||
context.preferences.addons["blenderbim"].preferences.svg_command,
|
||||
os.path.join(
|
||||
context.scene.BIMProperties.data_dir, "sheets", props.sheets[props.active_sheet_index].name + ".svg"
|
||||
context.scene.BIMProperties.data_dir, "sheets", props.active_sheet.name + ".svg"
|
||||
),
|
||||
)
|
||||
return {"FINISHED"}
|
||||
@@ -581,9 +587,9 @@ class AddDrawingToSheet(bpy.types.Operator):
|
||||
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
|
||||
try:
|
||||
sheet_builder.add_drawing(
|
||||
props.drawings[props.active_drawing_index].name, props.sheets[props.active_sheet_index].name
|
||||
props.drawings.active_drawing.name, props.active_sheet.name
|
||||
)
|
||||
except:
|
||||
except FileNotFoundError:
|
||||
self.report({"ERROR"}, "Drawings need to be created before being added to a sheet")
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -596,7 +602,7 @@ class CreateSheets(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
scene = context.scene
|
||||
props = scene.DocProperties
|
||||
name = props.sheets[props.active_sheet_index].name
|
||||
name = props.active_sheet.name
|
||||
sheet_builder = sheeter.SheetBuilder()
|
||||
sheet_builder.data_dir = scene.BIMProperties.data_dir
|
||||
sheet_builder.build(name)
|
||||
@@ -650,18 +656,23 @@ class OpenView(bpy.types.Operator):
|
||||
|
||||
|
||||
class OpenViewCamera(bpy.types.Operator):
|
||||
"""Select this drawing's camera object and expand its drawing properties"""
|
||||
bl_idname = "bim.open_view_camera"
|
||||
bl_label = "Open View Camera"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
view_name: bpy.props.StringProperty()
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.mode == "OBJECT"
|
||||
|
||||
def execute(self, context):
|
||||
new_drawing_index = context.scene.DocProperties.drawings.find(self.view_name)
|
||||
context.scene.DocProperties.active_drawing_index = new_drawing_index
|
||||
drawing = context.scene.DocProperties.drawings[new_drawing_index]
|
||||
context.view_layer.objects.active = drawing.camera
|
||||
doc_props = context.scene.DocProperties
|
||||
doc_props.active_drawing_index = doc_props.drawings.find(self.view_name)
|
||||
drawing = doc_props.active_drawing
|
||||
bpy.ops.object.select_all(action="DESELECT")
|
||||
drawing.camera.select_set(True)
|
||||
context.view_layer.objects.active = drawing.camera
|
||||
for area in context.screen.areas:
|
||||
if area.ui_type == "PROPERTIES":
|
||||
for space in area.spaces:
|
||||
@@ -712,6 +723,7 @@ class SelectDocIfcFile(bpy.types.Operator):
|
||||
bl_idname = "bim.select_doc_ifc_file"
|
||||
bl_label = "Select Documentation IFC File"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||
index: bpy.props.IntProperty()
|
||||
|
||||
@@ -1059,7 +1071,7 @@ class SelectScheduleFile(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.DocProperties
|
||||
props.schedules[props.active_schedule_index].file = self.filepath
|
||||
props.active_schedule.file = self.filepath
|
||||
return {"FINISHED"}
|
||||
|
||||
def invoke(self, context, event):
|
||||
@@ -1071,9 +1083,13 @@ class BuildSchedule(bpy.types.Operator):
|
||||
bl_idname = "bim.build_schedule"
|
||||
bl_label = "Build Schedule"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.scene.DocProperties.active_schedule.file
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.DocProperties
|
||||
schedule = props.schedules[props.active_schedule_index]
|
||||
schedule = props.active_schedule
|
||||
schedule_creator = scheduler.Scheduler()
|
||||
outfile = os.path.join(context.scene.BIMProperties.data_dir, "schedules", schedule.name + ".svg")
|
||||
schedule_creator.schedule(schedule.file, outfile)
|
||||
@@ -1092,7 +1108,7 @@ class AddScheduleToSheet(bpy.types.Operator):
|
||||
sheet_builder = sheeter.SheetBuilder()
|
||||
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
|
||||
sheet_builder.add_schedule(
|
||||
props.schedules[props.active_schedule_index].name, props.sheets[props.active_sheet_index].name
|
||||
props.active_schedule.name, props.active_sheet.name
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -1143,13 +1159,12 @@ class CleanWireframes(bpy.types.Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
objects = context.scene.objects
|
||||
if context.selected_objects:
|
||||
objects = context.selected_objects
|
||||
for obj in objects:
|
||||
if not isinstance(obj.data, bpy.types.Mesh):
|
||||
continue
|
||||
if "EDGE_SPLIT" not in [m.type for m in obj.modifiers]:
|
||||
else:
|
||||
objects = context.scene.objects
|
||||
for obj in (o for o in objects if o.type == "MESH"):
|
||||
if "EDGE_SPLIT" not in (m.type for m in obj.modifiers):
|
||||
obj.modifiers.new("EdgeSplit", "EDGE_SPLIT")
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -1159,11 +1174,13 @@ class CopyGrid(bpy.types.Operator):
|
||||
bl_label = "Add Grid"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return helper.get_active_drawing(context.scene)[0] is not None
|
||||
|
||||
def execute(self, context):
|
||||
proj_coll = helper.get_project_collection(context.scene)
|
||||
view_coll, camera = helper.get_active_drawing(context.scene)
|
||||
if view_coll is None:
|
||||
return {"CANCELLED"}
|
||||
is_ortho = camera.data.type == "ORTHO"
|
||||
bounds = helper.ortho_view_frame(camera.data) if is_ortho else None
|
||||
clipping = is_ortho and camera.data.BIMCameraProperties.target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW")
|
||||
@@ -1240,13 +1257,15 @@ class AddSectionsAnnotations(bpy.types.Operator):
|
||||
bl_label = "Add Sections"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
camera = helper.get_active_drawing(context.scene)[1]
|
||||
return camera and camera.data.type == "ORTHO"
|
||||
|
||||
def execute(self, context):
|
||||
scene = context.scene
|
||||
view_coll, camera = helper.get_active_drawing(scene)
|
||||
is_ortho = camera.data.type == "ORTHO"
|
||||
if not is_ortho:
|
||||
return {"CANCELLED"}
|
||||
bounds = helper.ortho_view_frame(camera.data) if is_ortho else None
|
||||
bounds = helper.ortho_view_frame(camera.data)
|
||||
|
||||
drawings = [
|
||||
d
|
||||
|
||||
Reference in New Issue
Block a user