Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
684e9cf
Add files via upload
bragostin Dec 21, 2019
3e9468d
Add files via upload
bragostin Dec 21, 2019
716519b
Add files via upload
bragostin Dec 21, 2019
9d78d9e
Add files via upload
bragostin Dec 21, 2019
fc59b6d
Add files via upload
bragostin Dec 21, 2019
0227c78
Add files via upload
bragostin Dec 21, 2019
68e0481
Add files via upload
bragostin Dec 21, 2019
e25608f
Add files via upload
bragostin Dec 21, 2019
8b87bed
Add files via upload
bragostin Dec 21, 2019
303ab2b
Add files via upload
bragostin Dec 21, 2019
450942a
Add files via upload
bragostin Dec 21, 2019
1410a95
Add files via upload
bragostin Dec 21, 2019
6c55cbf
Add files via upload
bragostin Dec 22, 2019
278b4d6
Add files via upload
bragostin Dec 22, 2019
a537ae5
Add files via upload
bragostin Dec 22, 2019
3f90a8c
Add files via upload
bragostin Dec 22, 2019
59f9c26
Add files via upload
bragostin Dec 26, 2019
3374374
Merge pull request #3 from CadQuery/master
bragostin Dec 26, 2019
e8aa961
Add files via upload
bragostin Dec 26, 2019
a85847e
Add files via upload
bragostin Dec 26, 2019
75c16f6
Add files via upload
bragostin Dec 26, 2019
6761498
Delete TestInterpPlate.py
bragostin Dec 26, 2019
12c4df6
Delete TestinterpPlate.py
bragostin Dec 26, 2019
4a8c8dc
Add files via upload
bragostin Dec 26, 2019
4e55bbf
Delete test_interpPlate.py
bragostin Dec 26, 2019
05e5887
Update test_cadquery.py
bragostin Dec 26, 2019
a84228e
Update test_cadquery.py
bragostin Dec 26, 2019
8eda788
Update test_cadquery.py
bragostin Dec 26, 2019
fd64195
Update test_cadquery.py
bragostin Dec 26, 2019
132016b
Added: asserts in tests
bragostin Dec 29, 2019
cbd59ac
Update test_cadquery.py
bragostin Dec 29, 2019
50e652b
Update test_cadquery.py
bragostin Dec 29, 2019
3d198a7
Update test_cadquery.py
bragostin Dec 29, 2019
23be0d9
Update test_cadquery.py
bragostin Dec 29, 2019
fcf3094
Update test_cadquery.py
bragostin Dec 30, 2019
9980ecd
Update test_cadquery.py
bragostin Dec 30, 2019
40c152a
Update shapes.py
bragostin Jan 5, 2020
09e84bf
assembleEdges moved to shapes.py
bragostin Jan 6, 2020
6ba1d6d
call to assembleEdges moved into interpPlate
bragostin Jan 6, 2020
5f553cd
Capitalization of variables changes to lower
bragostin Jan 6, 2020
737ddd6
Capitalization of variables changes to lower
bragostin Jan 6, 2020
a165473
set decimal_places to 0
bragostin Jan 6, 2020
95a34b8
arguments set to lowercase
bragostin Jan 6, 2020
1c6d69a
Test different decimal_places values
bragostin Jan 7, 2020
e14976d
Test different decimal_places values
bragostin Jan 7, 2020
fac69ed
Test different decimal_places values
bragostin Jan 7, 2020
415ffc5
Final decimal places values set
bragostin Jan 7, 2020
93da718
'TestAssembleEdges' not needed anymore
bragostin Jan 7, 2020
d4f7db7
Docstring added
bragostin Jan 7, 2020
25fe17c
Add files via upload
bragostin Feb 12, 2020
26d7c81
Add files via upload
bragostin Feb 12, 2020
4db4fc6
Add files via upload
bragostin Feb 12, 2020
8085955
Add files via upload
bragostin Feb 12, 2020
52ed6ed
Add files via upload
bragostin Feb 12, 2020
b6bc8c4
Add files via upload
bragostin Feb 12, 2020
0d01668
Add files via upload
bragostin Feb 12, 2020
1b2bcb7
Add files via upload
bragostin Feb 12, 2020
9548b05
Merge branch 'master' into BRepOffsetAPI_MakeFilling
bragostin Feb 12, 2020
809d127
Add files via upload
bragostin Feb 12, 2020
969be40
Add files via upload
bragostin Feb 12, 2020
4f85c77
Add files via upload
bragostin Feb 12, 2020
36c8023
Add files via upload
bragostin Feb 12, 2020
7812f36
Add files via upload
bragostin Feb 12, 2020
84ae4ea
Add files via upload
bragostin Feb 12, 2020
52ff375
Add files via upload
bragostin Feb 12, 2020
2532ed1
Update __init__.py
bragostin Feb 12, 2020
05ae2ce
Black formatting
bragostin Feb 12, 2020
2f7169a
Black formatting
bragostin Feb 12, 2020
3f35402
Black formatting
bragostin Feb 12, 2020
1914049
Black formatting
bragostin Feb 12, 2020
c17bc35
Black formatting
bragostin Feb 12, 2020
9708554
Black formatting
bragostin Feb 12, 2020
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
84 changes: 84 additions & 0 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,90 @@ def _sweep(

return Compound.makeCompound(toFuse)

def interpPlate(
self,
surf_edges,
surf_pts=[],
thickness=0,
combine=False,
clean=True,
degree=3,
nbPtsOnCur=15,
nbIter=2,
anisotropy=False,
tol2d=0.00001,
tol3d=0.0001,
tolAng=0.01,
tolCurv=0.1,
maxDeg=8,
maxSegments=9,
):
"""
Returns a plate surface that is 'thickness' thick, enclosed by 'surf_edge_pts' points, and going through 'surf_pts' points. Using pushpoints directly with interpPlate and combine=True, can be very ressources intensive depending on the complexity of the shape. In this case set combine=False.

:param surf_edges
:type 1 surf_edges: list of [x,y,z] float ordered coordinates
:type 2 surf_edges: list of ordered or unordered CadQuery wires
:param surf_pts = [] (uses only edges if [])
:type surf_pts: list of [x,y,z] float coordinates
:param thickness = 0 (returns 2D surface if 0)
:type thickness: float (may be negative or positive depending on thicknening direction)
:param combine: should the results be combined with other solids on the stack
(and each other)?
:type combine: true to combine shapes, false otherwise.
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
:param Degree = 3 (OCCT default)
:type Degree: Integer >= 2
:param NbPtsOnCur = 15 (OCCT default)
:type: NbPtsOnCur Integer >= 15
:param NbIter = 2 (OCCT default)
:type: NbIterInteger >= 2
:param Anisotropie = False (OCCT default)
:type Anisotropie: Boolean
:param: Tol2d = 0.00001 (OCCT default)
:type Tol2d: float > 0
:param Tol3d = 0.0001 (OCCT default)
:type Tol3dReal: float > 0
:param TolAng = 0.01 (OCCT default)
:type TolAngReal: float > 0
:param TolCurv = 0.1 (OCCT default)
:type TolCurvReal: float > 0
:param MaxDeg = 8 (OCCT default)
:type MaxDegInteger: Integer >= 2 (?)
:param MaxSegments = 9 (OCCT default)
:type MaxSegments: Integer >= 2 (?)
"""

# If thickness is 0, only a 2D surface will be returned.
if thickness == 0:
combine = False

# Creates interpolated plate
def _makeplate(pnt):
return Solid.interpPlate(
surf_edges,
surf_pts,
thickness,
degree,
nbPtsOnCur,
nbIter,
anisotropy,
tol2d,
tol3d,
tolAng,
tolCurv,
maxDeg,
maxSegments,
).translate(pnt)

plates = self.eachpoint(_makeplate, True)

# if combination is not desired, just return the created boxes
if not combine:
return plates
else:
return self.union(plates, clean=clean)

def box(
self,
length,
Expand Down
183 changes: 183 additions & 0 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@

from OCC.Core.BRepClass3d import BRepClass3d_SolidClassifier

from OCC.Core.GeomAbs import GeomAbs_C0
from OCC.Extend.TopologyUtils import TopologyExplorer, WireExplorer
from OCC.Core.GeomAbs import GeomAbs_Intersection
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeFilling
from OCC.Core.BRepOffset import BRepOffset_MakeOffset, BRepOffset_Skin
from OCC.Core.ShapeFix import ShapeFix_Wire

import warnings
from math import pi, sqrt
from functools import reduce
import warnings
Expand Down Expand Up @@ -991,6 +999,73 @@ def innerWires(self):

return [w for w in self.Wires() if not w.isSame(outer)]

@classmethod
def makeNSidedSurface(
cls,
edges,
points,
continuity=GeomAbs_C0,
degree=3,
nbPtsOnCur=15,
nbIter=2,
anisotropy=False,
tol2d=0.00001,
tol3d=0.0001,
tolAng=0.01,
tolCurv=0.1,
maxDeg=8,
maxSegments=9,
):
"""
Returns a surface enclosed by a closed polygon defined by 'edges' and going through 'points'.
:param points
:type points: list of gp_Pnt
:param edges
:type edges: list of TopologyExplorer().edges()
:param continuity=GeomAbs_C0
:type continuity: OCC.Core.GeomAbs continuity condition
:param Degree = 3 (OCCT default)
:type Degree: Integer >= 2
:param NbPtsOnCur = 15 (OCCT default)
:type: NbPtsOnCur Integer >= 15
:param NbIter = 2 (OCCT default)
:type: NbIterInteger >= 2
:param Anisotropie = False (OCCT default)
:type Anisotropie: Boolean
:param: Tol2d = 0.00001 (OCCT default)
:type Tol2d: float > 0
:param Tol3d = 0.0001 (OCCT default)
:type Tol3dReal: float > 0
:param TolAng = 0.01 (OCCT default)
:type TolAngReal: float > 0
:param TolCurv = 0.1 (OCCT default)
:type TolCurvReal: float > 0
:param MaxDeg = 8 (OCCT default)
:type MaxDegInteger: Integer >= 2 (?)
:param MaxSegments = 9 (OCCT default)
:type MaxSegments: Integer >= 2 (?)
"""

n_sided = BRepOffsetAPI_MakeFilling(
degree,
nbPtsOnCur,
nbIter,
anisotropy,
tol2d,
tol3d,
tolAng,
tolCurv,
maxDeg,
maxSegments,
)
for edg in edges:
n_sided.Add(edg, continuity)
for pt in points:
n_sided.Add(pt)
n_sided.Build()
face = n_sided.Shape()
return cls.cast(face).fix()

@classmethod
def makePlane(cls, length, width, basePnt=(0, 0, 0), dir=(0, 0, 1)):
basePnt = Vector(basePnt)
Expand Down Expand Up @@ -1165,6 +1240,114 @@ class Solid(Shape, Mixin3D):
a single solid
"""

@classmethod
def interpPlate(
cls,
surf_edges,
surf_pts,
thickness,
degree=3,
nbPtsOnCur=15,
nbIter=2,
anisotropy=False,
tol2d=0.00001,
tol3d=0.0001,
tolAng=0.01,
tolCurv=0.1,
maxDeg=8,
maxSegments=9,
):
"""
Returns a plate surface that is 'thickness' thick, enclosed by 'surf_edge_pts' points, and going through 'surf_pts' points.

:param surf_edges
:type 1 surf_edges: list of [x,y,z] float ordered coordinates
:type 2 surf_edges: list of ordered or unordered CadQuery wires
:param surf_pts = [] (uses only edges if [])
:type surf_pts: list of [x,y,z] float coordinates
:param thickness = 0 (returns 2D surface if 0)
:type thickness: float (may be negative or positive depending on thicknening direction)
:param Degree = 3 (OCCT default)
:type Degree: Integer >= 2
:param NbPtsOnCur = 15 (OCCT default)
:type: NbPtsOnCur Integer >= 15
:param NbIter = 2 (OCCT default)
:type: NbIterInteger >= 2
:param Anisotropie = False (OCCT default)
:type Anisotropie: Boolean
:param: Tol2d = 0.00001 (OCCT default)
:type Tol2d: float > 0
:param Tol3d = 0.0001 (OCCT default)
:type Tol3dReal: float > 0
:param TolAng = 0.01 (OCCT default)
:type TolAngReal: float > 0
:param TolCurv = 0.1 (OCCT default)
:type TolCurvReal: float > 0
:param MaxDeg = 8 (OCCT default)
:type MaxDegInteger: Integer >= 2 (?)
:param MaxSegments = 9 (OCCT default)
:type MaxSegments: Integer >= 2 (?)
"""

# POINTS CONSTRAINTS: list of (x,y,z) points, optional.
pts_array = [gp_Pnt(*pt) for pt in surf_pts]

# EDGE CONSTRAINTS
# If a list of wires is provided, make a closed wire
if not isinstance(surf_edges, list):
surf_edges = [o.vals()[0] for o in surf_edges.all()]
surf_edges = Wire.assembleEdges(surf_edges)
w = surf_edges.wrapped

# If a list of (x,y,z) points provided, build closed polygon
if isinstance(surf_edges, list):
e_array = [Vector(*e) for e in surf_edges]
wire_builder = BRepBuilderAPI_MakePolygon()
for e in e_array: # Create polygon from edges
wire_builder.Add(e.toPnt())
wire_builder.Close()
w = wire_builder.Wire()

edges = [i for i in TopologyExplorer(w).edges()]

# MAKE SURFACE
continuity = GeomAbs_C0 # Fixed, changing to anything else crashes.
face = Face.makeNSidedSurface(
edges,
pts_array,
continuity,
degree,
nbPtsOnCur,
nbIter,
anisotropy,
tol2d,
tol3d,
tolAng,
tolCurv,
maxDeg,
maxSegments,
)

# THICKEN SURFACE
if (
abs(thickness) > 0
): # abs() because negative values are allowed to set direction of thickening
solid = BRepOffset_MakeOffset()
solid.Initialize(
face.wrapped,
thickness,
1.0e-5,
BRepOffset_Skin,
False,
False,
GeomAbs_Intersection,
True,
) # The last True is important to make solid
solid.MakeOffsetShape()
return cls(solid.Shape())
else: # Return 2D surface only
return face

@classmethod
def isSolid(cls, obj):
"""
Expand Down
Loading