Beispiel #1
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();
    }
Beispiel #2
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();
    }
Beispiel #3
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);
                }

              }
            }
          }
        }
      }
    }