private void lDrawDesignElement(Graphics gfx, DesignElement delement, int offsetx, int offsety) { int tmpndx; Graphics3D.TransformDesignElement(lPhi, lTheta, delement, 0.0F); foreach (RectPlane tmpplane in delement.ProjectedPlanes) { for (tmpndx = 0; tmpndx < tmpplane.Points.Length; tmpndx++) { lTempPanelPoints[tmpndx].X = (int)(tmpplane.Points[tmpndx].X * lScaling) + offsetx; lTempPanelPoints[tmpndx].Y = (int)(tmpplane.Points[tmpndx].Y * lScaling) + offsety; } gfx.FillPolygon(lFillbrush, lTempPanelPoints); gfx.DrawLine(lOutlinepen, lTempPanelPoints[0], lTempPanelPoints[1]); gfx.DrawLine(lOutlinepen, lTempPanelPoints[1], lTempPanelPoints[2]); gfx.DrawLine(lOutlinepen, lTempPanelPoints[2], lTempPanelPoints[3]); gfx.DrawLine(lOutlinepen, lTempPanelPoints[3], lTempPanelPoints[0]); } }
public override void ScaleToElementSize(Graphics gfx) { double minx = 0; double maxx = 0; double miny = 0; double maxy = 0; bool valset = false; ResetMidpoint(); // measure all elements if ((Design != null) && (Design.Elements.Count > 0)) { foreach (DesignElement tmpde in Design.Elements) { if (tmpde.ElementType == DesignElement.ElementTypes.Rect) { int tmpndx; Graphics3D.TransformDesignElement(lPhi, lTheta, tmpde, 0.0F); if (!valset) { minx = tmpde.ProjectedPlanes[0].Points[0].X; maxx = tmpde.ProjectedPlanes[0].Points[0].X; miny = tmpde.ProjectedPlanes[0].Points[0].Y; maxy = tmpde.ProjectedPlanes[0].Points[0].Y; valset = true; } foreach (RectPlane tmpplane in tmpde.ProjectedPlanes) { for (tmpndx = 0; tmpndx < tmpplane.Points.Length; tmpndx++) { if (minx > tmpplane.Points[tmpndx].X) { minx = tmpplane.Points[tmpndx].X; } if (maxx < tmpplane.Points[tmpndx].X) { maxx = tmpplane.Points[tmpndx].X; } if (miny > tmpplane.Points[tmpndx].Y) { miny = tmpplane.Points[tmpndx].Y; } if (maxy < tmpplane.Points[tmpndx].Y) { maxy = tmpplane.Points[tmpndx].Y; } } } // measure label //Point3D lblpt = Graphics3D.TransformSinglePoint(lPhi, lTheta, tmpde.Midpoint, 0.0F); //SizeF strsz = gfx.MeasureString(tmpde.Name, LabelFont); //if (minx > lblpt.X) // minx = lblpt.X; //if (maxx < lblpt.X) // maxx = lblpt.X; //if (miny > lblpt.Y) // miny = lblpt.Y; //if (maxy < lblpt.Y) // maxy = lblpt.Y; } } } // draw coordinates if (ShowAxes) { SetAxisPoints(); // draw X cooridate Point3D pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisX[0], 0.0F); Point3D pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisX[1], 0.0F); if (minx > pt1.X) { minx = pt1.X; } if (maxx < pt1.X) { maxx = pt1.X; } if (miny > pt1.Y) { miny = pt1.Y; } if (maxy < pt1.Y) { maxy = pt1.Y; } if (minx > pt2.X) { minx = pt2.X; } if (maxx < pt2.X) { maxx = pt2.X; } if (miny > pt2.Y) { miny = pt2.Y; } if (maxy < pt2.Y) { maxy = pt2.Y; } //gfx.DrawString("+X", LabelFont, Brushes.Black, gpt1); //gfx.DrawString("-X", LabelFont, Brushes.Black, gpt2); // draw Y cooridate pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisY[0], 0.0F); pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisY[1], 0.0F); if (minx > pt1.X) { minx = pt1.X; } if (maxx < pt1.X) { maxx = pt1.X; } if (miny > pt1.Y) { miny = pt1.Y; } if (maxy < pt1.Y) { maxy = pt1.Y; } if (minx > pt2.X) { minx = pt2.X; } if (maxx < pt2.X) { maxx = pt2.X; } if (miny > pt2.Y) { miny = pt2.Y; } if (maxy < pt2.Y) { maxy = pt2.Y; } //gfx.DrawString("+Y", LabelFont, Brushes.Black, gpt1); //gfx.DrawString("-Y", LabelFont, Brushes.Black, gpt2); // draw Z cooridate pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisZ[0], 0.0F); pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisZ[1], 0.0F); if (minx > pt1.X) { minx = pt1.X; } if (maxx < pt1.X) { maxx = pt1.X; } if (miny > pt1.Y) { miny = pt1.Y; } if (maxy < pt1.Y) { maxy = pt1.Y; } if (minx > pt2.X) { minx = pt2.X; } if (maxx < pt2.X) { maxx = pt2.X; } if (miny > pt2.Y) { miny = pt2.Y; } if (maxy < pt2.Y) { maxy = pt2.Y; } //gfx.DrawString("+Z", LabelFont, Brushes.Black, gpt1); //gfx.DrawString("-Z", LabelFont, Brushes.Black, gpt2); } double xdiff = maxx - minx; double ydiff = maxy - miny; double scalex = (double)Width / xdiff; double scaley = (double)Height / ydiff; lScaling = (scalex > scaley ? scaley : scalex); EffectiveWidth = (int)(xdiff * lScaling); EffectiveHeight = (int)(ydiff * lScaling); }
public override int PaintElement(Graphics gfx, Rectangle displayrect, Point origintranslate, bool printing) { int outy = OffsetY - displayrect.Y + origintranslate.Y; int outx = OffsetX - displayrect.X + origintranslate.X; int tofstx = lMidpointX + OffsetX - displayrect.X + origintranslate.X; int tofsty = lMidpointY + OffsetY - displayrect.Y + origintranslate.Y; // draw all elements if ((Design != null) && (Design.Elements.Count > 0)) { foreach (DesignElement tmpde in Design.Elements) { if ((lSingleElement.Length == 0) || (lSingleElement.Equals(tmpde.Name))) { if (tmpde.ElementType == DesignElement.ElementTypes.Rect) { lDrawDesignElement(gfx, tmpde, tofstx, tofsty); // draw label if (lShowLabels) { Point3D lblpt = Graphics3D.TransformSinglePoint(Phi, Theta, tmpde.Midpoint, 0.0F); gfx.DrawString(tmpde.Name, LabelFont, Brushes.Black, new PointF((float)(lblpt.X * lScaling) + tofstx, (float)(lblpt.Y * lScaling) + tofsty)); } } } } } // draw coordinates if (lShowAxes) { Pen outlinepen = new Pen(Color.Black); SetAxisPoints(); // draw X cooridate Point3D pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisX[0], 0.0F); Point3D pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisX[1], 0.0F); PointF gpt1 = new PointF((float)(pt1.X * lScaling) + tofstx, (float)(pt1.Y * lScaling) + tofsty); PointF gpt2 = new PointF((float)(pt2.X * lScaling) + tofstx, (float)(pt2.Y * lScaling) + tofsty); gfx.DrawLine(outlinepen, gpt1, gpt2); // (float)(pt1.X * lScaling) + lMidpointX, (float)(pt1.Y * lScaling) + lMidpointX, (float)(pt2.X * lScaling) +lMidpointX, (float)(pt2.Y * lScaling) +lMidpointX); gfx.DrawString("+X", LabelFont, Brushes.Black, gpt1); gfx.DrawString("-X", LabelFont, Brushes.Black, gpt2); // draw Y cooridate pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisY[0], 0.0F); pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisY[1], 0.0F); gpt1.X = (float)(pt1.X * lScaling) + tofstx; gpt1.Y = (float)(pt1.Y * lScaling) + tofsty; gpt2.X = (float)(pt2.X * lScaling) + tofstx; gpt2.Y = (float)(pt2.Y * lScaling) + tofsty; gfx.DrawLine(outlinepen, gpt1, gpt2); // (float)(pt1.X * lScaling) + lMidpointX, (float)(pt1.Y * lScaling) + lMidpointX, (float)(pt2.X * lScaling) +lMidpointX, (float)(pt2.Y * lScaling) +lMidpointX); gfx.DrawString("+Y", LabelFont, Brushes.Black, gpt1); gfx.DrawString("-Y", LabelFont, Brushes.Black, gpt2); // draw Z cooridate pt1 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisZ[0], 0.0F); pt2 = Graphics3D.TransformSinglePoint(Phi, Theta, lAxisZ[1], 0.0F); gpt1.X = (float)(pt1.X * lScaling) + tofstx; gpt1.Y = (float)(pt1.Y * lScaling) + tofsty; gpt2.X = (float)(pt2.X * lScaling) + tofstx; gpt2.Y = (float)(pt2.Y * lScaling) + tofsty; gfx.DrawLine(outlinepen, gpt1, gpt2); // (float)(pt1.X * lScaling) + lMidpointX, (float)(pt1.Y * lScaling) + lMidpointX, (float)(pt2.X * lScaling) +lMidpointX, (float)(pt2.Y * lScaling) +lMidpointX); gfx.DrawString("+Z", LabelFont, Brushes.Black, gpt1); gfx.DrawString("-Z", LabelFont, Brushes.Black, gpt2); } return(OffsetY + Height); }