Beispiel #1
0
 bool ValidAnchor(Anchor anchor)
 {
   // TODO: Check here if anchor.Tag is to be included. (and possibly in future anchor.Type)
   return true;
 }
Beispiel #2
0
 private void GenerateAnchor(Anchor anchor, SysCAD.Protocol.Size defaultSize)
 {
   tempText += "MDrw_Anchor ";
   tempText += anchor.Tag + ", ";
   tempText += ((anchor.Positions[0] as SysCAD.Protocol.Point).X / 100.0F * defaultSize.Width).ToString() +
     ", "
     + ((anchor.Positions[0] as SysCAD.Protocol.Point).Y / 100.0F * defaultSize.Height).ToString() + "\r\n";
 }
Beispiel #3
0
 PortStatus PortCheck(ServiceProtocol serviceProtocol, Guid guid, Anchor anchor)
 {
   //		CNSGuidItem * pGuid = new CNSGuidItem();
   //		pGuid.m_Guid = guid;
   //		m_pUnmanaged.m_Guids.AddTail(null);
   //		CNSGuidItem * pGuid = m_pUnmanaged.m_Guids.Find(guid);
   //		CNSMdlLink * pLink = dynamic_cast<CNSMdlLink *>(guid);
   return PortStatus.Available;
 }
Beispiel #4
0
    private bool ParseAnchor(string atom, ArrayList arrayList)
    {
      atom = atom.Remove(0, 6);
      string[] atoms = atom.Split(charSplitArray, StringSplitOptions.RemoveEmptyEntries);

      if (atoms.Length != 3)
      {
        toolStripStatusLabel1.Text = "Incorrect number of parameters (tag, x, y): " + atom;
        toolStripStatusLabel1.BackColor = Color.Yellow;
        return false;
      }

      try
      {
        string tag = atoms[0];
        AnchorType type = AnchorType.Process;

        double x = double.Parse(atoms[1]);
        double y = double.Parse(atoms[2]);

        Anchor anchor = new Anchor(tag, type, 0, x, y);

        arrayList.Add(anchor);
      }
      catch
      {
        toolStripStatusLabel1.Text = "Error parsing parameters (tag, x, y): " + atom;
        toolStripStatusLabel1.BackColor = Color.Yellow;
        return false;
      }

      return true;
    }
Beispiel #5
0
    private void editPropertiesToolStripMenuItem_Click(object sender, EventArgs e)
    {
      EditProperties editProperties = new EditProperties();
      editProperties.group = modelStencil.Groups[0] as string;
      editProperties.tag = modelStencil.Tag;
      editProperties.anchors = modelStencil.Anchors;

      if (editProperties.ShowDialog() == DialogResult.OK)
      {
        modelStencil.Groups[0] = editProperties.group;
        modelStencil.Tag = editProperties.tag;

        ArrayList newAnchors = new ArrayList();
        foreach (Anchor anchor in modelStencil.Anchors)
        {
          if (editProperties.listView1.Items.ContainsKey(anchor.Tag))
          {
            newAnchors.Add(anchor);
          }
        }
        modelStencil.Anchors = newAnchors;

        foreach (ListViewItem listViewItem in editProperties.listView1.Items)
        {
          bool anchorFound = false;

          foreach (Anchor anchor in modelStencil.Anchors)
          {
            if (anchor.Tag == listViewItem.Text)
            {
              anchorFound = true;
              anchor.Look = (short)editProperties.listView1.Groups.IndexOf(listViewItem.Group);
            }
          }

          if (!anchorFound)
          {
            Anchor newAnchor = new Anchor(listViewItem.Text, AnchorType.Process,
                (short)editProperties.listView1.Groups.IndexOf(listViewItem.Group));
            modelStencil.Anchors.Add(newAnchor);
            newAnchor.Positions = new ArrayList();
          }
        }
      }

      ResetFlowChart(true);
      SetStencil(modelStencil);
      SetControls(modelStencil);
    }
Beispiel #6
0
    private void fcFlowChart_ArrowModified(object sender, ArrowMouseArgs e)
    {
      {
        int i = 2;

        while ((oldControlPoints.Count > 3) && (i < oldControlPoints.Count - 1))
        {

          if (MergePoints(oldControlPoints[i - 1], oldControlPoints[i]))
          {
            oldControlPoints.RemoveAt(i - 1);
            oldControlPoints.RemoveAt(i - 1);

            // Deal with the adjacent points being slightly out of algnment.
            if (Math.Abs(oldControlPoints[i - 1].X - oldControlPoints[i - 2].X) < Math.Abs(oldControlPoints[i - 1].Y - oldControlPoints[i - 2].Y))
            {
              oldControlPoints[i - 1].X = oldControlPoints[i - 2].X;
            }
            else
            {
              oldControlPoints[i - 1].Y = oldControlPoints[i - 2].Y;
            }
            i = 2;
          }

          else
          {
            i++;
          }
        }
      }

      if (MergePoints(oldControlPoints[0], oldControlPoints[1]))
      {
        oldControlPoints.RemoveAt(0);

        if (e.Arrow.CascadeOrientation == MindFusion.FlowChartX.Orientation.Horizontal)
          e.Arrow.CascadeOrientation = MindFusion.FlowChartX.Orientation.Vertical;

        else
          e.Arrow.CascadeOrientation = MindFusion.FlowChartX.Orientation.Horizontal;
      }

      if (MergePoints(oldControlPoints[oldControlPoints.Count - 1], oldControlPoints[oldControlPoints.Count - 2]))
      {
        oldControlPoints.RemoveAt(oldControlPoints.Count - 1);
      }

      form1.ToolStripStatusLabel.Text = "";

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

      GraphicLink graphicLink = (e.Arrow.Tag as EditorLink).GraphicLink as GraphicLink;

      if (oldOriginBox != null)
      {
        (e.Arrow.Tag as EditorLink).GraphicLink.Origin = oldOriginGuid;
        e.Arrow.Origin = oldOriginBox;
        e.Arrow.OrgnAnchor = oldOriginAnchor;
      }

      else if (newOriginBox != null)
      {
        (e.Arrow.Tag as EditorLink).GraphicLink.Origin = newOriginGuid;
        e.Arrow.Origin = newOriginBox;
        e.Arrow.OrgnAnchor = newOriginAnchor;
      }

      if (oldDestinationBox != null)
      {
        (e.Arrow.Tag as EditorLink).GraphicLink.Destination = oldDestinationGuid;
        e.Arrow.Destination = oldDestinationBox;
        e.Arrow.DestAnchor = oldDestinationAnchor;
      }

      else if (newDestinationBox != null)
      {
        (e.Arrow.Tag as EditorLink).GraphicLink.Destination = newDestinationGuid;
        e.Arrow.Destination = newDestinationBox;
        e.Arrow.DestAnchor = newDestinationAnchor;
      }

      State.SetControlPoints(e.Arrow, oldControlPoints);

      EditorNode originItem = e.Arrow.Origin.Tag as EditorNode;
      EditorNode destinationItem = e.Arrow.Destination.Tag as EditorNode;

      //Guid originGuid = Guid.Empty;
      //Guid destinationGuid = Guid.Empty;

      //if (originItem != null)
      //  originGuid = originItem.Guid;

      //if (destinationItem != null)
      //  destinationGuid = destinationItem.Guid;

      String originFullAnchor = null;
      String destinationFullAnchor = null;
      String originAnchorName = null;
      String destinationAnchorName = null;

      originItem.anchorIntToTag.TryGetValue(e.Arrow.OrgnAnchor, out originFullAnchor);

      if (originFullAnchor != null)
      {
        originAnchorName = originFullAnchor.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
        graphicLink.OriginPortID = Convert.ToInt16(originFullAnchor.Substring(originAnchorName.Length), CultureInfo.InvariantCulture);
      }

      destinationItem.anchorIntToTag.TryGetValue(e.Arrow.DestAnchor, out destinationFullAnchor);

      if (destinationFullAnchor != null)
      {
        destinationAnchorName = destinationFullAnchor.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
        graphicLink.DestinationPortID = Convert.ToInt16(destinationFullAnchor.Substring(destinationAnchorName.Length), CultureInfo.InvariantCulture);
      }

      SysCAD.Protocol.Action action = new SysCAD.Protocol.Action();
      if (graphicLink != null)
      {
        GraphicLink newGraphicLink = graphicLink.Clone();
        newGraphicLink.ControlPoints = State.GetControlPoints(e.Arrow.ControlPoints);
        action.Modify.Add(newGraphicLink);
      }


      AddAction(action);

      //if (!state.ModifyGraphicLink(out requestId,
      //  graphicLink.Guid,
      //  graphicLink.Tag,
      //  originGuid,
      //  destinationGuid,
      //  originAnchorName,
      //  originAnchorID,
      //  destinationAnchorName,
      //  destinationAnchorID,
      //  oldControlPoints,
      //  graphicLink.TagArea,
      //  graphicLink.TagAngle))
      //{ // failure, revert back to previous.
      //  // do something here...
      //}

      oldOriginGuid = Guid.Empty;
      oldOriginBox = null;
      oldOriginAnchor = -1;

      oldDestinationGuid = Guid.Empty;
      oldDestinationBox = null;
      oldDestinationAnchor = -1;

      newOriginGuid = Guid.Empty;
      newOriginTag = String.Empty;
      newOriginBox = null;
      newOriginAnchor = -1;

      newDestinationGuid = Guid.Empty;
      newDestinationTag = String.Empty;
      newDestinationBox = null;
      newDestinationAnchor = -1;
    }
Beispiel #7
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);
    }
Beispiel #8
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);
                }

              }
            }
          }
        }
      }
    }