Exemplo n.º 1
0
 private void btDeleteShape_Click(object sender, EventArgs e) {
     Core.ElementEnumerator<Core.ShapeInterface> Iterator = GetModel().GetSelectedShapes();
     Core.CmdMacro Cmd = new Core.CmdMacro();
     int i = 0;
     while (Iterator.MoveNext()) {
         Cmd.AddCmd(new Core.CmdDeleteShape(GetModel(), Iterator.Current));
         i++;
         //Iterator = GetDiagram().GetSelectedShapes();
     }
     if (i != 0) GetModel().GetUndoStack().Push(Cmd);
 }
Exemplo n.º 2
0
 private void btPasteShape_Click(object sender, EventArgs e) {
     ToolStripItem contextMenuItem = (ToolStripItem)sender;
     System.Drawing.Point NewPos, Ctxtpos;
     if (contextMenuItem.Tag is System.Drawing.Point) {
         Ctxtpos = (System.Drawing.Point)contextMenuItem.Tag;  //Location is stored as point in tag
     } else {
         Ctxtpos = new System.Drawing.Point(0, 0);
     }
     System.Drawing.Size PosOffset = System.Drawing.Size.Empty;
     IDataObject Data = Clipboard.GetDataObject();
     ShapeInterface Shape = null;
     Core.CmdMacro Cmd = new Core.CmdMacro();
     String[] Formats = Data.GetFormats(false);
     // Determines whether the data is in a format you can use.
     if (Data.GetDataPresent("stream")) {
         //string test = Data.GetData(DataFormats.Text).ToString();
         SerializerXML _Stream = new SerializerXML("JKFLOW", "1.0.0.0");
         MemoryStream _MemStream = new MemoryStream((byte[])Data.GetData("stream"));
         _Stream.OpenInputStream(_MemStream);
         string NodeGroup;
         int StartNodeLevel = 0, CurrNodeLevel = 0;
         do {
             NodeGroup = _Stream.GetNodeName();
             CurrNodeLevel = _Stream.GetNodeLevel();
             if (CurrNodeLevel < StartNodeLevel) { break; }
             if (_Stream.GetNodeType() != Core.SerializerBase.NodeType.NodeEnd) {
                 if (NodeGroup == "Shape") {
                     ShapeInterface SourceShape = ShapeFactory.DeserializeShape(_Stream);
                     if (PosOffset.IsEmpty) {
                         PosOffset.Width = Ctxtpos.X - SourceShape.GetBoundingBox().Location.X;
                         PosOffset.Height = Ctxtpos.Y - SourceShape.GetBoundingBox().Location.Y;
                     }
                     NewPos = SourceShape.GetBoundingBox().Location + PosOffset;
                     Shape = ShapeFactory.CreateShape(SourceShape.GetShapeTypeName());
                     Cmd.AddCmd(new Core.CmdAddShape(GetModel(),
                         Shape, NewPos, NewPos + SourceShape.GetBoundingBox().Size));
                 }
             }
         } while (_Stream.ReadNext());
         _Stream.CloseInputStream();
         _Stream = null;
         GetModel().GetUndoStack().Push(Cmd);
     }
 }
Exemplo n.º 3
0
 private void btCopyShape_Click(object sender, EventArgs e) {
     try {
         ToolStripItem contextMenuItem = (ToolStripItem)sender;
         Control contextMenu = (Control)contextMenuItem.GetCurrentParent();
         System.Drawing.Point Location = (contextMenu.Location);
         System.Drawing.Point PointA, PointB;
         Core.ElementEnumerator<Core.ShapeInterface> Iterator = GetModel().GetSelectedShapes();
         Core.CmdMacro Cmd = new Core.CmdMacro();
         List<ShapeInterface> Shapes = new List<ShapeInterface>();
         ShapeInterface Shape = null;
         DataObject _Data = new DataObject();
         int i = 0;
         SerializerXML _Stream = new SerializerXML("JKFLOW", "1.0.0.0");
         MemoryStream MemStream = new MemoryStream();
         _Stream.OpenOutputStream(MemStream);
         string Node = "Shape";
         while (Iterator.MoveNext()) {
             PointA = new System.Drawing.Point(Iterator.Current.GetBoundingBox().Left + 20, Iterator.Current.GetBoundingBox().Top + 20);
             PointB = new System.Drawing.Point(Iterator.Current.GetBoundingBox().Right + 20, Iterator.Current.GetBoundingBox().Bottom + 20);
             Shape = ShapeFactory.CreateShape(Iterator.Current.GetShapeTypeName());
             Shapes.Add(Shape);
             _Stream.WriteElementStart(Node);
             Iterator.Current.WriteToSerializer(_Stream);
             _Stream.WriteElementEnd(Node);
             Cmd.AddCmd(new Core.CmdAddShape(GetModel(), Shape, PointA, PointB));
             i++;
         }
         _Stream.CloseOutputStream();
         //if (i != 0) GetModel().GetUndoStack().Push(Cmd);
         _Data.SetData(DataFormats.Text, Cmd.GetText());
         _Data.SetData(Cmd.GetType(), Cmd);
         _Data.SetData("stream", MemStream.ToArray());
         Clipboard.SetDataObject(_Data);
     } catch (System.Runtime.InteropServices.ExternalException) {
         MessageBox.Show("The Clipboard could not be accessed. Please try again.");
     }
 }