Added measure for recesses in GUI

This commit is contained in:
Anton 2021-02-10 14:30:53 +01:00
parent 5ff9ac938f
commit d729b4ca7d
5 changed files with 114 additions and 49 deletions

View File

@ -120,7 +120,7 @@ Partial Class GUI
'
'AngleButton
'
Me.AngleButton.Location = New System.Drawing.Point(586, 55)
Me.AngleButton.Location = New System.Drawing.Point(529, 55)
Me.AngleButton.Margin = New System.Windows.Forms.Padding(2)
Me.AngleButton.Name = "AngleButton"
Me.AngleButton.Size = New System.Drawing.Size(92, 28)
@ -230,7 +230,7 @@ Partial Class GUI
'
Me.Label7.AutoSize = True
Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label7.Location = New System.Drawing.Point(306, 28)
Me.Label7.Location = New System.Drawing.Point(394, 31)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(78, 17)
Me.Label7.TabIndex = 21
@ -250,7 +250,7 @@ Partial Class GUI
'
'Button_Square
'
Me.Button_Square.Location = New System.Drawing.Point(728, 55)
Me.Button_Square.Location = New System.Drawing.Point(716, 55)
Me.Button_Square.Name = "Button_Square"
Me.Button_Square.Size = New System.Drawing.Size(92, 28)
Me.Button_Square.TabIndex = 25

View File

@ -2,8 +2,8 @@
Imports Excel = Microsoft.Office.Interop.Excel
Public Class GUI
'Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
Public Shared filepath As String = "C:\Users\xperd\Documents"
Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
'Public Shared filepath As String = "C:\Users\xperd\Documents"
Dim excelApp As Excel.Application = New Excel.Application
Dim excelWB As Excel.Workbook
@ -26,7 +26,6 @@ Public Class GUI
GUI_Functions.pointsMeasurements.Add("Lmes", {1, 2, 1})
GUI_Functions.pointsMeasurements.Add("Wmes", {2, 3, 2})
End Sub
Private Sub Get_Database()
@ -92,7 +91,7 @@ Public Class GUI
Me.Controls.Add(textBoxTemp)
End Sub
Public Sub Create_Label(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
Public Sub Create_LabelGUI(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
Dim LabelTemp As New Label
LabelTemp.Name = LabelName
LabelTemp.Text = LabelText
@ -102,6 +101,16 @@ Public Class GUI
Me.Controls.Add(LabelTemp)
End Sub
Public Sub Create_LabelPanel(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
Dim LabelTemp As New Label
LabelTemp.Name = LabelName
LabelTemp.Text = LabelText
LabelTemp.Left = LabelLeft
LabelTemp.Top = LabelTop
LabelTemp.Font = New Font("Microsoft Sans Serif", 7)
LabelTemp.BackColor = Color.Transparent
DrawingPanel.Controls.Add(LabelTemp)
End Sub
' ---------------------------------- Gratings Data ----------------------------------
' --- When user changes grating type ---

View File

@ -11,6 +11,8 @@
Private Shared DirSymbolPoints As New Dictionary(Of String, Decimal())
Private Shared ArrowSymbolPoints As New Dictionary(Of String, Decimal())
Public Shared measureLabels As New Dictionary(Of String, Integer())
Private Shared drawAspect, gratingAspect As Decimal
Public Shared scaleDiff As Decimal = 1
@ -116,7 +118,7 @@
End If
'Redraw grating
GUI.Refresh()
GUI.DrawingPanel.Refresh()
'SW X-values
pCon1(2) = (-GUI_Gratings_Data.gratingMaxL / 2) / 1000
@ -172,14 +174,13 @@
e.Graphics.DrawLine(symPen, ArrowSymbolPoints("p" & i)(0), ArrowSymbolPoints("p" & i)(1),
ArrowSymbolPoints("p" & i + 1)(0), ArrowSymbolPoints("p" & i + 1)(1))
Next
'e.Graphics.TranslateTransform(20, containerW - 20)
'e.Graphics.DrawString("Length", New Font("Microsoft Sans Serif", 8), Brushes.Black, New Point(45, -7))
'e.Graphics.RotateTransform(-90)
'e.Graphics.DrawString("Width", New Font("Microsoft Sans Serif", 8), Brushes.Black, New Point(45, -4))
'e.Graphics.RotateTransform(90)
'e.Graphics.TranslateTransform(-20, -containerW + 20)
' Draw measure labels
For i = 0 To measureLabels.Count - 1
Dim mesName As String = measureLabels.Keys(i)
e.Graphics.DrawString(measureLabels(mesName)(0), New Font("Microsoft Sans Serif", 7), Brushes.Black,
New Point(measureLabels(mesName)(1), measureLabels(mesName)(2)))
Next
' Draw actual grating (black)

View File

@ -8,7 +8,6 @@
Public Shared pointsMeasurements As New Dictionary(Of String, Integer())
Public Shared Sub AngleButton(sender As Object, e As EventArgs)
GUI.Controls("AngleButton").Enabled = False
GUI.Controls("Button_Square").Enabled = False
@ -18,11 +17,11 @@
GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
GUI.Create_Label("X_Label", "1", buttonX, buttonY + 43)
GUI.Create_LabelGUI("X_Label", "1", buttonX, buttonY + 43)
GUI.Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
AddHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
GUI.Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
GUI.Create_LabelGUI("Y_Label", "2", buttonX + 110, buttonY + 43)
angleFunctionActive = True
End Sub
@ -36,11 +35,11 @@
GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
GUI.Create_Label("X_Label", "1", buttonX, buttonY + 43)
GUI.Create_LabelGUI("X_Label", "1", buttonX, buttonY + 43)
GUI.Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
AddHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
GUI.Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
GUI.Create_LabelGUI("Y_Label", "2", buttonX + 110, buttonY + 43)
' Add option for corner or side
@ -49,7 +48,7 @@
Private Shared Sub FunctionText_Changed(sender As TextBox, e As EventArgs)
If Not GUI.Controls("X_TextBox").Text = "" And Not GUI.Controls("Y_TextBox").Text = "" Then
If GUI.DrawingPanel.Controls.Count = 2 Then 'FIXA BÄTTRE
If GUI.DrawingPanel.Controls.Count = 2 Then
' Create Buttons for all clickable points
For i = 0 To GUI_Drawing_Panel.pointsOrder.Count - 1
If pointsFunc(GUI_Drawing_Panel.pointsOrder(i)) Then
@ -114,14 +113,12 @@
Dim mesNum As Integer = pointsMeasurements.Count - 1
If angleFunctionActive Then
For i = 2 To pointsMeasurements.Count - 1
Dim mesName As String = pointsMeasurements.Keys(i)
If index < pointsMeasurements(mesName)(0) Then
If index + 1 < pointsMeasurements(mesName)(0) Then
pointsMeasurements(mesName)(0) = pointsMeasurements(mesName)(0) + 1
pointsMeasurements(mesName)(1) = pointsMeasurements(mesName)(1) + 1
ElseIf index = pointsMeasurements(mesName)(0) OrElse index = pointsMeasurements(mesName)(1) Then
ElseIf index + 1 = pointsMeasurements(mesName)(0) OrElse index + 1 = pointsMeasurements(mesName)(1) Then
pointsMeasurements(mesName)(1) = pointsMeasurements(mesName)(1) + 1
End If
@ -139,16 +136,14 @@
Else
'Kvadrant 1
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
'Outer measuements
pointsMeasurements("Lmes")(1) = pointsMeasurements("Lmes")(1) + 1
pointsMeasurements("Wmes")(0) = pointsMeasurements("Wmes")(0) + 1
pointsMeasurements("Wmes")(1) = pointsMeasurements("Wmes")(1) + 1
'Recess measuements
pointsMeasurements.Add("A_" & mesNum, {index + 1, index + 2, 1})
pointsMeasurements.Add("A_" & mesNum + 1, {index + 1, index + 2, 4})
@ -187,16 +182,24 @@
numOfNewPoints = 2
angleFunctionActive = False
Else ' square
For i = 2 To pointsMeasurements.Count - 1
Dim mesName As String = pointsMeasurements.Keys(i)
If index < pointsMeasurements(mesName)(0) Then
If index + 1 < pointsMeasurements(mesName)(0) Then
pointsMeasurements(mesName)(0) = pointsMeasurements(mesName)(0) + 2
pointsMeasurements(mesName)(1) = pointsMeasurements(mesName)(1) + 2
ElseIf index = pointsMeasurements(mesName)(0) OrElse index = pointsMeasurements(mesName)(1) Then
ElseIf index + 1 = pointsMeasurements(mesName)(0) Then
pointsMeasurements(mesName)(1) = pointsMeasurements(mesName)(1) + 2
GUI_Drawing_Panel.measureLabels(mesName)(0) = GUI_Drawing_Panel.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text
GUI_Drawing_Panel.measureLabels(mesName)(1) = GUI_Drawing_Panel.measureLabels(mesName)(1) + d1P / 2
ElseIf index + 1 = pointsMeasurements(mesName)(1) Then
pointsMeasurements(mesName)(1) = pointsMeasurements(mesName)(1) + 2
GUI_Drawing_Panel.measureLabels(mesName)(0) = GUI_Drawing_Panel.measureLabels(mesName)(0) - GUI.Controls("Y_TextBox").Text
GUI_Drawing_Panel.measureLabels(mesName)(2) = GUI_Drawing_Panel.measureLabels(mesName)(2) + d2P / 2
End If
Next
If pXP < GUI_Drawing_Panel.containerMidX Then
@ -209,6 +212,12 @@
'Recess measuements
pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 4})
pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 3})
'Label
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXP + d1P / 2 - 8,
pYP - d2P - 12 - 3})
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXP + d1P + 3,
pYP - d2P / 2 - 4})
Else
'Kvadrant 1
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
@ -222,6 +231,12 @@
'Recess measuements
pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 1})
pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 4})
'Label
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXP + d1P / 2 - 8,
pYP + d2P + 3})
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXP + d1P + 3,
pYP + d2P / 2 - 4})
End If
Else
If pYP > GUI_Drawing_Panel.containerMidY Then
@ -235,6 +250,12 @@
'Recess measuements
pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 3})
pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 2})
'Label
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXP - d1P / 2 - 8,
pYP - d2P - 12 - 3})
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXP - d1P - 18 - 3,
pYP - d2P / 2 - 4})
Else
'Kvadrant 2
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
@ -247,6 +268,12 @@
'Recess measuements
pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 2})
pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 1})
'Label
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXP - d1P / 2 - 8,
pYP + d2P + 3})
GUI_Drawing_Panel.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXP - d1P - 18 - 3,
pYP + d2P / 2 - 4})
End If
End If
pointsFunc.Add("pS" & pointCounter * 3 - 2, True)
@ -266,7 +293,7 @@
GUI_Drawing_Panel.pointsOrder.RemoveAt(index)
'Redraw grating
GUI.Refresh()
GUI.DrawingPanel.Refresh()
RemoveHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
GUI.Controls.RemoveByKey("X_TextBox")

View File

@ -1,6 +1,7 @@
Imports XCCLibrary
Imports SldWorks
Public Class SW_Drawing_Gratings
Private Shared sideCounter As Integer() = {0, 0, 0, 0}
Public Shared Sub CreateDrawing()
Dim pointTable As New DataTable
pointTable = GUI_Gratings_Data.Create_PointTable()
@ -103,6 +104,7 @@ Public Class SW_Drawing_Gratings
Dim myView As View
myView = iDrawing.CreateDrawViewFromModelView3(GUI.filepath & "\Temp\TESTPART1.SLDPRT", "*Front", swSheetWidth / 2, swSheetHeight / 2, 0)
Dim viewScale = myView.ScaleDecimal()
Dim swExtensions As SldWorks.ModelDocExtension
swExtensions = iDrawing.Extension
@ -114,14 +116,14 @@ Public Class SW_Drawing_Gratings
Dim X_Mid = (OutLine(2) - OutLine(0)) / 2 + OutLine(0)
Dim Y_Mid = (OutLine(3) - OutLine(1)) / 2 + OutLine(1)
For i = 2 To GUI_Functions.pointsMeasurements.Count - 1
Dim mesName As String = GUI_Functions.pointsMeasurements.Keys(i)
Add_Dimensions(GUI_Functions.pointsMeasurements(mesName), CompName, myView, iDrawing, swExtensions, X_Mid, OutLine, Y_Mid)
Add_Dimensions(GUI_Functions.pointsMeasurements(mesName), CompName, myView, iDrawing, swExtensions, OutLine, viewScale, X_Mid, Y_Mid)
Next
Add_Dimensions(GUI_Functions.pointsMeasurements("Lmes"), CompName, myView, iDrawing, swExtensions, X_Mid, OutLine, Y_Mid)
Add_Dimensions(GUI_Functions.pointsMeasurements("Wmes"), CompName, myView, iDrawing, swExtensions, X_Mid, OutLine, Y_Mid)
Add_Dimensions(GUI_Functions.pointsMeasurements("Lmes"), CompName, myView, iDrawing, swExtensions, OutLine, viewScale, X_Mid, Y_Mid)
Add_Dimensions(GUI_Functions.pointsMeasurements("Wmes"), CompName, myView, iDrawing, swExtensions, OutLine, viewScale, X_Mid, Y_Mid)
Dim myView2 As View
myView2 = iDrawing.CreateDrawViewFromModelView3(GUI.filepath & "\Temp\TESTPART1.SLDPRT", "*Bottom", swSheetWidth / 2, OutLine(3) + 0.03, 0)
Dim OutLine2 = myView2.GetOutline
@ -150,26 +152,52 @@ Public Class SW_Drawing_Gratings
End Sub
Private Shared Sub Add_Dimensions(points() As Integer, CompName As String, myView As View, iDrawing As DrawingDoc, swExtensions As SldWorks.ModelDocExtension _
, X_Mid As Double, OutLine() As Double, Y_Mid As Double)
, OutLine() As Double, viewScale As Double, X_Mid As Double, Y_Mid As Double)
Dim measurement As IDisplayDimension
Dim point1Name As String = "Point" & points(0) & "@Sketch1@" & CompName & "@" & myView.GetName2
Dim point2Name As String = "Point" & points(1) & "@Sketch1@" & CompName & "@" & myView.GetName2
Dim point1NameSW As String = "Point" & points(0) & "@Sketch1@" & CompName & "@" & myView.GetName2
Dim point2NameSW As String = "Point" & points(1) & "@Sketch1@" & CompName & "@" & myView.GetName2
iDrawing.ClearSelection2(True)
swExtensions.SelectByID2(point1Name, "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
swExtensions.SelectByID2(point2Name, "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
If points(2) = 1 Then
measurement = iDrawing.AddHorizontalDimension2(X_Mid, OutLine(3), 0)
ElseIf points(2) = 2 Then
measurement = iDrawing.AddVerticalDimension2(OutLine(2), Y_Mid, 0)
ElseIf points(2) = 3 Then
measurement = iDrawing.AddHorizontalDimension2(X_Mid, OutLine(1), 0)
Else
measurement = iDrawing.AddVerticalDimension2(OutLine(0), Y_Mid, 0)
End If
swExtensions.SelectByID2(point1NameSW, "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
swExtensions.SelectByID2(point2NameSW, "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
Dim mesOffset = 0.01
If points(2) = 1 OrElse points(2) = 3 Then
Dim point1 As Decimal = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(points(0) - 1))(2)
Dim point2 As Decimal = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(points(1) - 1))(2)
Dim xPos As Decimal
If Math.Abs(point1) > Math.Abs(point2) Then
xPos = point2 + (point1 - point2) / 2
Else
xPos = point1 + (point2 - point1) / 2
End If
If points(2) = 1 Then
measurement = iDrawing.AddHorizontalDimension2(X_Mid + xPos * viewScale, OutLine(3) + mesOffset * sideCounter(0), 0)
Else
measurement = iDrawing.AddHorizontalDimension2(X_Mid + xPos * viewScale, OutLine(1) - mesOffset * sideCounter(2), 0)
End If
Else
Dim point1 As Decimal = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(points(0) - 1))(3)
Dim point2 As Decimal = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(points(1) - 1))(3)
Dim yPos As Decimal
If Math.Abs(point1) > Math.Abs(point2) Then
yPos = point2 + (point1 - point2) / 2
Else
yPos = point1 + (point2 - point1) / 2
End If
If points(2) = 2 Then
measurement = iDrawing.AddVerticalDimension2(OutLine(2) + mesOffset * sideCounter(1), Y_Mid + yPos * viewScale, 0)
Else
measurement = iDrawing.AddVerticalDimension2(OutLine(0) - mesOffset * sideCounter(3), Y_Mid + yPos * viewScale, 0)
End If
End If
sideCounter(points(2) - 1) = sideCounter(points(2) - 1) + 1
iDrawing.ClearSelection2(True)
measurement.SetUnits2(False, 0, 1, 0, True, 12)