public void convert() { convertStatus = "Подготовка начальных данных"; observer.updateProgressStatus(); progress = 0; observer.updateProgress(); Number[] numbers = getRandNumbers(); Array.Sort(numbers, NumberComparator.compareNumber); progress = 10; double progressStep = (100 - progress) / numberOfPoints; observer.updateProgress(); StreamReader file = new StreamReader(path + "\\" + sourceName); StreamWriter outFile = new StreamWriter(outputPath); string line; string outLine = null; int xStep = 1; int yStep = 1; int zStep = 1; int commonIndex = 1; int index = 0; int numberIndex = 0; string[] strNum; while (((line = file.ReadLine()) != null) && (isConverting())) { if (line.Contains("SPACING")) { line = line.Substring(line.IndexOf("SPACING") + 8); strNum = line.Split(' '); try { xStep = Int32.Parse(strNum[0]); yStep = Int32.Parse(strNum[1]); zStep = Int32.Parse(strNum[2]); } catch (Exception e) { } } else if (StringsUtils.numberString(line)) { if (commonIndex % 100 == 0) { convertStatus = "Анализ строки номер " + commonIndex; observer.updateProgressStatus(); } strNum = line.Split(new char[] { ' ', '\t' }); for (int i = 0; i < strNum.Length / 3; i++) { if (numberIndex < numberOfPoints) { if (numbers[numberIndex].number == index) { outLine = StringsUtils.generateCSVString(numbers[numberIndex], strNum[i], strNum[i + 1], strNum[i + 2]); outFile.WriteLine(outLine); numberIndex++; progress += progressStep; observer.updateProgress(); } index++; } } } commonIndex++; } convertStatus = "Завершение работы"; observer.updateProgressStatus(); file.Close(); outFile.Close(); if (isConverting()) { progress = 100; observer.updateProgress(); convertStatus = SUCCESS; converting = false; observer.updateProgressStatus(); } else { convertStatus = "Конвертация отменена"; observer.updateProgressStatus(); } observer.updateButtonState(); }
public void rectangleConvert() { convertStatus = "Подготовка начальных данных"; observer.updateProgressStatus(); progress = 0; observer.updateProgress(); int remainX = (((targetFieldSizeX - 1) % targetFieldOffsetX) == 0) ? 0 : 1; int remainY = (((targetFieldSizeY - 1) % targetFieldOffsetY) == 0) ? 0 : 1; int remainZ = (((targetFieldSizeZ - 1) % targetFieldOffsetZ) == 0) ? 0 : 1; int numberOfXPoints = (((targetFieldSizeX - 1) / targetFieldOffsetX) > 0) ? (((targetFieldSizeX - 1) / targetFieldOffsetX) + 1 + remainX) : 2; int numberOfYPoints = (((targetFieldSizeY - 1) / targetFieldOffsetY) > 0) ? (((targetFieldSizeY - 1) / targetFieldOffsetY) + 1 + remainY) : 2; int numberOfZPoints = (((targetFieldSizeZ - 1) / targetFieldOffsetZ) > 0) ? (((targetFieldSizeZ - 1) / targetFieldOffsetZ) + 1 + remainZ) : 2; int numberOfTargetPoints = numberOfXPoints * numberOfYPoints * numberOfZPoints; double progressStep = (100.0) / numberOfTargetPoints; StreamReader file = new StreamReader(path + "\\" + sourceName); StreamWriter outFile = new StreamWriter(outputPath); string line; string outLine = null; int xStep = 1; int yStep = 1; int zStep = 1; int commonIndex = 1; int xIndex = 0; int yIndex = 0; int zIndex = 0; int numberIndex = 0; string[] strNum; while (((line = file.ReadLine()) != null) && (isConverting())) { if (line.Contains("SPACING")) { line = line.Substring(line.IndexOf("SPACING") + 8); strNum = line.Split(' '); try { xStep = Int32.Parse(strNum[0]); yStep = Int32.Parse(strNum[1]); zStep = Int32.Parse(strNum[2]); } catch (Exception e) { } } else if (StringsUtils.numberString(line)) { if (commonIndex % 100 == 0) { convertStatus = "Анализ строки номер " + commonIndex; observer.updateProgressStatus(); } strNum = line.Split(new char[] { ' ', '\t' }); for (int i = 0; i < strNum.Length / 3; i++) { if ((((xIndex >= targetFieldBeginX) && (xIndex < (targetFieldSizeX + targetFieldBeginX)) && ((xIndex - targetFieldBeginX) % targetFieldOffsetX == 0)) || (xIndex == (targetFieldSizeX + targetFieldBeginX - 1))) && (((yIndex >= targetFieldBeginY) && (yIndex < (targetFieldSizeY + targetFieldBeginY)) && ((yIndex - targetFieldBeginY) % targetFieldOffsetY == 0)) || (yIndex == (targetFieldSizeY + targetFieldBeginY - 1))) && (((zIndex >= targetFieldBeginZ) && (zIndex < (targetFieldSizeZ + targetFieldBeginZ)) && ((zIndex - targetFieldBeginZ) % targetFieldOffsetZ == 0)) || (zIndex == (targetFieldSizeZ + targetFieldBeginZ - 1)))) { Number number = new Number(); number.x = xIndex; number.y = yIndex; number.z = zIndex; outLine = StringsUtils.generateCSVString(number, strNum[i * 3], strNum[i * 3 + 1], strNum[i * 3 + 2]); outFile.WriteLine(outLine); progress += progressStep; observer.updateProgress(); } xIndex++; if (xIndex >= sourceFieldSizeX) { xIndex = 0; yIndex++; if (yIndex >= sourceFieldSizeY) { yIndex = 0; zIndex++; } } } } commonIndex++; } convertStatus = "Завершение работы"; observer.updateProgressStatus(); file.Close(); outFile.Close(); if (isConverting()) { progress = 100; observer.updateProgress(); convertStatus = "Конвертация успешно завершена"; converting = false; observer.updateProgressStatus(); } else { convertStatus = "Конвертация отменена"; observer.updateProgressStatus(); } observer.updateButtonState(); }