/// <summary> /// This method returns an default colored <see cref="VGElement"/> /// that represents the object in the database described by the three parameters /// </summary> /// <param name="shapeType">A <see cref="String"/> with the shape type Rectangle, Ellipse or Polyline</param> /// <param name="shapeName">A <see cref="String"/> with the shape name</param> /// <param name="shapeGroup">A <see cref="String"/> with the shapes group</param> /// <param name="strPtList">A <see cref="String"/> with the list of points to be converted /// with <see cref="ObjectStringConverter.StringToPointFList(String)"/></param> /// <returns>A <see cref="VGElement"/> that represents the object in the database described by the three parameters.</returns> public static VGElement GetVGElementFromDatabase( string shapeType, string shapeName, string shapeGroup, string strPtList) { // Create the shape depending on ShapeType RectangleF boundingRect = new RectangleF(); List<PointF> pointList = ObjectStringConverter.StringToPointFList(strPtList); switch (shapeType) { case "Rectangle": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke VGRectangle newRect = new VGRectangle( ShapeDrawAction.NameAndEdge, Pens.Red, SystemFonts.MenuFont, Color.Black, boundingRect, VGStyleGroup.None, shapeName, shapeGroup); newRect.TextAlignment = VGAlignment.Center; return newRect; case "Ellipse": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke VGEllipse newEllipse = new VGEllipse( ShapeDrawAction.NameAndEdge, Pens.Red, SystemFonts.MenuFont, Color.Black, boundingRect, VGStyleGroup.None, shapeName, shapeGroup); newEllipse.TextAlignment = VGAlignment.Center; return newEllipse; case "Polyline": // Create Polyline with defined stroke VGPolyline newPolyline = new VGPolyline( ShapeDrawAction.NameAndEdge, Pens.Red, SystemFonts.MenuFont, Color.Black, VGStyleGroup.None, shapeName, shapeGroup); newPolyline.TextAlignment = VGAlignment.Center; foreach (PointF point in pointList) { newPolyline.AddPt(point); } newPolyline.ClosePolyline(); boundingRect = newPolyline.Bounds; return newPolyline; } return null; }
/// <summary> /// Loads the shapes that are listed in the given database table /// and creates corresponding graphic elements. /// </summary> /// <param name="areaOfInterestTableRows"> /// Areas of interest table as /// a <see cref="DataGridViewRowCollection"/> /// </param> public void LoadShapesFromDataGridView(DataGridViewRowCollection areaOfInterestTableRows) { try { // Create aoi elements from data view this.AoiCollection = new VGElementCollection(); foreach (DataGridViewRow row in areaOfInterestTableRows) { if (!row.IsNewRow) { // retrieve shape parameters from cell values. var shapeName = row.Cells["colShapeName"].Value.ToString(); var strPtList = row.Cells["colShapePts"].Value.ToString(); Pen usedPen; Font usedFont; Color usedFontColor; VGAlignment usedAlignment; VGStyleGroup usedStyleGroup; var pointList = ObjectStringConverter.StringToPointFList(strPtList); var usedElementGroup = row.Cells["colShapeGroup"].Value.ToString(); switch (usedElementGroup) { case "Target": usedPen = this.TargetPen; usedFont = this.TargetFont; usedFontColor = this.TargetFontColor; usedStyleGroup = VGStyleGroup.AOI_TARGET; usedAlignment = this.TargetTextAlignment; break; case "SearchRect": usedPen = this.SearchRectPen; usedFont = this.SearchRectFont; usedFontColor = this.SearchRectFontColor; usedStyleGroup = VGStyleGroup.AOI_SEARCHRECT; usedAlignment = this.SearchRectTextAlignment; break; default: usedPen = this.DefaultPen; usedFont = this.DefaultFonts; usedFontColor = this.DefaultFontColor; usedStyleGroup = VGStyleGroup.AOI_NORMAL; usedAlignment = this.DefaultTextAlignment; break; } // Create the shape depending on ShapeType var boundingRect = new RectangleF(); switch (row.Cells["colShapeType"].Value.ToString()) { case "Rectangle": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke var newRect = new VGRectangle( this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, boundingRect, usedStyleGroup, shapeName, usedElementGroup); newRect.TextAlignment = usedAlignment; this.AoiCollection.Add(newRect); break; case "Ellipse": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke var newEllipse = new VGEllipse( this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, boundingRect, usedStyleGroup, shapeName, usedElementGroup); newEllipse.TextAlignment = usedAlignment; this.AoiCollection.Add(newEllipse); break; case "Polyline": // Create Polyline with defined stroke var newPolyline = new VGPolyline( this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, usedStyleGroup, shapeName, usedElementGroup); newPolyline.TextAlignment = usedAlignment; foreach (var point in pointList) { newPolyline.AddPt(point); } newPolyline.ClosePolyline(); this.AoiCollection.Add(newPolyline); break; } } } // Reset Elements (deselect and clear all) this.ResetPicture(); this.Elements.AddRange(this.AoiCollection); // If there were a selected element before updating, try // to select it again. if (this.SelectedElement != null) { foreach (VGElement element in this.Elements) { if (VGPolyline.Distance(element.Location, this.SelectedElement.Location) < 1) { this.SelectedElement = element; element.IsInEditMode = true; } } } this.DrawForeground(true); } catch (Exception ex) { ExceptionMethods.HandleException(ex); } }
/// <summary> /// This method converts the AOI table with areas of interest from the database /// into a list of <see cref="VGElement"/>s. /// </summary> /// <param name="aoiTable">The <see cref="DataTable"/> with the AOIs.</param> /// <returns>A <see cref="List{VGElement}"/> with the shapes.</returns> protected virtual VGElementCollection GetAOIElements(DataTable aoiTable) { Pen defaultPen = new Pen(Properties.Settings.Default.AOIStandardColor, Properties.Settings.Default.AOIStandardWidth); Pen targetPen = new Pen(Properties.Settings.Default.AOITargetColor, Properties.Settings.Default.AOITargetWidth); Pen searchRectPen = new Pen(Properties.Settings.Default.AOISearchRectColor, Properties.Settings.Default.AOISearchRectWidth); Font defaultFont = (Font)Properties.Settings.Default.AOIStandardFont.Clone(); Font targetFont = (Font)Properties.Settings.Default.AOITargetFont.Clone(); Font searchRectFont = (Font)Properties.Settings.Default.AOISearchRectFont.Clone(); Color defaultFontColor = Properties.Settings.Default.AOIStandardFontColor; Color targetFontColor = Properties.Settings.Default.AOITargetFontColor; Color searchRectFontColor = Properties.Settings.Default.AOISearchRectFontColor; VGElementCollection aoiList = new VGElementCollection(); int counter = 0; try { foreach (DataRow row in aoiTable.Rows) { string strPtList = row["ShapePts"].ToString(); string shapeName = row["ShapeName"].ToString(); Pen usedPen = defaultPen; Font usedFont = defaultFont; Color usedFontColor = defaultFontColor; VGStyleGroup usedStyleGroup = VGStyleGroup.AOI_NORMAL; List<PointF> pointList = ObjectStringConverter.StringToPointFList(strPtList); string usedElementGroup = row["ShapeGroup"].ToString(); switch (usedElementGroup) { case "Target": usedPen = targetPen; usedFont = targetFont; usedFontColor = targetFontColor; usedStyleGroup = VGStyleGroup.SCA_GRID_AOI; break; case "SearchRect": usedPen = searchRectPen; usedFont = searchRectFont; usedFontColor = searchRectFontColor; usedStyleGroup = VGStyleGroup.SCA_GRID_AOI; break; default: usedPen = defaultPen; usedFont = defaultFont; usedFontColor = defaultFontColor; usedStyleGroup = VGStyleGroup.SCA_GRID_AOI; break; } // Create the shape depending on ShapeType RectangleF boundingRect = new RectangleF(); switch (row["ShapeType"].ToString()) { case "Rectangle": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke VGRectangle newRect = new VGRectangle( ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, boundingRect, usedStyleGroup, shapeName, usedElementGroup); aoiList.Add(newRect); break; case "Ellipse": boundingRect.Location = pointList[0]; boundingRect.Width = pointList[2].X - pointList[0].X; boundingRect.Height = pointList[2].Y - pointList[0].Y; // Create Rect with defined stroke VGEllipse newEllipse = new VGEllipse( ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, boundingRect, usedStyleGroup, shapeName, usedElementGroup); aoiList.Add(newEllipse); break; case "Polyline": // Create Polyline with defined stroke VGPolyline newPolyline = new VGPolyline( ShapeDrawAction.NameAndEdge, usedPen, usedFont, usedFontColor, usedStyleGroup, shapeName, usedElementGroup); foreach (PointF point in pointList) { newPolyline.AddPt(point); } newPolyline.ClosePolyline(); aoiList.Add(newPolyline); boundingRect = newPolyline.Bounds; break; } counter++; } } catch (Exception ex) { ExceptionMethods.HandleException(ex); } return aoiList; }