using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Threading.Tasks; namespace ib.essetre.integration.egaltech { // La classe BTL rappresenta un singolo file BTL e come esso può contenere una o più Part (ovvero le travi di legno) // ed ogni Part può contenere una o più Feature (ovvero i tagli da effettuare) public class BTL { public string projectNumber ; public int productionId ; public int patternId ; public string barLength ; public string panelLength ; public string panelWidth ; public string barLoad90 ; public int RefPos ; public List parts ; // Contatore entità di contorno libero private int _FcEnt ; #if DEBUG [DllImport("IntegrationEgaltech2D32.dll", CharSet = CharSet.Unicode)] private static extern bool EgtInitBtlWriter() ; [DllImport("IntegrationEgaltech2D32.dll", CharSet = CharSet.Unicode)] private static extern int EgtStartBtlWriter() ; [DllImport("IntegrationEgaltech2D32.dll", CharSet = CharSet.Unicode)] private static extern bool EgtEndBtlWriter() ; #else [DllImport("IntegrationEgaltech2R32.dll", CharSet = CharSet.Unicode)] private static extern bool EgtInitBtlWriter() ; [DllImport("IntegrationEgaltech2R32.dll", CharSet = CharSet.Unicode)] private static extern int EgtStartBtlWriter() ; [DllImport("IntegrationEgaltech2R32.dll", CharSet = CharSet.Unicode)] private static extern bool EgtEndBtlWriter() ; #endif public BTL() {} public bool WriteIntoFile( string BtlPath, bool IsFromProject) { // Inizializzo libreria di base bool bInit = EgtInitBtlWriter() ; // Se un file txt (contenente messaggio di errore) con lo stesso nome esiste già viene cancellato if ( File.Exists( Path.ChangeExtension( BtlPath, ".txt"))) File.Delete( Path.ChangeExtension( BtlPath, ".txt")) ; // Se non esistono pezzi, non faccio alcunché if ( parts == null) return false ; int nStart = 0 ; // Reset entità di contorno libero _FcEnt = Constants.FcBaseId ; // Il seguente blocco 'using' si occupa della scrittura del file di testo, poi salvato in .btl try { using ( var tw = new StreamWriter( BtlPath, false)) { // Avvio scrittura parte geometrica nStart = (bInit ? EgtStartBtlWriter() : 0); tw.WriteLine( Constants.VERSION) ; tw.WriteLine( Constants.BUILD) ; tw.WriteLine( Constants.GENERAL) ; tw.WriteLine( Constants.PROJECT_NUMBER + this.projectNumber) ; tw.WriteLine( Constants.SCALE_UNIT + Constants.scaleUnit.ToString()) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"PRODID\":" + "\"" + ( IsFromProject ? 0 : productionId) + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"PATTID\":" + "\"" + ( IsFromProject ? 0 : patternId) + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"" + barLength + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"PANELLEN\":" + "\"" + panelLength + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"PANELWIDTH\":" + "\"" + panelWidth + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"REFPOS\":" + "\"" + RefPos.ToString() + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"PROJECT\":" + "\"" + ( IsFromProject ? "1" : "0") + "\"") ; if ( nStart <= 0) { tw.WriteLine(Constants.USERATTRIBUTE + "\"PROGID\":" + "\"" + (bInit ? "1" : "0") + "\"") ; } if ( nStart > 0) { foreach ( Part singlePart in parts) { tw.WriteLine( Constants.PART) ; tw.WriteLine( Constants.SINGLE_MEMBER_NUMBER + singlePart.singleMemberNumber) ; tw.WriteLine( Constants.MATERIAL + singlePart.Material) ; tw.WriteLine( Constants.COUNT + singlePart.count) ; double len = Convert.ToDouble( singlePart.length) * Math.Pow( 10, Constants.scaleUnit) ; int intLen = Convert.ToInt32( len) ; tw.WriteLine( Constants.LENGTH + intLen.ToString( "D8")) ; double hei = Convert.ToDouble( singlePart.height) * Math.Pow( 10, Constants.scaleUnit) ; int intHei = Convert.ToInt32( hei) ; tw.WriteLine( Constants.HEIGHT + intHei.ToString( "D8")) ; double wid = Convert.ToDouble( singlePart.width) * Math.Pow( 10, Constants.scaleUnit) ; int intWid = Convert.ToInt32( wid) ; tw.WriteLine( Constants.WIDTH + intWid.ToString( "D8")) ; string posX = singlePart.x.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\"") ; string posY = singlePart.y.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"POSY\":" + "\"" + posY + "\"") ; string posZ = singlePart.z.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"POSZ\":" + "\"" + posZ + "\"") ; string inv = singlePart.inverted.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\"") ; string rot = singlePart.rotated.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"ROTATED\":" + "\"" + rot + "\"") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"TYPE\":" + "\"" + singlePart.Type + "\"") ; string CutId = ( IsFromProject ? singlePart.elementId : singlePart.cutId).ToString() ; tw.WriteLine( Constants.USERATTRIBUTE + "\"CUTID\":" + "\"" + CutId + "\"") ; // Scrivo eventuale Outline foreach ( Feature singleFeature in singlePart.features) { // Assegno identificativo del processo string TaskId = (IsFromProject ? singleFeature.processId : singleFeature.taskId).ToString() ; // Se Outline (processo "251") elaborazione speciale if ( singleFeature.processKey.Contains( "251")) { WriteOutlineAperture( true, singleFeature, TaskId, tw) ; } } // Scrivo eventuali Aperture foreach ( Feature singleFeature in singlePart.features) { // Assegno identificativo del processo string TaskId = (IsFromProject ? singleFeature.processId : singleFeature.taskId).ToString() ; // Se Aperture (processo "252") elaborazione speciale if ( singleFeature.processKey.Contains( "252")) { WriteOutlineAperture( false, singleFeature, TaskId, tw) ; } } // Scrivo tutti gli altri processi foreach ( Feature singleFeature in singlePart.features) { // Assegno identificativo del processo string TaskId = ( IsFromProject ? singleFeature.processId : singleFeature.taskId).ToString() ; // Se Outline (processo "251") o Aperture (processo "252") salto if ( singleFeature.processKey.Contains( "251") || singleFeature.processKey.Contains( "252")) { ; } // Se Free Contour (processo "250") elaborazione speciale else if ( singleFeature.processKey.Contains( "250")) { WriteFreeContour( singleFeature, TaskId, tw) ; } // Altri processi else { bool bIsVariant = singleFeature.processKey.Contains("-900-") ; // Tipo di Process if ( bIsVariant) tw.WriteLine( Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.processParameters[26]) ; else tw.WriteLine( Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation) ; // Eventuale sistema di riferimto WriteReference( singleFeature, tw) ; // Parametri standard del Process ( 1 .. 26) tw.Write( Constants.PROCESS_PARAMETERS) ; for ( int i = 1 ; i <= 26 ; ++ i) { string singleParameter = singleFeature.processParameters[i-1] ; if ( i != 15 || ! ( singleFeature.processKey.Contains( "060") || singleFeature.processKey.Contains( "061"))) tw.Write( "P" + i.ToString( "D2") + ":" + MultAndConvertTo8( singleParameter) + " ") ; else tw.Write( "P" + i.ToString( "D2") + ":" + "\"" + singleFeature.text + "\" ") ; } tw.WriteLine( "") ; // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" for ( int i = 1 ; i <= 20 ; ++ i) { string singleParameter = singleFeature.processParameters[i+25] ; if ( ! singleParameter.Equals( "0") && ( ! bIsVariant || i != 1)) { singleParameter = singleParameter.Replace( ",", ".") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + i.ToString( "D2") + "\":\"" + singleParameter + "\" ") ; } } tw.WriteLine( Constants.PROCESS_IDENT + singleFeature.processIdent) ; tw.WriteLine( Constants.PROCESS + singleFeature.process) ; tw.WriteLine( Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + TaskId + "\"") ; } } } } } } catch { return false ; } // Concludo scrittura parte geometrica bool bEnd = (bInit && EgtEndBtlWriter()) ; // Scrittura file ausiliario con dati che non fanno ricalcolare le lavorazioni try { using ( var tw = new StreamWriter( Path.ChangeExtension( BtlPath, ".btm"), false)) { tw.WriteLine( "[AuxData]") ; tw.WriteLine( "LOAD90=" + barLoad90) ; tw.WriteLine( "PROGID=" + nStart.ToString()); } } catch { return false ; } return true ; } // Il seguente metodo analizza il campo sag1 della singleFeature passata: se non è vuoto allora la stringa // viene splittata nei parametri P di POLY ed analizzata private void WriteOutlineAperture( bool bOutline, Feature singleFeature, String TaskId, StreamWriter tw) { // Se non ci sono dati, esco if (singleFeature.sag1 == "") return; // Divido i dati in record punti string[] arrParam = singleFeature.sag1.Split(new string[] { "POLY([", "),", ")]" }, StringSplitOptions.RemoveEmptyEntries); // Se curva chiusa if ( arrParam[arrParam.Length - 1] == ",'P','C')") { // se primo punto è a metà di arco, copio l'ultimo punto inserendolo prima del primo if ( arrParam[0].StartsWith( "A")) { // elimino l'ultimo elemento Array.Resize( ref arrParam, arrParam.Length - 1) ; // copio l'ultimo elemento inserendolo prima del primo (tramite doppia inversione) Array.Reverse(arrParam); Array.Resize( ref arrParam, arrParam.Length + 1) ; arrParam[arrParam.Length - 1] = arrParam[0] ; Array.Reverse(arrParam); } // altrimenti copio il primo punto nell'ultimo elemento else arrParam[arrParam.Length - 1] = arrParam[0] ; } // altrimenti aperta, quindi elimino l'ultimo elemento else Array.Resize( ref arrParam, arrParam.Length - 1); // Se il parametro Q10 è 1, l'ordine dell'array viene invertito if ( singleFeature.processParameters[35] == "1") Array.Reverse(arrParam); // Recupero il lato di lavoro string sSide = singleFeature.processKey.Substring( Math.Max( 0, singleFeature.processKey.Length - 1)) ; // Ciclo sugli elementi Boolean flagArco = false ; for ( int i = 0 ; i < arrParam.Length ; i ++) { char[] separators = { ',', '(' } ; string[] parts = arrParam[i].Split( separators) ; // ogni parametro P di POLY viene splittato in più parti // il primo elemento di parts[] indica se ci troviamo all'inizio di un Arco o no switch ( parts[0]) { case "P": default: // Se StartPoint if ( i == 0) { tw.Write( ( bOutline ? Constants.OUTLINE_KEY : Constants.APERTURE_KEY)) ; tw.Write( Constants.SIDE + sSide + " ") ; tw.Write( Constants.PROCESS + singleFeature.process + " ") ; tw.Write( "P01:" + MultAndConvertTo8(parts[1]) + " "); // x tw.Write( "P02:" + MultAndConvertTo8(parts[2]) + " "); // y tw.Write( "P03:" + MultAndConvertTo8(parts[3]) + " "); // z tw.Write( "P06:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P08:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P10:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P11:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P12:" + Constants.EIGHT_ZEROS + " "); tw.Write("P13:" + MultAndConvertTo8(singleFeature.processParameters[12]) + " "); tw.Write("P14:" + MultAndConvertTo8(singleFeature.processParameters[13]) + " "); tw.Write("P15:" + MultAndConvertTo8(singleFeature.processParameters[14]) + " "); tw.WriteLine( " "); // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" for ( int j = 1; j <= 20; ++j) { string singleParameter = singleFeature.processParameters[j + 25]; if ( ! singleParameter.Equals( "0")) { singleParameter = singleParameter.Replace( ",", "."); tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + j.ToString( "D2") + "\":\"" + singleParameter + "\" "); } } // TaskId tw.WriteLine(Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + TaskId + "\""); } // se altrimenti FineArco else if ( flagArco) { string[] PrevParts = arrParam[i - 1].Split(separators); tw.Write( ( bOutline ? Constants.OUTLINE_KEY : Constants.APERTURE_KEY)) ; tw.Write( Constants.SIDE + sSide + " ") ; tw.Write( Constants.PROCESS + singleFeature.process + " ") ; tw.Write( "P01:" + MultAndConvertTo8(parts[1]) + " "); // x (EndPoint Arc) tw.Write( "P02:" + MultAndConvertTo8(parts[2]) + " "); // y (EndPoint Arc) tw.Write( "P03:" + MultAndConvertTo8(parts[3]) + " "); // z (Endpoint Arc) tw.Write( "P06:" + MultAndConvertTo8(PrevParts[5]) + " "); // side ang tw.Write( "P08:" + "00000200" + " "); tw.Write( "P10:" + MultAndConvertTo8(PrevParts[1]) + " "); // x (Point on Arc) tw.Write( "P11:" + MultAndConvertTo8(PrevParts[2]) + " "); // y (Point on Arc) tw.Write( "P12:" + MultAndConvertTo8(PrevParts[3]) + " "); // z (Point on Arc) tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); tw.WriteLine( " "); flagArco = false; } // altrimenti FineSegmento else { string[] PrevParts = arrParam[i - 1].Split(separators); tw.Write( ( bOutline ? Constants.OUTLINE_KEY : Constants.APERTURE_KEY)) ; tw.Write( Constants.SIDE + sSide + " ") ; tw.Write( Constants.PROCESS + singleFeature.process + " ") ; tw.Write( "P01:" + MultAndConvertTo8(parts[1]) + " "); // x tw.Write( "P02:" + MultAndConvertTo8(parts[2]) + " "); // y tw.Write( "P03:" + MultAndConvertTo8(parts[3]) + " "); // z tw.Write( "P06:" + MultAndConvertTo8(PrevParts[5]) + " "); // side ang tw.Write( "P08:" + "00000100" + " "); tw.Write( "P10:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P11:" + Constants.EIGHT_ZEROS + " "); tw.Write( "P12:" + Constants.EIGHT_ZEROS + " "); tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); tw.WriteLine( " "); } break; case "A": // InizioArco flagArco = true; break; } } } // Il seguente metodo analizza il campo sag1 della singleFeature passata: se non è vuoto allora la stringa // viene splittata nei parametri P di POLY ed analizzata private void WriteFreeContour( Feature singleFeature, String TaskId, StreamWriter tw) { // Se non ci sono dati, esco if ( singleFeature.sag1 == "") { if ( singleFeature.processParameters[12] == "20" && VerifyReference( singleFeature)) { WriteOnePoint( singleFeature, TaskId, tw) ; } return ; } // Verifico se c'è un secondo percorso bool bTwo = ( singleFeature.sag2 != "") ; // Se singolo contorno if ( ! bTwo) { string[] arrParam = singleFeature.sag1.Split( new string[] { "POLY([", "),", ")]" }, StringSplitOptions.RemoveEmptyEntries) ; AdjustContourArray( singleFeature, ref arrParam) ; WriteOneContour( singleFeature, ref arrParam, TaskId, 0, tw) ; } // altrimenti due contorni if ( bTwo) { // Primo contorno string[] arrParam = singleFeature.sag1.Split( new string[] { "POLY([", "),", ")]" }, StringSplitOptions.RemoveEmptyEntries) ; AdjustContourArray( singleFeature, ref arrParam) ; WriteOneContour( singleFeature, ref arrParam, TaskId, 1, tw) ; // Secondo contorno string[] arrParam2 = singleFeature.sag2.Split( new string[] { "POLY([", "),", ")]" }, StringSplitOptions.RemoveEmptyEntries) ; AdjustContourArray( singleFeature, ref arrParam2) ; WriteOneContour( singleFeature, ref arrParam2, TaskId, 2, tw) ; } } private void AdjustContourArray( Feature singleFeature, ref string[] arrParam) { // Se curva chiusa if ( arrParam[arrParam.Length - 1] == ",'P','C')") { // se primo punto è a metà di arco, copio l'ultimo punto inserendolo prima del primo if ( arrParam[0].StartsWith( "A")) { // elimino l'ultimo elemento Array.Resize( ref arrParam, arrParam.Length - 1) ; // copio l'ultimo elemento inserendolo prima del primo (tramite doppia inversione) Array.Reverse(arrParam); Array.Resize( ref arrParam, arrParam.Length + 1) ; arrParam[arrParam.Length - 1] = arrParam[0] ; Array.Reverse(arrParam); } // altrimenti copio il primo punto nell'ultimo elemento else arrParam[arrParam.Length - 1] = arrParam[0] ; } // altrimenti aperta, quindi elimino l'ultimo elemento else Array.Resize( ref arrParam, arrParam.Length-1) ; // Se il parametro Q10 è 1, l'ordine dell'array viene invertito if ( singleFeature.processParameters[35] == "1") Array.Reverse( arrParam) ; } private int GetContourArrayCount( ref string[] arrParam) { int nCount = 0 ; for ( int i = 0; i < arrParam.Length; i++) { char[] separators = { ',', '(' } ; string[] parts = arrParam[i].Split( separators) ; // ogni parametro P di POLY viene splittato in più parti if ( parts[0] != "A") nCount ++ ; } return nCount ; } private void WriteOnePoint( Feature singleFeature, String TaskId, StreamWriter tw) { ++ _FcEnt ; tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); // Eventuale sistema di riferimto WriteReference( singleFeature, tw) ; tw.Write(Constants.PROCESS_PARAMETERS); tw.Write("P01:" + Constants.EIGHT_ZEROS + " ") ; // x tw.Write("P02:" + Constants.EIGHT_ZEROS + " ") ; // y tw.Write("P03:" + Constants.EIGHT_ZEROS + " ") ; // z tw.Write("P05:" + Constants.EIGHT_ZEROS + " ") ; tw.Write("P06:" + Constants.EIGHT_ZEROS + " ") ; tw.Write("P07:" + Constants.EIGHT_ZEROS + " ") ; tw.Write("P08:" + Constants.EIGHT_ZEROS + " ") ; tw.Write("P09:" + Constants.EIGHT_ZEROS + " ") ; tw.Write("P13:" + MultAndConvertTo8(singleFeature.processParameters[12]) + " "); tw.Write("P14:" + MultAndConvertTo8(singleFeature.processParameters[13]) + " "); tw.Write("P15:" + MultAndConvertTo8(singleFeature.processParameters[14]) + " "); tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + _FcEnt.ToString()); tw.WriteLine(Constants.PROCESS + singleFeature.process); // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" for ( int j = 1 ; j <= 20 ; ++ j) { string singleParameter = singleFeature.processParameters[j+25] ; if ( ! singleParameter.Equals( "0")) { singleParameter = singleParameter.Replace( ",", ".") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + j.ToString( "D2") + "\":\"" + singleParameter + "\" ") ; } } // TaskId tw.WriteLine( Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + TaskId + "\"") ; } private void WriteOneContour( Feature singleFeature, ref string[] arrParam, String TaskId, int nInd, StreamWriter tw) { // Ciclo sugli elementi Boolean flagArco = false ; for ( int i = 0; i < arrParam.Length; i++) { char[] separators = { ',', '(' } ; string[] parts = arrParam[i].Split( separators) ; // ogni parametro P di POLY viene splittato in più parti // il primo elemento di parts[] indica se ci troviamo all'inizio di un Arco o no switch ( parts[0]) { case "P": default : // Se StartPoint if ( i == 0) { ++ _FcEnt ; tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); // Eventuale sistema di riferimto WriteReference( singleFeature, tw) ; tw.Write(Constants.PROCESS_PARAMETERS); tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z tw.Write("P05:" + MultAndConvertTo8(singleFeature.processParameters[4]) + " ") ; if ( nInd == 0) tw.Write("P06:" + Constants.EIGHT_ZEROS + " ") ; else if ( nInd == 1) tw.Write("P06:" + MultAndConvertTo8( (_FcEnt + GetContourArrayCount( ref arrParam))) + " ") ; else tw.Write("P06:" + MultAndConvertTo8( (_FcEnt - GetContourArrayCount( ref arrParam))) + " ") ; tw.Write("P07:" + MultAndConvertTo8(singleFeature.processParameters[6]) + " "); if ( nInd == 0) tw.Write("P08:" + "00000000" + " "); else tw.Write("P08:" + MultAndConvertTo8( ( nInd == 1 ? "100" : "101")) + " "); if ( i == arrParam.Length - 1) // Verifica se ci troviamo all'ultimo parametro di POLY tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); // L'ultimo elemento di POLY deve avere "P09: 00000000" else tw.Write("P09:" + MultAndConvertTo8( (_FcEnt + 1).ToString()) + " "); tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); tw.Write("P13:" + MultAndConvertTo8(singleFeature.processParameters[12]) + " "); tw.Write("P14:" + MultAndConvertTo8(singleFeature.processParameters[13]) + " "); tw.Write("P15:" + MultAndConvertTo8(singleFeature.processParameters[14]) + " "); tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + _FcEnt.ToString()); tw.WriteLine(Constants.PROCESS + singleFeature.process); // Se unico o primo contorno if ( nInd == 0 || nInd == 1) { // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" for ( int j = 1 ; j <= 20 ; ++ j) { string singleParameter = singleFeature.processParameters[j+25] ; if ( ! singleParameter.Equals( "0")) { singleParameter = singleParameter.Replace( ",", ".") ; tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + j.ToString( "D2") + "\":\"" + singleParameter + "\" ") ; } } // TaskId tw.WriteLine( Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + TaskId + "\"") ; } } // se altrimenti FineArco else if ( flagArco) { ++ _FcEnt ; string[] PrevParts = arrParam[i - 1].Split(separators); tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); tw.Write(Constants.PROCESS_PARAMETERS); tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x (EndPoint Arc) tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y (EndPoint Arc) tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z (Endpoint Arc) tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); tw.Write("P06:" + MultAndConvertTo8(PrevParts[5]) + " "); // side ang tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); tw.Write("P08:" + "00000200" + " "); if ( i == arrParam.Length - 1) tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); else tw.Write("P09:" + MultAndConvertTo8( (_FcEnt + 1).ToString()) + " "); tw.Write("P10:" + MultAndConvertTo8(PrevParts[1]) + " "); // x (Point on Arc) tw.Write("P11:" + MultAndConvertTo8(PrevParts[2]) + " "); // y (Point on Arc) tw.Write("P12:" + MultAndConvertTo8(PrevParts[3]) + " "); // z (Point on Arc) tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + _FcEnt.ToString()); tw.WriteLine(Constants.PROCESS + singleFeature.process); flagArco = false ; } // altrimenti FineSegmento else { ++ _FcEnt ; string[] PrevParts = arrParam[i - 1].Split(separators); tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); tw.Write(Constants.PROCESS_PARAMETERS); tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); tw.Write("P06:" + MultAndConvertTo8(PrevParts[5]) + " "); // side ang tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); tw.Write("P08:" + "00000100" + " "); if ( i == arrParam.Length - 1) tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); else tw.Write("P09:" + MultAndConvertTo8( (_FcEnt + 1).ToString()) + " "); tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + _FcEnt.ToString()); tw.WriteLine(Constants.PROCESS + singleFeature.process); } break; case "A": // InizioArco flagArco = true; break; } } } // Verifico se riferimento definito private bool VerifyReference( Feature singleFeature) { bool bToEmit = false ; for ( int i = 1 ; i <= 9 ; ++ i) { string singleParameter = singleFeature.processReference[i-1].Trim() ; if ( ! singleParameter.Equals( "0")) { bToEmit = true ; break ; } } return bToEmit ; } // Se definito, scrittura del riferimento private void WriteReference( Feature singleFeature, StreamWriter tw) { // Se non definito esco if ( ! VerifyReference( singleFeature)) return ; // Eseguo emissione tw.Write( Constants.REFERENCE_PLANE) ; string OX = singleFeature.processReference[0].Trim() ; tw.Write( "OX:" + MultAndConvertTo8( OX) + " ") ; string OY = singleFeature.processReference[1].Trim() ; tw.Write( "OY:" + MultAndConvertTo8( OY) + " ") ; string OZ = singleFeature.processReference[2].Trim() ; tw.Write( "OZ:" + MultAndConvertTo8( OZ) + " ") ; string XX = singleFeature.processReference[3].Trim() ; tw.Write( "XX:" + MultAndConvertTo8( XX) + " ") ; string XY = singleFeature.processReference[4].Trim() ; tw.Write( "XY:" + MultAndConvertTo8( XY) + " ") ; string XZ = singleFeature.processReference[5].Trim() ; tw.Write( "XZ:" + MultAndConvertTo8( XZ) + " ") ; string YX = singleFeature.processReference[6].Trim() ; tw.Write( "YX:" + MultAndConvertTo8( YX) + " ") ; string YY = singleFeature.processReference[7].Trim() ; tw.Write( "YY:" + MultAndConvertTo8( YY) + " ") ; string YZ = singleFeature.processReference[8].Trim() ; tw.Write( "YZ:" + MultAndConvertTo8( YZ)) ; tw.WriteLine( "") ; } // Il seguente metodo prende il valore di un Process Parameter, lo moltiplica per 10^scaleUnit // e lo converte in una stringa di 8 caratteri (i caratteri mancanti sono degli 0) private string MultAndConvertTo8( string processParameter) { string rp = processParameter.Replace( ",", ".") ; double sp = Convert.ToDouble( rp, CultureInfo.InvariantCulture) * Math.Pow( 10, Constants.scaleUnit) ; int intSp = Convert.ToInt32( sp) ; string s8 = intSp.ToString( "D8") ; return s8 ; } private string MultAndConvertTo8( double dVal) { double sp = dVal * Math.Pow( 10, Constants.scaleUnit) ; int intSp = Convert.ToInt32( sp) ; string s8 = intSp.ToString( "D8") ; return s8 ; } // Le 2 seguenti struct dichiarano i campi necessari alla costruzione di una Part e di una Feature public struct Part { public string singleMemberNumber ; public string count ; public string length ; public string height ; public string width ; public string Material ; public string Type ; public List features ; public double x ; public double y ; public double z ; public double inverted ; public double rotated ; public int elementId ; public int cutId ; } public struct Feature { public string taskId ; public string processKey ; public string designation ; public List processParameters ; public List processReference ; public string processIdent ; public string process ; public string sag1 ; public string sag2 ; public string text ; public string processId ; } } }