Files
Dario Sassi 4f1a9b8938 Icarus 2.6a1 :
- corretto controllo movimento pezzo (ora anche fuori da tavola purchè in area di stampa)
- aggiunta indicazione giorni mancanti alla fine del piano di manutenzione.
2024-01-26 16:14:34 +01:00

413 lines
14 KiB
VB.net

Imports System.Globalization
Imports EgtUILib
Imports EgtWPFLib5
Public Class DispositionPanelVM
Inherits VMBase
Public Property sXPos As String
Get
If Not IsNothing(Map.refTopPanelVM.SelPart) Then
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nReferenceId, GDB_ID.ROOT, ptReference)
Return LenToString(ptReference.x, 1)
Else
Return ""
End If
End Get
Set(value As String)
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nReferenceId, GDB_ID.ROOT, ptReference)
Dim dNewXPos As Double = ptReference.x
StringToLen(value, dNewXPos)
Dim b3Print As BBox3d = GetSolidForReferenceBBox(Map.refTopPanelVM.SelPart)
Dim dMin As Double = Math.Min( 0, CurrentMachine.b3ExtrusionArea.Min.x)
Dim dMax As Double = Math.Max( CurrentMachine.b3Tab.DimX, CurrentMachine.b3ExtrusionArea.Max.x)
If b3Print.Max.x > ptReference.x Then
dMax -= b3Print.Max.x - ptReference.x
End If
If b3Print.Min.x < ptReference.x Then
dMin += ptReference.x - b3Print.Min.x
End If
' riduco a spostamento massimo
If dNewXPos < dMin Then
dNewXPos = dMin
ElseIf dNewXPos > dMax Then
dNewXPos = dMax
End If
EgtMove(Map.refTopPanelVM.SelPart.nPartId, New Point3d(dNewXPos, ptReference.y, ptReference.z) - ptReference, GDB_RT.GLOB)
Map.refReferencePanelVM.UpdateFramePosition()
EgtDraw()
NotifyPropertyChanged(NameOf(sXPos))
' Imposto flag di ricalcolo part-program
EgtSetInfo(Map.refTopPanelVM.SelPart.nPartId, MAC_TORECALC_GENERATE, True)
End Set
End Property
Public Property sYPos As String
Get
If Not IsNothing(Map.refTopPanelVM.SelPart) Then
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nReferenceId, GDB_ID.ROOT, ptReference)
Return LenToString(ptReference.y, 1)
Else
Return ""
End If
End Get
Set(value As String)
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nReferenceId, GDB_ID.ROOT, ptReference)
Dim dNewYPos As Double = ptReference.y
StringToLen(value, dNewYPos)
Dim b3Print As BBox3d = GetSolidForReferenceBBox(Map.refTopPanelVM.SelPart)
Dim dMin As Double = Math.Min( 0, CurrentMachine.b3ExtrusionArea.Min.y)
Dim dMax As Double = Math.Max( CurrentMachine.b3Tab.DimY, CurrentMachine.b3ExtrusionArea.Max.y)
If b3Print.Max.y > ptReference.y Then
dMax -= b3Print.Max.y - ptReference.y
End If
If b3Print.Min.y < ptReference.y Then
dMin += ptReference.y - b3Print.Min.y
End If
' riduco a spostamento massimo
If dNewYPos < dMin Then
dNewYPos = dMin
ElseIf dNewyPos > dMax Then
dNewYPos = dMax
End If
EgtMove(Map.refTopPanelVM.SelPart.nPartId, New Point3d(ptReference.x, dNewYPos, ptReference.z) - ptReference, GDB_RT.GLOB)
Map.refReferencePanelVM.UpdateFramePosition()
EgtDraw()
NotifyPropertyChanged(NameOf(sYPos))
' Imposto flag di ricalcolo part-program
EgtSetInfo(Map.refTopPanelVM.SelPart.nPartId, MAC_TORECALC_GENERATE, True)
End Set
End Property
Public Property sZPos As String
Get
If Not IsNothing(Map.refTopPanelVM.SelPart) Then
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nPartReferenceId, GDB_ID.ROOT, ptReference)
Return LenToString(ptReference.z, 1)
Else
Return ""
End If
End Get
Set(value As String)
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nPartReferenceId, GDB_ID.ROOT, ptReference)
Dim dNewZPos As Double = ptReference.z
StringToLen(value, dNewZPos)
Dim b3Print As BBox3d = GetSolidForReferenceBBox(Map.refTopPanelVM.SelPart)
Dim dMin As Double = 0
If b3Print.Min.z < ptReference.z Then
dMin += ptReference.z - b3Print.Min.z
End If
' riduco a spostamento massimo
If dNewZPos < dMin Then
dNewZPos = dMin
End If
EgtMove(Map.refTopPanelVM.SelPart.nPartId, New Point3d(ptReference.x, ptReference.y, dNewZPos) - ptReference, GDB_RT.GLOB)
Map.refReferencePanelVM.UpdateFramePosition()
EgtDraw()
NotifyPropertyChanged(NameOf(sZPos))
' Imposto flag di ricalcolo part-program
EgtSetInfo(Map.refTopPanelVM.SelPart.nPartId, MAC_TORECALC_GENERATE, True)
End Set
End Property
Friend Sub UpdateZPos()
Dim ptReference As New Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nPartReferenceId, GDB_ID.ROOT, ptReference)
Dim dNewZPos As Double = ptReference.z
Dim b3Print As BBox3d = GetSolidForReferenceBBox(Map.refTopPanelVM.SelPart)
Dim dMin As Double = 0
If b3Print.Min.z < ptReference.z Then
dMin += ptReference.z - b3Print.Min.z
End If
If ptReference.z < dMin Then
EgtMove(Map.refTopPanelVM.SelPart.nPartId, New Point3d(ptReference.x, ptReference.y, dMin) - ptReference, GDB_RT.GLOB)
Map.refDispositionPanelVM.RefreshPos()
EgtDraw()
End If
NotifyPropertyChanged(NameOf(sZPos))
End Sub
' funzione che calcola il box totale del solido da stampare piu' ribs esterne ed unbounded
Friend Function GetSolidForReferenceBBox(SelPart As Print3dPartVM) As BBox3d
Dim b3Print As New BBox3d
EgtGetBBoxGlob(SelPart.nPrintSolidId, GDB_BB.EXACT, b3Print)
If EgtGetGroupObjs(SelPart.nRibsLayerId) > 0 Then
Dim b3Ribs As New BBox3d()
Dim nRibId As Integer = EgtGetFirstInGroup(SelPart.nRibsLayerId)
While nRibId <> GDB_ID.NULL
Dim nRibType As Integer = Machining.MPAR_RIBSTYPE.INTERNAL
If Not EgtGetInfo(nRibId, MAC_RIBSTYPE, nRibType) Then
EgtGetInfo(SelPart.nPartId, MAC_RIBSTYPE, nRibType)
End If
If nRibType = Machining.MPAR_RIBSTYPE.EXTERNAL OrElse nRibType = Machining.MPAR_RIBSTYPE.UNBOUNDED Then
Dim b3Rib As New BBox3d
EgtGetBBoxGlob(nRibId, GDB_BB.EXACT, b3Rib)
b3Ribs.Add(b3Rib)
End If
nRibId = EgtGetNext(nRibId)
End While
If Not b3Ribs.IsEmpty() Then
b3Print.Add(b3Ribs)
End If
End If
Return b3Print
End Function
Private m_RotAxes As Boolean() = { False, False, False}
Public Property RotX As Boolean
Get
Return m_RotAxes(0)
End Get
Set(value As Boolean)
m_RotAxes(0) = value
End Set
End Property
Public Property RotY As Boolean
Get
Return m_RotAxes(1)
End Get
Set(value As Boolean)
m_RotAxes(1) = value
End Set
End Property
Public Property RotZ As Boolean
Get
Return m_RotAxes(2)
End Get
Set(value As Boolean)
m_RotAxes(2) = value
End Set
End Property
Public ReadOnly Property vtSelRotAxes As Vector3d
Get
If m_RotAxes(0) Then
Return Vector3d.X_AX
ElseIf m_RotAxes(1) Then
Return Vector3d.Y_AX
Else
Return Vector3d.Z_AX
End If
End Get
End Property
Private m_sRotAngle As String
Public Property sRotAngle As String
Get
Return m_sRotAngle
End Get
Set(value As String)
Dim dNewAngle As Double = 0
If IsNothing( value) OrElse Not StringToLen(value, dNewAngle) Then
m_sRotAngle = 0
NotifyPropertyChanged(NameOf(sRotAngle))
Return
End If
Dim vtMovedPart As Vector3d
If EgtGetInfo(Map.refTopPanelVM.SelPart.nPartId, KEY_MOVEDPART, vtMovedPart) Then
Dim nEntId = EgtGetFirstInGroup(Map.refTopPanelVM.SelPart.nPrintSolidLayerId)
While nEntId <> GDB_ID.NULL
EgtMove(nEntId, -vtMovedPart, GDB_RT.GLOB)
nEntId = EgtGetNext(nEntId)
End While
EgtRemoveInfo(Map.refTopPanelVM.SelPart.nPartId, KEY_MOVEDPART)
End If
If EgtGetInfo(Map.refTopPanelVM.SelPart.nPartId, KEY_MOVEDPART2, vtMovedPart) Then
EgtMove(Map.refTopPanelVM.SelPart.nPartId, -vtMovedPart, GDB_RT.GLOB)
EgtMove(Map.refTopPanelVM.SelPart.nReferenceId, vtMovedPart, GDB_RT.GLOB)
EgtRemoveInfo(Map.refTopPanelVM.SelPart.nPartId, KEY_MOVEDPART2)
End If
Dim b3PrintSolid As New BBox3d
EgtGetBBoxGlob(Map.refTopPanelVM.SelPart.nPartId, GDB_BB.STANDARD, b3PrintSolid)
If EgtRotate(Map.refTopPanelVM.SelPart.nPartId, b3PrintSolid.Center, vtSelRotAxes, dNewAngle, GDB_RT.GLOB) Then
m_sRotAngle = 0
Map.refReferencePanelVM.UpdateFramePosition()
Map.refDispositionPanelVM.UpdateZPos()
RefreshPos()
EgtDraw()
NotifyPropertyChanged(NameOf(sRotAngle))
' Imposto flag di ricalcolo slice
EgtSetInfo(Map.refTopPanelVM.SelPart.nPartId, MAC_TORECALC_SLICE, True)
Else
m_sRotAngle = value
End If
End Set
End Property
Private m_bMove_IsChecked As Boolean
Public Property bMove_IsChecked As Boolean
Get
Return m_bMove_IsChecked
End Get
Set(value As Boolean)
If Map.refSceneHostVM.MainController.GetStep = 0 Then
m_bMove_IsChecked = value
If value Then
m_bRotate_IsChecked = False
NotifyPropertyChanged(NameOf(bRotate_IsChecked))
End If
Else
NotifyPropertyChanged(NameOf(bMove_IsChecked))
End If
End Set
End Property
Private m_bRotate_IsChecked As Boolean
Public Property bRotate_IsChecked As Boolean
Get
Return m_bRotate_IsChecked
End Get
Set(value As Boolean)
If Map.refSceneHostVM.MainController.GetStep = 0 Then
m_bRotate_IsChecked = value
If value Then
m_bMove_IsChecked = False
NotifyPropertyChanged(NameOf(bMove_IsChecked))
End If
Else
NotifyPropertyChanged(NameOf(bMove_IsChecked))
End If
End Set
End Property
' riferimento griglia prima della rotazione
Private m_PrevGridOrigin As New Frame3d
Private m_bRotating As Boolean
' Definizione comandi
Private m_cmdDragMove As ICommand
Private m_cmdDragRotate As ICommand
Sub New()
' Creo riferimento a questa classe in EgtCAM5Map
Map.SetRefDispositionPanelVM(Me)
End Sub
Friend Sub Init()
RotZ = True
NotifyPropertyChanged(NameOf(RotZ))
End Sub
Friend Sub RefreshPos()
NotifyPropertyChanged(NameOf(sXPos))
NotifyPropertyChanged(NameOf(sYPos))
NotifyPropertyChanged(NameOf(sZPos))
End Sub
Private Sub InitCommand()
' attivo modifiche su scena
Map.refSceneHostVM.MainScene.ResetStatus()
' seleziono percorso corrente
EgtDeselectAll()
EgtSelectObj(Map.refTopPanelVM.SelPart.nPartId)
EgtDraw()
End Sub
Friend Sub UpdateUI()
RefreshPos()
If m_bRotating Then
m_bRotating = False
' ripristino griglia
EgtSetGridFrame(m_PrevGridOrigin)
End If
EgtDeselectAll()
EgtDraw()
End Sub
Friend Sub OnKeyDown(Key As Forms.Keys)
If Key = Forms.Keys.Escape Then
If m_bRotating Then
m_bRotating = False
' ripristino griglia
EgtSetGridFrame(m_PrevGridOrigin)
End If
EgtDeselectAll()
EgtDraw()
End If
End Sub
#Region "COMMANDS"
#Region "DragMove"
Public ReadOnly Property DragMove_Command As ICommand
Get
If m_cmdDragMove Is Nothing Then
m_cmdDragMove = New Command(AddressOf DragMove)
End If
Return m_cmdDragMove
End Get
End Property
Public Sub DragMove()
If Map.refSceneHostVM.MainController.GetStep <> 0 Then Return
InitCommand()
Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.MOVE)
End Sub
#End Region ' DragMove
#Region "DragRotate"
Public ReadOnly Property DragRotate_Command As ICommand
Get
If m_cmdDragRotate Is Nothing Then
m_cmdDragRotate = New Command(AddressOf DragRotate)
End If
Return m_cmdDragRotate
End Get
End Property
Public Sub DragRotate()
If Map.refSceneHostVM.MainController.GetStep <> 0 Then Return
m_bRotating = True
m_PrevGridOrigin = EgtGetGridFrame()
InitCommand()
If AreSameVectorApprox(vtSelRotAxes, Vector3d.X_AX) Then
Map.refSceneHostVM.MainController.SetLastInteger(Controller.GRID_TYPE.RIGHT)
ElseIf AreSameVectorApprox(vtSelRotAxes, Vector3d.Y_AX) Then
Map.refSceneHostVM.MainController.SetLastInteger(Controller.GRID_TYPE.FRONT)
ElseIf AreSameVectorApprox(vtSelRotAxes, Vector3d.Z_AX) Then
Map.refSceneHostVM.MainController.SetLastInteger(Controller.GRID_TYPE.TOP)
End If
Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.GRID)
' recupero il piano di griglia corrente
Dim frCurr As New Frame3d(EgtGetGridFrame())
' ne modifico l'origine per portarla sullo stesso piano del punto( o punto inizio della curva)
Dim StartPoint As Point3d
EgtStartPoint(Map.refTopPanelVM.SelPart.nPartId, StartPoint)
frCurr.Move(StartPoint - frCurr.Orig())
' imposto nuova griglia
EgtSetGridFrame(frCurr)
EgtDraw()
Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.ROTATE)
End Sub
#End Region ' DragRotate
#End Region ' COMMANDS
End Class
Public Class FromBooleanToVisibility
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsNothing(value) OrElse TypeOf value IsNot Boolean Then
Return Visibility.Collapsed
End If
Return If(CBool(value), Visibility.Visible, Visibility.Collapsed)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotSupportedException()
End Function
End Class