Exemple #1
0
 public GraphicItem()
 {
   tagArea = new Rectangle(0.0, 0.0, 0.0, 0.0);
   tagAngle = 0.0;
   tagFont = new Font();
   tagVisible = false;
   opacity = 1.0;
 }
Exemple #2
0
 public GraphicItem(String tag, Rectangle tagArea, Double tagAngle, Font tagFont, Boolean tagVisible, Double opacity)
   : base(tag)
 {
   TagArea = tagArea;
   TagAngle = tagAngle;
   TagFont = tagFont;
   TagVisible = tagVisible;
   Opacity = opacity;
 }
Exemple #3
0
 public GraphicItem(Guid guid, String tag)
   : base(guid, tag)
 {
   tagArea = new Rectangle(0.0, 0.0, 0.0, 0.0);
   tagAngle = 0.0;
   tagFont = new Font();
   tagVisible = false;
   opacity = 1.0;
 }
Exemple #4
0
    private void UpdateStencil(ModelStencil modelStencil)
    {
      double minX = float.MaxValue;
      double maxX = float.MinValue;
      double minY = float.MaxValue;
      double maxY = float.MinValue;

      UpdateStencil(modelStencil.Elements, ref minX, ref minY, ref maxX, ref maxY);
      UpdateStencil(modelStencil.Decorations, ref minX, ref minY, ref maxX, ref maxY);

      double anchorMinX = minX;
      double anchorMaxX = maxX;
      double anchorMinY = minY;
      double anchorMaxY = maxY;

      UpdateStencil(modelStencil.Anchors, ref anchorMinX, ref anchorMinY, ref anchorMaxX, ref anchorMaxY);

      ScaleStencil(modelStencil.Elements, minX, minY, maxX, maxY);
      ScaleStencil(modelStencil.Decorations, minX, minY, maxX, maxY);

      ScaleStencil(modelStencil.Anchors, minX, minY, maxX, maxY);

      double scale = 1000.0F / Math.Max((maxX - minX), (maxY - minY));

      SysCAD.Protocol.Rectangle rect = new SysCAD.Protocol.Rectangle(minX * scale, minY * scale, (maxX - minX) * scale, (maxY - minY) * scale);

      box2.BoundingRect = rect;
      {
        int i;

        ModelStencil stencil = modelStencil;
        bool mirrorX = false;
        bool mirrorY = false;

        ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count];
        i = 0;
        foreach (Element element in stencil.Elements)
        {
          if (element is Arc)
          {
            Arc arc = element as Arc;
            elementTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s);
          }
          if (element is Line)
          {
            Line line = element as Line;
            double x1, y1, x2, y2;

            if (mirrorX)
              x1 = 100.0 - line.x1;
            else
              x1 = line.x1;

            if (mirrorY)
              y1 = 100.0 - line.y1;
            else
              y1 = line.y1;

            if (mirrorX)
              x2 = 100.0F - line.x2;
            else
              x2 = line.x2;

            if (mirrorY)
              y2 = 100.0 - line.y2;
            else
              y2 = line.y2;

            elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2);
          }
          if (element is Bezier)
          {
            Bezier bezier = element as Bezier;
            double x1, y1, x2, y2, x3, y3, x4, y4;

            if (mirrorX)
              x1 = 100.0 - bezier.x1;
            else
              x1 = bezier.x1;

            if (mirrorY)
              y1 = 100.0 - bezier.y1;
            else
              y1 = bezier.y1;

            if (mirrorX)
              x2 = 100.0 - bezier.x2;
            else
              x2 = bezier.x2;

            if (mirrorY)
              y2 = 100.0 - bezier.y2;
            else
              y2 = bezier.y2;

            if (mirrorX)
              x3 = 100.0 - bezier.x3;
            else
              x3 = bezier.x3;

            if (mirrorY)
              y3 = 100.0 - bezier.y3;
            else
              y3 = bezier.y3;

            if (mirrorX)
              x4 = 100.0 - bezier.x4;
            else
              x4 = bezier.x4;

            if (mirrorY)
              y4 = 100.0 - bezier.y4;
            else
              y4 = bezier.y4;

            elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4);
          }
          i++;
        }

        ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count];
        i = 0;
        foreach (Element decoration in stencil.Decorations)
        {
          if (decoration is Arc)
          {
            Arc arc = decoration as Arc;
            decorationTemplate[i] = new ArcTemplate((float)arc.x, (float)arc.y, (float)arc.w, (float)arc.h, (float)arc.a, (float)arc.s);
          }
          if (decoration is Line)
          {
            Line line = decoration as Line;
            double x1, y1, x2, y2;

            if (mirrorX)
              x1 = 100.0 - line.x1;
            else
              x1 = line.x1;

            if (mirrorY)
              y1 = 100.0 - line.y1;
            else
              y1 = line.y1;

            if (mirrorX)
              x2 = 100.0 - line.x2;
            else
              x2 = line.x2;

            if (mirrorY)
              y2 = 100.0 - line.y2;
            else
              y2 = line.y2;

            decorationTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2);
          }
          if (decoration is Bezier)
          {
            Bezier bezier = decoration as Bezier;
            double x1, y1, x2, y2, x3, y3, x4, y4;

            if (mirrorX)
              x1 = 100.0 - bezier.x1;
            else
              x1 = bezier.x1;

            if (mirrorY)
              y1 = 100.0 - bezier.y1;
            else
              y1 = bezier.y1;

            if (mirrorX)
              x2 = 100.0 - bezier.x2;
            else
              x2 = bezier.x2;

            if (mirrorY)
              y2 = 100.0 - bezier.y2;
            else
              y2 = bezier.y2;

            if (mirrorX)
              x3 = 100.0 - bezier.x3;
            else
              x3 = bezier.x3;

            if (mirrorY)
              y3 = 100.0 - bezier.y3;
            else
              y3 = bezier.y3;

            if (mirrorX)
              x4 = 100.0 - bezier.x4;
            else
              x4 = bezier.x4;

            if (mirrorY)
              y4 = 100.0 - bezier.y4;
            else
              y4 = bezier.y4;

            decorationTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4);
          }
          i++;
        }

        box2.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, null, stencil.FillMode, stencil.Tag));
      }


      SysCAD.Protocol.Rectangle anchorRect = new SysCAD.Protocol.Rectangle(anchorMinX * scale, anchorMinY * scale, (anchorMaxX - anchorMinX) * scale, (anchorMaxY - anchorMinY) * scale);

      foreach (Box box in anchorPointBoxes)
        flowChart2.DeleteObject(box);

      anchorPointBoxes.Clear();

      foreach (Anchor anchor in modelStencil.Anchors)
      {
        RectangleF displayRect = new RectangleF((float)(((anchor.Positions[0] as SysCAD.Protocol.Point).X / 100.0F * (maxX - minX) + minX) * scale),
                                                (float)(((anchor.Positions[0] as SysCAD.Protocol.Point).Y / 100.0F * (maxY - minY) + minY) * scale),
                                                0.0F, 0.0F);
        displayRect.Inflate(20.0F, 20.0F);
        Box box = flowChart2.CreateBox(displayRect.X, displayRect.Y, displayRect.Width, displayRect.Height);
        anchorPointBoxes.Add(box);
        box.Style = BoxStyle.Ellipse;
        box.ZTop();
        box.FillColor = Color.Red;
        box.FillColor = Color.FromArgb(100, box.FillColor);
      }

      anchorRect.Inflate((maxX - minX) * scale / 10.0F, (maxY - minY) * scale / 10.0F);
      flowChart2.DocExtents = anchorRect;
      flowChart2.ZoomToRect(anchorRect);
    }
Exemple #5
0
    internal void CreateLink(ModelLink modelLink, GraphicLink graphicLink)
    {

      if (flowChart.InvokeRequired)
      {
        flowChart.BeginInvoke(new CreateLinkDelegate(CreateLink), new object[] { modelLink, graphicLink });
      }
      else
      {
        bool isVisible = false;

        {
          EditorNode destinationNode, originNode;
          if (
            (editorNodes.TryGetValue(graphicLink.Origin, out originNode))
            &&
            (editorNodes.TryGetValue(graphicLink.Destination, out destinationNode))
            )
          {
            isVisible = ((originNode.Visible) || (destinationNode.Visible));
          }
        }

        Box textBox = null;

        {
          SysCAD.Protocol.Rectangle textArea = graphicLink.TagArea;

          if (textArea.IsEmpty) // We haven't got a TagArea stored in the item yet.
          {
            SysCAD.Protocol.Point pointOrigin = new SysCAD.Protocol.Point();
            SysCAD.Protocol.Point pointDestination = new SysCAD.Protocol.Point();
            SysCAD.Protocol.Point pointCenter = new SysCAD.Protocol.Point();

            if (graphicLink.ControlPoints != null && graphicLink.ControlPoints.Count > 1)
            {
              pointOrigin = graphicLink.ControlPoints[0];
              pointDestination = graphicLink.ControlPoints[graphicLink.ControlPoints.Count - 1];
              pointCenter = new SysCAD.Protocol.Point((pointDestination.X + pointOrigin.X) / 2.0F, (pointDestination.Y + pointOrigin.Y) / 2.0F);
            }

            textArea = new SysCAD.Protocol.Rectangle(pointCenter.X,
                                      pointCenter.Y + 4.0,
                                      20.0,
                                      4.0);
          }

          textBox = flowChart.CreateBox((float)textArea.X, (float)textArea.Y, (float)textArea.Width, (float)textArea.Height);
          textBox.RotationAngle = (float)graphicLink.TagAngle;
          textBox.FillColor = System.Drawing.Color.FromArgb(1, System.Drawing.Color.Black);
          textBox.FrameColor = System.Drawing.Color.FromArgb(1, System.Drawing.Color.Black);
          textBox.RotateContents = true;
          textBox.Style = BoxStyle.Shape;
          textBox.Shape = ShapeTemplate.FromId("Rectangle");
          textBox.EnabledHandles = Handles.ResizeTopLeft | Handles.ResizeTopRight |
            Handles.ResizeBottomRight | Handles.ResizeBottomLeft | Handles.ResizeTopCenter |
            Handles.ResizeMiddleRight | Handles.ResizeBottomCenter | Handles.ResizeMiddleLeft |
            Handles.Move;
          textBox.Text = graphicLink.Tag;
        }

        Arrow arrow = flowChart.CreateArrow(new PointF(0.0F, 0.0F), new PointF(10.0F, 10.0F));
        arrow.CustomDraw = CustomDraw.Additional;

        {
          switch (modelLink.LinkClass)
          {
            case "Pipe-1":
              break;
            case "CtrlLink":
              arrow.PenColor = System.Drawing.Color.Gray;
              break;
            default:
              arrow.PenColor = System.Drawing.Color.Red;
              break;
          }

          EditorNode origin = null;
          EditorNode destination = null;

          origin = Item(graphicLink.Origin);
          destination = Item(graphicLink.Destination);

          if (origin == null)
          {
            clientProtocol.LogMessage(out requestId, "Origin Guid " + graphicLink.Origin + " not found for link " + graphicLink.Tag, SysCAD.Log.MessageType.Error);
            return;
          }

          if (destination == null)
          {
            clientProtocol.LogMessage(out requestId, "Destination Guid " + graphicLink.Destination + " not found for link " + graphicLink.Tag, SysCAD.Log.MessageType.Error);
            return;
          }

          SysCAD.Protocol.Point pointOrigin = new SysCAD.Protocol.Point();
          SysCAD.Protocol.Point pointDestination = new SysCAD.Protocol.Point();

          if (graphicLink.ControlPoints != null && graphicLink.ControlPoints.Count > 1)
          {
            pointOrigin = graphicLink.ControlPoints[0];
            pointDestination = graphicLink.ControlPoints[graphicLink.ControlPoints.Count - 1];
          }

          if (origin != null)
          {
            if (origin.HiddenBox != null)
              arrow.Origin = origin.HiddenBox;
            else
              arrow.Origin = origin.ModelBox;
          }

          if (destination != null)
          {
            if (destination.HiddenBox != null)
              arrow.Destination = destination.HiddenBox;
            else
              arrow.Destination = destination.ModelBox;
          }

          if ((modelLink.OriginPort != null) && ((origin.ModelBox.Tag as EditorNode).anchorTagToInt.ContainsKey(modelLink.OriginPort + graphicLink.OriginPortID.ToString())))
            arrow.OrgnAnchor = (origin.ModelBox.Tag as EditorNode).anchorTagToInt[modelLink.OriginPort + graphicLink.OriginPortID.ToString()];
          else
          {
            Console.WriteLine("(origin.ModelBox.Tag as EditorNode).modelNode : " +
              (origin.ModelBox.Tag as EditorNode).ModelNode.Guid.ToString() + " : " +
              (origin.ModelBox.Tag as EditorNode).ModelNode.NodeClass.ToString() + " : " +
              (origin.ModelBox.Tag as EditorNode).ModelNode.Tag.ToString());

            Console.WriteLine("modelLink.OriginPort : " + modelLink.OriginPort);
            Console.WriteLine("graphicLink.OriginPortID.ToString() : " + graphicLink.OriginPortID.ToString());
            Console.WriteLine("anchorTagToInt Key:Value pairs:");
            foreach (string key in (origin.ModelBox.Tag as EditorNode).anchorTagToInt.Keys)
            {
              Console.WriteLine("  " + key + " : " + (origin.ModelBox.Tag as EditorNode).anchorTagToInt[key].ToString());
            }

            Console.WriteLine();
            Console.WriteLine();

            arrow.DestAnchor = -1;
          }

          if ((modelLink.DestinationPort != null) && ((destination.ModelBox.Tag as EditorNode).anchorTagToInt.ContainsKey(modelLink.DestinationPort + graphicLink.DestinationPortID.ToString())))
            arrow.DestAnchor = (destination.ModelBox.Tag as EditorNode).anchorTagToInt[modelLink.DestinationPort + graphicLink.DestinationPortID.ToString()];
          else
          {
            Console.WriteLine("(destination.ModelBox.Tag as EditorNode).modelNode : " +
              (destination.ModelBox.Tag as EditorNode).ModelNode.Guid.ToString() + " : " +
              (destination.ModelBox.Tag as EditorNode).ModelNode.NodeClass.ToString() + " : " +
              (destination.ModelBox.Tag as EditorNode).ModelNode.Tag.ToString());

            Console.WriteLine("modelLink.DestinationPort : " + modelLink.DestinationPort);
            Console.WriteLine("graphicLink.DestinationPortID.ToString() : " + graphicLink.DestinationPortID.ToString());
            Console.WriteLine("anchorTagToInt Key:Value pairs:");
            foreach (string key in (destination.ModelBox.Tag as EditorNode).anchorTagToInt.Keys)
            {
              Console.WriteLine("  " + key + " : " + (destination.ModelBox.Tag as EditorNode).anchorTagToInt[key].ToString());
            }

            Console.WriteLine();
            Console.WriteLine();

            arrow.DestAnchor = -1;
          }

          String originTag = "";

          if (origin != null) originTag = origin.Tag;

          String destinationTag = "";

          if (destination != null) destinationTag = destination.Tag;

          String originPort = "";
          if (modelLink.OriginPort != null) originPort = modelLink.OriginPort;

          String destinationPort = "";
          if (modelLink.DestinationPort != null) destinationPort = modelLink.DestinationPort;

          arrow.ToolTip = "Tag:" + graphicLink.Tag +
            "\nSrc: " + originTag + ":" + originPort +
            "\nDst: " + destinationTag + ":" + destinationPort;
          arrow.ArrowHead = ArrowHead.Triangle;
          arrow.Style = ArrowStyle.Cascading;

          if (graphicLink.ControlPoints != null && graphicLink.ControlPoints.Count > 1)
          {
            SetControlPoints(arrow, graphicLink.ControlPoints);
          }

          if (graphicLink.ControlPoints[0].X == graphicLink.ControlPoints[1].X)
          {
            arrow.CascadeOrientation = Orientation.Auto;
          }
          else
          {
            arrow.CascadeOrientation = Orientation.Auto;
          }
        }

        EditorLink editorLink = new EditorLink(this, graphicLink, modelLink);
        editorLink.Arrow = arrow;
        editorLink.TextBox = textBox;
        editorLink.UpdateVisibility();

        arrow.Tag = editorLink;
        textBox.Tag = editorLink;

        editorLinks.Add(editorLink.Guid, editorLink);

        NewElementSelection();
      }
    }
Exemple #6
0
    private void UpdateStencil(GraphicStencil graphicStencil)
    {
      double minX = double.MaxValue;
      double maxX = double.MinValue;
      double minY = double.MaxValue;
      double maxY = double.MinValue;

      UpdateStencil(graphicStencil.Elements, ref minX, ref minY, ref maxX, ref maxY);
      UpdateStencil(graphicStencil.Decorations, ref minX, ref minY, ref maxX, ref maxY);

      double textMinX = double.MaxValue;
      double textMaxX = double.MinValue;
      double textMinY = double.MaxValue;
      double textMaxY = double.MinValue;

      UpdateStencil(graphicStencil.TagArea, ref textMinX, ref textMinY, ref textMaxX, ref textMaxY);

      ScaleStencil(graphicStencil.Elements, minX, minY, maxX, maxY);
      ScaleStencil(graphicStencil.Decorations, minX, minY, maxX, maxY);

      double scale = 1000.0 / Math.Max((maxX - minX), (maxY - minY));

      SysCAD.Protocol.Rectangle rect = new SysCAD.Protocol.Rectangle(minX * scale, minY * scale, (maxX - minX) * scale, (maxY - minY) * scale);

      graphicStencil.defaultSize = new SysCAD.Protocol.Size((maxX - minX), (maxY - minY));

      box1.BoundingRect = rect;


      {
        GraphicStencil stencil = graphicStencil;
        bool mirrorX = false;
        bool mirrorY = false;

        ElementTemplate[] elementTemplate = new ElementTemplate[stencil.Elements.Count];
        {
          int i = 0;
          foreach (Element element in stencil.Elements)
          {
            if (element is Arc)
            {
              elementTemplate[i] = new ArcTemplate(
                (float)(element as Arc).x,
                (float)(element as Arc).y,
                (float)(element as Arc).w,
                (float)(element as Arc).h,
                (float)(element as Arc).a,
                (float)(element as Arc).s);
            }
            if (element is Line)
            {
              Line line = element as Line;
              double x1, y1, x2, y2;

              if (mirrorX)
                x1 = 100.0 - line.x1;
              else
                x1 = line.x1;

              if (mirrorY)
                y1 = 100.0 - line.y1;
              else
                y1 = line.y1;

              if (mirrorX)
                x2 = 100.0 - line.x2;
              else
                x2 = line.x2;

              if (mirrorY)
                y2 = 100.0 - line.y2;
              else
                y2 = line.y2;

              elementTemplate[i] = new LineTemplate((float)x1, (float)y1, (float)x2, (float)y2);
            }
            if (element is Bezier)
            {
              Bezier bezier = element as Bezier;
              double x1, y1, x2, y2, x3, y3, x4, y4;

              if (mirrorX)
                x1 = 100.0 - bezier.x1;
              else
                x1 = bezier.x1;

              if (mirrorY)
                y1 = 100.0 - bezier.y1;
              else
                y1 = bezier.y1;

              if (mirrorX)
                x2 = 100.0 - bezier.x2;
              else
                x2 = bezier.x2;

              if (mirrorY)
                y2 = 100.0 - bezier.y2;
              else
                y2 = bezier.y2;

              if (mirrorX)
                x3 = 100.0 - bezier.x3;
              else
                x3 = bezier.x3;

              if (mirrorY)
                y3 = 100.0 - bezier.y3;
              else
                y3 = bezier.y3;

              if (mirrorX)
                x4 = 100.0 - bezier.x4;
              else
                x4 = bezier.x4;

              if (mirrorY)
                y4 = 100.0 - bezier.y4;
              else
                y4 = bezier.y4;

              elementTemplate[i] = new BezierTemplate((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4);
            }
            i++;
          }
        }

        ElementTemplate[] decorationTemplate = new ElementTemplate[stencil.Decorations.Count];
        {
          int i = 0;
          foreach (Element decoration in stencil.Decorations)
          {
            if (decoration is Arc)
            {
              decorationTemplate[i] = new ArcTemplate(
                (float)(decoration as Arc).x,
                (float)(decoration as Arc).y,
                (float)(decoration as Arc).w,
                (float)(decoration as Arc).h,
                (float)(decoration as Arc).a,
                (float)(decoration as Arc).s);
            }
            if (decoration is Line)
            {
              decorationTemplate[i] = new LineTemplate(
                (float)(decoration as Line).x1,
                (float)(decoration as Line).y1,
                (float)(decoration as Line).x2,
                (float)(decoration as Line).y2);
            }
            if (decoration is Bezier)
            {
              decorationTemplate[i] = new BezierTemplate(
                (float)(decoration as Bezier).x1,
                (float)(decoration as Bezier).y1,
                (float)(decoration as Bezier).x2,
                (float)(decoration as Bezier).y2,
                (float)(decoration as Bezier).x3,
                (float)(decoration as Bezier).y3,
                (float)(decoration as Bezier).x4,
                (float)(decoration as Bezier).y4);
            }
            i++;
          }
        }

        box1.Shape = (new ShapeTemplate(elementTemplate, decorationTemplate, new ElementTemplate[0], stencil.fillMode, stencil.Tag));
      }

      SysCAD.Protocol.Rectangle textRect = new SysCAD.Protocol.Rectangle(textMinX * scale, textMinY * scale, (textMaxX - textMinX) * scale, (textMaxY - textMinY) * scale);

      textBox1.BoundingRect = textRect;
      //textBox1.Shape = graphicStencil.TextShapeTemplate(false, false);
      textBox1.ZTop();
      textBox1.FillColor = Color.FromArgb(100, Color.HotPink);

      double bothMinX = Math.Min(minX, textMinX);
      double bothMaxX = Math.Max(maxX, textMaxX);
      double bothMinY = Math.Min(minY, textMinY);
      double bothMaxY = Math.Max(maxY, textMaxY);

      SysCAD.Protocol.Rectangle bothRect = new SysCAD.Protocol.Rectangle(bothMinX * scale, bothMinY * scale, (bothMaxX - bothMinX) * scale, (bothMaxY - bothMinY) * scale);

      bothRect.Inflate((maxX - minX) * scale / 10.0F, (maxY - minY) * scale / 10.0F);
      flowChart1.DocExtents = bothRect;
      flowChart1.ZoomToRect(bothRect);
    }
Exemple #7
0
    internal void CreateNode(ModelNode modelNode, GraphicNode graphicNode)
    {
      if (flowChart.InvokeRequired)
      {
        flowChart.BeginInvoke(new CreateNodeDelegate(CreateNode), new object[] { modelNode, graphicNode });
      }
      else
      {
        creatingNode = true; // turn off flowchart events while we're mid-create.

        EditorNode editorNode = new EditorNode(this, graphicNode, modelNode);

        PureComponents.TreeView.Node treeViewNode = null;
        {
          treeViewNode = tvNavigation.AddNodeByPath(graphicNode.Path + graphicNode.Tag, graphicNode.Guid.ToString());
          treeViewNode.AllowDrop = false;

          treeViewNode.Tag = editorNode;

          NewElementSelection();
        }

        EditorArea editorArea = null;
        bool isVisible = false;
        if (treeViewNode.Parent != null) // if we're not root, make visibility same as parent.
        {
          if (treeViewNode.Parent.Tag is EditorArea)
            editorArea = treeViewNode.Parent.Tag as EditorArea;

          isVisible = treeViewNode.Parent.IsSelected;
        }

        ModelStencil modelStencil;
        GraphicStencil graphicStencil = GraphicStencil(graphicNode.Stencil);


        Box textBox = null, graphicBox = null, modelBox = null, hiddenBox = null;

        {
          SysCAD.Protocol.Rectangle textArea = graphicNode.TagArea;

          if (textArea.IsEmpty) // We haven't got a TagArea stored in the item yet.
          {
            if (graphicStencil != null)
            {
              textArea = new SysCAD.Protocol.Rectangle(graphicNode.X + graphicStencil.TagArea.X / graphicStencil.DefaultSize.Width * graphicNode.Width,
                                        graphicNode.Y + graphicStencil.TagArea.Y / graphicStencil.DefaultSize.Height * graphicNode.Height,
                                        graphicStencil.TagArea.Width / graphicStencil.DefaultSize.Width * graphicNode.Width,
                                        graphicStencil.TagArea.Height / graphicStencil.DefaultSize.Height * graphicNode.Height);
            }
            else
            {
              textArea = new SysCAD.Protocol.Rectangle(graphicNode.X,
                                        graphicNode.Y + 1.1F * graphicNode.Height,
                                        graphicNode.Width,
                                        graphicNode.Height / 2.0F);
            }
          }

          textBox = flowChart.CreateBox((float)textArea.X, (float)textArea.Y, (float)textArea.Width, (float)textArea.Height);
          textBox.RotationAngle = (float)graphicNode.TagAngle;
          textBox.FillColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
          textBox.FrameColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
          textBox.RotateContents = true;
          textBox.Style = BoxStyle.Shape;
          textBox.Shape = ShapeTemplate.FromId("Rectangle");
          textBox.EnabledHandles = Handles.ResizeTopLeft | Handles.ResizeTopRight |
            Handles.ResizeBottomRight | Handles.ResizeBottomLeft | Handles.ResizeTopCenter |
            Handles.ResizeMiddleRight | Handles.ResizeBottomCenter | Handles.ResizeMiddleLeft |
            Handles.Move;
          textBox.Text = graphicNode.Tag;
          textBox.Tag = editorNode;
          editorNode.TextBox = textBox;
          // Don't set this yet, happens after every zoom because it needs to be scaled.
          //textBox.Font = graphicNode.TagFont.BaseFont;
        }

        if (graphicNode.Stencil != null)
        {
          graphicBox = flowChart.CreateBox((float)graphicNode.X, (float)graphicNode.Y, (float)graphicNode.Width, (float)graphicNode.Height);
          graphicBox.RotationAngle = (float)graphicNode.Angle;
          graphicBox.ToolTip = graphicNode.Tag + "\n\nClassID: " + "graphicNode.Model";
          graphicBox.Style = BoxStyle.Shape;

          graphicBox.Tag = editorNode;
          editorNode.GraphicBox = graphicBox;

          if (GraphicStencil(graphicNode.Stencil) == null)
          // can't use graphicStencil because the above GraphicShape call will find a stencil even if the shape doesn't exist.
          {
            clientProtocol.LogMessage(out requestId, "GraphicStencil not found in library for stencil \'" + graphicNode.Stencil + "\'", SysCAD.Log.MessageType.Warning);
          }

          if (graphicStencil != null)
          {
            graphicBox.Shape = GetShapeTemplate(graphicStencil, graphicNode.MirrorX, graphicNode.MirrorY);
            // An attempt to deal with un-clickable non-model graphics...  failed, will have to try something else.
            // perhaps catch the click and look underneath expecially for graphicboxes???
            //if (graphicBox.Shape.Outline.Length == 0)
            //{
            //  ElementTemplate[] background = new ElementTemplate[4];
            //  background[0] = new LineTemplate(  0.0F,   0.0F,   0.0F, 100.0F);
            //  background[1] = new LineTemplate(  0.0F, 100.0F, 100.0F, 100.0F);
            //  background[2] = new LineTemplate(100.0F, 100.0F, 100.0F,   0.0F);
            //  background[3] = new LineTemplate(100.0F,   0.0F,   0.0F,   0.0F);

            //  graphicBox.Shape = new ShapeTemplate(background, graphicBox.Shape.Decorations, graphicBox.Shape.TagArea, FillMode.Alternate);
            //  graphicBox.FillColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            //  graphicBox.FrameColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            //}
          }
          else
            graphicBox.Shape = ShapeTemplate.FromId("Decision2");

          if (graphicNode.FillColor.IsEmpty)
            graphicNode.FillColor = graphicBox.FillColor;

          else
            graphicBox.FillColor = graphicNode.FillColor;
        }

        creatingNode = false; // we want any events to happen for the last created piece.

        if (modelNode != null)
        {
          modelBox = flowChart.CreateBox((float)graphicNode.X, (float)graphicNode.Y, (float)graphicNode.Width, (float)graphicNode.Height);
          modelBox.RotationAngle = (float)graphicNode.Angle;
          modelBox.ToolTip = graphicNode.Tag + "\n\nClassID: " + "graphicNode.Model";
          modelBox.Style = BoxStyle.Shape;
          modelBox.CustomDraw = CustomDraw.Additional;

          modelBox.Tag = editorNode;
          editorNode.ModelBox = modelBox;

          modelStencil = ModelStencil(modelNode.NodeClass);

          if (modelStencil == null)
          {
            clientProtocol.LogMessage(out requestId, "ModelStencil not found in library for shape \'" + modelNode.NodeClass + "\'", SysCAD.Log.MessageType.Error);
          }


          if (modelStencil != null)
          {
            modelBox.Shape = GetShapeTemplate(modelStencil, graphicNode.MirrorX, graphicNode.MirrorY);

            //RequestPortInfo test code.
            //{
            //  Int64 requestId2;
            //  RequestGraphicPortInfo(out requestId2, graphicNode.Guid, ((Anchor)(modelStencil.Anchors[0])).Tag);
            //}
          }
          else
            modelBox.Shape = ShapeTemplate.FromId("Decision2");

          modelBox.AnchorPattern = GetAnchorPattern(modelStencil, editorNode);

          modelBox.FillColor = System.Drawing.Color.FromArgb(220, 222, 184, 136);
          modelBox.FrameColor = System.Drawing.Color.FromArgb(255, 111, 92, 68);

          graphicBox.EnabledHandles = Handles.None;
          graphicBox.HandlesStyle = HandlesStyle.Invisible;

          if (modelBox.Shape.Outline.Length == 0) // we're going to need an invisible box to use for hit-testing.
          {
            hiddenBox = flowChart.CreateBox((float)graphicNode.X, (float)graphicNode.Y, (float)graphicNode.Width, (float)graphicNode.Height);
            hiddenBox.RotationAngle = (float)graphicNode.Angle;
            hiddenBox.ToolTip = modelNode.Tag + "\n\nClassID: " + "modelNode.Model";
            hiddenBox.Style = BoxStyle.Shape; //BoxStyle.Ellipse; // not sure whether to go with ellipse or rectangle here (without corners, it'll get in the way less...)
            hiddenBox.Shape = GetShapeTemplate(ModelStencil("Tank-1"), graphicNode.MirrorX, graphicNode.MirrorY);
            hiddenBox.FillColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            hiddenBox.FrameColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            hiddenBox.ZBottom();

            hiddenBox.Tag = editorNode;
            editorNode.HiddenBox = hiddenBox;

            graphicBox.AttachTo(hiddenBox, 0, 0, 100, 100);
          }
        }
        else
        {
          if ((graphicBox != null) && (graphicBox.Shape.Outline.Length == 0)) // we're going to need an invisible box to use for hit-testing.
          {
            hiddenBox = flowChart.CreateBox((float)graphicNode.X, (float)graphicNode.Y, (float)graphicNode.Width, (float)graphicNode.Height);
            hiddenBox.RotationAngle = (float)graphicNode.Angle;
            hiddenBox.ToolTip = graphicNode.Tag + "\n\nClassID: " + "graphicNode.Model";
            hiddenBox.Style = BoxStyle.Shape; //BoxStyle.Ellipse; // not sure whether to go with ellipse or rectangle here (without corners, it'll get in the way less...)
            hiddenBox.Shape = GetShapeTemplate(ModelStencil("Tank-1"), graphicNode.MirrorX, graphicNode.MirrorY);
            hiddenBox.FillColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            hiddenBox.FrameColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
            hiddenBox.ZBottom();

            hiddenBox.Tag = editorNode;
            editorNode.HiddenBox = hiddenBox;

            graphicBox.AttachTo(hiddenBox, 0, 0, 100, 100);
          }
        }

        if (modelBox != null)
        {
          textBox.AttachTo(modelBox, AttachToNode.BottomCenter);
          graphicBox.AttachTo(modelBox, 0, 0, 100, 100);
          if (editorArea != null)
            modelBox.AttachTo(editorArea.Box, AttachToNode.TopLeft);
        }
        else if (graphicBox != null)
        {
          textBox.AttachTo(graphicBox, AttachToNode.BottomCenter);
          if (hiddenBox != null)
            hiddenBox.AttachTo(graphicBox, 0, 0, 100, 100);
          if (editorArea != null)
            graphicBox.AttachTo(editorArea.Box, AttachToNode.TopLeft);
        }

        editorNode.Visible = isVisible;
        editorNodes.Add(editorNode.Guid, editorNode);
      }
    }
Exemple #8
0
    internal void SetY(Guid guid, float y)
    {
      EditorNode item;
      editorNodes.TryGetValue(guid, out item);

      if (item != null)
      {
        SysCAD.Protocol.Rectangle boundingRect = new SysCAD.Protocol.Rectangle(item.ModelBox.BoundingRect);
        boundingRect.Y = y;
        item.ModelBox.BoundingRect = boundingRect;
        item.GraphicBox.BoundingRect = boundingRect;
      }
    }
Exemple #9
0
    private void fcFlowChart_ArrowCreated(object sender, ArrowEventArgs e)
    {
      tempArrowKey++;
      String newLinkTag = "A_" + tempArrowKey.ToString(CultureInfo.InvariantCulture);
      e.Arrow.Text = newLinkTag;

      GraphicNode origin = null;
      GraphicNode destination = null;
      ModelNode modelOrigin = null;
      ModelNode modelDestination = null;
      String originPort = "";
      String destinationPort = "";
      Int16 originPortID = -1;
      Int16 destinationPortID = -1;
      List<SysCAD.Protocol.Point> controlPoints;
      SysCAD.Protocol.Rectangle textArea;

      if (newDestinationBox != null)
      {
        if (!((state.ClientProtocol.graphic.Nodes.TryGetValue((newDestinationBox.Tag as EditorNode).Guid, out destination)) &&
          (state.ClientProtocol.model.Nodes.TryGetValue(destination.ModelGuid, out modelDestination))))
        {
          state.ClientProtocol.LogMessage(out requestId, "Node missing for destination Box " + newDestinationBox.Tag, SysCAD.Log.MessageType.Error);
          return;
        }

        if (newDestinationAnchor != -1)
        {
          String fullAnchor = (newDestinationBox.Tag as EditorNode).anchorIntToTag[newDestinationAnchor];
          String anchorName = fullAnchor.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
          Int16 anchorID = Convert.ToInt16(fullAnchor.Substring(anchorName.Length), CultureInfo.InvariantCulture);
          destinationPort = anchorName;
          destinationPortID = anchorID;
        }
      }

      if (oldOriginBox != null)
      {
        if (!((state.ClientProtocol.graphic.Nodes.TryGetValue((newOriginBox.Tag as EditorNode).Guid, out origin)) &&
          (state.ClientProtocol.model.Nodes.TryGetValue(origin.ModelGuid, out modelOrigin))))
        {
          state.ClientProtocol.LogMessage(out requestId, "Node missing for origin Box " + newDestinationBox.Tag, SysCAD.Log.MessageType.Error);
          return;
        }

        if (oldOriginAnchor != -1)
        {
          String fullAnchor = (oldOriginBox.Tag as EditorNode).anchorIntToTag[oldOriginAnchor];
          String anchorName = fullAnchor.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
          Int16 anchorID = Convert.ToInt16(fullAnchor.Substring(anchorName.Length), CultureInfo.InvariantCulture);
          originPort = anchorName;
          originPortID = anchorID;
        }
      }

      controlPoints = State.GetControlPoints(e.Arrow.ControlPoints);

      textArea = new SysCAD.Protocol.Rectangle(0.0, 0.0, 0.0, 0.0);


      fcFlowChart.DeleteObject(e.Arrow);

      form1.ToolStripStatusLabel.Text = "";

      //arrowBeingModified.CustomDraw = CustomDraw.None;
      arrowBeingModifiedSelectionHandle = -1;
      arrowBeingModified = null;
      originAnchorChosen = null;
      destinationAnchorChosen = null;

      ModelLink modelLink = new ModelLink(new Guid(), string.Empty, "Pipe-1", modelOrigin.Guid, modelDestination.Guid, originPort, destinationPort);
      GraphicLink graphicLink = new GraphicLink(new Guid(), modelLink.Guid, string.Empty, origin.Guid, originPortID, destination.Guid, destinationPortID, controlPoints, 1.0, textArea, 0.0, new SysCAD.Protocol.Font(), true);

      SysCAD.Protocol.Action action = new SysCAD.Protocol.Action();

      action.Create.Add(modelLink);
      action.Create.Add(graphicLink);

      AddAction(action);
    }
Exemple #10
0
    private void InsertSymbol(object sender, EventArgs e)
    {
      GraphicStencilChangeForm gscf = new GraphicStencilChangeForm(state.GraphicUnselectedThumbnails, state.GraphicSelectedThumbnails, state.ModelStencils, state.GraphicStencils, "");
      if (gscf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        GraphicStencil graphicStencil = null;
        state.GraphicStencils.TryGetValue(gscf.Value, out graphicStencil);
        if (graphicStencil != null)
        {
          SysCAD.Protocol.Rectangle boundingRect = new SysCAD.Protocol.Rectangle(hoverPoint.X, hoverPoint.Y, 0.0, 0.0);
          boundingRect.Inflate(graphicStencil.DefaultSize.Width, graphicStencil.DefaultSize.Height);
          GraphicNode node = new GraphicNode("", hoverArea.GraphicArea.Path + hoverArea.GraphicArea.Tag, Guid.NewGuid(), gscf.Value, boundingRect, 0.0, graphicStencil.TagArea, 0.0, new SysCAD.Protocol.Font(), true, 1.0, Color.Beige, FillMode.Alternate, false, false);
          SysCAD.Protocol.Action action = new SysCAD.Protocol.Action();
          action.Create.Add(node);
          AddAction(action);
        }
      }

    }
Exemple #11
0
    private void fcFlowChart_DrawArrow(object sender, ArrowDrawArgs e)
    {
      Arrow arrow = e.Arrow;
      EditorLink link = arrow.Tag as EditorLink;

      if (arrow != arrowBeingModified)
      {

        if (arrowBeingModified == null)
        {
          {
            MindFusion.FlowChartX.Node node = arrow.Destination;
            Box box = null;

            if (node != null)
              box = node as Box;

            if ((box != null) && (arrow.DestAnchor != -1))
            {
              PointF anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(box.BoundingRect),
                box.AnchorPattern.Points[arrow.DestAnchor].X,
                box.AnchorPattern.Points[arrow.DestAnchor].Y,
                box.RotationAngle).ToPointF();

              PointF[] extensionPoints =
                new PointF[] { arrow.ControlPoints[arrow.ControlPoints.Count - 1], anchorPointPos };

              System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, 0, 0, 255), 0.0F);
              e.Graphics.DrawLines(pen, extensionPoints);

              pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, Color.Green), 0.0F);
              SysCAD.Protocol.Rectangle anchorPointRect = new SysCAD.Protocol.Rectangle(anchorPointPos, SysCAD.Protocol.Size.Empty);
              anchorPointRect.Inflate((double)fcFlowChart.SelHandleSize, (double)fcFlowChart.SelHandleSize);
              e.Graphics.DrawEllipse(pen, anchorPointRect);
            }

            else
            {
              Color errorColor = new Color();

              if (box != null)
              {
                errorColor = Color.Yellow;
                PointF anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(box.BoundingRect),
                  50,
                  50,
                  box.RotationAngle).ToPointF();

                PointF[] extensionPoints =
                  new PointF[] { arrow.ControlPoints[arrow.ControlPoints.Count - 1], anchorPointPos };

                System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.FromArgb(link.Opacity, errorColor), 0.0F);
                e.Graphics.DrawLines(pen1, extensionPoints);
              }
              else
                errorColor = Color.Red;

              System.Drawing.Pen pen = new System.Drawing.Pen(errorColor, fcFlowChart.SelHandleSize);
              PointF controlPoint = arrow.ControlPoints[arrow.ControlPoints.Count - 1];
              SysCAD.Protocol.Rectangle controlPointRect = new SysCAD.Protocol.Rectangle(controlPoint, SysCAD.Protocol.Size.Empty);
              controlPointRect.Inflate(fcFlowChart.SelHandleSize, fcFlowChart.SelHandleSize);
              e.Graphics.DrawEllipse(pen, controlPointRect);
            }
          }

          {
            MindFusion.FlowChartX.Node node = arrow.Origin;
            Box box = null;

            if (node != null)
              box = node as Box;

            if ((box != null) && (arrow.OrgnAnchor != -1))
            {
              PointF anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(box.BoundingRect),
                box.AnchorPattern.Points[arrow.OrgnAnchor].X,
                box.AnchorPattern.Points[arrow.OrgnAnchor].Y,
                box.RotationAngle).ToPointF();

              PointF[] extensionPoints =
                new PointF[] { arrow.ControlPoints[0], anchorPointPos };

              System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, 0, 0, 255), 0.0F);
              e.Graphics.DrawLines(pen, extensionPoints);

              pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, Color.Green), 0.0F);
              SysCAD.Protocol.Rectangle r = new SysCAD.Protocol.Rectangle(anchorPointPos, SysCAD.Protocol.Size.Empty);
              r.Inflate(fcFlowChart.SelHandleSize, fcFlowChart.SelHandleSize);
              e.Graphics.DrawEllipse(pen, r);
            }

            else
            {
              Color errorColor = new Color();

              if (box != null)
              {
                errorColor = Color.Yellow;

                PointF anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(box.BoundingRect),
                  50,
                  50,
                  box.RotationAngle).ToPointF();

                PointF[] extensionPoints =
                  new PointF[] { arrow.ControlPoints[0], anchorPointPos };

                System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.FromArgb(link.Opacity, Color.Yellow), 0.0F);
                e.Graphics.DrawLines(pen1, extensionPoints);
              }
              else
                errorColor = Color.Red;

              System.Drawing.Pen pen = new System.Drawing.Pen(errorColor, fcFlowChart.SelHandleSize);
              PointF p = arrow.ControlPoints[0];
              SysCAD.Protocol.Rectangle r = new SysCAD.Protocol.Rectangle(p, SysCAD.Protocol.Size.Empty);
              r.Inflate(fcFlowChart.SelHandleSize, fcFlowChart.SelHandleSize);
              e.Graphics.DrawEllipse(pen, r);
            }
          }
        }
      }

      else // this is an arrowbeingmodified...
      {
        {

          if (newDestinationAnchor != -1)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(newDestinationBox.BoundingRect),
              newDestinationBox.AnchorPattern.Points[newDestinationAnchor].X,
              newDestinationBox.AnchorPattern.Points[newDestinationAnchor].Y,
              newDestinationBox.RotationAngle);

            PointF[] extensionPoints =
              new PointF[] { arrow.ControlPoints[arrow.ControlPoints.Count - 1], anchorPointPos.ToPointF() };

            System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, Color.LightBlue), 0.0F);

            e.Graphics.DrawLines(pen, extensionPoints);
          }

          else if (oldDestinationAnchor != -1)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(oldDestinationBox.BoundingRect),
              oldDestinationBox.AnchorPattern.Points[oldDestinationAnchor].X,
              oldDestinationBox.AnchorPattern.Points[oldDestinationAnchor].Y,
              oldDestinationBox.RotationAngle);

            PointF[] extensionPoints =
              new PointF[] { arrow.ControlPoints[arrow.ControlPoints.Count - 1], anchorPointPos.ToPointF() };

            System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, 0, 0, 255), 0.0F);

            e.Graphics.DrawLines(pen, extensionPoints);
          }
        }

        {

          if (newOriginAnchor != -1)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(newOriginBox.BoundingRect),
              newOriginBox.AnchorPattern.Points[newOriginAnchor].X,
              newOriginBox.AnchorPattern.Points[newOriginAnchor].Y,
              newOriginBox.RotationAngle);

            PointF[] extensionPoints =
              new PointF[] { arrow.ControlPoints[0], anchorPointPos.ToPointF() };

            System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, Color.LightBlue), 0.0F);

            e.Graphics.DrawLines(pen, extensionPoints);
          }

          else if (oldOriginAnchor != -1)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(oldOriginBox.BoundingRect),
              oldOriginBox.AnchorPattern.Points[oldOriginAnchor].X,
              oldOriginBox.AnchorPattern.Points[oldOriginAnchor].Y,
              oldOriginBox.RotationAngle);

            PointF[] extensionPoints =
              new PointF[] { arrow.ControlPoints[0], anchorPointPos.ToPointF() };

            System.Drawing.Pen pen = new System.Drawing.Pen(Color.FromArgb(link.Opacity, 0, 0, 255), 0.0F);

            e.Graphics.DrawLines(pen, extensionPoints);
          }
        }
      }
    }