diff --git a/core/sockets.py b/core/sockets.py index 7f3dd59b7bd725090fd0cbac49a231b5894258e9..e14ee2e9c88a59151e0a3b16689c026fc3b0e8dc 100644 --- a/core/sockets.py +++ b/core/sockets.py @@ -1060,6 +1060,9 @@ class SvFilePathSocket(NodeSocket, SvSocketCommon): color = (0.9, 0.9, 0.3, 1.0) quick_link_to_node = 'SvFilePathNode' + filepath_node_mode: StringProperty( + name="filepath node mode", + description="use this property to configure the behaviour of a quicklinked filepath node") class SvSvgSocket(NodeSocket, SvSocketCommon): diff --git a/nodes/exchange/FCStd_read.py b/nodes/exchange/FCStd_read.py index f507fafa757fdb6341efeb0375443d06478829f3..b94c5182b8a76cf668077405ffb71f0e8d50fda4 100644 --- a/nodes/exchange/FCStd_read.py +++ b/nodes/exchange/FCStd_read.py @@ -76,7 +76,7 @@ else: def sv_init(self, context): - self.inputs.new('SvFilePathSocket', "File Path") + self.sv_new_input('SvFilePathSocket', "File Path", filepath_node_mode="FreeCAD") self.inputs.new('SvStringsSocket', "Part Filter") self.outputs.new('SvSolidSocket', "Solid") diff --git a/nodes/exchange/FCStd_sketch.py b/nodes/exchange/FCStd_sketch.py index 73ba06b3d2fcf355961fad954bc0a14b0f9f46fd..43a38defe61aa89eb16bfc0ef7a060bb1061f81f 100644 --- a/nodes/exchange/FCStd_sketch.py +++ b/nodes/exchange/FCStd_sketch.py @@ -74,7 +74,7 @@ else: self.wrapper_tracked_ui_draw_op(layout, SvReadFCStdSketchOperator.bl_idname, icon='FILE_REFRESH', text="UPDATE") def sv_init(self, context): - self.inputs.new('SvFilePathSocket', "File Path") + self.sv_new_input('SvFilePathSocket', "File Path", filepath_node_mode="FreeCAD") self.inputs.new('SvStringsSocket', "Sketch Filter") self.outputs.new('SvVerticesSocket', "Verts") diff --git a/nodes/exchange/FCStd_spreadsheet.py b/nodes/exchange/FCStd_spreadsheet.py index 137e149ef9882441a3c6c4fc04d1f9232f3510b8..37eed803e2ddb287e65efb1dd02ac939a9a3b5f2 100644 --- a/nodes/exchange/FCStd_spreadsheet.py +++ b/nodes/exchange/FCStd_spreadsheet.py @@ -73,7 +73,7 @@ else: self.wrapper_tracked_ui_draw_op(layout, SvFCStdSpreadsheetOperator.bl_idname, icon='FILE_REFRESH', text="UPDATE") def sv_init(self, context): - self.inputs.new('SvFilePathSocket', "File Path") + self.sv_new_input('SvFilePathSocket', "File Path", filepath_node_mode="FreeCAD") self.inputs.new('SvStringsSocket', "cell_in").prop_name = 'cell_in' self.outputs.new('SvStringsSocket', "cell_out") diff --git a/nodes/exchange/FCStd_write.py b/nodes/exchange/FCStd_write.py index 431be64d80cf938302aa62224ec15944b024f431..936811c294abfcb30d82d33684659c10d8aabaa7 100644 --- a/nodes/exchange/FCStd_write.py +++ b/nodes/exchange/FCStd_write.py @@ -89,7 +89,7 @@ else: def sv_init(self, context): - self.inputs.new('SvFilePathSocket', "File Path") + self.sv_new_input('SvFilePathSocket', "File Path", filepath_node_mode="FreeCAD") if self.obj_format == 'mesh': self.inputs.new('SvVerticesSocket', "Verts") diff --git a/nodes/network/file_path.py b/nodes/network/file_path.py index 98c61ce96813f1fdd9ff9b4a782573cb8cb87b4b..b73ca0af24820ae25d016c95e927f1ff2657a720 100644 --- a/nodes/network/file_path.py +++ b/nodes/network/file_path.py @@ -13,7 +13,7 @@ import bmesh from bpy.props import ( StringProperty, CollectionProperty, - IntProperty, + IntProperty, EnumProperty ) from bpy.types import ( Operator, @@ -34,14 +34,38 @@ class SvFilePathFinder(bpy.types.Operator, SvGenericNodeLocator): files: CollectionProperty(name="File Path", type=OperatorFileListElement) directory: StringProperty(subtype='DIR_PATH') - filepath: bpy.props.StringProperty( - name="File Path", description="Filepath used for writing waveform files", + filepath: StringProperty( + name="File Path", description="Filepath used for writing files", maxlen=1024, default="", subtype='FILE_PATH') + filename_ext: StringProperty(default="") + filter_glob: StringProperty(default="") + + def custom_config(self, context): + if self.mode == "FreeCAD": + self.filename_ext = ".FCStd" # ".tif" + self.filter_glob = "*.FCStd;*.FCStd1" # #*.tif;*.png;" (if more than one, separate by ;) + elif self.mode == "None": + self.filename_ext = '' + self.filter_glob = '' + + # mode: StringProperty(default='') + behaviours = ["FreeCAD", "None"] + mode: EnumProperty(items=[(i, i, '') for i in behaviours], update=custom_config, default='None') + def sv_execute(self, context, node): + if self.mode == "FreeCAD": + # This is triggered after the file is selected or typed in by the user in the Text Field of path + if self.directory and len(self.files) == 1: + if self.files[0].name and not self.files[0].name.endswith((".FCStd", ".FCStd1")): + self.files[0].name = self.files[0].name + ".FCStd" + node.set_data(self.directory, self.files) def invoke(self, context, event): + + self.custom_config(context) + wm = context.window_manager wm.fileselect_add(self) return {'RUNNING_MODAL'} @@ -60,6 +84,7 @@ class SvFilePathNode(bpy.types.Node, SverchCustomTreeNode): files_num: IntProperty(name='files number ', default=0) files: CollectionProperty(name="File Path", type=OperatorFileListElement) directory: StringProperty(subtype='DIR_PATH', update=updateNode) + mode: StringProperty(default='None', description="mode determines behaviour of the File Open Dialogue and Operator") def sv_init(self, context): @@ -68,7 +93,9 @@ class SvFilePathNode(bpy.types.Node, SverchCustomTreeNode): def draw_buttons(self, context, layout): op = 'node.sv_file_path' - self.wrapper_tracked_ui_draw_op(layout, op, icon='FILE', text='') + file_path_operator = self.wrapper_tracked_ui_draw_op(layout, op, icon='FILE', text='') + file_path_operator.mode = self.mode + if self.files_num == 0: layout.label(text=self.directory) elif self.files_num == 1: @@ -90,10 +117,24 @@ class SvFilePathNode(bpy.types.Node, SverchCustomTreeNode): else: self.files_num = len(files) + def get_linked_socket_mode_and_set_operator(self): + """ + only call this mode if the output(s) .is_linked returns true + """ + socket = self.outputs[0] + self.mode = "None" + if socket.is_linked: + other_socket = socket.other + if hasattr(other_socket, "filepath_node_mode"): + self.mode = other_socket.filepath_node_mode + def process(self): # return if no outputs are connected if not any(s.is_linked for s in self.outputs): return + + self.get_linked_socket_mode_and_set_operator() + directory = self.directory if self.files: files = [] diff --git a/nodes/solid/import_solid.py b/nodes/solid/import_solid.py index 6008b61593e36241c3a41c955afdfeed7155453f..195674fda1f74607d7b1cb1af4c371a4a5a523ca 100644 --- a/nodes/solid/import_solid.py +++ b/nodes/solid/import_solid.py @@ -20,7 +20,7 @@ else: solid_catergory = "Inputs" def sv_init(self, context): - self.inputs.new('SvFilePathSocket', "File Path") + self.sv_new_input('SvFilePathSocket', "File Path") #, filepath_node_mode="BREP") self.outputs.new('SvSolidSocket', "Solid") def process(self):