def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp point1[direction] = point0[direction] if (point1[direction-1] == point0[direction-1] or point1[direction-2] == point0[direction-2]): raise InvalidInputException points = [] # add two other corners: for i in range(3): if i != direction: point = point0[:] point[i] = point1[i] points.append(point) points.insert(1, point0) points.insert(3, point1) builder = BRepBuilderAPI.BRepBuilderAPI_MakePolygon() for pnt in points: builder.Add(gp.gp_Pnt(*pnt)) builder.Build() builder.Close() polygon = builder.Wire() face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(polygon).Face() self._final = [face] return self._final
def make_ellipsoid(focus1, focus2, major_axis): """ @param focus1: length 3 sequence giving first focus location @param focus2: length 3 sequence giving second focus location @param path_length: major axis length """ f1 = numpy.asarray(focus1) f2 = numpy.asarray(focus2) direction = -(f1 - f2) centre = (f1 + f2)/2. sep = numpy.sqrt((direction**2).sum()) minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 ) sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(minor_axis) scale = gp.gp_GTrsf() scale.SetValue(3,3, major_axis/minor_axis) ellipse = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), scale) loc = gp.gp_Ax3() loc.SetLocation(gp.gp_Pnt(*centre)) loc.SetDirection(gp.gp_Dir(*direction)) tr = gp.gp_Trsf() tr.SetTransformation(loc, gp.gp_Ax3()) trans = BRepBuilderAPI.BRepBuilderAPI_Transform(ellipse.Shape(), tr) shape = toshape(trans) return shape
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == point1: raise InvalidInputException dirvec = vec(0, 0, 0) dirvec[direction] = 1 axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir()) d = point0 - inp d[direction] = 0 dist = d.length() a = Geom.Geom_Circle(axis, dist).GetHandle() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire() d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face() self._final = [d] return self._final
def makeOffsetTestWire(): "creates difficult test cases for offsetting" p1 = OCCUtil.pnt(11.0, 0) p2 = OCCUtil.pnt(7.0, 8.0) p3 = OCCUtil.pnt(7.0, 12.0) p4 = OCCUtil.pnt(17.0, 22.0) p5 = OCCUtil.pnt(0.0, 22.0) p6 = OCCUtil.pnt(3.0, 17.0) p7 = OCCUtil.pnt(4.0, 8.0) c1 = OCCUtil.pnt(10.0, 18.5) c2 = OCCUtil.pnt(6.0, 3.0) edges = [] edges.append(OCCUtil.edgeFromTwoPoints(p1, p2)) edges.append(OCCUtil.edgeFromTwoPoints(p2, p3)) circle = GC.GC_MakeArcOfCircle(p3, c1, p4) #circle through 3 points e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge() edges.append(e2) edges.append(OCCUtil.edgeFromTwoPoints(p4, p5)) edges.append(OCCUtil.edgeFromTwoPoints(p5, p6)) edges.append(OCCUtil.edgeFromTwoPoints(p6, p7)) circle = GC.GC_MakeArcOfCircle(p1, c2, p7) #circle through 3 points e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle.Value()).Edge() edges.append(e3) return OCCUtil.wireFromEdges(edges)
def make_interp_parabola(FL, rmin, rmax, segments=50): A = 1./(4*FL) x = numpy.linspace(rmin, rmax, segments) y = (A * x**2) - FL points = [(X,0,Z) for X,Z in zip(x,y)] points.append((x[0],0,y[-1])) def pairs(itr): a,b = itertools.tee(itr) next(b) return zip(a,b) edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge( gp.gp_Pnt(*p1), gp.gp_Pnt(*p2)) for p1, p2 in pairs(points)) last_edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge( gp.gp_Pnt(*points[-1]), gp.gp_Pnt(*points[0])) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) wire.Add(last_edge.Edge()) face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire()) ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0), gp.gp_Dir(0,0,1)) revol = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax) return revol.Shape()
def makeCircleWire(): "designed to be include inside the square to simulate an island" circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 2, 0), gp.gp().DZ()), 1) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) return mw.Wire()
def OrientShape(self): # Intended to be called at end of CreateShape # Shape is expected to be in default position and orientation T = gp_Trsf() u = self.orientation.u v = self.orientation.v w = self.orientation.w #T.SetValues(u[0],u[1],u[2],0,v[0],v[1],v[2],0,w[0],w[1],w[2],0) T.SetValues(u[0],v[0],w[0],0,u[1],v[1],w[1],0,u[2],v[2],w[2],0) self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape() T.SetTranslation(gp_Vec(self.center[0],self.center[1],self.center[2])) self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape()
def make_wire(listOfPoints, close=False): vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in listOfPoints] edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) for v1,v2 in pairs(vertices)] if close: edges.append(BRepBuilderAPI.BRepBuilderAPI_MakeEdge(vertices[-1].Vertex(), vertices[0].Vertex())) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) return toshape(wire)
def makeHeartWire(): "make a heart wire" e1 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(4.0, 4.0, 0)) circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(2, 4, 0), gp.gp().DZ()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(4, 4, 0), gp.gp_Pnt(0, 4, 0)).Edge() circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(-2, 4, 0), gp.gp().DZ()), 2) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 4, 0), gp.gp_Pnt(-4, 4, 0)).Edge() e4 = Wrappers.edgeFromTwoPoints(gp.gp_Pnt(-4, 4, 0), gp.gp_Pnt(0, 0, 0)) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def makeSquareWithRoundHole(): points = [(0, 0), (0.05, -1.0), (1.0, 0), (2.0, 0), (2.0, 6.0), (0.0, 6.0)] ow = makeWireFromPointList(points) circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(1.0, 2, 0), gp.gp().DZ()), 0.75) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) circle = mw.Wire() builder = BRepBuilderAPI.BRepBuilderAPI_MakeFace(ow, True) builder.Add(circle) return builder.Face()
def makeHexArray(self, bottomLeftCenter, countX, countY): """ makes an array of hexagons bottomLeftCenter is the center of the top left hex, as a three-element tuple countX is the number of hexes in the x direction countY is the number of hexes in the y direction returns a list of wires representing a hexagon fill pattern """ pattern = self.makePeriodic(bottomLeftCenter) wireBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeWire(pattern) #make horizontal array tsf = gp.gp_Trsf() pDist = 2.0 * self.cartesianSpacing()[0] tsf.SetTranslation(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(pDist, 0, 0)) tx = BRepBuilderAPI.BRepBuilderAPI_Transform(tsf) currentShape = pattern for i in range(1, int((countX / 2) + 1)): tx.Perform(currentShape, False) currentShape = tx.Shape() #display.DisplayShape(currentShape); wireBuilder.Add(Wrappers.cast(currentShape)) #create an array by alternately offsetting one cell right and #moving down topHalf = wireBuilder.Wire() #topHalf= approximatedWire(topHalf); wires = [] wires.append(topHalf) dY = self.cartesianSpacing()[1] / 2.0 dX = self.cartesianSpacing()[0] ####TODO// performance note. This method takes about 31ms to compute 1000x1000 hex. # pretty good, except that nearly 50% of the time is spent in makeTransform!!! # a much better method would be to use the same transform object somehow for i in range(1, int(countY * 2)): if i % 2 == 0: t = makeTransform(0, dY * i, 0) else: t = makeTransform(dX, dY * i, 0) t.Perform(topHalf, False) w = Wrappers.cast(t.Shape()) #approximate the wire #wires.append ( approximatedWire(w)); wires.append(w) #display.DisplayShape(wires); return wires
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == inp: raise InvalidInputException a = GC.GC_MakeSegment(inp, point0).Value() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()] return self._final
def makeReversedWire(): "this is a square" p1 = gp.gp_Pnt(.5, .5, 0) p2 = gp.gp_Pnt(1, 4, 0) p3 = gp.gp_Pnt(2, 4, 0) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge() e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p2).Edge() e2.Reverse() e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p1).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) mw.Add(e2) mw.Add(e3) return mw.Wire()
def fixShape(shape): """ fixes a shape """ log.info("Fixing holes and degenerated Meshes...") sf = ShapeFix.ShapeFix_Shape(shape) sf.SetMaxTolerance(TOLERANCE) msgRegistrator = ShapeExtend.ShapeExtend_MsgRegistrator() sf.SetMsgRegistrator(msgRegistrator.GetHandle()) sf.Perform() log.info("ShapeFix Complete.") for i in range(0, 18): log.info("ShapeFix Status %d --> %s" % (i, sf.Status(i))) fixedShape = sf.Shape() #fixedShape = shape; return fixedShape #if the resulting shape is a compound, we need to convert #each shell to a solid, and then re-create a new compound of solids if fixedShape.ShapeType() == TopAbs.TopAbs_COMPOUND: log.warn("Shape is a compound. Creating solids for each shell.") builder = BRep.BRep_Builder() newCompound = TopoDS.TopoDS_Compound() #newCompound = TopoDS.TopoDS_CompSolid(); builder.MakeCompound(newCompound) #builder.MakeCompSolid(newCompound); for shell in Topo(fixedShape).shells(): solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(shell) solid = solidBuilder.Solid() sa = SolidAnalyzer(solid) print sa.friendlyDimensions() builder.Add(newCompound, solid) #time.sleep(4); #Topology.dumpTopology(newCompound); return newCompound #return temporarily after the first one else: log.info("Making Solid from the Shell...") solidBuilder = BRepBuilderAPI.BRepBuilderAPI_MakeSolid( ts.Shell(fixedShape)) return solidBuilder.Solid()
def preview(self, input, direction): point = input if self.step == 0 and point is not None: point1 = gp_.gp_Pnt_([0, 0, 0]) a = GC.GC_MakeSegment(point1, point).Value() self._final = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Shape() return self._final,
def copyToZ(self, z): "makes a copy of this slice, transformed to the specified z height" theCopy = Slice() theCopy.zLevel = z theCopy.zHeight = self.zHeight theCopy.sliceHeight = self.sliceHeight theCopy.fillWidth = self.fillWidth theCopy.hatchDir = self.hatchDir theCopy.checkSum = self.checkSum #make transformation p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(0, 0, z) xform = gp.gp_Trsf() xform.SetTranslation(p1, p2) bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform) #copy all of the faces for f in hSeqIterator(self.faces): bt.Perform(f, True) theCopy.addFace(Wrappers.cast(bt.Shape())) #copy all of the fillWires for w in hSeqIterator(self.fillWires): bt.Perform(w, True) #TestDisplay.display.showShape(bt.Shape() ); theCopy.fillWires.Append(Wrappers.cast(bt.Shape())) #copy all of the fillEdges for e in hSeqIterator(self.fillEdges): bt.Perform(e, True) #TestDisplay.display.showShape(bt.Shape() ); theCopy.fillEdges.Append(Wrappers.cast(bt.Shape())) return theCopy
def makeBsplineEdge(): pts = [] pts.append(OCCUtil.pnt(0.0, 0)) pts.append(OCCUtil.pnt(1.0, 0.0)) pts.append(OCCUtil.pnt(1.2, 0.1)) pts.append(OCCUtil.pnt(2.0, 2.0)) pts.append(OCCUtil.pnt(2.0, 2.4)) pts.append(OCCUtil.pnt(3.0, 2.4)) pts.append(OCCUtil.pnt(4.0, 1.5)) pts.append(OCCUtil.pnt(5.0, 1.5)) pts.append(OCCUtil.pnt(4.0, 0)) pts.append(OCCUtil.pnt(3.0, -0.1)) pts.append(OCCUtil.pnt(2.0, -0.1)) pts.append(OCCUtil.pnt(2.0, -0.1)) pts.append(OCCUtil.pnt(2.0, 0.2)) pts.append(OCCUtil.pnt(3.0, 0.5)) pts.append(OCCUtil.pnt(3.0, 1.0)) points = TColgp.TColgp_HArray1OfPnt(1, len(pts)) i = 1 for p in pts: points.SetValue(i, p) i += 1 #q = time.clock(); #for i in range(1000): gi = GeomAPI.GeomAPI_Interpolate(points.GetHandle(), False, 0.001) gi.Perform() curve = gi.Curve() #print "1000 iters: Elapsed: %0.3f " % ( time.clock() - q) builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(curve) return builder.Edge()
def intersectWiresUsingDistShapeShape(wire, edges): "intersect a wire with a series of edges. naive algorithm without bounding box sorting " ipoints = [] w = Wrappers.Wire(wire) circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(2, 4), gp.gp().DX2d()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(4, 4), tP(0, 4)).Edge() TestDisplay.display.showShape(e2) e4 = edgeFromTwoPoints((-4, 4), (0, 0)) TestDisplay.display.showShape(e4) brp = BRepExtrema.BRepExtrema_DistShapeShape(e2, e4) print "runing" brp.Perform() print "done" if brp.Value() < 0.001: print "intersection found!" #TODO need to handle the somewhat unusual cases that the intersection is #on a vertex for k in range(1, brp.NbSolution() + 1): p1 = brp.PointOnShape1(k) ipoints.append(p1.X(), p1.Y()) return (count, ipoints)
def makeSquareWire(): "this is a square" p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(5, 0, 0) p3 = gp.gp_Pnt(5, 5, 0) p4 = gp.gp_Pnt(0, 5, 0) e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2).Edge() e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2, p3).Edge() e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p3, p4).Edge() e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4, p1).Edge() mw = BRepBuilderAPI.BRepBuilderAPI_MakeWire() mw.Add(e1) mw.Add(e2) mw.Add(e3) mw.Add(e4) return mw.Wire()
def edgeFromTwoPoints(p1, p2): builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2) builder.Build() if builder.IsDone(): return builder.Edge() else: return None
def makeSection2(self, cuttingPlane, shapeToSection, zLevel): """ Uses BrepSection Algo. this generally returns a list of wires, not a face """ #section is certainly faster, but produces only edges. #those have to be re-organized into wires, probably #using ShapeAnalysis_WireOrder face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI.BRepAlgoAPI_Section(self.solid.shape, face) #section = BRepAlgo.BRepAlgo_Section(self.solid.shape,face); section.Build() if section.IsDone(): #Topology.dumpTopology(section.Shape()); #what we got back was a compound of edges t = Topo(section.Shape()) wb = OCCUtil.MultiWireBuilder() for e in t.edges(): wb.addEdge(e) wires = wb.getWires() print wires for w in wires: Topology.dumpTopology(w) return wires else: raise Exception("Could not compute Section!")
def copyToZ(self, z, layerNo): "makes a copy of this slice, transformed to the specified z height" theCopy = Slice() theCopy.zLevel = z theCopy.fillAngle = self.fillAngle theCopy.layerNo = layerNo theCopy.thickness = self.thickness #make transformation p1 = gp.gp_Pnt(0, 0, 0) p2 = gp.gp_Pnt(0, 0, z) xform = gp.gp_Trsf() xform.SetTranslation(p1, p2) bt = BRepBuilderAPI.BRepBuilderAPI_Transform(xform) #copy all of the faces for f in self.faces: bt.Perform(f.face, True) newFace = Face(OCCUtil.cast(bt.Shape())) #copy shells for shell in f.shellWires: #print shell bt.Perform(shell, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) #copy fillWires for fill in f.fillWires: bt.Perform(fill, True) newFace.shellWires.append(OCCUtil.cast(bt.Shape())) theCopy.addFace(newFace) return theCopy
def makeHeartWire2d(): "make a heart wire in 2d" e1 = edgeFromTwoPoints((0, 0), (4.0, 4.0)) circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(2, 4), gp.gp().DX2d()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(4, 4), tP(0, 4)).Edge() circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(-2, 4), gp.gp().DX2d()), 2) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(0, 4), tP(-4, 4)).Edge() e4 = edgeFromTwoPoints((-4, 4), (0, 0)) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def make_rays_wires(listOfRays, scale=None): raysItr = iter(listOfRays) first = next(raysItr) def MakeVertex(pt): vt = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*pt)) #print "make vertex", pt, vt return vt def MakeEdge(v1, v2): e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex()) #print "make edge", v1, v2, e return e wires = [BRepBuilderAPI.BRepBuilderAPI_MakeWire() for i in range(first.origin.shape[0])] v_start = [MakeVertex(pt) for pt in first.origin] v_end = [MakeVertex(pt) for pt in first.termination] first_edges = [MakeEdge(v1,v2) for v1, v2 in zip(v_start, v_end)] for edge, wire in zip(first_edges, wires): wire.Add(edge.Edge()) id_map = list(range(len(wires))) for rays in raysItr: id_map = [id_map[pid] for pid in rays.parent_idx] v_start = [v_end[pid] for pid in rays.parent_idx] v_end = [MakeVertex(pt) for pt in rays.termination] edges = [MakeEdge(v1,v2) for v1, v2 in zip(v_start, v_end)] for edge, w_id in zip(edges, id_map): wires[w_id].Add(edge.Edge()) return make_compound([w.Shape() for w in wires])
def normalEdgesAlongEdge(edge, length , interval): "compute an edge having length at the specified parameter on the supplied curve:" edgeList = []; ew = Wrappers.Edge(edge); zDir = gp.gp().DZ(); zVec = gp.gp_Vec(zDir); curve = ew.curve; pStart = ew.firstParameter; pEnd = ew.lastParameter; for p in Wrappers.frange6(pStart,pEnd,interval): tangent = gp.gp_Vec(); tanpoint = gp.gp_Pnt(); curve.D1(p,tanpoint,tangent ); axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) ); line = Geom.Geom_Line(axis ); e = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge(); if e: edgeList.append(e); return edgeList;
def CreateShape(self): outer = occprim.BRepPrimAPI_MakeCylinder(self.outer_radius,self.length).Shape() inner = occprim.BRepPrimAPI_MakeCylinder(self.inner_radius,self.length).Shape() self.occ_shape = occalgo.BRepAlgoAPI_Cut(outer,inner).Shape() T = gp_Trsf() T.SetTranslation(gp_Vec(0,0,-self.length/2)) self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape() self.OrientShape()
def edgeFromTwoPoints(p1, p2): "make a linear edge from two points " builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p1, p2) builder.Build() if builder.IsDone(): return builder.Edge() else: return None
def CreateShape(self): self.occ_shape = occprim.BRepPrimAPI_MakeCylinder( self.radius, self.length).Shape() T = gp_Trsf() T.SetTranslation(gp_Vec(0, 0, -self.length / 2)) self.occ_shape = occbuild.BRepBuilderAPI_Transform( self.occ_shape, T, False).Shape() self.OrientShape()
def _makeSlice(self, shapeToSlice, zLevel): s = Slice() #used to determine if a slice is identical to others. s.hatchDir = self.hatchReversed s.fillWidth = self.options.filling.fillWidth #change if layers are variable thickness s.sliceHeight = self.options.layerHeight s.zLevel = zLevel #make a cutting plane p = gp.gp_Pnt(0, 0, zLevel) origin = gp.gp_Pnt(0, 0, zLevel - 1) csys = gp.gp_Ax3(p, gp.gp().DZ()) cuttingPlane = gp.gp_Pln(csys) bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane) face = bff.Face() #odd, a halfspace is faster than a box? hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin) hs.Build() halfspace = hs.Solid() #make the cut bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace) cutShape = bc.Shape() foundFace = False for face in Topo(cutShape).faces(): if self._isAtZLevel(zLevel, face): foundFace = True log.debug("Face is at zlevel" + str(zLevel)) s.addFace(face) #TestDisplay.display.showShape(face); log.debug("Face" + str(face)) if self.options.useSliceFactoring: mySum = s.getCheckSum() #print 'Slice Created, Checksum is',mySum; for otherSlice in self.slices: #print "Slice Checksum=",otherSlice.getCheckSum(); if mySum == otherSlice.getCheckSum(): log.info( "This slice matches another one exactly. using that so we can save time." ) return otherSlice.copyToZ(zLevel) if not foundFace: log.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely") return None else: return s
def makeKeyHoleWire(): circle2 = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(40, 40, 2), gp.gp_Dir(0, 0, 1)), 10) Edge4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle2, gp.gp_Pnt(40, 50, 2), gp.gp_Pnt(50, 40, 2)).Edge() ExistingWire2 = BRepBuilderAPI.BRepBuilderAPI_MakeWire(Edge4).Wire() P1 = gp.gp_Pnt(50, 40, 2) P2 = gp.gp_Pnt(80, 40, 2) #5,204,0 Edge5 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(P1, P2).Edge() MW = BRepBuilderAPI.BRepBuilderAPI_MakeWire() MW.Add(Edge5) MW.Add(ExistingWire2) if MW.IsDone(): WhiteWire = MW.Wire() return [WhiteWire, Edge5, ExistingWire2]