Documentation
 All Classes Functions Variables Properties
AnnotationPage.h
1 #pragma once
2 #include <list>
3 #include "Annotation.h"
4 
5 using namespace System;
6 using namespace System::Text;
7 using namespace System::Drawing;
8 using namespace System::Drawing::Drawing2D;
9 using namespace MST::Imaging::Annotations;
10 using namespace System::Collections::Generic;
11 
12 namespace MST
13 {
14  namespace Imaging
15  {
16  namespace Annotations
17  {
22  public ref class AnnotationCollection : public System::Collections::IEnumerable
23  {
24  public:
29  {
30  m_AnnList = gcnew List<MSTAnnotation^>();
31  }
32 
36  property int AnnotationCount
37  {
38  int get(){return m_AnnList->Count;}
39  }
40 
44  property List<MSTAnnotation^>^ AllAnnotation
45  {
46  List<MSTAnnotation^>^ get(){return m_AnnList;}
47  }
48 
52  property MSTAnnotation^ Annotation[Int32]
53  {
54  MSTAnnotation^ get(Int32 value)
55  {
56  if(value <= m_AnnList->Count)
57  return m_AnnList[value];
58  else
59  return nullptr;
60  }
61  }
62 
66  virtual System::Collections::IEnumerator^ GetEnumerator();
67 
72  void AddAnnotation(MSTAnnotation^ obj);
73 
78  void RemoveAnnotation(MSTAnnotation^ obj);
79 
83  void RemoveAllAnnotation();
84  private:
85  List<MSTAnnotation^>^ m_AnnList;
86 
87  };
88 
89  public delegate void ZoomChangeEvent(float fScale);
95  public ref class MSTAnnotationPage
96  {
97  public:
102  MSTAnnotationPage(System::Windows::Forms::ScrollableControl^ parent)
103  {
104  m_AnnCollection = gcnew AnnotationCollection();
105  m_iRotateAngle = 0;
106  m_iZoom = 100;
107  m_bHorzFlip = false;
108  m_bVertFlip = false;
109  m_Parent = parent;
110  m_Tag = nullptr;
111  m_OrientationPath = gcnew System::Drawing::Drawing2D::GraphicsPath();
112  m_OrientationPath->AddRectangle(System::Drawing::Rectangle(0,0,100,100));
113  m_ImgPath = gcnew System::Drawing::Drawing2D::GraphicsPath();
114  }
115 
116  property Object^ Tag
117  {
118  Object^ get(){return m_Tag;}
119  void set(Object^ value){m_Tag=value;}
120  }
124  property AnnotationCollection^ Annotation
125  {
126  AnnotationCollection^ get(){return m_AnnCollection;}
127  }
128 
132  property System::Windows::Forms::ScrollableControl^ Parent
133  {
134  System::Windows::Forms::ScrollableControl^ get()
135  {
136  return m_Parent;
137  }
138  void set(System::Windows::Forms::ScrollableControl^ parent)
139  {
140  m_Parent = parent;
141  }
142  }
143 
147  property float Rotate
148  {
149  float get(){return m_iRotateAngle;}
150  void set(float Value)
151  {
152  while(Value >= 360)Value-=360;
153  while(Value <= -360)Value+=360;
154  if(Value < 0)Value = 360 + Value;
155  if(Value==m_iRotateAngle)return;
156  System::Drawing::Drawing2D::Matrix^ matrix = gcnew System::Drawing::Drawing2D::Matrix();
157  System::Drawing::Rectangle ClientRect = m_Parent->ClientRectangle;
158  matrix->RotateAt(Value-m_iRotateAngle,PointF(ClientRect.Width/2,ClientRect.Height/2),System::Drawing::Drawing2D::MatrixOrder::Append);
159  ApplyMatrix(matrix);
160  delete matrix;
161  m_iRotateAngle = (int)Value;
162  }
163  }
167  property bool FlipHorizontal
168  {
169  bool get(){return m_bHorzFlip;}
170  void set(bool Value)
171  {
172  if(m_bHorzFlip!=Value)
173  {
174  System::Drawing::Drawing2D::Matrix^ matrix = gcnew System::Drawing::Drawing2D::Matrix(-1, 0, 0, 1, 0, 0);
175  matrix->Translate(-m_Parent->ClientRectangle.Width,0);
176  ApplyMatrix(matrix);
177  delete matrix;
178  m_bHorzFlip = Value;
179  }
180  }
181  }
182 
186  property bool FlipVertical
187  {
188  bool get(){return m_bVertFlip;}
189  void set(bool Value)
190  {
191  if(m_bVertFlip!=Value)
192  {
193  System::Drawing::Drawing2D::Matrix^ matrix = gcnew System::Drawing::Drawing2D::Matrix(1, 0, 0, -1, 0, 0);
194  matrix->Translate(0,-m_Parent->ClientRectangle.Height);
195  ApplyMatrix(matrix);
196  delete matrix;
197  m_bVertFlip = Value;
198  }
199  }
200  }
201 
205  property float Zoom
206  {
207  float get(){return m_iZoom;}
208  void set(float Value)
209  {
210  if(Value<10)Value=10;
211  if(Value>9999)Value=9999;
212  if(Value==m_iZoom)return;
213  float fZoom = Value/m_iZoom;
214  System::Drawing::Drawing2D::Matrix^ matrix = gcnew System::Drawing::Drawing2D::Matrix();
215  System::Drawing::Rectangle rect = m_Parent->ClientRectangle;
216  float cx = rect.Width / 2;
217  float cy = rect.Height / 2;
218  matrix->Translate(cx,cy, System::Drawing::Drawing2D::MatrixOrder::Append);
219  matrix->Scale(fZoom,fZoom,System::Drawing::Drawing2D::MatrixOrder::Append);
220  matrix->Translate(-cx*(2*fZoom-1),-cy*(2*fZoom-1), System::Drawing::Drawing2D::MatrixOrder::Append);
221  ApplyMatrix(matrix);
222  delete matrix;
223  m_iZoom = Value;
224  ZoomChangeEventHandler(m_iZoom);
225  }
226  }
227 
228  property float Slope
229  {
230  float get()
231  {
232  PointF pt1 = m_OrientationPath->PathPoints[0];
233  PointF pt2 = m_OrientationPath->PathPoints[1];
234  return GetSlope(pt1 ,pt2);
235  }
236  }
237  property PointF ReferencePoint
238  {
239  PointF get()
240  {
241  array<PointF>^ ptArr = m_OrientationPath->PathPoints;
242  float minX=ptArr[0].X,minY=ptArr[0].Y,maxX=ptArr[0].X,maxY=ptArr[0].Y;
243  for(int i=1; i<ptArr->Length; i++)
244  {
245  minX = Math::Min(minX,ptArr[i].X);
246  minY = Math::Min(minY,ptArr[i].Y);
247  maxX = Math::Max(maxX,ptArr[i].X);
248  maxY = Math::Max(maxY,ptArr[i].Y);
249  }
250  return PointF(((float)(maxX+minX))/2,((float)(maxY+minY))/2);
251  }
252  }
253  property array<PointF>^ ImagePoints
254  {
255  array<PointF>^ get()
256  {
257  return m_ImgPath->PathPoints;
258  }
259  }
260 
268  MSTAnnotation^ CreateAnnotation(Annotations::Type type,Pen^ pen);
269 
275  void Draw(Graphics^ g,System::Drawing::Image^ image,bool bAnnotationVisible);
276  void DrawImage(Graphics^ g,System::Drawing::Image^ image,array<PointF>^ pts);
277  void DrawString(Graphics^ g,Font^ font,Color TextColor,StringFormat^ fmt,String^ Text,array<PointF>^ pts);
278  void DrawString(Graphics^ g,Font^ font,Color TextColor,String^ Text,array<PointF>^ pts);
279  array<Byte>^ BurnAnnotation(System::Drawing::Image^ image);
280 
285  void ApplyMatrix(System::Drawing::Drawing2D::Matrix^ matrix);
286 
287  void Translate(float cx,float cy)
288  {
289  if(cx==0&&cy==0)return;
290  System::Drawing::Drawing2D::Matrix^ matrix = gcnew System::Drawing::Drawing2D::Matrix();
291  matrix->Translate(cx,cy,System::Drawing::Drawing2D::MatrixOrder::Append);
292  ApplyMatrix(matrix);
293  delete matrix;
294  }
298  void BringImageToCenter();
299  void ScaleImageToFitWindow();
300  void ScaleImageToFitWindowWidth();
301  void ScaleImageToFitWindowHeight();
302  void SetImageDimension(float cx,float cy)
303  {
304  Rotate = 0;
305  FlipHorizontal = false;
306  FlipVertical = false;
307  Zoom = 100;
308  m_ImgPath->Reset();
309  array<PointF> ^arr = gcnew array<PointF>(4);
310  PointF pt = ReferencePoint;
311  arr[0]=PointF(pt.X-cx/2,pt.Y-cy/2);
312  arr[1]=PointF(pt.X+cx/2,pt.Y-cy/2);
313  arr[2]=PointF(pt.X-cx/2,pt.Y+cy/2);
314  arr[3]=PointF(pt.X+cx/2,pt.Y+cy/2);
315  m_ImgPath->AddPolygon(arr);
316  delete arr;
317  }
318  void TransformPoints(array<PointF>^,bool bFromCenter);
319  void TransformPoints(array<PointF>^);
320  void DeTransformPoints(array<PointF>^,bool bFromCenter);
321  void DeTransformPoints(array<PointF>^);
322  static float GetSlope(PointF pt1 , PointF pt2);
323  public:
324  event ZoomChangeEvent^ ZoomChangeEventHandler;
325  private:
326 
327  Object^ m_Tag;
328  int m_iRotateAngle;
329  float m_iZoom;
330  bool m_bHorzFlip;
331  bool m_bVertFlip;
332  AnnotationCollection^ m_AnnCollection;
333  System::Windows::Forms::ScrollableControl^ m_Parent;
334  System::Drawing::Drawing2D::GraphicsPath ^m_OrientationPath;
335  System::Drawing::Drawing2D::GraphicsPath ^m_ImgPath;
336  };
337 
338 
339  }
340  }
341 }
AnnotationCollection()
Constructor of a class.
Definition: AnnotationPage.h:28
Definition: AnnotationPage.h:95
MSTAnnotationPage(System::Windows::Forms::ScrollableControl^ parent)
Constructor of a class.
Definition: AnnotationPage.h:102
Definition: Annotation.h:45