public void AnnTransformer_AnnTransformer() { // set up a new unit converter with 96 DPI AnnUnitConverter converter = new AnnUnitConverter(96, 96); // set up a new matrix, scale it by 2,2 around the origin Matrix transform = new Matrix(); transform.Scale(2, 2); // set up the AnnTransformer AnnTransformer transformer = new AnnTransformer(converter, transform); // declare a new AnnPoint at 4, 5 inches // transform it to physical coordinate using the transformer and show it in pixels // then transform it back to its original logical coordinates Console.WriteLine("Point{0}--------", Environment.NewLine); AnnPoint pt1 = new AnnPoint(4, 5, AnnUnit.Inch); PrintOut(converter, " Original: ", pt1); AnnPoint pt2 = transformer.PointToPhysical(pt1); PrintOut(converter, " Physical: ", pt2); AnnPoint pt3 = transformer.PointToLogical(pt2); PrintOut(converter, " Logical : ", pt3); // declare an array of AnnPoints, do the same Console.WriteLine("Points{0}--------", Environment.NewLine); AnnPoint[] pts1 = { new AnnPoint(4, 5, AnnUnit.Inch), new AnnPoint(5.2f, 3, AnnUnit.Inch), new AnnPoint(2, 7.83f, AnnUnit.Inch), }; PrintOut(converter, " Original: ", pts1); AnnPoint[] pts2 = transformer.PointToPhysical(pts1); PrintOut(converter, " Physical: ", pts2); AnnPoint[] pts3 = transformer.PointToLogical(pts2); PrintOut(converter, " Logical : ", pts3); // declare a rectangle, do the same Console.WriteLine("Rectangle{0}--------", Environment.NewLine); AnnRectangle rc1 = new AnnRectangle(2, 3, 4, 1, AnnUnit.Inch); PrintOut(converter, " Original: ", rc1); AnnRectangle rc2 = transformer.RectangleToPhysical(rc1); PrintOut(converter, " Physical: ", rc2); AnnRectangle rc3 = transformer.RectangleToLogical(rc2); PrintOut(converter, " Logical : ", rc3); // declare a length, do the same Console.WriteLine("Length{0}--------", Environment.NewLine); AnnLength l1 = new AnnLength(10.5f, AnnUnit.Inch); PrintOut(converter, " Original: ", l1); AnnLength l2 = transformer.LengthToPhysical(l1); PrintOut(converter, " Physical: ", l2); AnnLength l3 = transformer.LengthToLogical(l2); PrintOut(converter, " Logical : ", l3); transform.Dispose(); } private void PrintOut(AnnUnitConverter converter, string text, AnnPoint pt) { Console.WriteLine("{0}{1}({2})", text, pt.ConvertTo(converter, AnnUnit.Inch), pt.ConvertTo(converter, AnnUnit.Pixel)); } private void PrintOut(AnnUnitConverter converter, string text, AnnPoint[] pts) { Console.WriteLine(text); for(int i = 0; i < pts.Length; i++) { Console.WriteLine(" {0}. {1}({2})", i, pts[i].ConvertTo(converter, AnnUnit.Inch), pts[i].ConvertTo(converter, AnnUnit.Pixel)); } } private void PrintOut(AnnUnitConverter converter, string text, AnnRectangle rc) { Console.WriteLine("{0}{1}({2})", text, rc.ConvertTo(converter, AnnUnit.Inch), rc.ConvertTo(converter, AnnUnit.Pixel)); } private void PrintOut(AnnUnitConverter converter, string text, AnnLength ln) { Console.WriteLine("{0}{1}({2})", text, new AnnLength(ln.Converted(converter, AnnUnit.Inch), AnnUnit.Inch), new AnnLength(ln.Converted(converter, AnnUnit.Pixel), AnnUnit.Pixel)); } |