diff --git a/PythonOCC/gui.py b/PythonOCC/gui.py new file mode 100644 index 0000000..8c960af --- /dev/null +++ b/PythonOCC/gui.py @@ -0,0 +1,253 @@ +from ryven.gui_env import * + +from qtpy.QtCore import Signal +from qtpy.QtWidgets import QLineEdit + + +# +# General Base Classes +# + + +class PythonOCCNodeGuiBase(NodeGUI): + + input_widget_classes = { + 'DataSmall': inp_widgets.Builder.evaled_line_edit(size='s', resizing=True), + } + + @staticmethod + def builder(): + return GuiBuilder + + +class GuiBuilder: + + @staticmethod + def attach_input_widgets(input_widgets): + """ + A decorator which automatically attaches input widgets specified + in the input_widgets list to the gui of the node. + """ + + # make sure all input widget names provided are valid + assert all([ + wn in PythonOCCNodeGuiBase.input_widget_classes + for wn in input_widgets if wn is not None + ]) + + def decorator(cls): + inp_widgets = { + i: {'name': widget_name, 'pos': 'besides'} + for i, widget_name in enumerate(input_widgets) + if widget_name is not None + } + if not issubclass(cls.GUI, PythonOCCNodeGuiBase): + # override GUI class + class AutoInputWidgets_NodeGui(PythonOCCNodeGuiBase): + init_input_widgets = inp_widgets + cls.GUI = AutoInputWidgets_NodeGui + else: + # add input widgets to existing GUI class + cls.GUI.init_input_widgets = inp_widgets + return cls + + return decorator + + +# +# Specific Node GUIs +# + + +class PyOCCBase_DynamicInputsGui(PythonOCCNodeGuiBase): + def __init__(self, params): + super().__init__(params) + + self.num_inputs = 0 + self.actions['add input'] = {'method': self.add_operand_input} + self.actions['remove input'] = {} + + def initialized(self): + # if the node was loaded from a state, catch up with + # the number of inputs + self.num_inputs = len(self.node.inputs) + # the actions are restrored automatically + + self.actions['remove input'] = { + i: { + 'method': self.remove_operand_input, + 'data': i, + } for i in range(self.num_inputs) + } + + def add_operand_input(self): + self.node.add_operand_input() + + # update actions + new_index = self.num_inputs + self.actions['remove input'][new_index] = { + 'method': self.remove_operand_input, + 'data': new_index, + } + self.num_inputs += 1 + + def remove_operand_input(self, index): + self.node.remove_operand_input(index) + del self.actions['remove input'][self.num_inputs-1] + self.num_inputs -= 1 + + +class GpNodeGui(PythonOCCNodeGuiBase): + color = '#5e0a91' + + +class BrepBuilderAPINodeGui(PythonOCCNodeGuiBase): + color = '#DAA520' + + +class BrepOffsetAPINodeGui(PythonOCCNodeGuiBase): + color = '#aabb44' + + +class BrepPrimAPINodeBase(PythonOCCNodeGuiBase): + color = '#aabb44' + + +class BrepAlgoAPINodeGui(PythonOCCNodeGuiBase): + color = '#ab0c36' + + +class BrepFilletAPINodeGui(PythonOCCNodeGuiBase): + color = '#e0149c' + + +class GeomNodeGui(PythonOCCNodeGuiBase): + color = '#c91604' + + +class GeomAPINodeGui(PythonOCCNodeGuiBase): + color = '#ff4633' + + +class TopExplorerGui(PythonOCCNodeGuiBase): + color = '#FF00FF' + + +class BoundingBoxGui(PythonOCCNodeGuiBase): + color = '#FF00FF' + + +class DisplayNodeGui(PythonOCCNodeGuiBase): + color = '#3355dd' + + +class ListGui(PyOCCBase_DynamicInputsGui): + color = '#000000' + + +class ListLengthGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class FlattenListGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class ListItemGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class RepeatDataGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class SerieGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class ShiftListGui(PythonOCCNodeGuiBase): + color = '#000000' + + +class DataExchangeNodeGui(PythonOCCNodeGuiBase): + color = '#6b6767' + + +# +# inport file node +# + + +class ImportFileNode_MainWidget(NodeMainWidget, QLineEdit): + + value_changed = Signal(object) + + def __init__(self, params): + NodeMainWidget.__init__(self, params) + QLineEdit.__init__(self) + + # self.setFixedWidth(80) + # self.setMinimumWidth(80) + self.resize(120, 31) + self.editingFinished.connect(self.editing_finished) + + def editing_finished(self): + # self.node.update() + self.value_changed.emit(self.get_val()) + + def get_val(self): + val = None + try: + val = eval(self.text()) + except Exception as e: + val = self.text() + return val + + def get_state(self): + data = {'text': self.text()} + return data + + def set_state(self, data): + self.setText(data['text']) + + +class ImportFileNode_Gui(NodeGUI): + main_widget_class = ImportFileNode_MainWidget + main_widget_pos = 'between ports' + + +# --------------------------------------------------------------------------------------------------------------------------------- + + +# +# Export +# + + +export_guis([ + PythonOCCNodeGuiBase, + PyOCCBase_DynamicInputsGui, + GuiBuilder, + + GpNodeGui, + BrepBuilderAPINodeGui, + BrepOffsetAPINodeGui, + BrepPrimAPINodeBase, + BrepAlgoAPINodeGui, + BrepFilletAPINodeGui, + GeomNodeGui, + GeomAPINodeGui, + TopExplorerGui, + BoundingBoxGui, + DisplayNodeGui, + ListGui, + ListLengthGui, + FlattenListGui, + ListItemGui, + RepeatDataGui, + SerieGui, + ShiftListGui, + DataExchangeNodeGui, + + ImportFileNode_Gui, +]) \ No newline at end of file diff --git a/PythonOCC/nodes.py b/PythonOCC/nodes.py index 298ad75..2b25885 100644 --- a/PythonOCC/nodes.py +++ b/PythonOCC/nodes.py @@ -1,6 +1,18 @@ -from ryven.NENV import * +from ryven.node_env import * + +guis = import_guis(__file__) + +# if ryven is runnign headless, there are no gui imports +attach_input_widgets = \ + guis.GuiBuilder.attach_input_widgets \ + if guis.GuiBuilder is not None else \ + lambda _: lambda cls: cls + + +# +# PythonOCC imports +# -widgets = import_widgets(__file__) from OCC.Core.ChFi2d import \ ChFi2d_AnaFilletAlgo @@ -110,10 +122,14 @@ filter_points_by_distance, \ curve_length -from OCCUtils.edge import Edge +# TODO: Edge import causes crash +# from OCCUtils.edge import Edge -# 3D Viewer ------------------------------------------ +# +# 3D Viewer +# + from datetime import datetime from OCC.Display.SimpleGui import init_display @@ -171,69 +187,114 @@ def Save_Screenshot(): add_function_to_menu('Screenshot', Save_Screenshot) -# ----------------------------------------------------- -# Base Classes + +# +# Data types +# + + +class OCCData(Data): + """ + Base class for all OCC data types passed between nodes. + """ + + # TODO: discuss data serialization approach + + # PythonOCC doesn't support pickling, so we need to + # come up with a serialization approach. + # There are who options for data serialization here: + # 1. Explicitly define serialization of all OCC types passed + # between nodes, to the point where it can be serialized + # by pickele (e.g. dict). This is a lot of work. + # 2. Violate correct graph reconstruction by simply loading + # any data into a placeholder e.g. `None`. + # This means the graph is not reconstructed exactly as it + # was saved, all OCCData objects will lose their payload, + # in particular all node output values will be useless. + # But if the nodes are designed correctly and do not store + # any state, by very few manual well chosen updates + # the user can effectively reconstruct the graph. + # For simplicity, this is the approach taken here for now. + + def get_data(self): + return None + + def set_data(self, data): + pass + + +# +# Node base classes +# class PythonOCCNodeBase(Node): + GUI = guis.PythonOCCNodeGuiBase + + def inp(self, index): + """Convenience method to unpack input data if applicable.""" + return self.input(index).payload if self.input(index) is not None else None + def get_inputs(self): - return (self.input(i) for i in range(len(self.inputs))) + """Convenience method to get a tuple of all (unpacked) input values.""" + return (self.inp(i) for i in range(len(self.inputs))) + + def have_gui(self): + # check if we are running with a GUI + # and not in headless mode + return hasattr(self, 'gui') class PythonOCCNodeBase_DynamicInputs(PythonOCCNodeBase): - def __init__(self, params): - super().__init__(params) + GUI = guis.PyOCCBase_DynamicInputsGui - self.num_inputs = 0 - - def setup_actions(self): - self.actions = {} - self.actions['add input'] = {'method': self.add_operand_input} - self.actions['rem input'] = {} + num_init_inputs = 0 def place_event(self): - self.setup_actions() - if 0 == self.num_inputs < len(self.inputs): - for i in range(len(self.inputs)): - self.register_new_operand_input(i) + for i in range(self.num_init_inputs): + if self.have_gui(): + self.gui.add_operand_input() + else: + self.add_operand_input() def add_operand_input(self): - self.create_input_dt(dtype=dtypes.Data(size='s')) - self.register_new_operand_input(self.num_inputs) + # self.create_input_dt(dtype=dtypes.Data(size='s')) + # TODO: input widgets are currently only supported in initial inputs + # fallback: + self.create_input() + self.update() def remove_operand_input(self, index): self.delete_input(index) - self.num_inputs -= 1 - del self.actions['rem input'][f'{self.num_inputs}'] self.update() - def register_new_operand_input(self, index): - self.actions['rem input'][f'{index}'] = { - 'method': self.remove_operand_input, - 'data': index - } - self.num_inputs += 1 - def update_event(self, inp=-1): - self.set_output_val(0, self.apply_op([self.input(i) for i in range(len(self.inputs))])) + self.set_output_val(0, OCCData( + self.apply_op([self.inp(i) for i in range(len(self.inputs))]) + )) def apply_op(self, elements: list): return None -# ------------------------------------------- - -# GP ---------------------------------------- +# +# GP nodes +# class GpNodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#5e0a91' + GUI = guis.GpNodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Pnt_Node(GpNodeBase): """ Generates Point_______- @@ -245,18 +306,20 @@ class Pnt_Node(GpNodeBase): title = 'point' init_inputs = [ - NodeInputBP('x', dtype=dtypes.Data(size='s')), - NodeInputBP('y', dtype=dtypes.Data(size='s')), - NodeInputBP('z', dtype=dtypes.Data(size='s')), + NodeInputType('x'), + NodeInputType('y'), + NodeInputType('z'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): x, y, z = self.clean(self.get_inputs()) - self.set_output_val(0, gp_Pnt(x, y, z)) + self.set_output_val(0, OCCData( + gp_Pnt(x, y, z) + )) def clean(self, coords): """Returns a tuple of coords where `None` values are replaced by 0""" @@ -271,14 +334,17 @@ class PointZero_Node(GpNodeBase): title = 'Point0' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): point = gp_Pnt(0,0,0) - self.set_output_val(0, point) + self.set_output_val(0, OCCData(point)) +@attach_input_widgets([ + 'DataSmall', +]) class DeconstructPnt_Node(GpNodeBase): """ Deconstruct Point_____- @@ -288,22 +354,27 @@ class DeconstructPnt_Node(GpNodeBase): title = 'deconstruct point' init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), + NodeInputType('point'), ] init_outputs = [ - NodeOutputBP('X'), - NodeOutputBP('Y'), - NodeOutputBP('Z'), + NodeOutputType('X'), + NodeOutputType('Y'), + NodeOutputType('Z'), ] def update_event(self, inp=-1): for point in self.get_inputs(): - self.set_output_val(0, point.X()) - self.set_output_val(1, point.Y()) - self.set_output_val(2, point.Z()) + self.set_output_val(0, OCCData(point.X())) + self.set_output_val(1, OCCData(point.Y())) + self.set_output_val(2, OCCData(point.Z())) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Vec_Node(GpNodeBase): """ Generates Vector______- @@ -315,18 +386,18 @@ class Vec_Node(GpNodeBase): title = 'Vector' init_inputs = [ - NodeInputBP('x', dtype=dtypes.Data(size='s')), - NodeInputBP('y', dtype=dtypes.Data(size='s')), - NodeInputBP('z', dtype=dtypes.Data(size='s')), + NodeInputType('x'), + NodeInputType('y'), + NodeInputType('z'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): x, y, z = self.get_inputs() - self.set_output_val(0, gp_Vec(x, y, z)) + self.set_output_val(0, OCCData(gp_Vec(x, y, z))) class DX_Node(GpNodeBase): @@ -337,12 +408,12 @@ class DX_Node(GpNodeBase): title = 'DirX' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): dx = gp_DX() - self.set_output_val(0, dx) + self.set_output_val(0, OCCData(dx)) class DY_Node(GpNodeBase): @@ -353,12 +424,12 @@ class DY_Node(GpNodeBase): title = 'DirY' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): dy = gp_DY() - self.set_output_val(0, dy) + self.set_output_val(0, OCCData(dy)) class DZ_Node(GpNodeBase): @@ -369,14 +440,19 @@ class DZ_Node(GpNodeBase): title = 'DirZ' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): dz = gp_DZ() - self.set_output_val(0, dz) + self.set_output_val(0, OCCData(dz)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Dir_Node(GpNodeBase): """ Generates Dir_______- @@ -388,20 +464,24 @@ class Dir_Node(GpNodeBase): title = 'dir' init_inputs = [ - NodeInputBP('x', dtype=dtypes.Data(size='s')), - NodeInputBP('y', dtype=dtypes.Data(size='s')), - NodeInputBP('z', dtype=dtypes.Data(size='s')), + NodeInputType('x'), + NodeInputType('y'), + NodeInputType('z'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): x, y, z = self.get_inputs() - self.set_output_val(0, gp_Dir(x, y, z)) + self.set_output_val(0, OCCData(gp_Dir(x, y, z))) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Ax2_Node(GpNodeBase): """ Generates Ax2_________- @@ -412,17 +492,17 @@ class Ax2_Node(GpNodeBase): title = 'Ax2' init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('dir', dtype=dtypes.Data(size='s')), + NodeInputType('point'), + NodeInputType('dir'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): point, dir_ = self.get_inputs() - self.set_output_val(0, gp_Ax2(point, dir_)) + self.set_output_val(0, OCCData(gp_Ax2(point, dir_))) class XOY_Node(GpNodeBase): """ @@ -432,12 +512,12 @@ class XOY_Node(GpNodeBase): title = 'AxZ' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): axz = gp_XOY() - self.set_output_val(0, axz) + self.set_output_val(0, OCCData(axz)) class YOZ_Node(GpNodeBase): """ @@ -447,12 +527,12 @@ class YOZ_Node(GpNodeBase): title = 'AxX' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): axx = gp_YOZ() - self.set_output_val(0, axx) + self.set_output_val(0, OCCData(axx)) class ZOX_Node(GpNodeBase): """ @@ -462,13 +542,17 @@ class ZOX_Node(GpNodeBase): title = 'AxY' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def place_event(self): axy = gp_ZOX() - self.set_output_val(0, axy) + self.set_output_val(0, OCCData(axy)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Pln_Node(GpNodeBase): """ Generates Plane_______- @@ -479,19 +563,23 @@ class Pln_Node(GpNodeBase): title = 'Plane' init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('dir', dtype=dtypes.Data(size='s')), + NodeInputType('point'), + NodeInputType('dir'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): point, dir_ = self.get_inputs() - self.set_output_val(0, gp_Pln(point, dir_)) + self.set_output_val(0, OCCData(gp_Pln(point, dir_))) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Trsf_Node(GpNodeBase): """ Generates transform___- @@ -502,12 +590,12 @@ class Trsf_Node(GpNodeBase): title = 'Transform' init_inputs = [ - NodeInputBP('shapes', dtype=dtypes.Data(size='s')), - NodeInputBP('vectors', dtype=dtypes.Data(size='s')), + NodeInputType('shapes'), + NodeInputType('vectors'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -525,7 +613,7 @@ def update_event(self, inp=-1): else: translated = BRepBuilderAPI_Transform(sh, trns).Shape() result.append(translated) - self.set_output_val(0, result) + self.set_output_val(0, OCCData(result)) elif isinstance(shapes, list) and not isinstance(vectors, list): for sh in (shapes): @@ -538,7 +626,7 @@ def update_event(self, inp=-1): else: translated = BRepBuilderAPI_Transform(sh, trns).Shape() result.append(translated) - self.set_output_val(0, result) + self.set_output_val(0, OCCData(result)) elif not isinstance(shapes, list) and isinstance(vectors, list): for v in (vectors): @@ -551,7 +639,7 @@ def update_event(self, inp=-1): else: translated = BRepBuilderAPI_Transform(shapes, trns).Shape() result.append(translated) - self.set_output_val(0, result) + self.set_output_val(0, OCCData(result)) else: trns = gp_Trsf() @@ -562,9 +650,14 @@ def update_event(self, inp=-1): translated = sh2 else: translated = BRepBuilderAPI_Transform(shapes, trns).Shape() - self.set_output_val(0, translated) + self.set_output_val(0, OCCData(translated)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Move2pts_Node(GpNodeBase): """ Move 2 points_________- @@ -575,13 +668,13 @@ class Move2pts_Node(GpNodeBase): title = 'Move2pnts' init_inputs = [ - NodeInputBP('shapes', dtype=dtypes.Data(size='s')), - NodeInputBP('from', dtype=dtypes.Data(size='s')), - NodeInputBP('to', dtype=dtypes.Data(size='s')), + NodeInputType('shapes'), + NodeInputType('from'), + NodeInputType('to'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -602,7 +695,7 @@ def update_event(self, inp=-1): trns.SetTranslation(v.Reversed()) translated = BRepBuilderAPI_Transform(sh, trns).Shape() result.append(translated) - self.set_output_val(0, result) + self.set_output_val(0, OCCData(result)) else: v = gp_Vec() @@ -613,9 +706,13 @@ def update_event(self, inp=-1): trns = gp_Trsf() trns.SetTranslation(v.Reversed()) translated = BRepBuilderAPI_Transform(shapes, trns).Shape() - self.set_output_val(0, translated) + self.set_output_val(0, OCCData(translated)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class MidPoint_Node(GpNodeBase): """ MidPoint_____________- @@ -626,12 +723,12 @@ class MidPoint_Node(GpNodeBase): title = 'MidPoint' init_inputs = [ - NodeInputBP('pointA', dtype=dtypes.Data(size='s')), - NodeInputBP('pointB', dtype=dtypes.Data(size='s')), + NodeInputType('pointA'), + NodeInputType('pointB'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -640,9 +737,12 @@ def update_event(self, inp=-1): vec2 = gp_Vec(pointB.XYZ()) midvec = (vec1 + vec2) / 2. midpoint = gp_Pnt(midvec.XYZ()) - self.set_output_val(0, midpoint) + self.set_output_val(0, OCCData(midpoint)) +@attach_input_widgets([ + 'DataSmall', +]) class Get_dir_from_edge_Node(GpNodeBase): """ Dir from Edge________- @@ -652,21 +752,24 @@ class Get_dir_from_edge_Node(GpNodeBase): title = 'DirfromEdge' init_inputs = [ - NodeInputBP('Edge', dtype=dtypes.Data(size='s')), + NodeInputType('Edge'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): + print('ERROR - EDGE IS BROKEN') + return + for edge in self.get_inputs(): edg = Edge(edge) first_point = BRep_Tool.Pnt(edg.first_vertex()) last_point = BRep_Tool.Pnt(edg.last_vertex()) dir_edge = gp_Dir(last_point.X() - first_point.X(), last_point.Y() - first_point.Y(), last_point.Z() - first_point.Z()) - self.set_output_val(0, dir_edge) + self.set_output_val(0, OCCData(dir_edge)) Gp_nodes = [ @@ -690,16 +793,20 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# BREPBUILDERAPI----------------------------- +# +# BrepBuilderAPI nodes +# class BrepBuilderAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#DAA520' + GUI = guis.BrepBuilderAPINodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class TwoPtsEdge_Node(BrepBuilderAPINodeBase): """ Generates 2 pts Edge__- @@ -710,12 +817,12 @@ class TwoPtsEdge_Node(BrepBuilderAPINodeBase): title = '2ptsEdge' init_inputs = [ - NodeInputBP('pnt1', dtype=dtypes.Data(size='s')), - NodeInputBP('Pnt2', dtype=dtypes.Data(size='s')), + NodeInputType('pnt1'), + NodeInputType('Pnt2'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -726,13 +833,16 @@ def update_event(self, inp=-1): for p1, p2 in zip(pnt1, pnt2): edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() edges.append(edge) - self.set_output_val(0, edges) + self.set_output_val(0, OCCData(edges)) else: edge = BRepBuilderAPI_MakeEdge(pnt1, pnt2).Edge() - self.set_output_val(0, edge) + self.set_output_val(0, OCCData(edge)) +@attach_input_widgets([ + 'DataSmall', +]) class Wire_Node(BrepBuilderAPINodeBase): """ Generates Wire________- @@ -742,11 +852,11 @@ class Wire_Node(BrepBuilderAPINodeBase): title = 'Wire' init_inputs = [ - NodeInputBP('pntslist', dtype=dtypes.Data(size='s')), + NodeInputType('pntslist'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -760,9 +870,13 @@ def update_event(self, inp=-1): edgepoint = BRepBuilderAPI_MakeEdge(pointsarray.Value(i), pointsarray.Value(i + 1)).Edge() wirebuild.Add(edgepoint) - self.set_output_val(0, wirebuild.Shape()) + self.set_output_val(0, OCCData(wirebuild.Shape())) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class WireFillet2d_Node(BrepBuilderAPINodeBase): """ Generates 2dWireFillet_- @@ -773,12 +887,12 @@ class WireFillet2d_Node(BrepBuilderAPINodeBase): title = '2dWireFillet' init_inputs = [ - NodeInputBP('pntslist', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), + NodeInputType('pntslist'), + NodeInputType('radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -807,9 +921,13 @@ def update_event(self, inp=-1): wirebuild.Add(fillet) wirebuild.Add(edges_list[-1]) - self.set_output_val(0, wirebuild.Shape()) + self.set_output_val(0, OCCData(wirebuild.Shape())) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class DiscretizeWire_Node(BrepBuilderAPINodeBase): """ Discretize Wire_______- @@ -820,12 +938,12 @@ class DiscretizeWire_Node(BrepBuilderAPINodeBase): title = 'DiscretizeWire' init_inputs = [ - NodeInputBP('Wire', dtype=dtypes.Data(size='s')), - NodeInputBP('Nb', dtype=dtypes.Data(size='s')), + NodeInputType('Wire'), + NodeInputType('Nb'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -840,9 +958,12 @@ def update_event(self, inp=-1): if npts.IsDone(): for i in range(1, npts.NbPoints() + 1): pnts.append(curve_adapt.Value(npts.Parameter(i))) - self.set_output_val(0, pnts) + self.set_output_val(0, OCCData(pnts)) # print(tmp) +@attach_input_widgets([ + 'DataSmall', +]) class CurveLength_Node(BrepBuilderAPINodeBase): """ Curve Length__________- @@ -852,18 +973,18 @@ class CurveLength_Node(BrepBuilderAPINodeBase): title = 'CurveLength' init_inputs = [ - NodeInputBP('Wire/Edge', dtype=dtypes.Data(size='s')), + NodeInputType('Wire/Edge'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): lengths = [] for curve in self.get_inputs(): lengths.append(curve_length(curve)) - self.set_output_val(0, lengths) + self.set_output_val(0, OCCData(lengths)) # print(tmp) @@ -876,16 +997,20 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# BREPOFFSETAPI------------------------------ +# +# BrepOffsetAPI nodes +# class BrepOffsetAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#aabb44' + GUI = guis.BrepOffsetAPINodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Pipe_Node(BrepOffsetAPINodeBase): """ Generates pipe________- @@ -896,12 +1021,12 @@ class Pipe_Node(BrepOffsetAPINodeBase): title = 'pipe' init_inputs = [ - NodeInputBP('wire', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), + NodeInputType('wire'), + NodeInputType('radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -929,7 +1054,7 @@ def update_event(self, inp=-1): profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() pipe = BRepOffsetAPI_MakePipe(w, profile_face).Shape() pipes.append(pipe) - self.set_output_val(0, pipes) + self.set_output_val(0, OCCData(pipes)) else: if isinstance(wire, TopoDS_Edge): @@ -950,7 +1075,7 @@ def update_event(self, inp=-1): profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire() profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape() - self.set_output_val(0, pipe) + self.set_output_val(0, OCCData(pipe)) BRepOffsetAPI_nodes = [ @@ -958,16 +1083,21 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# BREPPRIMAPI -------------------------------- +# +# BRepPrimAPI nodes +# class BrepPrimAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#aabb44' + GUI = guis.BrepPrimAPINodeBase +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Box_Node(BrepPrimAPINodeBase): """ Generates box_________- @@ -979,21 +1109,25 @@ class Box_Node(BrepPrimAPINodeBase): title = 'box' init_inputs = [ - NodeInputBP('w', dtype=dtypes.Data(size='s')), - NodeInputBP('l', dtype=dtypes.Data(size='s')), - NodeInputBP('h', dtype=dtypes.Data(size='s')), + NodeInputType('w'), + NodeInputType('l'), + NodeInputType('h'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): width, length, height = self.get_inputs() box = BRepPrimAPI_MakeBox(gp_Pnt(), width, length, height).Shape() - self.set_output_val(0, box) + self.set_output_val(0, OCCData(box)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Sphere_Node(BrepPrimAPINodeBase): """ Generates sphere_________- @@ -1004,20 +1138,25 @@ class Sphere_Node(BrepPrimAPINodeBase): title = 'sphere' init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), + NodeInputType('point'), + NodeInputType('radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): point, radius = self.get_inputs() sphere = BRepPrimAPI_MakeSphere(point, radius).Shape() - self.set_output_val(0, sphere) + self.set_output_val(0, OCCData(sphere)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Cylinder_Node(BrepPrimAPINodeBase): """ Generates cylinder_______- @@ -1029,20 +1168,25 @@ class Cylinder_Node(BrepPrimAPINodeBase): title = 'cylinder' init_inputs = [ - NodeInputBP('axe', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), - NodeInputBP('len', dtype=dtypes.Data(size='s')), + NodeInputType('axe'), + NodeInputType('radius'), + NodeInputType('len'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): axe, radius, length = self.get_inputs() cylinder = BRepPrimAPI_MakeCylinder(axe, radius, length).Shape() - self.set_output_val(0, cylinder) + self.set_output_val(0, OCCData(cylinder)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Torus_Node(BrepPrimAPINodeBase): """ Generates torus__________- @@ -1054,19 +1198,19 @@ class Torus_Node(BrepPrimAPINodeBase): title = 'torus' init_inputs = [ - NodeInputBP('axe', dtype=dtypes.Data(size='s')), - NodeInputBP('distance', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), + NodeInputType('axe'), + NodeInputType('distance'), + NodeInputType('radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): axe, distance, radius = self.get_inputs() torus = BRepPrimAPI_MakeTorus(axe, distance, radius).Shape() - self.set_output_val(0, torus) + self.set_output_val(0, OCCData(torus)) BRepPrimAPI_nodes = [ @@ -1077,16 +1221,20 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# BREPALGOAPI -------------------------------- +# +# BrepAlgoAPI nodes +# class BrepAlgoAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#ab0c36' + GUI = guis.BrepAlgoAPINodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Fuse_Node(BrepAlgoAPINodeBase): """ Generates fusion_________- @@ -1097,11 +1245,11 @@ class Fuse_Node(BrepAlgoAPINodeBase): title = 'fuse' init_inputs = [ - NodeInputBP('a', dtype=dtypes.Data(size='s')), - NodeInputBP('b', dtype=dtypes.Data(size='s')), + NodeInputType('a'), + NodeInputType('b'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1114,12 +1262,16 @@ def update_event(self, inp=-1): for i in range(2, count): ijk += 1 fuse_shps[ijk] = BRepAlgoAPI_Fuse(fuse_shps[ijk-1], a[i]).Shape() - self.set_output_val(0, fuse_shps[ijk]) + self.set_output_val(0, OCCData(fuse_shps[ijk])) else: fuse_shp = BRepAlgoAPI_Fuse(a, b).Shape() - self.set_output_val(0, fuse_shp) + self.set_output_val(0, OCCData(fuse_shp)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Common_Node(BrepAlgoAPINodeBase): """ Generates common_________- @@ -1130,19 +1282,23 @@ class Common_Node(BrepAlgoAPINodeBase): title = 'common' init_inputs = [ - NodeInputBP('a', dtype=dtypes.Data(size='s')), - NodeInputBP('b', dtype=dtypes.Data(size='s')), + NodeInputType('a'), + NodeInputType('b'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): a, b = self.get_inputs() common_shp = BRepAlgoAPI_Common(a, b).Shape() - self.set_output_val(0, common_shp) + self.set_output_val(0, OCCData(common_shp)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Cut_Node(BrepAlgoAPINodeBase): """ Generates cutting________- @@ -1153,11 +1309,11 @@ class Cut_Node(BrepAlgoAPINodeBase): title = 'cut' init_inputs = [ - NodeInputBP('Basis', dtype=dtypes.Data(size='s')), - NodeInputBP('Cutter', dtype=dtypes.Data(size='s')), + NodeInputType('Basis'), + NodeInputType('Cutter'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1170,16 +1326,20 @@ def update_event(self, inp=-1): for i in range(1, count): ijk += 1 cut_shps[ijk] = BRepAlgoAPI_Cut(cut_shps[ijk - 1], cutter[i]).Shape() - self.set_output_val(0, cut_shps[ijk]) + self.set_output_val(0, OCCData(cut_shps[ijk])) elif type(basis) is list and type(cutter) is not list: cut_shps = [] for b in basis: cut_shps.append(BRepAlgoAPI_Cut(b, cutter).Shape()) - self.set_output_val(0, cut_shps) + self.set_output_val(0, OCCData(cut_shps)) else: cut_shp = BRepAlgoAPI_Cut(basis, cutter).Shape() - self.set_output_val(0, cut_shp) + self.set_output_val(0, OCCData(cut_shp)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Section_Node(BrepAlgoAPINodeBase): """ Generates Sections_______- @@ -1190,11 +1350,11 @@ class Section_Node(BrepAlgoAPINodeBase): title = 'section' init_inputs = [ - NodeInputBP('Basis', dtype=dtypes.Data(size='s')), - NodeInputBP('Cutter', dtype=dtypes.Data(size='s')), + NodeInputType('Basis'), + NodeInputType('Cutter'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1208,15 +1368,15 @@ def update_event(self, inp=-1): for i in range(1, count): ijk += 1 cut_shps[ijk] = BRepAlgoAPI_Section(cut_shps[ijk - 1], cutter[i]).Shape() - self.set_output_val(0, cut_shps[ijk]) + self.set_output_val(0, OCCData(cut_shps[ijk])) elif type(basis) is list and type(cutter) is not list: cut_shps = [] for b in basis: cut_shps.append(BRepAlgoAPI_Section(b, cutter).Shape()) - self.set_output_val(0, cut_shps) + self.set_output_val(0, OCCData(cut_shps)) else: cut_shp = BRepAlgoAPI_Section(basis, cutter).Shape() - self.set_output_val(0, cut_shp) + self.set_output_val(0, OCCData(cut_shp)) BRepAlgoAPI_nodes = [ @@ -1227,16 +1387,19 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# BREPFILLETAPI -------------------------------- +# BrepFilletAPI nodes +# class BrepFilletAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#e0149c' + GUI = guis.BrepFilletAPINodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Fillet_Node(BrepFilletAPINodeBase): """ Generates fillet_________- @@ -1247,11 +1410,11 @@ class Fillet_Node(BrepFilletAPINodeBase): title = 'fillet' init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), + NodeInputType('radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1267,7 +1430,7 @@ def update_event(self, inp=-1): blended_fused_solids = fill.Shape() - self.set_output_val(0, blended_fused_solids) + self.set_output_val(0, OCCData(blended_fused_solids)) BRepFilletAPI_nodes = [ @@ -1275,14 +1438,19 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- +# +# Geom and GeomAPI nodes +# -# GEOMAPI------------------------------------ class GeomNodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#c91604' + GUI = guis.GeomNodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Circle_Node(GeomNodeBase): """ Draw circle______________- @@ -1293,30 +1461,29 @@ class Circle_Node(GeomNodeBase): title = 'Circle' init_inputs = [ - NodeInputBP('Ax2', dtype=dtypes.Data(size='s')), - NodeInputBP('Radius', dtype=dtypes.Data(size='s')), + NodeInputType('Ax2'), + NodeInputType('Radius'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): axis, radius = self.get_inputs() circle = Geom_Circle(axis, radius) - self.set_output_val(0, circle) + self.set_output_val(0, OCCData(circle)) Geom_nodes = [ Circle_Node, ] -# ------------------------------------------- - -# GEOMAPI------------------------------------ - class GeomAPINodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#ff4633' + GUI = guis.GeomAPINodeGui +@attach_input_widgets([ + 'DataSmall', +]) class PointsSurface_Node(GeomAPINodeBase): """ Generates surface________- @@ -1326,10 +1493,10 @@ class PointsSurface_Node(GeomAPINodeBase): title = 'PointsSurface' init_inputs = [ - NodeInputBP('points', dtype=dtypes.Data(size='s')), + NodeInputType('points'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1346,7 +1513,7 @@ def update_event(self, inp=-1): print(pts[c][n]) array.SetValue(n + 1, c + 1, pts[c][n]) nurbs = GeomAPI_PointsToBSplineSurface(array, 2, 2, GeomAbs_C2, 0.001).Surface() - self.set_output_val(0, nurbs) + self.set_output_val(0, OCCData(nurbs)) GeomAPI_nodes = [ @@ -1354,11 +1521,14 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# SHAPE ANALYSIS -------------------------- +# +# Shape Analysis +# +@attach_input_widgets([ + 'DataSmall', +]) class TopExplorer_Node(PythonOCCNodeBase): """ Topology Explorer________- @@ -1367,20 +1537,20 @@ class TopExplorer_Node(PythonOCCNodeBase): title = 'topexp' version = 'v0.1' - color = '#FF00FF' + GUI = guis.TopExplorerGui init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), ] init_outputs = [ - NodeOutputBP('vertex'), - NodeOutputBP('edges'), - NodeOutputBP('wires'), - NodeOutputBP('faces'), - NodeOutputBP('shells'), - NodeOutputBP('solids'), - NodeOutputBP('compounds'), - NodeOutputBP('compsolids'), + NodeOutputType('vertex'), + NodeOutputType('edges'), + NodeOutputType('wires'), + NodeOutputType('faces'), + NodeOutputType('shells'), + NodeOutputType('solids'), + NodeOutputType('compounds'), + NodeOutputType('compsolids'), ] def update_event(self, inp=-1): @@ -1452,16 +1622,19 @@ def update_event(self, inp=-1): compsolids.append(compsolid) topexp_compsolid.Next() - self.set_output_val(0, vertices_red) - self.set_output_val(1, edges) - self.set_output_val(2, wires) - self.set_output_val(3, faces) - self.set_output_val(4, shells) - self.set_output_val(5, solids) - self.set_output_val(6, compounds) - self.set_output_val(7, compsolids) + self.set_output_val(0, OCCData(vertices_red)) + self.set_output_val(1, OCCData(edges)) + self.set_output_val(2, OCCData(wires)) + self.set_output_val(3, OCCData(faces)) + self.set_output_val(4, OCCData(shells)) + self.set_output_val(5, OCCData(solids)) + self.set_output_val(6, OCCData(compounds)) + self.set_output_val(7, OCCData(compsolids)) +@attach_input_widgets([ + 'DataSmall', +]) class BoundingBox_Node(PythonOCCNodeBase): """ Bounding Box________- @@ -1470,13 +1643,13 @@ class BoundingBox_Node(PythonOCCNodeBase): title = 'bounding box' version = 'v0.1' - color = '#FF00FF' + GUI = guis.BoundingBoxGui init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), ] init_outputs = [ - NodeOutputBP('box'), + NodeOutputType('box'), ] def update_event(self, inp=-1): @@ -1484,7 +1657,7 @@ def update_event(self, inp=-1): for shape in self.get_inputs(): aBaryCenter, [aHalfX, aHalfY, aHalfZ], aBox = get_oriented_boundingbox(shape) bboxes.append(aBox) - self.set_output_val(0, bboxes) # TODO make it work for list + self.set_output_val(0, OCCData(bboxes)) # TODO make it work for list Shape_Analysis_nodes = [ @@ -1493,16 +1666,19 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# DISPLAY -------------------------------- +# +# Display nodes +# class DisplayNodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#3355dd' + GUI = guis.DisplayNodeGui +@attach_input_widgets([ + 'DataSmall', +]) class Display_Node(DisplayNodeBase): """ display shapes @@ -1512,7 +1688,7 @@ class Display_Node(DisplayNodeBase): title = 'display' init_inputs = [ - NodeInputBP('shapes', dtype=dtypes.Data(size='s')), + NodeInputType('shapes'), ] def update_event(self, inp=-1): @@ -1547,6 +1723,10 @@ def update_event(self, inp=-1): display.FitAll() +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class Color_Node(DisplayNodeBase): """ Choose Color_____________- @@ -1557,11 +1737,11 @@ class Color_Node(DisplayNodeBase): title = 'color' init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('Int', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), + NodeInputType('Int'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1570,11 +1750,11 @@ def update_event(self, inp=-1): if type(shape) is list: for shp in shape: shapecolored.append([shp, colore]) - self.set_output_val(0, shapecolored) + self.set_output_val(0, OCCData(shapecolored)) else: shapecolored.append(shape) shapecolored.append(colore) - self.set_output_val(0, shapecolored) + self.set_output_val(0, OCCData(shapecolored)) Display_nodes = [ @@ -1583,11 +1763,15 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- - -# TOOLS-------------------------------------- +# +# Utility nodes +# +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class List_Node(PythonOCCNodeBase_DynamicInputs): """ Generates List_______- @@ -1597,21 +1781,24 @@ class List_Node(PythonOCCNodeBase_DynamicInputs): title = 'List' version = 'v0.1' - color = '#000000' + GUI = guis.ListGui init_inputs = [ - NodeInputBP(dtype=dtypes.Data(size='s')), - NodeInputBP(dtype=dtypes.Data(size='s')), + NodeInputType(), + NodeInputType(), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def apply_op(self, elements: list): return elements +@attach_input_widgets([ + 'DataSmall', +]) class ListLength_Node(PythonOCCNodeBase): """ List Length__________- @@ -1620,25 +1807,28 @@ class ListLength_Node(PythonOCCNodeBase): title = 'ListLength' version = 'v0.1' - color = '#000000' + GUI = guis.ListLengthGui init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), + NodeInputType('list'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): for el in self.get_inputs(): if type(el) is list: length = len(el) - self.set_output_val(0, length) + self.set_output_val(0, OCCData(length)) else : pass +@attach_input_widgets([ + 'DataSmall', +]) class FlattenList_Node(PythonOCCNodeBase): """ Flatten list_________- @@ -1647,14 +1837,14 @@ class FlattenList_Node(PythonOCCNodeBase): title = 'FlattenList' version = 'v0.1' - color = '#000000' + GUI = guis.FlattenListGui init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), + NodeInputType('list'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1669,9 +1859,13 @@ def update_event(self, inp=-1): newlist.append(e) else: newlist.append(el) - self.set_output_val(0,newlist) + self.set_output_val(0, OCCData(newlist)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class ListItem_Node(PythonOCCNodeBase): """ Item list____________- @@ -1681,22 +1875,26 @@ class ListItem_Node(PythonOCCNodeBase): title = 'ListItem' version = 'v0.1' - color = '#000000' + GUI = guis.ListItemGui init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), - NodeInputBP('index', dtype=dtypes.Data(size='s')), + NodeInputType('list'), + NodeInputType('index'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): reflist, index = self.get_inputs() - self.set_output_val(0, reflist[index]) + self.set_output_val(0, OCCData(reflist[index])) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class RepeatData_Node(PythonOCCNodeBase): """ Repeat Data__________- @@ -1706,15 +1904,15 @@ class RepeatData_Node(PythonOCCNodeBase): title = 'RepeatData' version = 'v0.1' - color = '#000000' + GUI = guis.RepeatDataGui init_inputs = [ - NodeInputBP('Data', dtype=dtypes.Data(size='s')), - NodeInputBP('Length', dtype=dtypes.Data(size='s')), + NodeInputType('Data'), + NodeInputType('Length'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1726,9 +1924,14 @@ def update_event(self, inp=-1): repeat.append(d) else: repeat.append(Data) - self.set_output_val(0, repeat) + self.set_output_val(0, OCCData(repeat)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class Serie_Node(PythonOCCNodeBase): """ Create Serie_________- @@ -1739,16 +1942,16 @@ class Serie_Node(PythonOCCNodeBase): title = 'Serie' version = 'v0.1' - color = '#000000' + GUI = guis.SerieGui init_inputs = [ - NodeInputBP('Start', dtype=dtypes.Data(size='s')), - NodeInputBP('Step', dtype=dtypes.Data(size='s')), - NodeInputBP('Length', dtype=dtypes.Data(size='s')), + NodeInputType('Start'), + NodeInputType('Step'), + NodeInputType('Length'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1759,8 +1962,12 @@ def update_event(self, inp=-1): for l in range(Length-1): count += Step serie.append(count) - self.set_output_val(0, serie) + self.set_output_val(0, OCCData(serie)) +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class ShiftList_Node(PythonOCCNodeBase): """ Shift List___________- @@ -1770,15 +1977,15 @@ class ShiftList_Node(PythonOCCNodeBase): title = 'ShiftLIst' version = 'v0.1' - color = '#000000' + GUI = guis.ShiftListGui init_inputs = [ - NodeInputBP('List', dtype=dtypes.Data(size='s')), - NodeInputBP('ShiftValue', dtype=dtypes.Data(size='s')), + NodeInputType('List'), + NodeInputType('ShiftValue'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1790,7 +1997,7 @@ def update_event(self, inp=-1): elif value > 0: for i in range(value, len(list_)): shifted_list.append(list_[i]) - self.set_output_val(0, shifted_list) + self.set_output_val(0, OCCData(shifted_list)) Tools_nodes = [ @@ -1804,16 +2011,20 @@ def update_event(self, inp=-1): ] -# -------------------------------------------------------- - -# DATA EXCHANGE------------------------------------------ +# +# Data Exchange nodes +# class DataExchangeNodeBase(PythonOCCNodeBase): version = 'v0.1' - color = '#6b6767' + GUI = guis.DataExchangeNodeGui +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class ExportStep_Node(DataExchangeNodeBase): """ Generates Step_______- @@ -1824,12 +2035,12 @@ class ExportStep_Node(DataExchangeNodeBase): title = 'ExportStep' init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('fname', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), + NodeInputType('fname'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1848,19 +2059,18 @@ class ImportStep_Node(DataExchangeNodeBase): title = 'ImportStep' doc = 'returns the evaluated text that is typed into the input field' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] - main_widget_class = widgets.ImportFileNode_MainWidget - main_widget_pos = 'between ports' - style = 'normal' + # main_widget_class = guis.ImportFileNode_MainWidget + # main_widget_pos = 'between ports' + # style = 'normal' + GUI = guis.ImportFileNode_Gui def __init__(self, params): super().__init__(params) - self.actions['edit string via dialog'] = {'method': self.action_edit_via_dialog} self.string = None - def place_event(self): self.update() @@ -1873,33 +2083,22 @@ def main_widget_string_changed(self, string): def update_event(self, input_called=-1): shape = read_step_file(self.string) - self.set_output_val(0, shape) - - def action_edit_via_dialog(self): - return - - # from ..EditVal_Dialog import EditVal_Dialog - # - # val_dialog = EditVal_Dialog(parent=None, init_val=self.val) - # accepted = val_dialog.exec_() - # if accepted: - # self.main_widget().setText(str(val_dialog.get_val())) - # self.update() - + self.set_output_val(0, OCCData(shape)) def get_current_var_name(self): - return self.input(0) - + return self.inp(0) def get_state(self): - return { - 'string': self.string # self.main_widget().get_val() - } + return {'string': self.string} def set_state(self, data, version): self.string = data['string'] +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', +]) class ExportStl_Node(DataExchangeNodeBase): """ Generates Stl________- @@ -1910,12 +2109,12 @@ class ExportStl_Node(DataExchangeNodeBase): title = 'ExportStl' init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('name', dtype=dtypes.Data(size='s')), + NodeInputType('shape'), + NodeInputType('name'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -1932,19 +2131,18 @@ class ImportStl_Node(DataExchangeNodeBase): title = 'ImportStl' doc = 'returns the evaluated text that is typed into the input field' init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] - main_widget_class = widgets.ImportFileNode_MainWidget - main_widget_pos = 'between ports' - style = 'normal' + # main_widget_class = guis.ImportFileNode_MainWidget + # main_widget_pos = 'between ports' + # style = 'normal' + GUI = guis.ImportFileNode_Gui def __init__(self, params): super().__init__(params) - self.actions['edit string via dialog'] = {'method': self.action_edit_via_dialog} self.string = None - def place_event(self): self.update() @@ -1957,32 +2155,22 @@ def main_widget_string_changed(self, string): def update_event(self, input_called=-1): shape = read_stl_file(self.string) - self.set_output_val(0, shape) - - def action_edit_via_dialog(self): - return - - # from ..EditVal_Dialog import EditVal_Dialog - # - # val_dialog = EditVal_Dialog(parent=None, init_val=self.val) - # accepted = val_dialog.exec_() - # if accepted: - # self.main_widget().setText(str(val_dialog.get_val())) - # self.update() - + self.set_output_val(0, OCCData(shape)) def get_current_var_name(self): - return self.input(0) - + return self.inp(0) def get_state(self): - return { - 'string': self.string # self.main_widget().get_val() - } + return {'string': self.string} def set_state(self, data, version): self.string = data['string'] +@attach_input_widgets([ + 'DataSmall', + 'DataSmall', + 'DataSmall', +]) class ExportGcode_Node(DataExchangeNodeBase): """ Generates Gcode______- @@ -1994,13 +2182,13 @@ class ExportGcode_Node(DataExchangeNodeBase): title = 'ExportGcode' init_inputs = [ - NodeInputBP('points', dtype=dtypes.Data(size='s')), - NodeInputBP('name', dtype=dtypes.Data(size='s')), - NodeInputBP('speed', dtype=dtypes.Data(size='s')), + NodeInputType('points'), + NodeInputType('name'), + NodeInputType('speed'), ] init_outputs = [ - NodeOutputBP(), + NodeOutputType(), ] def update_event(self, inp=-1): @@ -2019,10 +2207,15 @@ def update_event(self, inp=-1): ] -# ------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------------------- + + +# +# Export +# -export_nodes( +export_nodes([ *Gp_nodes, *BRepBuilderAPI_nodes, *BRepOffsetAPI_nodes, @@ -2035,4 +2228,4 @@ def update_event(self, inp=-1): *Display_nodes, *Tools_nodes, *DataExchange_nodes, -) +]) diff --git a/PythonOCC/widgets.py b/PythonOCC/widgets.py deleted file mode 100644 index 5a91ae4..0000000 --- a/PythonOCC/widgets.py +++ /dev/null @@ -1,42 +0,0 @@ -from ryven.NWENV import * - -from qtpy.QtCore import Signal -from qtpy.QtWidgets import QLineEdit - - -class ImportFileNode_MainWidget(MWB, QLineEdit): - - value_changed = Signal(object) - - def __init__(self, params): - MWB.__init__(self, params) - QLineEdit.__init__(self) - - # self.setFixedWidth(80) - # self.setMinimumWidth(80) - self.resize(120, 31) - self.editingFinished.connect(self.editing_finished) - - def editing_finished(self): - # self.node.update() - self.value_changed.emit(self.get_val()) - - def get_val(self): - val = None - try: - val = eval(self.text()) - except Exception as e: - val = self.text() - return val - - def get_state(self): - data = {'text': self.text()} - return data - - def set_state(self, data): - self.setText(data['text']) - - -export_widgets( - ImportFileNode_MainWidget, -) \ No newline at end of file