コード例 #1
0
        private void maptest(IKarnoughMap map)
        {
            Assert.AreEqual("value1", map.valueNames[0]);
            Assert.AreEqual("value2", map.valueNames[1]);
            Assert.AreEqual("value3", map.valueNames[2]);

            Assert.AreEqual(TruthValue.True, map.getMapPoint(0, 0).values);
            Assert.AreEqual(TruthValue.True, map.getMapPoint(1, 0).values);
            Assert.AreEqual(TruthValue.True, map.getMapPoint(0, 1).values);
            Assert.AreEqual(TruthValue.True, map.getMapPoint(1, 1).values);
            Assert.AreEqual(TruthValue.False, map.getMapPoint(2, 0).values);
            Assert.AreEqual(TruthValue.False, map.getMapPoint(3, 0).values);
            Assert.AreEqual(TruthValue.False, map.getMapPoint(2, 1).values);
            Assert.AreEqual(TruthValue.False, map.getMapPoint(3, 1).values);

            Assert.AreEqual((byte)1, map.getMapPoint(0, 0).blockValue);
            Assert.AreEqual((byte)1, map.getMapPoint(1, 0).blockValue);
            Assert.AreEqual((byte)1, map.getMapPoint(0, 1).blockValue);
            Assert.AreEqual((byte)1, map.getMapPoint(1, 1).blockValue);
        }
コード例 #2
0
        //ここからカルノー図描画メソッド

        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();
        }