Files
omagoffice/SideEntityControl/SideEntityControlVM.vb
T
Emmanuele Sassi 61d7f6082f OmagOFFICE :
- Aggiunta possibilità di devinire l'inclinazione dei singoli lati con angoli diversi grazie all'apposita opzione.
2017-07-07 18:30:58 +00:00

995 lines
38 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Public Class SideEntityControlVM
Inherits VMBase
Public Enum ModeOpt As Integer
SIDEANGLE = 0
DRIP = 1
End Enum
Public Enum CallingWindowOpt As Integer
COMPO = 0
DXFIMPORT = 1
End Enum
' 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"
' Variabile che indica se sono in sideangle o drip
Friend m_Mode As ModeOpt
Friend Shared m_SideAngleCheck As Boolean = False
' Lista di tutte le entità inclinabili presenti nel progetto
Private m_SideEntityList As ObservableCollection(Of SideEntity)
Public Property SideEntityList As ObservableCollection(Of SideEntity)
Get
Return m_SideEntityList
End Get
Set(value As ObservableCollection(Of SideEntity))
m_SideEntityList = value
End Set
End Property
Private m_Parameter23_Visibility As Visibility
Public Property Parameter23_Visibility As Visibility
Get
Return m_Parameter23_Visibility
End Get
Set(value As Visibility)
m_Parameter23_Visibility = value
NotifyPropertyChanged("Parameter23_Visibility")
End Set
End Property
Private m_Parameter1_Visibility As Visibility
Public ReadOnly Property Parameter1_Visibility As Visibility
Get
If m_Mode = ModeOpt.SIDEANGLE Then
If m_SideAngleCheck Then
Return Visibility.Visible
Else
Return Visibility.Collapsed
End If
Else
Return Visibility.Visible
End If
End Get
End Property
Private m_Parameter1 As Double
Public Property Parameter1 As String
Get
Return DoubleToString(m_Parameter1, -2)
End Get
Set(value As String)
StringToDouble(value, m_Parameter1)
SideAngleEntity.m_Parameter1 = value
If m_Mode = ModeOpt.SIDEANGLE Then
' ciclo sui checkbox calcolati sul numero di lati inclinabili presenti
For Index As Integer = 0 To m_SideEntityList.Count - 1
' Nuovo angolo di inclinazione
Dim dSideAngle As Double
' Se checked lo imposto al valore letto dalla TxBx
If m_SideEntityList(Index).bIsChecked Then
StringToDouble(value, dSideAngle)
Else
' altrimenti lo imposto a zero
dSideAngle = 0
End If
' Lo modifico nella geometria e nella lista inclinazioni
ModifySideAngle(m_SideEntityList(Index).sEntityName, dSideAngle)
Next
' Aggiorno tutti i testi
RefreshSideAngleText()
Else
' Recupero il valore
StringToDouble(value, m_dDripOffset)
' Creo le geometrie dei gocciolatoi
RefreshSideAngleText()
End If
End Set
End Property
Private Sub SetParameter1(value As Double)
m_Parameter1 = value
SideAngleEntity.m_Parameter1 = value
NotifyPropertyChanged("Parameter1")
End Sub
Private m_Parameter2 As Double
Public Property Parameter2 As Double
Get
Return LenToString(m_Parameter2, -2)
End Get
Set(value As Double)
StringToLen(value, m_Parameter2)
End Set
End Property
Private Sub SetParameter2(value As Double)
m_Parameter2 = value
NotifyPropertyChanged("Parameter2")
End Sub
Private m_Parameter3 As Double
Public Property Parameter3 As Double
Get
Return LenToString(m_Parameter3, -2)
End Get
Set(value As Double)
StringToLen(value, m_Parameter3)
End Set
End Property
Private Sub SetParameter3(value As Double)
m_Parameter3 = value
NotifyPropertyChanged("Parameter3")
End Sub
Private m_dDripOffset As Double = 10
Private m_dDripDepth As Double = 10
Private m_dDripShort As Double = 0
Private m_CallingWndScene As Scene
Private m_CallingWindow As CallingWindowOpt
#Region "Messages"
Private m_Parameter1Msg As String
Public Property Parameter1Msg As String
Get
Return EgtMsg(MSG_COMPONENTPAGEUC + 47)
End Get
Set(value As String)
m_Parameter1Msg = value
NotifyPropertyChanged("Parameter1Msg")
End Set
End Property
Public ReadOnly Property Parameter2Msg As String
Get
Return EgtMsg(MSG_IMPORTPAGEUC + 11) ' Affondamento
End Get
End Property
Public ReadOnly Property Parameter3Msg As String
Get
Return EgtMsg(MSG_IMPORTPAGEUC + 12) ' Accorciamento
End Get
End Property
#End Region ' Messages
#Region "CONSTRUCTOR"
Sub New(CallingWindow As CallingWindowOpt, CallingWndScene As Scene, Mode As ModeOpt, SideEntityList As List(Of SideEntity))
SideAngleEntity.m_ModifySideAngle = AddressOf ModifySideAngle
SideAngleEntity.m_RefreshSideAngleText = AddressOf RefreshSideAngleText
m_CallingWindow = CallingWindow
m_CallingWndScene = CallingWndScene
m_Mode = Mode
m_SideEntityList = If(IsNothing(SideEntityList), New ObservableCollection(Of SideEntity), New ObservableCollection(Of SideEntity)(SideEntityList))
NotifyPropertyChanged("SideEntityList")
m_SideAngleCheck = If(GetMainPrivateProfileInt(S_COMPO, K_SIDEMODE, 0) = 0, True, False)
If CallingWindow = CallingWindowOpt.COMPO Then
' Imposto contesto corrente
EgtSetCurrentContext(CallingWndScene.GetCtx())
' se la lista non è vuota la leggo e metto le inclinazioni giuste
If m_Mode = ModeOpt.SIDEANGLE Then
If m_SideEntityList.Count > 0 Then
' Aggiorno indici che potrebbero essere cambiati se sono state modificate le misure
RefreshGeomId()
' Aggiorno testi in base alla tabella
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_SideEntityList.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 CallingWindow = CallingWindowOpt.DXFIMPORT Then
' Imposto contesto corrente
EgtSetCurrentContext(CallingWndScene.GetCtx())
' Inizializzo
DeleteSideAngle()
' Inizializzo lati per angoli (ne compilo la lista e aggiungo la scritta nel disegno)
InitSides()
RefreshSideAngleText()
If m_Mode = ModeOpt.SIDEANGLE Then
Dim nSelectedPart As Integer = DxfImportWindowMap.refDxfImportSceneHostV.m_nSelectedPart
If nSelectedPart <> GDB_ID.NULL Then
EgtSelectObj(nSelectedPart)
ReLoadSideAnglePage(SideEntityControlVM.CallingWindowOpt.DXFIMPORT)
End If
End If
End If
' Gestisco visualizzazione dei parametri
If m_Mode = ModeOpt.SIDEANGLE Then
Parameter23_Visibility = Windows.Visibility.Hidden
Else
Parameter23_Visibility = Windows.Visibility.Visible
End If
' Aggiorno valori
If m_Mode = ModeOpt.SIDEANGLE Then
Parameter1Msg = EgtMsg(MSG_IMPORTPAGEUC + 9) ' Angolo
Dim sVal As String = String.Empty
GetMainPrivateProfileString(S_SIDES, K_SIDEANGLE, "45", sVal)
SetParameter1(sVal)
Else
Parameter1Msg = EgtMsg(MSG_IMPORTPAGEUC + 10) ' Offset
m_dDripOffset = GetMainPrivateProfileDouble(S_SIDES, K_DRIPOFFSET, 20)
m_dDripDepth = GetMainPrivateProfileDouble(S_SIDES, K_DRIPDEPTH, 10)
m_dDripShort = GetMainPrivateProfileDouble(S_SIDES, K_DRIPSHORT, 0)
SetParameter1(LenToString(m_dDripOffset, 3))
SetParameter2(LenToString(m_dDripDepth, 3))
SetParameter3(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
#End Region ' CONSTRUCTOR
#Region "METHODS"
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_SideEntityList
Entity.nGeomId = EgtGetFirstNameInGroup(OutLoop, Entity.sEntityName)
Next
End Sub
'Private Sub RefreshCheckAndValue()
' For Each Entity In m_SideEntityList
' ' Creo testo con angolo di inclinazione
' If DirectCast(Entity, SideAngleEntity).dSideAngle <> 0 Then
' End If
' 'AddTextToLine(Entity.sEntityName & " = " & DoubleToString(Entity.dSideAngle, 1) & "°", Entity.nTextId, Entity.nGeomId, 10, dBBoxRad, True)
' Next
'End Sub
Private Sub RefreshSideAngleText()
' Imposto contesto corrente e ricavo Id pezzo
Dim Part1 As Integer = GDB_ID.NULL
EgtSetCurrentContext(m_CallingWndScene.GetCtx())
If m_CallingWindow = CallingWindowOpt.COMPO Then
Part1 = EgtGetFirstInGroup(GDB_ID.ROOT)
ElseIf m_CallingWindow = CallingWindowOpt.DXFIMPORT Then
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)
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_SideEntityList
Dim sText As String = Entity.sEntityName & " = " & DoubleToString(DirectCast(Entity, SideAngleEntity).dSideAngle, 1) & "°"
AddTextToLine(sText, Entity.nTextId, Entity.nGeomId, 10, dBBoxRad, True)
Next
' Altrimenti modalità gocciolatoio
Else
' Per ogni entità creo testo con nome
For Each Entity In m_SideEntityList
AddTextToLine(Entity.sEntityName, Entity.nTextId, Entity.nGeomId, 10, 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
' Imposto contesto corrente
EgtSetCurrentContext(m_CallingWndScene.GetCtx())
If m_CallingWindow = CallingWindowOpt.COMPO Then
' Ricavo nome primo pezzo
Part1 = EgtGetFirstInGroup(GDB_ID.ROOT)
ElseIf m_CallingWindow = CallingWindowOpt.DXFIMPORT Then
' 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)
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_CallingWindow = CallingWindowOpt.DXFIMPORT Then
If m_Mode = ModeOpt.SIDEANGLE Then
For Each Entity In m_SideEntityList
If DirectCast(Entity, SideAngleEntity).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_SideEntityList
If DirectCast(Entity, DripEntity).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_SideEntityList.Count - nIndex)).IsChecked = True
'Else
' GetChBxFromIndex(10 - (m_SideEntityList.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_CallingWindow = CallingWindowOpt.DXFIMPORT 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_CallingWindow = CallingWindowOpt.COMPO Then
m_SideEntityList.Add(New SideAngleEntity(CurrLine, sEntityName, TextLayer, 0, m_Mode))
' Cancello inclinazione nell'apposito campo info
EgtRemoveInfo(CurrLine, INFO_SIDE_ANGLE)
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName & " = 0°", TextLayer, CurrLine, 10, dBBoxRad, True)
Else
m_SideEntityList.Add(New SideAngleEntity(CurrLine, sEntityName, TextLayer, dSideAngleVal, m_Mode))
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName & " = " & DoubleToString(dSideAngleVal, 1) & "°", TextLayer, CurrLine, 10, 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_CallingWindow = CallingWindowOpt.DXFIMPORT 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_CallingWindow = CallingWindowOpt.COMPO Then
m_SideEntityList.Add(New DripEntity(CurrLine, sEntityName, TextLayer, False, m_Mode))
' Cancello gocciolatoio nell'apposito campo info
EgtRemoveInfo(CurrLine, INFO_HAVE_DRIP)
' Creo testo entità
AddTextToLine(sEntityName, TextLayer, CurrLine, 10, dBBoxRad, True)
Else
m_SideEntityList.Add(New DripEntity(CurrLine, sEntityName, TextLayer, bHaveDripVal, m_Mode))
' Creo testo con angolo di inclinazione 0
AddTextToLine(sEntityName, TextLayer, CurrLine, 10, dBBoxRad, True)
End If
End Sub
' Funzione che dato un segmento e una distanza, scrive il testo centrato alla sua destra
Friend Shared Sub AddTextToLine(sText As String, TextLayer As Integer, CurrLine As Integer, dDistance As Double, dBBoxRad As Double, bTextExt As Boolean)
' Calcolo altezza testo
Dim dH As Double = 0.075 * dBBoxRad
' Creo testo
Dim nText As Integer = EgtCreateTextAdv(TextLayer, New Point3d(0, 0, 0), 0, sText, "", 500, False, dH, 1, 0, INS_POS.MC)
' Calcolo punto in cui posizionare il testo
' calcolo BBox del testo
Dim ptMinBBox As Point3d
Dim ptMaxBBox As Point3d
EgtGetBBox(nText, GDB_BB.STANDARD, ptMinBBox, ptMaxBBox)
' calcolo centro del BBox
Dim ptMidBBox As Point3d
ptMidBBox = Point3d.Media(ptMinBBox, ptMaxBBox)
' calcolo vettore della CurrLine
Dim ptLineStart As Point3d
EgtStartPoint(CurrLine, nText, ptLineStart)
Dim ptLineEnd As Point3d
EgtEndPoint(CurrLine, nText, ptLineEnd)
Dim vtCurrLine As Vector3d = ptLineEnd - ptLineStart
' lo normalizzo per ottenerne il versore
vtCurrLine.Normalize()
' calcolo vettore dal centro del BBox all'estremo più vicino se testo esterno alla figura
Dim vtptExtptMC As Vector3d
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
' ruoto il vettore della CurrLine per ottenerne il perpendicolare
If bTextExt Then
vtCurrLine.Rotate(Vector3d.Z_AX, -90)
Else
vtCurrLine.Rotate(Vector3d.Z_AX, 90)
End If
' Calcolo il centro del testo
Dim ptTextMC As Point3d = Point3d.Media(ptLineStart, ptLineEnd) + vtCurrLine * (dDistance + (vtCurrLine * vtptExtptMC))
EgtMove(nText, (ptTextMC - Point3d.ORIG))
End Sub
' 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_SideEntityList
If DirectCast(Entity, DripEntity).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, 0, 255))
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
' 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, m_SideEntityList)
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'inclinazione 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, m_SideEntityList)
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()
'Else
' m_DripEntityList.Clear()
'End If
'' 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 Sub
Friend Sub ReLoadSideAnglePage(CallingWindow As CallingWindowOpt)
' Ricavo nome pezzo precedentemente selezionato
Dim Part1 As Integer = DxfImportWindowMap.refDxfImportSceneHostV.m_PrevSelPart
EgtErase(EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER))
m_SideEntityList.Clear()
If CallingWindow = CallingWindowOpt.COMPO Then
' Imposto contesto corrente
EgtSetCurrentContext(m_CallingWndScene.GetCtx())
' se la lista non è vuota la leggo e metto le inclinazioni giuste
If m_Mode = ModeOpt.SIDEANGLE Then
If m_SideEntityList.Count > 0 Then
' Aggiorno indici che potrebbero essere cambiati se sono state modificate le misure
RefreshGeomId()
' Aggiorno testi in base alla tabella
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_SideEntityList.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 CallingWindow = CallingWindowOpt.DXFIMPORT Then
' Imposto contesto corrente
EgtSetCurrentContext(m_CallingWndScene.GetCtx())
' Inizializzo
DeleteSideAngle()
' Inizializzo lati per angoli (ne compilo la lista e aggiungo la scritta nel disegno)
InitSides()
RefreshSideAngleText()
End If
' Gestisco visualizzazione dei parametri
If m_Mode = ModeOpt.SIDEANGLE Then
Parameter23_Visibility = Windows.Visibility.Hidden
Else
Parameter23_Visibility = Windows.Visibility.Visible
End If
' Aggiorno valori
If m_Mode = ModeOpt.SIDEANGLE Then
Parameter1Msg = EgtMsg(MSG_IMPORTPAGEUC + 9) ' Angolo
Dim sVal As String = String.Empty
GetMainPrivateProfileString(S_SIDES, K_SIDEANGLE, "45", sVal)
SetParameter1(sVal)
Else
Parameter1Msg = EgtMsg(MSG_IMPORTPAGEUC + 10) ' Offset
m_dDripOffset = GetMainPrivateProfileDouble(S_SIDES, K_DRIPOFFSET, 20)
m_dDripDepth = GetMainPrivateProfileDouble(S_SIDES, K_DRIPDEPTH, 10)
m_dDripShort = GetMainPrivateProfileDouble(S_SIDES, K_DRIPSHORT, 0)
SetParameter1(LenToString(m_dDripOffset, 3))
SetParameter2(LenToString(m_dDripDepth, 3))
SetParameter3(LenToString(m_dDripShort, 3))
End If
End Sub
Friend Sub Close()
If m_CallingWindow = CallingWindowOpt.COMPO 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))
End If
ElseIf m_CallingWindow = CallingWindowOpt.DXFIMPORT Then
' Ricavo nome pezzo precedentemente selezionato
Dim Part1 As Integer = DxfImportWindowMap.refDxfImportSceneHostV.m_nSelectedPart
EgtErase(EgtGetFirstNameInGroup(Part1, SIDE_ANGLE_LAYER))
EgtDeselectAll()
End If
If m_Mode = ModeOpt.SIDEANGLE Then
WriteMainPrivateProfileString(S_SIDES, K_SIDEANGLE, m_Parameter1)
Else
WriteMainPrivateProfileString(S_SIDES, K_DRIPOFFSET, DoubleToString(m_dDripOffset, 3))
WriteMainPrivateProfileString(S_SIDES, K_DRIPDEPTH, DoubleToString(m_dDripDepth, 3))
WriteMainPrivateProfileString(S_SIDES, K_DRIPSHORT, DoubleToString(m_dDripShort, 3))
End If
EgtDraw()
End Sub
#End Region ' METHODS
End Class
Public MustInherit Class SideEntity
Inherits VMBase
Private m_nGeomId As Integer
Public Property nGeomId As Integer
Get
Return m_nGeomId
End Get
Set(value As Integer)
m_nGeomId = value
End Set
End Property
Private m_sEntityName As String
Public ReadOnly Property sEntityName As String
Get
Return m_sEntityName
End Get
End Property
Private m_nTextId As Integer
Public ReadOnly Property nTextId As Integer
Get
Return m_nTextId
End Get
End Property
Private m_Mode As SideEntityControlVM.ModeOpt
Public ReadOnly Property Value_Visibility As Visibility
Get
If m_Mode = SideEntityControlVM.ModeOpt.SIDEANGLE Then
If SideEntityControlVM.m_SideAngleCheck Then
Return Visibility.Collapsed
Else
Return Visibility.Visible
End If
Else
Return Visibility.Visible
End If
End Get
End Property
'Private m_Check_Visibility As Visibility
Public ReadOnly Property Check_Visibility As Visibility
Get
If m_Mode = SideEntityControlVM.ModeOpt.SIDEANGLE Then
If SideEntityControlVM.m_SideAngleCheck Then
Return Visibility.Visible
Else
Return Visibility.Collapsed
End If
Else
Return Visibility.Visible
End If
End Get
End Property
Public MustOverride Property bIsChecked As Boolean
Sub New(nId As Integer, sEntityName As String, nTextId As Integer, Mode As SideEntityControlVM.ModeOpt)
m_nGeomId = nId
m_sEntityName = sEntityName
m_nTextId = nTextId
m_Mode = Mode
End Sub
End Class
Friend Class SideAngleEntity
Inherits SideEntity
Friend Shared m_Parameter1 As Double
Friend Shared m_ModifySideAngle As Action(Of String, Double)
Friend Shared m_RefreshSideAngleText As Action
Private m_dSideAngle As Double
Public Property GrphSideAngle As String
Get
Return DoubleToString(m_dSideAngle, 2)
End Get
Set(value As String)
If value <> m_dSideAngle Then
If Not String.IsNullOrWhiteSpace(value) Then
StringToDouble(value, m_dSideAngle)
Else
' altrimenti lo imposto a zero
m_dSideAngle = 0
End If
' Lo modifico nella geometria e nella lista inclinazioni
m_ModifySideAngle(sEntityName, dSideAngle)
' Aggiorno tutti i testi
m_RefreshSideAngleText()
End If
End Set
End Property
Public Property dSideAngle As Double
Get
Return m_dSideAngle
End Get
Set(value As Double)
m_dSideAngle = value
End Set
End Property
Public Overrides Property bIsChecked As Boolean
Get
Return Not m_dSideAngle = 0
End Get
Set(value As Boolean)
If value Then
m_dSideAngle = m_Parameter1
Else
m_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 = "A" & nCurrSide.ToString()
' Lo modifico nella geometria e nella lista inclinazioni
m_ModifySideAngle(sEntityName, m_dSideAngle)
' Aggiorno tutti i testi
m_RefreshSideAngleText()
NotifyPropertyChanged("bIsChecked")
End Set
End Property
Sub New(nId As Integer, sEntityName As String, nTextId As Integer, dSideAngle As Double, Mode As SideEntityControlVM.ModeOpt)
MyBase.New(nId, sEntityName, nTextId, Mode)
m_dSideAngle = dSideAngle
End Sub
Friend Shared Function FindEntity(sEntityName As String, EntityList As ObservableCollection(Of SideEntity)) As SideAngleEntity
If IsNothing(EntityList) Then
Return Nothing
End If
For Each Entity In EntityList
If Entity.sEntityName = sEntityName Then
Return Entity
End If
Next
Return Nothing
End Function
End Class
Friend Class DripEntity
Inherits SideEntity
Private m_bHaveDrip As Boolean
Public Property bHaveDrip As Boolean
Get
Return m_bHaveDrip
End Get
Set(value As Boolean)
m_bHaveDrip = value
End Set
End Property
Public Overrides Property bIsChecked As Boolean
Get
Return m_bHaveDrip
End Get
Set(value As Boolean)
m_bHaveDrip = value
NotifyPropertyChanged("bIsChecked")
End Set
End Property
Sub New(nId As Integer, sEntityName As String, nTextId As Integer, bHaveDrip As Boolean, Mode As SideEntityControlVM.ModeOpt)
MyBase.New(nId, sEntityName, nTextId, Mode)
m_bHaveDrip = bHaveDrip
End Sub
Friend Shared Function FindEntity(sEntityName As String, EntityList As ObservableCollection(Of SideEntity)) As DripEntity
If IsNothing(EntityList) Then
Return Nothing
End If
For Each Entity In EntityList
If Entity.sEntityName = sEntityName Then
Return Entity
End If
Next
Return Nothing
End Function
End Class