Files
omagoffice/InstrumentPanel/PrintPanelVM.vb
2023-02-09 09:49:04 +01:00

85 lines
3.0 KiB
VB.net

Imports EgtUILib
Imports EgtWPFLib5
Public Class PrintPanelVM
' Definizione comandi
Private m_cmdPrint As ICommand
Public ReadOnly Property PrintToolTip As String
Get
Return "Print shading" & vbCrLf & "Print hidden line (Shift)"
End Get
End Property
#Region "PrintCommand"
Public ReadOnly Property PrintCommand As ICommand
Get
If m_cmdPrint Is Nothing Then
m_cmdPrint = New Command(AddressOf Print)
End If
Return m_cmdPrint
End Get
End Property
Public Sub Print(ByVal param As Object)
Dim SM_Select As SM = SM.SHADING
If (Keyboard.Modifiers And ModifierKeys.Shift) > 0 Then
SM_Select = SM.HIDDENLINE
EgtSetLineAttribs(3)
End If
Dim printDlg As New PrintDialog
Dim sPath = OmagOFFICEMap.refMainWindowVM.MainWindowM.sTempDir & "\Image.png"
If printDlg.ShowDialog() Then
' Recupero le dimensioni dell'area di stampa
Dim dW As Double = printDlg.PrintableAreaWidth
Dim dH As Double = printDlg.PrintableAreaHeight
Try
' Creo l'immagine da allegare
' EgtZoom(ZM.ALL, True)
' Prendo l'immagine per la stampa
Dim colWhite As New Color3d(255, 255, 255)
Dim nImgW As Integer = GetWidthDimProjectV()
Dim nImgH As Integer = GetHeightDimProjectV()
If Not EgtGetImage(SM_Select, colWhite, colWhite, nImgW, nImgH, sPath) Then
' Error in creating the print image
EgtOutLog(EgtMsg(50181))
EgtSetLineAttribs(1)
Return
End If
EgtSetLineAttribs(1)
'Metodo complesso di stampa che permette di rilasciare il file :
'carico la bitmap e la metto in uno stream in memoria
Dim stream As System.IO.Stream = New System.IO.MemoryStream()
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(sPath)
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
bitmap.Dispose()
' la sposto in una BitmapImage
Dim bitImage As New System.Windows.Media.Imaging.BitmapImage()
bitImage.BeginInit()
bitImage.StreamSource = stream
bitImage.EndInit()
' la sposto in un Visual Control
Dim tmpImg As New Image
tmpImg.BeginInit()
tmpImg.Source = bitImage
'tmpImg.Margin = New Thickness(-100)
tmpImg.Stretch = Stretch.Uniform
' ruoto a seconda dell'aspetto della pagina
'If (dH > dW And nImgH < nImgW) Or (dH < dW And nImgH > nImgW) Then
' tmpImg.LayoutTransform = New RotateTransform(-90)
'End If
tmpImg.EndInit()
' eseguo la stampa
printDlg.PrintVisual(tmpImg, "Parts Layout")
Catch
' Rrror in executing print
EgtOutLog(EgtMsg(50182))
End Try
End If
End Sub
#End Region ' PrintCommand
End Class