' ViewportExtensionMethods.cs (c) 2007-2012 Tony Tanzillo
' Converted from C# to VB.NET
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.DatabaseServices
Public Module ViewportExtensionMethods
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function GetModelToPaperTransform(vport As Viewport) As Matrix3d
If vport.PerspectiveOn Then
Throw New NotSupportedException("Perspective views not supported")
End If
Dim center As Point3d = New Point3d(vport.ViewCenter.X, vport.ViewCenter.Y, 0.0)
Return Matrix3d.Displacement(New Vector3d(vport.CenterPoint.X - center.X, vport.CenterPoint.Y - center.Y, 0.0)) *
Matrix3d.Scaling(vport.CustomScale, center) * Matrix3d.Rotation(vport.TwistAngle, Vector3d.ZAxis, Point3d.Origin) *
Matrix3d.WorldToPlane(New Plane(vport.ViewTarget, vport.ViewDirection))
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function GetPaperToModelTransform(vport As Viewport) As Matrix3d
Return vport.GetModelToPaperTransform().Inverse()
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function PaperToModel(point As Point3d, vport As Viewport) As Point3d
Return point.TransformBy(vport.GetModelToPaperTransform().Inverse())
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function ModelToPaper(point As Point3d, viewport As Viewport) As Point3d
Return point.TransformBy(viewport.GetModelToPaperTransform())
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Sub PaperToModel(entity As Entity, vport As Viewport)
entity.TransformBy(vport.GetModelToPaperTransform().Inverse())
End Sub
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Sub ModelToPaper(entity As Entity, viewport As Viewport)
entity.TransformBy(viewport.GetModelToPaperTransform())
End Sub
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function PaperToModel(source As IEnumerable(Of Point3d), viewport As Viewport) As IEnumerable(Of Point3d)
Dim xform As Matrix3d = viewport.GetModelToPaperTransform().Inverse()
Return source.[Select](Function(p As Point3d) p.TransformBy(xform))
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Function ModelToPaper(source As IEnumerable(Of Point3d), viewport As Viewport) As IEnumerable(Of Point3d)
Dim xform As Matrix3d = viewport.GetModelToPaperTransform()
Return source.[Select](Function(p As Point3d) p.TransformBy(xform))
End Function
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Sub PaperToModel(src As IEnumerable(Of Entity), viewport As Viewport)
Dim xform As Matrix3d = viewport.GetModelToPaperTransform().Inverse()
For Each ent As Entity In src
ent.TransformBy(xform)
Next
End Sub
<System.Runtime.CompilerServices.ExtensionAttribute()>
Public Sub ModelToPaper(src As IEnumerable(Of Entity), viewport As Viewport)
Dim xform As Matrix3d = viewport.GetModelToPaperTransform()
For Each ent As Entity In src
ent.TransformBy(xform)
Next
End Sub
End Module