Example #1
0
 public double GetTextAbsciss(double textCenterX, double textWidth, E3Font font, Sheet sheet)
 {
     double textOffset = font.height - textWidth / 2;
     return sheet.MoveRight(textCenterX, textOffset);
 }
 private void PlaceSchemes(List<SymbolScheme> schemes, E3Project project, Sheet sheet, E3Text text, string sheetMark)
 {
     double gridStep = 4;
     Group group = project.GetGroupById(0);
     Graphic graphic = project.GetGraphicById(0);
     int sheetCount=1;
     CreateSheet(sheet, sheetMark, ref sheetCount);
     bool needToCreate = false;
     double availableWith = sheet.DrawingArea.Width * 0.9;
     double startX = sheet.MoveRight(sheet.DrawingArea.Left, sheet.DrawingArea.Width * 0.05);
     Point sheetCenter = new Point(sheet.MoveRight(sheet.DrawingArea.Left, sheet.DrawingArea.Width / 2), sheet.MoveDown(sheet.DrawingArea.Top, sheet.DrawingArea.Height / 2));
     double totalSchemeWidth = gridStep;
     List<SymbolScheme> notPlacedSchemes = new List<SymbolScheme>();
     foreach (SymbolScheme scheme in schemes)
     {
         if (scheme.Size.Width > availableWith)
         {
             if (needToCreate)
                 CreateSheet(sheet, sheetMark, ref sheetCount);
             else
                 needToCreate = true;
             scheme.Place(sheet, graphic, group, text, sheetCenter);
             continue;
         }
         totalSchemeWidth += scheme.Size.Width + gridStep;
         if (totalSchemeWidth < availableWith)
             notPlacedSchemes.Add(scheme);
         else
         {
             if (needToCreate)
                 CreateSheet(sheet, sheetMark, ref sheetCount);
             else
                 needToCreate = true;
             double width = notPlacedSchemes.Sum(s => s.Size.Width);
             double totalGap = availableWith - width;
             double gap = totalGap / (notPlacedSchemes.Count + 1);
             double x = startX;
             foreach (SymbolScheme notPlacedScheme in notPlacedSchemes)
             {
                 x = sheet.MoveRight(x, gap + notPlacedScheme.Size.Width / 2 );
                 notPlacedScheme.Place(sheet, graphic, group, text, new Point(x, sheetCenter.Y));
                 x = sheet.MoveRight(x, notPlacedScheme.Size.Width / 2);
             }
             notPlacedSchemes.Clear();
             totalSchemeWidth = gridStep + scheme.Size.Width;
             notPlacedSchemes.Add(scheme);
         }
     }
     if (notPlacedSchemes.Count > 0)
     {
         if (needToCreate)
             CreateSheet(sheet, sheetMark, ref sheetCount);
         double width = notPlacedSchemes.Sum(s => s.Size.Width);
         double totalGap = availableWith - width;
         double gap = totalGap / (notPlacedSchemes.Count + 1);
         double x = startX;
         foreach (SymbolScheme notPlacedScheme in notPlacedSchemes)
         {
             x = sheet.MoveRight(x, gap + notPlacedScheme.Size.Width / 2);
             notPlacedScheme.Place(sheet, graphic, group, text, new Point(x, sheetCenter.Y));
             x = sheet.MoveRight(x, notPlacedScheme.Size.Width / 2);
         }
     }
 }
 private List<int> PlaceHorizontally(Sheet sheet, Graphic graphic, E3Text text, Point placePosition, E3Font smallFont, E3Font bigFont)
 {
     List<int> groupIds = new List<int>(6);
     int sheetId = sheet.Id;
     double x = sheet.MoveLeft(placePosition.X, Size.Width / 2);
     double y = sheet.MoveDown(placePosition.Y, bigOffset + smallFontHeight);
     groupIds.Add(text.CreateText(sheetId, cableInfo.Type, x, y, smallFont));
     double x2 = sheet.MoveRight(x, typeTextWidth + smallOffset);
     groupIds.Add(graphic.CreateLine(sheetId, x, placePosition.Y, x2, placePosition.Y, lineHeight,connectionColorIndex));
     double radius = diameter / 2;
     double halfNameTextWidth = nameTextWidth / 2;
     x = sheet.MoveRight(x2, radius - halfNameTextWidth + ovalLength / 2);
     y = sheet.MoveDown(placePosition.Y, bigFontHeight / 2);
     groupIds.Add(text.CreateText(sheetId, cableInfo.Name, x, y, bigFont));
     x = sheet.MoveRight(x2, radius);
     if (isCircle)
     {
         groupIds.Add(graphic.CreateCircle(sheetId, x, placePosition.Y, radius));
         x = sheet.MoveRight(x, radius);
     }
     else
     {
         groupIds.Add(graphic.CreateArc(sheetId, x, placePosition.Y, radius, 90, 270));
         double y1 = sheet.MoveUp(placePosition.Y, radius);
         double y2 = sheet.MoveDown(placePosition.Y, radius);
         x2 = sheet.MoveRight(x, ovalLength);
         groupIds.Add(graphic.CreateLine(sheetId, x, y1, x2, y1));
         groupIds.Add(graphic.CreateLine(sheetId, x, y2, x2, y2));
         groupIds.Add(graphic.CreateArc(sheetId, x2, placePosition.Y, radius, 270, 90));
         x = sheet.MoveRight(x2, radius);
     }
     x2 = sheet.MoveRight(x, smallOffset + lengthTextWidth);
     groupIds.Add(graphic.CreateLine(sheetId, x, placePosition.Y, x2, placePosition.Y, lineHeight,connectionColorIndex));
     x = sheet.MoveRight(x, smallOffset);
     y = sheet.MoveUp(placePosition.Y, bigOffset);
     groupIds.Add(text.CreateText(sheetId, cableInfo.Length, x, y, smallFont));
     PlacedPosition = placePosition;
     return groupIds;
 }
 private List<int> PlaceVertically(Sheet sheet, Graphic graphic, E3Text text, Point placePosition, E3Font smallFont, E3Font bigFont)
 {
     List<int> groupIds = new List<int>(5);
     int sheetId = sheet.Id;
     double radius = diameter / 2;
     double x, y2;
     double y = sheet.MoveUp(placePosition.Y, Size.Height / 2 - radius);
     if (isCircle)
     {
         groupIds.Add(graphic.CreateCircle(sheetId, placePosition.X, y, radius));
     }
     else
     {
         x = sheet.MoveLeft(placePosition.X, ovalLength / 2);
         groupIds.Add(graphic.CreateArc(sheetId, x, y, radius, 90, 270));
         double x2 = sheet.MoveRight(x, ovalLength);
         groupIds.Add(graphic.CreateArc(sheetId, x2, y, radius, 270, 90));
         y = sheet.MoveDown(y, radius);
         y2 = sheet.MoveUp(y, 2 * radius);
         groupIds.Add(graphic.CreateLine(sheetId, x, y, x2, y));
         groupIds.Add(graphic.CreateLine(sheetId, x, y2, x2, y2));
         y = sheet.MoveUp(y, radius);
     }
     x = sheet.MoveLeft(placePosition.X, nameTextWidth / 2);
     y = sheet.MoveDown(y, bigFontHeight / 2);
     groupIds.Add(text.CreateText(sheetId, cableInfo.Name, x,y, bigFont));
     y = sheet.MoveDown(y, radius - bigFontHeight/2);
     y2 = sheet.MoveDown(y, smallOffset + Math.Max(typeTextWidth, lengthTextWidth));
     groupIds.Add(graphic.CreateLine(sheetId, placePosition.X, y, placePosition.X, y2, lineHeight,connectionColorIndex));
     y = sheet.MoveDown(y, smallOffset+typeTextWidth);
     x = sheet.MoveLeft(placePosition.X, bigOffset);
     groupIds.Add(text.CreateVerticalText(sheetId, cableInfo.Type, x, y, smallFont));
     x = sheet.MoveRight(placePosition. X, bigOffset + smallFontHeight);
     y = sheet.MoveUp(y, typeTextWidth - lengthTextWidth);
     groupIds.Add(text.CreateVerticalText(sheetId, cableInfo.Length, x, y, smallFont));
     PlacedPosition = placePosition;
     return groupIds;
 }
 private void PlaceSymbols(Sheet sheet, Graphic graphic, Group e3group, E3Text text, Dictionary<int, double> horizontalOffsetById, double startAbsciss, double groupOrdinate)
 {
     double offset = 0;
     foreach (int id in horizontalOffsetById.Keys)
     {
         ISchemeSymbol symbol = symbolById[id];
         offset += horizontalOffsetById[id];
         double absciss = sheet.MoveRight(startAbsciss, offset);
         symbol.Place(new Point(absciss, groupOrdinate), sheet, graphic, e3group, text);
     }
 }
 public void Place(Point placePosition, Sheet sheet, Graphic graphic, Group group, E3Text text)
 {
     PlacedPosition = placePosition;
     double width = 0.2;
     List<int> ids = new List<int>(5);
     double halfBaseLength = triangleBaseLength / 2;
     Point leftBottom = new Point(sheet.MoveLeft(placePosition.X, halfBaseLength), placePosition.Y);
     Point rightBottom = new Point(sheet.MoveRight(placePosition.X, halfBaseLength), placePosition.Y);
     Point top = new Point(placePosition.X, sheet.MoveUp(placePosition.Y, triangleHeight));
     int sheetId = sheet.Id;
     ids.Add(graphic.CreateLine(sheetId, leftBottom.X, leftBottom.Y, rightBottom.X, rightBottom.Y, width));
     ids.Add(graphic.CreateLine(sheetId, leftBottom.X, leftBottom.Y, top.X, top.Y, width));
     ids.Add(graphic.CreateLine(sheetId, rightBottom.X, rightBottom.Y, top.X, top.Y, width));
     ids.Add(text.CreateText(sheetId, description, top.X, sheet.MoveUp(top.Y, descriptionVerticalMargin), font));
     ids.AddRange(CableLayoutById.Values.First().Place(sheet, graphic, placePosition));
     group.CreateGroup(ids);
 }
 private void CreateTurningConnectingLine(Sheet sheet, Graphic graphic, double lineHeight, int sheetId, Dictionary<int, double> abscissesByCableId, double lastCableLayoutY, CableSymbol cableSymbol, ISchemeSymbol symbol)
 {
     double absciss = abscissesByCableId[cableSymbol.CableId];
     double symbolX, turnX;
     if (absciss > cableSymbol.PlacedPosition.X)
     {
         symbolX = sheet.MoveRight(cableSymbol.PlacedPosition.X, cableSymbol.Size.Width / 2);
         turnX = sheet.MoveLeft(symbol.PlacedPosition.X, symbol.LeftMargin + gridStep);
     }
     else
     {
         symbolX = sheet.MoveLeft(cableSymbol.PlacedPosition.X, cableSymbol.Size.Width / 2);
         turnX = sheet.MoveRight(symbol.PlacedPosition.X, symbol.RightMargin + gridStep);
     }
     double symbolY = cableSymbol.PlacedPosition.Y;
     graphic.CreateLine(sheetId, absciss, lastCableLayoutY, turnX, lastCableLayoutY, lineHeight, connectionColorIndex);
     graphic.CreateLine(sheetId, turnX, lastCableLayoutY, turnX, symbolY, lineHeight, connectionColorIndex);
     graphic.CreateLine(sheetId, turnX, symbolY, symbolX, symbolY, lineHeight, connectionColorIndex);
 }
 private void PlaceCableSymbols(Sheet sheet, Graphic graphic, Group e3group, E3Text text, double startAbsciss, double topGroupOrdinate, double bottomGroupOrdinate)
 {
     foreach (int cableId in cableSymbolById.Keys)
     {
         CableSymbol cableSymbol = cableSymbolById[cableId];
         if (cableSymbol.Orientation == Orientation.Horizontal)
         {
             List<int> groupIds = symbolIdsByCableId[cableId];
             groupIds.Sort((id1,id2) => GetGroupPosition(id1).CompareTo(GetGroupPosition(id2)));
             ISchemeSymbol firstSymbol = symbolById[groupIds.First()];
             ISchemeSymbol secondSymbol = symbolById[groupIds.Last()];
             double firstPointX = sheet.MoveRight(firstSymbol.PlacedPosition.X, firstSymbol.RightMargin);
             double y = (firstSymbol.Level == Level.Bottom) ? sheet.MoveDown(bottomGroupOrdinate, bottomGroupBottomMargin) : sheet.MoveDown (topGroupOrdinate, topGroupBottomMargin);
             Point firstPoint = new Point (firstPointX, y);
             double secondPointX = sheet.MoveLeft(secondSymbol.PlacedPosition.X, secondSymbol.LeftMargin);
             Point secondPoint = new Point(secondPointX, y);
             double x = (firstPoint.X + secondPoint.X) / 2;
             double cableSymbolHalfHeight = cableSymbol.Size.Height / 2;
             y = sheet.MoveDown(y, cableSymbolHalfHeight + gridStep);
             cableSymbol.Place(sheet, graphic, text, e3group, new Point(x, y));
          }
     }
     if (topGroupHorizontalOffsetById.Count > 0)
     {
         double top = symbolById[topGroupHorizontalOffsetById.Keys.First()].PlacedPosition.Y;
         ISchemeSymbol bottomSymbol = symbolById[bottomGroupHorizontalOffsetById.Keys.First()];
         double bottom = sheet.MoveUp(bottomSymbol.PlacedPosition.Y, bottomSymbol.TopMargin);
         double center = (top + bottom) / 2;
         foreach (VerticalConnection verticalConnection in verticalConnections)
             foreach (CableSymbol cableSymbol in verticalConnection.VerticalCableSymbols)
             {
                 double y = sheet.MoveDown(center, (cableSymbol.Size.Height - cableSymbol.Diameter) / 2);
                 cableSymbol.Place(sheet, graphic, text, e3group, new Point(sheet.MoveRight(startAbsciss, verticalConnection.OffsetByCableId[cableSymbol.CableId]), y));
             }
     }
 }
 private int DrawSignalAndSetConnectionPoint(SymbolPin pin, Level position, Sheet sheet, E3Text text, int sheetId, double pinBottom, double pinTop, double pinLeft)
 {
     double xSignalText = sheet.MoveRight(pinLeft, 1);
     double ySignalText;
     E3Font font = new E3Font(height: smallFont.height);
     if (position == Level.Top)
     {
         ySignalText = sheet.MoveUp(pinTop, skewLineOffset);
         font.alignment = Alignment.Left;
     }
     else
     {
         ySignalText = sheet.MoveDown(pinBottom, skewLineOffset);
         font.alignment = Alignment.Right;
     }
     return text.CreateVerticalText(sheetId, pin.Signal, xSignalText, ySignalText, font);
 }
 private void CreateStraightConnectingLine(Sheet sheet, Graphic graphic, double lineHeight, int sheetId, Dictionary<int, double> abscissesByCableId, double layoutPlacedY, CableSymbol cableSymbol)
 {
     double absciss = abscissesByCableId[cableSymbol.CableId];
     double symbolX = (absciss > cableSymbol.PlacedPosition.X) ? sheet.MoveRight(cableSymbol.PlacedPosition.X, cableSymbol.Size.Width / 2) : sheet.MoveLeft(cableSymbol.PlacedPosition.X, cableSymbol.Size.Width / 2);
     double symbolY = cableSymbol.PlacedPosition.Y;
     graphic.CreateLine(sheetId, absciss, layoutPlacedY, absciss, symbolY, lineHeight, connectionColorIndex);
     graphic.CreateLine(sheetId, symbolX, symbolY, absciss, symbolY, lineHeight, connectionColorIndex);
 }
 private List<int> DrawPins(Sheet sheet, Graphic graphic, E3Text text, List<SymbolPin> pins, double pinsHeight, double pinsWidth, int sheetId, double xLeft, double pinBottom, double pinTop, Level position)
 {
     List<int> graphicIds = new List<int>(pins.Count * 2 + 1);
     double pinLeft = sheet.MoveRight(xLeft, (Size.Width - pinsWidth) / 2);
     foreach (SymbolPin pin in pins)
     {
         double pinRight = sheet.MoveRight(pinLeft, gridStep);
         int pinOutlineId = graphic.CreateRectangle(sheetId, pinLeft, pinBottom, pinRight, pinTop);
         graphicIds.Add(pinOutlineId);
         double textWidth = text.GetTextLength(pin.Name, smallFont);
         double xPinText = sheet.MoveRight(sheet.MoveRight(pinLeft, halfGridStep), smallFont.height / 2 - 0.2);
         double yPinText = sheet.MoveUp(pinBottom, (pinsHeight - textWidth) / 2);
         graphicIds.Add(text.CreateVerticalText(sheetId, pin.Name, xPinText, yPinText, smallFont));
         int signalTextId = DrawSignalAndSetConnectionPoint(pin, position, sheet, text, sheetId, pinBottom, pinTop, pinLeft);
         graphicIds.Add(signalTextId);
         pinLeft = pinRight;
     }
     return graphicIds;
 }
 private List<int> CreateTerminalSymbol(Sheet sheet, E3Text text, Graphic graphic, int sheetId, Point position)
 {
     List<int> groupIds;
     E3Font smallFont = new E3Font(height:2.5, alignment: Alignment.Left);
     int outlineId = CreateOutline(sheet, graphic, sheetId, position);
     double offset = 0.5;
     double xText = sheet.MoveRight(sheet.MoveRight(position.X, halfGridStep), smallFont.height / 2 - 0.2);
     if (!String.IsNullOrEmpty(Assignment))
     {
         double yAssignmentText = sheet.MoveUp(position.Y, offset);
         groupIds = new List<int>(3);
         groupIds.Add(text.CreateVerticalText(sheetId, Assignment, xText, yAssignmentText, smallFont));
     }
     else
         groupIds = new List<int>(2);
     groupIds.Add(outlineId);
     nameWidth = text.GetTextLength(Name, smallFont);
     double top = sheet.MoveUp(position.Y, Size.Height);
     double yText = sheet.MoveDown(top, offset + nameWidth);
     groupIds.Add(text.CreateVerticalText(sheetId, Name, xText, yText, smallFont));
     foreach (SymbolPin topPin in topPins)
     {
         int signalTextId = DrawSignalAndSetConnectionPoint(topPin, Level.Top, sheet, text, sheetId, position.Y, top, position.X);
         groupIds.Add(signalTextId);
     }
     foreach (SymbolPin bottomPin in bottomPins)
     {
         int signalTextId = DrawSignalAndSetConnectionPoint(bottomPin, Level.Bottom, sheet, text, sheetId, position.Y, top, position.X);
         groupIds.Add(signalTextId);
     }
     return groupIds;
 }
 private int CreateOutline(Sheet sheet, Graphic graphic, int sheetId, Point placePosition)
 {
     double x1 = placePosition.X;
     double y1 = placePosition.Y;
     double x2 = sheet.MoveRight(x1, Size.Width);
     double y2 = sheet.MoveUp(y1, Size.Height);
     return graphic.CreateRectangle(sheetId, x1, y1, x2, y2);
 }
 private List<int> CreateDeviceSymbol(Sheet sheet, E3Text text, Graphic graphic, int sheetId, Point position )
 {
     List<int> groupIds = new List<int>((topPins.Count + bottomPins.Count) * 2 + 2);
     E3Font bigFont = new E3Font(alignment: Alignment.Left);
     groupIds.Add(CreateOutline(sheet, graphic, sheetId, position));
     double xText = sheet.MoveRight(position.X, (Size.Width - nameWidth) / 2);
     double spaceForName = Size.Height - bottomPinsHeight - topPinsHeight;
     double offsetForName = (spaceForName - bigFont.height) / 2;
     double yText = sheet.MoveUp(position.Y, bottomPinsHeight + offsetForName);
     groupIds.Add(text.CreateText(sheetId, Name, xText, yText, bigFont));
     double top = sheet.MoveUp(position.Y, Size.Height);
     double pinBottom = sheet.MoveDown(top, topPinsHeight);
     List<int> topPinIds = DrawPins(sheet, graphic, text, topPins, topPinsHeight, topPinsWidth, sheetId, position.X, pinBottom, top, Level.Top);
     double pinTop = sheet.MoveUp(position.Y, bottomPinsHeight);
     List<int> bottomPinIds = DrawPins(sheet, graphic, text, bottomPins, bottomPinsHeight, bottomPinsWidth, sheetId, position.X, position.Y, pinTop, Level.Bottom);
     groupIds.AddRange(topPinIds);
     groupIds.AddRange(bottomPinIds);
     return groupIds;
 }
 public List<int> Place(Sheet sheet, Graphic graphic, Point placePosition)
 {
     double lineHeight = 0.2;
     List<int> ids = new List<int>();
     int sheetId = sheet.Id;
     int colorIndex = 16;
     double endOrdinate = (level == Level.Top) ? sheet.MoveUp(placePosition.Y, verticalOffset) : sheet.MoveDown(placePosition.Y, verticalOffset);
     List<Point> placedPoints = new List<Point>(startOffsets.Count);
     if (skewDirection == Position.Center )
         foreach (Point startOffset in startOffsets)
         {
             double x = sheet.MoveRight(placePosition.X, startOffset.X);
             double y = (level == Level.Top) ? sheet.MoveUp(placePosition.Y, startOffset.Y) : sheet.MoveDown(placePosition.Y, startOffset.Y);
             ids.Add(graphic.CreateLine(sheetId, x, y, x, endOrdinate, lineHeight,colorIndex));
             placedPoints.Add(new Point(x, endOrdinate));
         }
     else
         for (int i = 0; i < startOffsets.Count; i++)
         {
             Point startOffset = startOffsets[i];
             double xStart = sheet.MoveRight(placePosition.X, startOffset.X);
             double yStart = (level == Level.Top) ? sheet.MoveUp(placePosition.Y, startOffset.Y) : sheet.MoveDown(placePosition.Y, startOffset.Y);
             double yIntermediate = (level == Level.Top) ? sheet.MoveUp(yStart, gridStep) :  sheet.MoveDown(yStart, gridStep);
             double xIntermediate = (skewDirection == Position.Left) ? sheet.MoveLeft(xStart, skewOffset) : sheet.MoveRight(xStart, skewOffset);
             ids.Add(graphic.CreateLine(sheetId, xStart, yStart, xIntermediate, yIntermediate, lineHeight, colorIndex));
             ids.Add(graphic.CreateLine(sheetId, xIntermediate, yIntermediate, xIntermediate, endOrdinate, lineHeight, colorIndex));
             placedPoints.Add(new Point(xIntermediate, endOrdinate));
         }
     PlacedPoints = placedPoints;
     if (minOffset!=maxOffset)
         ids.Add(graphic.CreateLine(sheetId, sheet.MoveRight(placePosition.X, minOffset),endOrdinate, sheet.MoveRight(placePosition.X, maxOffset), endOrdinate, 0.5 ,colorIndex));
     return ids;
 }