Ejemplo n.º 1
0
        private void AdjustCableLayouts(Dictionary <int, CableLayout> cableLayoutById, Dictionary <int, CableSymbol> cableSymbolById, Dictionary <int, CableInfo> cableInfoById)
        {
            List <CableLayout> topLayouts = new List <CableLayout>();
            List <CableLayout> bottomLeftHorizontalCableLayouts  = new List <CableLayout>();
            List <CableLayout> bottomRightHorizontalCableLayouts = new List <CableLayout>();
            List <CableLayout> bottomVerticalCableLayouts        = new List <CableLayout>();

            foreach (int cableId in cableIds)
            {
                CableLayout cableLayout = cableLayoutById[cableId];
                if (cableLayout.Level == Level.Top)
                {
                    topLayouts.Add(cableLayout);
                }
                else
                {
                    if (cableSymbolById[cableId].Orientation == Orientation.Vertical)
                    {
                        bottomVerticalCableLayouts.Add(cableLayout);
                    }
                    else
                    if (matePositionByCableId[cableId] < groupPosition)
                    {
                        bottomLeftHorizontalCableLayouts.Add(cableLayout);
                    }
                    else
                    {
                        bottomRightHorizontalCableLayouts.Add(cableLayout);
                    }
                }
            }
            VerticalCableLayoutComparer verticalComparer = new VerticalCableLayoutComparer(cableInfoById, matePositionByCableId);

            topLayouts.Sort(verticalComparer);
            bottomVerticalCableLayouts.Sort(verticalComparer);
            HorizontalCableLayoutComparer horizontalComparer = new HorizontalCableLayoutComparer(cableInfoById, matePositionByCableId, groupPosition);

            bottomRightHorizontalCableLayouts.Sort(horizontalComparer);
            bottomLeftHorizontalCableLayouts.Sort(horizontalComparer);
            int totalCablesCount             = bottomLeftHorizontalCableLayouts.Count + bottomRightHorizontalCableLayouts.Count + bottomVerticalCableLayouts.Count;
            List <CableLayout> bottomLayouts = new List <CableLayout>(totalCablesCount);

            bottomLayouts.AddRange(bottomLeftHorizontalCableLayouts);
            bottomLayouts.AddRange(bottomVerticalCableLayouts);
            bottomLayouts.AddRange(bottomRightHorizontalCableLayouts);
            SetLayoutsSkewDirectionAndOffset(cableLayoutById, topLayouts);
            SetLayoutsSkewDirectionAndOffset(cableLayoutById, bottomLayouts);
            bottomCableVerticalOffsetByStep = GetCableVerticalOffsetByStep(bottomLayouts);
            topCableVerticalOffsetByStep    = GetCableVerticalOffsetByStep(topLayouts);
            foreach (CableLayout cableLayout in cableLayoutById.Values)
            {
                cableLayout.verticalOffset = (cableLayout.Level == Level.Bottom) ? bottomCableVerticalOffsetByStep[cableLayout.verticalOffsetStep] : topCableVerticalOffsetByStep[cableLayout.verticalOffsetStep];
            }
        }
Ejemplo n.º 2
0
        private static bool IsLayoutIntersect(CableLayout firstLayout, CableLayout secondLayout)
        {
            if (firstLayout.verticalOffsetStep != secondLayout.verticalOffsetStep)
            {
                return(false);
            }
            double firstMin  = firstLayout.MinOffset;
            double firstMax  = firstLayout.MaxOffset;
            double secondMin = secondLayout.MinOffset;
            double secondMax = secondLayout.MaxOffset;

            return((firstMax > secondMin && firstMin < secondMax) || (secondMax > firstMin && secondMin < firstMax));
        }
 public AssignmentReferenceSymbol(string assignment, int id, int cableId, E3Text text)
 {
     this.id = id;
     triangleHeight = 4;
     triangleBaseLength = 2;
     descriptionVerticalMargin = 2;
     description ="В "+ assignment;
     font = new E3Font();
     double descriptionLength = text.GetTextLength(description, font);
     height = triangleHeight + descriptionVerticalMargin + font.height;
     margin = Math.Max(triangleBaseLength, descriptionLength) / 2;
     cableIds = new List<int>() { cableId };
     CableLayout cableLayout = new CableLayout(cableId, Level.Bottom);
     cableLayout.AddOffset(new Point(0,0));
     CableLayoutById = new Dictionary<int, CableLayout>() { {cableId, cableLayout} };
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Функция вычисляет штраф за некрасивое расположение, "критерии красоты" - 1. Скошенные кабеля должны быть выше 2. Чем левее, тем выше
        /// </summary>
        /// <param name="layouts"></param>
        /// <returns></returns>
        private static int GetFine(List <CableLayout> layouts)
        {
            int fine = 0;

            for (int i = 0; i < layouts.Count; i++)
            {
                CableLayout layout = layouts[i];
                fine += (int)Math.Abs(layout.MaxOffset - layout.MinOffset) * layout.verticalOffsetStep * 1000;  // +1 чтобы не было вырожденного случая умножения на 0.
                fine += layout.verticalOffsetStep * 10 * (i + 1);
                if (layout.SkewDirection != Position.Center)
                {
                    fine += layout.verticalOffsetStep * 100 * (i + 1);
                }
            }
            return(fine);
        }
Ejemplo n.º 5
0
        private void SetLayoutsSkewDirectionAndOffset(Dictionary <int, CableLayout> cableLayoutById, List <CableLayout> cableLayouts)
        {
            List <List <int> > layoutIdsWithRepeatedOffsets = new List <List <int> >();

            for (int i = 0; i < cableLayouts.Count - 1; i++)
            {
                CableLayout  firstLayout       = cableLayouts[i];
                List <Point> firstOffsets      = firstLayout.StartOffsets;
                int          firstOffsetsCount = firstOffsets.Count;
                for (int j = i + 1; j < cableLayouts.Count; j++)
                {
                    CableLayout secondLayout = cableLayouts[j];
                    if (firstOffsets.Intersect(secondLayout.StartOffsets).Count() == firstOffsetsCount)
                    {
                        AddIdsWithRepeatedOffsetToList(layoutIdsWithRepeatedOffsets, firstLayout.Id, secondLayout.Id);
                    }
                }
            }
            double skewOffset;

            if (layoutIdsWithRepeatedOffsets.Count == 1)
            {
                List <int>  ids         = layoutIdsWithRepeatedOffsets.First();
                CableLayout firstLayout = cableLayoutById[ids.First()];
                skewOffset = (firstLayout.StartOffsets.Max(p => p.X) - firstLayout.StartOffsets.Min(p => p.X)) + gridStep;
            }
            else
            {
                skewOffset = gridStep * 1.5;
            }
            foreach (List <int> ids in layoutIdsWithRepeatedOffsets)
            {
                for (int i = 0; i < ids.Count; i++)
                {
                    Position direction;
                    switch (i)
                    {
                    case 0: direction = Position.Left; break;

                    case 1: direction = Position.Center; break;

                    default: direction = Position.Right; break;
                    }
                    cableLayoutById[ids[i]].SetSkewDirectionAndoffset(direction, skewOffset);
                }
            }
        }
Ejemplo n.º 6
0
        private static int GetLayoutIntersectionCount(List <CableLayout> layouts)
        {
            int intersectionCount = 0;

            for (int i = 0; i < layouts.Count - 1; i++)
            {
                CableLayout firstLayout = layouts[i];
                for (int j = i + 1; j < layouts.Count; j++)
                {
                    if (IsLayoutIntersect(firstLayout, layouts[j]))
                    {
                        intersectionCount++;
                    }
                }
            }
            return(intersectionCount);
        }
Ejemplo n.º 7
0
        public AssignmentReferenceSymbol(string assignment, int id, int cableId, E3Text text)
        {
            this.id                   = id;
            triangleHeight            = 4;
            triangleBaseLength        = 2;
            descriptionVerticalMargin = 2;
            description               = "В " + assignment;
            font = new E3Font();
            double descriptionLength = text.GetTextLength(description, font);

            height   = triangleHeight + descriptionVerticalMargin + font.height;
            margin   = Math.Max(triangleBaseLength, descriptionLength) / 2;
            cableIds = new List <int>()
            {
                cableId
            };
            CableLayout cableLayout = new CableLayout(cableId, Level.Bottom);

            cableLayout.AddOffset(new Point(0, 0));
            CableLayoutById = new Dictionary <int, CableLayout>()
            {
                { cableId, cableLayout }
            };
        }
 private static List<double> GetAbscisses(double symbolPlacedX, CableLayout cableLayout)
 {
     List<double> abscisses = new List<double>();
     List<double> placedXes = cableLayout.PlacedPoints.Select(p => p.X).ToList();
     double min = placedXes.Min();
     double max = placedXes.Max();
     abscisses.Add(min);
     if (max>min)
     {
         abscisses.Add(max);
         double x = min + 1;
         while (x < max)
         {
             abscisses.Add(x);
             x += 1;
         }
         if (symbolPlacedX > min && symbolPlacedX < max)
             abscisses.Add(symbolPlacedX);
     }
     return abscisses;
 }