private void InitialiseFile() { _guids = new Dictionary <string, int>(); _ifcLines = new Dictionary <int, string>(); _ifcContents = new Dictionary <int, string>(); _exportList = new List <int>(); _ifcType = new Dictionary <int, string>(); _relVoids = new List <int>(); _relProps = new List <int>(); _relAggregates = new List <int>(); _ifcelements = new List <int>(); _ifcSites = new List <int>(); _ownerhistoryEntityLabel = -1; _projectEntityLabel = -1; _mainPlacement = -1; _header = ""; _footer = ""; var mode = SectionMode.Header; var fp = new FileTextParser(TxtInputFile.Text); string readLine; var requiredLines = new List <int>(); var lineBuffer = ""; var re = new Regex( "#(\\d+)" + // integer index " *" + // optional spaces "=" + // = " *" + // optional spaces "([^ (]*)" + // class information type (anything but an open bracket as many times) " *" + // optional spaces "\\(" + // the open bracket (escaped) "(.*)" + // anything repeated "\\) *;" // the closing bracket escaped and the semicolon ); var reGuid = new Regex(@"^ *'([^']*)' *,", RegexOptions.Compiled); var reMainPlacement = new Regex(@"IFCLOCALPLACEMENT[ \t\r\n]*\(\$", RegexOptions.Compiled); while ((readLine = fp.NextLine()) != null) { if (readLine.ToLowerInvariant().Trim() == "data;") { _header += readLine + "\r\n"; mode = SectionMode.Data; } else if (mode == SectionMode.Data && readLine.ToLowerInvariant().Trim() == "endsec;") { _footer += readLine + "\r\n"; mode = SectionMode.Footer; } else if (mode == SectionMode.Data) { lineBuffer += readLine; var m = re.Match(lineBuffer); if (!m.Success) { continue; } var iEntityLabel = Convert.ToInt32(m.Groups[1].ToString()); var type = m.Groups[2].ToString().ToUpperInvariant(); var content = m.Groups[3].Value; _ifcLines.Add(iEntityLabel, lineBuffer); _ifcContents.Add(iEntityLabel, content); _ifcType.Add(iEntityLabel, type); if (type == "IFCRELVOIDSELEMENT") { _relVoids.Add(iEntityLabel); } else if (type == "IFCRELDEFINESBYPROPERTIES") { _relProps.Add(iEntityLabel); } else if (type == "IFCRELAGGREGATES") { _relAggregates.Add(iEntityLabel); } var mGuid = reGuid.Match(content); if (mGuid.Success) { var val = mGuid.Groups[1].Value; if (!_guids.ContainsKey(val)) { _guids.Add(val, iEntityLabel); } } if (type == "IFCPROJECT") { requiredLines.Add(iEntityLabel); _projectEntityLabel = iEntityLabel; } else if (type == "IFCSITES") { _ifcSites.Add(iEntityLabel); } else if (type == "IFCOWNERHISTORY") { _ownerhistoryEntityLabel = iEntityLabel; } else if (type == "IFCLOCALPLACEMENT" && _mainPlacement == -1) { if (reMainPlacement.IsMatch(lineBuffer)) { _mainPlacement = iEntityLabel; } } lineBuffer = ""; } else { if (mode == SectionMode.Header) { _header += readLine + "\r\n"; } else { _footer += readLine + "\r\n"; } } } fp.Close(); fp.Dispose(); GCommands.IsEnabled = true; CmdSave.IsEnabled = true; foreach (var i in requiredLines) { RecursiveAdd(i); } UpdateExportList(); }
private void cmdInit_Click(object sender, RoutedEventArgs e) { _ifcLines = new Dictionary <int, string>(); _ifcContents = new Dictionary <int, string>(); _elementsToExport = new List <int>(); _ifcType = new Dictionary <int, string>(); _header = ""; _footer = ""; FileTextParser fp = new FileTextParser(TxtInputFile.Text); string readLine; bool foundAnyLine = false; List <int> requiredLines = new List <int>(); //Regex re = new Regex( // "#(\\d+)" + // integer index // " *" + // optional spaces // "=" + // = // " *" + // optional spaces // "([^(]*)" + // class information type (anything but an open bracket as many times) // "\\(" + // the open bracket (escaped) // "(.*)" + // anything repeated // "\\);" // the closing bracket escaped and the semicolon // ); Regex re = new Regex( "#(\\d+)" + // integer index " *" + // optional spaces "=" + // = " *" + // optional spaces "([^ (]*)" + // class information type (anything but an open bracket as many times) " *" + // optional spaces "\\(" + // the open bracket (escaped) "(.*)" + // anything repeated "\\);" // the closing bracket escaped and the semicolon ); while ((readLine = fp.NextLine()) != null) { Match m = re.Match(readLine); if (m.Success) { foundAnyLine = true; int iId = Convert.ToInt32(m.Groups[1].ToString()); string type = m.Groups[2].ToString(); _ifcLines.Add(iId, readLine); _ifcContents.Add(iId, m.Groups[3].ToString()); _ifcType.Add(iId, type); if ( type == "IFCPROJECT" ) { requiredLines.Add(iId); } } else { if (foundAnyLine == false) { _header += readLine + "\r\n"; } else { _footer += readLine + "\r\n"; } } } fp.Close(); fp.Dispose(); GCommands.IsEnabled = true; if (true) { foreach (int i in requiredLines) { RecursiveAdd(i); } } UpdateStatusCount(); }
private void InitialiseFile() { _guids = new Dictionary <string, int>(); _ifcLines = new Dictionary <int, string>(); _ifcContents = new Dictionary <int, string>(); _elementsToExport = new List <int>(); _ifcType = new Dictionary <int, string>(); _header = ""; _footer = ""; var mode = SectionMode.Header; var fp = new FileTextParser(TxtInputFile.Text); string readLine; var requiredLines = new List <int>(); var lineBuffer = ""; var re = new Regex( "#(\\d+)" + // integer index " *" + // optional spaces "=" + // = " *" + // optional spaces "([^ (]*)" + // class information type (anything but an open bracket as many times) " *" + // optional spaces "\\(" + // the open bracket (escaped) "(.*)" + // anything repeated "\\) *;" // the closing bracket escaped and the semicolon ); var reGuid = new Regex(@"^ *'([^']*)' *,"); while ((readLine = fp.NextLine()) != null) { if (readLine.ToLowerInvariant().Trim() == "data;") { _header += readLine + "\r\n"; mode = SectionMode.Data; } else if (mode == SectionMode.Data && readLine.ToLowerInvariant().Trim() == "endsec;") { _footer += readLine + "\r\n"; mode = SectionMode.Footer; } else if (mode == SectionMode.Data) { lineBuffer += readLine; var m = re.Match(lineBuffer); if (!m.Success) { continue; } var iId = Convert.ToInt32(m.Groups[1].ToString()); var type = m.Groups[2].ToString(); var content = m.Groups[3].Value; _ifcLines.Add(iId, lineBuffer); _ifcContents.Add(iId, content); _ifcType.Add(iId, type); var mGuid = reGuid.Match(content); if (mGuid.Success) { var val = mGuid.Groups[1].Value; if (!_guids.ContainsKey(val)) { _guids.Add(val, iId); } } if (type == "IFCPROJECT") { requiredLines.Add(iId); } lineBuffer = ""; } else { if (mode == SectionMode.Header) { _header += readLine + "\r\n"; } else { _footer += readLine + "\r\n"; } } } fp.Close(); fp.Dispose(); GCommands.IsEnabled = true; CmdSave.IsEnabled = true; foreach (var i in requiredLines) { RecursiveAdd(i); } UpdateExportList(); }