Imports EgtUILib Public Class DispositionParameterExpanderVM Inherits ViewModelBase Public Enum ObjectType As Integer RAWPART = 1 PART = 2 FIXTURE = 3 End Enum Private m_ActiveObject As ObjectType Public Property ActiveObject As ObjectType Get Return m_ActiveObject End Get Set(value As ObjectType) If value <> m_ActiveObject Then Select Case value Case ObjectType.RAWPART RawPartIsExpanded = True Case ObjectType.PART PartIsExpanded = True Case ObjectType.FIXTURE FixtureIsExpanded = True End Select m_ActiveObject = value End If m_ActiveObject = value End Set End Property Friend m_Id As Integer Public ReadOnly Property Id As Integer Get Return m_Id End Get End Property Private m_Name As String Public Property Name As String Get Return m_Name End Get Set(value As String) m_Name = value End Set End Property Private m_RawPartIsExpanded As Boolean Public Property RawPartIsExpanded As Boolean Get Return m_RawPartIsExpanded End Get Set(value As Boolean) If value <> m_RawPartIsExpanded Then If value Then ' Chiudo Part e Fixture PartIsExpanded = False FixtureIsExpanded = False ' verifico se è attiva l'opzione muovi con ventose If Map.refRawPartOptionVM.MoveWithFixture() Then ' Abilito la selezione dei RawPart con ventose Map.refProjectVM.SceneSelType = SceneSelTypeOpt.RAWPARTWITHFIXTURE Else ' Abilito la selezione dei RawPart Map.refProjectVM.SceneSelType = SceneSelTypeOpt.RAWPART End If If m_MoveIsChecked Then m_RawRefGroupVisibility = Visibility.Visible OnPropertyChanged("RawRefGroupVisibility") End If Else ' Nascondo i bottoni per impostare la posizione di riferimento del grezzo m_RawRefGroupVisibility = Visibility.Collapsed OnPropertyChanged("RawRefGroupVisibility") ' smarco la prima entità selezionata EgtResetMark(EgtGetFirstSelectedObj) EgtDeselectAll() EgtDraw() End If m_RawPartIsExpanded = value ActiveObject = ObjectType.RAWPART OnPropertyChanged("RawPartIsExpanded") End If End Set End Property Private m_PartIsExpanded As Boolean Public Property PartIsExpanded As Boolean Get Return m_PartIsExpanded End Get Set(value As Boolean) If value <> m_PartIsExpanded Then If value Then ' Chiudo RawPart e Fixture RawPartIsExpanded = False FixtureIsExpanded = False Else ' smarco la prima entità selezionata EgtResetMark(EgtGetFirstSelectedObj) EgtDeselectAll() EgtDraw() End If m_PartIsExpanded = value ActiveObject = ObjectType.PART OnPropertyChanged("PartIsExpanded") End If End Set End Property Private m_FixtureIsExpanded As Boolean Public Property FixtureIsExpanded As Boolean Get Return m_FixtureIsExpanded End Get Set(value As Boolean) If value <> m_FixtureIsExpanded Then If value Then ' Chiudo RawPart e Part RawPartIsExpanded = False PartIsExpanded = False ' Abilito la selezione delle Fixture Map.refProjectVM.SceneSelType = SceneSelTypeOpt.FIXTURE m_ExpandFixtureFunction() Else ' smarco la prima entità selezionata EgtResetMark(EgtGetFirstSelectedObj) ' deseleziono tutto ed aggiorno la visualizzazione EgtDeselectAll() EgtDraw() End If m_FixtureIsExpanded = value ActiveObject = ObjectType.FIXTURE OnPropertyChanged("FixtureIsExpanded") End If End Set End Property Private m_MoveIsChecked As Boolean Public Property MoveIsChecked As Boolean Get Return m_MoveIsChecked End Get Set(value As Boolean) If value <> m_MoveIsChecked Then Map.refProjectVM.SetMoveInDisposition(value) InputValue = String.Empty OnPropertyChanged("InputValue") If value Then If m_RawPartIsExpanded Then m_RawRefGroupVisibility = Visibility.Visible OnPropertyChanged("RawRefGroupVisibility") Else m_RawRefGroupVisibility = Visibility.Collapsed OnPropertyChanged("RawRefGroupVisibility") End If m_InputMsg = "Move to:" Else m_RawRefGroupVisibility = Visibility.Collapsed OnPropertyChanged("RawRefGroupVisibility") m_InputMsg = "Rotate of:" End If OnPropertyChanged("InputMsg") m_MoveIsChecked = value End If End Set End Property Private m_InputValue As String Public Property InputValue As String Get Return m_InputValue End Get Set(value As String) If Not String.IsNullOrEmpty(m_InputErrorMsg) Then m_InputErrorMsg = String.Empty OnPropertyChanged("InputErrorMsg") End If m_InputValue = value End Set End Property Private m_BLIsChecked As Boolean = True Public ReadOnly Property BLIsChecked As Boolean Get Return m_BLIsChecked End Get End Property Private m_RawRefPosition As MCH_CR = MCH_CR.BL Private m_RawRefGroupVisibility As Visibility Public ReadOnly Property RawRefGroupVisibility As Visibility Get Return m_RawRefGroupVisibility End Get End Property ' Actions Private m_ExpandFixtureFunction As Action Private m_FixtureParameters As FixtureParametersV Public ReadOnly Property FixtureParameters As ContentControl Get If IsNothing(m_FixtureParameters) Then m_FixtureParameters = New FixtureParametersV m_FixtureParameters.DataContext = New FixtureParametersVM(m_ExpandFixtureFunction) End If Return m_FixtureParameters End Get End Property Private m_RawPartOptions As RawPartOptionV Public ReadOnly Property RawPartOptions As ContentControl Get If IsNothing(m_RawPartOptions) Then m_RawPartOptions = New RawPartOptionV m_RawPartOptions.DataContext = New RawPartOptionVM End If Return m_RawPartOptions End Get End Property #Region "Messages" Private m_InputMsg As String Public ReadOnly Property InputMsg As String Get Return m_InputMsg End Get End Property Private m_InputErrorMsg As String Public ReadOnly Property InputErrorMsg As String Get Return m_InputErrorMsg End Get End Property Public ReadOnly Property OkMsg As String Get Return EgtMsg(MSG_DISPOSITION + 1) End Get End Property #End Region ' Messages ' Definizione comandi Private m_cmdDone As ICommand Private m_cmdCheckedRawRef As ICommand #Region "CONSTRUCTOR" Sub New(ByRef OpenDispositionFunction As Action(Of Boolean)) OpenDispositionFunction = AddressOf OpenDispositionParameters MoveIsChecked = True m_BLIsChecked = True OnPropertyChanged("BLIsChecked") m_RawRefPosition = MCH_CR.BL End Sub #End Region #Region "METHODS" Public Sub OpenDispositionParameters(bFirst As Boolean) If bFirst Then ActiveObject = ObjectType.RAWPART Else ActiveObject = ObjectType.FIXTURE End If Select Case m_ActiveObject Case ObjectType.RAWPART ' Abilito la selezione delle Fixture Map.refProjectVM.SceneSelType = SceneSelTypeOpt.RAWPART Case ObjectType.FIXTURE ' Abilito la selezione delle Fixture Map.refProjectVM.SceneSelType = SceneSelTypeOpt.FIXTURE End Select Map.refRawPartOptionVM.SetMoveWithFixture(False) Map.refFixtureParametersVM.UpdateFixtureTypeList() End Sub #End Region ' METHODS #Region "COMMANDS" #Region "DoneCommand" ''' ''' Returns a command that do Done. ''' Public ReadOnly Property DoneCommand As ICommand Get If m_cmdDone Is Nothing Then m_cmdDone = New RelayCommand(AddressOf Done) End If Return m_cmdDone End Get End Property ''' ''' Execute the Point. This method is invoked by the DoneCommand. ''' Public Sub Done(ByVal param As Object) ' Verifico la validità del punto in Input If Not String.IsNullOrEmpty(m_InputValue) Then ' se movimento di traslazione If m_MoveIsChecked Then Dim InputPoint As New Point3d(0, 0, 0) Dim Values() As String = m_InputValue.Split(","c) If Values.Count = 2 Then StringToLen(Values(0), InputPoint.x) StringToLen(Values(1), InputPoint.y) Else m_InputErrorMsg = "Il valore non è una cordinata XY" OnPropertyChanged("InputErrorMsg") Return End If ' Vettore di movimento Dim vtMove As Vector3d ' lo imposto a seconda del tipo del primo elemento selezionato Dim nFirstSelectedId As Integer = EgtGetFirstSelectedObj() ' se è un grezzo If EgtVerifyRawPartCurrPhase(nFirstSelectedId) Then ' imposto il riferimento della tavola Dim ptTableRef As Point3d EgtGetTableRef(1, ptTableRef) ' calcolo il punto del grezzo da posizionar nelle coordinate di input Dim ptRawRefPoint As Point3d = DispositionUtility.GetRawPartRefPoint(nFirstSelectedId, m_RawRefPosition) ' creo un punto con le coordinate di input espresse rispetto alla tavola Dim TableRefInputPoint As New Point3d(InputPoint) TableRefInputPoint.LocToLoc(EgtGetGridFrame(), New Frame3d(ptTableRef)) ' calcolo il vettore di spostamento del grezzo vtMove = TableRefInputPoint - ptRawRefPoint ' se è una ventosa ElseIf EgtVerifyFixture(nFirstSelectedId) Then Dim SelObjFrame3d As New Frame3d(Frame3d.GLOB) EgtGetGroupGlobFrame(nFirstSelectedId, SelObjFrame3d) SelObjFrame3d.ToLoc(EgtGetGridFrame()) Dim FixturePoint As New Point3d(SelObjFrame3d.Orig) ' Ricavo il vettore di movimento (tengo solo XY) vtMove = InputPoint - FixturePoint vtMove.z = 0 End If ' Muovo tutti gli oggetti selezionati DispositionUtility.MoveRawPartPartAndFixture(GDB_ID.SEL, vtMove, DispositionUtility.SelType.NULL) ' se è un grezzo If EgtVerifyRawPartCurrPhase(nFirstSelectedId) Then Dim ptRawRefPoint As Point3d = DispositionUtility.GetRawPartRefPoint(nFirstSelectedId, m_RawRefPosition) ' verifico se lo spostamento effettuato differisce da quello richiesto Dim vtRemainingMove As Vector3d = InputPoint - ptRawRefPoint ' se differisce If Not vtRemainingMove.IsSmall() Then ' eseguo lo spostamento rimanente sull'asse x DispositionUtility.MoveRawPartPartAndFixture(GDB_ID.SEL, New Vector3d(vtRemainingMove.x, 0, 0), DispositionUtility.SelType.NULL) ' eseguo lo spostamento rimanente sull'asse y DispositionUtility.MoveRawPartPartAndFixture(GDB_ID.SEL, New Vector3d(0, vtRemainingMove.y, 0), DispositionUtility.SelType.NULL) End If End If ' se rotazione Else Dim nSelId As Integer = EgtGetFirstSelectedObj() If nSelId = GDB_ID.NULL Then Return Dim sVal As String = m_InputValue Dim vtRotAx As Vector3d = Vector3d.Z_AX() ' se si opera su grezzi If EgtVerifyRawPartCurrPhase(nSelId) Then ' Se primo carattere è nome asse If sVal(0) = "X"c Then sVal = sVal.Remove( 0, 1) vtRotAx = Vector3d.X_AX() ElseIf sVal(0) = "Y"c Then sVal = sVal.Remove( 0, 1) vtRotAx = Vector3d.Y_AX() ElseIf sVal(0) = "Z"c Then sVal = sVal.Remove( 0, 1) vtRotAx = Vector3d.Z_AX() End If End If Dim InputAngle As Double = 0 If Not StringToDouble(sVal, InputAngle) Then m_InputErrorMsg = "Il valore non è un angolo valido" OnPropertyChanged("InputErrorMsg") Return End If ' eseguo rotazione While nSelId <> GDB_ID.NULL Select Case m_ActiveObject Case ObjectType.RAWPART If EgtRotateRawPart(nSelId, vtRotAx, InputAngle) Then Dim vtOrigMove As Vector3d = Vector3d.NULL() Dim vtRefMove As Vector3d = Vector3d.NULL() DispositionUtility.VerifyRawPosition(nSelId, vtOrigMove, vtRefMove) Else m_InputErrorMsg = "Impossibile ruotare il grezzo." OnPropertyChanged("InputErrorMsg") End If Case ObjectType.PART 'EgtMove... Case ObjectType.FIXTURE If Not EgtRotateFixture(nSelId, InputAngle) Then m_InputErrorMsg = "Impossibile ruotare la ventosa" OnPropertyChanged("InputErrorMsg") End If End Select nSelId = EgtGetNextSelectedObj() End While End If EgtDraw() End If End Sub #End Region ' DoneCommand #Region "CheckedRawRefCommand" ''' ''' Returns a command that do Done. ''' Public ReadOnly Property CheckedRawRefCommand As ICommand Get If m_cmdCheckedRawRef Is Nothing Then m_cmdCheckedRawRef = New RelayCommand(AddressOf CheckedRawRef) End If Return m_cmdCheckedRawRef End Get End Property ''' ''' Execute the Point. This method is invoked by the DoneCommand. ''' Public Sub CheckedRawRef(ByVal param As Object) Dim nRawRef As MCH_CR = DirectCast(param, MCH_CR) m_RawRefPosition = nRawRef End Sub #End Region ' CheckedRawRefCommand #End Region End Class