Files
OmagCUT/SideAngleUc.xaml.vb
T
Dario Sassi 0e540997f2 OmagCUT 1.9a4 :
- corretta gestione nomi utensili in lavorazione dopo cambio del nome stesso in utensile
- migliorata gestione dialogo import file
- migliorata visualizzazione angoli dei profili dei lati sui pezzi.
2018-02-02 15:30:40 +00:00

1092 lines
43 KiB
VB.net

Imports EgtUILib
Public Class SideAngleUC
Public Enum ModeOpt As Integer
SIDEANGLE = 0
DRIP = 1
End Enum
' Variabile che indica se sono in sideangle o drip
Friend m_Mode As ModeOpt
' Costanti layer componenti
Friend Const COMPO_LAYER_AUX As String = "LayAux"
Friend Const COMPO_LAYER_QUOTATURE As String = "Quotature"
Friend Const COMPO_LAYER_ETICHETTE As String = "Etichette"
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
Private m_DrawPage As DrawPageUC
' Riferimento alla pagina che ha aperto SideAngleUC
Private m_CallingPage As MainWindow.Pages
' Lista di tutte le entità inclinabili presenti nel progetto
Friend m_SideAngleEntityList As New List(Of SideAngleEntity)
Friend m_DripEntityList As New List(Of DripEntity)
Friend m_dDripOffset As Double = 10
Friend m_dDripDepth As Double = 10
Friend m_dDripShort As Double = 0
Private Sub SideAngleUC_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
' Imposto riferimenti ad altre pagine
m_DrawPage = m_MainWindow.m_DrawPageUC
m_CallingPage = m_MainWindow.m_ActivePage
' Imposto messaggi
If m_Mode = ModeOpt.SIDEANGLE Then
Parameter1TxBl.Text = EgtMsg(MSG_IMPORTPAGEUC + 9) ' Angolo
Else
Parameter1TxBl.Text = EgtMsg(MSG_IMPORTPAGEUC + 10) ' Offset
Parameter2TxBl.Text = EgtMsg(MSG_IMPORTPAGEUC + 11) ' Affondamento
Parameter3TxBl.Text = EgtMsg(MSG_IMPORTPAGEUC + 12) ' Accorciamento
End If
If m_Mode = ModeOpt.SIDEANGLE Then
A1TxBx.Text = "0"
A2TxBx.Text = "0"
A3TxBx.Text = "0"
A4TxBx.Text = "0"
A5TxBx.Text = "0"
A6TxBx.Text = "0"
A7TxBx.Text = "0"
A8TxBx.Text = "0"
A9TxBx.Text = "0"
A10TxBx.Text = "0"
End If
If m_CallingPage = MainWindow.Pages.Draw Then
' Imposto questa come pagina correntemente visualizzata nella drawpage
m_DrawPage.m_ActiveComponentPage = DrawPageUC.Pages.SideAngle
' Imposto contesto corrente
EgtSetCurrentContext(m_MainWindow.m_DrawPageUC.DrawScene.GetCtx())
' se la lista non è vuota la leggo e metto le inclinazioni giuste
If m_Mode = ModeOpt.SIDEANGLE Then
If m_SideAngleEntityList.Count > 0 Then
' Aggiorno indici che potrebbero essere cambiati se sono state modificate le misure
RefreshGeomId()
' Aggiorno testi nel disegno
RefreshSideAngleText()
' Aggiorno check e valori
RefreshCheckAndValue()
Else
' Inizializzo lati per angoli (ne compilo la lista e aggiungo la scritta nel disegno)
InitSides()
End If
Else
If m_DripEntityList.Count > 0 Then
' Aggiorno indici che potrebbero essere cambiati se sono state modificate le misure
RefreshGeomId()
' Aggiorno testi in base alla tabella
RefreshSideAngleText()
Else
' Inizializzo lati per angoli (ne compilo la lista e aggiungo la scritta nel disegno)
InitSides()
End If
End If
ElseIf m_CallingPage = MainWindow.Pages.Import Then
' Imposto contesto corrente
EgtSetCurrentContext(m_MainWindow.m_ImportPageUC.ImportScene.GetCtx())
' Inizializzo
DeleteSideAngle()
' Inizializzo lati per angoli (ne compilo la lista e aggiungo la scritta nel disegno)
InitSides()
' Aggiorno testi nel disegno
RefreshSideAngleText()
' Aggiorno check e valori
RefreshCheckAndValue()
End If
' Gestisco Checkbox e nomi in base al numero di lati inclinabili
TxBlChBxView()
' Gestisco visualizzazione dei parametri
If m_Mode = ModeOpt.SIDEANGLE Then
A1.Visibility = Windows.Visibility.Collapsed
A2.Visibility = Windows.Visibility.Collapsed
A3.Visibility = Windows.Visibility.Collapsed
A4.Visibility = Windows.Visibility.Collapsed
A5.Visibility = Windows.Visibility.Collapsed
A6.Visibility = Windows.Visibility.Collapsed
A7.Visibility = Windows.Visibility.Collapsed
A8.Visibility = Windows.Visibility.Collapsed
A9.Visibility = Windows.Visibility.Collapsed
A10.Visibility = Windows.Visibility.Collapsed
Parameter1TxBl.Visibility = Windows.Visibility.Hidden
Parameter1TxBx.Visibility = Windows.Visibility.Hidden
Parameter2TxBl.Visibility = Windows.Visibility.Hidden
Parameter2TxBx.Visibility = Windows.Visibility.Hidden
Parameter3TxBl.Visibility = Windows.Visibility.Hidden
Parameter3TxBx.Visibility = Windows.Visibility.Hidden
Else
A1TxBx.Visibility = Windows.Visibility.Collapsed
A2TxBx.Visibility = Windows.Visibility.Collapsed
A3TxBx.Visibility = Windows.Visibility.Collapsed
A4TxBx.Visibility = Windows.Visibility.Collapsed
A5TxBx.Visibility = Windows.Visibility.Collapsed
A6TxBx.Visibility = Windows.Visibility.Collapsed
A7TxBx.Visibility = Windows.Visibility.Collapsed
A8TxBx.Visibility = Windows.Visibility.Collapsed
A9TxBx.Visibility = Windows.Visibility.Collapsed
A10TxBx.Visibility = Windows.Visibility.Collapsed
Parameter1TxBl.Visibility = Windows.Visibility.Visible
Parameter1TxBx.Visibility = Windows.Visibility.Visible
Parameter2TxBl.Visibility = Windows.Visibility.Visible
Parameter2TxBx.Visibility = Windows.Visibility.Visible
Parameter3TxBl.Visibility = Windows.Visibility.Visible
Parameter3TxBx.Visibility = Windows.Visibility.Visible
End If
' Aggiorno valori
If m_Mode = ModeOpt.SIDEANGLE Then
Dim sVal As String = String.Empty
GetPrivateProfileString(S_SIDES, K_SIDEANGLE, "45", sVal, m_MainWindow.GetIniFile())
Parameter1TxBx.Text = sVal
Else
m_dDripOffset = GetPrivateProfileDouble(S_SIDES, K_DRIPOFFSET, 20, m_MainWindow.GetIniFile())
m_dDripDepth = GetPrivateProfileDouble(S_SIDES, K_DRIPDEPTH, 10, m_MainWindow.GetIniFile())
m_dDripShort = GetPrivateProfileDouble(S_SIDES, K_DRIPSHORT, 0, m_MainWindow.GetIniFile())
Parameter1TxBx.Text = LenToString(m_dDripOffset, 3)
Parameter2TxBx.Text = LenToString(m_dDripDepth, 3)
Parameter3TxBx.Text = LenToString(m_dDripShort, 3)
End If
' Nascondo layer delle misure
Dim Part1 As Integer = EgtGetFirstInGroup(GDB_ID.ROOT)
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_AUX), GDB_ST.OFF)
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_QUOTATURE), GDB_ST.OFF)
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_ETICHETTE), GDB_ST.OFF)
EgtZoom(ZM.ALL)
End Sub
Private Sub TxBlChBxView()
' Numero di lati da visualizzare
Dim nCount As Integer = If(m_Mode = ModeOpt.SIDEANGLE,
m_SideAngleEntityList.Count(), m_DripEntityList.Count())
' Lati nascosti
For Index As Integer = 1 To 10 - nCount
If m_Mode = ModeOpt.SIDEANGLE Then
GetSideTxBxFromIndex(Index).Visibility = Windows.Visibility.Hidden
Else
GetChBxFromIndex(Index).Visibility = Windows.Visibility.Hidden
End If
GetTxBlFromIndex(Index).Visibility = Windows.Visibility.Hidden
Next
' Lati visibili
Dim TxBlIndex As Integer = 1
For Index As Integer = 10 - nCount + 1 To 10
If m_Mode = ModeOpt.SIDEANGLE Then
GetSideTxBxFromIndex(Index).Visibility = Windows.Visibility.Visible
Else
GetChBxFromIndex(Index).Visibility = Windows.Visibility.Visible
End If
GetTxBlFromIndex(Index).Text = If(m_Mode = ModeOpt.SIDEANGLE,
m_SideAngleEntityList(TxBlIndex - 1).sEntityName,
m_DripEntityList(TxBlIndex - 1).sEntityName)
GetTxBlFromIndex(Index).Visibility = Windows.Visibility.Visible
TxBlIndex += 1
Next
End Sub
Private Function GetChBxFromIndex(Index As Integer) As CheckBox
Select Case Index
Case 1
Return A1
Case 2
Return A2
Case 3
Return A3
Case 4
Return A4
Case 5
Return A5
Case 6
Return A6
Case 7
Return A7
Case 8
Return A8
Case 9
Return A9
Case Else
Return A10
End Select
End Function
Private Function GetSideTxBxFromIndex(Index As Integer) As EgtWPFLib.EgtTextBox
Select Case Index
Case 1
Return A1TxBx
Case 2
Return A2TxBx
Case 3
Return A3TxBx
Case 4
Return A4TxBx
Case 5
Return A5TxBx
Case 6
Return A6TxBx
Case 7
Return A7TxBx
Case 8
Return A8TxBx
Case 9
Return A9TxBx
Case Else
Return A10TxBx
End Select
End Function
Private Function GetTxBlFromIndex(Index As Integer) As TextBlock
Select Case Index
Case 1
Return Entity1
Case 2
Return Entity2
Case 3
Return Entity3
Case 4
Return Entity4
Case 5
Return Entity5
Case 6
Return Entity6
Case 7
Return Entity7
Case 8
Return Entity8
Case 9
Return Entity9
Case Else
Return Entity10
End Select
End Function
Private Sub SideAngleUC_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
If m_CallingPage = MainWindow.Pages.Draw Then
' Ricavo nome primo pezzo
Dim Part1 As Integer = EgtGetFirstInGroup(GDB_ID.ROOT)
' Attivo layer delle misure
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_AUX), GDB_ST.ON_)
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_QUOTATURE), GDB_ST.ON_)
EgtSetStatus(EgtGetFirstNameInGroup(Part1, COMPO_LAYER_ETICHETTE), GDB_ST.ON_)
' Svuoto layer in cui sono presenti i testi con le inclinazioni dei lati
If m_Mode = ModeOpt.SIDEANGLE Then
EgtEmptyGroup(EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER))
Else
EgtEmptyGroup(EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER))
End If
ElseIf m_CallingPage = MainWindow.Pages.Import Then
' Ricavo nome pezzo precedentemente selezionato
Dim Part1 As Integer = m_MainWindow.m_ImportPageUC.m_PrevSelPart
EgtErase(EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER))
End If
If m_Mode = ModeOpt.SIDEANGLE Then
WritePrivateProfileString(S_SIDES, K_SIDEANGLE, Parameter1TxBx.Text, m_MainWindow.GetIniFile())
Else
WritePrivateProfileString(S_SIDES, K_DRIPOFFSET, DoubleToString(m_dDripOffset, 3), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_SIDES, K_DRIPDEPTH, DoubleToString(m_dDripDepth, 3), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_SIDES, K_DRIPSHORT, DoubleToString(m_dDripShort, 3), m_MainWindow.GetIniFile())
End If
EgtDraw()
End Sub
Private Sub RefreshGeomId()
' Ricavo nome primo pezzo
Dim Part1 As Integer = EgtGetFirstInGroup(GDB_ID.ROOT)
' Ricavo nome layer con geometria esterna pezzo
Dim OutLoop As Integer = EgtGetFirstNameInGroup(Part1, NAME_OUTLOOP)
For Each Entity In m_SideAngleEntityList
Entity.nGeomId = EgtGetFirstNameInGroup(OutLoop, Entity.sEntityName)
Next
End Sub
Private Sub RefreshCheckAndValue()
For EntityIndex = 1 To m_SideAngleEntityList.Count
Dim Entity As SideAngleEntity = m_SideAngleEntityList(EntityIndex - 1)
' Creo testo con angolo di inclinazione
'If Entity.dSideAngle <> 0 Then
Dim nTxBxIndex As Integer = 10 - m_SideAngleEntityList.Count + EntityIndex
GetSideTxBxFromIndex(nTxBxIndex).Text = DoubleToString(Entity.dSideAngle, 1)
'End If
Next
End Sub
Private Sub RefreshSideAngleText()
' Imposto contesto corrente e ricavo Id pezzo
Dim Part1 As Integer = GDB_ID.NULL
If m_CallingPage = MainWindow.Pages.Draw Then
EgtSetCurrentContext(m_MainWindow.m_DrawPageUC.DrawScene.GetCtx())
Part1 = EgtGetFirstInGroup(GDB_ID.ROOT)
ElseIf m_CallingPage = MainWindow.Pages.Import Then
EgtSetCurrentContext(m_MainWindow.m_ImportPageUC.ImportScene.GetCtx())
Part1 = EgtGetFirstSelectedObj()
End If
' Calcolo dimensione ingombro OutLoop
Dim OutLoop As Integer = EgtGetFirstNameInGroup(Part1, NAME_OUTLOOP)
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(OutLoop, GDB_BB.STANDARD, ptMin, ptMax)
Dim dBBoxRad As Double = 0.5 * Point3d.DistXY(ptMin, ptMax)
' Preparo layer con testi inclinazioni (svuotandolo o creandolo)
Dim TextLayer As Integer = EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER)
If TextLayer <> GDB_ID.NULL Then
EgtEmptyGroup(TextLayer)
Else
TextLayer = EgtCreateGroup(Part1)
EgtSetName(TextLayer, SIDE_ANGLE_LAYER)
EgtSetColor(TextLayer, New Color3d(0, 0, 0))
End If
' Se modalità angoli di inclinazione...
If m_Mode = ModeOpt.SIDEANGLE Then
' Per ogni entità, creo testo con nome e angolo di inclinazione
For Each Entity In m_SideAngleEntityList
Dim sText As String = Entity.sEntityName & " = " & DoubleToString(Entity.dSideAngle, 1) & "°"
AddTextToLine(sText, Entity.nTextId, Entity.nGeomId, 20, dBBoxRad, True)
Next
' Altrimenti modalità gocciolatoio
Else
' Per ogni entità creo testo con nome
For Each Entity In m_DripEntityList
AddTextToLine(Entity.sEntityName, Entity.nTextId, Entity.nGeomId, 20, dBBoxRad, True)
Next
' Creo le geometrie dei gocciolatoi
CreateDripGeom(Part1)
End If
' Aggiorno visualizzazione
EgtZoom(ZM.ALL)
End Sub
Private Sub InitSides()
Dim Part1 As Integer
If m_CallingPage = MainWindow.Pages.Draw Then
' Imposto contesto corrente
EgtSetCurrentContext(m_MainWindow.m_DrawPageUC.DrawScene.GetCtx())
' Ricavo nome primo pezzo
Part1 = EgtGetFirstInGroup(GDB_ID.ROOT)
Else
' Imposto contesto corrente
EgtSetCurrentContext(m_MainWindow.m_ImportPageUC.ImportScene.GetCtx())
' Ricavo nome primo pezzo
Part1 = EgtGetFirstSelectedObj()
End If
AdjustFlatPart(Part1)
' Ricavo nome layer con geometria esterna pezzo
Dim OutLoop As Integer = EgtGetFirstNameInGroup(Part1, NAME_OUTLOOP)
' Calcolo dimensione ingombro OutLoop
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(OutLoop, GDB_BB.STANDARD, ptMin, ptMax)
Dim dBBoxRad As Double = 0.5 * Point3d.DistXY(ptMin, ptMax)
' Creo layer per testi se non esiste già
Dim TextLayer As Integer = EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER)
If TextLayer = GDB_ID.NULL Then
TextLayer = EgtCreateGroup(Part1)
EgtSetName(TextLayer, SIDE_ANGLE_LAYER)
EgtSetColor(TextLayer, New Color3d(0, 0, 0))
End If
Dim LastLine As Integer = EgtGetLastInGroup(OutLoop)
Dim CurrLine As Integer = EgtGetFirstInGroup(OutLoop)
Dim NextLine As Integer = EgtGetNext(CurrLine)
' Creo indice per numerare le entità in ImportPage
Dim nEntityIndex As Integer = 1
' Ciclo che verifica se possibile inclinare la linea corrente fino alla penultima
While NextLine <> GDB_ID.NULL
If m_Mode = ModeOpt.SIDEANGLE Then
If VerifyIsSideAnglePossible(LastLine, CurrLine, NextLine) Then
' Aggiungo il lato alla lista di quelli inclinabili e ne azzero l'inclinazione
AddSideAngle(CurrLine, TextLayer, dBBoxRad, nEntityIndex)
nEntityIndex += 1
End If
Else
If VerifyIsSideDripPossible(LastLine, CurrLine, NextLine) Then
' Aggiungo il lato alla lista di quelli su cui è possibile mettere il gocciolatoio
AddDripSide(CurrLine, TextLayer, dBBoxRad, nEntityIndex)
nEntityIndex += 1
End If
End If
LastLine = CurrLine
CurrLine = NextLine
NextLine = EgtGetNext(CurrLine)
End While
' Verifico ultima linea
NextLine = EgtGetFirstInGroup(OutLoop)
If m_Mode = ModeOpt.SIDEANGLE Then
If VerifyIsSideAnglePossible(LastLine, CurrLine, NextLine) Then
' Aggiungo il lato alla lista di quelli inclinabili e ne azzero l'inclinazione
AddSideAngle(CurrLine, TextLayer, dBBoxRad, nEntityIndex)
nEntityIndex += 1
End If
Else
If VerifyIsSideDripPossible(LastLine, CurrLine, NextLine) Then
' Aggiungo il lato alla lista di quelli su cui è possibile mettere il gocciolatoio
AddDripSide(CurrLine, TextLayer, dBBoxRad, nEntityIndex)
nEntityIndex += 1
End If
End If
' Aggiorno interfaccia
If m_CallingPage = MainWindow.Pages.Import Then
If m_Mode = ModeOpt.SIDEANGLE Then
For Each Entity In m_SideAngleEntityList
If Entity.dSideAngle <> 0 Then
Dim nI As Integer = 0
StringToInt(Entity.sEntityName.Substring(1), nI)
CheckSide(nI)
End If
Next
Else
For Each Entity In m_DripEntityList
If Entity.bHaveDrip Then
Dim nI As Integer = 0
StringToInt(Entity.sEntityName.Substring(1), nI)
CheckSide(nI)
End If
Next
End If
End If
End Sub
'Funzione che checka i lati
Private Sub CheckSide(nIndex As Integer)
' Seleziono checkbox
If m_Mode = ModeOpt.SIDEANGLE Then
GetChBxFromIndex(10 - (m_SideAngleEntityList.Count - nIndex)).IsChecked = True
Else
GetChBxFromIndex(10 - (m_DripEntityList.Count - nIndex)).IsChecked = True
End If
End Sub
' Funzione che verifica se la linea corrente è inclinabile in base al tipo della precedente e successiva
Private Function VerifyIsSideAnglePossible(LastLine As Integer, CurrLine As Integer, NextLine As Integer) As Boolean
' Verifico se CurrLine è una linea
If EgtGetType(CurrLine) <> GDB_TY.CRV_LINE Then
Return False
End If
' Verifico se curva precedente mi permette di inclinare
Dim bLastOk As Boolean = False
If EgtGetType(LastLine) = GDB_TY.CRV_LINE Then
bLastOk = True
ElseIf EgtGetType(LastLine) = GDB_TY.CRV_ARC Then
' Ricavo direzione finale linea precedente
Dim vtLastEnd As Vector3d
EgtEndVector(LastLine, vtLastEnd)
' Ricavo direzione iniziale linea corrente
Dim vtCurrStart As Vector3d
EgtStartVector(CurrLine, vtCurrStart)
' Confronto direzioni per vedere se sono tangenti
' calcolo differenza dei vettori
Dim vtDiff As Vector3d = vtLastEnd - vtCurrStart
' verifico che sia nulla o quasi
bLastOk = Not vtDiff.IsSmall()
Else
EgtOutLog("Error in Compo Outloop: found an entity that is not a line or a arc")
End If
' Verifico se curva successiva mi permette di inclinare
Dim bNextOk As Boolean = False
If EgtGetType(NextLine) = GDB_TY.CRV_LINE Then
bNextOk = True
ElseIf EgtGetType(NextLine) = GDB_TY.CRV_ARC Then
' Ricavo direzione finale linea corrente
Dim vtCurrEnd As Vector3d
EgtEndVector(CurrLine, vtCurrEnd)
' Ricavo direzione iniziale linea successiva
Dim vtNextStart As Vector3d
EgtStartVector(NextLine, vtNextStart)
' Confronto direzioni per vedere se sono tangenti
' calcolo differenza dei vettori
Dim vtDiff As Vector3d = vtCurrEnd - vtNextStart
' verifico che sia nulla o quasi
bNextOk = Not vtDiff.IsSmall()
Else
EgtOutLog("Error in Compo Outloop: found an entity that is not a line or a arc")
End If
' Se entrambe me lo permettono restituisco vero
If bLastOk And bNextOk Then
Return True
End If
Return False
End Function
' Funzione che verifica se alla linea corrente è associabile un canalino
Private Function VerifyIsSideDripPossible(LastLine As Integer, CurrLine As Integer, NextLine As Integer) As Boolean
' Verifico se CurrLine è una linea
If EgtGetType(CurrLine) <> GDB_TY.CRV_LINE Then
Return False
End If
Return True
End Function
' Funzione che gestisce le operazioni sull'entità da inclinare
Private Sub AddSideAngle(CurrLine As Integer, TextLayer As Integer, dBBoxRad As Double, nEntityIndex As Integer)
' Se sono in importa
If m_CallingPage = MainWindow.Pages.Import Then
EgtSetName(CurrLine, "A" & nEntityIndex.ToString())
End If
'Ricavo angolo dell'entità
Dim dSideAngleVal As Double
If Not EgtGetInfo(CurrLine, INFO_SIDE_ANGLE, dSideAngleVal) Then
dSideAngleVal = 0
End If
' Aggiungo entità all'elenco di quelle inclinabili
Dim sEntityName As String = String.Empty
EgtGetName(CurrLine, sEntityName)
If m_CallingPage = MainWindow.Pages.Draw Then
m_SideAngleEntityList.Add(New SideAngleEntity(CurrLine, sEntityName, TextLayer, 0))
' Cancello inclinazione nell'apposito campo info
EgtRemoveInfo(CurrLine, INFO_SIDE_ANGLE)
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName & " = 0°", TextLayer, CurrLine, 20, dBBoxRad, True)
Else
m_SideAngleEntityList.Add(New SideAngleEntity(CurrLine, sEntityName, TextLayer, dSideAngleVal))
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName & " = " & DoubleToString(dSideAngleVal, 1) & "°", TextLayer, CurrLine, 20, dBBoxRad, True)
End If
End Sub
' Funzione che gestisce le operazioni sull'entità con gocciolatoio
Private Sub AddDripSide(CurrLine As Integer, TextLayer As Integer, dBBoxRad As Double, nEntityIndex As Integer)
' Se sono in importa
If m_CallingPage = MainWindow.Pages.Import Then
EgtSetName(CurrLine, "A" & nEntityIndex.ToString())
End If
' Ricavo info dell'entità
Dim bHaveDripVal As Boolean
If Not EgtGetInfo(CurrLine, INFO_HAVE_DRIP, bHaveDripVal) Then
bHaveDripVal = False
End If
' Aggiungo entità all'elenco di quelle che possono avere il gocciolatoio
Dim sEntityName As String = String.Empty
EgtGetName(CurrLine, sEntityName)
If m_CallingPage = MainWindow.Pages.Draw Then
m_DripEntityList.Add(New DripEntity(CurrLine, sEntityName, TextLayer, False))
' Cancello gocciolatoio nell'apposito campo info
EgtRemoveInfo(CurrLine, INFO_HAVE_DRIP)
' Creo testo entità
AddTextToLine(sEntityName, TextLayer, CurrLine, 20, dBBoxRad, True)
Else
m_DripEntityList.Add(New DripEntity(CurrLine, sEntityName, TextLayer, bHaveDripVal))
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName, TextLayer, CurrLine, 20, dBBoxRad, True)
End If
End Sub
' Funzione che dato un segmento e una distanza, scrive il testo centrato alla sua sinistra (destra se bTextExt)
Friend Shared Function AddTextToLine(sText As String, TextLayer As Integer, CurrLine As Integer, dDistance As Double,
dBBoxRad As Double, bTextExt As Boolean, Optional bRot As Boolean = False) As Integer
' Calcolo altezza testo
Dim dH As Double = 0.05 * dBBoxRad
' Creo testo
Dim nText As Integer = EgtCreateTextAdv(TextLayer, Point3d.ORIG(), 0, sText, "", 500, False, dH, 1, 0, INS_POS.MC)
' Calcolo posizionamento
' BBox del testo e suo centro
Dim ptMinBBox As Point3d
Dim ptMaxBBox As Point3d
EgtGetBBox(nText, GDB_BB.STANDARD, ptMinBBox, ptMaxBBox)
Dim ptMidBBox As Point3d
ptMidBBox = Point3d.Media(ptMinBBox, ptMaxBBox)
' estremi della CurrLine
Dim ptLineStart As Point3d
EgtStartPoint(CurrLine, nText, ptLineStart)
Dim ptLineEnd As Point3d
EgtEndPoint(CurrLine, nText, ptLineEnd)
' versore della CurrLine
Dim vtCurrLine As Vector3d = ptLineEnd - ptLineStart
vtCurrLine.Normalize()
' versore perpendicolare alla CurrLine che punta verso il testo
Dim vtOrtoLine As New Vector3d(vtCurrLine)
If bTextExt Then
vtOrtoLine.Rotate(Vector3d.Z_AX(), -90)
Else
vtOrtoLine.Rotate(Vector3d.Z_AX(), 90)
End If
' eventuale rotazione del testo
Dim dRotAng As Double = 0
If bRot Then
dRotAng = Math.Atan2(vtCurrLine.y, vtCurrLine.x) * 180 / Math.PI
Dim dSpecRotAng = dRotAng
If dSpecRotAng > 91 Then
dSpecRotAng -= 180
ElseIf dSpecRotAng < -89 Then
dSpecRotAng += 180
End If
EgtRotate(nText, Point3d.ORIG(), Vector3d.Z_AX(), dSpecRotAng)
End If
' vettore dal centro del BBox all'estremo più vicino
Dim vtptExtptMC As Vector3d
If bRot Then
vtptExtptMC = New Vector3d(0, ptMidBBox.y - ptMinBBox.y, 0)
vtptExtptMC.Rotate(Vector3d.Z_AX(), dRotAng)
Else
If bTextExt Then
If vtCurrLine.x > 0 Then
If vtCurrLine.y > 0 Then
vtptExtptMC = ptMidBBox - New Point3d(ptMinBBox.x, ptMaxBBox.y, 0)
Else
vtptExtptMC = ptMidBBox - ptMaxBBox
End If
Else
If vtCurrLine.y > 0 Then
vtptExtptMC = ptMidBBox - ptMinBBox
Else
vtptExtptMC = ptMidBBox - New Point3d(ptMaxBBox.x, ptMinBBox.y, 0)
End If
End If
Else
If vtCurrLine.x > 0 Then
If vtCurrLine.y > 0 Then
vtptExtptMC = ptMidBBox - New Point3d(ptMaxBBox.x, ptMinBBox.y, 0)
Else
vtptExtptMC = ptMidBBox - ptMinBBox
End If
Else
If vtCurrLine.y > 0 Then
vtptExtptMC = ptMidBBox - ptMaxBBox
Else
vtptExtptMC = ptMidBBox - New Point3d(ptMinBBox.x, ptMaxBBox.y, 0)
End If
End If
End If
End If
' Calcolo il centro del testo
Dim ptTextMC As Point3d = Point3d.Media(ptLineStart, ptLineEnd) + vtOrtoLine * (dDistance + (vtOrtoLine * vtptExtptMC))
EgtMove(nText, (ptTextMC - Point3d.ORIG()))
Return nText
End Function
' Funzione che crea le geometrie dei gocciolatoi
Friend Sub CreateDripGeom(nPartId As Integer)
' Recupero Id layer di contorno esterno
Dim nOutLoopId = EgtGetFirstNameInGroup(nPartId, NAME_OUTLOOP)
' Preparo layer con geometria gocciolatoi (svuotandolo o creandolo)
Dim DripLayer As Integer = EgtGetFirstNameInGroup(nPartId, NAME_DRIPCUT)
If DripLayer <> GDB_ID.NULL Then
EgtEmptyGroup(DripLayer)
Else
DripLayer = EgtCreateGroup(nPartId)
EgtSetName(DripLayer, NAME_DRIPCUT)
End If
' Per ogni entità con gocciolatoio, ne inserisco una copia nel layer
Dim vSelId As New List(Of Integer)
For Each Entity In m_DripEntityList
If Entity.bHaveDrip Then
Dim nSouId As Integer = EgtGetFirstNameInGroup(nOutLoopId, Entity.sEntityName)
Dim nNewId As Integer = EgtCopyGlob(nSouId, DripLayer)
EgtSetName(nNewId, Entity.sEntityName)
vSelId.Add(nNewId)
End If
Next
' Concateno le curve
EgtCreateCurveCompoByReorder(DripLayer, vSelId.Count(), vSelId.ToArray(), New Point3d(), True)
' Eseguo offset dei risultati ed eventuali accorciamenti iniziali e finali
Dim nCrvId As Integer = EgtGetFirstInGroup(DripLayer)
While nCrvId <> GDB_ID.NULL
EgtOffsetCurve(nCrvId, -m_dDripOffset, OFF_TYPE.EXTEND)
EgtSetColor(nCrvId, New Color3d(255, 165, 0))
EgtSetInfo(nCrvId, INFO_DEPTH, m_dDripDepth)
If m_dDripShort > EPS_SMALL Then
Dim dLen As Double
EgtCurveLength(nCrvId, dLen)
EgtTrimCurveEndAtLen(nCrvId, dLen - m_dDripShort)
EgtTrimCurveStartAtLen(nCrvId, m_dDripShort)
EgtSetInfo(nCrvId, INFO_STRICT, "1")
End If
nCrvId = EgtGetNext(nCrvId)
End While
End Sub
Private Sub SideCheck_Click(sender As Object, e As RoutedEventArgs) Handles A1.Click, A2.Click, A3.Click, A4.Click, A5.Click, A6.Click, A7.Click, A8.Click, A9.Click, A10.Click
Dim CurrCheckBox As CheckBox = e.Source
If m_Mode = ModeOpt.SIDEANGLE Then
' Nuovo angolo di inclinazione
Dim dSideAngle As Double
' Se checked lo imposto al valore letto dalla TxBx
If CurrCheckBox.IsChecked() Then
StringToDouble(Parameter1TxBx.Text, dSideAngle)
' altrimenti lo imposto a zero
Else
dSideAngle = 0
End If
' Converto nome checkbox in nome elemento tenendo conto dello slittamento verso il basso
Dim nCurrSide As Integer = m_SideAngleEntityList.Count() - (10 - CInt(CurrCheckBox.Name.Substring(1)))
Dim sCurrSide As String = m_SideAngleEntityList(nCurrSide - 1).sEntityName
' Lo modifico nella geometria e nella lista inclinazioni
ModifySideAngle(sCurrSide, dSideAngle)
' Aggiorno tutti i testi
RefreshSideAngleText()
Else
' Recupero stato entità
Dim bVal As Boolean = CurrCheckBox.IsChecked()
' Converto nome checkbox in nome elemento tenendo conto dello slittamento verso il basso
Dim nCurrSide As Integer = m_DripEntityList.Count() - (10 - CInt(CurrCheckBox.Name.Substring(1)))
Dim sCurrSide As String = m_DripEntityList(nCurrSide - 1).sEntityName
' Modifico info gocciolatoi
ModifyDrip(sCurrSide, bVal)
' Aggiorno tutti i testi e le geometrie
RefreshSideAngleText()
End If
End Sub
Private Sub A1TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A1TxBx.EgtClosed
SetSideAngleFromTxBx(1, A1TxBx)
End Sub
Private Sub A2TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A2TxBx.EgtClosed
SetSideAngleFromTxBx(2, A2TxBx)
End Sub
Private Sub A3TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A3TxBx.EgtClosed
SetSideAngleFromTxBx(3, A3TxBx)
End Sub
Private Sub A4TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A4TxBx.EgtClosed
SetSideAngleFromTxBx(4, A4TxBx)
End Sub
Private Sub A5TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A5TxBx.EgtClosed
SetSideAngleFromTxBx(5, A5TxBx)
End Sub
Private Sub A6eTxBx_EgtClosed(sender As Object, e As EventArgs) Handles A6TxBx.EgtClosed
SetSideAngleFromTxBx(6, A6TxBx)
End Sub
Private Sub A7TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A7TxBx.EgtClosed
SetSideAngleFromTxBx(7, A7TxBx)
End Sub
Private Sub A8TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A8TxBx.EgtClosed
SetSideAngleFromTxBx(8, A8TxBx)
End Sub
Private Sub A9TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A9TxBx.EgtClosed
SetSideAngleFromTxBx(9, A9TxBx)
End Sub
Private Sub A10TxBx_EgtClosed(sender As Object, e As EventArgs) Handles A10TxBx.EgtClosed
SetSideAngleFromTxBx(10, A10TxBx)
End Sub
Private Sub SetSideAngleFromTxBx(SideIndex As Integer, AngleTxBx As EgtWPFLib.EgtTextBox)
' Nuovo angolo di inclinazione
Dim dSideAngle As Double
StringToDouble(AngleTxBx.Text, dSideAngle)
' Converto nome checkbox in nome elemento tenendo conto dello slittamento verso il basso
Dim nCurrSide As Integer = m_SideAngleEntityList.Count() - (10 - SideIndex)
Dim sCurrSide As String = m_SideAngleEntityList(nCurrSide - 1).sEntityName
' Lo modifico nella geometria e nella lista inclinazioni
ModifySideAngle(sCurrSide, dSideAngle)
' Aggiorno tutti i testi
RefreshSideAngleText()
End Sub
' Funzione che modifica l'inclinazione di un lato
Friend Function ModifySideAngle(sEntityName As String, dSideAngle As Double) As Boolean
' Ricavo CurrEntity dal nome
Dim CurrEntity As SideAngleEntity = SideAngleEntity.FindEntity(sEntityName)
If IsNothing(CurrEntity) Then
EgtOutLog("Error in side angle definition: selected line not found in SideAngleList")
Return False
End If
' Scrivo nuovo angolo nelle info
If dSideAngle <> 0 Then
EgtSetInfo(CurrEntity.nGeomId, INFO_SIDE_ANGLE, dSideAngle)
' Cancello inclinazione nell'apposito campo info
Else
EgtRemoveInfo(CurrEntity.nGeomId, INFO_SIDE_ANGLE)
End If
' Aggiorno lista entità con nuova inclinazione
CurrEntity.dSideAngle = dSideAngle
Return True
End Function
' Funzione che modifica l'eventuale canalino di un lato
Friend Function ModifyDrip(sEntityName As String, bVal As Boolean) As Boolean
' Ricavo CurrEntity dal nome
Dim CurrEntity As DripEntity = DripEntity.FindEntity(sEntityName)
If IsNothing(CurrEntity) Then
EgtOutLog("Error in drip definition: selected line not found in DripEntity")
Return False
End If
' Scrivo nuovo angolo nelle info
If bVal Then
EgtSetInfo(CurrEntity.nGeomId, INFO_HAVE_DRIP, "1")
' Cancello inclinazione nell'apposito campo info
Else
EgtRemoveInfo(CurrEntity.nGeomId, INFO_HAVE_DRIP)
End If
' Aggiorno lista entità con nuova inclinazione
CurrEntity.bHaveDrip = bVal
Return True
End Function
Friend Sub DeleteSideAngle()
' Cancello lista lati inclinati
If m_Mode = ModeOpt.SIDEANGLE Then
m_SideAngleEntityList.Clear()
' Annullo tutti i testi
A1TxBx.Text = String.Empty
A2TxBx.Text = String.Empty
A3TxBx.Text = String.Empty
A4TxBx.Text = String.Empty
A5TxBx.Text = String.Empty
A6TxBx.Text = String.Empty
A7TxBx.Text = String.Empty
A8TxBx.Text = String.Empty
A9TxBx.Text = String.Empty
A10TxBx.Text = String.Empty
Else
m_DripEntityList.Clear()
' Annullo tutti i CheckBox
A1.IsChecked = False
A2.IsChecked = False
A3.IsChecked = False
A4.IsChecked = False
A5.IsChecked = False
A6.IsChecked = False
A7.IsChecked = False
A8.IsChecked = False
A9.IsChecked = False
A10.IsChecked = False
End If
End Sub
Private Sub Parameter1TxBx_EgtClosed(sender As Object, e As EventArgs) Handles Parameter1TxBx.EgtClosed
If m_Mode = ModeOpt.SIDEANGLE Then
'' ciclo sui checkbox calcolati sul numero di lati inclinabili presenti
'For Index As Integer = 10 - m_SideAngleEntityList.Count + 1 To 10
' ' Nuovo angolo di inclinazione
' Dim dSideAngle As Double
' ' Se checked lo imposto al valore letto dalla TxBx
' If GetChBxFromIndex(Index).IsChecked() Then
' StringToDouble(Parameter1TxBx.Text, dSideAngle)
' Else
' ' altrimenti lo imposto a zero
' dSideAngle = 0
' End If
' ' Converto nome checkbox in nome elemento tenendo conto dello slittamento verso il basso
' Dim nCurrSide As Integer = m_SideAngleEntityList.Count() - (10 - CInt(GetChBxFromIndex(Index).Name.Substring(1)))
' Dim sCurrSide As String = m_SideAngleEntityList(nCurrSide - 1).sEntityName
' ' Lo modifico nella geometria e nella lista inclinazioni
' ModifySideAngle(sCurrSide, dSideAngle)
'Next
'' Aggiorno tutti i testi
'RefreshSideAngleText()
Else
' Recupero il valore
StringToDouble(Parameter1TxBx.Text, m_dDripOffset)
' Creo le geometrie dei gocciolatoi
RefreshSideAngleText()
End If
End Sub
Private Sub Parameter2TxBx_EgtClosed(sender As Object, e As EventArgs) Handles Parameter2TxBx.EgtClosed
If m_Mode = ModeOpt.DRIP Then
' Recupero il valore
StringToDouble(Parameter2TxBx.Text, m_dDripDepth)
' Creo le geometrie dei gocciolatoi
RefreshSideAngleText()
End If
End Sub
Private Sub Parameter3TxBx_EgtClosed(sender As Object, e As EventArgs) Handles Parameter3TxBx.EgtClosed
If m_Mode = ModeOpt.DRIP Then
' Recupero il valore
StringToDouble(Parameter3TxBx.Text, m_dDripShort)
' Creo le geometrie dei gocciolatoi
RefreshSideAngleText()
End If
End Sub
Friend Sub WriteSideAngleForNest(nCtx As Integer)
' Imposto contesto corrente
EgtSetCurrentContext(nCtx)
Dim CurrPart As Integer
CurrPart = EgtGetFirstInGroup(GDB_ID.ROOT)
While CurrPart <> GDB_ID.NULL
' Ricavo nome layer con geometria esterna pezzo
Dim OutLoop As Integer = EgtGetFirstNameInGroup(CurrPart, NAME_OUTLOOP)
' Calcolo dimensione ingombro OutLoop
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(OutLoop, GDB_BB.STANDARD, ptMin, ptMax)
Dim dBBoxRad As Double = 0.5 * Point3d.DistXY(ptMin, ptMax)
' Creo layer per testi nesting
Dim TextLayer As Integer = EgtCreateGroup(CurrPart)
EgtSetName(TextLayer, SIDE_ANGLE_LAYER)
EgtSetColor(TextLayer, New Color3d(0, 0, 128))
' Ciclo sulle linee di contorno, se hanno info con inclinazione aggiungo testo con angolo
Dim CurrLine As Integer = EgtGetFirstInGroup(OutLoop)
While CurrLine <> GDB_ID.NULL
Dim dSideAngle As Double = 0
EgtGetInfo(CurrLine, INFO_SIDE_ANGLE, dSideAngle)
Dim dSideAngle2 As Double = 0
EgtGetInfo(CurrLine, INFO_SIDE_ANGLE2, dSideAngle2)
If Math.Abs(dSideAngle) > EPS_ANG_SMALL Then
' Creo testo con angolo di inclinazione
Dim sText As String = DoubleToString(dSideAngle, 1) & "°"
If Math.Abs(dSideAngle2) > EPS_ANG_SMALL Then sText &= "; " & DoubleToString(dSideAngle2, 1) & "°"
AddTextToLine(sText, TextLayer, CurrLine, 15, dBBoxRad, False, True)
End If
CurrLine = EgtGetNext(CurrLine)
End While
CurrPart = EgtGetNext(CurrPart)
End While
End Sub
Friend Sub ReLoadSideAnglePage()
SideAngleUC_Unloaded(Me, New RoutedEventArgs)
SideAngleUC_Loaded(Me, New RoutedEventArgs)
End Sub
End Class
Friend Class SideAngleEntity
Private Shared m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
Private m_nGeomId As Integer
Private m_sEntityName As String
Private m_nTextId As Integer
Private m_dSideAngle As Double
Public Property nGeomId As Integer
Get
Return m_nGeomId
End Get
Set(value As Integer)
m_nGeomId = value
End Set
End Property
Public ReadOnly Property sEntityName As String
Get
Return m_sEntityName
End Get
End Property
Public ReadOnly Property nTextId As Integer
Get
Return m_nTextId
End Get
End Property
Public Property dSideAngle As Double
Get
Return m_dSideAngle
End Get
Set(value As Double)
m_dSideAngle = value
End Set
End Property
Sub New(nId As Integer, sEntityName As String, nTextId As Integer, dSideAngle As Double)
m_nGeomId = nId
m_sEntityName = sEntityName
m_nTextId = nTextId
m_dSideAngle = dSideAngle
End Sub
Friend Shared Function FindEntity(sEntityName As String) As SideAngleEntity
Dim EntityList As List(Of SideAngleEntity) = Nothing
If m_MainWindow.m_ActivePage = MainWindow.Pages.Draw Then
EntityList = m_MainWindow.m_DrawPageUC.m_SideAngle.m_SideAngleEntityList
ElseIf m_MainWindow.m_ActivePage = MainWindow.Pages.Import Then
EntityList = m_MainWindow.m_ImportPageUC.m_SideAngleUC.m_SideAngleEntityList
End If
If IsNothing(EntityList) Then
Return Nothing
End If
For Each Entity In EntityList
If Entity.m_sEntityName = sEntityName Then
Return Entity
End If
Next
Return Nothing
End Function
End Class
Friend Class DripEntity
Private Shared m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
Private m_nGeomId As Integer
Private m_sEntityName As String
Private m_nTextId As Integer
Private m_bHaveDrip As Boolean
Public Property nGeomId As Integer
Get
Return m_nGeomId
End Get
Set(value As Integer)
m_nGeomId = value
End Set
End Property
Public ReadOnly Property sEntityName As String
Get
Return m_sEntityName
End Get
End Property
Public ReadOnly Property nTextId As Integer
Get
Return m_nTextId
End Get
End Property
Public Property bHaveDrip As Boolean
Get
Return m_bHaveDrip
End Get
Set(value As Boolean)
m_bHaveDrip = value
End Set
End Property
Sub New(nId As Integer, sEntityName As String, nTextId As Integer, bHaveDrip As Boolean)
m_nGeomId = nId
m_sEntityName = sEntityName
m_nTextId = nTextId
m_bHaveDrip = bHaveDrip
End Sub
Friend Shared Function FindEntity(sEntityName As String) As DripEntity
Dim EntityList As List(Of DripEntity) = Nothing
If m_MainWindow.m_ActivePage = MainWindow.Pages.Draw Then
EntityList = m_MainWindow.m_DrawPageUC.m_SideAngle.m_DripEntityList
ElseIf m_MainWindow.m_ActivePage = MainWindow.Pages.Import Then
EntityList = m_MainWindow.m_ImportPageUC.m_SideAngleUC.m_DripEntityList
End If
If IsNothing(EntityList) Then
Return Nothing
End If
For Each Entity In EntityList
If Entity.m_sEntityName = sEntityName Then
Return Entity
End If
Next
Return Nothing
End Function
End Class