Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fp config from socket #4456

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion nodes/exchange/FCStd_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def draw_buttons(self, context, layout):

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")

Expand Down
2 changes: 1 addition & 1 deletion nodes/exchange/FCStd_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def draw_buttons(self, context, layout):
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")
Expand Down
2 changes: 1 addition & 1 deletion nodes/exchange/FCStd_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def draw_buttons(self, context, layout):
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")
Expand Down
2 changes: 1 addition & 1 deletion nodes/exchange/FCStd_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def draw_buttons(self, context, layout):


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")
Expand Down
49 changes: 45 additions & 4 deletions nodes/network/file_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bpy.props import (
StringProperty,
CollectionProperty,
IntProperty,
IntProperty, EnumProperty
)
from bpy.types import (
Operator,
Expand All @@ -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'}
Expand All @@ -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):

Expand All @@ -68,7 +93,9 @@ def sv_init(self, context):
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:
Expand All @@ -90,10 +117,24 @@ def set_data(self, dirname, files):
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 = []
Expand Down
2 changes: 1 addition & 1 deletion nodes/solid/import_solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SvImportSolidNode(bpy.types.Node, SverchCustomTreeNode):
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):
Expand Down