Пример #1
0
 internal void ProcessNextFrame()
 {
     if (!m_GoBufferProcessing)
     {
         m_ActiveSentence = doc.NCProgram.Sentences[m_SentencePointer++];
         ProcessSentence();
     }
     else
     {
         Vector3D direction;
         if (m_GoBufferProcessing)
         {
             if (m_ActiveSentence.GoBuffer.Count > 0)
             {
                 direction = m_ActiveSentence.GoBuffer.Dequeue();
                 Debug.Assert(!EpsilonTests.IsNearlyZeroEpsHigh(direction.Length()));
                 BVHPolyMesh2D tsv = m_TSVCalculator.FeedRate2D(doc.ToolSet.ActiveSlot.Tool, direction);
                 Do2DBooleanOps(doc.Parts[0], tsv);
                 doc.ToolSet.ActiveSlot.Tool.Translate(direction);
                 if (m_ActiveSentence.GoBuffer.Count == 0)
                     m_GoBufferProcessing = false;
             }
             else
                 m_GoBufferProcessing = false;
         }
     }
 }
Пример #2
0
 internal void AddSentence(Sentence s)
 {
     list.Add(s);
 }
Пример #3
0
        /*
        * author:      Florian Ennemoser
        * desc:        Calculates the values for a circle segment.
        * parameters:  curCommand: The currend cnc command including x,y,i and k values
        *              prevCommand: The previous command where the tool is currently positioned
        */
        public void ProcessCurve(Sentence curCommand, Sentence prevCommand, Queue<Vector3D> goBuffer, ref Vector3D absStart)
        {
            if (EpsilonTests.IsNearlyZeroEpsHigh(curCommand.I) && EpsilonTests.IsNearlyZeroEpsHigh(curCommand.K))
                throw new Exception("Either I or K must be greater/less than zero");

            double l = 0.00; // the distance between the start point on the circle segment and the end point on the circle segment
            double r = Math.Sqrt(Math.Abs(curCommand.I) * Math.Abs(curCommand.I) + Math.Abs(curCommand.K) * Math.Abs(curCommand.K)); // circle radius
            double arc = 0.00; //the arc

            if (EpsilonTests.IsNearlyZeroEpsHigh(prevCommand.Y - curCommand.Y)) //special case: angle is 180°
            {
                if (EpsilonTests.IsNearlyZeroEpsHigh(curCommand.I)) //circle origin lies directly on the horizontal axis of start- end endpoint of circle
                {
                    arc = 2 * r * Math.PI * 0.5;
                }
                else
                {
                    l = Math.Abs(prevCommand.X - curCommand.X);
                    arc = Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
                }
            }
            else if (EpsilonTests.IsNearlyZeroEpsHigh(Math.Abs(prevCommand.X - curCommand.X) - Math.Abs(curCommand.K)) && EpsilonTests.IsNearlyZeroEpsHigh(Math.Abs(curCommand.I))) //special case: angle is 90° or 270°
            {
                if(IsGreaterHalfCircle())
                    arc = 2 * r * Math.PI * 0.75;
                else
                    arc = 2 * r * Math.PI * 0.25;
            }
            else //angle is ]90°,180°[
            {
                l = Math.Sqrt(Math.Pow(Math.Abs(prevCommand.Y) - Math.Abs(curCommand.Y), 2) + Math.Pow(Math.Abs(prevCommand.X) - Math.Abs(curCommand.X), 2));
                if (IsGreaterHalfCircle())
                    arc = 2 * r * Math.PI -  Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
                else
                    arc = Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
            }

            Debug.Assert(arc > 0, "The arc must be greater than 0");
            Debug.Assert(r > 0, "The radius must be greater than 0");

               // double segment = 12.566370614359172953850573533118;
               // double segment = 6.28139;
            double segment = 0.2;
            int counter = 1;
            double xPrev = Math.Abs(curCommand.K); //x-distance from circle center point to tool-position of last frame
            double yPrev = Math.Abs(curCommand.I); //y-distance from circle center point to tool-position of last frame
            Quadrant startQuadrant = GetQuadrant(curCommand.I, curCommand.K); //quadrant where arc starts
            Quadrant curQuadrant = startQuadrant;
            Quadrant prevQuadrant = startQuadrant;
            double alpha = CalcStartAngle(curCommand.interpolationMode, r, startQuadrant, curCommand.I);
            Vector3D amount;

            while (segment * counter < arc || EpsilonTests.IsNearlyZeroEpsHigh(arc - segment * counter))
            {
                alpha += segment / r;
                GetQuadrant(alpha, startQuadrant, ref curQuadrant, ref prevQuadrant, curCommand.interpolationMode);
                double deltaX = calcX(ref xPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                double deltaY = calcY(ref yPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                prevQuadrant = curQuadrant;
                amount = new Vector3D(deltaX,deltaY,0);

                if (!EpsilonTests.IsGreaterEpsHigh(amount.Length()))
                    throw new Exception("Length too small: " + amount.Length());
                goBuffer.Enqueue(amount);

                counter++;
            }

            double arcLeft = arc - segment * (counter-1);
            if (!EpsilonTests.IsNearlyZeroEpsHigh(arcLeft))
            {
                alpha += arcLeft / r;
                GetQuadrant(alpha, startQuadrant, ref curQuadrant, ref prevQuadrant, curCommand.interpolationMode);
                double deltaX = calcX(ref xPrev, alpha, r, startQuadrant,  curQuadrant, prevQuadrant, curCommand.interpolationMode);
                double deltaY = calcY(ref yPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                amount = new Vector3D(deltaX, deltaY, 0);
                double l1 = amount.Length();
                if (amount.Length() >= 0.0001)
                    goBuffer.Enqueue(amount);
                else
                {
                    Vector3D last = goBuffer.Last();
                    last.X += amount.X;
                    last.Y += amount.Y;
                    Debug.Assert(last.Z == 0);
                }
            }

            #if DEBUG
            double overallX = 0;
            double overallY = 0;
            foreach (Vector3D v in goBuffer)
            {
                overallX += v.X;
                overallY += v.Y;
            }
            #endif
            absStart = new Vector3D(curCommand.X,curCommand.Y,0);
        }
Пример #4
0
 internal void Reset()
 {
     m_TrajCalculator = new TrajectoryCalculator(doc);
     m_TSVCalculator = new TSVCalculator(doc);
     m_ActiveSentence = null;
     m_SentencePointer = 0;
     m_GoBufferProcessing = false;
 }