public BasicLayoutRenderInfo(IViewDescription viewDescription) { double val1 = viewDescription.ViewportWidth / viewDescription.ViewWidth; double val2 = viewDescription.ViewportHeight / viewDescription.ViewHeight; if (DxfUtil.IsSaneNotZero(val1) && DxfUtil.IsSaneNotZero(val2)) { this.ModelToLayoutScaling = System.Math.Min(val1, val2); Vector2D vector2D = val1 > val2 ? new Vector2D(0.5 * val2 / val1 * viewDescription.ViewportWidth, 0.5 * viewDescription.ViewportHeight) : new Vector2D(0.5 * viewDescription.ViewportWidth, 0.5 * val1 / val2 * viewDescription.ViewportHeight); WW.Math.Point2D viewportCenter = (WW.Math.Point2D)viewDescription.ViewportCenter; this.LayoutViewport = new Bounds2D(viewportCenter - vector2D, viewportCenter + vector2D); this.ModelToLayoutTransform = Transformation4D.Translation((WW.Math.Vector3D)viewDescription.ViewportCenter) * Transformation4D.Scaling(this.ModelToLayoutScaling) * ViewUtil.GetBasicModelToViewportTransform(viewDescription) * Transformation4D.Translation(-(WW.Math.Vector3D)viewDescription.ViewportCenter); } else { this.LayoutViewport = new Bounds2D(); this.ModelToLayoutTransform = Matrix4D.Identity; this.ModelToLayoutScaling = 0.0; } }
private DxfLayout.PlotInfo GetPlotInfo( bool invertY, DxfLayout.BasicLayoutRenderInfo layoutRenderInfo) { Size2D plotPaperSize = this.PlotPaperSize; if (plotPaperSize.X == 0.0 || plotPaperSize.Y == 0.0) { return((DxfLayout.PlotInfo)null); } double y = invertY ? this.UnprintableMarginBottom : plotPaperSize.Y - this.UnprintableMarginTop; WW.Math.Point3D toPoint1 = new WW.Math.Point3D(this.UnprintableMarginLeft, invertY ? plotPaperSize.Y - this.UnprintableMarginTop : this.UnprintableMarginBottom, 0.0); WW.Math.Point3D toPoint2 = new WW.Math.Point3D(plotPaperSize.X - this.UnprintableMarginRight, y, 0.0); WW.Math.Point3D toReferencePoint = new WW.Math.Point3D(0.5 * (toPoint1.X + toPoint2.X), 0.5 * (toPoint1.Y + toPoint2.Y), 0.0); Matrix4D matrix4D1 = Matrix4D.Identity; switch (this.PlotRotation) { case PlotRotation.QuarterCounterClockwise: matrix4D1 = Transformation4D.RotateZ(System.Math.PI / 2.0); break; case PlotRotation.Half: matrix4D1 = Transformation4D.RotateZ(System.Math.PI); break; case PlotRotation.QuarterClockwise: matrix4D1 = Transformation4D.RotateZ(-1.0 * System.Math.PI / 2.0); break; } if (invertY) { matrix4D1 *= Transformation4D.Scaling(1.0, -1.0, 1.0); } WW.Math.Point3D point3D1 = new WW.Math.Point3D(layoutRenderInfo.LayoutViewport.Min, 0.0); WW.Math.Point3D point3D2 = new WW.Math.Point3D(layoutRenderInfo.LayoutViewport.Max, 0.0); WW.Math.Point3D fromReferencePoint = new WW.Math.Point3D(layoutRenderInfo.LayoutViewport.Center, 0.0); Matrix4D matrix4D2 = Transformation4D.Translation((WW.Math.Vector3D)fromReferencePoint) * matrix4D1 * Transformation4D.Translation(-(WW.Math.Vector3D)fromReferencePoint); WW.Math.Point3D point3D3 = matrix4D2 * point3D1; point3D2 = matrix4D2 * point3D2; double scaling; Matrix4D toPaperTransform = DxfUtil.GetScaleTransform(new WW.Math.Point3D(System.Math.Min(point3D3.X, point3D2.X), System.Math.Min(point3D3.Y, point3D2.Y), 0.0), new WW.Math.Point3D(System.Math.Max(point3D3.X, point3D2.X), System.Math.Max(point3D3.Y, point3D2.Y), 0.0), fromReferencePoint, toPoint1, toPoint2, toReferencePoint, out scaling) * matrix4D2; return(new DxfLayout.PlotInfo(this, plotPaperSize, new Rectangle2D(toPoint1.X, System.Math.Min(toPoint1.Y, toPoint2.Y), toPoint2.X, System.Math.Max(toPoint1.Y, toPoint2.Y)), toPaperTransform, scaling)); }
internal void method_0( DxfTableContent tableContent, double width, double height, double rotation, double horizontalMargin, double verticalMargin) { DxfBlock valueObject = this.ValueObject as DxfBlock; if (valueObject == null) { this.dxfContentFormat_0.method_6(1.0); } else { DxfInsert dxfInsert = new DxfInsert(valueObject); foreach (DxfTableAttribute dxfTableAttribute in (List <DxfTableAttribute>) this.dxfTableAttributeCollection_0) { if (dxfTableAttribute.AttributeDefinition != null) { DxfAttribute dxfAttribute1 = new DxfAttribute(dxfTableAttribute.AttributeDefinition); dxfAttribute1.Text = dxfTableAttribute.Value; DxfAttribute dxfAttribute2 = dxfAttribute1; dxfAttribute2.AlignmentPoint1 = dxfAttribute2.AlignmentPoint1 - valueObject.BasePoint; if (dxfAttribute1.AlignmentPoint2.HasValue) { DxfAttribute dxfAttribute3 = dxfAttribute1; WW.Math.Point3D? alignmentPoint2 = dxfAttribute3.AlignmentPoint2; WW.Math.Vector3D basePoint = valueObject.BasePoint; dxfAttribute3.AlignmentPoint2 = alignmentPoint2.HasValue ? new WW.Math.Point3D?(alignmentPoint2.GetValueOrDefault() - basePoint) : new WW.Math.Point3D?(); } } } BoundsCalculator boundsCalculator = new BoundsCalculator(); boundsCalculator.GetBounds(tableContent.Model, (DxfEntity)dxfInsert); Bounds3D bounds = boundsCalculator.Bounds; Matrix4D transform = Transformation4D.Translation(valueObject.BasePoint) * Transformation4D.RotateZ(rotation) * Transformation4D.Translation(-valueObject.BasePoint); bounds.Transform(transform); Vector2D vector2D = new Vector2D((width - 2.0 * horizontalMargin) / bounds.Delta.X, (height - 2.0 * verticalMargin) / bounds.Delta.Y); this.dxfContentFormat_0.BlockScale = System.Math.Min(vector2D.X, vector2D.Y); } }
internal Bounds3D method_1(DxfTable table) { DxfBlock valueObject = this.ValueObject as DxfBlock; if (valueObject == null) { return((Bounds3D)null); } DxfInsert dxfInsert = new DxfInsert(valueObject); foreach (DxfTableAttribute dxfTableAttribute in (List <DxfTableAttribute>) this.dxfTableAttributeCollection_0) { if (dxfTableAttribute.AttributeDefinition != null) { DxfAttribute dxfAttribute1 = new DxfAttribute(dxfTableAttribute.AttributeDefinition); dxfAttribute1.Text = dxfTableAttribute.Value; DxfAttribute dxfAttribute2 = dxfAttribute1; dxfAttribute2.AlignmentPoint1 = dxfAttribute2.AlignmentPoint1 - valueObject.BasePoint; if (dxfAttribute1.AlignmentPoint2.HasValue) { DxfAttribute dxfAttribute3 = dxfAttribute1; WW.Math.Point3D? alignmentPoint2 = dxfAttribute3.AlignmentPoint2; WW.Math.Vector3D basePoint = valueObject.BasePoint; dxfAttribute3.AlignmentPoint2 = alignmentPoint2.HasValue ? new WW.Math.Point3D?(alignmentPoint2.GetValueOrDefault() - basePoint) : new WW.Math.Point3D?(); } } } BoundsCalculator boundsCalculator = new BoundsCalculator(); boundsCalculator.GetBounds(table.Content.Model, (DxfEntity)dxfInsert); Bounds3D bounds = boundsCalculator.Bounds; Matrix4D transform = Transformation4D.Translation(valueObject.BasePoint) * Transformation4D.RotateZ(this.dxfContentFormat_0.Rotation) * Transformation4D.Translation(-valueObject.BasePoint); bounds.Transform(transform); return(bounds); }
public DxfAttribute AddAttribute(DxfAttributeDefinition attdef, string text) { DxfAttribute dxfAttribute = new DxfAttribute(attdef, text); this.Attributes.Add(dxfAttribute); if (dxfAttribute.Model == null) { try { dxfAttribute.Style = attdef.Style; } catch (NullReferenceException ex) { throw new DxfException("Cannot create attribute from attribute definition which is not attached to a model!\nDid you already add the attribute definition to a block and the block to the model's Blocks?"); } } WW.Math.Vector3D vector3D = this.Block != null ? this.Block.BasePoint : WW.Math.Vector3D.Zero; dxfAttribute.FixAlignmentPoints(); dxfAttribute.TransformMe((TransformConfig)GraphicsConfig.WhiteBackground, this.BasicBlockInsertionTransformation * Transformation4D.Translation(-vector3D)); return(dxfAttribute); }
private void DrawInternal(DxfInsert.Interface46 drawHandler, bool drawBlock) { Matrix4D toWcsTransform = DxfUtil.GetToWCSTransform(this.ZAxis); Matrix4D matrix4D1 = Transformation4D.Translation((WW.Math.Vector3D) this.InsertionPoint); Matrix4D matrix4D2 = Transformation4D.RotateZ(this.Rotation); Matrix4D matrix4D3 = Transformation4D.Scaling(this.ScaleFactor); ushort num1 = this.RowCount; if (num1 < (ushort)1) { num1 = (ushort)1; } ushort num2 = this.ColumnCount; if (num2 < (ushort)1) { num2 = (ushort)1; } for (int row = 0; row < (int)num1; ++row) { for (int column = 0; column < (int)num2; ++column) { if (drawBlock) { Matrix4D matrix4D4 = toWcsTransform * matrix4D1 * matrix4D2 * Transformation4D.Translation((double)column * this.ColumnSpacing, (double)row * this.RowSpacing, 0.0) * matrix4D3; drawHandler.imethod_0(row, column, matrix4D4); if (this.Block != null) { switch (this.method_16(matrix4D4, drawHandler)) { case DxfInsert.Enum44.const_1: case DxfInsert.Enum44.const_2: drawHandler.Draw(this.Block, true); break; case DxfInsert.Enum44.const_3: drawHandler.Draw(this.Block, true); drawHandler.InsertCellDrawContext.vmethod_1(); break; } } } if (this.Attributes.Count > 0) { WW.Math.Vector3D vector = new WW.Math.Vector3D((double)column * this.ColumnSpacing, (double)row * this.RowSpacing, 0.0); vector = (toWcsTransform * matrix4D2).Transform(vector); Matrix4D instanceTransform = Transformation4D.Translation(vector.X, vector.Y, vector.Z); drawHandler.imethod_1(row, column, instanceTransform); foreach (DxfAttribute attribute in (IEnumerable <DxfAttribute>) this.Attributes) { drawHandler.Draw(attribute); } } } } }
public static Matrix4D Scaling(Vector3D v, Point3D origin) { Vector3D v1 = (Vector3D)origin; return(Transformation4D.Translation(v1) * Transformation4D.Scaling(v) * Transformation4D.Translation(-v1)); }
public static Matrix4D Scaling(double s, Point3D origin) { Vector3D v = (Vector3D)origin; return(Transformation4D.Translation(v) * Transformation4D.Scaling(s) * Transformation4D.Translation(-v)); }
public static Matrix4D GetScaleTransform( Point3D fromPoint1, Point3D fromPoint2, Point3D fromReferencePoint, Point3D toPoint1, Point3D toPoint2, Point3D toReferencePoint, out double scaling) { Vector3D vector3D1 = toPoint2 - toPoint1; Vector3D vector3D2 = fromPoint2 - fromPoint1; double num1 = vector3D1.X / vector3D2.X; double num2 = vector3D1.Y / vector3D2.Y; scaling = System.Math.Abs(num1) <= System.Math.Abs(num2) ? num1 : num2; scaling = System.Math.Abs(scaling); Matrix4D matrix4D = Transformation4D.Translation(0.0, 0.0, toPoint1.Z) * Transformation4D.Scaling(scaling * (double)System.Math.Sign(num1), scaling * (double)System.Math.Sign(num2), scaling) * Transformation4D.Translation(0.0, 0.0, -fromPoint1.Z); Point3D point3D = matrix4D.Transform(fromReferencePoint); return(Transformation4D.Translation(toReferencePoint - point3D) * matrix4D); }
public static Matrix4D GetScaleAndTranslateTransform( Point2D fromP1, Point2D fromP2, Point2D toP1, Point2D toP2) { double x = (toP2.X - toP1.X) / (fromP2.X - fromP1.X); double y = (toP2.Y - toP1.Y) / (fromP2.Y - fromP1.Y); Point2D midPoint1 = Point2D.GetMidPoint(toP1, toP2); Point2D midPoint2 = Point2D.GetMidPoint(fromP1, fromP2); return(Transformation4D.Translation(midPoint1.X, midPoint1.Y, 0.0) * Transformation4D.Scaling(x, y, 1.0) * Transformation4D.Translation(-midPoint2.X, -midPoint2.Y, 0.0)); }
internal static IList <Class908> smethod_6( DxfText text, Color color, short lineWeight, Matrix4D insertionTransformation, Bounds2D collectBounds, out Vector2D alignmentTranslation, out Vector2D alignmentScaling) { Class425 class425 = Class594.smethod_10(text.DisplayString, text.Height, text.ObliqueAngle, text.WidthFactor, text.Style, color); Vector2D zero = Vector2D.Zero; class425.imethod_0(ref zero, text.Height, Enum24.flag_3); alignmentTranslation = Vector2D.Zero; Bounds2D bounds = class425.GetBounds(Enum24.flag_0, (Class985)null); if (zero != Vector2D.Zero) { bounds.Update(0.0, 0.0); bounds.Update(zero.X, zero.Y); } double x = 1.0; double y = 1.0; if (bounds.Initialized && text.AlignmentPoint2.HasValue) { if (text.VerticalAlignment != TextVerticalAlignment.Baseline) { switch (text.VerticalAlignment) { case TextVerticalAlignment.Bottom: alignmentTranslation.Y = class425.Blocks.Count > 0 ? class425.Blocks.First.Value.Settings.Font.Metrics.Descent : -bounds.Min.Y; break; case TextVerticalAlignment.Middle: alignmentTranslation.Y = -0.5 * text.Height; break; case TextVerticalAlignment.Top: alignmentTranslation.Y = -text.Height; break; } } switch (text.HorizontalAlignment) { case TextHorizontalAlignment.Left: alignmentTranslation.X = -bounds.Corner1.X; break; case TextHorizontalAlignment.Center: alignmentTranslation.X = -bounds.Center.X; break; case TextHorizontalAlignment.Right: alignmentTranslation.X = -bounds.Corner2.X; break; case TextHorizontalAlignment.Aligned: x = (text.AlignmentPoint2.Value - text.AlignmentPoint1).GetLength() / bounds.Delta.X; y = x; bounds = new Bounds2D(new WW.Math.Point2D(bounds.Corner1.X, y * bounds.Corner1.Y), new WW.Math.Point2D(bounds.Corner1.X + x * bounds.Delta.X, y * bounds.Corner2.Y)); alignmentTranslation.X = -bounds.Corner2.X; break; case TextHorizontalAlignment.Middle: alignmentTranslation.Y = -bounds.Center.Y; alignmentTranslation.X = -bounds.Center.X; break; case TextHorizontalAlignment.Fit: x = (text.AlignmentPoint2.Value - text.AlignmentPoint1).GetLength() / bounds.Delta.X; bounds = new Bounds2D(bounds.Corner1, new WW.Math.Point2D(bounds.Corner1.X + x * bounds.Delta.X, bounds.Corner2.Y)); alignmentTranslation.X = -bounds.Corner2.X; break; } } IList <Class908> class908List = (IList <Class908>) new List <Class908>(); class425.imethod_3((ICollection <Class908>)class908List, insertionTransformation * Transformation4D.Translation(alignmentTranslation.X, alignmentTranslation.Y, 0.0) * Transformation4D.Scaling(x, y, 1.0), lineWeight); if (collectBounds != null) { bounds.Move(alignmentTranslation.X, alignmentTranslation.Y); collectBounds.Update(bounds); } alignmentScaling = new Vector2D(x, y); return(class908List); }
private void method_0( IShape2D path, Color color, Matrix4D transform, bool filled, double extrusion, bool isChar) { if (!path.HasSegments) { return; } ISurfaceGraphicsFactory graphicsFactory0 = this.isurfaceGraphicsFactory_0; IList <Polyline2D> flattened = (IList <Polyline2D>)ShapeTool.GetFlattened(path, this.surface_0.Config.ShapeFlattenEpsilon); this.isurfaceGraphicsFactory_0.SetColor(this.surface_0.GetPlotColor(this.dxfEntity_0, color)); Interface41 transformer = (Interface41)this.surface_0.GetTransformer().Clone(); transformer.SetPreTransform(transform); if (!filled) { IList <Polyline4D> polyline4DList1 = DxfUtil.smethod_48(flattened, transformer); foreach (Polyline4D polyline4D in (IEnumerable <Polyline4D>)polyline4DList1) { graphicsFactory0.CreatePolyline((IList <Vector4D>)polyline4D, polyline4D.Closed); } if (extrusion == 0.0) { return; } transformer.SetPreTransform(Transformation4D.Translation(0.0, 0.0, extrusion)); IList <Polyline4D> polyline4DList2 = DxfUtil.smethod_48(flattened, transformer); foreach (Polyline4D polyline4D in (IEnumerable <Polyline4D>)polyline4DList2) { graphicsFactory0.CreatePolyline((IList <Vector4D>)polyline4D, polyline4D.Closed); } Polyline4D polyline4D1 = new Polyline4D(2); polyline4D1.Add(Vector4D.Zero); polyline4D1.Add(Vector4D.Zero); for (int index1 = polyline4DList1.Count - 1; index1 >= 0; --index1) { Polyline4D polyline4D2 = polyline4DList1[index1]; Polyline4D polyline4D3 = polyline4DList2[index1]; for (int index2 = polyline4D2.Count - 1; index2 >= 0; --index2) { polyline4D1[0] = polyline4D2[index2]; polyline4D1[1] = polyline4D3[index2]; graphicsFactory0.CreatePolyline((IList <Vector4D>)polyline4D1, false); } } } else { List <Triangulator2D.Triangle> triangleList; List <WW.Math.Point2D> point2DList; if (isChar) { Class454 class454 = this.surface_0.CharTriangulationCache.method_0(path, this.surface_0.Config); triangleList = class454.Triangles; point2DList = class454.Points; } else { triangleList = new List <Triangulator2D.Triangle>(); point2DList = new List <WW.Math.Point2D>(); IList <IList <WW.Math.Point2D> > polygons = (IList <IList <WW.Math.Point2D> >) new List <IList <WW.Math.Point2D> >(); foreach (Polyline2D polyline2D in (IEnumerable <Polyline2D>)flattened) { polygons.Add((IList <WW.Math.Point2D>)polyline2D); } Triangulator2D.Triangulate(polygons, (IList <Triangulator2D.Triangle>)triangleList, (IList <WW.Math.Point2D>)point2DList); } Polyline2D polyline = new Polyline2D((IEnumerable <WW.Math.Point2D>)point2DList); Polyline4D polyline4D1 = DxfUtil.smethod_49(polyline, transformer); if (extrusion == 0.0) { for (int index = 0; index < triangleList.Count; ++index) { Triangulator2D.Triangle triangle = triangleList[index]; this.isurfaceGraphicsFactory_0.CreateTriangle(polyline4D1[triangle.I0], polyline4D1[triangle.I1], polyline4D1[triangle.I2], (IList <bool>)null); } } else { if (extrusion == 0.0) { return; } IList <Polyline4D> polyline4DList1 = DxfUtil.smethod_48(flattened, transformer); transformer.SetPreTransform(Transformation4D.Translation(0.0, 0.0, extrusion)); Polyline4D polyline4D2 = DxfUtil.smethod_49(polyline, transformer); IList <Polyline4D> polyline4DList2 = DxfUtil.smethod_48(flattened, transformer); if (extrusion > 0.0) { for (int index = 0; index < triangleList.Count; ++index) { Triangulator2D.Triangle triangle = triangleList[index]; this.isurfaceGraphicsFactory_0.CreateTriangle(polyline4D1[triangle.I0], polyline4D1[triangle.I2], polyline4D1[triangle.I1], (IList <bool>)null); } for (int index = 0; index < triangleList.Count; ++index) { Triangulator2D.Triangle triangle = triangleList[index]; this.isurfaceGraphicsFactory_0.CreateTriangle(polyline4D2[triangle.I0], polyline4D2[triangle.I1], polyline4D2[triangle.I2], (IList <bool>)null); } } else { for (int index = 0; index < triangleList.Count; ++index) { Triangulator2D.Triangle triangle = triangleList[index]; this.isurfaceGraphicsFactory_0.CreateTriangle(polyline4D1[triangle.I0], polyline4D1[triangle.I1], polyline4D1[triangle.I2], (IList <bool>)null); } for (int index = 0; index < triangleList.Count; ++index) { Triangulator2D.Triangle triangle = triangleList[index]; this.isurfaceGraphicsFactory_0.CreateTriangle(polyline4D2[triangle.I0], polyline4D2[triangle.I2], polyline4D2[triangle.I1], (IList <bool>)null); } } for (int index1 = polyline4DList1.Count - 1; index1 >= 0; --index1) { Polyline4D polyline4D3 = polyline4DList1[index1]; Polyline4D polyline4D4 = polyline4DList2[index1]; Polyline2D polyline2D = flattened[index1]; IList <Vector3D> normals = (IList <Vector3D>) new List <Vector3D>(polyline4D3.Count + 1); for (int index2 = 0; index2 < polyline4D3.Count; ++index2) { int index3 = (index2 + 1) % polyline4D3.Count; Vector2D vector2D = polyline2D[index3] - polyline2D[index2]; normals.Add(transformer.Transform(new Vector3D(vector2D.Y, -vector2D.X, 0.0))); } normals.Add(normals[0]); this.isurfaceGraphicsFactory_0.CreateQuadStrip((IList <Vector4D>)polyline4D3, (IList <Vector4D>)polyline4D4, normals, 0, 0); } } } }
public Matrix4D GetTransform() { Matrix4D toWcsTransform = DxfUtil.GetToWCSTransform(this.vector3D_0); toWcsTransform.Transpose(); Matrix4D matrix4D = Transformation4D.RotateZ(this.double_3) * toWcsTransform; return((!this.PerspectiveMode ? Matrix4D.Identity : new Matrix4D(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 / this.double_0, 0.0, 0.0, -1.0 / this.double_0, 0.0) * Transformation4D.Translation(0.0, 0.0, -this.vector3D_0.GetLength())) * Transformation4D.Translation(-this.point2D_0.X, -this.point2D_0.Y, 0.0) * matrix4D * Transformation4D.Translation(-(Vector3D)this.point3D_0)); }