Skip to content

Commit

Permalink
backend cleanups (licence, SvGenericNodeLocator..) (#4070)
Browse files Browse the repository at this point in the history
* change touched licences

* file_path node

* objects_mk3 node

* make them consistent

* typo

* imports are favoured

* haha..oops

* standardize viewer_waveform too

* add argument

* resolve sv3dtools

* elaborate the comment on throttle

* better explanation?

* update export_solid

* missing license

* update evolver.py

* update genes_holder.py

* use oneliner for if-not-node

* update multi_cache.py

* update file path.py node

* update objects_mk3

* update export_solid

* update svg_document

* removal all instances of idtree and idname

* SvGenericNodeLocator gets a better debug statement

* diff license
  • Loading branch information
zeffii authored May 3, 2021
1 parent 8eb7d08 commit 0024862
Showing 21 changed files with 198 additions and 384 deletions.
6 changes: 3 additions & 3 deletions node_tree.py
Original file line number Diff line number Diff line change
@@ -441,7 +441,7 @@ def exception(self, msg, *args, **kwargs):
def wrapper_tracked_ui_draw_op(self, layout_element, operator_idname, **keywords):
"""
this wrapper allows you to track the origin of a clicked operator, by automatically passing
the idname and idtree of the tree.
the node_name and tree_name to the operator.
example usage:
@@ -450,8 +450,8 @@ def wrapper_tracked_ui_draw_op(self, layout_element, operator_idname, **keywords
"""
op = layout_element.operator(operator_idname, **keywords)
op.idname = self.name
op.idtree = self.id_data.name
op.node_name = self.name
op.tree_name = self.id_data.name
return op

def get_bpy_data_from_name(self, identifier, bpy_data_kind): # todo, method which have nothing related with nodes
23 changes: 6 additions & 17 deletions nodes/exchange/gcode_exporter.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE

# made by: Alessandro Zomparelli
# url: www.alessandrozomparelli.com
6 changes: 6 additions & 0 deletions nodes/exchange/nurbs_in.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE

import bpy
from bpy.props import FloatProperty, EnumProperty, BoolProperty, StringProperty
42 changes: 15 additions & 27 deletions nodes/list_mutators/multi_cache.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE

import ast
import inspect
from itertools import product
from mathutils.noise import seed_set, random

import bpy
from bpy.props import FloatVectorProperty, IntVectorProperty, IntProperty, BoolProperty, StringProperty, EnumProperty

from mathutils.noise import seed_set, random

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import changable_sockets, dataCorrect, updateNode, zip_long_repeat
from sverchok.utils.sv_operator_utils import SvGenericNodeLocator


class SvvMultiCacheReset(bpy.types.Operator):
class SvvMultiCacheReset(bpy.types.Operator, SvGenericNodeLocator):
'''Clear Cache'''
bl_idname = "node.multy_cache_reset"
bl_label = "Multi Cache Reset"

idtree: bpy.props.StringProperty(default='')
idname: bpy.props.StringProperty(default='')

def execute(self, context):
node = bpy.data.node_groups[self.idtree].nodes[self.idname]
node = self.get_node(context)
if not node: return {'CANCELLED'}

node.fill_empty_dict()
updateNode(node, context)
return {'FINISHED'}


class SvMultiCacheNode(bpy.types.Node, SverchCustomTreeNode):
"""
Triggers: Store List
@@ -80,20 +70,17 @@ def pause_recording_update(self, context):
memory: StringProperty(default="")

def draw_buttons(self, context, layout):

layout.prop(self, 'pause_recording')
layout.prop(self, 'unwrap')
self.wrapper_tracked_ui_draw_op(layout, "node.multy_cache_reset", icon='X', text="RESET")


def sv_init(self, context):
self.inputs.new('SvStringsSocket', 'Data')
self.inputs.new('SvStringsSocket', 'In Bucket').prop_name = 'in_bucket'
self.inputs.new('SvStringsSocket', 'Out Bucket').prop_name = 'out_bucket'
self.outputs.new('SvStringsSocket', 'Data')
self.fill_empty_dict()


def write_memory_prop(self, data):
'''write values to string property'''
self.memory = ''.join(str(data))
@@ -117,6 +104,7 @@ def sv_update(self):
def process(self):
if not self.outputs['Data'].is_linked:
return

in_bucket_s = self.inputs['In Bucket'].sv_get()[0]
out_bucket_s = self.inputs['Out Bucket'].sv_get()[0]
if not self.node_id in self.node_mem:
54 changes: 18 additions & 36 deletions nodes/logic/evolver.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE


import ast
import random
import time
from collections import namedtuple
from typing import NamedTuple
import numpy as np

import bpy
from mathutils.noise import seed_set, random
from bpy.props import (
BoolProperty, StringProperty, EnumProperty, IntProperty, FloatProperty
)
BoolProperty, StringProperty, EnumProperty, IntProperty, FloatProperty)

from mathutils.noise import seed_set, random
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.core.update_system import make_tree_from_nodes, do_update
from sverchok.utils.sv_operator_utils import SvGenericNodeLocator
from sverchok.utils.listutils import (
listinput_getI,
listinput_getF,
@@ -537,17 +528,14 @@ def evolve(self):
self.node.info_label = info


class SvEvolverRun(bpy.types.Operator):
class SvEvolverRun(bpy.types.Operator, SvGenericNodeLocator):

bl_idname = "node.evolver_run"
bl_label = "Evolver Run"

idtree: bpy.props.StringProperty(default='')
idname: bpy.props.StringProperty(default='')

def execute(self, context):
tree = bpy.data.node_groups[self.idtree]
node = bpy.data.node_groups[self.idtree].nodes[self.idname]
node = self.get_node(context)
if not node: return {'CANCELLED'}

if not node.inputs[0].is_linked:
node.info_label = "Stopped - Fitness not linked"
@@ -577,17 +565,15 @@ def set_fittest(tree, genes, agent, update_list):
finally:
tree.sv_process = True

class SvEvolverSetFittest(bpy.types.Operator):
class SvEvolverSetFittest(bpy.types.Operator, SvGenericNodeLocator):

bl_idname = "node.evolver_set_fittest"
bl_label = "Evolver Run"

idtree: bpy.props.StringProperty(default='')
idname: bpy.props.StringProperty(default='')

def execute(self, context):
tree = bpy.data.node_groups[self.idtree]
node = bpy.data.node_groups[self.idtree].nodes[self.idname]
node = self.get_node(context)
if not node: return {'CANCELLED'}

data = evolver_mem[node.node_id]
genes = data["genes"]
population = data["population"]
@@ -780,9 +766,5 @@ def process(self):
s.sv_set([])






classes = [SvEvolverRun, SvEvolverSetFittest, SvEvolverNode]
register, unregister = bpy.utils.register_classes_factory(classes)
36 changes: 12 additions & 24 deletions nodes/logic/genes_holder.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE

import ast
from itertools import product

from mathutils.noise import seed_set, random
import bpy
from bpy.props import FloatVectorProperty, IntVectorProperty, IntProperty, BoolProperty, StringProperty, EnumProperty


from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import dataCorrect, updateNode
from sverchok.utils.sv_operator_utils import SvGenericNodeLocator


class SvGenesHolderReset(bpy.types.Operator):
class SvGenesHolderReset(bpy.types.Operator, SvGenericNodeLocator):

bl_idname = "node.number_genes_reset"
bl_label = "Number Genes Reset"

idtree: bpy.props.StringProperty(default='')
idname: bpy.props.StringProperty(default='')

def execute(self, context):
node = bpy.data.node_groups[self.idtree].nodes[self.idname]
node = self.get_node(context)
if not node: return {'CANCELLED'}

if node.number_type == 'vector':
input_name = 'Vertices'
else:
@@ -152,7 +141,6 @@ def draw_vector_buttons(self, col):

def draw_buttons(self, context, layout):


col = layout.column(align=True)
row = col.row(align=True)
row.prop(self, "number_type", expand=True)
33 changes: 12 additions & 21 deletions nodes/network/file_path.py
Original file line number Diff line number Diff line change
@@ -23,27 +23,25 @@
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, match_long_repeat
from sverchok.utils.modules import sv_bmesh
from sverchok.utils.sv_operator_utils import SvGenericNodeLocator

class SvFilePathFinder(bpy.types.Operator):

class SvFilePathFinder(bpy.types.Operator, SvGenericNodeLocator):
'''Select Files from browser window'''
bl_idname = "node.sv_file_path"
bl_label = "Select Files/Folder"

idtree: StringProperty(default='')
idname: StringProperty(default='')
files: CollectionProperty(
name="File Path",
type=OperatorFileListElement,
)
directory: StringProperty(
subtype='DIR_PATH',
)
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",
maxlen=1024, default="", subtype='FILE_PATH')

def execute(self, context):
node = bpy.data.node_groups[self.idtree].nodes[self.idname]
node = self.get_node(context)
if not node: return {'CANCELLED'}

node.set_data(self.directory, self.files)
return {'FINISHED'}

@@ -57,22 +55,15 @@ class SvFilePathNode(bpy.types.Node, SverchCustomTreeNode):
"""
Triggers: OS file path
Tooltip: get path file from OS
"""

bl_idname = "SvFilePathNode"
bl_label = "File Path"
bl_icon = "FILE"

files_num: bpy.props.IntProperty(name='files number ', default=0)

files: CollectionProperty(
name="File Path",
type=OperatorFileListElement,
)
directory: StringProperty(
subtype='DIR_PATH',
update=updateNode)
files_num: IntProperty(name='files number ', default=0)
files: CollectionProperty(name="File Path", type=OperatorFileListElement)
directory: StringProperty(subtype='DIR_PATH', update=updateNode)

def sv_init(self, context):

Loading

0 comments on commit 0024862

Please sign in to comment.