' Autor: EsKaRaLaKaKaTua
' Descripción: Curve para VB.NET
' Version: 1.0.1.0
' Fecha: 14 de Febrero de 2009
Imports System
Imports System.Collections.Generic
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Friend Class Curve
Implements IDisposable
Private ReadOnly _vlax As VLAX
Private _entity As AcadEntity
Private Shared ReadOnly _allowedTypes As List(Of String) = GetAllowedTypes()
Friend Sub New(ByVal instance As AcadApplication)
_vlax = New VLAX(instance)
End Sub
Friend ReadOnly Property Area() As Double
Get
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
result = CDbl(.EvalLispExpression("(vlax-curve-getArea (handent handle))"))
.NullifySymbol("handle")
End With
Return result
End Get
End Property
Friend ReadOnly Property Closed() As Boolean
Get
Dim result As Boolean
With _vlax
.SetLispSymbol("handle", _entity.Handle)
result = CBool(.EvalLispExpression("(vlax-curve-isClosed (handent handle))"))
.NullifySymbol("handle")
End With
Return result
End Get
End Property
Friend ReadOnly Property CurveType() As String
Get
Return _entity.ObjectName
End Get
End Property
Friend ReadOnly Property EndParameter() As Double
Get
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
result = CDbl(.EvalLispExpression("(vlax-curve-getEndParam (handent handle))"))
.NullifySymbol("handle")
End With
Return result
End Get
End Property
Friend ReadOnly Property Endpoint() As Double()
Get
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.EvalLispExpression("(setq lst (vlax-curve-getEndPoint (handent handle)))")
result = .GetLispList("lst")
.NullifySymbol("handle", "lst")
End With
Return GetDoubleArray(result)
End Get
End Property
Friend Property Entity() As AcadEntity
Get
Return _entity
End Get
Set(ByVal value As AcadEntity)
If Not _allowedTypes.Contains(value.ObjectName) Then
Throw New Exception("La entidad no es una curva")
End If
_entity = value
End Set
End Property
Friend ReadOnly Property Length() As Double
Get
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.EvalLispExpression("(setq curve (handent handle))")
result = CDbl(.EvalLispExpression("(vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))"))
.NullifySymbol("handle", "curve")
End With
Return result
End Get
End Property
Friend ReadOnly Property Periodic() As Boolean
Get
Dim result As Boolean
With _vlax
.SetLispSymbol("handle", _entity.Handle)
result = CBool(.EvalLispExpression("(vlax-curve-isPeriodic (handent handle))"))
.NullifySymbol("handle")
End With
Return result
End Get
End Property
Friend ReadOnly Property Planar() As Boolean
Get
Dim result As Boolean
With _vlax
.SetLispSymbol("handle", _entity.Handle)
result = CBool(.EvalLispExpression("(vlax-curve-isPlanar (handent handle))"))
.NullifySymbol("handle")
End With
Return result
End Get
End Property
Friend ReadOnly Property StartPoint() As Double()
Get
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.EvalLispExpression("(setq lst (vlax-curve-getStartPoint (handent handle)))")
result = .GetLispList("lst")
.NullifySymbol("handle", "lst")
End With
Return GetDoubleArray(result)
End Get
End Property
Friend Function GetClosestPointTo(ByVal Point As Object, _
Optional ByVal Extend As Boolean = False) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("givenPt", Point)
If Extend Then .EvalLispExpression("(setq ext T)")
.EvalLispExpression("(setq lst (vlax-curve-getClosestPointTo (handent handle) givenPt ext))")
result = .GetLispList("lst")
.NullifySymbol("handle", "lst", "ext", "givenPt")
End With
Return GetDoubleArray(result)
End Function
Friend Function GetClosestPointToProjection(ByVal Point As Object, _
ByVal Normal As Object, _
Optional ByVal Extend As Boolean = False) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("givenPt", Point)
.SetLispSymbol("normal", Normal)
If Extend Then
.EvalLispExpression("(setq ext T)")
End If
.EvalLispExpression("(setq lst (vlax-curve-getClosestPointToProjection (handent handle) givenPt normal ext))")
result = .GetLispList("lst")
.NullifySymbol("handle", "lst", "normal", "ext", "givenPt")
End With
Return GetDoubleArray(result)
End Function
Public Function GetDistanceAtParameter(ByVal Param As Double) As Double
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("param", Param)
result = CDbl(.EvalLispExpression("(vlax-curve-getDistAtParam (handent handle) param)"))
.NullifySymbol("handle", "param")
End With
Return result
End Function
Friend Function GetDistanceAtPoint(ByVal Point As Object) As Double
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("point", Point)
result = CDbl(.EvalLispExpression("(vlax-curve-getDistAtPoint (handent handle) point)"))
.NullifySymbol("handle", "point")
End With
Return result
End Function
Friend Function GetFirstDerivative(ByVal Param As Double) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("param", Param)
.EvalLispExpression("(setq lst (vlax-curve-getFirstDeriv (handent handle) param))")
result = .GetLispList("lst")
.NullifySymbol("handle", "param", "lst")
End With
Return GetDoubleArray(result)
End Function
Friend Function GetParameterAtDistance(ByVal Dist As Double) As Double
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("dist", Dist)
result = CDbl(.EvalLispExpression("(vlax-curve-getParamAtDist (handent handle) dist)"))
.NullifySymbol("handle", "dist")
End With
Return result
End Function
Friend Function GetParameterAtPoint(ByVal Point As Object) As Double
Dim result As Double
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("point", Point)
result = CDbl(.EvalLispExpression("(vlax-curve-getparamAtPoint (handent handle) point)"))
.NullifySymbol("handle", "point")
End With
Return result
End Function
Friend Function GetPointAtDistance(ByVal Dist As Double) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("dist", Dist)
.EvalLispExpression("(setq lst (vlax-curve-getPointAtDist (handent handle) dist))")
result = .GetLispList("lst")
.NullifySymbol("handle", "dist", "lst")
End With
Return GetDoubleArray(result)
End Function
Friend Function GetPointAtParameter(ByVal Param As Double) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("param", Param)
.EvalLispExpression("(setq lst (vlax-curve-getPointAtParam (handent handle) param))")
result = .GetLispList("lst")
.NullifySymbol("handle", "param", "lst")
End With
Return GetDoubleArray(result)
End Function
Friend Function GetSecondDerivative(ByVal Param As Double) As Double()
Dim result() As Object
With _vlax
.SetLispSymbol("handle", _entity.Handle)
.SetLispSymbol("param", Param)
.EvalLispExpression("(setq lst (vlax-curve-getSecondDeriv (handent handle) param))")
result = .GetLispList("lst")
.NullifySymbol("handle", "param", "lst")
End With
Return GetDoubleArray(result)
End Function
Private Shared Function GetDoubleArray(ByVal obj() As Object) As Double()
Dim result(obj.Length - 1) As Double
For i As Integer = 0 To obj.Length - 1
result(i) = CDbl(obj(i))
Next
Return result
End Function
Private Shared Function GetAllowedTypes() As List(Of String)
Dim list As New List(Of String)
list.Add("AcDbCircle")
list.Add("AcDbLine")
list.Add("AcDbArc")
list.Add("AcDbSpline")
list.Add("AcDb3dPolyline")
list.Add("AcDbPolyline")
list.Add("AcDb2dPolyline")
list.Add("AcDbEllipse")
list.Add("AcDbLeader")
Return list
End Function
Private disposedValue As Boolean
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
_vlax.Dispose()
End If
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
Public Sub Dispose() _
Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class