def split_edge_with_face(event=None): display.EraseAll() p0 = gp_Pnt() vnorm = gp_Dir(1, 0, 0) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face() p1 = gp_Pnt(0, 0, 15) p2 = gp_Pnt(0, 0, -15) edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() # Initialize splitter splitter = BOPAlgo_Splitter() # Add the edge as an argument and the face as a tool. This will split # the edge with the face. splitter.AddArgument(edge) splitter.AddTool(face) splitter.Perform() edges = [] exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE) while exp.More(): edges.append(exp.Current()) exp.Next() print('Number of edges in split shape: ', len(edges)) display.DisplayShape(edges[0], color='red') display.DisplayShape(edges[1], color='green') display.DisplayShape(edges[2], color='yellow') display.FitAll()
def make_face_to_contour_from(): v1 = make_vertex(gp_Pnt(0, 0, 0)) v2 = make_vertex(gp_Pnt(10, 0, 0)) v3 = make_vertex(gp_Pnt(7, 10, 0)) v4 = make_vertex(gp_Pnt(10, 20, 0)) v5 = make_vertex(gp_Pnt(0, 20, 0)) v6 = make_vertex(gp_Pnt(3, 10, 0)) e1 = make_edge(v1, v2) e2 = make_edge(v2, v3) e3 = make_edge(v3, v4) e4 = make_edge(v4, v5) e5 = make_edge(v5, v6) e6 = make_edge(v6, v1) v7 = make_vertex(gp_Pnt(2, 2, 0)) v8 = make_vertex(gp_Pnt(8, 2, 0)) v9 = make_vertex(gp_Pnt(7, 3, 0)) v10 = make_vertex(gp_Pnt(3, 3, 0)) e7 = make_edge(v7, v8) e8 = make_edge(v8, v9) e9 = make_edge(v9, v10) e10 = make_edge(v10, v7) w1 = make_wire([e1, e2, e3, e4, e5, e6]) f = make_face(w1) w2 = make_wire(e7, e8, e9, e10) f2 = make_face(w2) f3 = boolean_cut(f, f2) return f3
def fillet(event=None): Box = BRepPrimAPI_MakeBox(gp_Pnt(-400, 0, 0), 200, 230, 180).Shape() fillet_ = BRepFilletAPI_MakeFillet(Box) # Add fillet on each edge for e in TopologyExplorer(Box).edges(): fillet_.Add(20, e) blendedBox = fillet_.Shape() P1 = gp_Pnt(250, 150, 75) S1 = BRepPrimAPI_MakeBox(300, 200, 200).Shape() S2 = BRepPrimAPI_MakeBox(P1, 120, 180, 70).Shape() Fuse = BRepAlgoAPI_Fuse(S1, S2) FusedShape = Fuse.Shape() fill = BRepFilletAPI_MakeFillet(FusedShape) for e in TopologyExplorer(FusedShape).edges(): fill.Add(e) for i in range(1, fill.NbContours() + 1): length = fill.Length(i) Rad = 0.15 * length fill.SetRadius(Rad, i, 1) blendedFusedSolids = fill.Shape() display.EraseAll() display.DisplayShape(blendedBox) display.DisplayShape(blendedFusedSolids) display.FitAll()
def line(): # create a line p1 = gp_Pnt(2., 3., 4.) d1 = gp_Dir(4., 5., 6.) line1 = Geom_Line(p1, d1) ais_line1 = AIS_Line(line1) # if we need to edit color, we can simply use SetColor # ais_line1.SetColor(Quantity_NOC_RED) # but actually we need to edit more, not just color. Line width and style as well # To do that, we need to do use AIS_Drawer and apply it to ais_line1 drawer = Prs3d_Drawer() ais_line1.SetAttributes(drawer) display.Context.Display(ais_line1, False) # we can apply the same rule for other lines by just doing a for loop for i in range(1, 5): p2 = gp_Pnt(i, 2., 5.) d2 = gp_Dir(4 * i, 6., 9.) line2 = Geom_Line(p2, d2) ais_line2 = AIS_Line(line2) width = float(i) drawer = ais_line2.Attributes() # asp : first parameter color, second type, last width asp = Prs3d_LineAspect(Quantity_Color(9 * i), i, width) drawer.SetLineAspect(asp) ais_line2.SetAttributes(drawer) display.Context.Display(ais_line2, False) start_display()
def get_transform(self): d = self.declaration result = gp_Trsf() #: TODO: Order matters... how to configure it??? if d.operations: for op in d.operations: t = gp_Trsf() if isinstance(op, Translate): t.SetTranslation(gp_Vec(op.x, op.y, op.z)) elif isinstance(op, Rotate): t.SetRotation( gp_Ax1(gp_Pnt(*op.point), gp_Dir(*op.direction)), op.angle) elif isinstance(op, Mirror): Ax = gp_Ax2 if op.plane else gp_Ax1 t.SetMirror(Ax(gp_Pnt(*op.point), gp_Dir(op.x, op.y, op.z))) elif isinstance(op, Scale): t.SetScale(gp_Pnt(*op.point), op.s) result.Multiply(t) else: axis = gp_Ax3() axis.SetDirection(d.direction.proxy) result.SetTransformation(axis) result.SetTranslationPart(gp_Vec(*d.position)) if d.rotation: t = gp_Trsf() t.SetRotation(gp_Ax1(d.position.proxy, d.direction.proxy), d.rotation) result.Multiply(t) return result
def center_boundingbox(shape): ''' compute the center point of a TopoDS_Shape, based on its bounding box @param shape: TopoDS_* instance returns a gp_Pnt instance ''' xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(shape, 1e-6) return midpoint(gp_Pnt(xmin, ymin, zmin), gp_Pnt(xmax, ymax, zmax))
def create_shape(self): attrs = self.element.attrib x1 = parse_unit(attrs.get('x1', 0)) y1 = parse_unit(attrs.get('y1', 0)) x2 = parse_unit(attrs.get('x2', 0)) y2 = parse_unit(attrs.get('y2', 0)) return BRepBuilderAPI_MakeEdge(gp_Pnt(x1, y1, 0), gp_Pnt(x2, y2, 0)).Edge()
def bisect_pnt(event=None): display.EraseAll() p1 = gp_Pnt2d(1, 0.5) p2 = gp_Pnt2d(0, 1e5) bi = GccAna_Pnt2dBisec(p1, p2) bisec = bi.ThisSolution() # enum GccInt_Lin, GccInt_Cir, GccInt_Ell, GccInt_Par, GccInt_Hpr, GccInt_Pnt p1_ = make_vertex(gp_Pnt(p1.X(), p1.Y(), 0)) p2_ = make_vertex(gp_Pnt(p2.X(), p2.Y(), 0)) display.DisplayShape([p1_, p2_]) display.DisplayColoredShape(make_edge2d(bisec), 'BLUE') display.FitAll()
def draw_lines(pnt_list, nr_of_points, display): """ rendering a large number of points through the usual way of: display.DisplayShape( make_vertex( gp_Pnt() ) ) is fine for TopoDS_Shapes but certainly not for large number of points. in comparison, drawing all the voxel samples takes 18sec using the approach above, but negigable when using this function its about 2 orders of Magnitude faster, so worth the extra hassle here we use a more close-to-the-metal approach of drawing directly in OpenGL see [1] for a more detailed / elegant way to perform this task [1] http://www.opencascade.org/org/forum/thread_21732/?forum=3 Parameters ---------- pnt_list: list of (x,y,z) tuples vertex list display: qtViewer3d """ a_presentation, group = create_ogl_group(display) black = Quantity_Color(Quantity_NOC_BLACK) asp = Graphic3d_AspectLine3d(black, Aspect_TOL_SOLID, 1) gg = Graphic3d_ArrayOfPolylines( nr_of_points * 2, nr_of_points * 2, 0, # maxEdges False, # hasVColors True) try: while 1: pnt = gp_Pnt(*next(pnt_list)) gg.AddVertex(pnt) pnt = gp_Pnt(*next(pnt_list)) gg.AddVertex(pnt) # create the line, with a random color gg.AddBound(2, random.random(), random.random(), random.random()) except StopIteration: pass group.SetPrimitivesAspect(asp) group.AddPrimitiveArray(gg) a_presentation.Display()
def setUpClass(cls): """ Set up for TColgp_HSequenceOfPnt. """ p1 = gp_Pnt() p2 = gp_Pnt(1, 0, 0) p3 = gp_Pnt(2, 0, 0) seq = TColgp_SequenceOfPnt() seq.Append(p1) seq.Append(p2) seq.Append(p3) cls._hseq = TColgp_HSequenceOfPnt(seq)
def test_Points3D(self): """ Test if the points are updated by reference. """ p0 = gp_Pnt() p1 = gp_Pnt() p2 = gp_Pnt() self.tri.Points3D(p0, p1, p2) self.assertAlmostEqual(p0.X(), 1.) self.assertAlmostEqual(p1.X(), 2.) self.assertAlmostEqual(p2.X(), 2.) self.assertAlmostEqual(p2.Y(), 1.)
def setUpClass(cls): """ Set up for TColgp_HArray1OfPnt. """ p1 = gp_Pnt() p2 = gp_Pnt(1, 0, 0) p3 = gp_Pnt(2, 0, 0) arr = TColgp_Array1OfPnt(1, 3) arr.SetValue(1, p1) arr.SetValue(2, p2) arr.SetValue(3, p3) cls._harr = TColgp_HArray1OfPnt(arr)
def solve_radius(event=None): display.EraseAll() p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(0, 10, 0) p3 = gp_Pnt(0, 10, 10) p4 = gp_Pnt(0, 0, 10) p5 = gp_Pnt(5, 5, 5) poly = make_closed_polygon([p1, p2, p3, p4]) for i in arange(0.1, 3., 0.2).tolist(): rcs = RadiusConstrainedSurface(display, poly, p5, i) # face = rcs.solve() print('Goal: %s radius: %s' % (i, rcs.curr_radius)) time.sleep(0.5)
def geom_plate(event=None): display.EraseAll() p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(0, 10, 0) p3 = gp_Pnt(0, 10, 10) p4 = gp_Pnt(0, 0, 10) p5 = gp_Pnt(5, 5, 5) poly = make_closed_polygon([p1, p2, p3, p4]) edges = [i for i in TopologyExplorer(poly).edges()] face = make_n_sided(edges, [p5]) display.DisplayShape(edges) display.DisplayShape(make_vertex(p5)) display.DisplayShape(face, update=True)
def surface_from_curves(): ''' @param display: ''' # First spline array = [] array.append(gp_Pnt(-4, 0, 2)) array.append(gp_Pnt(-7, 2, 2)) array.append(gp_Pnt(-6, 3, 1)) array.append(gp_Pnt(-4, 3, -1)) array.append(gp_Pnt(-3, 5, -2)) pt_list1 = point_list_to_TColgp_Array1OfPnt(array) SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve() # Second spline a2 = [] a2.append(gp_Pnt(-4, 0, 2)) a2.append(gp_Pnt(-2, 2, 0)) a2.append(gp_Pnt(2, 3, -1)) a2.append(gp_Pnt(3, 7, -2)) a2.append(gp_Pnt(4, 9, -1)) pt_list2 = point_list_to_TColgp_Array1OfPnt(a2) SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve() # Fill with StretchStyle aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle) SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0))) SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0))) # Fill with CoonsStyle aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle) SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0))) SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0))) # Fill with CurvedStyle aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle) aBSplineSurface1 = aGeomFill1.Surface() aBSplineSurface2 = aGeomFill2.Surface() aBSplineSurface3 = aGeomFill3.Surface() display.DisplayShape(make_face(aBSplineSurface1, 1e-6)) display.DisplayShape(make_face(aBSplineSurface2, 1e-6)) display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
def pipe(): # the bspline path, must be a wire array2 = TColgp_Array1OfPnt(1, 3) array2.SetValue(1, gp_Pnt(0, 0, 0)) array2.SetValue(2, gp_Pnt(0, 1, 2)) array2.SetValue(3, gp_Pnt(0, 2, 3)) bspline2 = GeomAPI_PointsToBSpline(array2).Curve() path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge() path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire() # the bspline profile. Profile mist be a wire array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, 0)) array.SetValue(2, gp_Pnt(1, 2, 0)) array.SetValue(3, gp_Pnt(2, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) bspline = GeomAPI_PointsToBSpline(array).Curve() profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge() # pipe pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape() display.DisplayShape(profile_edge, update=False) display.DisplayShape(path_wire, update=False) display.DisplayShape(pipe, update=True)
def heightmap_from_image(event=None): """ takes the heightmap from a jpeg file and apply a texture this example requires numpy/matplotlib """ print("opening image") heightmap = Image.open('images/mountain_heightmap.jpg') heightmap.show() width = heightmap.size[0] height = heightmap.size[1] # create the gp_Pnt array print("parse image and fill in point array") for i in range(1, width): for j in range(1, height): # all 3 RGB values are equal, just take the first one # vertex 1 height_value = heightmap.getpixel((i - 1, j - 1))[0] v1 = gp_Pnt(i, j, float(height_value) / 10) # vertex 2 height_value = heightmap.getpixel((i, j - 1))[0] v2 = gp_Pnt(i + 1, j, float(height_value) / 10) # vertex 3 height_value = heightmap.getpixel((i, j))[0] v3 = gp_Pnt(i + 1, j + 1, float(height_value) / 10) # vertex 4 height_value = heightmap.getpixel((i - 1, j))[0] v4 = gp_Pnt(i, j + 1, float(height_value) / 10) # boundaries b1 = boundary_curve_from_2_points(v1, v2) b2 = boundary_curve_from_2_points(v2, v3) b3 = boundary_curve_from_2_points(v3, v4) b4 = boundary_curve_from_2_points(v4, v1) # bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2) bConstrainedFilling.Init(b1, b2, b3, b4, False) srf1 = bConstrainedFilling.Surface() # make a face from this srf patch = BRepBuilderAPI_MakeFace() bounds = True toldegen = 1e-6 patch.Init(srf1, bounds, toldegen) patch.Build() display.DisplayShape(patch.Face()) # then create faces print("%s%%" % int(float(i) / width * 100)) #display.process_events() display.FitAll() # finally display image heightmap.show()
def create_shape(self): data = self.element.attrib.get('d') shapes = [] path = None for cmd, params in self.parse_path(data): if cmd == 'M': if path is not None: shapes.append(path.Wire()) path = BRepBuilderAPI_MakeWire() last_pnt = gp_Pnt(params[0], params[1], 0) start_pnt = last_pnt elif cmd in ['L', 'H', 'V']: pnt = gp_Pnt(params[0], params[1], 0) path.Add(BRepBuilderAPI_MakeEdge(last_pnt, pnt).Edge()) last_pnt = pnt elif cmd == 'Q': # Quadratic Bezier pts = TColgp_Array1OfPnt(1, 3) pts.SetValue(1, last_pnt) pts.SetValue(2, gp_Pnt(params[0], params[1], 0)) last_pnt = gp_Pnt(params[2], params[3], 0) pts.SetValue(3, last_pnt) curve = Geom_BezierCurve(pts) path.Add(BRepBuilderAPI_MakeEdge(curve).Edge()) elif cmd == 'C': # Cubic Bezier pts = TColgp_Array1OfPnt(1, 4) pts.SetValue(1, last_pnt) pts.SetValue(2, gp_Pnt(params[0], params[1], 0)) pts.SetValue(3, gp_Pnt(params[2], params[3], 0)) last_pnt = gp_Pnt(params[4], params[5], 0) pts.SetValue(4, last_pnt) curve = Geom_BezierCurve(pts) path.Add(BRepBuilderAPI_MakeEdge(curve).Edge()) elif cmd == 'A': # Warning: Play at your own risk! x1, y1 = last_pnt.X(), last_pnt.Y() rx, ry, phi, large_arc_flag, sweep_flag, x2, y2 = params phi = radians(phi) pnt = gp_Pnt(x2, y2, 0) cx, cy, rx, ry = compute_arc_center(x1, y1, rx, ry, phi, large_arc_flag, sweep_flag, x2, y2) z_dir = Z_DIR if sweep_flag else NEG_Z_DIR # sweep_flag c = make_ellipse((cx, cy, 0), rx, ry, phi, z_dir) curve = GC_MakeArcOfEllipse(c, last_pnt, pnt, True).Value() path.Add(BRepBuilderAPI_MakeEdge(curve).Edge()) last_pnt = pnt elif cmd == 'Z': if not last_pnt.IsEqual(start_pnt, 10e-6): edge = BRepBuilderAPI_MakeEdge(last_pnt, start_pnt).Edge() path.Add(edge) shapes.append(path.Wire()) path = None # Close path last_pnt = start_pnt if path is not None: shapes.append(path.Wire()) return shapes
def create_shape(self): attrs = self.element.attrib cx = parse_unit(attrs.get('cx', 0)) cy = parse_unit(attrs.get('cy', 0)) r = parse_unit(attrs.get('r', 0)) circle = gp_Circ(gp_Ax2(gp_Pnt(cx, cy, 0), Z_DIR), r) return BRepBuilderAPI_MakeEdge(circle).Edge()
def project_point_on_curve(): ''' ''' point_to_project = gp_Pnt(1., 2., 3.) radius = 5. # create a circle, centered at origin with a given radius circle = Geom_Circle(gp_XOY(), radius) display.DisplayShape(circle) display.DisplayShape(point_to_project, update=True) display.DisplayMessage(point_to_project, "P") # project the point P on the circle projection = GeomAPI_ProjectPointOnCurve(point_to_project, circle) # get the results of the projection # the point projected_point = projection.NearestPoint() # the number of possible results nb_results = projection.NbPoints() print("NbResults : %i" % nb_results) pstring = "N : at Distance : %f" % projection.LowerDistance() display.DisplayMessage(projected_point, pstring) # thre maybe many different possible solutions if nb_results > 0: for i in range(1, nb_results + 1): Q = projection.Point(i) distance = projection.Distance(i) pstring = "Q%i: at Distance :%f" % (i, distance) display.DisplayShape(Q) display.DisplayMessage(Q, pstring)
def heightmap_from_equation(f, x_min=-1, x_max=1, y_min=-1, y_max=1): """ takes an equation z= f(x,y) and plot the related point cloud as a bspline surface """ print("compute surface") n = 100 # initialize x axis step_x = (x_max - x_min) / n x_ = [] for i in range(n): x_.append(x_min + i * step_x) # initialize y axis step_y = (y_max - y_min) / n y_ = [] for i in range(n): y_.append(y_min + i * step_y) # compute z array = TColgp_Array2OfPnt(1, len(x_), 1, len(y_)) i = 1 for x in x_: j = 1 for y in y_: z = f(x, y) point_to_add = gp_Pnt(x, y, z) array.SetValue(i, j, point_to_add) j += 1 i += 1 print("bspline surface creation") bspl_surface = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() display.DisplayShape(bspl_surface, update=True)
def get_transform(self): """ Create a transform which rotates the default axis to align with the normal given by the position Returns ------- transform: gp_Trsf """ d = self.declaration # Move to position and align along direction axis t = gp_Trsf() if d.direction.is_parallel(DZ): t.SetRotation(AZ, d.direction.angle(DZ) + d.rotation) else: d1 = d.direction.cross(DZ) axis = gp_Ax1(gp_Pnt(0, 0, 0), d1.proxy) t.SetRotation(axis, d.direction.angle(DZ)) # Apply the rotation an reverse any rotation added in sign = 1 if d1.y >= 0 else -1 angle = d.rotation + sign * d1.angle(DX) if angle: rot = gp_Trsf() rot.SetRotation(AZ, angle) t.Multiply(rot) t.SetTranslationPart(gp_Vec(*d.position)) return t
def create_shape(self): shape = BRepBuilderAPI_MakePolygon() for m in re.finditer(r'(\-?\d+\.?\d*),(\-?\d+\.?\d*)\s+', self.element.attrib.get('points', '')): x, y = map(float, m.groups()) shape.Add(gp_Pnt(x, y, 0)) return shape.Wire()
def boolean_cut(base): # Create a cylinder cylinder_radius = 0.25 cylinder_height = 2.0 cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, -cylinder_height / 2.0), gp_Dir(0.0, 0.0, 1.0)) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius, cylinder_height) # Repeatedly move and subtract it from the input shape move = gp_Trsf() boolean_result = base clone_radius = 1.0 for clone in range(8): angle = clone * pi / 4.0 # Move the cylinder move.SetTranslation( gp_Vec(cos(angle) * clone_radius, sin(angle) * clone_radius, 0.0)) moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move, True).Shape() # Subtract the moved cylinder from the drilled sphere boolean_result = BRepAlgoAPI_Cut(boolean_result, moved_cylinder).Shape() return boolean_result
def solve_radius(event=None): if not HAS_SCIPY: print("sorry cannot run solve_radius, scipy was not found...") return display.EraseAll() p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(0, 10, 0) p3 = gp_Pnt(0, 10, 10) p4 = gp_Pnt(0, 0, 10) p5 = gp_Pnt(5, 5, 5) poly = make_closed_polygon([p1, p2, p3, p4]) for i in (0.1, 0.5, 1.5, 2., 3., 0.2): rcs = RadiusConstrainedSurface(display, poly, p5, i) rcs.solve() print('Goal: %s radius: %s' % (i, rcs.curr_radius)) time.sleep(0.1)
def generate_shape(): """Create a sphere with faces top and bottom""" sphere_radius = 1.0 sphere_angle = atan(0.5) sphere_origin = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) sphere = BRepPrimAPI_MakeSphere(sphere_origin, sphere_radius, -sphere_angle, sphere_angle).Shape() return sphere
def offset_cube(event=None): S2 = BRepPrimAPI_MakeBox(gp_Pnt(300, 0, 0), 220, 140, 180).Shape() offsetB = BRepOffsetAPI_MakeOffsetShape(S2, -20, 0.01, BRepOffset_Skin, False, False, GeomAbs_Arc) offB = display.DisplayColoredShape(S2, 'BLUE') display.Context.SetTransparency(offB, 0.3, True) display.DisplayColoredShape(offsetB.Shape(), 'GREEN') display.FitAll()
def radius(self, u): '''returns the radius at u ''' # NOT SO SURE IF THIS IS THE SAME THING!!! self._curvature.SetParameter(u) pnt = gp_Pnt() self._curvature.CentreOfCurvature(pnt) return pnt
def glue_solids_edges(event=None): display.EraseAll() display.Context.RemoveAll(True) # With common edges S3 = BRepPrimAPI_MakeBox(500., 400., 300.).Shape() S4 = BRepPrimAPI_MakeBox(gp_Pnt(0., 0., 300.), gp_Pnt(200., 200., 500.)).Shape() faces_S3 = get_faces(S3) faces_S4 = get_faces(S4) # tagging allows to visually find the right faces to glue tag_faces(faces_S3, "BLUE", "s3") tag_faces(faces_S4, "GREEN", "s4") F3, F4 = faces_S3[5], faces_S4[4] glue2 = BRepFeat_Gluer(S4, S3) glue2.Bind(F4, F3) glue2.Build() shape = glue2.Shape() # move the glued shape, such to be able to inspect input and output # of glueing operation trsf = gp_Trsf() trsf.SetTranslation(gp_Vec(750, 0, 0)) shape.Move(TopLoc_Location(trsf)) common_edges = LocOpe_FindEdges(F4, F3) common_edges.InitIterator() n = 0 while common_edges.More(): edge_from = common_edges.EdgeFrom() edge_to = common_edges.EdgeTo() tag_edge(edge_from, "edge_{0}_from".format(n)) tag_edge(edge_to, "edge_{0}_to".format(n)) glue2.Bind(edge_from, edge_to) common_edges.Next() n += 1 tag_faces(get_faces(shape), "BLACK", "") display.FitAll()
def set_position(self, position, direction=None): d = self.declaration direction = direction or d.direction clip_plane = self.clip_plane pln = clip_plane.ToPlane() pln.SetPosition(gp_Ax3(gp_Pnt(*position), gp_Dir(*direction))) clip_plane.SetEquation(pln) self.update_viewer()