From e5bfd3f67c0e32070b2e9b7d92fa92ded7038cb0 Mon Sep 17 00:00:00 2001 From: ThaHobbyist Date: Fri, 17 Jan 2025 17:52:31 +0530 Subject: Implemented operators for mergePatchPairs in blockMesh --- __init__.py | 17 +++++-- lib/global_properties.py | 6 ++- models/blockmesh/boundary_control_operators.py | 64 ++++++++++++++++++++++++++ models/run_panel_operators.py | 16 +++++-- views/mainpanel/view.py | 44 +++++++++++------- views/schemas/UIList_schemas.py | 15 +++++- 6 files changed, 135 insertions(+), 27 deletions(-) diff --git a/__init__.py b/__init__.py index 09bc8d0..9716fab 100755 --- a/__init__.py +++ b/__init__.py @@ -129,6 +129,7 @@ classes = ( CUSTOM_UL_faces, CUSTOM_UL_edges_Main, CUSTOM_UL_edges_Sub, + CUSTOM_UL_face_merge, VNT_OT_faceactions, VNT_OT_set_face_name, VNT_OT_set_type_face, @@ -156,6 +157,8 @@ classes = ( VNT_OT_vertex_data_control, VNT_OT_edge_data_control, VNT_OT_boundary_data_control, + VNT_OT_merge_faces, + VNT_OT_merge_faces_delete, # VNT_OT_generate_edge, # VNT_OT_edit_edge, # VNT_OT_destroy_edge, @@ -344,16 +347,22 @@ def register(): bpy.types.Scene.simblk = CollectionProperty(type=VNT_global_properties_collection) bpy.types.Scene.simblk_index = IntProperty() - bpy.types.Scene.bcustom = CollectionProperty(type=VNT_global_properties_collection) + bpy.types.Scene.bcustom = CollectionProperty(type=VNT_global_properties_collection) # for blocks bpy.types.Scene.bcustom_index = IntProperty() - bpy.types.Scene.vcustom = CollectionProperty(type=VNT_global_properties_collection) + bpy.types.Scene.vcustom = CollectionProperty(type=VNT_global_properties_collection) # for vertices bpy.types.Scene.vcustom_index = IntProperty() - bpy.types.Scene.fcustom = CollectionProperty(type=VNT_global_properties_collection) + bpy.types.Scene.fcustom = CollectionProperty(type=VNT_global_properties_collection) # for faces bpy.types.Scene.fcustom_index = IntProperty() - bpy.types.Scene.ecustom = CollectionProperty(type=VNT_global_properties_collection_edge_verts) + bpy.types.Scene.faceList_master = EnumProperty("Face List", items=list_current_faces) + bpy.types.Scene.faceList_slave = EnumProperty("Face List", items=list_current_faces) + + bpy.types.Scene.fmcustom = CollectionProperty(type=VNT_global_properties_collection) # for face merging + bpy.types.Scene.fmcustom_index = IntProperty() + + bpy.types.Scene.ecustom = CollectionProperty(type=VNT_global_properties_collection_edge_verts) # for edges bpy.types.Scene.ecustom_index = IntProperty() bpy.types.Scene.vert_index = IntProperty(name="Vertex Index", default=0) diff --git a/lib/global_properties.py b/lib/global_properties.py index 2c3fa9e..6101a41 100755 --- a/lib/global_properties.py +++ b/lib/global_properties.py @@ -10,6 +10,8 @@ import bpy from bpy.types import PropertyGroup +from venturial.models.blockmesh.boundary_control_operators import list_current_faces + class CUSTOM_LocProps(bpy.types.PropertyGroup): vert_loc: FloatVectorProperty(name='verts') @@ -69,7 +71,9 @@ class VNT_global_properties_collection(PropertyGroup): min = 0.0, max = 1.0, default = (1.0,1.0,1.0,1.0)) - + + master_face : EnumProperty("Master Face", items=list_current_faces) + slave_face : EnumProperty("Slave Face", items=list_current_faces) b_name: StringProperty() setcellx: IntProperty() diff --git a/models/blockmesh/boundary_control_operators.py b/models/blockmesh/boundary_control_operators.py index 1d4c07e..668e957 100755 --- a/models/blockmesh/boundary_control_operators.py +++ b/models/blockmesh/boundary_control_operators.py @@ -410,3 +410,67 @@ class VNT_OT_clearfaces(Operator): else: self.report({'INFO'}, "Nothing to remove") return{'FINISHED'} + +# Operators for mergepatchpairs +class VNT_OT_merge_faces(Operator): + bl_idname = "vnt.merge_faces" + bl_label = "Merge Faces" + bl_description = "Merge selected Faces" + bl_options = {'REGISTER', 'UNDO'} + + def draw(self, context): + layout = self.layout + cs = context.scene + + r1 = layout.row(align=True) + r1.label(text="Master Face:") + r1.prop(cs, "faceList_master") + + r2 = layout.row(align=True) + r2.label(text="Slave:") + r2.prop(cs, "faceList_slave") + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self, width=300) + + def execute(self, context): + cs = context.scene + + if cs.faceList_master == cs.faceList_slave: + self.report({'ERROR'}, "Master and Slave faces cannot be same") + return {'CANCELLED'} + else: + item = cs.fmcustom.add() + item.master_face = cs.faceList_master + item.slave_face = cs.faceList_slave + + return {'FINISHED'} + +class VNT_OT_merge_faces_delete(Operator): + bl_idname = "vnt.merge_faces_delete" + bl_label = "Separate Faces" + bl_description = "Separate selected Face pairs" + bl_options = {'REGISTER', 'UNDO'} + + @classmethod + def poll(cls, context): + return bool(context.scene.fmcustom) + + def invoke(self, context, event): + return context.window_manager.invoke_confirm(self, event) + + def execute(self, context): + if bool(context.scene.fcustom): + context.scene.fmcustom.clear() + self.report({'INFO'}, "All items removed") + else: + self.report({'INFO'}, "Nothing to remove") + return{'FINISHED'} + + + +def list_current_faces(self, context): + items = [] + for i, f in enumerate(context.scene.fcustom): + items.append((str(f.face_des), f.face_des, f"{f.face_des}, {f.name}")) + return items \ No newline at end of file diff --git a/models/run_panel_operators.py b/models/run_panel_operators.py index 8cce7e8..478888d 100755 --- a/models/run_panel_operators.py +++ b/models/run_panel_operators.py @@ -122,6 +122,9 @@ def write_dict(m, out_fp): #todo blockdict.append("mergePatchPairs") blockdict.append("(") + mergePatchPairs=data['mergePatchPairs'] + for mpp in mergePatchPairs: + blockdict.append(f"({mpp[0]} {mpp[1]})") blockdict.append(");") #-------mergePatchPairs end--------- @@ -211,10 +214,11 @@ class VNT_OT_fill_dict_file(Operator): bmdict['boundary'].append([i.face_des, i.face_type, face_strtolist(i.name)]) # Add Edges(arc, polyLine, spline, BSpline) to Dictionary + # cp_edge_list = [scn.acustom, scn.pcustom, scn.scustom, scn.bscustom] # cp_edge_list = [scn.ecustom] - # edge_type = ["arc", "polyLine", "spline", "BSpline"] - + # edge_type = ["arc", "polyLine", "spline", "BSpline"] + for ix in range(0, len(scn.ecustom)): # change the way edges are stored ''' Old code @@ -243,9 +247,6 @@ class VNT_OT_fill_dict_file(Operator): vert_index = [] edge = scn.ecustom[ix] - # Check type from edge.type - # Get indices for each vert in edge.vc - # Add the vertices into a list from edge.vert_collection edge_type = { "ARC": "arc", "PLY": "polyLine", @@ -261,6 +262,11 @@ class VNT_OT_fill_dict_file(Operator): e_verts = [list(v.vert_loc) for v in edge.vert_collection] bmdict["edges"].append([e_type, vert_index, e_verts]) + # Add MergePatchPairs to Dictionary + for i in scn.fmcustom: + pair = (i.master_face, i.slave_face) + bmdict['mergePatchPairs'].append(pair) + m = json.dumps(bmdict, sort_keys=True, indent=2) text_obj.from_string(m) diff --git a/views/mainpanel/view.py b/views/mainpanel/view.py index e45aede..494d48b 100755 --- a/views/mainpanel/view.py +++ b/views/mainpanel/view.py @@ -262,17 +262,17 @@ class layout_controller: def VNT_ST_boundary(self, layout, context): cs = context.scene - layout=layout.box() + box_1=layout.box() data = cs.face_name # r0 = layout.row() # r0.label(text="Boundary Controls") - r0 = layout.row() - r0.prop(cs, "face_sel_mode", toggle=True) + b1r0 = box_1.row() + b1r0.prop(cs, "face_sel_mode", toggle=True) - r1 = layout.row() - r1.operator(VNT_OT_New_Boundary.bl_idname, text="New Boundary") + b1r1 = box_1.row() + b1r1.operator(VNT_OT_New_Boundary.bl_idname, text="New Boundary") # r1 = layout.row() @@ -296,18 +296,30 @@ class layout_controller: # r4.active_default = False # new line - r2 = layout.row().grid_flow(row_major=True, columns=4, even_columns=False, align = True) - - r2.operator(VNT_OT_selectfaces.bl_idname, text="", icon="STICKY_UVS_LOC").select_all = True - r2.operator(VNT_OT_selectfaces.bl_idname, text="", icon="STICKY_UVS_DISABLE").select_all = False - r2.operator(VNT_OT_faceactions.bl_idname, text="", icon="REMOVE").action = "REMOVE" - r2.alert = True - r2.operator(VNT_OT_clearfaces.bl_idname, text="", icon="TRASH") - r2.alert = True + b1r2 = box_1.row().grid_flow(row_major=True, columns=4, even_columns=False, align = True) + + b1r2.operator(VNT_OT_selectfaces.bl_idname, text="", icon="STICKY_UVS_LOC").select_all = True + b1r2.operator(VNT_OT_selectfaces.bl_idname, text="", icon="STICKY_UVS_DISABLE").select_all = False + b1r2.operator(VNT_OT_faceactions.bl_idname, text="", icon="REMOVE").action = "REMOVE" + b1r2.alert = True + b1r2.operator(VNT_OT_clearfaces.bl_idname, text="", icon="TRASH") + b1r2.alert = True - r3 = layout.row() - r3.scale_y = 1.4 - r3.template_list("CUSTOM_UL_faces", "", cs, "fcustom", cs, "fcustom_index", rows=2) + b1r3 = box_1.row() + b1r3.scale_y = 1.4 + b1r3.template_list("CUSTOM_UL_faces", "", cs, "fcustom", cs, "fcustom_index", rows=2) + + box_2 = layout.box() + b2r0 = box_2.row() + b2r0.label(text="Face Merging") + + b2r1 = box_2.row() + b2r1.operator(VNT_OT_merge_faces.bl_idname, text="Merge Faces") + b2r1.alert = True + b2r1.operator(VNT_OT_merge_faces_delete.bl_idname, text="", icon="TRASH") + + b2r2 = box_2.row() + b2r2.template_list("CUSTOM_UL_face_merge", "", cs, "fmcustom", cs, "fmcustom_index", rows=2) def VNT_ST_step_controls(self, layout, context): cs = context.scene diff --git a/views/schemas/UIList_schemas.py b/views/schemas/UIList_schemas.py index abb1657..14b6c8e 100755 --- a/views/schemas/UIList_schemas.py +++ b/views/schemas/UIList_schemas.py @@ -166,6 +166,19 @@ class CUSTOM_UL_faces(UIList): def invoke(self, context, event): pass +class CUSTOM_UL_face_merge(UIList): + def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): + box = layout.box() + col = box.column() + row = col.split() + row.prop(item, "master_face", text="Master Face", emboss=True) + row = row.split() + row.prop(item, "slave_face", text="Slave Face", emboss=True) + # row.prop(item, "enabled", text="", index=index) + + def invoke(self, context, event): + pass + ''' class CUSTOM_UL_edges(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): @@ -184,7 +197,7 @@ class CUSTOM_UL_edges_Main(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): row = layout.row() row.label(text=f"Edge {index}") - row.prop(item, "edge_type", text="") + row.prop(item, "edge_type" , text="") def invoke(self, context, event): pass -- cgit