//ここからカルノー図描画メソッド public void Value2Map(IKarnoughMap map) { int valueCount = map.valueNames.Count(); //int valueCount = 3; render.BeginDraw(); render.Clear(background); int margin = 10; int ColumHeight = 30; int RowWidth = 100; //外枠 render.DrawLine(new RawVector2(margin, margin), new RawVector2(margin, height - margin), LineColor); render.DrawLine(new RawVector2(margin, margin), new RawVector2(width - margin, margin), LineColor); render.DrawLine(new RawVector2(width - margin, height - margin), new RawVector2(width - margin, margin), LineColor); render.DrawLine(new RawVector2(width - margin, height - margin), new RawVector2(margin, height - margin), LineColor); render.DrawLine(new RawVector2(margin, margin + (ColumHeight * 2)), new RawVector2(width - margin, margin + (ColumHeight * 2)), LineColor); render.DrawLine(new RawVector2(margin + (RowWidth * 2), margin), new RawVector2(margin + (RowWidth * 2), height - margin), LineColor); render.DrawLine(new RawVector2(margin + (RowWidth * 2), margin + ColumHeight), new RawVector2(width - margin, margin + ColumHeight), LineColor); render.DrawLine(new RawVector2(margin + RowWidth, margin + (ColumHeight * 2)), new RawVector2(margin + RowWidth, height - margin), LineColor); //行と列の数の設定 int columCount = 2; int rowCount = 2; for (int i = 3; i <= valueCount; i++) { if (i % 2 == 1) { columCount = columCount * 2; } else { rowCount = rowCount * 2; } } //セルの大きさ int valueWidth = ((width - margin) - (margin + (RowWidth * 2))) / columCount; int valueHeight = ((height - margin) - (margin + (ColumHeight * 2))) / rowCount; //縦の罫線 for (int i = 1; i < columCount; i++) { //int valueWidth = ((width - margin) - (margin + (RowWidth * 2)))/columCount; int x = margin + (RowWidth * 2) + (valueWidth * i); int y_start = margin + ColumHeight; int y_end = height - margin; render.DrawLine(new RawVector2(x, y_start), new RawVector2(x, y_end), LineColor); } //横の罫線 for (int i = 1; i < rowCount; i++) { //int valueHeight = ((height - margin) - (margin + (ColumHeight * 2)))/rowCount; int y = margin + (ColumHeight * 2) + (valueHeight * i); int x_start = margin + RowWidth; int x_end = width - margin; render.DrawLine(new RawVector2(x_start, y), new RawVector2(x_end, y), LineColor); } //文字の描画 var fontFactory = new SharpDX.DirectWrite.Factory(); var textFormat = new TextFormat(fontFactory, "メイリオ", 24.0f); textFormat.TextAlignment = TextAlignment.Center; var textBrush = new SharpDX.Direct2D1.SolidColorBrush(render, new RawColor4(1f, 1f, 1f, 1f)); //列のインデックス string[] columStr = valueStr(columCount); for (int i = 0; i < columCount; i++) { int x_shift = margin + (RowWidth * 2); int x_start = x_shift + (valueWidth * i); int x_end = x_shift + (valueWidth * (i + 1)); int y_start = margin + ColumHeight; int y_end = margin + (ColumHeight * 2); TextFormat textTmpFormat; if (columCount >= 8) { textTmpFormat = new TextFormat(fontFactory, "メイリオ", 20.0f); textTmpFormat.TextAlignment = TextAlignment.Center; } else { textTmpFormat = textFormat; } render.DrawText(columStr[i], textTmpFormat, new RawRectangleF(x_start, y_start, x_end, y_end), textBrush, DrawTextOptions.None); } //行のインデックス string[] rowStr = valueStr(rowCount); for (int i = 0; i < rowCount; i++) { int x_start = margin + RowWidth; int x_end = x_start + RowWidth; int y_shift = margin + (ColumHeight * 2); int y_start = y_shift + (valueHeight * i) + (valueHeight / 2 - 10); int y_end = y_start + (valueHeight * (i + 1)); render.DrawText(rowStr[i], textFormat, new RawRectangleF(x_start, y_start, x_end, y_end), textBrush, DrawTextOptions.None); } //mapを描画 for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columCount; j++) { int xStartCell = margin + (RowWidth * 2) + (valueWidth * j); int yStartCell = margin + (ColumHeight * 2) + (valueHeight * i) + (valueHeight / 2 - 10); int xEndCell = xStartCell + valueWidth; int yEndCell = yStartCell + valueHeight; TruthValue v = map.getMapPoint(j, i).values; string s = ""; switch (v) { case TruthValue.False: s = "0"; break; case TruthValue.True: s = "1"; break; case TruthValue.Null: s = "d"; break; } var MaptextFormat = new TextFormat(fontFactory, "メイリオ", 30.0f); var mapBrush = indexFontColor(0); MaptextFormat.TextAlignment = TextAlignment.Center; render.DrawText(s, MaptextFormat, new RawRectangleF(xStartCell, yStartCell, xEndCell, yEndCell), mapBrush, DrawTextOptions.None); } } //囲む(blockid=10まで) for (byte i = 1; i < 10; i++) { List <IAxisKarnoughComponent> com = map.getBlockIDList(i); if (com.Count == 0) { break; } int maxX = 0; int maxY = 0; int minX = 16; int minY = 16; foreach (IAxisKarnoughComponent c in com) { if (maxX < c.x) { maxX = c.x; } if (minX > c.x) { minX = c.x; } if (maxY < c.y) { maxY = c.y; } if (minY > c.y) { minY = c.y; } } var color = indexFontColor(i); int rectMargin = 10; int startX = (margin + (RowWidth * 2) + (valueWidth * minX)) + rectMargin; int endX = (margin + (RowWidth * 2) + (valueWidth * (maxX + 1))) - rectMargin; int startY = (margin + (ColumHeight * 2) + (valueHeight * minY)) + rectMargin; int endY = (margin + (ColumHeight * 2) + (valueHeight * (maxY + 1))) - rectMargin; render.DrawRectangle(new RawRectangleF(startX, startY, endX, endY), color); } //列の変数名 int x_label_Xstart = margin + (RowWidth * 2); int x_label_Xend = width - margin; int x_label_Ystart = margin; int x_label_Yend = margin + ColumHeight; render.DrawText(getlabel(map, valueCount, true), textFormat, new RawRectangleF(x_label_Xstart, x_label_Ystart, x_label_Xend, x_label_Yend), textBrush, DrawTextOptions.None); //行の変数名 int y_label_Xstart = margin; int y_label_Xend = margin + RowWidth; int y_label_Ystart = margin + (ColumHeight * 2) + ((valueHeight * rowCount) / 2) - (10 * rowCount / 4); int y_label_Yend = height - margin; render.DrawText(getlabel(map, valueCount, false), textFormat, new RawRectangleF(y_label_Xstart, y_label_Ystart, y_label_Xend, y_label_Yend), textBrush, DrawTextOptions.None); render.EndDraw(); }
public IKarnoughLogic getExp(IKarnoughMap map) { IKarnoughLogic outputVal = new KarnoughLogic(); outputVal.valueNames = map.valueNames; //List<List<bool>> valuelists = new List<List<bool>>(); //とりあえずBlockIDが10まで for (byte i = 1; i < 10; i++) { List <List <bool> > valuelists = new List <List <bool> >(); List <IAxisKarnoughComponent> com = map.getBlockIDList(i); List <TruthValue> truthval = new List <TruthValue>();; if (com.Count == 0) { break; } foreach (IAxisKarnoughComponent c in com) { List <bool> booleanLST = axisX(map.valueNames.Count(), c.x); booleanLST.AddRange(axisY(map.valueNames.Count(), c.y)); valuelists.Add(booleanLST); } for (int j = 0; j < map.valueNames.Count(); j++) { List <bool> Xlist = new List <bool>(); foreach (List <bool> lst in valuelists) { Xlist.Add(lst[j]); } bool prevLogic = Xlist[0]; TruthValue result; if (prevLogic == true) { result = TruthValue.True; } else { result = TruthValue.False; } foreach (bool b in Xlist) { if (prevLogic != b) { result = TruthValue.Null; break; } } truthval.Add(result); } outputVal.values.Add(truthval); } //未定義の部分(blockid=0) List <IAxisKarnoughComponent> nodefinedBool = map.getBlockIDList(0); foreach (IAxisKarnoughComponent c in nodefinedBool) { if (c.values == TruthValue.True) { List <bool> valList = axisX(map.valueNames.Count(), c.x); valList.AddRange(axisY(map.valueNames.Count(), c.y)); List <TruthValue> val = new List <TruthValue>(); foreach (bool b in valList) { if (b == true) { val.Add(TruthValue.True); } else { val.Add(TruthValue.False); } } outputVal.values.Add(val); } } return(outputVal); }