Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Introducing "Solid Section" node #4878

Merged
merged 8 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions docs/nodes/solid/solid_section.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Solid Section
=============

.. image:: https://user-images.githubusercontent.com/66558924/212058287-c0426edb-7f56-425d-8e7c-cc99ff8700c7.jpg

Dependencies
------------

This node requires `FreeCAD library <https://nortikin.github.io/sverchok/docs/data_structure/solids.html>`_ to work.


Functionality
-------------

This node generates the intersection Curves and Points between different Shapes including Solids, Solid Faces, Solid Edges, NURBS Surfaces and NURBS Curves.

The node can operate on pair of objects ("Shape A" intersects "Shape B") or on pair of lists of objects.

Inputs
------

This node has the following inputs:

* **Shape A**. The first object to perform operation on. This input is
mandatory and can accept a list of Shapes*.
* **Shape B**. The second object to perform operation on. This input is
mandatory and can accept a list of Shapes*.

Curves (NURBS Curves and Solid Edges) cannot be mixed with other Shape types.
For example [<NURBS_Curve>, <Solid_Edge>, <Solid>] is not a valid input list.

Valid inputs are [<NURBS_Curve1>, <NURBS_Curve2>, <Solid_Edge>] or [<NURBS_Curve>, <Solid_Edge>]
or [<NURBS_Surface1>, <Solid>, <NURBS_Surface2>] etc.

Options
-------

This node has the following parameters:

* **NURBS Output**. This parameter is available in the N panel only. If
checked, the node will generate curves in NURBS representation. Otherwise, it
will generate standard FreeCAD curves (Solid Edge curves). Unchecked by default.

Outputs
-------

This node has the following outputs:

* **Vertices**. The resulting intersection (puncture) Points or endpoints of the intersection Curves.
* **Curves**. The resulting intersection Curves.

Product variations of the Section operation:

* Solid × Curve → Point (common case) or Curve (if the curve or part of the curve overlays with the solid)

* Solid × Surface → Curve (common case) or Point (when both are only touching)

* Curve × Surface → Point (common case) or Curve (if the curve or part of the curve overlays with the surface)

* Solid × Solid → Curve (common case) or Point (when both are only touching)

* Surface × Surface → Curve (common case) or Point (when both are only touching)

* Curve × Curve → Point (common case) or Curve (if curves overlay at a certain segment)


If no intersections are found the node will output empty lists.


Examples
--------

**Curve** × **Curve** → **Points**:

.. image:: https://user-images.githubusercontent.com/66558924/212648237-1f4f052f-1a61-496c-a0db-27eebb8c9524.jpg



**Curves** × **Surface** → **Points and Curve**:

.. image:: https://user-images.githubusercontent.com/66558924/212650377-26c0af14-1b6d-4039-b655-7719ae4dee03.jpg


**Surface** × **List of Surfaces** → **Curves**:

.. image:: https://user-images.githubusercontent.com/66558924/212664158-65bc2f04-0376-4b8a-bbbf-05812fc4e76e.jpg


**Surface** × **Solid** → **Curves**:

.. image:: https://user-images.githubusercontent.com/66558924/212653198-d616f3ad-d533-4409-a2bf-2e65213f6939.jpg


1 change: 1 addition & 0 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
- SvChamferSolidNode
- SvFilletSolidNode
- SvSolidBooleanNode
- SvSolidSectionNode
- SvSolidGeneralFuseNode
- SvMirrorSolidNode
- SvOffsetSolidNode
Expand Down
1 change: 1 addition & 0 deletions menus/full_by_data_type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
- SvChamferSolidNode
- SvFilletSolidNode
- SvSolidBooleanNode
- SvSolidSectionNode
- SvSolidGeneralFuseNode
- SvMirrorSolidNode
- SvOffsetSolidNode
Expand Down
1 change: 1 addition & 0 deletions menus/full_nortikin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
- SvChamferSolidNode
- SvFilletSolidNode
- SvSolidBooleanNode
- SvSolidSectionNode
- SvSolidGeneralFuseNode

- ---
Expand Down
107 changes: 107 additions & 0 deletions nodes/solid/solid_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE

import bpy
from bpy.props import BoolProperty

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (updateNode, map_recursive, zip_long_repeat,
ensure_nesting_level, get_data_nesting_level)
from sverchok.utils.curve.freecad import SvSolidEdgeCurve
from sverchok.dependencies import FreeCAD

if FreeCAD is not None:
import Part

class SvSolidSectionNode(SverchCustomTreeNode, bpy.types.Node):
"""
Triggers: Section
Tooltip: Generate Intersection Curves and Points
"""
bl_idname = 'SvSolidSectionNode'
bl_label = 'Solid Section'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_SOLID_SECTION'
sv_category = "Solid Operators"
sv_dependencies = {'FreeCAD'}

nurbs_output : BoolProperty(
name = "NURBS Output",
description = "Output curves in NURBS representation",
default = False,
update=updateNode)

def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)
layout.prop(self, 'nurbs_output', toggle=True)

def sv_init(self, context):
self.inputs.new('SvSolidSocket', "Shape A")
self.inputs.new('SvSolidSocket', "Shape B")

self.outputs.new('SvVerticesSocket', "Vertices")
self.outputs.new('SvCurveSocket', "Curves")

def make_solid(self, solids):
rendetto marked this conversation as resolved.
Show resolved Hide resolved
base = solids[0].copy()
rest = solids[1:]
solid = base.section(rest)
return solid

def process(self):
if not any(socket.is_linked for socket in self.outputs):
return

solids_out = []

solids_a_in = self.inputs['Shape A'].sv_get()
solids_b_in = self.inputs['Shape B'].sv_get()
level_a = get_data_nesting_level(solids_a_in, data_types=(Part.Shape,))
level_b = get_data_nesting_level(solids_b_in, data_types=(Part.Shape,))
solids_a_in = ensure_nesting_level(solids_a_in, 2, data_types=(Part.Shape,))
solids_b_in = ensure_nesting_level(solids_b_in, 2, data_types=(Part.Shape,))
level = max(level_a, level_b)

for params in zip_long_repeat(solids_a_in, solids_b_in):
new_solids = []
for solid_a, solid_b in zip_long_repeat(*params):
result = self.make_solid([solid_a, solid_b])
new_solids.append(result)
solids_out.extend(new_solids)

def get_verts(solid):
verts = []
for v in solid.Vertexes:
verts.append(v.Point[:])
return verts

def get_edges(solid):
edges_curves = []
for e in solid.Edges:
try:
curve = SvSolidEdgeCurve(e)
if self.nurbs_output:
curve = curve.to_nurbs()
edges_curves.append(curve)
except TypeError:
pass
return edges_curves

verts_out = map_recursive(get_verts, solids_out, data_types=(Part.Shape,))
edges_out = map_recursive(get_edges, solids_out, data_types=(Part.Shape,))

self.outputs['Vertices'].sv_set(verts_out)
self.outputs['Curves'].sv_set(edges_out)


def register():
bpy.utils.register_class(SvSolidSectionNode)


def unregister():
bpy.utils.unregister_class(SvSolidSectionNode)

Binary file added ui/icons/sv_solid_section.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.