My Project
shapeLib.cs
查看本檔案說明文件.
1 using ShapeLib.VShape;
2 using System;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows;
10 using System.Windows.Controls;
11 using System.Windows.Forms;
12 using System.Xml;
13 using System.Xml.Serialization;
14 
15 
16 namespace ShapeLib.VShape
17 {
18 
19  static public class shapeLib
20  {
26 
27  static public IList<ShapeObj> SupportedShape(getForm myview)
28  {
29  if (myview != null)
30  Data.view = myview;
31 
32 
33  return ret;
34  }
35 
36  //static public void initControl(Canvas grid ,Canvas control)
37  //{
38  // Data.mygrid = grid;
39  // Data.myControl = control;
40  //}
41 
42  static public GModel Data = new GModel();
43  static IList<ShapeObj> ret = new[] { new ShapeObj(), new ShapeCircle(), new ShapeRectangle(), new ShapeCurve(), new ShapeTriangle(), new ShaperightTriangle(), new ShapeArrow(), new ShapeText(), new ShapePencil(), new Sproerty() };
44 
45  /* static public void InsertText(String txt)
46  {
47  if (shapeLib.Data.currShape != null)
48  {
49  shapeLib.Data.currShape.Text += txt;
50  shapeLib.Data.currShape.redraw(1);
51 
52  }
53 
54  }*/
55  static public void copy()
56  {
57  // gPath tp = new gPath();
58 
59  // tp.copyVal(shapeLib.Data.gdc.sroot.PathList[ru.Sel]);
60  if (Data.multiSelList.Count > 0)
61  {
62 
63  using (MemoryStream stream = new MemoryStream())
64  {
65  XmlSerializer s = new XmlSerializer(typeof(List<gPath>));
66 
67 
68  s.Serialize(XmlWriter.Create(stream), Data.multiSelList);
69 
70  stream.Flush();
71  stream.Seek(0, SeekOrigin.Begin);
72 
73  StreamReader sr = new StreamReader(stream);
74  string myStr = sr.ReadToEnd();
75 
76  System.Windows.Clipboard.SetText(myStr);
77  shiftPos = 0;
78  }
79  }
80  }
81 
82  static int shiftPos =0;
83  static public void paste()
84  {
85  String str = System.Windows.Clipboard.GetText();
86 
87  shiftPos += 30;
88  XmlSerializer serializer = new XmlSerializer(typeof(List<gPath>));
89  using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(str)))
90  {
91  List<gPath> tpList = (List< gPath>) serializer.Deserialize(XmlReader.Create(ms));
92  foreach (gPath tp in tpList)
93  {
95  if (shapeLib.Data.gdc.checkWhich(tp) != -1)
96  {
97  tp.controlBtn1 = new Point(tp.controlBtn1.X + shiftPos, tp.controlBtn1.Y + shiftPos);
98  tp.controlBtn2 = new Point(tp.controlBtn2.X + shiftPos, tp.controlBtn2.Y + shiftPos);
99  tp.controlBtn3 = new Point(tp.controlBtn3.X + shiftPos, tp.controlBtn3.Y + shiftPos);
100  tp.controlBtn4 = new Point(tp.controlBtn4.X + shiftPos, tp.controlBtn4.Y + shiftPos);
101  }
102  tp.redraw(1);
103 
104  shapeLib.Data.gdc.writeIn(tp, 0);
106  }
107  // reDraw(true);
108  }
109 
110  }
111 
112  }
113 
114  public class GModel
115  {
116  public getForm view;
117  public int lineSpace = 9;
118  public int UItype = 1;
119  public String colortype = "black";
120  public GraphDoc gdc = new GraphDoc();
121  public Canvas mygrid;
122  public System.Windows.Controls.UserControl Root;
123  // public Canvas myControl;
124 
125  public checkHitDraw chd = new checkHitDraw();
126  public RUse ru = new RUse();
127  public gPoint gp;
128  //public System.Windows.Forms.Panel panel1;
129  // public gPath tempFPath;
130  public byte colorR = 0;
131  public byte colorG = 0;
132  public byte colorB = 0;
133  public int strokeT = 3;
134 
135 
136  public String Status = "rest"; //繪製曲線時的狀態
137  public Point pStart, pEnd; //滑鼠起點和終點
138  public Point tempStart;
139 
140  public bool bfirst = true; //是否為繪製新圖形
141  public bool bCanMove = false; //繪製時,滑鼠是否可以移動
142  public bool bhave = false; //you have choose
143  public bool gCanMove = false; //選取後是否可以移動
144  public bool bConThing = false; //是否有選取物件
145  public bool OnIt = false; //是否有滑入或滑出選取物件
146  public int mClick = 0;
147  public gPath currShape;
148  public List<gPath> multiSelList = new List<gPath>();
149  }
150 }
static GModel Data
Definition: shapeLib.cs:42
List< gPath > multiSelList
Definition: shapeLib.cs:148
checkHitDraw chd
Definition: shapeLib.cs:125
System.Windows.Point controlBtn3
Definition: GraphDoc.cs:255
List< gPath > PathList
Definition: GraphDoc.cs:30
void writeIn(gPath Data, int Action)
維護 undo stack ,把目前狀態存起來.並清空redo stack,如果之前有undo 動作,是回覆到某一狀態,在此之後的動作都可清除
Definition: GraphDoc.cs:96
System.Windows.Point controlBtn4
Definition: GraphDoc.cs:256
某一類的形狀.包含UI 的界面,繪製方式.更新方式.新增方式
Definition: ShapeObj.cs:59
System.Windows.Point controlBtn2
Definition: GraphDoc.cs:254
static void copy()
Definition: shapeLib.cs:55
void redraw(int removetype)
Definition: GraphDoc.cs:286
記錄shape list,action data stack 記錄動作,每個動作(pointAry)包含,該圖是圖形的第幾個(Listplace),之前記錄是否己有相同圖是第幾個,...
Definition: GraphDoc.cs:37
static IList< ShapeObj > SupportedShape(getForm myview)
define supported shape
Definition: shapeLib.cs:27
static IList< ShapeObj > ret
Definition: shapeLib.cs:43
System.Windows.Point controlBtn1
Definition: GraphDoc.cs:253
System.Windows.Controls.UserControl Root
Definition: shapeLib.cs:122
int checkWhich(gPath gp)
Definition: GraphDoc.cs:50
static void paste()
Definition: shapeLib.cs:83
delegate IForm getForm()