Imports EgtUILib Imports EgtWPFLib5 Public Class FreeContourManagerVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Enum FreeContourTypes As Integer ONE = 0 ONEWITHANGLES = 1 TWO = 2 End Enum Private m_bIsActive As Boolean = False Public ReadOnly Property bIsActive As Boolean Get Return m_bIsActive End Get End Property Private m_nSelTextId As Integer = GDB_ID.NULL ' parametro che indica se e' in corso l'editing di un angolo Private m_bIsModifyingTextAngle As Boolean = False Public ReadOnly Property bIsModifyingTextAngle As Boolean Get Return m_bIsModifyingTextAngle End Get End Property Private m_TypeList As New List(Of String)({"Un percorso", "Un percorso con angoli", "Due percorsi"}) Public Property TypeList As List(Of String) Get Return m_TypeList End Get Set(value As List(Of String)) m_TypeList = value End Set End Property Private m_SelType As Integer Public Property SelType As Integer Get Return m_SelType End Get Set(value As Integer) ' se precedentemente impostato 2 percorsi Select Case m_SelType Case FreeContourTypes.ONEWITHANGLES ' elimino layer testi angoli EgtErase(nSideAngTextLayer) nSideAngTextLayer = GDB_ID.NULL m_TextAngle_Visibility = Visibility.Collapsed NotifyPropertyChanged(NameOf(TextAngle_Visibility)) Case FreeContourTypes.TWO ' chiedo conferma If MessageBox.Show(EgtMsg(61862), "", MessageBoxButton.YesNo, MessageBoxImage.Warning) <> MessageBoxResult.Yes Then m_SelType = FreeContourTypes.TWO NotifyPropertyChanged(NameOf(SelType)) Return Else ' elimino secondo percorso EgtErase(nNewSecondPathId) End If End Select m_SelType = value ' se nuova impostazione e' uno con angoli If m_SelType = FreeContourTypes.ONEWITHANGLES Then ' creo testi angoli sul percorso CreateSideAngText("") m_TextAngle_Visibility = Visibility.Visible End If NotifyPropertyChanged(NameOf(TextAngle_Visibility)) EgtDraw() End Set End Property Private m_Line2P_IsEnabled As Boolean Public Property Line2P_IsEnabled As Boolean Get Return m_Line2P_IsEnabled End Get Set(value As Boolean) m_Line2P_IsEnabled = value End Set End Property Private m_TextAngle_Visibility As Visibility Public Property TextAngle_Visibility As Visibility Get Return m_TextAngle_Visibility End Get Set(value As Visibility) m_TextAngle_Visibility = value End Set End Property Dim SelPart As BTLPartVM Dim SelFeature As BTLFeatureVM Dim nSelPartId As Integer Dim nSelFeatureId As Integer Dim nProcessingLayerId As Integer Dim nAuxId As Integer = 0 Dim nSecondAuxId As Integer = 0 Dim nOrigPathId As Integer = GDB_ID.NULL Dim nNewPathId As Integer = GDB_ID.NULL Dim nOrigSecondPathId As Integer = GDB_ID.NULL Dim nNewSecondPathId As Integer = GDB_ID.NULL Dim nSideAngTextLayer As Integer = GDB_ID.NULL ' Definizione comandi Private m_cmdLine2P As ICommand Private m_cmdModifyCurve As ICommand Private m_cmdAddPointCurve As ICommand Private m_cmdArcflip As ICommand Private m_cmdMove As ICommand Private m_cmdRotate As ICommand Private m_cmdMirror As ICommand Private m_cmdScale As ICommand Private m_cmdRemovePointCurve As ICommand Private m_cmdTextAngle As ICommand #End Region ' FIELDS & PROPERTIES #Region "CONSTRUCTORS" Sub New() ' imposto riferimento in Map Map.SetRefFreeContourManagerVM(Me) End Sub #End Region ' CONSTRUCTORS #Region "METHODS" Friend Sub Open() m_bIsActive = True ' imposto Part/Feature/Layer Processing ... SelPart = Map.refProjectVM.BTLStructureVM.SelBTLPart SelFeature = Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM nSelPartId = Map.refProjectVM.BTLStructureVM.SelBTLPart.nPartId nSelFeatureId = Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM.nFeatureId nProcessingLayerId = EgtGetFirstNameInGroup(nSelPartId, PROCESSINGS) Dim sAuxId As String = "" If EgtGetInfo(nSelFeatureId, "AUXID", sAuxId) Then ' verifico se ha uno o due percorsi Dim sAuxIdSplit() As String = sAuxId.Split(","c) If Integer.TryParse(sAuxIdSplit(0), nAuxId) Then nOrigPathId = nSelFeatureId + nAuxId ' faccio copia del percorso feature nNewPathId = EgtCopyGlob(nOrigPathId, nSelFeatureId, GDB_POS.AFTER) ' imposto modalita' un percorso m_SelType = FreeContourTypes.ONE End If If sAuxIdSplit.Count > 1 AndAlso Not String.IsNullOrWhiteSpace(sAuxIdSplit(1)) Then If Integer.TryParse(sAuxIdSplit(1), nSecondAuxId) Then nOrigSecondPathId = nSelFeatureId + nSecondAuxId ' faccio copia del percorso feature nNewSecondPathId = EgtCopyGlob(nOrigSecondPathId, nSelFeatureId, GDB_POS.AFTER) ' imposto modalita' due percorsi m_SelType = FreeContourTypes.TWO End If Else Dim sSideAng As String = "" ' verifico se c'e' info angoli If EgtGetInfo(nOrigPathId, "SideAng", sSideAng) Then ' creo testi angoli sul percorso CreateSideAngText(sSideAng) ' imposto modalita' con angoli m_SelType = FreeContourTypes.ONEWITHANGLES End If End If End If ' imposto filtro selezione solo su curve Map.refSceneHostVM.MainScene.SetObjFilterForSel(False, True, False, False, False) ' imposto layer corrente per disegno EgtSetCurrPartLayer(nSelPartId, nProcessingLayerId) ' nascondo tutte le feature Dim nTempFeatureId As Integer = EgtGetFirstInGroup(nProcessingLayerId) While nTempFeatureId <> GDB_ID.NULL EgtSetMode(nTempFeatureId, GDB_MD.HIDDEN) nTempFeatureId = EgtGetNext(nTempFeatureId) End While ' nascondo tutti gli outline Dim nOutlineLayerId As Integer = EgtGetFirstNameInGroup(nSelPartId, OUTLINE) Dim nTempOutlineId As Integer = EgtGetFirstInGroup(nOutlineLayerId) While nTempOutlineId <> GDB_ID.NULL EgtSetMode(nTempOutlineId, GDB_MD.HIDDEN) nTempOutlineId = EgtGetNext(nTempOutlineId) End While ' deseleziono tutto EgtDeselectAll() ' rendo visibile e seleziono solo percorso feature EgtSetMode(nNewPathId, GDB_MD.STD) EgtSelectObj(nNewPathId) ' verifico se modalita' uno o due percorsi Select Case m_SelType Case FreeContourTypes.ONE ' se c'e' gia' un percorso disattivo la possibilita' di aggiungerne m_Line2P_IsEnabled = (nNewPathId = GDB_ID.NULL) m_TextAngle_Visibility = False Case FreeContourTypes.ONEWITHANGLES ' se c'e' gia' un percorso disattivo la possibilita' di aggiungerne m_Line2P_IsEnabled = (nNewPathId = GDB_ID.NULL) m_TextAngle_Visibility = True Case FreeContourTypes.TWO ' se ci sono gia' due percorsi ' disattivo la possibilita' di aggiungerne m_Line2P_IsEnabled = (nNewPathId = GDB_ID.NULL OrElse nNewSecondPathId = GDB_ID.NULL) m_TextAngle_Visibility = False End Select NotifyPropertyChanged(NameOf(Line2P_IsEnabled)) NotifyPropertyChanged(NameOf(TextAngle_Visibility)) ' posiziono la griglia sulla faccia attiva ''EgtSetGridFrame() EgtSetGridShow(True, True) ' attivo modifiche su scena Map.refSceneHostVM.MainScene.ResetStatus() ' attivo bottoni save e cancel SelFeature.RefreshFCMBtnVisibility() ' nascondo Part Manager Map.refProjectVM.SetPartManager_Visibility(False) Map.refProjectVM.NotifyPropertyChanged(NameOf(Map.refProjectVM.PartManager_Visibility)) ' attivo pannello Map.refProjectVM.SetFreeContourManager_Visibility(True) EgtDraw() End Sub Friend Sub Close(bSave As Boolean) If m_bIsActive Then m_bIsActive = False Else Return End If ' gestisco salvataggio If bSave Then ' cancello vecchio percorso EgtErase(nOrigPathId) ' ricalcolo auxid EgtSetInfo(nSelFeatureId, "AUXID", (nNewPathId - nSelFeatureId).ToString("+#;-#;0")) Else ' elimino nuovo percorso EgtErase(nNewPathId) End If ' mostro tutte le altre feature Dim nTempFeatureId As Integer = EgtGetFirstInGroup(nProcessingLayerId) While nTempFeatureId <> GDB_ID.NULL If nTempFeatureId <> nSelFeatureId Then EgtSetMode(nTempFeatureId, GDB_MD.STD) End If nTempFeatureId = EgtGetNext(nTempFeatureId) End While ' mostro outline Dim nOutlineLayerId As Integer = EgtGetFirstNameInGroup(nSelPartId, OUTLINE) Dim nTempOutlineId As Integer = EgtGetFirstInGroup(nOutlineLayerId) While nTempOutlineId <> GDB_ID.NULL EgtSetMode(nTempOutlineId, GDB_MD.STD) nTempOutlineId = EgtGetNext(nTempOutlineId) End While ' elimino eventuale layer dei testi angoli EgtErase(nSideAngTextLayer) ' nascondo la griglia EgtSetGridShow(False, False) ' disattivo pannello Map.refProjectVM.SetFreeContourManager_Visibility(False) ' imposto filtro selezione solo su curve Map.refSceneHostVM.MainScene.SetObjFilterForSel(False, True, False, False, False) ' attivo bottone edit SelFeature.RefreshFCMBtnVisibility() ' resetto tutte le variabili correnti SelPart = Nothing SelFeature = Nothing nSelPartId = GDB_ID.NULL nSelFeatureId = GDB_ID.NULL nProcessingLayerId = GDB_ID.NULL ' riattivo Part Manager Map.refProjectVM.SetPartManager_Visibility(True) Map.refProjectVM.NotifyPropertyChanged(NameOf(Map.refProjectVM.PartManager_Visibility)) ' disattivo modifiche su scena Map.refSceneHostVM.MainScene.SetStatusNull() End Sub Private Sub CreateSideAngText(SideAng As String) ' creo testi angoli sul percorso If nSideAngTextLayer = GDB_ID.NULL Then nSideAngTextLayer = EgtCreateGroup(nSelPartId) End If Dim sSideAngSplit() As String = SideAng.Split(","c) Dim nSideFirst As Integer Dim nSideLast As Integer EgtCurveDomain(nOrigPathId, nSideFirst, nSideLast) Dim nSideCnt As Integer = nSideLast - nSideFirst For Index = 0 To nSideCnt ' riporto angoli nel disegno Dim ptText As Point3d EgtAtParamPoint(nOrigPathId, Index + 0.5, ptText) Dim nSideAng As Double = 0 If sSideAngSplit.Count - 1 >= Index Then StringToDouble(sSideAngSplit(Index), nSideAng) End If EgtCreateText(nSideAngTextLayer, ptText, nSideAng & "°", 20) Next End Sub Friend Sub CloseIsModifyingTextAngle(bResult As Boolean) If bResult Then ' scrivo info con nuova inclinazione Dim dAng As Double StringToDouble(Map.refFreeContourInputVM.Text, dAng) EgtSetInfo(m_nSelTextId, "SideAng", dAng) EgtModifyText(m_nSelTextId, dAng & "°") End If m_nSelTextId = GDB_ID.NULL Map.refSceneHostVM.MainScene.SetObjFilterForSel(False, True, False, False, False) Map.refFreeContourInputVM.ResetInputBox() m_bIsModifyingTextAngle = False End Sub Friend Sub TextAngleSelected(nId As Integer) m_nSelTextId = nId ' mostro campo da editare Map.refFreeContourInputVM.PrepareInputBox("Inclinazione lato", "Indicare inclinazione lato selezionato", "", False, False) Dim dSideAng As Double = 0 EgtGetInfo(nId, "SideAng", dSideAng) Map.refFreeContourInputVM.SetInputBoxText(dSideAng) End Sub #End Region ' METHODS #Region "COMMANDS" #Region "Line2PCommand" ''' ''' Returns a command that do Line2P. ''' Public ReadOnly Property Line2PCommand As ICommand Get If m_cmdLine2P Is Nothing Then m_cmdLine2P = New Command(AddressOf Line2P) End If Return m_cmdLine2P End Get End Property ''' ''' Execute the Line2P. This method is invoked by the Line2PCommand. ''' Public Sub Line2P(ByVal param As Object) If (Keyboard.Modifiers And ModifierKeys.Control) = ModifierKeys.Control Then Map.refSceneHostVM.MainController.SetContinue() End If Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.LINE2P) End Sub #End Region ' Line2PCommand #Region "ModifyCurve" ''' ''' Returns a command that do Linear Dimension. ''' Public ReadOnly Property ModifyCurveCommand As ICommand Get If m_cmdModifyCurve Is Nothing Then m_cmdModifyCurve = New Command(AddressOf ModifyCurve) End If Return m_cmdModifyCurve End Get End Property ''' ''' Execute the LinearDimension. This method is invoked by the LinDimCommand. ''' Public Sub ModifyCurve(ByVal param As Object) Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.MODIFYCURVE) End Sub #End Region ' ModifyCurve #Region "AddPointCurve" ''' ''' Returns a command that do Linear Dimension. ''' Public ReadOnly Property AddPointCurveCommand As ICommand Get If m_cmdAddPointCurve Is Nothing Then m_cmdAddPointCurve = New Command(AddressOf AddPointCurve) End If Return m_cmdAddPointCurve End Get End Property ''' ''' Execute the LinearDimension. This method is invoked by the LinDimCommand. ''' Public Sub AddPointCurve(ByVal param As Object) If (Keyboard.Modifiers And ModifierKeys.Control) = ModifierKeys.Control Then Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.CLOSECOMPO) ElseIf (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.CURVETOARC) Else Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.ADDPOINTCURVE) End If End Sub #End Region ' AddPointCurve #Region "RemovePointCurve" ''' ''' Returns a command that do Linear Dimension. ''' Public ReadOnly Property RemovePointCurveCommand As ICommand Get If m_cmdRemovePointCurve Is Nothing Then m_cmdRemovePointCurve = New Command(AddressOf RemovePointCurve) End If Return m_cmdRemovePointCurve End Get End Property ''' ''' Execute the LinearDimension. This method is invoked by the LinDimCommand. ''' Public Sub RemovePointCurve(ByVal param As Object) If (Keyboard.Modifiers And ModifierKeys.Control) = ModifierKeys.Control Then Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.OPENCOMPO) ElseIf (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.CURVETOLINE) Else Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.REMOVEPOINTCURVE) End If End Sub #End Region ' RemovePointCurve #Region "ArcFlipCommand" ''' ''' Returns a command that do Arc Flip. ''' Public ReadOnly Property ArcFlipCommand As ICommand Get If m_cmdArcflip Is Nothing Then m_cmdArcflip = New Command(AddressOf ArcFlip) End If Return m_cmdArcflip End Get End Property ''' ''' Execute the ArcFlip. This method is invoked by the ArcFlipCommand. ''' Public Sub ArcFlip(ByVal param As Object) If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.ARCEXPLEMENTARY) Else Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.ARCFLIP) End If End Sub #End Region ' ArcFlipCommand #Region "MoveCommand" ''' ''' Returns a command that do Move. ''' Public ReadOnly Property MoveCommand As ICommand Get If m_cmdMove Is Nothing Then m_cmdMove = New Command(AddressOf Move) End If Return m_cmdMove End Get End Property ''' ''' Execute the Move. This method is invoked by the MoveCommand. ''' Public Sub Move(ByVal param As Object) Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.MOVE) End Sub #End Region ' MoveCommand #Region "RotateCommand" ''' ''' Returns a command that do Rotate. ''' Public ReadOnly Property RotateCommand As ICommand Get If m_cmdRotate Is Nothing Then m_cmdRotate = New Command(AddressOf Rotate) End If Return m_cmdRotate End Get End Property ''' ''' Execute the Rotate. This method is invoked by the RotateCommand. ''' Public Sub Rotate(ByVal param As Object) Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.ROTATE) End Sub #End Region ' RotateCommand #Region "MirrorCommand" ''' ''' Returns a command that do Mirror. ''' Public ReadOnly Property MirrorCommand As ICommand Get If m_cmdMirror Is Nothing Then m_cmdMirror = New Command(AddressOf Mirror) End If Return m_cmdMirror End Get End Property ''' ''' Execute the Mirror. This method is invoked by the MirrorCommand. ''' Public Sub Mirror(ByVal param As Object) Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.MIRROR) End Sub #End Region ' MirrorCommand #Region "ScaleCommand" ''' ''' Returns a command that do Scale. ''' Public ReadOnly Property ScaleCommand As ICommand Get If m_cmdScale Is Nothing Then m_cmdScale = New Command(AddressOf Scale) End If Return m_cmdScale End Get End Property ''' ''' Execute the Scale. This method is invoked by the ScaleCommand. ''' Public Sub Scale(ByVal param As Object) Map.refSceneHostVM.MainController.ExecuteCommand(Controller.CMD.SCALE) End Sub #End Region ' ScaleCommand #Region "TextAngle" ''' ''' Returns a command that do Scale. ''' Public ReadOnly Property TextAngle_Command As ICommand Get If m_cmdTextAngle Is Nothing Then m_cmdTextAngle = New Command(AddressOf TextAngle) End If Return m_cmdTextAngle End Get End Property ''' ''' Execute the Scale. This method is invoked by the ScaleCommand. ''' Public Sub TextAngle(ByVal param As Object) ' imposto slezione solo testi Map.refSceneHostVM.MainScene.SetObjFilterForSel(False, False, False, False, True) m_bIsModifyingTextAngle = True End Sub #End Region ' ScaleCommand #End Region ' COMMANDS End Class