コード例 #1
0
ファイル: 25industrial.cs プロジェクト: zxs1102/industrial
    // Procedures
    // External procedures
    // Chapter: Graphics / Text
    // Short Description: This procedure writes a text message.
    public void disp_message(object hv_WindowHandle, object hv_String, object hv_CoordSystem,
                             object hv_Row, object hv_Column, object hv_Color, object hv_Box)
    {
        HOperatorSetX    Op    = new HOperatorSetX();
        HTupleX          Tuple = new HTupleX();
        HDevWindowStackX COMExpWinHandleStack = new HDevWindowStackX();
        HSystemX         sys = new HSystemX();

        // Local control variables

        object hv_Red, hv_Green, hv_Blue, hv_Row1Part;
        object hv_Column1Part, hv_Row2Part, hv_Column2Part, hv_RowWin;
        object hv_ColumnWin, hv_WidthWin, hv_HeightWin, hv_MaxAscent;
        object hv_MaxDescent, hv_MaxWidth, hv_MaxHeight, hv_R1 = null;
        object hv_C1 = null, hv_FactorRow = null, hv_FactorColumn = null;
        object hv_Width = null, hv_Index = null, hv_Ascent = null, hv_Descent = null;
        object hv_W = null, hv_H = null, hv_FrameHeight = null, hv_FrameWidth = null;
        object hv_R2 = null, hv_C2 = null, hv_DrawMode = null, hv_Exception = null;
        object hv_CurrentColor = null;

        // Initialize local and output iconic variables

        //This procedure displays text in a graphics window.
        //
        //Input parameters:
        //WindowHandle: The WindowHandle of the graphics window, where
        //   the message should be displayed
        //String: A tuple of strings containing the text message to be displayed
        //CoordSystem: If set to 'window', the text position is given
        //   with respect to the window coordinate system.
        //   If set to 'image', image coordinates are used.
        //   (This may be useful in zoomed images.)
        //Row: The row coordinate of the desired text position
        //   If set to -1, a default value of 12 is used.
        //Column: The column coordinate of the desired text position
        //   If set to -1, a default value of 12 is used.
        //Color: defines the color of the text as string.
        //   If set to [], '' or 'auto' the currently set color is used.
        //   If a tuple of strings is passed, the colors are used cyclically
        //   for each new textline.
        //Box: If set to 'true', the text is written within a white box.
        //
        //prepare window
        Op.GetRgb(hv_WindowHandle, out hv_Red, out hv_Green, out hv_Blue);
        Op.GetPart(hv_WindowHandle, out hv_Row1Part, out hv_Column1Part, out hv_Row2Part,
                   out hv_Column2Part);
        Op.GetWindowExtents(hv_WindowHandle, out hv_RowWin, out hv_ColumnWin, out hv_WidthWin,
                            out hv_HeightWin);
        Op.SetPart(hv_WindowHandle, 0, 0, Tuple.TupleSub(hv_HeightWin, 1), Tuple.TupleSub(
                       hv_WidthWin, 1));
        //
        //default settings
        if (Convert.ToInt32(Tuple.TupleEqual(hv_Row, -1)) != 0)
        {
            hv_Row = 12;
        }
        if (Convert.ToInt32(Tuple.TupleEqual(hv_Column, -1)) != 0)
        {
            hv_Column = 12;
        }
        if (Convert.ToInt32(Tuple.TupleEqual(hv_Color, null)) != 0)
        {
            hv_Color = "";
        }
        //
        hv_String = Tuple.TupleSplit(Tuple.TupleAdd(Tuple.TupleAdd("", hv_String), ""),
                                     "\n");
        //
        //Estimate extentions of text depending on font size.
        Op.GetFontExtents(hv_WindowHandle, out hv_MaxAscent, out hv_MaxDescent, out hv_MaxWidth,
                          out hv_MaxHeight);
        if (Convert.ToInt32(Tuple.TupleEqual(hv_CoordSystem, "window")) != 0)
        {
            hv_R1 = hv_Row;
            hv_C1 = hv_Column;
        }
        else
        {
            //transform image to window coordinates
            hv_FactorRow = Tuple.TupleDiv(Tuple.TupleMult(1.0, hv_HeightWin), Tuple.TupleAdd(
                                              Tuple.TupleSub(hv_Row2Part, hv_Row1Part), 1));
            hv_FactorColumn = Tuple.TupleDiv(Tuple.TupleMult(1.0, hv_WidthWin), Tuple.TupleAdd(
                                                 Tuple.TupleSub(hv_Column2Part, hv_Column1Part), 1));
            hv_R1 = Tuple.TupleMult(Tuple.TupleAdd(Tuple.TupleSub(hv_Row, hv_Row1Part), 0.5),
                                    hv_FactorRow);
            hv_C1 = Tuple.TupleMult(Tuple.TupleAdd(Tuple.TupleSub(hv_Column, hv_Column1Part),
                                                   0.5), hv_FactorColumn);
        }
        //
        //display text box depending on text size
        if (Convert.ToInt32(Tuple.TupleEqual(hv_Box, "true")) != 0)
        {
            //calculate box extents
            hv_String = Tuple.TupleAdd(Tuple.TupleAdd(" ", hv_String), " ");
            hv_Width  = null;
            for (hv_Index = 0; Convert.ToInt32(hv_Index) <= Convert.ToInt32(Tuple.TupleSub(
                                                                                Tuple.TupleLength(hv_String), 1)); hv_Index = Convert.ToInt32(hv_Index) + 1)
            {
                Op.GetStringExtents(hv_WindowHandle, Tuple.TupleSelect(hv_String, hv_Index),
                                    out hv_Ascent, out hv_Descent, out hv_W, out hv_H);
                hv_Width = Tuple.TupleConcat(hv_Width, hv_W);
            }
            hv_FrameHeight = Tuple.TupleMult(hv_MaxHeight, Tuple.TupleLength(hv_String));
            hv_FrameWidth  = Tuple.TupleMax(Tuple.TupleConcat(0, hv_Width));
            hv_R2          = Tuple.TupleAdd(hv_R1, hv_FrameHeight);
            hv_C2          = Tuple.TupleAdd(hv_C1, hv_FrameWidth);
            //display rectangles
            Op.GetDraw(hv_WindowHandle, out hv_DrawMode);
            Op.SetDraw(hv_WindowHandle, "fill");
            Op.SetColor(hv_WindowHandle, "light gray");
            Op.DispRectangle1(hv_WindowHandle, Tuple.TupleAdd(hv_R1, 3), Tuple.TupleAdd(
                                  hv_C1, 3), Tuple.TupleAdd(hv_R2, 3), Tuple.TupleAdd(hv_C2, 3));
            Op.SetColor(hv_WindowHandle, "white");
            Op.DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
            Op.SetDraw(hv_WindowHandle, hv_DrawMode);
        }
        else if (Convert.ToInt32(Tuple.TupleNotEqual(hv_Box, "false")) != 0)
        {
            hv_Exception = "Wrong value of control parameter Box";
            throw new HException(hv_Exception);
        }
        //Write text.
        for (hv_Index = 0; Convert.ToInt32(hv_Index) <= Convert.ToInt32(Tuple.TupleSub(Tuple.TupleLength(
                                                                                           hv_String), 1)); hv_Index = Convert.ToInt32(hv_Index) + 1)
        {
            hv_CurrentColor = Tuple.TupleSelect(hv_Color, Tuple.TupleMod(hv_Index, Tuple.TupleLength(
                                                                             hv_Color)));
            if (Convert.ToInt32(Tuple.TupleAnd(Tuple.TupleNotEqual(hv_CurrentColor, ""),
                                               Tuple.TupleNotEqual(hv_CurrentColor, "auto"))) != 0)
            {
                Op.SetColor(hv_WindowHandle, hv_CurrentColor);
            }
            else
            {
                Op.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
            }
            hv_Row = Tuple.TupleAdd(hv_R1, Tuple.TupleMult(hv_MaxHeight, hv_Index));
            Op.SetTposition(hv_WindowHandle, hv_Row, hv_C1);
            Op.WriteString(hv_WindowHandle, Tuple.TupleSelect(hv_String, hv_Index));
        }
        //reset changed window settings
        Op.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
        Op.SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part, hv_Column2Part);

        return;
    }