diff --git a/src/geouned/GEOUNED/decompose/decom_one.py b/src/geouned/GEOUNED/decompose/decom_one.py index 6853b5d5..e8351c22 100644 --- a/src/geouned/GEOUNED/decompose/decom_one.py +++ b/src/geouned/GEOUNED/decompose/decom_one.py @@ -72,7 +72,7 @@ def cut_full_cylinder(solid, options, tolerances, numeric_format): surfaces.add_cylinder(cylinder, options, tolerances, numeric_format, False) # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_gu, face, universe_box): p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) break @@ -131,7 +131,16 @@ def gen_plane(pos, normal, diag): return plane_center -def cyl_bound_planes(face, boundBox): +def other_face_edge(current_edge, current_face, solid): + for face in solid.Faces: + if face.isSame(current_face): + continue + for edge in face.Edges: + if current_edge.isSame(edge): + return face + + +def cyl_bound_planes(solid, face, boundBox): Edges = face.OuterWire.Edges planes = [] for e in Edges: @@ -140,6 +149,13 @@ def cyl_bound_planes(face, boundBox): except: curve = "none" + adjacent_face = other_face_edge(e, face, solid) + if adjacent_face is not None: + if type(adjacent_face.Surface) is GU.TorusGu: + continue # doesn't create plane if other face is a torus + if face.Surface.isSameSurface(adjacent_face.Surface): + continue # doesn't create plane if other face has same surface + if curve[0:6] == "Circle": dir = e.Curve.Axis center = e.Curve.Center @@ -159,7 +175,7 @@ def cyl_bound_planes(face, boundBox): return planes -def torus_bound_planes(face, boundBox, tolerances): +def torus_bound_planes(solid, face, boundBox, tolerances): params = face.ParameterRange planes = [] if is_same_value(params[1] - params[0], twoPi, tolerances.value): @@ -173,6 +189,11 @@ def torus_bound_planes(face, boundBox, tolerances): except: curve = "none" + adjacent_face = other_face_edge(e, face, solid) + if adjacent_face is not None: + if face.Surface.isSameSurface(adjacent_face.Surface): + continue # doesn't create plane if other face has same surface + if curve[0:6] == "Circle": dir = e.Curve.Axis if not is_parallel(dir, face.Surface.Axis, tolerances.angle): @@ -262,7 +283,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for if kind in ["Planes", "All"]: # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -280,7 +301,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_cone(cone, tolerances) if kind in ["Planes", "All"]: - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -294,7 +315,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_sphere(sphere, tolerances) if kind in ["Planes", "All"]: - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -311,7 +332,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_torus(torus, tolerances) if kind in ["Planes", "All"]: - for p in torus_bound_planes(face, universe_box, tolerances): + for p in torus_bound_planes(solid_GU, face, universe_box, tolerances): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) diff --git a/src/geouned/GEOUNED/utils/data_classes.py b/src/geouned/GEOUNED/utils/data_classes.py index 1c5fd15f..1c305938 100644 --- a/src/geouned/GEOUNED/utils/data_classes.py +++ b/src/geouned/GEOUNED/utils/data_classes.py @@ -408,7 +408,7 @@ class NumericFormat: C_r (str, optional): Cylinder radius. Defaults to "12f". C_xyz (str, optional): Cylinder center. Defaults to "12f". K_xyz (str, optional): Cone apex. Defaults to "13.6e". - K_tan2 (str, optional): Cone tan^2 value. Defaults to "12f". + K_tan2 (str, optional): Cone tan^2 value. Defaults to "13.6e". T_r (str, optional): Torus radii. Defaults to "14.7e". T_xyz (str, optional): Torus center. Defaults to "14.7e". GQ_1to6 (str, optional): GQ 1 to 6 coefficients (order 2 x2,y2,z2,xy,...). Defaults to "18.15f". @@ -426,7 +426,7 @@ def __init__( C_r: str = "12f", C_xyz: str = "12f", K_xyz: str = "13.6e", - K_tan2: str = "12f", + K_tan2: str = "13.6e", T_r: str = "14.7e", T_xyz: str = "14.7e", GQ_1to6: str = "18.15f", diff --git a/src/geouned/GEOUNED/utils/geometry_gu.py b/src/geouned/GEOUNED/utils/geometry_gu.py index 4011cbe5..6af3f4bb 100644 --- a/src/geouned/GEOUNED/utils/geometry_gu.py +++ b/src/geouned/GEOUNED/utils/geometry_gu.py @@ -50,6 +50,15 @@ def __init__(self, face, plane3Pts=False): self.dim1 = face.ParameterRange[1] - face.ParameterRange[0] self.dim2 = face.ParameterRange[3] - face.ParameterRange[2] + def isSameSurface(self, surface): + if type(surface) is not PlaneGu: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + if abs(self.Axis.dot(self.Position) - surface.Axis.dot(surface.Position)) > 1e-5: + return False + return True + class CylinderGu(SurfacesGu): """GEOUNED Cylinder Class""" @@ -61,6 +70,18 @@ def __init__(self, face): self.Center = face.Surface.Center self.dimL = face.ParameterRange[3] - face.ParameterRange[2] + def isSameSurface(self, surface): + if type(surface) is not CylinderGu: + return False + if abs(self.Radius - surface.Radius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class ConeGu(SurfacesGu): """GEOUNED Cone Class""" @@ -74,6 +95,18 @@ def __init__(self, face): self.dimR = face.Surface.Radius self.Radius = face.Surface.Radius + def isSameSurface(self, surface): + if type(surface) is not ConeGu: + return False + if abs(self.SemiAngle - surface.SemiAngle) > 1e-5: + return False + d = self.Apex - surface.Apex + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class SphereGu(SurfacesGu): """GEOUNED Sphere Class""" @@ -84,6 +117,16 @@ def __init__(self, face): self.Center = face.Surface.Center self.Radius = face.Surface.Radius + def isSameSurface(self, surface): + if type(surface) is not SphereGu: + return False + if abs(self.Radius - surface.Radius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + return True + class TorusGu(SurfacesGu): """GEOUNED Torus Class""" @@ -95,6 +138,20 @@ def __init__(self, face): self.MajorRadius = face.Surface.MajorRadius self.MinorRadius = face.Surface.MinorRadius + def isSameSurface(self, surface): + if type(surface) is not TorusGu: + return False + if abs(self.MajorRadius - surface.MajorRadius) > 1e-5: + return False + if abs(self.MinorRadius - surface.MinorRadius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class SolidGu: """GEOUNED Solid Class""" @@ -112,9 +169,8 @@ def __init__(self, solid, tolerances, plane3Pts=False): toroidIndex = [] for i, face in enumerate(self.Faces): - if str(face.Surface) != "": - continue - toroidIndex.append(i) + if type(face.Surface) is TorusGu: + toroidIndex.append(i) if len(toroidIndex) != 0: tFaces = self.same_torus_surf(toroidIndex) @@ -259,6 +315,9 @@ def getUVNodes(self): def isEqual(self, face): return self.__face__.isEqual(face.__face__) + def isSame(self, face): + return self.__face__.isSame(face.__face__) + def valueAt(self, u, v): return self.__face__.valueAt(u, v) @@ -286,16 +345,16 @@ def define_list_face_gu(face_list, plane3Pts=False): def define_surface(face, plane3Pts): - kind_surf = str(face.Surface) - if kind_surf == "": + kind_surf = type(face.Surface) + if kind_surf is Part.Plane: Surf_GU = PlaneGu(face, plane3Pts) - elif kind_surf == "": + elif kind_surf is Part.Cylinder: Surf_GU = CylinderGu(face) - elif kind_surf == "": + elif kind_surf is Part.Cone: Surf_GU = ConeGu(face) - elif kind_surf[0:6] == "Sphere": + elif kind_surf is Part.Sphere: Surf_GU = SphereGu(face) - elif kind_surf == "": + elif kind_surf is Part.Toroid: Surf_GU = TorusGu(face) else: logger.info(f"bad Surface type {kind_surf}")