Documentation
 All Classes Functions Variables Properties
TwoPointAnnotation.h
1 #include "Annotation.h"
2 #include "AnnotationPage.h"
3 using namespace System;
4 using namespace System::Collections::Generic;
5 using namespace System::Text;
6 using namespace System::Drawing;
7 using namespace System::Drawing::Drawing2D;
8 
9 namespace MST
10 {
11  namespace Imaging
12  {
13  namespace Annotations
14  {
15  public ref class TwoPointAnnotation abstract : public MSTAnnotation
16  {
17  public:
18  TwoPointAnnotation(Pen^ pen,MSTAnnotationPage^ page):MSTAnnotation(pen,page)
19  {
20  m_ptArr = gcnew array<PointF>(2);
21  m_ptArr[0] = PointF(0,0);
22  m_ptArr[1] = PointF(0,0);
23  }
24  };
25 
26  public ref class Line : public TwoPointAnnotation
27  {
28  public:
29  Line(Pen^ pen,MSTAnnotationPage^ page) : TwoPointAnnotation(pen,page){}
30  property Type AnnotationType
31  {
32  virtual Type get() override
33  {
34  return Annotations::Type::Line;
35  }
36  }
37  virtual bool IntersectsRect(System::Drawing::Rectangle rect)override
38  {
39  return IsLineIntersectsRect(m_ptArr,rect);
40  }
41  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
42  {
43  gp->AddLine(ptArr[0],ptArr[1]);
44  }
45  };
46 
47  public ref class Rectangle : public TwoPointAnnotation
48  {
49  public:
50  Rectangle(Pen^ pen,MSTAnnotationPage^ page) : TwoPointAnnotation(pen,page)
51  {
52  m_clrFill = Color::Transparent;
53  }
54  [CategoryAttribute("General"), DescriptionAttribute("Color to fill in annotation. [Format: RGB/ARGB]")]
55  property Color FillColor
56  {
57  virtual Color get()
58  {
59  return m_clrFill;
60  }
61  virtual void set(Color clr)
62  {
63  m_clrFill = clr;
64  }
65  }
66 
67  property Type AnnotationType
68  {
69  virtual Type get() override
70  {
71  return Annotations::Type::Rectangle;
72  }
73  }
74 
75  property PointF Points[Int16]
76  {
77  virtual PointF get(Int16 iIndex)override
78  {
79  if(iIndex < 0 || iIndex >= 4) throw gcnew System::ArgumentException("index out of bound");
80  return m_ptArr[iIndex];
81  }
82  virtual void set(Int16 iIndex,PointF Value)override
83  {
84  if(m_ptArr->Length < 4 && iIndex==0)
85  {
86  m_ptArr[0] = Value;
87  return;
88  }
89  if(m_ptArr->Length<4)Array::Resize(m_ptArr,4);
90  m_ptArr[iIndex] = Value;
91  Matrix^ mat = gcnew Matrix();
92  mat->Rotate(-m_pPage->Slope);
93  mat->TransformPoints(m_ptArr);
94  if(iIndex==0||iIndex==1)
95  {
96  m_ptArr[2].X = m_ptArr[1].X;
97  m_ptArr[2].Y = m_ptArr[0].Y;
98  m_ptArr[3].X = m_ptArr[0].X;
99  m_ptArr[3].Y = m_ptArr[1].Y;
100  }
101  else
102  {
103  m_ptArr[0].X = m_ptArr[3].X;
104  m_ptArr[0].Y = m_ptArr[2].Y;
105  m_ptArr[1].X = m_ptArr[2].X;
106  m_ptArr[1].Y = m_ptArr[3].Y;
107  }
108  mat->Reset();
109  mat->Rotate(m_pPage->Slope);
110  mat->TransformPoints(m_ptArr);
111  delete mat;
112  }
113  }
114  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
115  {
116  if(ptArr->Length<4)
117  {
118  gp->AddRectangle(System::Drawing::Rectangle(Math::Min(ptArr[0].X,ptArr[1].X),
119  Math::Min(ptArr[0].Y,ptArr[1].Y),
120  Math::Abs(ptArr[0].X-ptArr[1].X),
121  Math::Abs(ptArr[0].Y-ptArr[1].Y)));
122  }
123  else
124  {
125  gp->AddLine(ptArr[0],ptArr[2]);
126  gp->AddLine(ptArr[2],ptArr[1]);
127  gp->AddLine(ptArr[1],ptArr[3]);
128  gp->CloseFigure();
129  }
130 
131  }
132 
133  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override;
134 
135  virtual void Load(System::Xml::XmlElement^ element)override;
136  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
137  private:
138  Color m_clrFill;
139  };
140 
141 
142  public ref class Hilite : public Rectangle
143  {
144  public:
145  Hilite(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(gcnew Pen(Color::Transparent,1),page)
146  {
147  FillColor = Color::Gray;
148  }
149  [BrowsableAttribute(false)]
150  property Color FillColor
151  {
152  virtual Color get()override
153  {
154  return Color::FromArgb(128,__super::FillColor.R,__super::FillColor.G,__super::FillColor.B);
155  }
156  virtual void set(Color clr)override
157  {
158  __super::FillColor = clr;
159  }
160  }
161  [CategoryAttribute("General"), DescriptionAttribute("Hilite Color")]
162  property Color HiliteColor
163  {
164  virtual Color get()
165  {
166  return FillColor;
167  }
168  virtual void set(Color clr)
169  {
170  FillColor = clr;
171  }
172  }
173  [BrowsableAttribute(false)]
174  property Int32 BorderWidth
175  {
176  Int32 get()
177  {
178  return 0;
179  }
180  }
181  [BrowsableAttribute(false)]
182  property Color BorderColor
183  {
184  Color get()
185  {
186  return Color::Red;
187  }
188  }
189  property Type AnnotationType
190  {
191  virtual Type get() override
192  {
193  return Annotations::Type::Hilite;
194  }
195  }
196  };
197 
198  public ref class Arrow : public Line
199  {
200  public:
201  Arrow(Pen^ pen,MSTAnnotationPage^ page) : Line(pen,page)
202  {
203  m_pen->CustomStartCap = gcnew System::Drawing::Drawing2D::AdjustableArrowCap(5,8,true);
204  }
205 
206  property Type AnnotationType
207  {
208  virtual Type get() override
209  {
210  return Annotations::Type::Arrow;
211  }
212  }
213  };
214 
215  public ref class Ruler : public Line
216  {
217  public:
218  Ruler(Pen^ pen,MSTAnnotationPage^ page) : Line(pen,page)
219  {
220  m_bShowTick = true;
221  m_bShowRulerMeasurement = true;
222  }
223 
224  property Type AnnotationType
225  {
226  virtual Type get() override
227  {
228  return Annotations::Type::Ruler;
229  }
230  }
231 
232  property bool TickMarks
233  {
234  bool get(){return m_bShowTick;}
235  void set(bool value){m_bShowTick=value;}
236  }
237 
238  property bool RulerMeasurement
239  {
240  bool get(){return m_bShowRulerMeasurement;}
241  void set(bool value){m_bShowRulerMeasurement=value;}
242  }
243 
244  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
245  {
246  gp->AddLine(ptArr[0],ptArr[1]);
247  if(m_bShowTick)
248  {
249  gp->StartFigure();
250  Graphics^ g = Graphics::FromHwnd(IntPtr(0));
251  float cx = 2.54/g->DpiX;
252  float cy = 2.54/g->DpiY;
253  delete g;
254  array<PointF>^ normalPts = GetNormalPoints();
255  DrawScale(gp,ptArr[0],ptArr[1],getdistance(normalPts[0],normalPts[1],cx,cy));
256  double dx = System::Convert::ToDouble( ptArr[0].X- ptArr[1].X);
257  double dy = System::Convert::ToDouble( ptArr[0].Y- ptArr[1].Y);
258  dx /= System::Math::Sqrt(System::Math::Pow(ptArr[0].X- ptArr[1].X, 2) + System::Math::Pow(ptArr[0].Y-ptArr[1].Y, 2));
259  dy /= System::Math::Sqrt(System::Math::Pow(ptArr[0].X- ptArr[1].X, 2) + System::Math::Pow(ptArr[0].Y-ptArr[1].Y, 2));
260  gp->AddLine((float)(ptArr[1].X + 12*dy),(float)(ptArr[1].Y - 12*dx),(float)(ptArr[1].X - 12*dy),(float)(ptArr[1].Y + 12*dx));
261  }
262  }
263  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection) override;
268  virtual void Load(XmlElement^ element)override;
269 
275  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
276  protected:
277  bool m_bShowTick;
278  bool m_bShowRulerMeasurement;
279  };
280 
281  public ref class CrossProduct: public TwoPointAnnotation
282  {
283  public:
284  CrossProduct(Pen^ pen,MSTAnnotationPage^ page) : TwoPointAnnotation(pen,page)
285  {
286  m_bShowTick = true;
287  m_bShowRulerMeasurement = true;
288  }
289  property Type AnnotationType
290  {
291  virtual Type get() override
292  {
293  return Annotations::Type::CrossProduct;
294  }
295  }
296  property Int16 PointsCount
297  {
298  virtual Int16 get()override{return 4;}
299  }
300 
301  property array<PointF>^ Points
302  {
303  virtual array<PointF>^ get()override
304  {
305  if(m_ptArr->Length==4)
306  return m_ptArr;
307  else
308  {
309  array<PointF>^ newArr = (array<PointF>^)m_ptArr->Clone();
310  Array::Resize(newArr,4);
311  double dx = System::Convert::ToDouble( newArr[0].X- newArr[1].X);
312  double dy = System::Convert::ToDouble( newArr[0].Y- newArr[1].Y);
313 
314  dx /= System::Math::Sqrt(System::Math::Pow(newArr[0].X- newArr[1].X, 2) + System::Math::Pow(newArr[0].Y-newArr[1].Y, 2));
315  dy /= System::Math::Sqrt(System::Math::Pow(newArr[0].X- newArr[1].X, 2) + System::Math::Pow(newArr[0].Y-newArr[1].Y, 2));
316  double distance = getdistance(newArr[0],newArr[1],1,1)/2;
317  PointF pt((newArr[0].X+newArr[1].X)/2,(newArr[0].Y+newArr[1].Y)/2);
318  newArr[2]=PointF((float)(pt.X + distance*dy),(float)(pt.Y - distance*dx));
319  newArr[3]=PointF((float)(pt.X - distance*dy),(float)(pt.Y + distance*dx));
320  return newArr;
321  }
322  }
323  }
324  property PointF Points[Int16]
325  {
326  virtual PointF get(Int16 iIndex)override
327  {
328  if(iIndex < 0 || iIndex >= 4) throw gcnew System::ArgumentException("Index out of range.");
329  if(iIndex < 2 || m_ptArr->Length >3)
330  return m_ptArr[iIndex];
331  else
332  {
333  array<PointF>^ ptArr = Points;
334  return ptArr[iIndex];
335  }
336  }
337  virtual void set(Int16 iIndex,PointF Value)override
338  {
339  if(iIndex < 0 || iIndex >= 4) throw gcnew System::ArgumentException("Index out of range.");
340  if(m_ptArr->Length < 4)
341  {
342  if(m_ptArr->Length>=iIndex)
343  Array::Resize(m_ptArr,iIndex+1);
344  m_ptArr[iIndex] = Value;
345  }
346  else
347  {
348  PointF pt;
349  float m,c;
350  if(iIndex == 0 || iIndex ==1)
351  {
352  float Numerator = m_ptArr[1].Y-m_ptArr[0].Y;
353  float Denominator = m_ptArr[1].X-m_ptArr[0].X;
354  if(Denominator ==0)
355  Denominator=(float)0.001;
356  m = Numerator/Denominator;
357  c = m_ptArr[1].Y-m*m_ptArr[1].X;
358  }
359  else
360  {
361  float Numerator = m_ptArr[3].Y-m_ptArr[2].Y;
362  float Denominator = m_ptArr[3].X-m_ptArr[2].X;
363  if(Denominator ==0)
364  Denominator=(float)0.001;
365  m = Numerator/Denominator;
366  c = m_ptArr[3].Y-m*m_ptArr[3].X;
367  }
368  pt.X = (m*Value.Y + Value.X - m*c)/(m*m+1);
369  pt.Y = (m*m*Value.Y + m*Value.X + c)/(m*m+1);
370  m_ptArr[iIndex] = pt;
371  }
372  }
373  }
374  virtual Int16 GetPointIndex(PointF pt)override
375  {
376  m_ptArr = Points;
377  return __super::GetPointIndex(pt);
378  }
379 
380  property bool TickMarks
381  {
382  bool get(){return m_bShowTick;}
383  void set(bool value){m_bShowTick=value;}
384  }
385 
386  property bool RulerMeasurement
387  {
388  bool get(){return m_bShowRulerMeasurement;}
389  void set(bool value){m_bShowRulerMeasurement=value;}
390  }
396  virtual bool IntersectsRect(System::Drawing::Rectangle rect)override
397  {
398  array<PointF> ^ptArr = gcnew array<PointF>(2);
399  ptArr[0] = m_ptArr[2];
400  ptArr[1] = m_ptArr[3];
401  return IsLineIntersectsRect(m_ptArr,rect)||IsLineIntersectsRect(ptArr,rect);
402  }
403  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
404  {
405  Graphics^ g = Graphics::FromHwnd(IntPtr(0));
406  float cx = 2.54/g->DpiX;
407  float cy = 2.54/g->DpiY;
408  delete g;
409  array<PointF>^ normalPts = GetNormalPoints();
410 
411  gp->AddLine(ptArr[0],ptArr[1]);
412  gp->StartFigure();
413  if(m_bShowTick)
414  DrawScale(gp,ptArr[0],ptArr[1],getdistance(normalPts[0],normalPts[1],cx,cy));
415  gp->AddLine(ptArr[2],ptArr[3]);
416  gp->StartFigure();
417  if(m_bShowTick)
418  DrawScale(gp,ptArr[2],ptArr[3],getdistance(normalPts[2],normalPts[3],cx,cy));
419  }
420  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection) override;
425  virtual void Load(XmlElement^ element)override;
426 
432  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
433  protected:
434  bool m_bShowTick;
435  bool m_bShowRulerMeasurement;
436  };
437 
438  public ref class Ellipse : public Rectangle
439  {
440  public:
441  Ellipse(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(pen,page)
442  {
443  }
444  property Type AnnotationType
445  {
446  virtual Type get() override
447  {
448  return Annotations::Type::Ellipse;
449  }
450  }
451  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptfArr)override
452  {
453  array<PointF>^ ptArr = (array<PointF>^)ptfArr->Clone();
454  Matrix^ mat = gcnew Matrix();
455  float Slope = (ptArr->Length>2)?m_pPage->Slope:0;
456  mat->Rotate(-Slope);
457  mat->TransformPoints(ptArr);
458  System::Drawing::Rectangle rect(Math::Min(ptArr[0].X,ptArr[1].X),
459  Math::Min(ptArr[0].Y,ptArr[1].Y),
460  Math::Abs(ptArr[0].X-ptArr[1].X+1),
461  Math::Abs(ptArr[0].Y-ptArr[1].Y+1));
462  gp->AddEllipse(rect);
463  mat->Reset();
464  mat->Rotate(Slope);
465  gp->Transform(mat);
466  delete mat;
467  }
468  };
469 
470 
471  public ref class Cloud : public Rectangle
472  {
473  public:
474  Cloud(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(pen,page)
475  {
476  }
477  property Type AnnotationType
478  {
479  virtual Type get() override
480  {
481  return Annotations::Type::Cloud;
482  }
483  }
484  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override;
485  virtual void Draw(Graphics^ gp,array<PointF>^ ptArr,bool bShowSelection)override;
486  };
487 
488  public ref class ScratchOut : public Rectangle
489  {
490  public:
491  ScratchOut(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(pen,page)
492  {
493  }
494  [BrowsableAttribute(false)]
495  property Color FillColor
496  {
497  virtual Color get()override
498  {
499  return Color::Transparent;
500  }
501  }
502  property Type AnnotationType
503  {
504  virtual Type get() override
505  {
506  return Annotations::Type::ScratchOut;
507  }
508  }
509  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override;
510  };
511 
512  public ref class TextNote : public Rectangle
513  {
514  public:
515  TextNote(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(pen,page)
516  {
517  m_TextBox = gcnew System::Windows::Forms::TextBox();
518  m_sText = gcnew String("Write Text Here.");
519  FillColor = Color::Yellow;
520  m_font = gcnew Font("Calibri",20);
521  m_TextColor = Color::Green;
522  m_bEdit = false;
523  }
524 
525  [BrowsableAttribute(false)]
526  property bool Edit
527  {
528  bool get()
529  {
530  return m_bEdit;
531  }
532  void set(bool Value)
533  {
534  m_bEdit = Value;
535  EditText(Value);
536  }
537  }
538 
539  property Type AnnotationType
540  {
541  virtual Type get() override
542  {
543  return Annotations::Type::TextNote;
544  }
545  }
546 
547  [CategoryAttribute("General"), DescriptionAttribute("Text font.")]
548  property System::Drawing::Font^ font
549  {
550  System::Drawing::Font^ get(){return m_font;}
551  void set(System::Drawing::Font^ Value){m_font = Value;}
552  }
553  [CategoryAttribute("General"), DescriptionAttribute("Text.")]
554  property String^ Text
555  {
556  String^ get(){return m_sText;}
557  void set(String^ Value)
558  {
559  if(Value != nullptr && Value->Length>0)
560  m_sText = Value;
561  }
562  }
563  [CategoryAttribute("General"), DescriptionAttribute("Text color. [Format: RGB/ARGB]")]
564  property System::Drawing::Color TextColor
565  {
566  Color get(){return m_TextColor;}
567  void set(Color Value){m_TextColor=Value;}
568  }
569  void EditText(bool value);
570  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override;
571  virtual void Load(System::Xml::XmlElement^ element)override;
572  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
573  protected:
574  Color m_TextColor;
575  String^ m_sText;
576  Font^ m_font;
577  bool m_bEdit;
578  static System::Windows::Forms::TextBox^ m_TextBox;
579 
580  };
581 
582  public ref class Stamp : public Rectangle
583  {
584  public:
585  Stamp(Pen^ pen,MSTAnnotationPage^ page) : Rectangle(pen,page)
586  {
587  m_sText = "Stamp";
588  m_font = gcnew Font("Calibri",20);
589  m_TextColor = Color::Green;
590  FillColor = Color::FromArgb(128,0,255,0);
591  m_Image = nullptr;
592  }
593  property Type AnnotationType
594  {
595  virtual Type get() override
596  {
597  return Annotations::Type::Stamp;
598  }
599  }
600  [CategoryAttribute("General"), DescriptionAttribute("Text.")]
601  property String^ Text
602  {
603  String^ get(){return m_sText;}
604  void set(String^ Value)
605  {
606  m_Image = nullptr;
607  m_sText = Value;
608  }
609  }
610  [CategoryAttribute("General"), DescriptionAttribute("Image.")]
611  property Image^ StampImage
612  {
613  Image^ get(){return m_Image;}
614  void set(Image^ Value)
615  {
616  m_Image = Value;
617  m_sText = nullptr;
618  }
619  }
620  [CategoryAttribute("General"), DescriptionAttribute("Text color. [Format: RGB/ARGB]")]
621  property System::Drawing::Color TextColor
622  {
623  Color get(){return m_TextColor;}
624  void set(Color Value){m_TextColor=Value;}
625  }
626  [CategoryAttribute("General"), DescriptionAttribute("Text font.")]
627  property System::Drawing::Font^ font
628  {
629  System::Drawing::Font^ get(){return m_font;}
630  void set(System::Drawing::Font^ Value){m_font = Value;}
631  }
632 
633  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override;
634  virtual void Load(System::Xml::XmlElement^ element)override;
635  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
636  protected:
637  Color m_TextColor;
638  String^ m_sText;
639  Font^ m_font;
640  Image^ m_Image;
641  };
642 
643  }
644  }
645 }
Definition: TwoPointAnnotation.h:281
Definition: TwoPointAnnotation.h:438
Definition: TwoPointAnnotation.h:512
Definition: TwoPointAnnotation.h:26
Definition: TwoPointAnnotation.h:47
Definition: AnnotationPage.h:95
Definition: TwoPointAnnotation.h:15
virtual bool IntersectsRect(System::Drawing::Rectangle rect) override
use to check annotation lies in rectangle or not.
Definition: TwoPointAnnotation.h:396
Definition: TwoPointAnnotation.h:471
Definition: TwoPointAnnotation.h:215
Definition: TwoPointAnnotation.h:488
Definition: TwoPointAnnotation.h:142
virtual bool IntersectsRect(System::Drawing::Rectangle rect) override
use to check annotation lies in rectangle or not.
Definition: TwoPointAnnotation.h:37
Definition: Image.h:15
Definition: TwoPointAnnotation.h:582
Definition: TwoPointAnnotation.h:198
virtual Int16 GetPointIndex(PointF pt) override
use to get index of point.
Definition: TwoPointAnnotation.h:374
Definition: Annotation.h:45