static void Test2() { Denisenko.Cutting.Sheet sheet = new Denisenko.Cutting.Sheet(); sheet.Height = 1225; sheet.Width = 1830; sheet.Thickness = 16; CuttingScheme scheme = new CuttingScheme(); scheme.Parameters = new ParametersCollection(); scheme.Parameters.CutOffBottom = 15; scheme.Parameters.CutOffLeft = 15; scheme.Parameters.CutOffRight = 15; scheme.Parameters.CutOffTop = 15; scheme.Parameters.CutterThickness = 5; scheme.Sheet = sheet; Section right; Section top; Section lane; lane = scheme.Cut(scheme.RootSection, 950, CutType.Vertical, out right); scheme.Cut(lane, 290, CutType.Horizontal, out top); scheme.Cut(top, 290, CutType.Horizontal, out top); lane = scheme.Cut(top, 285, CutType.Horizontal, out top); scheme.Cut(lane, 720, CutType.Vertical, out right); lane = scheme.Cut(top, 790, CutType.Vertical, out right); LC4Convertor cvtr = new LC4Convertor(); Job job = cvtr.Convert(new List <CuttingScheme>(new CuttingScheme[] { scheme })); job.Name = "job2"; job.SaveLC4("job2.lc4", true); }
public Boolean NextResult() { //m_started = true; if (m_parts.Count == 0) { throw new CannotCutDetailsException("Нельзя расположить детали, список деталей не заполнен."); } if (m_sheets.Count == 0) { throw new CannotCutDetailsException("Нельзя расположить детали, список листов не заполнен."); } CuttingScheme best_result = null; foreach (var sheet in m_sheets) { var result = Layout2d(m_parts, sheet, Parameters.CutterThickness); if (object.ReferenceEquals(best_result, null)) { best_result = result; } else { if (result.BetterThan(best_result)) { best_result = result; } } } m_result = best_result; return(!object.ReferenceEquals(best_result, null)); }
public void ConvertSectionTest() { LC4Convertor target = new LC4Convertor(); TestProject.Denisenko_Cutting_Converting_LC4ConvertorAccessor accessor = new TestProject.Denisenko_Cutting_Converting_LC4ConvertorAccessor(target); ParametersCollection parameters = new ParametersCollection(); parameters.CutterThickness = 10M; CuttingScheme scheme = new CuttingScheme(); scheme.Width = 1000M; scheme.Height = 1000M; scheme.Parameters = parameters; Section someSection = null; scheme.Cut(scheme.RootSection, 20M, CutType.Vertical, out someSection); Section prevSection = null; Section input = scheme.RootSection.NestedSections[0]; Section cut = scheme.RootSection.NestedSections[1]; LC4Section expected = new LC4Section(); expected.Size = LC4Numeric.FromNonScaled(30); expected.SectionType = LC4SectionType.Anschnitt; LC4Section actual; actual = accessor.ConvertSection(input, prevSection, cut); Assert.AreEqual <LC4Section>(expected, actual, "Denisenko.Cutting.Converting.LC4Convertor.ConvertSection did not return the expec" + "ted value."); Assert.Inconclusive("Verify the correctness of this test method."); }
unsafe public static CuttingScheme ConvertLayout(_Layout * layout, ParametersCollection parameters, Sheet sheet) { CuttingScheme result = new CuttingScheme(); result.Sheet = sheet; result.Parameters = parameters; CuttingResultBuilder builder = new CuttingResultBuilder(); builder.LoadSections(layout, result); return result; }
public void Redo() { if (m_historyCurrent < m_historyEnd) { m_historyCurrent++; m_cutting = m_history[m_historyCurrent]; SyncronizeSections(); } }
public void Undo() { if (m_historyCurrent > m_historyBegin) { m_historyCurrent--; m_cutting = m_history[m_historyCurrent]; SyncronizeSections(); } }
public void MakeUndoPoint() { m_history[m_historyCurrent] = new CuttingScheme(m_cutting); m_historyCurrent = (m_historyCurrent + 1) % MaxHistory; if (m_historyBegin == m_historyCurrent) { m_historyBegin = (m_historyBegin + 1) % MaxHistory; } m_historyEnd = m_historyCurrent; m_history[m_historyCurrent] = m_cutting; }
unsafe public static CuttingScheme ConvertLayout(_Layout *layout, ParametersCollection parameters, Sheet sheet) { CuttingScheme result = new CuttingScheme(); result.Sheet = sheet; result.Parameters = parameters; CuttingResultBuilder builder = new CuttingResultBuilder(); builder.LoadSections(layout, result); return(result); }
internal void Stub() { CuttingResultForm form = new CuttingResultForm(); List <CuttingScheme> schemes = new List <CuttingScheme>(); CuttingScheme scheme = new CuttingScheme(); scheme.Height = 1200; scheme.Width = 2100; scheme.Material = new Material(1, "ЛДСП Белая", true); scheme.Parameters = new ParametersCollection(); scheme.Parameters.CutterThickness = 4; Section remain; scheme.Cut(scheme.RootSection, 500, CutType.Vertical, out remain); Section remain2; scheme.Cut(remain, 550, CutType.Horizontal, out remain2); schemes.Add((CuttingScheme)scheme.Clone()); form.DataSource = schemes; form.MdiParent = MainForm.Instance; form.Show(); }
public void Convert(ICollection<CuttingScheme> output, StreamReader tr) { // сканирование dxf, загрузка линий и текстов int typeCode; string data; while (true) { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 0 && data == "SECTION") { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 2 && data == "ENTITIES") { break; } } } List<Line> lines = new List<Line>(); _texts = new LinkedList<Text>(); while (!tr.EndOfStream) { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 0 && data == "LINE") { Line line = new Line(); line.Read(tr); lines.Add(line); } else if (typeCode == 0 && data == "TEXT") { Text text = new Text(); text.Read(tr); _texts.AddLast(text); } } // составляем список резов, выбирая линии со стилем HIDDEN LinkedList<Line> buffer = new LinkedList<Line>(lines); _cuts = new LinkedList<Line>(); BazUtils.TakeFrom(buffer, _cuts, BazUtils.CutsPredicate); // составляем список прямоугольноков, собирая их из линий List<Line> otherLines = new List<Line>(); LinkedList<Rectangle> rects = new LinkedList<Rectangle>(); while (buffer.Count > 0) { Line line1 = buffer.First.Value; buffer.RemoveFirst(); Line line2 = BazUtils.FindContLine(line1, buffer); if (line2 == null) { otherLines.Add(line1); continue; } buffer.Remove(line2); Line line3 = BazUtils.FindContLine(line2, buffer); if (line3 == null) { otherLines.Add(line1); otherLines.Add(line2); continue; } buffer.Remove(line3); Line line4 = BazUtils.FindContLine(line2, buffer); if (line4 != null) { otherLines.Add(line1); otherLines.Add(line2); otherLines.Add(line3); continue; } buffer.Remove(line4); Rectangle rect = new Rectangle(); rect.LeftBottom.X = Math.Min(line1.P1.X, line2.P2.X); rect.LeftBottom.Y = Math.Min(line1.P1.Y, line2.P2.Y); rect.RightTop.X = Math.Max(line1.P1.X, line2.P2.X); rect.RightTop.Y = Math.Max(line1.P1.Y, line2.P2.Y); rects.AddLast(rect); } BazUtils.BubbleSort<Rectangle>(rects, Rectangle.SquareDescending); while (rects.Count > 0) { // находим прямоугольники листа и его обрезанной части Rectangle sheetRect = rects.First.Value; rects.RemoveFirst(); List<Rectangle> internals = new List<Rectangle>(); BazUtils.TakeFrom<Rectangle>(rects, internals, sheetRect.IsContains); if (internals.Count == 0) { break; } Rectangle cutoffRect = internals[0]; // определяем ширину реза и направление первого реза CutMatcher matcher = new CutMatcher(); CuttingDirection firstCut; matcher.Bounds = cutoffRect; Line match = BazUtils.Lookup(_cuts, matcher.MatchHorizontalCut); if (match == null) { match = BazUtils.Lookup(_cuts, matcher.MatchVerticalCut); _cutterThick = (cutoffRect.LeftBottom.Y - match.P1.Y) * 2; firstCut = CuttingDirection.Vertical; } else { _cutterThick = (cutoffRect.LeftBottom.X - match.P1.X) * 2; firstCut = CuttingDirection.Horizontal; } // заполняем полученные параметры раскроя ParametersCollection pars = new ParametersCollection(); pars.CutterThickness = (decimal)(_cutterThick * 10.0); pars.CutOffLeft = (decimal)((cutoffRect.LeftBottom.X - sheetRect.LeftBottom.X) * 10.0); pars.CutOffBottom = (decimal)((cutoffRect.LeftBottom.Y - sheetRect.LeftBottom.Y) * 10.0); pars.CutOffRight = (decimal)((sheetRect.RightTop.X - cutoffRect.RightTop.X) * 10.0); pars.CutOffTop = (decimal)((sheetRect.RightTop.Y - cutoffRect.RightTop.Y) * 10.0); _scheme = new CuttingScheme(); _scheme.Parameters = pars; _scheme.Sheet = new Sheet(); _scheme.Sheet.Thickness = 16; _scheme.Height = (decimal)((sheetRect.RightTop.Y - sheetRect.LeftBottom.Y) * 10.0); _scheme.Width = (decimal)((sheetRect.RightTop.X - sheetRect.LeftBottom.X) * 10.0); _scheme.Sheet.Width = _scheme.Width; _scheme.Sheet.Height = _scheme.Height; // составляем сам раскрой if (firstCut == CuttingDirection.Vertical) { CutHorizontalStrip(_scheme.RootSection, cutoffRect); } else { CutVerticalStrip(_scheme.RootSection, cutoffRect); } // получаем количество листов из строчки под раскроем List<Text> sheetInfo = new List<Text>(); TextMatcher textMatcher = new TextMatcher(); textMatcher.Bounds = sheetRect.HorizStrip(sheetRect.LeftBottom.Y - 30, sheetRect.LeftBottom.Y); BazUtils.TakeFrom<Text>(_texts, sheetInfo, textMatcher.IsInside); sheetInfo.Sort(Text.PosYAscending); string sheetsCountStr = sheetInfo[0].Value; int eqPos = sheetsCountStr.LastIndexOf('='); _scheme.Repetitions = int.Parse(sheetsCountStr.Substring(eqPos + 1, sheetsCountStr.Length - eqPos - 1)); output.Add(_scheme); } }
private void DataSource_OnChange(CuttingScheme sender) { SyncronizeSections(); }
unsafe public void LoadSections(_Layout *input, CuttingScheme output) { m_result = output; Recursive(input, output.RootSection); }
public void Convert(ICollection <CuttingScheme> output, StreamReader tr) { // сканирование dxf, загрузка линий и текстов int typeCode; string data; while (true) { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 0 && data == "SECTION") { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 2 && data == "ENTITIES") { break; } } } List <Line> lines = new List <Line>(); _texts = new LinkedList <Text>(); while (!tr.EndOfStream) { typeCode = int.Parse(tr.ReadLine()); data = tr.ReadLine(); if (typeCode == 0 && data == "LINE") { Line line = new Line(); line.Read(tr); lines.Add(line); } else if (typeCode == 0 && data == "TEXT") { Text text = new Text(); text.Read(tr); _texts.AddLast(text); } } // составляем список резов, выбирая линии со стилем HIDDEN LinkedList <Line> buffer = new LinkedList <Line>(lines); _cuts = new LinkedList <Line>(); BazUtils.TakeFrom(buffer, _cuts, BazUtils.CutsPredicate); // составляем список прямоугольноков, собирая их из линий List <Line> otherLines = new List <Line>(); LinkedList <Rectangle> rects = new LinkedList <Rectangle>(); while (buffer.Count > 0) { Line line1 = buffer.First.Value; buffer.RemoveFirst(); Line line2 = BazUtils.FindContLine(line1, buffer); if (line2 == null) { otherLines.Add(line1); continue; } buffer.Remove(line2); Line line3 = BazUtils.FindContLine(line2, buffer); if (line3 == null) { otherLines.Add(line1); otherLines.Add(line2); continue; } buffer.Remove(line3); Line line4 = BazUtils.FindContLine(line2, buffer); if (line4 != null) { otherLines.Add(line1); otherLines.Add(line2); otherLines.Add(line3); continue; } buffer.Remove(line4); Rectangle rect = new Rectangle(); rect.LeftBottom.X = Math.Min(line1.P1.X, line2.P2.X); rect.LeftBottom.Y = Math.Min(line1.P1.Y, line2.P2.Y); rect.RightTop.X = Math.Max(line1.P1.X, line2.P2.X); rect.RightTop.Y = Math.Max(line1.P1.Y, line2.P2.Y); rects.AddLast(rect); } BazUtils.BubbleSort <Rectangle>(rects, Rectangle.SquareDescending); while (rects.Count > 0) { // находим прямоугольники листа и его обрезанной части Rectangle sheetRect = rects.First.Value; rects.RemoveFirst(); List <Rectangle> internals = new List <Rectangle>(); BazUtils.TakeFrom <Rectangle>(rects, internals, sheetRect.IsContains); if (internals.Count == 0) { break; } Rectangle cutoffRect = internals[0]; // определяем ширину реза и направление первого реза CutMatcher matcher = new CutMatcher(); CuttingDirection firstCut; matcher.Bounds = cutoffRect; Line match = BazUtils.Lookup(_cuts, matcher.MatchHorizontalCut); if (match == null) { match = BazUtils.Lookup(_cuts, matcher.MatchVerticalCut); _cutterThick = (cutoffRect.LeftBottom.Y - match.P1.Y) * 2; firstCut = CuttingDirection.Vertical; } else { _cutterThick = (cutoffRect.LeftBottom.X - match.P1.X) * 2; firstCut = CuttingDirection.Horizontal; } // заполняем полученные параметры раскроя ParametersCollection pars = new ParametersCollection(); pars.CutterThickness = (decimal)(_cutterThick * 10.0); pars.CutOffLeft = (decimal)((cutoffRect.LeftBottom.X - sheetRect.LeftBottom.X) * 10.0); pars.CutOffBottom = (decimal)((cutoffRect.LeftBottom.Y - sheetRect.LeftBottom.Y) * 10.0); pars.CutOffRight = (decimal)((sheetRect.RightTop.X - cutoffRect.RightTop.X) * 10.0); pars.CutOffTop = (decimal)((sheetRect.RightTop.Y - cutoffRect.RightTop.Y) * 10.0); _scheme = new CuttingScheme(); _scheme.Parameters = pars; _scheme.Sheet = new Sheet(); _scheme.Sheet.Thickness = 16; _scheme.Height = (decimal)((sheetRect.RightTop.Y - sheetRect.LeftBottom.Y) * 10.0); _scheme.Width = (decimal)((sheetRect.RightTop.X - sheetRect.LeftBottom.X) * 10.0); _scheme.Sheet.Width = _scheme.Width; _scheme.Sheet.Height = _scheme.Height; // составляем сам раскрой if (firstCut == CuttingDirection.Vertical) { CutHorizontalStrip(_scheme.RootSection, cutoffRect); } else { CutVerticalStrip(_scheme.RootSection, cutoffRect); } // получаем количество листов из строчки под раскроем List <Text> sheetInfo = new List <Text>(); TextMatcher textMatcher = new TextMatcher(); textMatcher.Bounds = sheetRect.HorizStrip(sheetRect.LeftBottom.Y - 30, sheetRect.LeftBottom.Y); BazUtils.TakeFrom <Text>(_texts, sheetInfo, textMatcher.IsInside); sheetInfo.Sort(Text.PosYAscending); string sheetsCountStr = sheetInfo[0].Value; int eqPos = sheetsCountStr.LastIndexOf('='); _scheme.Repetitions = int.Parse(sheetsCountStr.Substring(eqPos + 1, sheetsCountStr.Length - eqPos - 1)); output.Add(_scheme); } }