2424from __future__ import with_statement
2525from functools import wraps
2626import warnings
27+ import operator
28+ import math
2729
2830from OCC .BRep import BRep_Tool
31+ from OCC .BRepAdaptor import BRepAdaptor_HCurve
2932from OCC .BRepOffset import BRepOffset_Skin
3033from OCC .Geom import Geom_TrimmedCurve
3134from OCC .GeomConvert import GeomConvert_ApproxCurve
32- from OCC .GeomLProp import *
33- from OCC .BRepBuilderAPI import *
34- from OCC .BRepPrimAPI import *
35+ from OCC .GeomLProp import GeomLProp_SLProps
36+ from OCC .BRepBuilderAPI import (BRepBuilderAPI_MakeFace ,
37+ BRepBuilderAPI_Transform ,
38+ BRepBuilderAPI_Sewing ,
39+ BRepBuilderAPI_MakePolygon ,
40+ BRepBuilderAPI_MakeWire ,
41+ BRepBuilderAPI_MakeSolid ,
42+ BRepBuilderAPI_MakeShell ,
43+ BRepBuilderAPI_MakeEdge2d ,
44+ BRepBuilderAPI_MakeEdge ,
45+ BRepBuilderAPI_MakeVertex ,
46+ BRepBuilderAPI_FindPlane )
47+ from OCC .BRepPrimAPI import (BRepPrimAPI_MakeBox , BRepPrimAPI_MakePrism )
3548from OCC .BRepOffsetAPI import BRepOffsetAPI_MakeEvolved
36- from OCC .GeomAbs import *
37- from OCC .TopAbs import *
38- from OCC .TopoDS import *
39- from OCC .gp import *
40-
41- from Common import *
42- from Context import assert_isdone
43- from types_lut import ShapeToTopology
49+ from OCC .GeomAbs import (GeomAbs_Arc , GeomAbs_C2 , GeomAbs_C0 , GeomAbs_Tangent ,
50+ GeomAbs_Intersection , GeomAbs_G1 , GeomAbs_G2 ,
51+ GeomAbs_C1 )
52+ from OCC .TopAbs import TopAbs_REVERSED
53+ from OCC .TopoDS import (TopoDS_Wire , TopoDS_Solid , TopoDS_Vertex , TopoDS_Shape ,
54+ TopoDS_Builder , TopoDS_Compound )
55+ from OCC .TColgp import TColgp_SequenceOfVec , TColgp_HArray1OfPnt
56+ from OCC .gp import (gp_Vec , gp_Pnt , gp_Dir , gp_Trsf , gp_Ax1 , gp_Quaternion ,
57+ gp_Circ , gp_Pln )
58+
59+ from OCCUtils .Common import (TOLERANCE , assert_isdone , to_tcol_ , to_adaptor_3d ,
60+ vertex2pnt , smooth_pnts , points_to_bspline ,
61+ project_point_on_curve )
62+ from OCCUtils .types_lut import ShapeToTopology
63+ from OCCUtils .Topology import Topo
4464
45- import operator
46- import math
4765
4866EPSILON = TOLERANCE = 1e-6
4967ST = ShapeToTopology ()
@@ -243,9 +261,8 @@ def make_wire(*args):
243261 # if we get an iterable, than add all edges to wire builder
244262 if isinstance (args [0 ], list ) or isinstance (args [0 ], tuple ):
245263 wire = BRepBuilderAPI_MakeWire ()
246- #from OCC.TopTools import TopTools_ListOfShape
247264 for i in args [0 ]:
248- wire .Add (i )
265+ wire .Add (i )
249266 wire .Build ()
250267 return wire .Wire ()
251268
@@ -297,7 +314,7 @@ def make_closed_polygon(*args):
297314
298315def make_circle (pnt , radius ):
299316 '''
300- returns an edge
317+ returns an edge
301318 @param pnt:
302319 @param radius:
303320 '''
@@ -330,24 +347,15 @@ def make_prism(profile, vec):
330347 '''
331348 makes a finite prism
332349 '''
333- pri = BRepPrimAPI_MakePrism (profile , vec , True )
350+ pri = BRepPrimAPI_MakePrism (profile , vec , True )
334351 with assert_isdone (pri , 'failed building prism' ):
335352 pri .Build ()
336353 return pri .Shape ()
337354
338355
339- def make_prism_shell (profile , vec ):
340- '''
341- makes a finite prism
342- '''
343- from OCC .BRepOffsetAPI import BRepOffsetAPI_MakePipeShell
344- return BRepOffsetAPI_MakePipeShell ()
345-
346-
347356def make_offset_shape (shapeToOffset , offsetDistance , tolerance = TOLERANCE ,
348357 offsetMode = BRepOffset_Skin , intersection = False ,
349358 selfintersection = False , joinType = GeomAbs_Arc ):
350- # TODO: refactor assert_isdone
351359 '''
352360 builds an offsetted shell from a shape
353361 construct an offsetted version of the shape
@@ -360,8 +368,7 @@ def make_offset_shape(shapeToOffset, offsetDistance, tolerance=TOLERANCE,
360368 offsetMode ,
361369 intersection ,
362370 selfintersection ,
363- joinType
364- )
371+ joinType )
365372 if offset .IsDone ():
366373 return offset .Shape ()
367374 else :
@@ -371,7 +378,6 @@ def make_offset_shape(shapeToOffset, offsetDistance, tolerance=TOLERANCE,
371378
372379
373380def make_offset (wire_or_face , offsetDistance , altitude = 0 , joinType = GeomAbs_Arc ):
374- # TODO: refactor assert_isdone
375381 '''
376382 builds a offsetted wire or face from a wire or face
377383 construct an offsetted version of the shape
@@ -400,20 +406,6 @@ def make_offset(wire_or_face, offsetDistance, altitude=0, joinType=GeomAbs_Arc):
400406 return None
401407
402408
403- def make_draft (profile , vec ):
404- '''
405- makes a finite prism
406- '''
407- raise NotImplementedError
408-
409-
410- def make_filling (profile , vec ):
411- '''
412- makes a n-sided patch from constraints
413- '''
414- raise NotImplementedError
415-
416-
417409def make_loft (elements , ruled = False , tolerance = TOLERANCE , continuity = GeomAbs_C2 , check_compatibility = True ):
418410 from OCC .BRepOffsetAPI import BRepOffsetAPI_ThruSections
419411 sections = BRepOffsetAPI_ThruSections (False , ruled , tolerance )
@@ -423,7 +415,7 @@ def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2,
423415 elif isinstance (i , TopoDS_Vertex ):
424416 sections .AddVertex (i )
425417 else :
426- raise TypeError ('elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool' % ( i .__class__ ) )
418+ raise TypeError ('elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool' % i .__class__ )
427419
428420 sections .CheckCompatibility (check_compatibility )
429421 sections .SetContinuity (continuity )
@@ -438,28 +430,22 @@ def make_ruled(edgeA, edgeB):
438430 from OCC .BRepFill import brepfill_Face
439431 return brepfill_Face (edgeA , edgeB )
440432
441- #===========================================================================
442- # ---CONVENIENCE---
443- #===========================================================================
444433
445- def make_plane (center = gp_Pnt (0 ,0 , 0 ),
446- vec_normal = gp_Vec (0 ,0 , 1 ),
434+ def make_plane (center = gp_Pnt (0 , 0 , 0 ),
435+ vec_normal = gp_Vec (0 , 0 , 1 ),
447436 extent_x_min = - 100. ,
448437 extent_x_max = 100. ,
449438 extent_y_min = - 100. ,
450439 extent_y_max = 100. ,
451- depth = 0.
452- ):
453-
440+ depth = 0. ):
454441 if depth != 0 :
455- P1 = center .add_vec (gp_Vec (0 , 0 , depth ))
442+ center = center .add_vec (gp_Vec (0 , 0 , depth ))
456443 PL = gp_Pln (center , vec_normal .as_dir ())
457444 face = make_face (PL ,
458445 extent_x_min ,
459446 extent_x_max ,
460447 extent_y_min ,
461- extent_y_max ,
462- )
448+ extent_y_max )
463449 return face
464450
465451
@@ -479,9 +465,9 @@ def make_oriented_box(v_corner, v_x, v_y, v_z):
479465 verts = map (lambda x : x .as_pnt (), [v_corner , v_corner + v_x , v_corner + v_x + v_y , v_corner + v_y ])
480466 p = make_polygon (verts , closed = True )
481467 li = make_line (v_corner .as_pnt (), (v_corner + v_z ).as_pnt ())
482- ooo = BRepOffsetAPI_MakePipe (p , li )
483- ooo .Build ()
484- shp = ooo .Shape ()
468+ bmp = BRepOffsetAPI_MakePipe (p , li )
469+ bmp .Build ()
470+ shp = bmp .Shape ()
485471
486472 bottom = make_face (p )
487473 top = translate_topods_from_vector (bottom , v_z , True )
@@ -497,22 +483,6 @@ def make_box(*args):
497483 return box .Shape ()
498484
499485
500- def make_spline (pnts = ['' ], tangents = ['' ], epsilon = EPSILON ):
501- '''
502- @param pnts: list_of_gp_Pnts
503- @param tangents: list_of_tangent_vecs_at_gp_Pnts
504- None where we do not care about tangency
505- None or empty list if we don't care about tangency at all
506- @param epsilon: tolerence
507- '''
508- raise NotImplementedError
509-
510-
511- #===========================================================================
512- # NEW
513- #===========================================================================
514-
515-
516486def make_n_sided (edges , points , continuity = GeomAbs_C0 ):
517487 """
518488 builds an n-sided patch, respecting the constraints defined by *edges*
@@ -561,7 +531,6 @@ def make_n_sections(edges):
561531
562532def make_coons (edges ):
563533 from OCC .GeomFill import GeomFill_BSplineCurves , GeomFill_StretchStyle
564- bt = BRep_Tool ()
565534 if len (edges ) == 4 :
566535 spl1 , spl2 , spl3 , spl4 = edges
567536 srf = GeomFill_BSplineCurves (spl1 , spl2 , spl3 , spl4 , GeomFill_StretchStyle )
@@ -580,7 +549,6 @@ def make_constrained_surface_from_edges(edges):
580549 '''
581550 DOESNT RESPECT BOUNDARIES
582551 '''
583- from OCC .BRepAdaptor import BRepAdaptor_HCurve
584552 from OCC .GeomPlate import GeomPlate_MakeApprox , GeomPlate_BuildPlateSurface
585553 from OCC .BRepFill import BRepFill_CurveConstraint
586554 bpSrf = GeomPlate_BuildPlateSurface (3 , 15 , 2 )
@@ -598,10 +566,6 @@ def make_constrained_surface_from_edges(edges):
598566 face = make_face (plate .Surface (), uMin , uMax , vMin , vMax )
599567 return face
600568
601- #===========================================================================
602- # NEW
603- #===========================================================================
604-
605569
606570def add_wire_to_face (face , wire , reverse = False ):
607571 '''
@@ -640,6 +604,7 @@ def sew_shapes(shapes, tolerance=0.001):
640604# ---BOOL---
641605#===========================================================================
642606
607+
643608def boolean_cut (shapeToCutFrom , cuttingShape ):
644609 from OCC .BRepAlgoAPI import BRepAlgoAPI_Cut
645610 try :
@@ -701,7 +666,6 @@ def trim_wire(wire, shapeLimit1, shapeLimit2, periodic=False):
701666
702667def fix_shape (shp , tolerance = 1e-3 ):
703668 from OCC .ShapeFix import ShapeFix_Shape
704- te = ShapeToTopology ()
705669 fix = ShapeFix_Shape (shp )
706670 fix .SetFixFreeShellMode (True )
707671 sf = fix .FixShellTool ().GetObject ()
@@ -741,10 +705,6 @@ def translate_topods_from_vector(brep_or_iterable, vec, copy=False):
741705 return [translate_topods_from_vector (brep_or_iterable , vec , copy ) for i in brep_or_iterable ]
742706
743707
744- def scale_non_uniformal ():
745- raise NotImplementedError
746-
747-
748708def scale_uniformal (brep , pnt , factor , copy = False ):
749709 '''
750710 translate a brep over a vector
@@ -839,7 +799,6 @@ def fit_plane_through_face_vertices(_face):
839799 :return: Geom_Plane
840800 """
841801 from OCC .GeomPlate import GeomPlate_BuildAveragePlane
842- from Topology import Topo
843802
844803 uvs_from_vertices = [_face .project_vertex (vertex2pnt (i )) for i in Topo (_face ).vertices ()]
845804 normals = [gp_Vec (_face .DiffGeom .normal (* uv [0 ])) for uv in uvs_from_vertices ]
@@ -863,7 +822,7 @@ def project_edge_onto_plane(edg, plane):
863822 :return: TopoDS_Edge projected on the plane
864823 """
865824 from OCC .GeomProjLib import geomprojlib_ProjectOnPlane
866- proj = geomprojlib_ProjectOnPlane (edg .adaptor .Curve ().Curve (), plane .GetHandle (), plane .Axis ().Direction (), 1 )
825+ proj = geomprojlib_ProjectOnPlane (edg .adaptor .Curve ().Curve (), plane .GetHandle (), plane .Axis ().Direction (), 1 )
867826 return make_edge (proj )
868827
869828
@@ -898,7 +857,6 @@ def geodesic_path(pntA, pntB, edgA, edgB, kbe_face, n_segments=20, _tolerance=0.
898857 :param n_iter: maximum number of iterations
899858 :return: TopoDS_Edge
900859 """
901- from Common import smooth_pnts
902860 uvA , srf_pnt_A = kbe_face .project_vertex (pntA )
903861 uvB , srf_pnt_B = kbe_face .project_vertex (pntB )
904862
0 commit comments