Example #1
0
        public bool IsAdjacentTo(FlatFace otherFace)
        {
            if (this == otherFace)
            {
                throw new InvalidOperationException();
            }

            foreach (FlatLoop thisLoop in loops)
            {
                foreach (FlatFin thisFin in thisLoop.Fins)
                {
                    foreach (FlatLoop otherLoop in otherFace.Loops)
                    {
                        foreach (FlatFin otherFin in otherLoop.Fins)
                        {
                            if (otherFin.AdjacentFin == thisFin)
                            {
                                return(true);
                            }

                            if (thisFin.AdjacentFin == otherFin)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Example #2
0
        public bool FaceInterferes(FlatFace candidateFace)
        {
            Body tool   = candidateFace.CreateUnfoldedFaceBody();
            Body target = flatBodyShape.Copy();

            return(target.GetCollision(tool) == Collision.Intersect);
        }
Example #3
0
        public void AddFace(FlatFace flatFace)
        {
            flatFaces.Add(flatFace);
            flatPattern.FlatFaceMapping[flatFace.SourceFace] = flatFace;

            foreach (FlatLoop flatLoop in flatFace.Loops)
            {
                foreach (FlatFin flatFin in flatLoop.Fins)
                {
                    Face testFace = flatFin.FlatFace.SourceFace.GetAdjacentFace(flatFin.SourceFin.Edge);
                    if (testFace == null)                      // one-sided (laminar) edge
                    {
                        continue;
                    }
                    if (!FlatPattern.FlatFaceExists(testFace))
                    {
                        openFins.Add(flatFin);
                    }

                    List <FlatFin> removeFins = new List <FlatFin>();
                    foreach (FlatFin baseFin in openFins)
                    {
                        if (baseFin.SourceFin.Edge.Equals(flatFin.SourceFin.Edge) && !baseFin.FlatFace.Equals(flatFace))
                        {
                            removeFins.Add(baseFin);
                        }
                    }
                    foreach (FlatFin removeFin in removeFins)
                    {
                        openFins.Remove(removeFin);
                    }
                }
            }

            openFins.Sort(new FlatFin.FlatFinComparer());              // get longest fin --TBD use sorted list structure?
            openFins.Reverse();

            if (flatPattern.IsDetectingIntersections)
            {
                Body body = flatFace.CreateUnfoldedFaceBody();
                if (flatBodyShape == null)
                {
                    flatBodyShape = body;
                }
                else
                {
                    try {
                        flatBodyShape.Unite(new Body[] { body });
                    }
                    catch {
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "flatBodyShape", flatBodyShape);
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "tool", body);
                        Debug.Fail("Boolean failed when merging flatBodyShape.");
                    }
                }
            }
        }
Example #4
0
        public FlatLoop(Loop sourceLoop, FlatFace flatFace)
        {
            this.sourceLoop = sourceLoop;
            this.flatFace = flatFace;

            fins = new List<FlatFin>();
            foreach (Fin fin in sourceLoop.Fins)
                fins.Add(new FlatFin(this, fin));
        }
        public FlatLoop(Loop sourceLoop, FlatFace flatFace)
        {
            this.sourceLoop = sourceLoop;
            this.flatFace   = flatFace;

            fins = new List <FlatFin>();
            foreach (Fin fin in sourceLoop.Fins)
            {
                fins.Add(new FlatFin(this, fin));
            }
        }
Example #6
0
        public FlatFin OtherFlatFin(FlatFace flatFace)
        {
            foreach (FlatLoop flatLoop in flatFace.Loops)
            {
                foreach (FlatFin flatFin in flatLoop.Fins)
                {
                    if (flatFin.SourceFin.Edge.Equals(this.SourceFin.Edge))
                    {
                        return(flatFin);
                    }
                }
            }

            Debug.Fail("Could not find other FlatFin!");
            return(null);
        }
Example #7
0
        /*
         * LoopUnfold attempts to add as many FlatFaces to a FlatBody as it can.  If interference checking is off, it will add all of the
         * faces of the body. (Actually, the shell, as we do not handle voids).  We expect for the seed face of the FlatBody to already
         * be created, so we have some FlatFins from which to propogate.
         *
         * If interference checking is on, multiple flat bodies are required to avoid collisions.  Therefore
         * we return the list of FlatFins on the completed FlatBody that need to start as the seeds for additional FlatBodies.  By returning
         * the FlatFins on the base, rather than just the faces, we can easily transfrom the adjacent FlatFace to line up with that FlatFin
         * by making it the seed face for the next FlatBody.
         */

        // TBD add tab code would go here, created extra flatfaces, but we need to consider the tabs as part of the collision detection???

        private List <FlatFin> LoopUnfold(FlatBody flatBody)
        {
            Debug.Assert(flatBody.FlatFaces.Count > 0);              // should only be one, but more is harmless if we optimize with seeds of several flatfaces

            List <FlatFin> remainingFins = new List <FlatFin>();

            while (flatBody.OpenFins.Count > 0)
            {
                if (AddInHelper.IsEscDown)
                {
                    break;
                }

                FlatFace       testFace        = null;
                List <FlatFin> interferingFins = new List <FlatFin>();

                foreach (FlatFin baseFin in flatBody.OpenFins)                    // OpenFins sorts itself to present the most desirable edge (the longest)
                {
                    testFace            = new FlatFace(baseFin.FlatFace.SourceFace.GetAdjacentFace(baseFin.SourceFin.Edge), flatBody);
                    baseFin.AdjacentFin = baseFin.OtherFlatFin(testFace);                      // make symmetric? Careful: FlatFace.Render() relies on the assumption it is not

                    testFace.Transform = Matrix.CreateMapping(AddInHelper.CreateFrame(baseFin.Start, (baseFin.End - baseFin.Start).Direction, -Direction.DirZ)) *
                                         Matrix.CreateMapping(AddInHelper.CreateFrame(baseFin.AdjacentFin.SourceEnd, (baseFin.AdjacentFin.SourceStart - baseFin.AdjacentFin.SourceEnd).Direction, baseFin.AdjacentFin.FlatFace.SourcePlane.Frame.DirZ)).Inverse;

                    if (isDetectingCollisions && flatBody.FaceInterferes(testFace))                      // FaceInterferes only gets called if isDetectingCollisions == True
                    {
                        interferingFins.Add(baseFin);
                    }
                    else
                    {
                        flatBody.AddFace(testFace);
                        baseFin.IsInternal             = true;
                        baseFin.AdjacentFin.IsInternal = true;
                        break;
                    }
                }

                foreach (FlatFin baseFin in interferingFins)
                {
                    flatBody.OpenFins.Remove(baseFin);
                    remainingFins.Add(baseFin);
                }
            }

            return(remainingFins);
        }
Example #8
0
        public void AddFace(FlatFace flatFace)
        {
            flatFaces.Add(flatFace);
            flatPattern.FlatFaceMapping[flatFace.SourceFace] = flatFace;

            foreach (FlatLoop flatLoop in flatFace.Loops) {
                foreach (FlatFin flatFin in flatLoop.Fins) {
                    Face testFace = flatFin.FlatFace.SourceFace.GetAdjacentFace(flatFin.SourceFin.Edge);
                    if (testFace == null)  // one-sided (laminar) edge
                        continue;
                    if (!FlatPattern.FlatFaceExists(testFace)) {
                        openFins.Add(flatFin);
                    }

                    List<FlatFin> removeFins = new List<FlatFin>();
                    foreach (FlatFin baseFin in openFins)
                        if (baseFin.SourceFin.Edge.Equals(flatFin.SourceFin.Edge) && !baseFin.FlatFace.Equals(flatFace))
                            removeFins.Add(baseFin);
                    foreach (FlatFin removeFin in removeFins)
                        openFins.Remove(removeFin);
                }
            }

            openFins.Sort(new FlatFin.FlatFinComparer());  // get longest fin --TBD use sorted list structure?
            openFins.Reverse();

            if (flatPattern.IsDetectingIntersections) {
                Body body = flatFace.CreateUnfoldedFaceBody();
                if (flatBodyShape == null)
                    flatBodyShape = body;
                else {
                    try {
                        flatBodyShape.Unite(new Body[] { body });
                    }
                    catch {
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "flatBodyShape", flatBodyShape);
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "tool", body);
                        Debug.Fail("Boolean failed when merging flatBodyShape.");
                    }
                }
            }
        }
Example #9
0
        private void LoopFlatBodies(Face startFace)
        {
            List <FlatFin> remainingFins = new List <FlatFin>();
            FlatFin        nextFin       = null;

            while (true)
            {
                FlatBody flatBody = new FlatBody(this);
                flatBodies.Add(flatBody);

                FlatFace baseFace = new FlatFace(startFace, flatBody);

                FlatLoop flatLoop = null;
                foreach (FlatLoop testLoop in baseFace.Loops)
                {
                    if (testLoop.SourceLoop.IsOuter)
                    {
                        flatLoop = testLoop;
                        break;
                    }
                }
                Debug.Assert(flatLoop != null);

                Point startPoint = flatLoop.SourcePoints[0];
                Point endPoint   = flatLoop.SourcePoints[1];
                Frame startFrame = Frame.Create(startPoint, (endPoint - startPoint).Direction, baseFace.SourcePlane.Frame.DirZ);

                Frame endFrame;
                if (nextFin == null)                 // Pick the origin on the first pass, otherwise place it where it overlaps
                {
                    endFrame = Frame.Create(Point.Origin, Direction.DirX, -Direction.DirZ);
                }
                else                 // use the location of the open fin on the FlatBody where it couldn't be placed
                {
                    endFrame = Frame.Create(nextFin.End, (nextFin.Start - nextFin.End).Direction, -Direction.DirZ);
                }

                baseFace.Transform = Matrix.CreateMapping(endFrame) * Matrix.CreateMapping(startFrame).Inverse;
                flatBody.AddFace(baseFace);

                remainingFins.AddRange(LoopUnfold(flatBody));                  // Most of the unfolding work is here

                List <FlatFin> cleanRemainingFins = new List <FlatFin>();
                foreach (FlatFin flatFin in remainingFins)
                {
                    if (!FlatFaceExists(flatFin.AdjacentFin.FlatFace.SourceFace))
                    {
                        cleanRemainingFins.Add(flatFin);
                    }
                }
                remainingFins = cleanRemainingFins;

                if (remainingFins.Count == 0)
                {
                    return;
                }
                else
                {
                    nextFin = remainingFins[0];
                    remainingFins.Remove(nextFin);
                    startFace = nextFin.AdjacentFin.FlatFace.SourceFace;
                }
            }
        }
Example #10
0
        public bool FaceInterferes(FlatFace candidateFace)
        {
            Body tool = candidateFace.CreateUnfoldedFaceBody();
            Body target = flatBodyShape.Copy();

            return target.GetCollision(tool) == Collision.Intersect;
        }
Example #11
0
        public bool IsAdjacentTo(FlatFace otherFace)
        {
            if (this == otherFace)
                throw new InvalidOperationException();

            foreach (FlatLoop thisLoop in loops) {
                foreach (FlatFin thisFin in thisLoop.Fins) {
                    foreach (FlatLoop otherLoop in otherFace.Loops) {
                        foreach (FlatFin otherFin in otherLoop.Fins) {
                            if (otherFin.AdjacentFin == thisFin)
                                return true;

                            if (thisFin.AdjacentFin == otherFin)
                                return true;
                        }
                    }
                }
            }

            return false;
        }