public override void Draw(Graphics g) { Pen pen = new Pen(Color, PenWidth); g.DrawEllipse(pen, DrawRectangle.GetNormalizedRectangle(Rectangle)); Shape._shapeType = ShapeType.Annotation_Ellipse; Shape.StartPoint = new Point(Rectangle.X, Rectangle.Y); Shape.Width = Rectangle.Width; Shape.Height = Rectangle.Height; pen.Dispose(); }
//This below method was added by Darshan on 19-10-2015(Description given below). /// <summary> /// This method will draw the graph on the panel to the image. /// </summary> /// <param name="srcBitmap">Image name</param> public void DrawEllipseToBitmap(ref Bitmap srcBitmap, int id, Common.PicBoxSizeMode sizeMode = Common.PicBoxSizeMode.Zoom) { SolidBrush brush = new SolidBrush(Color.FromName(AnnotationVariables.annotationMarkingColor)); Common.CommonMethods _common = Common.CommonMethods.CreateInstance(); if (sizeMode == Common.PicBoxSizeMode.Zoom) { inp = new Image <Bgr, byte>(Form1.tempBm.Width, Form1.tempBm.Height); } else { inp = new Image <Bgr, byte>(Form1.pbxWidth, Form1.pbxHeight); } List <Point> TempPointArr = new List <Point>(); _common.Image = inp.ToBitmap(); _common.Height = Form1.pbxHeight; _common.Width = Form1.pbxWidth; Point actualImageRectStartPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X, rectangle.Y), sizeMode); Point actualImageRectWidthPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X + rectangle.Width, rectangle.Y), sizeMode); Point actualImageRectHeightPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X, rectangle.Y + rectangle.Height), sizeMode); if (sizeMode != Common.PicBoxSizeMode.Zoom) { actualImageRectStartPoint.X = Convert.ToInt32((float)actualImageRectStartPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectStartPoint.Y = Convert.ToInt32((float)actualImageRectStartPoint.Y * (float)srcBitmap.Height / (float)inp.Height); actualImageRectWidthPoint.X = Convert.ToInt32((float)actualImageRectWidthPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectWidthPoint.Y = Convert.ToInt32((float)actualImageRectWidthPoint.Y * (float)srcBitmap.Height / (float)inp.Height); actualImageRectHeightPoint.X = Convert.ToInt32((float)actualImageRectHeightPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectHeightPoint.Y = Convert.ToInt32((float)actualImageRectHeightPoint.Y * (float)srcBitmap.Height / (float)inp.Height); } int width = (int)Math.Sqrt(Math.Pow(((double)actualImageRectStartPoint.X - (double)actualImageRectWidthPoint.X), 2)); int height = (int)Math.Sqrt(Math.Pow(((double)actualImageRectStartPoint.Y - (double)actualImageRectHeightPoint.Y), 2)); int x, y, xCenter, yCenter; xCenter = actualImageRectStartPoint.X + width / 2; yCenter = actualImageRectStartPoint.Y + height / 2; x = actualImageRectStartPoint.X; y = actualImageRectStartPoint.Y; Bitmap bm = inp.ToBitmap(); Rectangle ellipseRectangle = new Rectangle(actualImageRectStartPoint, new Size(width, height)); Graphics g = Graphics.FromImage(srcBitmap); g.DrawEllipse(new Pen(Color.FromName(AnnotationVariables.annotationMarkingColor), 9.0f), DrawRectangle.GetNormalizedRectangle(ellipseRectangle)); //DrawAnnotationNumber(g, id); g.DrawString(id.ToString(), new Font(FontFamily.GenericSansSerif, 43.2f, FontStyle.Bold, GraphicsUnit.Pixel), brush, new PointF(xCenter - 10, y - 60)); g.Dispose(); }
/// <summary> /// Left mouse button is pressed /// </summary> /// <param name="drawArea"></param> /// <param name="e"></param> public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e) { selectMode = SelectionMode.None; Point point = new Point(e.X, e.Y); // Test for resizing (only if control is selected, cursor is on the handle) int n = drawArea.ListGraphics.SelectionCount; for (int i = 0; i < n; i++) { DrawObject o = drawArea.ListGraphics.GetSelectedObject(i); int handleNumber = o.HitTest(point); if (handleNumber > 0) { selectMode = SelectionMode.Size; // keep resized object in class members resizedObject = o; resizedObjectHandle = handleNumber; // Since we want to resize only one object, unselect all other objects drawArea.ListGraphics.UnselectAll(); o.Selected = true; break; } } // Test for move (cursor is on the object) if (selectMode == SelectionMode.None) { List <AnnotationComments> annocmt = null; int n1 = drawArea.ListGraphics.Count; DrawObject o = null; if (drawArea.comments.Count != 0) { annocmt = drawArea.comments; annocmt.Reverse(); } string[] str = drawArea.ListGraphics.graphicType; for (int i = 0; i < n1; i++) { int a = drawArea.ListGraphics[i].HitTest(point); if (drawArea.ListGraphics[i].PointContainer(point) == 0) { o = drawArea.ListGraphics[i]; break; } //if (drawArea.ListGraphics[i].HitTest(point) == 0) //{ // o = drawArea.ListGraphics[i]; // //if(annocmt!=null) // // //o.ID = annocmt[i].ID; // break; //} } if (o != null) { isZoom = false; selectMode = SelectionMode.Move; // Unselect all if Ctrl is not pressed and clicked object is not selected yet if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected) { drawArea.ListGraphics.UnselectAll(); } // Select clicked object o.Selected = true; if (o is DrawPolygon) { DrawPolygon polyGon = o as DrawPolygon; if (AnnotationVariables.isGlaucomaTool) { _eventHandler.Notify(_eventHandler.EnableMovePointInCDRTool, new Args());//public void Notify(String n, Args args) defined in IVLEventHandler.By ashutosh 25-07-2017 } } drawArea.Cursor = Cursors.SizeAll; } } // Net selection if (selectMode == SelectionMode.None) { // click on background if ((Control.ModifierKeys & Keys.Control) == 0) { drawArea.ListGraphics.UnselectAll(); drawArea.unselectalltext(); } selectMode = SelectionMode.NetSelection; isZoom = true; drawArea.DrawNetRectangle = true; } lastPoint.X = e.X; lastPoint.Y = e.Y; startPoint.X = e.X; startPoint.Y = e.Y; drawArea.Capture = true; drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint); drawArea.Refresh(); }
/// <summary> /// Normalize rectangle /// </summary> public override void Normalize() { rectangle = DrawRectangle.GetNormalizedRectangle(rectangle); }
/// <summary> /// Mouse is moved. /// None button is pressed, ot left button is pressed. /// </summary> /// <param name="drawArea"></param> /// <param name="e"></param> public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) { Point point = new Point(e.X, e.Y); Point point1 = new Point(); // set cursor when mouse button is not pressed if (e.Button == MouseButtons.None) { Cursor cursor = null; for (int i = 0; i < drawArea.ListGraphics.Count; i++) { int n = drawArea.ListGraphics[i].HitTest(point); if (n == 5) { point1 = drawArea.ListGraphics[i].GetHandleCursor(n).HotSpot; //annotateText.Location = drawArea.active_point; } if (n > 0) { cursor = drawArea.ListGraphics[i].GetHandleCursor(n); break; } } if (cursor == null) { cursor = Cursors.Default; } drawArea.Cursor = cursor; return; } if (e.Button != MouseButtons.Left) { return; } /// Left button is pressed // Find difference between previous and current position int dx = e.X - lastPoint.X; int dy = e.Y - lastPoint.Y; lastPoint.X = e.X; lastPoint.Y = e.Y; int ControlIndx = 0; int shiftVal = 0; // resize if (selectMode == SelectionMode.Size) { if (resizedObject != null) { if (AnnotationVariables.isGlaucomaTool) { if (resizedObject is DrawPolygon) { if (ToolPolygon.modifyPolygon) { if (e.Button != MouseButtons.Left) { return; } DrawPolygon poly = resizedObject as DrawPolygon;// this line has been added in order to get the polygon details instead of directly getting from the generic object which solves the problem cup going outside disc and disc coming inside cup by sriram if (!poly.isCup) { if (ToolPolygon.DrawDiscPolygon == null) { return; // precaution } // if (distance < minDistance) { // Distance between last two points is less than minimum - // move last point if (ToolPolygon.DrawCupPolygon != null) { if (!NearestNeighbours((Point[])ToolPolygon.DrawCupPolygon.pointArray.ToArray(typeof(Point)), point)) { resizedObject.MoveHandleTo(point, resizedObjectHandle); } if (AnnotationVariables.isGlaucomaToolViewing) { Args arg = new Args(); arg["Save"] = true; arg["IsViewed"] = false; _eventHandler.Notify(_eventHandler.UpdateGlaucomaToolControls, arg); } } else { resizedObject.MoveHandleTo(point, resizedObjectHandle); } } } else { if (ToolPolygon.DrawCupPolygon == null) { return; // precaution } // if (distance < minDistance) { // Distance between last two points is less than minimum - // move last point if (ToolPolygon.DrawDiscPolygon != null) { if (NearestNeighbours((Point[])ToolPolygon.DrawDiscPolygon.pointArray.ToArray(typeof(Point)), point)) { //if (!InsidePolygon((Point[])ToolPolygon.DrawDiscPolygon.pointArray.ToArray(typeof(Point)), point)) resizedObject.MoveHandleTo(point, resizedObjectHandle); } if (AnnotationVariables.isGlaucomaToolViewing) { Args arg = new Args(); if (drawArea.ListGraphics[0].HandleCount >= 3 && drawArea.ListGraphics[1].HandleCount >= 3)//this has been added to solve the defect no 0001515 { arg["Save"] = true; arg["IsViewed"] = false; } else { arg["Save"] = false; arg["IsViewed"] = true; } _eventHandler.Notify(_eventHandler.UpdateGlaucomaToolControls, arg); } } else { resizedObject.MoveHandleTo(point, resizedObjectHandle); } } } } } } else { resizedObject.MoveHandleTo(point, resizedObjectHandle); Args arg = new Args(); arg["Save"] = true; arg["IsViewed"] = false; _eventHandler.Notify(_eventHandler.AnnotationButtonsRefresh, arg); } drawArea.Refresh(); Rectangle handleRect = drawArea.ListGraphics[ControlIndx].GetHandleRectangle(5); point.X = handleRect.X; point.Y = handleRect.Y; //drawArea.active_point = point; ////ToolObject.text_move(drawArea, e); //(drawArea.Controls[ControlIndx] as Panel).Location = drawArea.active_point; //drawArea.Controls[ControlIndx].SendToBack(); //drawArea.Refresh(); } } // move if (!AnnotationVariables.isGlaucomaTool) { if (selectMode == SelectionMode.Move) { int n = drawArea.ListGraphics.SelectionCount; for (int i = 0; i < n; i++) { drawArea.ListGraphics.GetSelectedObject(i).Move(dx, dy); //if (i == 5) //{ // drawArea.active_point = drawArea.ListGraphics[i].GetHandleCursor(n).HotSpot; //} } //This below if statement was added by Darshan on 25-08-2015 to solve Defect no 0000596: system is getting crashed. if (n > 0) { Rectangle handleRect = drawArea.ListGraphics[ControlIndx].GetHandleRectangle(5); point.X = handleRect.X; point.Y = handleRect.Y; drawArea.Refresh(); drawArea.active_point = point; } Args arg = new Args(); arg["Save"] = true; arg["IsViewed"] = false; _eventHandler.Notify(_eventHandler.AnnotationButtonsRefresh, arg); //drawArea.Location = new Point(point.X, point.Y); //foreach (AnnotationText item in drawArea.Controls) //{ // item.Location = drawArea.active_point; //} // (drawArea.Controls[ControlIndx] as Panel).Location = drawArea.active_point; // //ToolObject.text_move(drawArea, e); // drawArea.Controls[ControlIndx].SendToBack(); // drawArea.Cursor = Cursors.SizeAll; //drawArea.Refresh(); } if (selectMode == SelectionMode.NetSelection) { drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint); drawArea.Refresh(); return; } } }