Handle so the GUI can draw an arbitary number of points
This commit is contained in:
parent
0e2ede0625
commit
15dcfcab2d
|
|
@ -7,22 +7,27 @@ Public Class GUI
|
||||||
Dim drawW, drawH As Integer
|
Dim drawW, drawH As Integer
|
||||||
Dim drawAspect, gratingAspect As Decimal
|
Dim drawAspect, gratingAspect As Decimal
|
||||||
Dim scaleDiff As Decimal
|
Dim scaleDiff As Decimal
|
||||||
Dim pCon1(3) As Decimal 'pCon(0) = pixel X, pCon(2) = SW X, etc.
|
|
||||||
Dim pCon2(3) As Decimal
|
Public pCon1(3) As Decimal 'pCon(0) = pixel X, pCon(2) = SW X, etc.
|
||||||
Dim pCon3(3) As Decimal
|
Public pCon2(3) As Decimal
|
||||||
Dim pCon4(3) As Decimal
|
Public pCon3(3) As Decimal
|
||||||
|
Public pCon4(3) As Decimal
|
||||||
|
|
||||||
|
Dim points As New Dictionary(Of String, Decimal())
|
||||||
|
Dim pointsOrder As New List(Of String)
|
||||||
|
|
||||||
|
|
||||||
' --- Start method when GUI loads ---
|
' --- Start method when GUI loads ---
|
||||||
Sub GUI_load() Handles MyBase.Load
|
Sub GUI_load() Handles MyBase.Load
|
||||||
containerPanel = DrawingPanel
|
containerPanel = DrawingPanel
|
||||||
|
|
||||||
AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
|
AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
|
||||||
|
|
||||||
Get_DrawboxParameters()
|
Get_DrawboxParameters()
|
||||||
|
|
||||||
Set_ContainerPointsX()
|
Set_ContainerPointsX()
|
||||||
Set_ContainerPointsY()
|
Set_ContainerPointsY()
|
||||||
|
|
||||||
'Create_StartPoints()
|
Create_StartPoints()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
' --- Retrive parameters for the drawing box ---
|
' --- Retrive parameters for the drawing box ---
|
||||||
|
|
@ -58,7 +63,15 @@ Public Class GUI
|
||||||
pCon4(1) = containerMidY + drawH / 2
|
pCon4(1) = containerMidY + drawH / 2
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
' --- Draw all the lines for the container ---
|
' --- Sets the start points for the grating ---
|
||||||
|
Private Sub Create_StartPoints()
|
||||||
|
For i = 1 To 4
|
||||||
|
points.Add("p" & i, CallByName(Me, "pCon" & i, vbGet))
|
||||||
|
pointsOrder.Add("p" & i)
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
' --- Draw all the lines for the container and grating ---
|
||||||
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
|
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
|
||||||
Dim penCon As Pen = New Pen(Color.DarkRed, 1)
|
Dim penCon As Pen = New Pen(Color.DarkRed, 1)
|
||||||
penCon.DashPattern = {4, 8}
|
penCon.DashPattern = {4, 8}
|
||||||
|
|
@ -67,8 +80,20 @@ Public Class GUI
|
||||||
e.Graphics.DrawLine(penCon, CInt(pCon3(0)), CInt(pCon3(1)), CInt(pCon4(0)), CInt(pCon4(1)))
|
e.Graphics.DrawLine(penCon, CInt(pCon3(0)), CInt(pCon3(1)), CInt(pCon4(0)), CInt(pCon4(1)))
|
||||||
e.Graphics.DrawLine(penCon, CInt(pCon4(0)), CInt(pCon4(1)), CInt(pCon1(0)), CInt(pCon1(1)))
|
e.Graphics.DrawLine(penCon, CInt(pCon4(0)), CInt(pCon4(1)), CInt(pCon1(0)), CInt(pCon1(1)))
|
||||||
|
|
||||||
|
Dim pen As Pen = New Pen(Color.Black, 1)
|
||||||
|
For i = 0 To pointsOrder.Count - 1
|
||||||
|
Dim pTemp1() As Decimal
|
||||||
|
Dim pTemp2() As Decimal
|
||||||
|
|
||||||
'Här måste den anpassa sig till antal punkter som ska ritas och i vilken ordning
|
pTemp1 = points(pointsOrder(i))
|
||||||
|
Try
|
||||||
|
pTemp2 = points(pointsOrder(i + 1))
|
||||||
|
Catch ex As Exception
|
||||||
|
pTemp2 = points(pointsOrder(0))
|
||||||
|
End Try
|
||||||
|
|
||||||
|
e.Graphics.DrawLine(pen, CInt(pTemp1(0)), CInt(pTemp1(1)), CInt(pTemp2(0)), CInt(pTemp2(1)))
|
||||||
|
Next
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
' --- Generate a table containing all the points X- and Y-values ---
|
' --- Generate a table containing all the points X- and Y-values ---
|
||||||
|
|
@ -77,24 +102,21 @@ Public Class GUI
|
||||||
pointTable.Columns.Add("X", GetType(Decimal))
|
pointTable.Columns.Add("X", GetType(Decimal))
|
||||||
pointTable.Columns.Add("Y", GetType(Decimal))
|
pointTable.Columns.Add("Y", GetType(Decimal))
|
||||||
|
|
||||||
pointTable.Rows.Add()
|
For i = 0 To pointsOrder.Count - 1
|
||||||
pointTable.Rows(0)("X") = pCon1(2)
|
Dim pTemp() As Decimal
|
||||||
pointTable.Rows(0)("Y") = pCon1(3)
|
pTemp = points(pointsOrder(i))
|
||||||
pointTable.Rows.Add()
|
|
||||||
pointTable.Rows(1)("X") = pCon2(2)
|
pointTable.Rows.Add()
|
||||||
pointTable.Rows(1)("Y") = pCon2(3)
|
pointTable.Rows(i)("X") = pTemp(2)
|
||||||
pointTable.Rows.Add()
|
pointTable.Rows(i)("Y") = pTemp(3)
|
||||||
pointTable.Rows(2)("X") = pCon3(2)
|
Next
|
||||||
pointTable.Rows(2)("Y") = pCon3(3)
|
|
||||||
pointTable.Rows.Add()
|
|
||||||
pointTable.Rows(3)("X") = pCon4(2)
|
|
||||||
pointTable.Rows(3)("Y") = pCon4(3)
|
|
||||||
|
|
||||||
Return pointTable
|
Return pointTable
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
' ---------- GUI interactions ------------
|
|
||||||
|
' ---------------------------------- GUI interactions ----------------------------------
|
||||||
|
|
||||||
' --- When update button is pressed ---
|
' --- When update button is pressed ---
|
||||||
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
|
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
|
||||||
|
|
@ -148,7 +170,4 @@ Public Class GUI
|
||||||
Program.Create_Drawing()
|
Program.Create_Drawing()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
|
|
||||||
' CallByName(Me, "p" & i + 1 & "X", vbGet)
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
Imports XCCLibrary
|
Imports XCCLibrary
|
||||||
Imports SolidWorks.Interop.sldworks
|
|
||||||
Imports SolidWorks.Interop.swconst
|
|
||||||
Imports System.Runtime.InteropServices
|
|
||||||
Imports System
|
|
||||||
Imports SldWorks
|
Imports SldWorks
|
||||||
Public Class Program
|
Public Class Program
|
||||||
Public Shared Sub Export_SW(pointTable As DataTable)
|
Public Shared Sub Export_SW(pointTable As DataTable)
|
||||||
|
|
@ -11,8 +7,6 @@ Public Class Program
|
||||||
Dim Model As ModelDoc2
|
Dim Model As ModelDoc2
|
||||||
Dim RootPoint(2) As Double
|
Dim RootPoint(2) As Double
|
||||||
Dim Normal(2) As Double
|
Dim Normal(2) As Double
|
||||||
'Dim TempBody As Body2
|
|
||||||
'Dim isGood As Boolean
|
|
||||||
swApp.UserControl = True
|
swApp.UserControl = True
|
||||||
'Create a new blank document
|
'Create a new blank document
|
||||||
Model = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2020\templates\part.prtdot", 0, 0, 0)
|
Model = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2020\templates\part.prtdot", 0, 0, 0)
|
||||||
|
|
@ -56,7 +50,6 @@ Public Class Program
|
||||||
|
|
||||||
swSkMgr.InsertSketch(True)
|
swSkMgr.InsertSketch(True)
|
||||||
|
|
||||||
|
|
||||||
Dim status As Boolean
|
Dim status As Boolean
|
||||||
Dim swModelDocExtension As ModelDocExtension
|
Dim swModelDocExtension As ModelDocExtension
|
||||||
|
|
||||||
|
|
@ -69,13 +62,11 @@ Public Class Program
|
||||||
|
|
||||||
swFeature = swFeatureMgr.FeatureExtrusion3(True, False, False, 0, 0, 0.001, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
|
swFeature = swFeatureMgr.FeatureExtrusion3(True, False, False, 0, 0, 0.001, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
|
||||||
|
|
||||||
|
|
||||||
Dim iPart As PartDoc
|
Dim iPart As PartDoc
|
||||||
iPart = swApp.ActiveDoc
|
iPart = swApp.ActiveDoc
|
||||||
Dim newName As String
|
Dim newName As String
|
||||||
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTPART" & 1 & ".SLDPRT"
|
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTPART" & 1 & ".SLDPRT"
|
||||||
longstatus = iPart.SaveAs3(newName, 0, 0)
|
longstatus = iPart.SaveAs3(newName, 0, 0)
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Shared Sub Create_Drawing()
|
Public Shared Sub Create_Drawing()
|
||||||
|
|
@ -98,18 +89,13 @@ Public Class Program
|
||||||
swSheet.SetTemplateName("C:\ProgramData\SolidWorks\SOLIDWORKS 2020\lang\english\sheetformat\a3 - iso.slddrt")
|
swSheet.SetTemplateName("C:\ProgramData\SolidWorks\SOLIDWORKS 2020\lang\english\sheetformat\a3 - iso.slddrt")
|
||||||
swSheet.ReloadTemplate(True)
|
swSheet.ReloadTemplate(True)
|
||||||
|
|
||||||
Dim myView
|
Dim myView As View
|
||||||
myView = iDrawing.CreateDrawViewFromModelView3("C:\Users\Anton\Documents\Exjobb\Temp\TESTPART1.SLDPRT", "*Front", swSheetWidth / 2, swSheetHeight / 2, 0)
|
myView = iDrawing.CreateDrawViewFromModelView3("C:\Users\Anton\Documents\Exjobb\Temp\TESTPART1.SLDPRT", "*Front", swSheetWidth / 2, swSheetHeight / 2, 0)
|
||||||
|
|
||||||
Dim longstatus As Integer
|
Dim longstatus As Integer
|
||||||
Dim newName As String
|
Dim newName As String
|
||||||
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTDRAWING" & 1 & ".SLDDRW"
|
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTDRAWING" & 1 & ".SLDDRW"
|
||||||
longstatus = iDrawing.SaveAs3(newName, 0, 0)
|
longstatus = iDrawing.SaveAs3(newName, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue