From d0c9e02e136bc7d896c99309a9ef68c83b1cc27d Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 12 May 2016 15:30:23 +0000 Subject: [PATCH] OmagCUT 1.6r1 : - migliorie e correzione in movimento grezzi con ventose. --- ConstGen.vb | 9 ++ MoveRawPartPage.xaml.vb | 177 ++++++++++++++++++++++++------------- My Project/AssemblyInfo.vb | 4 +- SplitPageUC.xaml.vb | 11 +-- 4 files changed, 131 insertions(+), 70 deletions(-) diff --git a/ConstGen.vb b/ConstGen.vb index 3ed04e5..23003a7 100644 --- a/ConstGen.vb +++ b/ConstGen.vb @@ -51,6 +51,13 @@ Module ConstGen ' Delta Z sovratavola per evitare problemi di visualizzazione texture Public Const DELTAZ_ADDTAB As Double = 0.1 + ' Nome testa con ventose per spostamento pezzi + Public Const VACUUM_HEAD As String = "H4" + ' Nome gruppo layout in testa con ventose + Public Const VACUUM_HEAD_LAYOUT As String = "LAYOUT" + ' Nome oggetto frame prima uscita di una testa + Public Const HEAD_FIRST_EXIT As String = "_T1" + ' Costanti per lavorazioni Public Const MACH_GROUP As String = "Mach01" Public Const MAIN_TAB As String = "MainTab" @@ -68,6 +75,8 @@ Module ConstGen Public Const KEY_KERF As String = "Kerf" ' Nome del contorno del grezzo Public Const NAME_RAW_OUTLINE As String = "RawOutline" + ' Nome della regione del kerf grezzo + Public Const NAME_KERF_REGION As String = "KerfRegion" ' Nome della regione fuori kerf nel grezzo Public Const NAME_OUTKERF As String = "SheetOut" ' Chiave per definizione del grezzo per punti diff --git a/MoveRawPartPage.xaml.vb b/MoveRawPartPage.xaml.vb index e6f492a..1949637 100644 --- a/MoveRawPartPage.xaml.vb +++ b/MoveRawPartPage.xaml.vb @@ -10,8 +10,10 @@ Public Class MoveRawPartPage Private m_nCurrPhase As Integer = 0 ' Dati movimento Private m_dStep As Double = 0 - ' Tipo movimento dei grezzi - Private m_bPerp As Boolean = False + ' Tipo manipolatore con ventosa + Private m_nVacType As Integer = 0 + ' Tipo movimento dei grezzi (manuale o con testa ventosa) + Private m_bByHand As Boolean = True ' Gestione movimento manuale perpendicolare Private m_vtDir As New Vector3d ' direzione di movimento Private m_ptMid As New Point3d ' punto medio del taglio @@ -22,11 +24,10 @@ Public Class MoveRawPartPage Private m_nVacId As Integer = GDB_ID.NULL Private m_nRefId As Integer = GDB_ID.NULL Private m_RawPartDataList As New List(Of RawPartData) + Private m_ptTabCen As New Point3d Private Sub MoveRawPartPage_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized PrevBtn.IsEnabled = False - ' Leggo tipo movimento grezzi - m_bPerp = (GetPrivateProfileInt(S_RAWMOVE, K_PERPENDICULAR, 0, m_MainWindow.GetIniFile()) <> 0) ' Assegno testi RemovePartBtn.Content = EgtMsg(MSG_MOVERAWPAGEUC + 1) 'Rimuovi End Sub @@ -34,6 +35,13 @@ Public Class MoveRawPartPage Private Sub MoveRawPartPage_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC m_bActive = True + ' Leggo tipo manipolatore con ventosa + ' (0=assente, 1=dietro, 2=laterale esterno, 3= laterale interno) + m_nVacType = 0 + EgtGetInfo(EgtGetHeadId(VACUUM_HEAD), "VacType", m_nVacType) + ' Leggo tipo movimento grezzi + m_bByHand = (m_nVacType = 0 Or + (GetPrivateProfileInt(S_RAWMOVE, K_PERPENDICULAR, 0, m_MainWindow.GetIniFile()) <> 0)) ' Deseleziono tutto EgtDeselectAll() ' Recupero i tagli allungati prima definiti @@ -47,10 +55,14 @@ Public Class MoveRawPartPage Dim nPrevPhase As Integer = EgtGetCurrPhase() ' Creo nuova fase m_nCurrPhase = EgtAddPhase() - ' Origine tavola + ' Origine della tavola Dim ptOri As Point3d EgtGetTableRef(1, ptOri) Dim vtOri As New Vector3d(ptOri.x, ptOri.y, ptOri.z) + ' Centro della tavola + Dim b3Tab As New BBox3d + EgtGetTableArea(1, b3Tab) + m_ptTabCen = b3Tab.Center() ' Se non ci sono tagli allungati, confermo i grezzi If Cuts.Length() = 0 Then ' Ciclo sui grezzi @@ -133,7 +145,7 @@ Public Class MoveRawPartPage m_dStep = GetPrivateProfileDouble(S_RAWMOVE, K_RAWSTEP, 50, m_MainWindow.GetIniFile()) StepMoveTxBx.Text = LenToString(m_dStep, 3) ' Se movimento manuale perpendicolare - If m_bPerp Then + If m_bByHand Then ' Se esiste taglio passante determino direzione di movimento If Cuts.Length() > 0 Then ' recupero taglio di separazione @@ -173,7 +185,7 @@ Public Class MoveRawPartPage m_RawPartDataList.Capacity() = 10 End If ' Aggiorno interfaccia per taglio perpendicolare - If m_bPerp Then + If m_bByHand Then LeftBtn.Visibility = Windows.Visibility.Hidden RightBtn.Visibility = Windows.Visibility.Hidden RemovePartBtn.Visibility = Windows.Visibility.Visible @@ -217,12 +229,12 @@ Public Class MoveRawPartPage If nStat = GDB_ST.SEL Then EgtSetStatus(nId, GDB_ST.ON_) ' Se con ventose, le nascondo - If Not m_bPerp Then EgtSetStatus(m_nVacId, GDB_ST.OFF) + If Not m_bByHand Then EgtSetStatus(m_nVacId, GDB_ST.OFF) Else EgtDeselectAll() EgtSetStatus(nId, GDB_ST.SEL) ' Se con ventose le posiziono sul grezzo - If Not m_bPerp Then PutVacuumCupsOnRaw(nId) + If Not m_bByHand Then PutVacuumCupsOnRaw(nId) End If EgtDraw() Exit While @@ -235,7 +247,7 @@ Public Class MoveRawPartPage Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL ' Se movimento perpendicolare, è allontanamento - If m_bPerp Then + If m_bByHand Then ' Recupero il centro del grezzo Dim ptRawCen As Point3d GetRawCenter(nRawId, ptRawCen) @@ -266,7 +278,7 @@ Public Class MoveRawPartPage Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL ' Se movimento perpendicolare, è avvicinamento - If m_bPerp Then + If m_bByHand Then ' Se sono già a contatto, non devo fare alcunché If m_dCurrDist < EPS_SMALL Then Return ' Recupero il centro del grezzo @@ -349,7 +361,7 @@ Public Class MoveRawPartPage Private Sub MoveRawPartPage_Unloaded(sender As Object, e As EventArgs) Handles Me.Unloaded m_bActive = False ' Se movimento con ventose - If Not m_bPerp Then + If Not m_bByHand Then ' nascondo le ventose EgtSetStatus(m_nVacId, GDB_ST.OFF) ' aggiungo al gruppo disposizione dei sottogruppi con i dati di movimento dei grezzi spostati @@ -378,6 +390,8 @@ Public Class MoveRawPartPage EgtSetInfo(nRpmId, "Ad", sInfo) sInfo = rwData.m_sCups EgtSetInfo(nRpmId, "Vc", sInfo) + sInfo = m_nVacType.ToString() + EgtSetInfo(nRpmId, "Vt", sInfo) End If Next ' Eseguo calcolo speciale dei movimenti @@ -389,10 +403,10 @@ Public Class MoveRawPartPage ' Cancello eventuali vecchie ventose RemoveVacuumCups() ' Identificativo ventose nella macchina - Dim nLayId As Integer = EgtGetFirstNameInGroup(EgtGetHeadId("H4"), "LAYOUT") + Dim nLayId As Integer = EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), VACUUM_HEAD_LAYOUT) If nLayId = GDB_ID.NULL Then Return False ' Identificativo riferimento della testa nella macchina - Dim nT1Id As Integer = EgtGetFirstNameInGroup(EgtGetHeadId("H4"), "_T1") + Dim nT1Id As Integer = EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), HEAD_FIRST_EXIT) If nT1Id = GDB_ID.NULL Then Return False ' Creo gruppo temporaneo in cui copiarli m_nTempId = EgtCreateGroup(GDB_ID.ROOT) @@ -406,7 +420,7 @@ Public Class MoveRawPartPage EgtSetStatus(m_nVacId, GDB_ST.OFF) Dim nId As Integer = EgtGetFirstInGroup(m_nVacId) While nId <> GDB_ID.NULL - Select EgtGetType(nId) + Select Case EgtGetType(nId) Case GDB_TY.CRV_LINE, GDB_TY.CRV_ARC, GDB_TY.CRV_BEZ, GDB_TY.CRV_COMPO EgtSetStatus(nId, GDB_ST.ON_) Case Else @@ -432,7 +446,7 @@ Public Class MoveRawPartPage Private Function ResetVacuumCups() As Boolean ' Ripristino posizione e rotazione originali Dim frOriRef As New Frame3d - EgtFrame(EgtGetFirstNameInGroup(EgtGetHeadId("H4"), "_T1"), GDB_ID.ROOT, frOriRef) + EgtFrame(EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), HEAD_FIRST_EXIT), GDB_ID.ROOT, frOriRef) Dim frCurrRef As New Frame3d EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef) EgtMove(m_nVacId, frOriRef.Orig() - frCurrRef.Orig(), GDB_RT.GLOB) @@ -456,68 +470,65 @@ Public Class MoveRawPartPage End Function Private Function PutVacuumCupsOnRaw(nRawId As Integer) As Boolean - If m_bPerp Then Return False + If m_bByHand Then Return False ' Ripristino posizione originale ventose ResetVacuumCups() ' Visualizzo le ventose EgtSetStatus(m_nVacId, GDB_ST.ON_) - ' Centro della tavola - Dim b3Tab As New BBox3d - EgtGetTableArea(1, b3Tab) - Dim ptTabCen As Point3d = b3Tab.Center() ' Box e baricentro del grezzo (riportato sopra al grezzo) Dim b3Raw As New BBox3d GetRawBox(nRawId, b3Raw) Dim ptRawCen As Point3d GetRawCenter(nRawId, ptRawCen) - ptRawCen.z += b3Raw.DimZ() / 2 + 1 + ptRawCen.z += b3Raw.DimZ() / 2 + ' Se non esiste, creo la regione del kerf del grezzo + Dim nRawRegId = EgtGetFirstNameInGroup(nRawId, NAME_KERF_REGION) + If nRawRegId = GDB_ID.NULL Then + Dim nOutlineId As Integer = EgtGetFirstNameInGroup(nRawId, NAME_KERF) + nRawRegId = EgtCreateSurfFlatRegion(nRawId, nOutlineId) + EgtSetName(nRawRegId, NAME_KERF_REGION) + EgtSetStatus(nRawRegId, GDB_ST.OFF) + End If + ' Baricentro della regione di kerf + Dim ptKerfCen As Point3d + EgtCentroid(nRawRegId, GDB_ID.ROOT, ptKerfCen) ' Cerco migliore configurazione di ventose per prendere il grezzo - Const MAX_SEL As Integer = 100 + Const MAX_SEL As Integer = 20 For nI As Integer = 1 To MAX_SEL ' Recupero la configurazione di ventose nI-esima Dim sCups() As String = Nothing Dim sCups2() As String = Nothing If Not GetVacuumCupSelection(nI, sCups, sCups2) Then Return False ' Determino validità soluzioni della configurazione - Dim dDist = TestVacuumCupSelection(sCups, b3Raw, ptRawCen, ptTabCen) - Dim dDist2 = TestVacuumCupSelection(sCups2, b3Raw, ptRawCen, ptTabCen) + Dim vtMove As New Vector3d + Dim ptRotCen As New Point3d + Dim dRotAngDeg As Double = 0 + Dim vtMove2 As New Vector3d + Dim ptRotCen2 As New Point3d + Dim dRotAngDeg2 As Double = 0 + Dim dDist = TestVacuumCupSelection(sCups, b3Raw, ptKerfCen, nRawRegId, vtMove, ptRotCen, dRotAngDeg) + Dim dDist2 = TestVacuumCupSelection(sCups2, b3Raw, ptKerfCen, nRawRegId, vtMove2, ptRotCen2, dRotAngDeg2) If dDist > INFINITO - 1 And dDist2 > INFINITO - 1 Then Continue For If dDist2 < dDist Then sCups = sCups2 + vtMove = vtMove2 + ptRotCen = ptRotCen2 + dRotAngDeg = dRotAngDeg2 End If - ' Ne calcolo il box - Dim b3Vac As New BBox3d + ' Eseguo il movimento + EgtMove(m_nVacId, vtMove, GDB_RT.GLOB) + EgtRotate(m_nVacId, ptRotCen, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB) + ' Visualizzo le ventose For nJ As Integer = 0 To sCups.Length() - 1 Dim nCupId = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ)) - Dim b3Cup As New BBox3d - If EgtGetBBoxGlob(nCupId, GDB_BB.STANDARD, b3Cup) Then b3Vac.Add(b3Cup) + EgtSetStatus(nCupId, GDB_ST.ON_) Next - ' Verifico se box minore di quello del pezzo - If (b3Vac.DimX() < b3Raw.DimX() And b3Vac.DimY() < b3Raw.DimY()) Or - (b3Vac.DimX() < b3Raw.DimY() And b3Vac.DimY() < b3Raw.DimX()) Then - ' Eseguo il movimento - Dim vtMove As Vector3d = ptRawCen - b3Vac.Center() - EgtMove(m_nVacId, vtMove, GDB_RT.GLOB) - b3Vac.Move(vtMove) - ' Allineo il lato lungo delle ventose con quello del grezzo - Dim dAngRotDeg As Double = 0 - If (b3Vac.DimX() >= b3Vac.DimY() And b3Raw.DimX() < b3Raw.DimY()) Or - (b3Vac.DimX() < b3Vac.DimY() And b3Raw.DimX() >= b3Raw.DimY()) Then - dAngRotDeg = 90 - EgtRotate(m_nVacId, b3Vac.Center(), Vector3d.Z_AX(), dAngRotDeg, GDB_RT.GLOB) - End If - ' Visualizzo le ventose - For nJ As Integer = 0 To sCups.Length() - 1 - Dim nCupId = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ)) - EgtSetStatus(nCupId, GDB_ST.ON_) - Next - ' Aggiorno dati del grezzo - Dim frCurrRef As New Frame3d - EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef) - Dim vtDelta As Vector3d = frCurrRef.Orig() - ptRawCen - AddRawPartData(nRawId, vtDelta, dAngRotDeg, sCups) - Return True - End If + ' Aggiorno dati del grezzo + Dim frCurrRef As New Frame3d + EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef) + Dim vtDelta As Vector3d = frCurrRef.Orig() - ptRawCen + AddRawPartData(nRawId, vtDelta, dRotAngDeg, sCups) + Return True Next Return False End Function @@ -546,7 +557,8 @@ Public Class MoveRawPartPage Return True End Function - Private Function TestVacuumCupSelection(sCups() As String, b3Raw As BBox3d, ptRawCen As Point3d, ptTabCen As Point3d) As Double + Private Function TestVacuumCupSelection(sCups() As String, b3Raw As BBox3d, ptRawCen As Point3d, nRawRegId As Integer, + ByRef vtMove As Vector3d, ByRef ptRotCen As Point3d, ByRef dRotAngDeg As Double) As Double ' Se definizione mancante, scarto soluzione If IsNothing(sCups) Then Return INFINITO ' Ne calcolo il box @@ -558,31 +570,70 @@ Public Class MoveRawPartPage Next If b3Vac.IsEmpty() Then Return INFINITO ' Se box maggiore di quello del pezzo, scarto soluzione - If (b3Vac.DimX() > b3Raw.DimX() And b3Vac.DimX() > b3Raw.DimY()) Or - (b3Vac.DimY() > b3Raw.DimX() And b3Vac.DimY() > b3Raw.DimY()) Then + If Not ((b3Vac.DimX() < b3Raw.DimX() And b3Vac.DimY() < b3Raw.DimY()) Or + (b3Vac.DimX() < b3Raw.DimY() And b3Vac.DimY() < b3Raw.DimX())) Then Return INFINITO End If ' Determino il movimento - Dim vtMove As Vector3d = ptRawCen - b3Vac.Center() + vtMove = ptRawCen - b3Vac.Center() b3Vac.Move(vtMove) ' Determino la rotazione, allineando il lato lungo delle ventose con quello del grezzo - Dim dAngRotDeg As Double = 0 + ptRotCen = b3Vac.Center() + dRotAngDeg = 0 If (b3Vac.DimX() >= b3Vac.DimY() And b3Raw.DimX() < b3Raw.DimY()) Or (b3Vac.DimX() < b3Vac.DimY() And b3Raw.DimX() >= b3Raw.DimY()) Then - dAngRotDeg = 90 + dRotAngDeg = 90 End If + ' Identificativi delle ventose + Dim nCups(sCups.Length() - 1) As Integer + For nJ As Integer = 0 To sCups.Length() - 1 + nCups(nJ) = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ)) + Next + ' Eseguo verifica delle ventose rispetto al grezzo + Dim bVacOk As Boolean = True + If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then + ' Provo ad aggiungere rotazione di + 45 + dRotAngDeg += 45 + If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then + ' Provo ad aggiungere rotazione di - 45 + dRotAngDeg -= 90 + If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then + bVacOk = False + End If + End If + End If + If Not bVacOk Then Return INFINITO ' Recupero riferimento della testa ventose Dim frCurrRef As New Frame3d EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef) Dim ptRef As Point3d = frCurrRef.Orig() ' Applico movimento e rotazione al punto ptRef.Move(vtMove) - ptRef.Rotate(b3Vac.Center(), Vector3d.Z_AX(), dAngRotDeg) + ptRef.Rotate(ptRotCen, Vector3d.Z_AX(), dRotAngDeg) ' Ne calcolo la distanza dal centro della tavola - Dim dDist As Double = Point3d.DistXY(ptRef, ptTabCen) + Dim dDist As Double = Point3d.DistXY(ptRef, m_ptTabCen) Return dDist End Function + Private Function TestVacuumCups(nCups() As Integer, nRawRegId As Integer, + vtMove As Vector3d, ptRotCen As Point3d, dRotAngDeg As Double) As Boolean + ' Eseguo verifica delle ventose rispetto al grezzo + Dim bVacOk As Boolean = True + For nJ As Integer = 0 To nCups.Length() - 1 + Dim nCupId = nCups(nJ) + ' Eseguo rototraslazione delle ventose per verificare se sono contenute nel grezzo + EgtMove(nCupId, vtMove, GDB_RT.GLOB) + EgtRotate(nCupId, ptRotCen, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB) + ' Confronto le regioni + If EgtSurfFrChunkSimpleClassify(nRawRegId, 0, nCupId, 0) <> REGC.IN2 Then bVacOk = False + ' Annullo rototraslazione + EgtRotate(nCupId, ptRotCen, Vector3d.Z_AX(), -dRotAngDeg, GDB_RT.GLOB) + EgtMove(nCupId, -vtMove, GDB_RT.GLOB) + ' Se verifica fallita, esco dal ciclo + If Not bVacOk Then Exit For + Next + Return bVacOk + End Function Private Function AddRawPartData(nRawId As Integer) As Integer ' Cerco in lista record con dati del grezzo indicato diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index 6e8fd11..8af4cd3 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -60,5 +60,5 @@ Imports System.Windows ' by using the '*' as shown below: ' - - + + diff --git a/SplitPageUC.xaml.vb b/SplitPageUC.xaml.vb index 83e7b6d..701b355 100644 --- a/SplitPageUC.xaml.vb +++ b/SplitPageUC.xaml.vb @@ -6,8 +6,8 @@ Public Class SplitPageUC ' Riferimento alla MainWindow Private m_MainWindow As MainWindow = Application.Current.MainWindow - ' Tipo movimento dei grezzi - Private m_bPerp As Boolean = False + ' Tipo movimento dei grezzi (manuale o con testa ventosa) + Private m_bByHand As Boolean = True ' Stato Private m_nCurrPhase As Integer = 0 Private m_MachiningList As New List(Of Machining) @@ -21,8 +21,6 @@ Public Class SplitPageUC PrevBtn.IsEnabled = False ' Collego lista di oggetti a ListBox MachiningLsBx.ItemsSource = m_ItemList - ' Leggo tipo movimento grezzi - m_bPerp = (GetPrivateProfileInt(S_RAWMOVE, K_PERPENDICULAR, 0, m_MainWindow.GetIniFile()) <> 0) ' Assegno testi OnOffBtn.Content = EgtMsg(MSG_SPLITPAGEUC + 1) ' On/Off AllOnBtn.Content = EgtMsg(MSG_SPLITPAGEUC + 2) ' Tutti On @@ -36,6 +34,9 @@ Public Class SplitPageUC End Sub Private Sub SplitPageUC_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded + ' Leggo tipo movimento grezzi + m_bByHand = (EgtGetHeadId(VACUUM_HEAD) = GDB_ID.NULL Or + (GetPrivateProfileInt(S_RAWMOVE, K_PERPENDICULAR, 0, m_MainWindow.GetIniFile()) <> 0)) ' Nascondo eventuali pezzi in parcheggio HideParkedParts() EgtZoom(ZM.ALL) @@ -569,7 +570,7 @@ Public Class SplitPageUC If m_MainWindow.GetKeyOption(MainWindow.KEY_OPT.MAN_MANIP) Or m_MainWindow.GetKeyOption(MainWindow.KEY_OPT.AUTO_MANIP) Then ' Se allontanamento perpendicolare - If m_bPerp Then + If m_bByHand Then ' Ci deve essere almeno 1 taglio disabilitato e 1 e 1 solo passante NextBtn.IsEnabled = (GetDisabledCutsCount() > 0 And GetSplitCutsCount() = 1) ' Altrimenti