예제 #1
0
파일: Form1.cs 프로젝트: 15831944/Test3-1
        private void flowChart1_BoxModified(object sender, BoxMouseArgs e)
        {
            if (e.Box.Tag is Arc)
            {
                Arc arc = e.Box.Tag as Arc;
                arc.x = GridUnfix(e.Box.BoundingRect.X);
                arc.y = GridUnfix(e.Box.BoundingRect.Y);
                arc.w = e.Box.BoundingRect.Width;
                arc.h = e.Box.BoundingRect.Height;
            }
            else if (e.Box.Tag is SysCAD.Protocol.Point)
            {
                SysCAD.Protocol.Point point = e.Box.Tag as SysCAD.Protocol.Point;
                point.X = GridUnfix(e.Box.BoundingRect.X + 1.0F);
                point.Y = GridUnfix(e.Box.BoundingRect.Y + 1.0F);
            }

            SetStencil(modelStencil);
        }
예제 #2
0
파일: State.cs 프로젝트: ChrisMoreton/Test3
    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
    private void fcFlowChart_ArrowCreating(object sender, AttachConfirmArgs e)
    {
      SysCAD.Protocol.Point originPos = new SysCAD.Protocol.Point(e.Arrow.ControlPoints[0]);
      Box originBox = fcFlowChart.GetBoxAt(originPos.ToPointF(), 2.0F);

      originBox = (originBox.Tag as EditorNode).ModelBox;

      if (originBox != null)
      {
        int closestI = 0;
        Double closestDistance = Double.MaxValue;

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

          if (originBox.AnchorPattern.Points[i].AllowOutgoing)
          {
            SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(originBox.BoundingRect),
              originBox.AnchorPattern.Points[i].X,
              originBox.AnchorPattern.Points[i].Y,
              originBox.RotationAngle);

            Double thisDistance = Distance(originPos, anchorPointPos);

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

        newOriginGuid = (originBox.Tag as EditorNode).Guid;
        newOriginTag = (originBox.Tag as EditorNode).Tag;
        newOriginBox = originBox;

        newOriginAnchor = closestI;
      }

      DoArrowModifyingOperations(e.Arrow, e.Arrow.ControlPoints.Count - 1);
      //arrowBeingModified = e.Arrow;
      //arrowBeingModified.CustomDraw = CustomDraw.Additional;
      //arrowBeingModified.ZTop();
      //fcFlowChart.RecreateCacheImage();
    }
예제 #4
0
    private void DoArrowModifyingOperations(Arrow arrow, int selectionHandle)
    {
      oldControlPoints = State.GetControlPoints(arrow.ControlPoints);

      arrowBeingModifiedSelectionHandle = selectionHandle;
      arrowBeingModified = arrow;
      //arrowBeingModified.CustomDraw = CustomDraw.Additional;
      arrowBeingModified.ZTop();

      if (arrow.Tag != null)
        oldOriginGuid = (arrow.Tag as EditorLink).GraphicLink.Origin;
      else
        oldOriginGuid = Guid.Empty;

      oldOriginBox = arrow.Origin as Box;
      oldOriginAnchor = arrow.OrgnAnchor;

      if (arrow.Tag != null)
        oldDestinationGuid = (arrow.Tag as EditorLink).GraphicLink.Destination;
      else
        oldDestinationGuid = Guid.Empty;

      oldDestinationBox = arrow.Destination as Box;
      oldDestinationAnchor = arrow.DestAnchor;

      if (state.Permissions.Modify)
      {
        if (arrowBeingModifiedSelectionHandle == 0)
        {
          SysCAD.Protocol.Point originPos = new SysCAD.Protocol.Point(arrowBeingModified.ControlPoints[0]);
          Box originBox = fcFlowChart.GetBoxAt(originPos.ToPointF(), 2.0F);

          if ((selectionHandle == 0) && (originBox != null) && (!(arrowBeingModified.Origin is Box)))
          {
            originBox = (originBox.Tag as EditorNode).ModelBox;

            if (originBox != null)
            {
              int closestI = 0;
              Double closestDistance = Double.MaxValue;

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

                if (originBox.AnchorPattern.Points[i].AllowOutgoing)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(originBox.BoundingRect),
                    originBox.AnchorPattern.Points[i].X,
                    originBox.AnchorPattern.Points[i].Y,
                    originBox.RotationAngle);
                  Double thisDistance = Distance(originPos, anchorPointPos);

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

              newOriginGuid = (originBox.Tag as EditorNode).Guid;
              newOriginTag = (originBox.Tag as EditorNode).Tag;
              newOriginBox = originBox;
              newOriginAnchor = closestI;

              String anchorString;
              (newOriginBox.Tag as EditorNode).anchorIntToTag.TryGetValue(newOriginAnchor, out anchorString);

              if (anchorString != null)
              {
                form1.ToolStripStatusLabel.Text = "Origin Item: " + newOriginTag +
      " : " + " Oritin Port: " + anchorString.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
              }
            }
          }
        }
        //else if (oldOriginBox != null)
        //{
        //  (e.Arrow.Tag as Link).graphicLink.Origin = oldOriginGuid;
        //  e.Arrow.Origin = oldOriginBox;
        //  e.Arrow.OrgnAnchor = oldOriginAnchor;
        //}

        if (selectionHandle == arrowBeingModified.ControlPoints.Count - 1)
        {
          SysCAD.Protocol.Point destinationPos = new SysCAD.Protocol.Point(arrowBeingModified.ControlPoints[arrowBeingModified.ControlPoints.Count - 1]);
          Box destinationBox = fcFlowChart.GetBoxAt(destinationPos.ToPointF(), 2.0F);

          if ((destinationBox != null) && (destinationBox.Tag != null) && (!(arrowBeingModified.Destination is Box)))
          {
            destinationBox = (destinationBox.Tag as EditorNode).ModelBox;

            if (destinationBox != null)
            {
              int closestI = 0;
              Double closestDistance = Double.MaxValue;

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

                if (destinationBox.AnchorPattern.Points[i].AllowIncoming)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(destinationBox.BoundingRect),
                    destinationBox.AnchorPattern.Points[i].X,
                    destinationBox.AnchorPattern.Points[i].Y,
                    destinationBox.RotationAngle);
                  Double thisDistance = Distance(destinationPos, anchorPointPos);

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

              newDestinationGuid = (destinationBox.Tag as EditorNode).Guid;
              newDestinationTag = (destinationBox.Tag as EditorNode).Tag;
              newDestinationBox = destinationBox;
              newDestinationAnchor = closestI;

              String anchorString;
              (newDestinationBox.Tag as EditorNode).anchorIntToTag.TryGetValue(newDestinationAnchor, out anchorString);

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

      if ((newOriginBox != null) && (newDestinationBox != null) && (newOriginBox == newDestinationBox)) // refliexive, disconnect modifying end.
      {

        if (selectionHandle == 0)
        {
          newOriginGuid = Guid.Empty;
          newOriginTag = String.Empty;
          newOriginBox = null;
          newOriginAnchor = -1;

          form1.ToolStripStatusLabel.Text = "";
        }

        if (selectionHandle == arrowBeingModified.ControlPoints.Count - 1)
        {
          newDestinationGuid = Guid.Empty;
          newDestinationTag = String.Empty;
          newDestinationBox = null;
          newDestinationAnchor = -1;

          form1.ToolStripStatusLabel.Text = "";
        }
      }

      fcFlowChart.RecreateCacheImage();
    }
예제 #5
0
    static public SysCAD.Protocol.Point GetRelativeAnchorPosition(SysCAD.Protocol.Rectangle nodeRect, Double x, Double y, Double angle)
    {
      SysCAD.Protocol.Point point = new SysCAD.Protocol.Point(nodeRect.X + nodeRect.Width * x / 100.0, nodeRect.Y + nodeRect.Height * y / 100.0);

      if (angle != 0)
      {
        point = rotatePointAt(point, getCenter(nodeRect), angle);
      }
      return point;
    }
예제 #6
0
    private void fcFlowChart_DrawBox(object sender, BoxDrawArgs e)
    {
      if (arrowBeingModified != null)
      {
        SysCAD.Protocol.Point originPos = new SysCAD.Protocol.Point(arrowBeingModified.ControlPoints[0]);
        Box originBox = fcFlowChart.GetBoxAt(originPos.ToPointF(), 2.0F);

        if (originBox != null)
        {
          originBox = (originBox.Tag as EditorNode).ModelBox;

          if (originBox != null)
          {

            if (originBox.AnchorPattern != null)
            {
              //if (originAnchorChosen == null)
              {
                Double closest = Double.MaxValue;

                foreach (AnchorPoint anchorPoint in originBox.AnchorPattern.Points)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(originBox.BoundingRect),
                    anchorPoint.X,
                    anchorPoint.Y,
                    originBox.RotationAngle);

                  Double distance = Distance(anchorPointPos, originPos);

                  if (distance < closest)
                  {
                    closest = distance;
                    originAnchorChosen = anchorPoint.Tag as Anchor;
                  }
                }

                // if (state.PortCheck(out requestId, (originBox.Tag as Item).Guid, originAnchorChosen) == PortStatus.Available)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(originBox.BoundingRect),
                    (originAnchorChosen.Positions[0] as SysCAD.Protocol.Point).X,
                    (originAnchorChosen.Positions[0] as SysCAD.Protocol.Point).Y,
                    originBox.RotationAngle);

                  PointF[] extensionPoints =
                    new PointF[] { anchorPointPos.ToPointF(), anchorPointPos.ToPointF() };
                  System.Drawing.Pen pen = new System.Drawing.Pen(Color.Yellow, fcFlowChart.SelHandleSize);
                  e.Graphics.DrawEllipse(pen, RectangleF.FromLTRB(
                    anchorPointPos.ToPointF().X - fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().Y - fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().X + fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().Y + fcFlowChart.SelHandleSize));
                  e.Graphics.DrawLines(pen, extensionPoints);
                }
              }
            }
          }
        }

        SysCAD.Protocol.Point destinationPos = new SysCAD.Protocol.Point(arrowBeingModified.ControlPoints[arrowBeingModified.ControlPoints.Count - 1]);
        Box destinationBox = fcFlowChart.GetBoxAt(destinationPos.ToPointF(), 2.0F);

        if (destinationBox != null)
        {
          destinationBox = (destinationBox.Tag as EditorNode).ModelBox;

          if (destinationBox != null)
          {

            if (destinationBox.AnchorPattern != null)
            {
              if (destinationAnchorChosen != null)
              {
                Double closest = Double.MaxValue;

                foreach (AnchorPoint anchorPoint in destinationBox.AnchorPattern.Points)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(destinationBox.BoundingRect),
                    anchorPoint.X,
                    anchorPoint.Y,
                    destinationBox.RotationAngle);

                  Double distance = Distance(anchorPointPos, destinationPos);

                  if (distance < closest)
                  {
                    closest = distance;
                    destinationAnchorChosen = anchorPoint.Tag as Anchor;
                  }
                }

                //if (state.PortCheck(out requestId, (destinationBox.Tag as Item).Guid, destinationAnchorChosen) == PortStatus.Available)
                {
                  SysCAD.Protocol.Point anchorPointPos = GetRelativeAnchorPosition(new SysCAD.Protocol.Rectangle(destinationBox.BoundingRect),
                    (destinationAnchorChosen.Positions[0] as SysCAD.Protocol.Point).X,
                    (destinationAnchorChosen.Positions[0] as SysCAD.Protocol.Point).Y,
                    destinationBox.RotationAngle);

                  PointF[] extensionPoints =
                    new PointF[] { anchorPointPos.ToPointF(), anchorPointPos.ToPointF() };
                  System.Drawing.Pen pen = new System.Drawing.Pen(Color.Yellow, fcFlowChart.SelHandleSize);
                  e.Graphics.DrawEllipse(pen, RectangleF.FromLTRB(
                    anchorPointPos.ToPointF().X - fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().Y - fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().X + fcFlowChart.SelHandleSize,
                    anchorPointPos.ToPointF().Y + fcFlowChart.SelHandleSize));
                  e.Graphics.DrawLines(pen, extensionPoints);
                }

              }
            }
          }
        }
      }
    }