def addEdge(self, edge):
        loop = self._currentLoop()
        range = btool.Range(edge)
        logging.debug("Edge Bounds:" + str(range))
        hc = btool.Curve(edge)
        ad = GeomAdaptor.GeomAdaptor_Curve(hc[0])

        #this could be simplified-- QuasiUnformDeflection probably handles a line
        #correcly anyway?

        #if ad.GetType() == GeomAbs.GeomAbs_Line:
        #	logging.debug( "Edge Appears to be a line." );
        #	if edge.Orientation() == TopAbs.TopAbs_FORWARD:
        #		bPt = btool.Pnt(topexp.FirstVertex(edge))
        #		ePt = btool.Pnt(topexp.LastVertex(edge))
        #	else:
        #		bPt = btool.Pnt(topexp.LastVertex(edge))
        #		ePt = btool.Pnt(topexp.FirstVertex(edge))
        #	loop.addPoint(bPt.X(),bPt.Y());
        #	loop.addPoint(ePt.X(),ePt.Y());
        #
        #else:
        logging.debug("Edge is a curve of type:" + str(ad.GetType()))
        gc = GCPnts.GCPnts_QuasiUniformDeflection(ad, 0.1, hc[1], hc[2])
        i = 1
        numPts = gc.NbPoints()
        logging.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
            loop.addPoint(tPt.X(), tPt.Y())
Beispiel #2
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);
Beispiel #3
0
 def discretePoints(self, deflection):
     "a generator for all the points on the edge, in forward order"
     gc = GCPnts.GCPnts_QuasiUniformDeflection(self.curve, deflection,
                                               self.firstParameter,
                                               self.lastParameter)
     print "Making Dicrete Points!"
     i = 1
     numPts = gc.NbPoints()
     while i <= numPts:
         if self.reversed:
             yield gc.Value(numPts - i + 1)
         else:
             yield gc.Value(i)
         i += 1
Beispiel #4
0
def pointsFromWire(wire, spacing):
    "Makes a single parameterized adapter curve from a wire"

    points = []
    #make a parameterized approximation of the wire
    adaptor = BRepAdaptor.BRepAdaptor_CompCurve(wire)
    adaptor.SetPeriodic(True)
    gc = GCPnts.GCPnts_UniformAbscissa(adaptor, spacing, 0.0001)

    if gc.IsDone():
        log.info("Computed %d Points Successfully for the wire." %
                 gc.NbPoints())
        for i in range(1, gc.NbPoints()):
            points.append(adaptor.Value(gc.Parameter(i)))

    #workaround: for some odd reason periodic curves do not honor the start and the end
    #so work around by removing the last point if it is too close to the first one
    if points[0].Distance(points[len(points) - 1]) < spacing:
        points.pop()
        log.info("Correcing for GCPnts periodic curve bug")

    return points