Handle so the GUI can draw an arbitary number of points

This commit is contained in:
Anton 2021-01-27 17:36:33 +01:00
parent 0e2ede0625
commit 15dcfcab2d
2 changed files with 45 additions and 40 deletions

View File

@ -7,22 +7,27 @@ Public Class GUI
Dim drawW, drawH As Integer
Dim drawAspect, gratingAspect 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
Dim pCon3(3) As Decimal
Dim pCon4(3) As Decimal
Public pCon1(3) As Decimal 'pCon(0) = pixel X, pCon(2) = SW X, etc.
Public pCon2(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 ---
Sub GUI_load() Handles MyBase.Load
containerPanel = DrawingPanel
AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
Get_DrawboxParameters()
Set_ContainerPointsX()
Set_ContainerPointsY()
'Create_StartPoints()
Create_StartPoints()
End Sub
' --- Retrive parameters for the drawing box ---
@ -58,7 +63,15 @@ Public Class GUI
pCon4(1) = containerMidY + drawH / 2
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)
Dim penCon As Pen = New Pen(Color.DarkRed, 1)
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(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
' --- 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("Y", GetType(Decimal))
pointTable.Rows.Add()
pointTable.Rows(0)("X") = pCon1(2)
pointTable.Rows(0)("Y") = pCon1(3)
pointTable.Rows.Add()
pointTable.Rows(1)("X") = pCon2(2)
pointTable.Rows(1)("Y") = pCon2(3)
pointTable.Rows.Add()
pointTable.Rows(2)("X") = pCon3(2)
pointTable.Rows(2)("Y") = pCon3(3)
pointTable.Rows.Add()
pointTable.Rows(3)("X") = pCon4(2)
pointTable.Rows(3)("Y") = pCon4(3)
For i = 0 To pointsOrder.Count - 1
Dim pTemp() As Decimal
pTemp = points(pointsOrder(i))
pointTable.Rows.Add()
pointTable.Rows(i)("X") = pTemp(2)
pointTable.Rows(i)("Y") = pTemp(3)
Next
Return pointTable
End Function
' ---------- GUI interactions ------------
' ---------------------------------- GUI interactions ----------------------------------
' --- When update button is pressed ---
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
@ -148,7 +170,4 @@ Public Class GUI
Program.Create_Drawing()
End Sub
End Class
' CallByName(Me, "p" & i + 1 & "X", vbGet)
End Class

View File

@ -1,8 +1,4 @@
Imports XCCLibrary
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports SldWorks
Public Class Program
Public Shared Sub Export_SW(pointTable As DataTable)
@ -11,8 +7,6 @@ Public Class Program
Dim Model As ModelDoc2
Dim RootPoint(2) As Double
Dim Normal(2) As Double
'Dim TempBody As Body2
'Dim isGood As Boolean
swApp.UserControl = True
'Create a new blank document
Model = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2020\templates\part.prtdot", 0, 0, 0)
@ -56,7 +50,6 @@ Public Class Program
swSkMgr.InsertSketch(True)
Dim status As Boolean
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)
Dim iPart As PartDoc
iPart = swApp.ActiveDoc
Dim newName As String
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTPART" & 1 & ".SLDPRT"
longstatus = iPart.SaveAs3(newName, 0, 0)
End Sub
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.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)
Dim longstatus As Integer
Dim newName As String
newName = "C:\Users\Anton\Documents\Exjobb\Temp" & "\TESTDRAWING" & 1 & ".SLDDRW"
longstatus = iDrawing.SaveAs3(newName, 0, 0)
End Sub
End Class