Example #1
0
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]);
Example #2
0
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])
Example #3
0
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])
Example #4
0
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])
Example #5
0
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)
Example #6
0
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;
Example #7
0
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();   
Example #8
0
    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
Example #9
0
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()
Example #10
0
def get2dCurveFrom3dEdge(edge):
    """
		returns a curve given an edge.
		here, we want to get a curve from a 3dEdge, since with this approach we'll only be getting existing
		curves from a 3d source
	"""
    # first, convert the curve to a 2d curve
    btool = BRep.BRep_Tool()
    handleCurve = btool.Curve(edge)[0]
    return GeomAPI.GeomAPI().To2d(handleCurve, gp.gp_Pln(gp.gp_Pnt(0, 0, 0), gp.gp().DZ()))
Example #11
0
	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;		
Example #12
0
	def followEdge(self,edgeWrapper,feed):
		#print str(edgeWrapper);
		if self.verbose:
			generator.comment("Follow: " + str(edgeWrapper));
		
		#check to see if we should reverse this edge. Perhaps reversing it will work better.
		if not self.isPointClose(edgeWrapper.firstPoint,0.005):
			#print "moving to start."
			generator.moveTo(edgeWrapper.firstPoint,feed,"G00");		
		
		if edgeWrapper.isLine():
			generator.lineTo(edgeWrapper.lastPoint,feed);
			
		elif edgeWrapper.isCircle() and useArcs:
			circle = edgeWrapper.curve.Circle();
			center = circle.Location();
			
			axisDir = circle.Axis().Direction(); #need this to determine which way the arc goes			
			#assume we are essentially in 2d space, so we're looking only at wehter the
			#axis of the circle is +z or -z
			zDir = gp.gp().DZ();
			
			if edgeWrapper.reversed:
				zDir = zDir.Reversed();
						
			#TODO: handle incremental coordinates
			generator.arc(center.X()-edgeWrapper.firstPoint.X(),center.Y()-edgeWrapper.firstPoint.Y(),
				edgeWrapper.lastPoint.X(),edgeWrapper.lastPoint.Y(),
				edgeWrapper.lastPoint.Z(),zDir.IsEqual(axisDir,TOLERANCE));
			self.lastMove = None;
			
		else:
			edge = edgeWrapper.edge;
			range = Brep_Tool.Range(edge);
			log.debug( "Edge Bounds:" + str(range) );
			hc= Brep_Tool.Curve(edge);
			ad = GeomAdaptor.GeomAdaptor_Curve(hc[0]);
			log.debug(  "Edge is a curve of type:" + str(ad.GetType()));
			
			p1 = hc[1];
			p2 = hc[2];
			gc = GCPnts.GCPnts_QuasiUniformDeflection(ad,0.001,p1,p2);
			i=1;
			numPts = gc.NbPoints();
			log.debug( "Discretized Curve has" + str(numPts) + " points." );
			while i<=numPts:
				if edge.Orientation() == TopAbs.TopAbs_FORWARD:
					tPt = gc.Value(i);
				else:
					tPt = gc.Value(numPts-i+1);
				i+=1;
				generator.movePt(tPt,feed);
			
			#last point is the end
			generator.lineTo(edgeWrapper.lastPoint);
 def _isAtZLevel(self, zLevel, face):
     bf = BRepGProp.BRepGProp_Face(face)
     bounds = bf.Bounds()
     vec = gp.gp_Vec()
     zDir = gp.gp().DZ()
     pt = gp.gp_Pnt()
     #get a normal vector to the face
     bf.Normal(bounds[0], bounds[1], pt, vec)
     z = pt.Z()
     sDir = gp.gp_Dir(vec)
     return (abs(z - zLevel) < 0.0001) and (zDir.IsParallel(sDir, 0.0001))
Example #14
0
 def _isAtZLevel(self, zLevel, face):
     bf = BRepGProp.BRepGProp_Face(face)
     bounds = bf.Bounds()
     vec = gp.gp_Vec()
     zDir = gp.gp().DZ()
     pt = gp.gp_Pnt()
     # get a normal vector to the face
     bf.Normal(bounds[0], bounds[1], pt, vec)
     z = pt.Z()
     sDir = gp.gp_Dir(vec)
     return (abs(z - zLevel) < 0.0001) and (zDir.IsParallel(sDir, 0.0001))
Example #15
0
def get2dCurveFrom3dEdge(edge):
    """
		returns a curve given an edge.
		here, we want to get a curve from a 3dEdge, since with this approach we'll only be getting existing
		curves from a 3d source
	"""
    #first, convert the curve to a 2d curve
    btool = BRep.BRep_Tool()
    handleCurve = btool.Curve(edge)[0]
    return GeomAPI.GeomAPI().To2d(handleCurve,
                                  gp.gp_Pln(gp.gp_Pnt(0, 0, 0),
                                            gp.gp().DZ()))
Example #16
0
def isFaceAtZLevel(zLevel,face):
    bf = BRepGProp.BRepGProp_Face(face);
    bounds = bf.Bounds();
    vec = gp.gp_Vec();
    zDir = gp.gp().DZ();
    pt = gp.gp_Pnt();
    
    #get a normal vector to the face
    bf.Normal(bounds[0],bounds[1],pt,vec);
    z=pt.Z();    
    sDir = gp.gp_Dir(vec);
    return (abs(z - zLevel) < 0.0001 ) and ( zDir.IsParallel(sDir,0.0001))
Example #17
0
    def _computeSlice(self, zLevel, layerNo, fillAngle):

        cSlice = Slice()
        cSlice.zLevel = zLevel
        cSlice.layerNo = layerNo
        cSlice.fillAngle = fillAngle
        cSlice.thickness = self.options.layerHeight

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)

        #makeSection will use the old reliable way that will get a face from each cut.
        #makeSection2 will use BRepAlgoaPI_Section, but has problems ordering the edges correctly.
        newFaces = self.makeSection(cuttingPlane, self.solid.shape, zLevel)
        for f in newFaces:
            cSlice.addFace(Face(f))
        #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(self.solid.shape,halfspace);
        #cutShape = bc.Shape();

        #for face in Topo(cutShape).faces():
        #    if OCCUtil.isFaceAtZLevel(zLevel,face):
        #        cSlice.addFace(Face(face));
        #        break;

        mySum = cSlice.computeFingerPrint()

        #
        #uncomment to enable layer copying.
        #
        #check for identical slices. return matching ones if found.
        if self.sliceMap.has_key(mySum):
            #print "i can copy this layer!"
            return self.sliceMap[mySum].copyToZ(zLevel, layerNo)

        self.sliceMap[mySum] = cSlice
        #print "This slice has %d faces." % len(cSlice.faces)

        if self.options.fillingEnabled:
            self._fillSlice(cSlice)

        return cSlice
Example #18
0
    def _computeSlice(self, zLevel, layerNo, fillAngle):

        cSlice = Slice()
        cSlice.zLevel = zLevel
        cSlice.layerNo = layerNo
        cSlice.fillAngle = fillAngle
        cSlice.thickness = self.options.layerHeight

        # make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)

        # makeSection will use the old reliable way that will get a face from each cut.
        # makeSection2 will use BRepAlgoaPI_Section, but has problems ordering the edges correctly.
        newFaces = self.makeSection(cuttingPlane, self.solid.shape, zLevel)
        for f in newFaces:
            cSlice.addFace(Face(f))
        # 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(self.solid.shape,halfspace);
        # cutShape = bc.Shape();

        # for face in Topo(cutShape).faces():
        #    if OCCUtil.isFaceAtZLevel(zLevel,face):
        #        cSlice.addFace(Face(face));
        #        break;

        mySum = cSlice.computeFingerPrint()

        #
        # uncomment to enable layer copying.
        #
        # check for identical slices. return matching ones if found.
        if self.sliceMap.has_key(mySum):
            # print "i can copy this layer!"
            return self.sliceMap[mySum].copyToZ(zLevel, layerNo)

        self.sliceMap[mySum] = cSlice
        # print "This slice has %d faces." % len(cSlice.faces)

        if self.options.fillingEnabled:
            self._fillSlice(cSlice)

        return cSlice
Example #19
0
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();         
Example #20
0
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 _makeSlice(self, shapeToSlice, zLevel):
        s = Slice()

        #change if layers are variable thickness
        s.sliceHeight = self.sliceHeight
        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()

        #search the shape for faces at the specified zlevel
        texp = TopExp.TopExp_Explorer()
        texp.Init(cutShape, TopAbs.TopAbs_FACE)
        foundFace = False
        while (texp.More()):
            face = ts.Face(texp.Current())
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                logging.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face, self.saveSliceFaces)
            texp.Next()

        #free memory
        face.Nullify()
        bc.Destroy()
        texp.Clear()
        texp.Destroy()

        if not foundFace:
            logging.warn("No faces found after slicing at zLevel " +
                         str(zLevel) + " !. Skipping This layer completely")
            return None
        else:
            return s
Example #22
0
	def _makeSlice(self,shapeToSlice,zLevel):
		s = Slice();
		
		#change if layers are variable thickness
		s.sliceHeight = self.sliceHeight;		
		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();
		
		#search the shape for faces at the specified zlevel
		texp = TopExp.TopExp_Explorer();
		texp.Init(cutShape,TopAbs.TopAbs_FACE);
		foundFace = False;
		while ( texp.More() ):
			face = ts.Face(texp.Current());
			if self._isAtZLevel(zLevel,face):
				foundFace = True;
				logging.debug( "Face is at zlevel" + str(zLevel) );
				s.addFace(face,self.saveSliceFaces);
			texp.Next();
		
		#free memory
		face.Nullify();
		bc.Destroy();
		texp.Clear();
		texp.Destroy();
			
		if not foundFace:
			logging.warn("No faces found after slicing at zLevel " + str(zLevel) + " !. Skipping This layer completely");
			return None;
		else:				
			return s;		
Example #23
0
def normalEdgeAtParameter(edge, param, length ):
	"compute an edge having length at the specified parameter on the supplied curve:"

	ew = Wrappers.Edge(edge);
	zDir = gp.gp().DZ();
	zVec = gp.gp_Vec(zDir);
	
	tangent = gp.gp_Vec();
	tanpoint = gp.gp_Pnt();
	
	curve = ew.curve;
	curve.D1(param,tanpoint,tangent );
	axis = gp.gp_Ax1(tanpoint, gp.gp_Dir(tangent.Crossed(zVec) ) );
	
	line = Geom.Geom_Line(axis );
	return  BRepBuilderAPI.BRepBuilderAPI_MakeEdge(line.GetHandle(),0, length).Edge();
Example #24
0
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)
Example #25
0
	def followEdge(self,e,finish=False):
		"""
		return a sequence of points for an edge as a generator
		NOTE: this algorithm leaves a potential linear move not returned,
		so you have to check pendingLinearMove at the end and return  it if not null
		"""
		
		ew = Wrappers.Edge(e);
		log.debug("Follow Edge: " + str(ew));
		
		#if no current point, move to the first edge.
		if not self.currentPoint:
			log.debug("No Current Point, Move to start.");
			"no current point defined yet."
			self.currentPoint = ew.firstPoint;
			yield LinearMove(None,ew.firstPoint,False);
		else:
			"there is a current point. But if the start of the edge is not close, we have to move there"
			if self.isClose(ew.firstPoint):
				log.debug("No moved Required to get to edge start.");
			else:
				log.debug("Must Move to first point, running any previous move.");
				t= self._fetchPendingMove();
				p = None;
				if t:
					p = t.toPoint;
					yield t;
				
				log.debug("Moving to First Point of Edge");
				self.currentPoint = ew.firstPoint;
				yield LinearMove(p,ew.firstPoint,False);
				
		if ew.isLine():
			"the last move was a line, and this one is too."
			"if this move is parallel to the last one, then we'll dump that one"
			"and replace it with this one. otherwise, we'll execute it first"
			thisMoveDir = gp.gp_Vec(ew.firstPoint,ew.lastPoint);
			if self.pendingLinearMove:				
				if  not self.pendingLinearMove.dir.IsParallel(thisMoveDir,self.tolerance):
					"this move is parallel to the last one, so replace with this one"
					log.info("Move is redundant, replacing with this one.");
					yield self.pendingLinearMove;

			log.debug("Saving Move as Pending.");
			self.pendingLinearMove = LinearMove(ew.firstPoint,ew.lastPoint,True);
			self.currentPoint = ew.lastPoint;
		else:
			t= self._fetchPendingMove();
			if t:
				log.debug("Flushing a pending linear move...");
				yield t;

			if ew.isCircle() and self.useArcs:
				log.debug("Curve is a Circle");
				circle = ew.curve.Circle();
				center = circle.Location();

				axisDir = circle.Axis().Direction();				
				#assume we are essentially in 2d space, so we're looking only at wehter the
				#axis of the circle is +z or -z
				zDir = gp.gp().DZ();
				
				if ew.reversed:
					zDir = zDir.Reversed();
				ccw = zDir.IsEqual(axisDir,self.tolerance);	
				self.currentPoint = ew.lastPoint;
				
				includedAngle = abs( ew.firstParameter - ew.lastParameter );
				a = ArcMove(ew.firstPoint, ew.lastPoint, center, ccw ,includedAngle);
				#circles are parameterized between zero and 2*pi.
				yield a;
				#yield  ArcMove(ew.firstPoint, ew.lastPoint, center, ccw );				
			else:
				log.debug("Curve is not a line or a circle");
				"a curve, or a circle we'll approximate"
				#the generated points might include the beginning of the curve,
				#so test for that, but only for the first point
				firstP = True;
				lastPoint = None;
				for p in ew.discretePoints(self.approximatedCurveDeflection):
					#check the first generated point for a duplicate
					if firstP and self.isClose(p):
						firstP = False;
						continue;
					
					yield LinearMove(lastPoint,p,True);
					lastPoint = p;

				self.currentPoint = lastPoint;
				
		#flush any last remaining move
		if finish:
			t= self._fetchPendingMove();
			if t:
				yield t;	
Example #26
0
def makeCircleWire():
    circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(0, 2, 0),
                                  gp.gp().DZ()), .75)
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0, 1.25, 0),
                                                gp.gp_Pnt(0, 1.25, 0)).Edge()
    return Wrappers.wireFromEdges([e2])
Example #27
0
def makeCircleWire():
	circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(0,2,0),gp.gp().DZ()),.75);
	e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, gp.gp_Pnt(0,1.25,0),gp.gp_Pnt(0,1.25,0)).Edge();
	return Wrappers.wireFromEdges([e2]);
Example #28
0
    def followEdge(self, e, finish=False):
        """
		return a sequence of points for an edge as a generator
		NOTE: this algorithm leaves a potential linear move not returned,
		so you have to check pendingLinearMove at the end and return  it if not null
		"""

        ew = Wrappers.Edge(e)
        log.debug("Follow Edge: " + str(ew))

        #if no current point, move to the first edge.
        if not self.currentPoint:
            log.debug("No Current Point, Move to start.")
            "no current point defined yet."
            self.currentPoint = ew.firstPoint
            yield LinearMove(None, ew.firstPoint, False)
        else:
            "there is a current point. But if the start of the edge is not close, we have to move there"
            if self.isClose(ew.firstPoint):
                log.debug("No moved Required to get to edge start.")
            else:
                log.debug(
                    "Must Move to first point, running any previous move.")
                t = self._fetchPendingMove()
                p = None
                if t:
                    p = t.toPoint
                    yield t

                log.debug("Moving to First Point of Edge")
                self.currentPoint = ew.firstPoint
                yield LinearMove(p, ew.firstPoint, False)

        if ew.isLine():
            "the last move was a line, and this one is too."
            "if this move is parallel to the last one, then we'll dump that one"
            "and replace it with this one. otherwise, we'll execute it first"
            thisMoveDir = gp.gp_Vec(ew.firstPoint, ew.lastPoint)
            if self.pendingLinearMove:
                if not self.pendingLinearMove.dir.IsParallel(
                        thisMoveDir, self.tolerance):
                    "this move is parallel to the last one, so replace with this one"
                    log.info("Move is redundant, replacing with this one.")
                    yield self.pendingLinearMove

            log.debug("Saving Move as Pending.")
            self.pendingLinearMove = LinearMove(ew.firstPoint, ew.lastPoint,
                                                True)
            self.currentPoint = ew.lastPoint
        else:
            t = self._fetchPendingMove()
            if t:
                log.debug("Flushing a pending linear move...")
                yield t

            if ew.isCircle() and self.useArcs:
                log.debug("Curve is a Circle")
                circle = ew.curve.Circle()
                center = circle.Location()

                axisDir = circle.Axis().Direction()
                #assume we are essentially in 2d space, so we're looking only at wehter the
                #axis of the circle is +z or -z
                zDir = gp.gp().DZ()

                if ew.reversed:
                    zDir = zDir.Reversed()
                ccw = zDir.IsEqual(axisDir, self.tolerance)
                self.currentPoint = ew.lastPoint

                includedAngle = abs(ew.firstParameter - ew.lastParameter)
                a = ArcMove(ew.firstPoint, ew.lastPoint, center, ccw,
                            includedAngle)
                #circles are parameterized between zero and 2*pi.
                yield a
                #yield  ArcMove(ew.firstPoint, ew.lastPoint, center, ccw );
            else:
                log.debug("Curve is not a line or a circle")
                "a curve, or a circle we'll approximate"
                #the generated points might include the beginning of the curve,
                #so test for that, but only for the first point
                firstP = True
                lastPoint = None
                for p in ew.discretePoints(self.approximatedCurveDeflection):
                    #check the first generated point for a duplicate
                    if firstP and self.isClose(p):
                        firstP = False
                        continue

                    yield LinearMove(lastPoint, p, True)
                    lastPoint = p

                self.currentPoint = lastPoint

        #flush any last remaining move
        if finish:
            t = self._fetchPendingMove()
            if t:
                yield t
Example #29
0
	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;
	
if __name__=='__main__':

	circle = gp.gp_Circ(gp.gp_Ax2(gp.gp_Pnt(0,0,0),gp.gp().DZ()),1);
	
	#make a few edges
	e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle,5,6.2).Edge();
	TestDisplay.display.showShape(e1);

	for e in normalEdgesAlongEdge(e1,0.1,0.1 ):
		TestDisplay.display.showShape(e);
		
	
	e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(0,0,0),gp.gp_Pnt(1,1,0)).Edge();
	TestDisplay.display.showShape(e2);

	for e in normalEdgesAlongEdge(e2,0.1,0.1 ):
		TestDisplay.display.showShape(e);