Documentation
 All Classes Functions Variables Properties
MultiPointAnnotation.h
1 #include "Annotation.h"
2 
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  {
19  public ref class MultiPointAnnotation abstract : public MSTAnnotation
20  {
21  public:
28 
32  [BrowsableAttribute(false)]
33  property bool Closed
34  {
35  bool get(){return m_bClosed;}
36  void set(bool bClosed)
37  {
38  m_bClosed = bClosed;
39  }
40  }
41 
47  virtual bool HitTest(PointF pt)override
48  {
49  if(Closed)return __super::HitTest(pt);
50  else
51  {
52  System::Drawing::Rectangle rect(pt.X-3,pt.Y-3,7,7);
53  if(IntersectsRect(rect))
54  return true;
55  GraphicsPath^ gp = graphicsPath;
56  bool Inside = false;
57  if(gp!=nullptr)
58  {
59  Inside = gp->IsOutlineVisible(pt,m_pen);
60  delete gp;
61  }
62  return Inside;
63  }
64  }
65 
70  void addPoint(PointF pt);
71 
76  virtual void Load(XmlElement^ element)override;
77 
83  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
84  protected:
87  bool m_bClosed;
88  };
89 
94  public ref class Pencil :MultiPointAnnotation
95  {
96  public:
102  Pencil(Pen^ pen,MSTAnnotationPage^ page) : MultiPointAnnotation(pen,page){}
103 
107  property Type AnnotationType
108  {
109  virtual Type get() override
110  {
111  return Annotations::Type::Pencil;
112  }
113  }
114 
118  property Int16 PointsCount
119  {
120  virtual Int16 get()override{return 2;}
121  }
122  property array<RectangleF>^ PointRect
123  {
124  virtual array<RectangleF>^ get()override
125  {
126  array<PointF>^ pts = gcnew array<PointF>{m_ptArr[0],m_ptArr[m_ptArr->Length-1]};
127  array<RectangleF>^ rectArr = gcnew array<RectangleF>(2);
128  for(int i=0;i<pts->Length;i++)
129  {
130  rectArr[i] = RectangleF(pts[i].X-4,pts[i].Y-4,8,8);
131  }
132  return rectArr;
133  }
134  }
135 
139  property PointF Points[Int16]
140  {
141  virtual PointF get(Int16 iIndex)override
142  {
143  if(iIndex==0)return m_ptArr[0];
144  else return m_ptArr[m_ptArr->Length-1];
145  }
146  virtual void set(Int16 iIndex,PointF Value)override
147  {
148  PointF pt = Points[iIndex];
149  for(int i=0;i<m_ptArr->Length;i++)
150  {
151  m_ptArr[i].X += Value.X -pt.X;
152  m_ptArr[i].Y += Value.Y -pt.Y;
153  }
154  }
155  }
156  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
157  {
158  gp->AddLines(ptArr);
159  }
160  };
161 
166  public ref class PolyLine : public MultiPointAnnotation
167  {
168  public:
174  PolyLine(Pen^ pen,MSTAnnotationPage^ page) : MultiPointAnnotation(pen,page){}
175 
176 
180  property Type AnnotationType
181  {
182  virtual Type get() override
183  {
184  return Annotations::Type::Polyline;
185  }
186  }
187 
191  [CategoryAttribute("General"), DescriptionAttribute("Color to fill in annotation. [Format: RGB/ARGB]")]
192  property Color FillColor
193  {
194  Color get(){return m_FillColor;}
195  void set(Color Value)
196  {
197  m_FillColor=Value;
198  }
199  }
200 
205  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override
206  {
207  if(Closed)
208  {
209  GraphicsPath^ gp = gcnew GraphicsPath();
210  Draw(gp,ptArr);
211  Brush^ brush = gcnew SolidBrush(m_FillColor);
212  g->FillPath(brush,gp);
213  delete gp;
214  delete brush;
215  }
216  __super::Draw(g,ptArr,bShowSelection);
217  }
218  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
219  {
220  gp->AddLines(ptArr);
221  if(Closed)
222  gp->CloseFigure();
223  }
224 
229  virtual void Load(XmlElement^ element)override;
230 
236  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
237  protected:
238  Color m_FillColor;
239  };
240 
245  public ref class PolyRuler : public PolyLine
246  {
247  public:
253  PolyRuler(Pen^ pen,MSTAnnotationPage^ page) : PolyLine(pen,page)
254  {
255  m_bShowTick = true;
256  m_bShowRulerMeasurement = true;
257  }
261  property Type AnnotationType
262  {
263  virtual Type get() override
264  {
265  return Annotations::Type::PolyRuler;
266  }
267  }
268  [BrowsableAttribute(false)]
269  property Color FillColor
270  {
271  Color get(){return Color::Black;}
272  }
273 
274  property bool TickMarks
275  {
276  bool get(){return m_bShowTick;}
277  void set(bool value){m_bShowTick=value;}
278  }
279 
280  property bool RulerMeasurement
281  {
282  bool get(){return m_bShowRulerMeasurement;}
283  void set(bool value){m_bShowRulerMeasurement=value;}
284  }
285 
286  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
287  {
288  __super::Draw(gp,ptArr);
289  if(m_bShowTick)
290  {
291  Graphics^ g = Graphics::FromHwnd(IntPtr(0));
292  float cx = 2.54/g->DpiX;
293  float cy = 2.54/g->DpiY;
294  delete g;
295  array<PointF>^ normalPts = GetNormalPoints();
296  gp->StartFigure();
297  for(int i=0;i<ptArr->Length-1;i++)
298  {
299  DrawScale(gp,ptArr[i],ptArr[i+1],getdistance(normalPts[i],normalPts[i+1],cx,cy));
300  }
301  }
302  }
307  virtual void Load(XmlElement^ element)override;
308 
314  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
315  virtual void Draw(Graphics ^g,array<PointF>^ ptArr,bool bShowSelection)override;
316  protected:
317  void DrawMeasurement(Graphics^ g,PointF pt,array<PointF>^ ptArr);
318  protected:
319  bool m_bShowTick;
320  bool m_bShowRulerMeasurement;
321  };
322 
327  public ref class Curve : public MultiPointAnnotation
328  {
329  public:
335  Curve(Pen^ pen,MSTAnnotationPage^ page) : MultiPointAnnotation(pen,page){}
336 
340  property Type AnnotationType
341  {
342  virtual Type get() override
343  {
344  return Annotations::Type::Curve;
345  }
346  }
350  [CategoryAttribute("General"), DescriptionAttribute("Color to fill in annotation. [Format: RGB/ARGB]")]
351  property Color FillColor
352  {
353  Color get(){return m_FillColor;}
354  void set(Color Value)
355  {
356  m_FillColor=Value;
357  }
358  }
359  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
360  {
361  if(ptArr->Length<3)
362  gp->AddLines(ptArr);
363  else
364  {
365  if(Closed)gp->AddClosedCurve(ptArr);
366  else gp->AddCurve(ptArr);
367  }
368  }
373  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override;
374 
379  virtual void Load(XmlElement^ element)override;
380 
386  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
387  protected:
388  Color m_FillColor;
389  };
394  public ref class Angle : public MultiPointAnnotation
395  {
396  public:
402  Angle(Pen^ pen,MSTAnnotationPage^ page) : MultiPointAnnotation(pen,page)
403  {
404  m_bShowTick = true;
405  m_bShowRulerMeasurement = true;
406  m_bShowAngleMeasurement =true;
407  }
408 
412  property Type AnnotationType
413  {
414  virtual Type get() override
415  {
416  return Annotations::Type::Angle;
417  }
418  }
419 
420  property bool TickMarks
421  {
422  bool get(){return m_bShowTick;}
423  void set(bool value){m_bShowTick=value;}
424  }
425 
426  property bool RulerMeasurement
427  {
428  bool get(){return m_bShowRulerMeasurement;}
429  void set(bool value){m_bShowRulerMeasurement=value;}
430  }
431 
432  property bool AngleMeasurement
433  {
434  bool get(){return m_bShowAngleMeasurement;}
435  void set(bool value){m_bShowAngleMeasurement=value;}
436  }
437 
438  virtual void Draw(GraphicsPath^ gp,array<PointF>^ ptArr)override
439  {
440  gp->AddLine(ptArr[0],ptArr[1]);
441  gp->StartFigure();
442  if(ptArr->Length>2)
443  gp->AddLine(ptArr[0],ptArr[2]);
444  gp->StartFigure();
445  AddArc(gp,ptArr);
446  Graphics^ g = Graphics::FromHwnd(IntPtr(0));
447  float cx = 2.54/g->DpiX;
448  float cy = 2.54/g->DpiY;
449  delete g;
450  array<PointF>^ normalPts = GetNormalPoints();
451  gp->StartFigure();
452  if(m_bShowTick)DrawScale(gp,ptArr[1],ptArr[0],getdistance(normalPts[0],normalPts[1],cx,cy));
453  if(m_bShowTick && ptArr->Length>2)
454  DrawScale(gp,ptArr[0],ptArr[2],getdistance(normalPts[0],normalPts[2],cx,cy));
455  }
456 
462  virtual bool IntersectsRect(System::Drawing::Rectangle rect)override
463  {
464  if(m_ptArr->Length==3)
465  {
466  array<PointF> ^ptArr = gcnew array<PointF>(2);
467  ptArr[0] = m_ptArr[0];
468  ptArr[1] = m_ptArr[2];
469  return IsLineIntersectsRect(m_ptArr,rect)||IsLineIntersectsRect(ptArr,rect);
470  }
471  else
472  {
473  return IsLineIntersectsRect(m_ptArr,rect);
474  }
475  }
476 
481  virtual void Load(XmlElement^ element)override;
482 
488  virtual void Save(XmlDocument^ writer,XmlElement^ element)override;
493  virtual void Draw(Graphics^ g,array<PointF>^ ptArr,bool bShowSelection)override;
494 
499  void AddArc(GraphicsPath^ path,array<PointF>^ ptArr);
500 
508  static array<float>^ GetAngles(PointF pt0,PointF pt1,PointF pt2);
509  protected:
510  bool m_bShowTick;
511  bool m_bShowRulerMeasurement;
512  bool m_bShowAngleMeasurement;
513  };
514  }
515  }
516 }
Pencil(Pen^ pen, MSTAnnotationPage^ page)
Constructor of a class.
Definition: MultiPointAnnotation.h:102
Definition: MultiPointAnnotation.h:245
Definition: MultiPointAnnotation.h:394
virtual bool IntersectsRect(System::Drawing::Rectangle rect) override
use to check annotation lies in rectangle or not.
Definition: MultiPointAnnotation.h:462
virtual bool HitTest(PointF pt) override
It is overrided function and use to check point lies in annotation or not.
Definition: MultiPointAnnotation.h:47
Definition: AnnotationPage.h:95
MultiPointAnnotation(Pen^ pen, MSTAnnotationPage^ page)
Constructor of a class.
Definition: MultiPointAnnotation.h:27
virtual void Draw(Graphics^ g, array< PointF >^ptArr, bool bShowSelection) override
Used to draw annotations.
Definition: MultiPointAnnotation.h:205
Definition: MultiPointAnnotation.h:19
PolyRuler(Pen^ pen, MSTAnnotationPage^ page)
Constructor of a class.
Definition: MultiPointAnnotation.h:253
PolyLine(Pen^ pen, MSTAnnotationPage^ page)
Constructor of a class.
Definition: MultiPointAnnotation.h:174
bool m_bClosed
Used to closed multipoint annotation i.e. if this is true then annotations starting and ending point ...
Definition: MultiPointAnnotation.h:87
Definition: MultiPointAnnotation.h:166
Definition: MultiPointAnnotation.h:94
Curve(Pen^ pen, MSTAnnotationPage^ page)
Constructor of a class.
Definition: MultiPointAnnotation.h:335
Definition: MultiPointAnnotation.h:327
Definition: Annotation.h:45