From 87fbdec1e7ac4888d3c369000f1092e947479e21 Mon Sep 17 00:00:00 2001 From: leon-thomm Date: Wed, 2 Feb 2022 12:41:01 +0100 Subject: [PATCH 1/5] removed duplicate nodes.py --- nodes.py | 1997 ------------------------------------------------------ 1 file changed, 1997 deletions(-) delete mode 100644 nodes.py diff --git a/nodes.py b/nodes.py deleted file mode 100644 index a19c0d9..0000000 --- a/nodes.py +++ /dev/null @@ -1,1997 +0,0 @@ -from ryven.NENV import * - -widgets = import_widgets(__file__) - -from OCC.Core.ChFi2d import \ - ChFi2d_AnaFilletAlgo - -from OCC.Core.gp import \ - gp_Pnt, \ - gp_Vec, \ - gp_Dir, \ - gp_Ax2, \ - gp_Pln, \ - gp_Trsf, \ - gp_DX, \ - gp_DY, \ - gp_DZ, \ - gp_Circ, \ - gp_XOY, \ - gp_YOZ, \ - gp_ZOX - -from OCC.Core.BRep import \ - BRep_Tool - -from OCC.Core.BRepBuilderAPI import \ - BRepBuilderAPI_Transform, \ - BRepBuilderAPI_MakeEdge, \ - BRepBuilderAPI_MakeWire, \ - BRepBuilderAPI_MakeFace - -from OCC.Core.BRepPrimAPI import \ - BRepPrimAPI_MakeBox, \ - BRepPrimAPI_MakeSphere, \ - BRepPrimAPI_MakeCylinder, \ - BRepPrimAPI_MakeTorus - -from OCC.Core.BRepAdaptor import \ - BRepAdaptor_CompCurve - -from OCC.Core.BRepAlgoAPI import \ - BRepAlgoAPI_Fuse, \ - BRepAlgoAPI_Common, \ - BRepAlgoAPI_Cut, \ - BRepAlgoAPI_Section - -from OCC.Core.BRepOffsetAPI import \ - BRepOffsetAPI_MakePipe - -from OCC.Core.Geom import \ - Geom_Circle - -from OCC.Core.GeomAbs import \ - GeomAbs_C2 - -from OCC.Core.GCPnts import \ - GCPnts_UniformAbscissa - -from OCC.Core.GeomAPI import \ - GeomAPI_PointsToBSplineSurface - -from OCC.Core.STEPControl import \ - STEPControl_Writer, \ - STEPControl_AsIs - -from OCC.Core.TColgp import \ - TColgp_Array1OfPnt, \ - TColgp_Array2OfPnt - -from OCC.Core.TopAbs import \ - TopAbs_EDGE, \ - TopAbs_FACE, \ - TopAbs_SHELL, \ - TopAbs_VERTEX, \ - TopAbs_WIRE, \ - TopAbs_SOLID, \ - TopAbs_COMPOUND, \ - TopAbs_COMPSOLID - -from OCC.Core.TopExp import \ - TopExp_Explorer - -from OCC.Core.TopoDS import \ - topods_Edge, \ - TopoDS_Edge, \ - topods_Face, \ - topods_Shell, \ - topods_Vertex, \ - topods_Wire, \ - TopoDS_Wire, \ - topods_Solid, \ - topods_Compound, \ - topods_CompSolid - -from OCC.Extend.DataExchange import \ - write_stl_file, \ - read_stl_file, \ - read_step_file - -from OCC.Core.BRepFilletAPI import \ - BRepFilletAPI_MakeFillet - -from OCC.Extend.TopologyUtils import \ - TopologyExplorer - -from OCC.Extend.ShapeFactory import \ - get_oriented_boundingbox - -from OCCUtils.Common import \ - filter_points_by_distance, \ - curve_length - -# 3D Viewer ------------------------------------------ - -from OCC.Display.SimpleGui import init_display -display, start_display, add_menu, add_function_to_menu = init_display() -add_menu('View') - -def Fit_All(): - display.FitAll() - -def Iso_View(): - display.View_Iso() - display.FitAll() - -def Top_View(): - display.View_Top() - display.FitAll() - -def Left_View(): - display.View_Left() - display.FitAll() - -def Front_View(): - display.View_Front() - display.FitAll() - -def Right_View(): - display.View_Right() - display.FitAll() - -def Bottom_View(): - display.View_Bottom() - display.FitAll() - -def Rear_View(): - display.View_Rear() - display.FitAll() - - -add_function_to_menu('View', Fit_All) -add_function_to_menu('View', Iso_View) -add_function_to_menu('View', Top_View) -add_function_to_menu('View', Left_View) -add_function_to_menu('View', Front_View) -add_function_to_menu('View', Right_View) -add_function_to_menu('View', Bottom_View) -add_function_to_menu('View', Rear_View) - -# ----------------------------------------------------- -# Base Classes - - -class PythonOCCNodeBase(Node): - - def get_inputs(self): - return (self.input(i) for i in range(len(self.inputs))) - - -class PythonOCCNodeBase_DynamicInputs(PythonOCCNodeBase): - - def __init__(self, params): - super().__init__(params) - - self.num_inputs = 0 - - def setup_actions(self): - self.actions = {} - self.actions['add input'] = {'method': self.add_operand_input} - self.actions['rem input'] = {} - - 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) - - def add_operand_input(self): - self.create_input_dt(dtype=dtypes.Data(size='s')) - self.register_new_operand_input(self.num_inputs) - 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))])) - - def apply_op(self, elements: list): - return None - - -# ------------------------------------------- - -# GP ---------------------------------------- - - -class GpNodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#5e0a91' - - -class Pnt_Node(GpNodeBase): - """ - Generates Point_______- - o_X___________________- - o_Y___________________- - o_Z___________________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - x, y, z = self.clean(self.get_inputs()) - self.set_output_val(0, gp_Pnt(x, y, z)) - - def clean(self, coords): - """Returns a tuple of coords where `None` values are replaced by 0""" - return ( (c if c is not None else 0) for c in coords ) - - -class PointZero_Node(GpNodeBase): - """ - Generates Point Zero__- - """ - - title = 'Point0' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - point = gp_Pnt(0,0,0) - self.set_output_val(0, point) - - -class DeconstructPnt_Node(GpNodeBase): - """ - Deconstruct Point_____- - o_Point_______________- - """ - - title = 'deconstruct point' - - init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP('X'), - NodeOutputBP('Y'), - NodeOutputBP('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()) - - -class Vec_Node(GpNodeBase): - """ - Generates Vector______- - o_X___________________- - o_Y___________________- - o_Z___________________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - x, y, z = self.get_inputs() - self.set_output_val(0, gp_Vec(x, y, z)) - - -class DX_Node(GpNodeBase): - """ - Generates Dir X____- - """ - - title = 'DirX' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - dx = gp_DX() - self.set_output_val(0, dx) - - -class DY_Node(GpNodeBase): - """ - Generates Dir Y____- - """ - - title = 'DirY' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - dy = gp_DY() - self.set_output_val(0, dy) - - -class DZ_Node(GpNodeBase): - """ - Generates Dir Z____- - """ - - title = 'DirZ' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - dz = gp_DZ() - self.set_output_val(0, dz) - - -class Dir_Node(GpNodeBase): - """ - Generates Dir_______- - o_X___________________- - o_Y___________________- - o_Z___________________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - x, y, z = self.get_inputs() - self.set_output_val(0, gp_Dir(x, y, z)) - - -class Ax2_Node(GpNodeBase): - """ - Generates Ax2_________- - o_Point_______________- - o_Dir_________________- - """ - - title = 'Ax2' - - init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('dir', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - point, dir_ = self.get_inputs() - self.set_output_val(0, gp_Ax2(point, dir_)) - -class XOY_Node(GpNodeBase): - """ - Generates Ax Z____- - """ - - title = 'AxZ' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - axz = gp_XOY() - self.set_output_val(0, axz) - -class YOZ_Node(GpNodeBase): - """ - Generates Ax X____- - """ - - title = 'AxX' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - axx = gp_YOZ() - self.set_output_val(0, axx) - -class ZOX_Node(GpNodeBase): - """ - Generates Ax Y____- - """ - - title = 'AxY' - - init_outputs = [ - NodeOutputBP(), - ] - - def place_event(self): - axy = gp_ZOX() - self.set_output_val(0, axy) - -class Pln_Node(GpNodeBase): - """ - Generates Plane_______- - o_Point_______________- - o_Dir_________________- - """ - - title = 'Plane' - - init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('dir', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - point, dir_ = self.get_inputs() - self.set_output_val(0, gp_Pln(point, dir_)) - - -class Trsf_Node(GpNodeBase): - """ - Generates transform___- - o_[Shapes]____________- - o_[Vectors]___________- - """ - - title = 'Transform' - - init_inputs = [ - NodeInputBP('shapes', dtype=dtypes.Data(size='s')), - NodeInputBP('vectors', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shapes, vectors = self.get_inputs() - result = [] - - if isinstance(shapes, list) and isinstance(vectors, list): - for sh, v in zip(shapes, vectors): - trns = gp_Trsf() - trns.SetTranslation(v) - if isinstance(sh, gp_Pnt): - sh2 = sh - sh2.Transform(trns) - translated = sh2 - else: - translated = BRepBuilderAPI_Transform(sh, trns).Shape() - result.append(translated) - self.set_output_val(0, result) - - elif isinstance(shapes, list) and not isinstance(vectors, list): - for sh in (shapes): - trns = gp_Trsf() - trns.SetTranslation(vectors) - if isinstance(sh, gp_Pnt): - sh2 = sh - sh2.Transform(trns) - translated = sh2 - else: - translated = BRepBuilderAPI_Transform(sh, trns).Shape() - result.append(translated) - self.set_output_val(0, result) - - elif not isinstance(shapes, list) and isinstance(vectors, list): - for v in (vectors): - trns = gp_Trsf() - trns.SetTranslation(v) - if isinstance(shapes, gp_Pnt): - sh2 = shapes - sh2.Transform(trns) - translated = sh2 - else: - translated = BRepBuilderAPI_Transform(shapes, trns).Shape() - result.append(translated) - self.set_output_val(0, result) - - else: - trns = gp_Trsf() - trns.SetTranslation(vectors) - if isinstance(shapes, gp_Pnt): - sh2 = shapes - sh2.Transform(trns) - translated = sh2 - else: - translated = BRepBuilderAPI_Transform(shapes, trns).Shape() - self.set_output_val(0, translated) - - -class Move2pts_Node(GpNodeBase): - """ - Move 2 points_________- - o_from pnt____________- - o_to pnt______________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shapes, from_pnt, to_pnt = self.get_inputs() - vectors = [] - result = [] - - if isinstance(from_pnt, list): - for f, t in zip(from_pnt, to_pnt): - v = gp_Vec() - x = t.X() - f.X() - y = t.Y() - f.Y() - z = t.Z() - f.Z() - v.SetCoord(x, y, z) - vectors.append(v) - for sh, v, in zip(shapes, vectors): - trns = gp_Trsf() - trns.SetTranslation(v.Reversed()) - translated = BRepBuilderAPI_Transform(sh, trns).Shape() - result.append(translated) - self.set_output_val(0, result) - - else: - v = gp_Vec() - x = to_pnt.X() - from_pnt.X() - y = to_pnt.Y() - from_pnt.Y() - z = to_pnt.Z() - from_pnt.Z() - v.SetCoord(x, y, z) - trns = gp_Trsf() - trns.SetTranslation(v.Reversed()) - translated = BRepBuilderAPI_Transform(shapes, trns).Shape() - self.set_output_val(0, translated) - - -class MidPoint_Node(GpNodeBase): - """ - MidPoint_____________- - o_Point A____________- - o_Point B______________- - """ - - title = 'MidPoint' - - init_inputs = [ - NodeInputBP('pointA', dtype=dtypes.Data(size='s')), - NodeInputBP('pointB', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - pointA, pointB = self.get_inputs() - vec1 = gp_Vec(pointA.XYZ()) - vec2 = gp_Vec(pointB.XYZ()) - midvec = (vec1 + vec2) / 2. - midpoint = gp_Pnt(midvec.XYZ()) - self.set_output_val(0, midpoint) - - -Gp_nodes = [ - Pnt_Node, - DeconstructPnt_Node, - PointZero_Node, - Dir_Node, - Vec_Node, - DX_Node, - DY_Node, - DZ_Node, - Ax2_Node, - XOY_Node, - YOZ_Node, - ZOX_Node, - Pln_Node, - Trsf_Node, - Move2pts_Node, - MidPoint_Node, -] - - -# ------------------------------------------- - -# BREPBUILDERAPI----------------------------- - - -class BrepBuilderAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#DAA520' - - -class TwoPtsEdge_Node(BrepBuilderAPINodeBase): - """ - Generates 2 pts Edge__- - o_Point_______________- - o_Point_______________- - """ - - title = '2ptsEdge' - - init_inputs = [ - NodeInputBP('pnt1', dtype=dtypes.Data(size='s')), - NodeInputBP('Pnt2', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - pnt1, pnt2 = self.get_inputs() - - if isinstance(pnt1, list): - edges = [] - for p1, p2 in zip(pnt1, pnt2): - edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() - edges.append(edge) - self.set_output_val(0, edges) - - else: - edge = BRepBuilderAPI_MakeEdge(pnt1, pnt2).Edge() - self.set_output_val(0, edge) - - -class Wire_Node(BrepBuilderAPINodeBase): - """ - Generates Wire________- - o_List of Points______- - """ - - title = 'Wire' - - init_inputs = [ - NodeInputBP('pntslist', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - - for pointlist in self.get_inputs(): - pointsarray = TColgp_Array1OfPnt(1, len(pointlist)) - for n, i in enumerate(pointlist): - pointsarray.SetValue(n + 1, i) - wirebuild = BRepBuilderAPI_MakeWire() - for i in range(1, len(pointlist)): - edgepoint = BRepBuilderAPI_MakeEdge(pointsarray.Value(i), pointsarray.Value(i + 1)).Edge() - wirebuild.Add(edgepoint) - - self.set_output_val(0, wirebuild.Shape()) - - -class WireFillet2d_Node(BrepBuilderAPINodeBase): - """ - Generates 2dWireFillet_- - o_List of Points______- - o_Fillet Radius_______- - """ - - title = '2dWireFillet' - - init_inputs = [ - NodeInputBP('pntslist', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - pointlist, radius = self.get_inputs() - if radius == 0: - radius = 0.01 - - pointsarray = TColgp_Array1OfPnt(1, len(pointlist)) - for n, i in enumerate(pointlist): - pointsarray.SetValue(n + 1, i) - - edges = {} - ijk = 0 - for i in range(1, len(pointlist)): - edges[ijk] = BRepBuilderAPI_MakeEdge(pointsarray.Value(i), pointsarray.Value(i + 1)).Edge() - ijk += 1 - edges_list = list(edges.values()) - wirebuild = BRepBuilderAPI_MakeWire() - - for index, edge in enumerate(edges_list[:-1]): - f = ChFi2d_AnaFilletAlgo() - f.Init(edges_list[index], edges_list[index+ 1], gp_Pln()) - f.Perform(radius) - fillet = f.Result(edges_list[index], edges_list[index + 1]) - wirebuild.Add(edge) - wirebuild.Add(fillet) - - wirebuild.Add(edges_list[-1]) - self.set_output_val(0, wirebuild.Shape()) - - -class DiscretizeWire_Node(BrepBuilderAPINodeBase): - """ - Discretize Wire_______- - o_Wire________________- - o_Nb of points________- - """ - - title = 'DiscretizeWire' - - init_inputs = [ - NodeInputBP('Wire', dtype=dtypes.Data(size='s')), - NodeInputBP('Nb', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - wire, nbpts = self.get_inputs() - pnts = [] # points to create bsplines - if isinstance(wire, TopoDS_Edge): - wire = BRepBuilderAPI_MakeWire(wire).Wire() - curve_adapt = BRepAdaptor_CompCurve(wire) - # print(curve_adapt) - _lbound, _ubound = curve_adapt.FirstParameter(), curve_adapt.LastParameter() - npts = GCPnts_UniformAbscissa(curve_adapt, nbpts, _lbound, _ubound) - 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) - # print(tmp) - -class CurveLength_Node(BrepBuilderAPINodeBase): - """ - Curve Length__________- - o_Wire/Edge(L)________- - """ - - title = 'CurveLength' - - init_inputs = [ - NodeInputBP('Wire/Edge', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - lengths = [] - for curve in self.get_inputs(): - lengths.append(curve_length(curve)) - self.set_output_val(0, lengths) - # print(tmp) - - -BRepBuilderAPI_nodes = [ - TwoPtsEdge_Node, - Wire_Node, - WireFillet2d_Node, - DiscretizeWire_Node, - CurveLength_Node, -] - - -# ------------------------------------------- - -# BREPOFFSETAPI------------------------------ - - -class BrepOffsetAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#aabb44' - - -class Pipe_Node(BrepOffsetAPINodeBase): - """ - Generates pipe________- - o_Wire________________- - o_Radius______________- - """ - - title = 'pipe' - - init_inputs = [ - NodeInputBP('wire', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - wire, radius = self.get_inputs() - - if type(wire) is list: - pipes = [] - for w in wire: - if isinstance(w, TopoDS_Edge): - w = BRepBuilderAPI_MakeWire(w).Wire() - topexp_vertex = TopExp_Explorer() - topexp_vertex.Init(w, TopAbs_VERTEX) - vertices = [] - while topexp_vertex.More(): - vert = topods_Vertex(topexp_vertex.Current()) - point = BRep_Tool.Pnt(vert) - vertices.append(point) - topexp_vertex.Next() - dir_ = gp_Dir(vertices[1].X()-vertices[0].X(), vertices[1].Y()-vertices[0].Y(), vertices[1].Z()-vertices[0].Z()) - if radius == 0: - radius = 0.01 - circle = gp_Circ(gp_Ax2(vertices[0], dir_), radius) - profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() - profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire() - profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() - pipe = BRepOffsetAPI_MakePipe(w, profile_face).Shape() - pipes.append(pipe) - self.set_output_val(0, pipes) - - else: - if isinstance(wire, TopoDS_Edge): - wire = BRepBuilderAPI_MakeWire(wire).Wire() - topexp_vertex = TopExp_Explorer() - topexp_vertex.Init(wire, TopAbs_VERTEX) - vertices = [] - while topexp_vertex.More(): - vert = topods_Vertex(topexp_vertex.Current()) - point = BRep_Tool.Pnt(vert) - vertices.append(point) - topexp_vertex.Next() - dir_ = gp_Dir(vertices[1].X() - vertices[0].X(), vertices[1].Y() - vertices[0].Y(), vertices[1].Z() - vertices[0].Z()) - if radius == 0: - radius = 0.01 - circle = gp_Circ(gp_Ax2(vertices[0], dir_), radius) - profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() - 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) - - -BRepOffsetAPI_nodes = [ - Pipe_Node, -] - - -# ------------------------------------------- - -# BREPPRIMAPI -------------------------------- - - -class BrepPrimAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#aabb44' - - -class Box_Node(BrepPrimAPINodeBase): - """ - Generates box_________- - o_Width_______________- - o_Length______________- - o_Height______________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - 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) - - -class Sphere_Node(BrepPrimAPINodeBase): - """ - Generates sphere_________- - o_Center point/ax2_______- - o_Radius_________________- - """ - - title = 'sphere' - - init_inputs = [ - NodeInputBP('point', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - point, radius = self.get_inputs() - sphere = BRepPrimAPI_MakeSphere(point, radius).Shape() - self.set_output_val(0, sphere) - - -class Cylinder_Node(BrepPrimAPINodeBase): - """ - Generates cylinder_______- - o_Axe____________________- - o_Radius_________________- - o_Length_________________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - 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) - -class Torus_Node(BrepPrimAPINodeBase): - """ - Generates torus__________- - o_Ax2____________________- - o_Distance center/center_- - o_Radius_________________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - 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) - - -BRepPrimAPI_nodes = [ - Box_Node, - Sphere_Node, - Cylinder_Node, - Torus_Node, -] - - -# ------------------------------------------- - -# BREPALGOAPI -------------------------------- - - -class BrepAlgoAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#ab0c36' - - -class Fuse_Node(BrepAlgoAPINodeBase): - """ - Generates fusion_________- - o_Part 1 (or list)_______- - o_Part 2_________________- - """ - - title = 'fuse' - - init_inputs = [ - NodeInputBP('a', dtype=dtypes.Data(size='s')), - NodeInputBP('b', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - a, b = self.get_inputs() - if type(a) is list: - count = len(a) - fuse_shps = {} - ijk = 0 - fuse_shps[ijk] = BRepAlgoAPI_Fuse(a[0], a[1]).Shape() - 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]) - else: - fuse_shp = BRepAlgoAPI_Fuse(a, b).Shape() - self.set_output_val(0, fuse_shp) - - -class Common_Node(BrepAlgoAPINodeBase): - """ - Generates common_________- - o_Part 1_________________- - o_Part 2_________________- - """ - - title = 'common' - - init_inputs = [ - NodeInputBP('a', dtype=dtypes.Data(size='s')), - NodeInputBP('b', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - 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) - - -class Cut_Node(BrepAlgoAPINodeBase): - """ - Generates cutting________- - o_Basis__________________- - o_Cutter (or list)_______- - """ - - title = 'cut' - - init_inputs = [ - NodeInputBP('Basis', dtype=dtypes.Data(size='s')), - NodeInputBP('Cutter', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - basis, cutter = self.get_inputs() - if type(cutter) is list and type(basis) is not list: - count = len(cutter) - cut_shps = {} - ijk = 0 - cut_shps[ijk] = BRepAlgoAPI_Cut(basis, cutter[0]).Shape() - 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]) - 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) - else: - cut_shp = BRepAlgoAPI_Cut(basis, cutter).Shape() - self.set_output_val(0, cut_shp) - -class Section_Node(BrepAlgoAPINodeBase): - """ - Generates Sections_______- - o_Basis__________________- - o_Cutter (or list)_______- - """ - - title = 'section' - - init_inputs = [ - NodeInputBP('Basis', dtype=dtypes.Data(size='s')), - NodeInputBP('Cutter', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - basis, cutter = self.get_inputs() - if None not in (basis, cutter): - if type(cutter) is list and type(basis) is not list: - count = len(cutter) - cut_shps = {} - ijk = 0 - cut_shps[ijk] = BRepAlgoAPI_Section(basis, cutter[0]).Shape() - 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]) - 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) - else: - cut_shp = BRepAlgoAPI_Section(basis, cutter).Shape() - self.set_output_val(0, cut_shp) - - -BRepAlgoAPI_nodes = [ - Fuse_Node, - Common_Node, - Cut_Node, - Section_Node, -] - - -# ------------------------------------------- - -# BREPFILLETAPI -------------------------------- - - -class BrepFilletAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#e0149c' - - -class Fillet_Node(BrepFilletAPINodeBase): - """ - Generates fillet_________- - o_Shape__________________- - o_Radius_________________- - """ - - title = 'fillet' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('radius', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shape, radius = self.get_inputs() - fill = BRepFilletAPI_MakeFillet(shape) - - for e in TopologyExplorer(shape).edges(): - fill.Add(e) - - for i in range(1, fill.NbContours() + 1): - length = fill.Length(i) - fill.SetRadius(radius, i, 1) - - blended_fused_solids = fill.Shape() - - self.set_output_val(0, blended_fused_solids) - - -BRepFilletAPI_nodes = [ - Fillet_Node, -] - - -# ------------------------------------------- - -# GEOMAPI------------------------------------ - -class GeomNodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#c91604' - -class Circle_Node(GeomNodeBase): - """ - Draw circle______________- - o_Ax2____________________- - o_Radius_________________- - """ - - title = 'Circle' - - init_inputs = [ - NodeInputBP('Ax2', dtype=dtypes.Data(size='s')), - NodeInputBP('Radius', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - axis, radius = self.get_inputs() - circle = Geom_Circle(axis, radius) - self.set_output_val(0, circle) - -Geom_nodes = [ - Circle_Node, -] - -# ------------------------------------------- - -# GEOMAPI------------------------------------ - -class GeomAPINodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#ff4633' - -class PointsSurface_Node(GeomAPINodeBase): - """ - Generates surface________- - o_List of points_________- - """ - - title = 'PointsSurface' - - init_inputs = [ - NodeInputBP('points', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - count = 0 - pts = {} - for l in self.get_inputs(): - pts[count] = l - nbpts = len(l) - count += 1 - pts_list = list(pts.values()) - array = TColgp_Array2OfPnt(1, nbpts, 1, len(pts_list)) # nbrow, nbcol - for c in range(count): - for n in range(nbpts): - 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) - - -GeomAPI_nodes = [ - PointsSurface_Node, -] - - -# ------------------------------------------- - -# SHAPE ANALYSIS -------------------------- - - -class TopExplorer_Node(PythonOCCNodeBase): - """ - Topology Explorer________- - o_Shape__________________- - """ - - title = 'topexp' - version = 'v0.1' - color = '#FF00FF' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP('vertex'), - NodeOutputBP('edges'), - NodeOutputBP('wires'), - NodeOutputBP('faces'), - NodeOutputBP('shells'), - NodeOutputBP('solids'), - NodeOutputBP('compounds'), - NodeOutputBP('compsolids'), - ] - - def update_event(self, inp=-1): - for shape in self.get_inputs(): - #find vertices - topexp_vertex = TopExp_Explorer() - topexp_vertex.Init(shape, TopAbs_VERTEX) - vertices = [] - while topexp_vertex.More(): - vert = topods_Vertex(topexp_vertex.Current()) - point = BRep_Tool.Pnt(vert) - vertices.append(point) - topexp_vertex.Next() - vertices_red = filter_points_by_distance(vertices, 0.01) - #find edges - topexp_edge = TopExp_Explorer() - topexp_edge.Init(shape, TopAbs_EDGE) - edges = [] - while topexp_edge.More(): - edge = topods_Edge(topexp_edge.Current()) - edges.append(edge) - topexp_edge.Next() - # find wires - topexp_wire = TopExp_Explorer() - topexp_wire.Init(shape, TopAbs_WIRE) - wires = [] - while topexp_wire.More(): - wire = topods_Wire(topexp_wire.Current()) - wires.append(wire) - topexp_wire.Next() - #find faces - topexp_face = TopExp_Explorer() - topexp_face.Init(shape, TopAbs_FACE) - faces = [] - while topexp_face.More(): - face = topods_Face(topexp_face.Current()) - faces.append(face) - topexp_face.Next() - #find shells - topexp_shell = TopExp_Explorer() - topexp_shell.Init(shape, TopAbs_SHELL) - shells = [] - while topexp_shell.More(): - shell = topods_Shell(topexp_shell.Current()) - shells.append(shell) - topexp_shell.Next() - # find solids - topexp_solid = TopExp_Explorer() - topexp_solid.Init(shape, TopAbs_SOLID) - solids = [] - while topexp_solid.More(): - solid = topods_Solid(topexp_solid.Current()) - solids.append(solid) - topexp_solid.Next() - # find compounds - topexp_compound = TopExp_Explorer() - topexp_compound.Init(shape, TopAbs_COMPOUND) - compounds = [] - while topexp_compound.More(): - compound = topods_Compound(topexp_compound.Current()) - compounds.append(compound) - topexp_compound.Next() - # find compsolids - topexp_compsolid = TopExp_Explorer() - topexp_compsolid.Init(shape, TopAbs_COMPSOLID) - compsolids = [] - while topexp_compsolid.More(): - compsolid = topods_CompSolid(topexp_compsolid.Current()) - 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) - - -class BoundingBox_Node(PythonOCCNodeBase): - """ - Bounding Box________- - o_Shape__________________- - """ - - title = 'bounding box' - version = 'v0.1' - color = '#FF00FF' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP('box'), - ] - - def update_event(self, inp=-1): - bboxes = [] - 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 - - -Shape_Analysis_nodes = [ - TopExplorer_Node, - BoundingBox_Node, -] - - -# ------------------------------------------- - -# DISPLAY -------------------------------- - - -class DisplayNodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#3355dd' - - -class Display_Node(DisplayNodeBase): - """ - display shapes - o_Shapes__________________- - """ - - title = 'display' - - init_inputs = [ - NodeInputBP('shapes', dtype=dtypes.Data(size='s')), - ] - - def update_event(self, inp=-1): - display.EraseAll() - for v in self.get_inputs(): - if v is None: - pass - elif type(v) is list : - for el in v: - if type(el) is list : - for e in el: - if type(e) is list: - shape = e[0] - colore = e[1] - display.DisplayShape(shape, color=colore) - else: - if isinstance(e, int): - shape = el[0] - colore = el[1] - display.DisplayShape(shape, color=colore) - else: - display.DisplayShape(e) - else: - if isinstance(el, int): - shape = v[0] - colore = v[1] - display.DisplayShape(shape, color=colore) - else: - display.DisplayShape(el) - else : - display.DisplayShape(v) - display.FitAll() - - -class Color_Node(DisplayNodeBase): - """ - Choose Color_____________- - o_Shape__________________- - o_QuantityColor(int)_____- - """ - - title = 'color' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('Int', dtype=dtypes.Data(size='s')), - ] - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shapecolored = [] - shape, colore = self.get_inputs() - if type(shape) is list: - for shp in shape: - shapecolored.append([shp, colore]) - self.set_output_val(0, shapecolored) - else: - shapecolored.append(shape) - shapecolored.append(colore) - self.set_output_val(0, shapecolored) - - -Display_nodes = [ - Display_Node, - Color_Node, -] - - -# ------------------------------------------- - -# TOOLS-------------------------------------- - - -class List_Node(PythonOCCNodeBase_DynamicInputs): - """ - Generates List_______- - o_A__________________- - o_B__________________- - """ - - title = 'List' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP(dtype=dtypes.Data(size='s')), - NodeInputBP(dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def apply_op(self, elements: list): - return elements - - -class ListLength_Node(PythonOCCNodeBase): - """ - List Length__________- - o_List_______________- - """ - - title = 'ListLength' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - 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) - else : - pass - - -class FlattenList_Node(PythonOCCNodeBase): - """ - Flatten list_________- - o_List_______________- - """ - - title = 'FlattenList' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - newlist = [] - for el in self.get_inputs(): - if type(el) is list: - for e in el: - if type(e) is list: - for a in e: - newlist.append(a) - else: - newlist.append(e) - else: - newlist.append(el) - self.set_output_val(0,newlist) - - -class ListItem_Node(PythonOCCNodeBase): - """ - Item list____________- - o_List_______________- - o_Indec______________- - """ - - title = 'ListItem' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('list', dtype=dtypes.Data(size='s')), - NodeInputBP('index', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - reflist, index = self.get_inputs() - self.set_output_val(0, reflist[index]) - - -class RepeatData_Node(PythonOCCNodeBase): - """ - Repeat Data__________- - o_Data as List_______- - o_Length of repeat___- - """ - - title = 'RepeatData' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('Data', dtype=dtypes.Data(size='s')), - NodeInputBP('Length', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - Data, Length = self.get_inputs() - repeat = [] - for l in range(Length): - if type(Data) is list: - for d in Data: - repeat.append(d) - else: - repeat.append(Data) - self.set_output_val(0, repeat) - - -class Serie_Node(PythonOCCNodeBase): - """ - Create Serie_________- - o_Start______________- - o_Step_______________- - o_Length_____________- - """ - - title = 'Serie' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('Start', dtype=dtypes.Data(size='s')), - NodeInputBP('Step', dtype=dtypes.Data(size='s')), - NodeInputBP('Length', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - Start, Step, Length = self.get_inputs() - serie = [] - count = Start - serie.append(Start) - for l in range(Length-1): - count += Step - serie.append(count) - self.set_output_val(0, serie) - -class ShiftList_Node(PythonOCCNodeBase): - """ - Shift List___________- - o_List_______________- - o_Shift value________- - """ - - title = 'ShiftLIst' - version = 'v0.1' - color = '#000000' - - init_inputs = [ - NodeInputBP('List', dtype=dtypes.Data(size='s')), - NodeInputBP('ShiftValue', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - list_, value = self.get_inputs() - shifted_list = [] - if value < 0: - for i in range(len(list_) - value): - shifted_list.append(list_[i]) - elif value > 0: - for i in range(value, len(list_)): - shifted_list.append(list_[i]) - self.set_output_val(0, shifted_list) - - -Tools_nodes = [ - List_Node, - ListLength_Node, - FlattenList_Node, - ListItem_Node, - RepeatData_Node, - Serie_Node, - ShiftList_Node, -] - - -# -------------------------------------------------------- - -# DATA EXCHANGE------------------------------------------ - - -class DataExchangeNodeBase(PythonOCCNodeBase): - version = 'v0.1' - color = '#6b6767' - - -class ExportStep_Node(DataExchangeNodeBase): - """ - Generates Step_______- - o_Shape______________- - o_Name_______________- - """ - - title = 'ExportStep' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('fname', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shape, filename = self.get_inputs() - step_writer = STEPControl_Writer() - step_writer.Transfer(shape, STEPControl_AsIs) - status = step_writer.Write(str(filename)+'.stp') - - -class ImportStep_Node(DataExchangeNodeBase): - """ - Import Step__________- - o_Filename___________- - """ - - title = 'ImportStep' - doc = 'returns the evaluated text that is typed into the input field' - init_outputs = [ - NodeOutputBP(), - ] - main_widget_class = widgets.ImportFileNode_MainWidget - main_widget_pos = 'between ports' - style = 'normal' - - 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() - - def view_place_event(self): - self.main_widget().value_changed.connect(self.main_widget_string_changed) - - def main_widget_string_changed(self, string): - self.string = string - self.update() - - 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() - - - def get_current_var_name(self): - return self.input(0) - - - def get_state(self): - return { - 'string': self.string # self.main_widget().get_val() - } - - def set_state(self, data, version): - self.string = data['string'] - - -class ExportStl_Node(DataExchangeNodeBase): - """ - Generates Stl________- - o_Shape______________- - o_Name_______________- - """ - - title = 'ExportStl' - - init_inputs = [ - NodeInputBP('shape', dtype=dtypes.Data(size='s')), - NodeInputBP('name', dtype=dtypes.Data(size='s')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - shape, filename = self.get_inputs() - status = write_stl_file(shape, str(filename)+'.stl', mode="ascii", linear_deflection=0.9, angular_deflection=0.5) - - -class ImportStl_Node(DataExchangeNodeBase): - """ - Import Stl___________- - o_Filename___________- - """ - - title = 'ImportStl' - doc = 'returns the evaluated text that is typed into the input field' - init_outputs = [ - NodeOutputBP(), - ] - main_widget_class = widgets.ImportFileNode_MainWidget - main_widget_pos = 'between ports' - style = 'normal' - - 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() - - def view_place_event(self): - self.main_widget().value_changed.connect(self.main_widget_string_changed) - - def main_widget_string_changed(self, string): - self.string = string - self.update() - - 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() - - - def get_current_var_name(self): - return self.input(0) - - - def get_state(self): - return { - 'string': self.string # self.main_widget().get_val() - } - - def set_state(self, data, version): - self.string = data['string'] - -class ExportGcode_Node(DataExchangeNodeBase): - """ - Generates Gcode______- - o_List of point______- - o_Name_______________- - o_Speed______________- - """ - - 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')), - ] - - init_outputs = [ - NodeOutputBP(), - ] - - def update_event(self, inp=-1): - points, filename, speed = self.get_inputs() - with open(str(filename)+'.gcode', 'w') as file: - for point in points: - file.write('G1 X' + str(point.X()) + ' Y' + str(point.Y()) + ' Z' + str(point.Z()) + ' F' + str(speed) + '\n') - - -DataExchange_nodes = [ - ExportStep_Node, - ImportStep_Node, - ExportStl_Node, - ImportStl_Node, - ExportGcode_Node, -] - - -# ------------------------------------------- - - -export_nodes( - *Gp_nodes, - *BRepBuilderAPI_nodes, - *BRepOffsetAPI_nodes, - *BRepPrimAPI_nodes, - *BRepAlgoAPI_nodes, - *BRepFilletAPI_nodes, - *Geom_nodes, - *GeomAPI_nodes, - *Shape_Analysis_nodes, - *Display_nodes, - *Tools_nodes, - *DataExchange_nodes, -) From aebaa262f7b49505f5bd3f67b63d9c3a1f5e1477 Mon Sep 17 00:00:00 2001 From: leon-thomm Date: Sat, 29 Apr 2023 23:06:46 +0200 Subject: [PATCH 2/5] nodes package fully adapted --- PythonOCC/gui.py | 254 +++++++++++++ PythonOCC/nodes.py | 869 ++++++++++++++++++++++++++----------------- PythonOCC/widgets.py | 42 --- 3 files changed, 785 insertions(+), 380 deletions(-) create mode 100644 PythonOCC/gui.py delete mode 100644 PythonOCC/widgets.py diff --git a/PythonOCC/gui.py b/PythonOCC/gui.py new file mode 100644 index 0000000..7fee42c --- /dev/null +++ b/PythonOCC/gui.py @@ -0,0 +1,254 @@ +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 isinstance(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_DynamicImportsGui(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 + + # for debugging only + 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(PythonOCCNodeGuiBase): + 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_DynamicImportsGui, + 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..be9cbbe 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_DynamicImportsGui - 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 From c0c01782c5546ffbadad2e634852f2565b3e1c32 Mon Sep 17 00:00:00 2001 From: leon-thomm Date: Sun, 30 Apr 2023 11:43:21 +0200 Subject: [PATCH 3/5] brings back OCCUtils.edge.Edge had top upgrade pythonocc-core --- PythonOCC/nodes.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/PythonOCC/nodes.py b/PythonOCC/nodes.py index be9cbbe..24b5a51 100644 --- a/PythonOCC/nodes.py +++ b/PythonOCC/nodes.py @@ -122,8 +122,7 @@ filter_points_by_distance, \ curve_length -# TODO: Edge import causes crash -# from OCCUtils.edge import Edge +from OCCUtils.edge import Edge # @@ -760,9 +759,6 @@ class Get_dir_from_edge_Node(GpNodeBase): ] 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()) From db6d9070d017833deec5c623752ccae927135591 Mon Sep 17 00:00:00 2001 From: leon-thomm Date: Sun, 30 Apr 2023 11:47:59 +0200 Subject: [PATCH 4/5] nevermind still crashes --- PythonOCC/nodes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PythonOCC/nodes.py b/PythonOCC/nodes.py index 24b5a51..be9cbbe 100644 --- a/PythonOCC/nodes.py +++ b/PythonOCC/nodes.py @@ -122,7 +122,8 @@ filter_points_by_distance, \ curve_length -from OCCUtils.edge import Edge +# TODO: Edge import causes crash +# from OCCUtils.edge import Edge # @@ -759,6 +760,9 @@ class Get_dir_from_edge_Node(GpNodeBase): ] 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()) From 7d5dfd2ce36b08bf637ddf687e3c0fce104b152b Mon Sep 17 00:00:00 2001 From: leon-thomm Date: Sat, 13 May 2023 18:32:34 +0200 Subject: [PATCH 5/5] fix GUI class overwrite --- PythonOCC/gui.py | 9 ++++----- PythonOCC/nodes.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/PythonOCC/gui.py b/PythonOCC/gui.py index 7fee42c..8c960af 100644 --- a/PythonOCC/gui.py +++ b/PythonOCC/gui.py @@ -41,7 +41,7 @@ def decorator(cls): for i, widget_name in enumerate(input_widgets) if widget_name is not None } - if not isinstance(cls.GUI, PythonOCCNodeGuiBase): + if not issubclass(cls.GUI, PythonOCCNodeGuiBase): # override GUI class class AutoInputWidgets_NodeGui(PythonOCCNodeGuiBase): init_input_widgets = inp_widgets @@ -59,7 +59,7 @@ class AutoInputWidgets_NodeGui(PythonOCCNodeGuiBase): # -class PyOCCBase_DynamicImportsGui(PythonOCCNodeGuiBase): +class PyOCCBase_DynamicInputsGui(PythonOCCNodeGuiBase): def __init__(self, params): super().__init__(params) @@ -73,7 +73,6 @@ def initialized(self): self.num_inputs = len(self.node.inputs) # the actions are restrored automatically - # for debugging only self.actions['remove input'] = { i: { 'method': self.remove_operand_input, @@ -142,7 +141,7 @@ class DisplayNodeGui(PythonOCCNodeGuiBase): color = '#3355dd' -class ListGui(PythonOCCNodeGuiBase): +class ListGui(PyOCCBase_DynamicInputsGui): color = '#000000' @@ -227,7 +226,7 @@ class ImportFileNode_Gui(NodeGUI): export_guis([ PythonOCCNodeGuiBase, - PyOCCBase_DynamicImportsGui, + PyOCCBase_DynamicInputsGui, GuiBuilder, GpNodeGui, diff --git a/PythonOCC/nodes.py b/PythonOCC/nodes.py index be9cbbe..2b25885 100644 --- a/PythonOCC/nodes.py +++ b/PythonOCC/nodes.py @@ -248,7 +248,7 @@ def have_gui(self): class PythonOCCNodeBase_DynamicInputs(PythonOCCNodeBase): - GUI = guis.PyOCCBase_DynamicImportsGui + GUI = guis.PyOCCBase_DynamicInputsGui num_init_inputs = 0