Пример #1
0
        private void ViewShowLinks()
        {
            frmFlowChart.State.ShowLinks = ((IBarCheckableCommand)barManager1.Commands["View.ShowLinks"]).Checked;

            foreach (Arrow arrow in frmFlowChart.FlowChart.Arrows)
            {
                EditorLink link = arrow.Tag as EditorLink;
                if (link != null)
                {
                    link.UpdateVisibility();
                }
                else
                {
                    frmFlowChart.State.ClientProtocol.LogMessage(out requestId, "EditorLink missing for Arrow (Text: " + arrow.Text + ".)", SysCAD.Log.MessageType.Error);
                }
            }
        }
Пример #2
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();
      }
    }
Пример #3
0
 public void SetArrow(State state, Arrow arrow, GraphicLink graphicLink, ModelLink modelLink)
 {
   EditorLink link = new EditorLink(state, graphicLink, modelLink);
   link.Arrow = arrow;
   editorLinks.Add(graphicLink.Guid, link);
 }
Пример #4
0
 private void RouteLink(EditorLink link)
 {
   RouteLink(link.Arrow);
 }
Пример #5
0
    private void SetHoverMembers(MouseEventArgs e)
    {
      PointF ptF = fcFlowChart.ClientToDoc(new System.Drawing.Point(e.X, e.Y));

      Arrow hoverArrow = fcFlowChart.GetArrowAt(ptF, 2.0F);
      Box hoverBox = fcFlowChart.GetBoxAt(ptF, 2.0F);

      hoverLink = null;
      hoverNode = null;
      hoverArea = null;

      if ((hoverArrow != null) && (hoverArrow.Tag is EditorLink))
        hoverLink = hoverArrow.Tag as EditorLink;

      if ((hoverBox != null) && (hoverBox.Tag is EditorNode))
        hoverNode = hoverBox.Tag as EditorNode;
      else
      {
        foreach (EditorNode node in state.Nodes)
        {
          if (node.Locked)
          {
            if (((node.ModelBox != null) && (node.ModelBox.BoundingRect.Contains(ptF))) ||
              ((node.GraphicBox != null) && (node.GraphicBox.BoundingRect.Contains(ptF))) ||
              ((node.TextBox != null) && (node.TextBox.BoundingRect.Contains(ptF))) ||
              ((node.HiddenBox != null) && (node.HiddenBox.BoundingRect.Contains(ptF))))
            {
              hoverNode = node;
              return;
            }
          }
        }
      }

      if ((hoverBox != null) && (hoverBox.Tag is EditorArea))
        hoverArea = (hoverBox.Tag as EditorArea);
      else
      {
        foreach (EditorArea area in state.Areas)
        {
          if (area.Box.BoundingRect.Contains(ptF))
          {
            hoverArea = area;
            return;
          }
        }
      }
    }
Пример #6
0
    private void fcFlowChart_MouseMove(object sender, MouseEventArgs e)
    {
      SetHoverMembers(e);

      EditorNode editorNode = null;
      form1.fcHoverview.ClearAll();
      form1.hoverviewIncomingLinks.Clear();
      form1.hoverviewOutgoingLinks.Clear();
      // Update Hoverview.

      if (hoverNode != null)
      {
        editorNode = hoverNode;
        form1.hoverviewIncomingLinks.Clear();
        form1.hoverviewOutgoingLinks.Clear();
        if (hoverNode.ModelBox != null)
        {
          foreach (Arrow arrow in hoverNode.ModelBox.IncomingArrows)
            form1.hoverviewIncomingLinks.Add(arrow.Tag as EditorLink);
          foreach (Arrow arrow in hoverNode.ModelBox.OutgoingArrows)
            form1.hoverviewOutgoingLinks.Add(arrow.Tag as EditorLink);
        }
      }
      else if (fcFlowChart.Selection.Boxes.Count == 1)
      {
        editorNode = fcFlowChart.Selection.Boxes[0].Tag as EditorNode;
        form1.hoverviewIncomingLinks.Clear();
        form1.hoverviewOutgoingLinks.Clear();
        foreach (Arrow arrow in fcFlowChart.Selection.Boxes[0].IncomingArrows)
          form1.hoverviewIncomingLinks.Add(arrow.Tag as EditorLink);
        foreach (Arrow arrow in fcFlowChart.Selection.Boxes[0].OutgoingArrows)
          form1.hoverviewOutgoingLinks.Add(arrow.Tag as EditorLink);

      }

      if (editorNode != null)
      {
        ModelNode modelNode = editorNode.ModelNode;
        if (modelNode != null)
        {
          ModelStencil modelStencil = State.ModelStencil(modelNode.NodeClass);

          if (modelStencil != null)
          {
            float scale;
            if (form1.fcHoverview.Size.Width / modelStencil.DefaultSize.Width > form1.fcHoverview.Size.Height / modelStencil.DefaultSize.Height)
            {
              scale = (float)(form1.fcHoverview.Size.Height / modelStencil.DefaultSize.Height) / 5.0F;
            }
            else
            {
              scale = (float)(form1.fcHoverview.Size.Width / modelStencil.DefaultSize.Width) / 5.0F;
            }

            //float scale = 100.0F / (float)Math.Sqrt((float)graphicStencil.defaultSize.Width * (float)graphicStencil.default5Size.Width + (float)graphicStencil.defaultSize.Height * (float)graphicStencil.defaultSize.Height);
            form1.fcHoverview.AntiAlias = SmoothingMode.AntiAlias;


            form1.hoverviewBox = form1.fcHoverview.CreateBox(0.0F, 0.0F, (float)modelStencil.DefaultSize.Width * scale, (float)modelStencil.DefaultSize.Height * scale);
            form1.hoverviewBox.FillColor = System.Drawing.Color.FromArgb(220, 222, 184, 136);
            form1.hoverviewBox.FrameColor = System.Drawing.Color.FromArgb(255, 111, 92, 68);

            //Table table = form1.fcHoverview.CreateTable(0.0F, 10.0F + (float)graphicStencil.defaultSize.Height * scale, 80.0F, 30.0F);
            //table.Caption = "Ports";
            //table.ColumnCount = 2;
            //int i = table.AddRow();

            if (modelStencil != null)
              form1.hoverviewBox.Shape = State.GetShapeTemplate(modelStencil, false, false);
            else
              form1.hoverviewBox.Shape = ShapeTemplate.FromId("Decision2");

            form1.hoverviewBox.AnchorPattern = State.GetAnchorPattern(modelStencil, editorNode);

            form1.hoverviewBox.Tag = editorNode;
            form1.hoverviewBox.Visible = true;
            form1.hoverviewBox.Style = BoxStyle.Shape;

            foreach (EditorLink link in form1.hoverviewIncomingLinks)
            {
              Arrow arrow = state.Arrow(link.Guid);

              int portId = 0;
              (editorNode.ModelBox.Tag as EditorNode).anchorTagToInt.TryGetValue(link.ModelLink.DestinationPort + link.GraphicLink.DestinationPortID.ToString(CultureInfo.InvariantCulture), out portId);

              if (form1.hoverviewBox.AnchorPattern.Points.Count > portId)
              {
                PointF anchorPointPos = FrmFlowChart.GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(form1.hoverviewBox.BoundingRect),
                  form1.hoverviewBox.AnchorPattern.Points[portId].X,
                  form1.hoverviewBox.AnchorPattern.Points[portId].Y,
                  form1.hoverviewBox.RotationAngle).ToPointF();

                PointF pt1 = Flowchart2Hoverbox(link.Arrow.Destination.BoundingRect,
                                   form1.hoverviewBox.BoundingRect,
                                   arrow.ControlPoints[arrow.ControlPoints.Count - 2]);
                PointF pt2 = Flowchart2Hoverbox(link.Arrow.Destination.BoundingRect,
                                   form1.hoverviewBox.BoundingRect,
                                   arrow.ControlPoints[arrow.ControlPoints.Count - 1]);

                ///Box box1 = form1.fcHoverview.CreateBox(pt1.X*2.0F, pt1.Y, 0.001F, 0.01F);
                //box1.Visible = false;
                //box1.FillColor = System.Drawing.Color.FromArgb(20, 222, 184, 136);
                //box1.FrameColor = System.Drawing.Color.FromArgb(25, 111, 92, 68);
                //Box box2 = form1.fcHoverview.CreateBox(pt2.X, pt2.Y, 0.001F, 0.01F);
                //box2.Visible = false;
                Arrow arrow1 = form1.fcHoverview.CreateArrow(pt1, pt2);
                Arrow arrow2 = form1.fcHoverview.CreateArrow(pt2, anchorPointPos);
                arrow1.ArrowHead = ArrowHead.Triangle;
                arrow1.ArrowHeadSize = 2.0F;
                arrow1.FillColor = Color.Black;

                arrow2.PenColor = Color.Blue;
              }


              form1.fcHoverview.Selection.Clear();
            }

            foreach (EditorLink link in form1.hoverviewOutgoingLinks)
            {
              Arrow arrow = state.Arrow(link.Guid);

              int portId = 0;
              (editorNode.ModelBox.Tag as EditorNode).anchorTagToInt.TryGetValue(link.ModelLink.OriginPort + link.GraphicLink.OriginPortID.ToString(CultureInfo.InvariantCulture), out portId);

              if (form1.hoverviewBox.AnchorPattern.Points.Count > portId)
              {
                PointF anchorPointPos = FrmFlowChart.GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(form1.hoverviewBox.BoundingRect),
                                form1.hoverviewBox.AnchorPattern.Points[portId].X,
                                form1.hoverviewBox.AnchorPattern.Points[portId].Y,
                                form1.hoverviewBox.RotationAngle).ToPointF();

                PointF pt1 = Flowchart2Hoverbox(link.Arrow.Origin.BoundingRect,
                                   form1.hoverviewBox.BoundingRect,
                                   arrow.ControlPoints[1]);
                PointF pt2 = Flowchart2Hoverbox(link.Arrow.Origin.BoundingRect,
                                   form1.hoverviewBox.BoundingRect,
                                   arrow.ControlPoints[0]);

                ///Box box1 = form1.fcHoverview.CreateBox(pt1.X*2.0F, pt1.Y, 0.001F, 0.01F);
                //box1.Visible = false;
                //box1.FillColor = System.Drawing.Color.FromArgb(20, 222, 184, 136);
                //box1.FrameColor = System.Drawing.Color.FromArgb(25, 111, 92, 68);
                //Box box2 = form1.fcHoverview.CreateBox(pt2.X, pt2.Y, 0.001F, 0.01F);
                //box2.Visible = false;
                Arrow arrow1 = form1.fcHoverview.CreateArrow(pt2, pt1);
                Arrow arrow2 = form1.fcHoverview.CreateArrow(pt2, anchorPointPos);
                arrow1.ArrowHead = ArrowHead.Triangle;
                arrow1.ArrowHeadSize = 2.0F;
                arrow1.FillColor = Color.Black;

                arrow2.PenColor = Color.Blue;
              }
              form1.fcHoverview.Selection.Clear();
            }

            RectangleF zoomRect = form1.hoverviewBox.BoundingRect;
            zoomRect.Inflate(form1.hoverviewBox.BoundingRect.Width * 0.4F, form1.hoverviewBox.BoundingRect.Height * 0.4F);
            form1.fcHoverview.ZoomToRect(zoomRect);
          }
        }
      }

      if ((hoverNode != null) && (hoverNode.ModelBox != null) && (hoverNode.ModelBox.AnchorPattern != null))
      {
        int closestI = 0;
        Double closestDistance = Double.MaxValue;

        for (int i = 0; i < hoverNode.ModelBox.AnchorPattern.Points.Count; i++)
        {

          if (hoverNode.ModelBox.AnchorPattern.Points[i].AllowOutgoing)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(hoverNode.ModelBox.BoundingRect),
              hoverNode.ModelBox.AnchorPattern.Points[i].X,
              hoverNode.ModelBox.AnchorPattern.Points[i].Y,
              hoverNode.ModelBox.RotationAngle);
            Double thisDistance = Distance(new SysCAD.Protocol.Point(fcFlowChart.ClientToDoc(new System.Drawing.Point(e.X, e.Y))), anchorPointPos);

            if (thisDistance < closestDistance)
            {
              closestDistance = thisDistance;
              closestI = i;
            }
          }
        }

        String hoverTag = hoverNode.Tag;
        int hoverAnchor = closestI;

        String anchorString;
        hoverNode.anchorIntToTag.TryGetValue(hoverAnchor, out anchorString);

        if (anchorString != null)
        {
          form1.ToolStripStatusLabel.Text = "Item: " + hoverTag +
  " : " + " Port: " + anchorString.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
        }
      }

      if (oldHoverLink != null)
        if (oldHoverLink != hoverLink) // we've moved on, un-hover the old one.
          oldHoverLink.Hovered = false;

      if (oldHoverNode != null) // deal with old itemBox.
        if (oldHoverNode != hoverNode) // we've moved on, un-hover the old one.
          oldHoverNode.Hovered = false;

      if (hoverLink != null)
        hoverLink.Hovered = true;

      if (hoverNode != null)
        hoverNode.Hovered = true;

      oldHoverLink = hoverLink;
      oldHoverNode = hoverNode;
    }