Ejemplo n.º 1
0
        private void RotateSide(TubeM currentPos, int Angle)
        {
            var kondi = 1;

            switch (Angle)
            {
            case 270:
                kondi = -1;
                break;

            default:
                kondi = 1;
                break;
            }
            var centerRow        = (SidePincer1.Row + SidePincer2.Row) / 2;
            var centerColumn     = (SidePincer1.Column + SidePincer2.Column) / 2;
            var secondPincer1col = centerColumn + (12 + TranslationMainUp) * kondi * Math.Round(Math.Sin((RotationSide + 90) * Math.PI / 180));
            var secondPincer2col = centerColumn - (12 + TranslationMainUp) * kondi * Math.Round(Math.Sin((RotationSide + 90) * Math.PI / 180));
            var secondPincer1row = centerRow + (12 + TranslationMainUp) * kondi * Math.Round(Math.Cos((RotationSide + 90) * Math.PI / 180));
            var secondPincer2row = centerRow - (12 + TranslationMainUp) * kondi * Math.Round(Math.Cos((RotationSide + 90) * Math.PI / 180));

            if (Tubes.Where(x => x.Row == secondPincer1row).Where(y => y.Column == secondPincer1col).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                Tubes.Where(x => x.Row == secondPincer2row).Where(y => y.Column == secondPincer2col).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
            {
                RotationSide = (short)(RotationSide + kondi * 90);
                SidePincer1  = Tubes.Where(x => x.Row == secondPincer1row).Where(y => y.Column == secondPincer1col).FirstOrDefault();
                SidePincer2  = Tubes.Where(x => x.Row == secondPincer2row).Where(y => y.Column == secondPincer2col).FirstOrDefault();
            }
        }
Ejemplo n.º 2
0
        public Object Clone()
        {
            StyleCollection res = new StyleCollection();

            List <StyleObject> allStyles = new List <StyleObject>();

            res.AllStyles = allStyles;

            res.Poles = Poles.Clone() as PoleStyle;
            allStyles.Add(res.Poles);

            res.Tubes = Tubes.Clone() as TubeStyle;
            allStyles.Add(res.Tubes);

            res.Chromosomes = Chromosomes.Clone() as ChromosomeStyle;
            allStyles.Add(res.Chromosomes);

            res.Springs = Springs.Clone() as SpringStyle;
            allStyles.Add(res.Springs);

            res.Cell = Cell.Clone() as CellStyle;
            allStyles.Add(res.Cell);

            return(res);
        }
Ejemplo n.º 3
0
        private void Pathfinder(TubeM currentPos, int row, int column, List <TubeM> pathList)
        {
            bool rS = false;
            bool cS = false;

            if ((EnNode.Row - currentPos.Row) > 0)
            {
                row += 1;
                rS   = true;
            }
            else if ((EnNode.Row - currentPos.Row) < 0)
            {
                row -= 1;
                rS   = true;
            }
            if ((EnNode.Column - currentPos.Column) > 0)
            {
                column += 1;
                cS      = true;
            }
            else if ((EnNode.Column - currentPos.Column) < 0)
            {
                column -= 1;
                cS      = true;
            }
            var currentPos1 = Tubes.Where(x => x.Row == row).Where(y => y.Column == column).Where(x => x.ColorProp != "Black").FirstOrDefault();

            if (currentPos1 == null)
            {
                if (rS && cS)
                {
                    currentPos1 = Tubes.Where(x => x.Row == currentPos.Row).Where(y => y.Column == column).Where(x => x.ColorProp != "Black").FirstOrDefault();
                    if (currentPos1 != null)
                    {
                        currentPos = currentPos1;
                        row        = currentPos.Row;
                    }
                    else
                    {
                        currentPos = Tubes.Where(x => x.Row == row).Where(y => y.Column == currentPos.Column).Where(x => x.ColorProp != "Black").FirstOrDefault();
                        column     = currentPos.Column;
                    }
                }
                //additional elses must be added
            }
            else
            {
                currentPos = currentPos1;
            }
            pathList.Add(currentPos);
            if (currentPos != EnNode)
            {
                if (currentPos.ColorProp != "Red")
                {
                    currentPos.ColorProp = "Blue";
                }
                Pathfinder(currentPos, row, column, pathList);
            }
        }
Ejemplo n.º 4
0
        private void ResetColor()
        {
            var blueTubes = Tubes.Where(x => x.ColorProp == "Blue");

            foreach (var item in blueTubes)
            {
                item.ColorProp = "Gray";
            }
        }
Ejemplo n.º 5
0
        public void ClearTubeAtIndex(int index)
        {
            if (index == Tubes.Count)
            {
                CloseTube();
            }

            Destroy(Tubes[index]);
            Tubes.RemoveAt(index);
        }
Ejemplo n.º 6
0
        public void CloseTube()
        {
            if (CurrentSegment == null)
            {
                return;
            }

            AddLoop();
            EndTubeSegment();
            TubeFrontSphere.transform.SetParent(CurrentTubeParent.transform);
            Tubes.Add(CurrentTubeParent);
            CurrentTubeParent = null;
        }
Ejemplo n.º 7
0
        private TubeM ShiftMain(TubeM currentPos, List <int> coordinates)
        {
            var rows    = coordinates.First();
            var columns = coordinates.Last();

            if ((rows * rows + columns * columns) > 98)
            {//needs improvement
                int i = 6 - TranslationMainUp;
                while (i > 0)
                {
                    var rowMain1    = MainPincer1.Row + Math.Round(Math.Cos(Math.PI * RotationMain / 180)) * i;
                    var columnMain1 = MainPincer1.Column + Math.Round(Math.Sin(Math.PI * RotationMain / 180)) * i;
                    var rowMain2    = MainPincer2.Row + Math.Round(Math.Cos(Math.PI * RotationMain / 180)) * i;
                    var columnMain2 = MainPincer2.Column + Math.Round(Math.Sin(Math.PI * RotationMain / 180)) * i;
                    if (Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                        Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
                    {
                        MainPincer1 = Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).FirstOrDefault();
                        MainPincer2 = Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).FirstOrDefault();
                        var currentPosrow = currentPos.Row + Math.Round(Math.Cos(Math.PI * RotationMain / 180)) * i;
                        var currentPoscol = currentPos.Column + Math.Round(Math.Sin(Math.PI * RotationMain / 180)) * i;
                        currentPos = Tubes.Where(x => x.Row == currentPosrow).Where(y => y.Column == currentPoscol).FirstOrDefault();
                        pathList.Add(currentPos);
                        break;
                    }
                    i = i - 1;
                }

                if (i == 0)
                {
                    if (TranslationMainRight < 12)
                    {
                        TranslationMainRight += 1;
                        ShiftMain(currentPos, coordinates);
                    }
                    else
                    {
                        currentPos = TryToRotate(currentPos, 90);
                        ShiftMain(currentPos, coordinates);
                    }
                }
                TranslationMainUp = (short)(TranslationMainUp + i);
            }
            else
            {
                currentPos = EnNode;
            }
            return(currentPos);
        }
Ejemplo n.º 8
0
        private void SetStartPincers()
        {
            var mainPincer1row = -1 * Math.Round(Math.Cos(Math.PI * StartingAngle / 180)) + StNode.Row;
            var mainPincer1col = -1 * Math.Round(Math.Sin(Math.PI * StartingAngle / 180)) + StNode.Column;
            var mainPincer2row = -15 * Math.Round(Math.Cos(Math.PI * StartingAngle / 180)) + StNode.Row;
            var mainPincer2col = -15 * Math.Round(Math.Sin(Math.PI * StartingAngle / 180)) + StNode.Column;

            MainPincer1 = Tubes.Where(x => x.Row == mainPincer1row).Where(x => x.Column == mainPincer1col).Where(x => x.ColorProp != "Black").FirstOrDefault();
            MainPincer2 = Tubes.Where(x => x.Row == mainPincer2row).Where(x => x.Column == mainPincer2col).Where(x => x.ColorProp != "Black").FirstOrDefault();
            if (MainPincer1 == null || MainPincer2 == null)
            {
                ResetCoordinates();
                return;
            }
            RotationMain = StartingAngle;
            RotationSide = (short)(RotationMain + 45);
            var centerRow        = (mainPincer1row + mainPincer2row) / 2;
            var centerColumn     = (mainPincer1col + mainPincer2col) / 2;
            var secondPincer1col = centerColumn + 12 * Math.Round(Math.Sin(RotationSide * Math.PI / 180));
            var secondPincer2col = centerColumn - 12 * Math.Round(Math.Sin(RotationSide * Math.PI / 180));
            var secondPincer1row = centerRow + 12 * Math.Round(Math.Cos(RotationSide * Math.PI / 180));
            var secondPincer2row = centerRow - 12 * Math.Round(Math.Cos(RotationSide * Math.PI / 180));

            SidePincer1 = Tubes.Where(x => x.Row == secondPincer1row).Where(x => x.Column == secondPincer1col).Where(x => x.ColorProp != "Black").FirstOrDefault();
            SidePincer2 = Tubes.Where(x => x.Row == secondPincer2row).Where(x => x.Column == secondPincer2col).Where(x => x.ColorProp != "Black").FirstOrDefault();
            if (SidePincer1 == null || SidePincer2 == null)
            {
                secondPincer1col = centerColumn + 12 * Math.Round(Math.Cos(RotationSide * Math.PI / 180));
                secondPincer2col = centerColumn - 12 * Math.Round(Math.Cos(RotationSide * Math.PI / 180));
                secondPincer1row = centerRow + 12 * Math.Round(Math.Sin(RotationSide * Math.PI / 180));
                secondPincer2row = centerRow - 12 * Math.Round(Math.Sin(RotationSide * Math.PI / 180));
                SidePincer1      = Tubes.Where(x => x.Row == secondPincer1row).Where(x => x.Column == secondPincer1col).Where(x => x.ColorProp != "Black").FirstOrDefault();
                SidePincer2      = Tubes.Where(x => x.Row == secondPincer2row).Where(x => x.Column == secondPincer2col).Where(x => x.ColorProp != "Black").FirstOrDefault();
                if (SidePincer1 == null || SidePincer2 == null)
                {
                    ResetCoordinates();
                    return;
                }
                RotationSide = (short)(RotationMain + 135);
            }
        }
Ejemplo n.º 9
0
        private void ShiftSide(TubeM currentPos, List <int> coordinates)
        {
            //revert translation to zero
            var row1 = SidePincer1.Row;
            var col1 = SidePincer1.Column;
            var row2 = SidePincer2.Row;
            var col2 = SidePincer2.Column;
            int i    = TranslationMainUp;

            while (i > 0)
            {
                var rowSide1 = SidePincer1.Row + Math.Round(Math.Cos(Math.PI * RotationMain / 180)) * i;
                var rowSide2 = SidePincer2.Row + Math.Round(Math.Cos(Math.PI * RotationMain / 180)) * i;
                if (Tubes.Where(x => x.Row == rowSide1).Where(y => y.Column == SidePincer1.Column).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                    Tubes.Where(x => x.Row == rowSide2).Where(y => y.Column == SidePincer2.Column).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
                {
                    SidePincer1 = Tubes.Where(x => x.Row == rowSide1).Where(y => y.Column == SidePincer1.Column).FirstOrDefault();
                    SidePincer2 = Tubes.Where(x => x.Row == rowSide2).Where(y => y.Column == SidePincer2.Column).FirstOrDefault();
                    break;
                }
                i = i - 1;
            }
            TranslationMainUp = (short)(TranslationMainUp - i);
            int j = TranslationMainRight;

            while (j > 0)
            {
                var colSide1 = SidePincer1.Column + Math.Round(Math.Sin(Math.PI * RotationMain / 180)) * i;
                var colSide2 = SidePincer2.Column + Math.Round(Math.Sin(Math.PI * RotationMain / 180)) * i;
                if (Tubes.Where(x => x.Row == SidePincer1.Row).Where(y => y.Column == colSide1).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                    Tubes.Where(x => x.Row == SidePincer2.Row).Where(y => y.Column == colSide2).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
                {
                    SidePincer1 = Tubes.Where(x => x.Row == SidePincer1.Row).Where(y => y.Column == colSide1).FirstOrDefault();
                    SidePincer2 = Tubes.Where(x => x.Row == SidePincer2.Row).Where(y => y.Column == colSide2).FirstOrDefault();
                    break;
                }
                j = j - 1;
            }
            TranslationMainRight = (short)(TranslationMainRight - j);
        }
        public void LoadGeometricRepresentation(List <DtObject> elements)
        {
            try
            {
                foreach (var elem in elements)
                {
                    if (elem.Id != Guid.Empty)
                    {
                        _controller.IntBase.ApiCore.DtObjects.GetObjectGeometryAsThreeJs(elem.Id);
                    }

                    if (elem.Id == Guid.Empty)
                    {
                        elem.Id = Guid.NewGuid();
                    }

                    var data = elem.AttributeGroups["geometry"]["picture"].ToString();

                    if (data != null)
                    {
                        var bytePolyeder = Convert.FromBase64String(data);
                        var NULLcompress = Convert.ToInt32(elem.AttributeGroups["geometry"]["compress"]);
                        var compress     = (byte)(NULLcompress == null ? 1 : NULLcompress);

                        CBaseElementPolyeder poly = null;
                        try
                        {
                            if (Convert.ToInt32(elem.AttributeGroups["geometry"]["type"]) == 7)
                            {
                                poly = CsgGeometry.Create(bytePolyeder, compress);
                            }
                            else
                            {
                                poly = DeserializeVarbinaryMax.DeserializePolyeder(bytePolyeder, compress);

                                if (poly.face.Count == 0 && poly.edge.Count > 0)
                                {
                                    poly = Tubes.CreateTube(poly);
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }

                        var stringMatrix = elem.AttributeGroups["geometry"]["matrix"].ToString();
                        if (!string.IsNullOrEmpty(stringMatrix) && poly != null)
                        {
                            /*
                             * var mat = new CMatrix(Convert.FromBase64String(stringMatrix));
                             * poly.MultiplyWithMatrix(mat.Values);
                             */
                        }

                        var col = elem.AttributeGroups["geometry"]["color"];
                        // try
                        // {
                        //     elem.Material = col != null
                        //         ? Color.FromArgb((int) Convert.ToUInt32(col))
                        //         : Color.Transparent;
                        // }
                        // catch (Exception)
                        // {
                        //     baseElem.Material = col != null ? Color.FromArgb(Convert.ToInt32(col)) : Color.Transparent;
                        // }
                        //
                        // if (col == null || baseElem.Material == Color.FromArgb(255, 128, 128, 128))
                        // {
                        //     if (poly != null)
                        //     {
                        //         baseElem.Material = poly.IsSpecialColorDefined()
                        //             ? Color.FromArgb((int) poly.GetSpecialColor())
                        //             : Color.FromArgb(255, 128, 128, 128);
                        //     }
                        //     else
                        //         baseElem.Material = Color.FromArgb(255, 128, 128, 128);
                        // }
                        //
                        // if (poly != null)
                        // {
                        //     poly.ID = baseElem.Id;
                        //     baseElem.Polyeder = poly;
                        //     poly.Radius = null;
                        //     poly.Bendingrolle = null;
                        // }
                        // else
                        // {
                        //     Debug.Print(
                        //         $"Invalid geometry for {((GenericElement) baseElem).TypeName} with ID {baseElem.Id}!");
                        // }
                    }

                    // elem.LoadState |= ElementLoadState.GeometryLoaded;
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Ejemplo n.º 11
0
        private TubeM TryToRotate(TubeM currentPos, int Angle)
        {
            if (RotationMain > 360)
            {
                RotationMain = (short)(RotationMain - 360);
            }
            if (RotationSide > 360)
            {
                RotationSide = (short)(RotationSide - 360);
            }
            if (RotationMain < 0)
            {
                RotationMain = (short)(RotationMain + 360);
            }
            if (RotationSide < 0)
            {
                RotationSide = (short)(RotationSide + 360);
            }
            if (RotationMax == 30)
            {
                Debug.WriteLine("You are stuck");
                throw new Exception();
            }
            if (Angle < 0)
            {
                Angle = 360 + Angle;
            }
            switch (Angle)
            {
            case 90:
                var a = RotationSide;
                if (RotationMain > RotationSide)
                {
                    a = (short)(360 + RotationSide);
                }
                if (a - RotationMain == 135)
                {
                    var rowMain1    = MainPincer1.Row + 14 * Math.Round(Math.Cos(Math.PI * RotationSide / 180));
                    var columnMain1 = MainPincer1.Column + 14 * Math.Round(Math.Sin(Math.PI * RotationSide / 180));
                    var rowMain2    = MainPincer2.Row - 14 * Math.Round(Math.Cos(Math.PI * RotationSide / 180));
                    var columnMain2 = MainPincer2.Column - 14 * Math.Round(Math.Sin(Math.PI * RotationSide / 180));
                    if (Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                        Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
                    {
                        RotationMain += 90;
                        MainPincer1   = Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).FirstOrDefault();
                        MainPincer2   = Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).FirstOrDefault();
                        var currentPosrow = currentPos.Row + 16 * Math.Cos(Math.PI * RotationSide / 180);
                        var currentPoscol = currentPos.Column + 16 * Math.Sin(Math.PI * RotationSide / 180);
                        currentPos = Tubes.Where(x => x.Row == currentPosrow).Where(y => y.Column == currentPoscol).FirstOrDefault();
                        pathList.Add(currentPos);
                    }
                    else
                    {
                        currentPos   = TryToRotate(currentPos, 270);
                        RotationMax += 1;
                    }
                }
                else
                {
                    RotationMax += 1;
                    RotateSide(currentPos, 90);
                    currentPos = TryToRotate(currentPos, 90);
                }
                return(currentPos);

            case 180:
                currentPos = TryToRotate(currentPos, 90);
                currentPos = TryToRotate(currentPos, 90);
                return(currentPos);

            case 270:
                var ab = RotationSide;
                if (RotationMain > RotationSide)
                {
                    ab = (short)(360 + RotationSide);
                }
                if ((ab - RotationMain) == 45)
                {
                    var rowMain1    = MainPincer1.Row - 14 * Math.Round(Math.Cos(Math.PI * RotationSide / 180));
                    var columnMain1 = MainPincer1.Column - 14 * Math.Round(Math.Sin(Math.PI * RotationSide / 180));
                    var rowMain2    = MainPincer2.Row + 14 * Math.Round(Math.Cos(Math.PI * RotationSide / 180));
                    var columnMain2 = MainPincer2.Column + 14 * Math.Round(Math.Sin(Math.PI * RotationSide / 180));
                    if (Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).Where(x => x.ColorProp != "Black").FirstOrDefault() != null &&
                        Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).Where(x => x.ColorProp != "Black").FirstOrDefault() != null)
                    {
                        RotationMain -= 90;
                        MainPincer1   = Tubes.Where(x => x.Row == rowMain1).Where(y => y.Column == columnMain1).FirstOrDefault();
                        MainPincer2   = Tubes.Where(x => x.Row == rowMain2).Where(y => y.Column == columnMain2).FirstOrDefault();
                        var currentPosrow = currentPos.Row - 16 * Math.Round(Math.Cos(Math.PI * RotationSide / 180));
                        var currentPoscol = currentPos.Column - 16 * Math.Round(Math.Sin(Math.PI * RotationSide / 180));
                        currentPos = Tubes.Where(x => x.Row == currentPosrow).Where(y => y.Column == currentPoscol).FirstOrDefault();
                        pathList.Add(currentPos);
                    }
                    else
                    {
                        currentPos   = TryToRotate(currentPos, 90);
                        RotationMax += 1;
                    }
                }
                else
                {
                    RotateSide(currentPos, 270);
                }
                return(currentPos);

            default:
                return(currentPos);
            }
        }
Ejemplo n.º 12
0
 public void Init()
 {
     _tubes = new Tubes(Aoc.Framework.Input.GetStringVector(this));
     _tubes.Walk();
 }
Ejemplo n.º 13
0
 public TubeFinder(Tubes tubeData)
 {
     _tubes = tubeData ?? throw new NullReferenceException(nameof(tubeData));
 }