Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
You specify units value that cannot be converted to pixels
Rank: Advanced Member
Groups: Guest
Joined: 3/3/2008(UTC) Posts: 185
Thanks: 8 times
|
Hi, We have a code as below to "reset" the vobject angle. But, sometimes, it does crash... and here are the error message that we get... Mod - _PaneDesign, Proc - ResetAngle, Ln 10 5 - You specify units value that cannot be converted to pixels.(Aurigma.GraphicsMill) May I know what can we do to prevent this? Thanks. Code:
Public Sub ResetAngle()
Const ProcedureName = "ResetAngle"
1: Try
2: Dim obj As Aurigma.GraphicsMill.WinControls.VObject
3: For Each obj In _mlvMain.CurrentDesigner.VObjects
4: If TypeOf obj Is Aurigma.GraphicsMill.WinControls.ImageVObject Then
5: Dim corners As System.Drawing.PointF() = GetTransformedCornerPoints(obj)
6: Dim angle As Single = CalcAngle(New System.Drawing.PointF(1000, 0), New System.Drawing.PointF(corners(1).X - corners(0).X, corners(1).Y - corners(0).Y))
7: Dim point As New PointF(obj.GetVObjectBounds.Width / 2, obj.GetVObjectBounds.Height / 2)
8: If angle <> 0 Then
9: obj.Transform.RotateAt(-angle, point)
10: obj.Update()
11: End If
12: ElseIf TypeOf obj Is Aurigma.GraphicsMill.WinControls.TextVObject Then
13: Dim corners As System.Drawing.PointF() = GetTextTransformedCornerPoints(obj)
14: Dim angle As Single = CalcAngle(New System.Drawing.PointF(1000, 0), New System.Drawing.PointF(corners(1).X - corners(0).X, corners(1).Y - corners(0).Y))
15: Dim point As New PointF(obj.GetVObjectBounds.X + obj.GetVObjectBounds.Width / 2, obj.GetVObjectBounds.Y + obj.GetVObjectBounds.Height / 2)
16: If angle <> 0 Then
17: obj.Transform.RotateAt(-angle, point)
18: obj.Update()
19: End If
20: End If
21: Next
22: Catch ex As Exception
23: WriteErrLog(Err.Number, Err.Source, Err.Description, gstrModule, ProcedureName, Err.Erl)
24: End Try
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 3/9/2008(UTC) Posts: 554
Was thanked: 1 time(s) in 1 post(s)
|
Hi Ching-Yen, We tried to investigate your problem but we have not the code of these functions from your code: GetTransformedCornerPoints(obj) GetTextTransformedCornerPoints(obj) Could you please send me the code of these functions. Edited by user Friday, May 8, 2009 4:02:43 PM(UTC)
| Reason: Not specified |
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 3/3/2008(UTC) Posts: 185
Thanks: 8 times
|
Public Function GetTransformedCornerPoints(ByVal obj As Aurigma.GraphicsMill.WinControls.ImageVObject) As System.Drawing.PointF() Const ProcedureName = "GetTransformedCornerPoints" 1: Dim baseRect As System.Drawing.RectangleF = obj.GetVObjectBounds()
2: Dim cornerPnts As System.Drawing.PointF() = New System.Drawing.PointF(3) {}
3: Try 4: cornerPnts(0) = baseRect.Location 5: cornerPnts(1) = New System.Drawing.PointF(baseRect.Right, baseRect.Top) 6: cornerPnts(2) = New System.Drawing.PointF(baseRect.Right, baseRect.Bottom) 7: cornerPnts(3) = New System.Drawing.PointF(baseRect.Left, baseRect.Bottom)
8: obj.Transform.TransformPoints(cornerPnts)
9: Catch ex As Exception 10: WriteErrLog(Err.Number, Err.Source, Err.Description, gstrModule, ProcedureName, Err.Erl) 11: Finally 12: End Try 13: Return cornerPnts End Function
Public Function GetTextTransformedCornerPoints(ByVal obj As Aurigma.GraphicsMill.WinControls.TextVObject) As System.Drawing.PointF() 1: Dim baseRect As System.Drawing.RectangleF = obj.GetVObjectBounds()
2: Dim cornerPnts As System.Drawing.PointF() = New System.Drawing.PointF(3) {} Const ProcedureName = "GetTextTransformedCornerPoints" 3: Try 4: cornerPnts(0) = baseRect.Location 5: cornerPnts(1) = New System.Drawing.PointF(baseRect.Right, baseRect.Top) 6: cornerPnts(2) = New System.Drawing.PointF(baseRect.Right, baseRect.Bottom) 7: cornerPnts(3) = New System.Drawing.PointF(baseRect.Left, baseRect.Bottom)
8: obj.Transform.TransformPoints(cornerPnts)
9: Catch ex As Exception 10: WriteErrLog(Err.Number, Err.Source, Err.Description, gstrModule, ProcedureName, Err.Erl) 11: Finally 12: End Try 13: Return cornerPnts End Function
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 3/9/2008(UTC) Posts: 554
Was thanked: 1 time(s) in 1 post(s)
|
Hi, Thanks for the code. We found the reason of your problem. Try the following code: Code:Private Shared Function CalcAngle( _
ByVal v0 As System.Drawing.PointF, _
ByVal v1 As System.Drawing.PointF) As Single
Dim dotProduct As Single = v0.X * v1.X + v0.Y + v1.Y
Dim vLengthProduct As Single = CalcLength(v0) * CalcLength(v1)
If vLengthProduct < 0.01 Then
Throw New ApplicationException("Ups, div by zero error...")
End If
'this is the fix. The argument of Acos() should be in [0, 1] interval
Dim cosValue As Double = Math.Min(1.0F, dotProduct / vLengthProduct)
cosValue = Math.Max(-1.0F, cosValue)
Dim result As Single = CType(Math.Acos(cosValue) / Math.PI * 180, Single)
Dim vecProduct As Single = v0.X * v1.Y - v0.Y * v1.X
If vecProduct < 0 Then
result = 360 - result
End If
Return result
End Function
|
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
You specify units value that cannot be converted to pixels
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.