예제 #1
0
파일: Form1.cs 프로젝트: ChrisMoreton/Test3
    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);
    }
예제 #2
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);
        }
      }

    }
예제 #3
0
파일: Form1.cs 프로젝트: ChrisMoreton/Test3
    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);
    }
예제 #4
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);
          }
        }
      }
    }