示例#1
0
    def updateCenterWithCommand(cls, commandArgs: List[str],
                                initial: QVector3D, nextPoint: QVector3D,
                                absoluteIJKMode: bool,
                                clockwise: bool) -> QVector3D:
        i = qQNaN()
        j = qQNaN()
        k = qQNaN()
        r = qQNaN()
        c = ""

        for t in commandArgs:
            if len(t) > 0:
                # c = t[0].upper().toLatin1()
                c = t[0].upper()
                if c == 'I':
                    i = float(t[1:])
                elif c == 'J':
                    j = float(t[1:])
                elif c == 'K':
                    k = float(t[1:])
                elif c == 'R':
                    r = float(t[1:])

        if qIsNaN(i) and qIsNaN(j) and qIsNaN(k):
            return cls.convertRToCenter(initial, nextPoint, r, absoluteIJKMode,
                                        clockwise)

        return cls.updatePointWithCommand_FromVector3D(initial, i, j, k,
                                                       absoluteIJKMode)
示例#2
0
    def processCommand(self, args: List[str]) -> PointSegment:
        gCodes = []
        ps = None

        # Handle F code
        speed = GcodePreprocessorUtils.parseCoord(args, 'F')
        if not qIsNaN(speed):
            if self.m_isMetric:
                self.m_lastSpeed = speed
            else:
                self.m_lastSpeed = speed * 25.4

        # Handle S code
        spindleSpeed = GcodePreprocessorUtils.parseCoord(args, 'S')
        if not qIsNaN(spindleSpeed):
             self.m_lastSpindleSpeed = spindleSpeed

        # Handle P code
        dwell = GcodePreprocessorUtils.parseCoord(args, 'P')
        if not qIsNaN(dwell):
            self.m_points[-1].setDwell(dwell)

        # handle G codes.
        gCodes = GcodePreprocessorUtils.parseCodes(args, 'G')

        # If there was no command, add the implicit one to the party.
        if len(gCodes) == 0 and self.m_lastGcodeCommand != -1:
            gCodes.append(self.m_lastGcodeCommand)
        
        for code in gCodes:
            ps = self.handleGCode(code, args)

        return ps
示例#3
0
 def testLength(self, start: QVector3D, end: QVector3D):
     length = (start - end).length()
     if (not qIsNaN(length)) and length != 0:
         if qIsNaN(self.m_minLength):
             self.m_minLength = length
         else:
             self.m_minLength = min(self.m_minLength, length)
示例#4
0
 def nMax(cls, v1: float, v2: float) -> float:
     if (not qIsNaN(v1)) and (not qIsNaN(v2)):
         return max(v1, v2)
     elif not qIsNaN(v1):
         return v1
     elif not qIsNaN(v2):
         return v2
     else:
         return qQNaN()
示例#5
0
    def generatePointsAlongArcBDring_Arc(
            cls, plane: PointSegment.Plane, start: QVector3D, end: QVector3D,
            center: QVector3D, clockwise: bool, R: float, minArcLength: float,
            arcPrecision: float, arcDegreeMode: bool) -> List[QVector3D]:
        '''
        Generates the points along an arc including the start and end points.
        '''
        radius = R

        # Rotate vectors according to plane
        m = QMatrix4x4()
        m.setToIdentity()
        if plane == PointSegment.Plane.XY:
            pass
        elif plane == PointSegment.Plane.ZX:
            m.rotate(90, 1.0, 0.0, 0.0)
        elif plane == PointSegment.Plane.YZ:
            m.rotate(-90, 0.0, 1.0, 0.0)

        start = m * start
        end = m * end
        center = m * center

        # Check center
        if qIsNaN(center.length()):
            return []

        # Calculate radius if necessary.
        if radius == 0:
            radius = math.sqrt(
                math.pow((start.x() - center.x(), 2.0) +
                         math.pow(end.y() - center.y(), 2.0)))

        startAngle = cls.getAngle(center, start)
        endAngle = cls.getAngle(center, end)
        sweep = cls.calculateSweep(startAngle, endAngle, clockwise)

        # Convert units.
        arcLength = sweep * radius

        numPoints = 0

        if arcDegreeMode and arcPrecision > 0:
            numPoints = max(1.0, sweep / (cls.M_PI * arcPrecision / 180))
        else:
            if arcPrecision <= 0 and minArcLength > 0:
                arcPrecision = minArcLength

            numPoints = math.ceil(arcLength / arcPrecision)

        return cls.generatePointsAlongArcBDring_Num(plane, start, end, center,
                                                    clockwise, radius,
                                                    startAngle, sweep,
                                                    numPoints)
示例#6
0
    def updateExtremes(self, drawable: ShaderDrawable):
        if not qIsNaN(drawable.getMinimumExtremes().x()): 
            self.m_xMin = drawable.getMinimumExtremes().x() 
        else: 
            self.m_xMin = 0
        
        if not qIsNaN(drawable.getMaximumExtremes().x()): 
            self.m_xMax = drawable.getMaximumExtremes().x() 
        else: self.m_xMax = 0
        
        if not qIsNaN(drawable.getMinimumExtremes().y()): 
            self.m_yMin = drawable.getMinimumExtremes().y() 
        else: 
            self.m_yMin = 0
        
        if not qIsNaN(drawable.getMaximumExtremes().y()):
             self.m_yMax = drawable.getMaximumExtremes().y() 
        else: 
            self.m_yMax = 0
        
        if not qIsNaN(drawable.getMinimumExtremes().z()):
             self.m_zMin = drawable.getMinimumExtremes().z()
        else: 
            self.m_zMin = 0
        
        if not qIsNaN(drawable.getMaximumExtremes().z()): 
            self.m_zMax = drawable.getMaximumExtremes().z() 
        else: 
            self.m_zMax = 0

        self.m_xSize = self.m_xMax - self.m_xMin
        self.m_ySize = self.m_yMax - self.m_yMin
        self.m_zSize = self.m_zMax - self.m_zMin
示例#7
0
    def updateProgramEstimatedTime(self, lines: List[LineSegment]) -> QTime:
        time = 0

        for line in lines:
            ls = LineSegment(line)
            #  foreach (LineSegment *ls, lines) {
            length = (ls.getEnd() - ls.getStart()).length()

            if not qIsNaN(length) and not qIsNaN(
                    ls.getSpeed()) and ls.getSpeed() != 0:
                cond1 = self.ui.slbFeedOverride.isChecked(
                ) and not ls.isFastTraverse()
                cond2 = self.ui.slbRapidOverride.isChecked(
                ) and ls.isFastTraverse()

                speed = ls.getSpeed()
                val1 = (speed * self.ui.slbFeedOverride.value() / 100)
                val2 = speed

                if cond1:
                    time += val1
                else:
                    if cond2:
                        time += val1
                    else:
                        time += val2  # Update for rapid override

        time *= 60

        t = QTime()

        t.setHMS(0, 0, 0)
        t = t.addSecs(time)

        self.ui.glwVisualizer.setSpendTime(QTime(0, 0, 0))
        self.ui.glwVisualizer.setEstimatedTime(t)

        return t
示例#8
0
    def addArcPointSegment(self, nextPoint: QVector3D, clockwise: bool, args: List[str]) -> PointSegment:
        ps = PointSegment.PointSegment_FromQVector3D(nextPoint, self.m_commandNumber)

        self.m_commandNumber += 1

        center = GcodePreprocessorUtils.updateCenterWithCommand(args, self.m_currentPoint, nextPoint, self.m_inAbsoluteIJKMode, clockwise)
        radius = GcodePreprocessorUtils.parseCoord(args, 'R')

        # Calculate radius if necessary.
        if qIsNaN(radius):
            m = QMatrix4x4()
            m.setToIdentity()

            if self.m_currentPlane == PointSegment.Plane.XY:
                pass
            elif self.m_currentPlane == PointSegment.Plane.ZX:
                m.rotate(90, 1.0, 0.0, 0.0)
            elif self.m_currentPlane == PointSegment.Plane.YZ:
                m.rotate(-90, 0.0, 1.0, 0.0)

            radius = math.sqrt( \
                math.pow(((m * self.m_currentPoint).x() - (m * center).x()), 2.0) + \
                math.pow(((m * self.m_currentPoint).y() - (m * center).y()), 2.0))

        ps.setIsMetric(self.m_isMetric)
        ps.setArcCenter(center)
        ps.setIsArc(True)
        ps.setRadius(radius)
        ps.setIsClockwise(clockwise)
        ps.setIsAbsolute(self.m_inAbsoluteMode)
        ps.setSpeed(self.m_lastSpeed)
        ps.setSpindleSpeed(self.m_lastSpindleSpeed)
        ps.setPlane(self.m_currentPlane)
        self.m_points.append(ps)

        # Save off the endpoint.
        self.m_currentPoint = nextPoint
        return ps
示例#9
0
    def updatePointWithCommand_FromVector3D(cls, initial: QVector3D, x: float,
                                            y: float, z: float,
                                            absoluteMode: bool) -> QVector3D:
        '''
        Update a point given the new coordinates.
        '''
        newPoint = QVector3D(initial.x(), initial.y(), initial.z())

        if absoluteMode:
            if not qIsNaN(x): newPoint.setX(x)
            if not qIsNaN(y): newPoint.setY(y)
            if not qIsNaN(z): newPoint.setZ(z)
        else:
            if not qIsNaN(x): newPoint.setX(newPoint.x() + x)
            if not qIsNaN(y): newPoint.setY(newPoint.y() + y)
            if not qIsNaN(z): newPoint.setZ(newPoint.z() + z)

        return newPoint
示例#10
0
    def generateG1FromPoints(cls, start: QVector3D, end: QVector3D,
                             absoluteMode: bool, precision: int) -> str:
        sb = "G1"

        if absoluteMode:
            if not qIsNaN(end.x()):
                sb.append("X" + "%.*f" % (precision, end.x()))
            if not qIsNaN(end.y()):
                sb.append("Y" + "%.*f" % (precision, end.y()))
            if not qIsNaN(end.z()):
                sb.append("Z" + "%.*f" % (precision, end.z()))
        else:
            if not qIsNaN(end.x()):
                sb.append("X" + "%.*f" % (precision, end.x() - start.x()))
            if not qIsNaN(end.y()):
                sb.append("Y" + "%.*f" % (precision, end.y() - start.y()))
            if not qIsNaN(end.z()):
                sb.append("Z" + "%.*f" % (precision, end.z() - start.z()))

        return sb
示例#11
0
 def handleMCode(self, code: float, args: List[str]):
     spindleSpeed = GcodePreprocessorUtils.parseCoord(args, 'S')
     if not qIsNaN(spindleSpeed):
         self.m_lastSpindleSpeed = spindleSpeed
示例#12
0
    def parse_gcode(self, gcode: str):
        '''
        '''
        self.reset()
        self.gcode = gcode

        lastX = sNaN
        lastY = sNaN
        lastZ = sNaN
        lastF = sNaN

        def parse() -> float:
            self.char_no += 1
            while self.char_no < len(
                    self.gcode) and (self.gcode[self.char_no] == ' '
                                     or self.gcode[self.char_no] == '\t'):
                self.char_no += 1
            begin = self.char_no
            while (self.char_no < len(self.gcode)
                   and self.gcode[self.char_no] in "+-.0123456789"):
                self.char_no += 1
            try:
                end = self.char_no
                return float(self.gcode[begin:end])
            except Exception:
                return None

        self.char_no = 0
        self.line_no = 0

        while self.char_no < len(self.gcode):

            g = sNaN
            x = sNaN
            y = sNaN
            z = sNaN
            f = sNaN

            while self.char_no < len(
                    self.gcode
            ) and self.gcode[self.char_no] != '' and self.gcode[
                    self.char_no] != '\r' and self.gcode[self.char_no] != '\n':
                if self.gcode[self.char_no] == 'G' or self.gcode[
                        self.char_no] == 'g':
                    g = parse()
                elif self.gcode[self.char_no] == 'X' or self.gcode[
                        self.char_no] == 'x':
                    x = parse()
                elif self.gcode[self.char_no] == 'Y' or self.gcode[
                        self.char_no] == 'y':
                    y = parse()
                elif self.gcode[self.char_no] == 'Z' or self.gcode[
                        self.char_no] == 'z':
                    z = parse()
                elif self.gcode[self.char_no] == 'F' or self.gcode[
                        self.char_no] == 'f':
                    f = parse()
                else:
                    self.char_no += 1

            if g == 0 or g == 1:
                if not qIsNaN(x):
                    if qIsNaN(lastX):
                        for j in range(len(self.path)):
                            self.path[j][0] = x
                    lastX = x

                if not qIsNaN(y):
                    if qIsNaN(lastY):
                        for j in range(len(self.path)):
                            self.path[j][1] = y
                    lastY = y

                if not qIsNaN(z):
                    if qIsNaN(lastZ):
                        for j in range(len(self.path)):
                            self.path[j][2] = z
                    lastZ = z

                if not qIsNaN(f):
                    if qIsNaN(lastF):
                        for j in range(len(self.path)):
                            self.path[j][3] = f
                    lastF = f

                self.path.append([lastX, lastY, lastZ, lastF])
                self.path_idx_line_no[len(self.path) - 1] = self.line_no

            while self.char_no < len(self.gcode) and self.gcode[
                    self.char_no] != '\r' and self.gcode[self.char_no] != '\n':
                self.char_no += 1
            while self.char_no < len(
                    self.gcode) and (self.gcode[self.char_no] == '\r'
                                     or self.gcode[self.char_no] == '\n'):
                if self.gcode[self.char_no] == '\n':
                    self.line_no += 1
                self.char_no += 1

        # last thing
        self.eval_path_time()