// Main procedure private void action() { HOperatorSetX Op = new HOperatorSetX(); HTupleX Tuple = new HTupleX(); HDevWindowStackX COMExpWinHandleStack = new HDevWindowStackX(); // Local iconic variables HUntypedObjectX ho_Image = null, ho_SymbolRegions = null; // Local control variables object hv_BarCodeHandle, hv_WindowHandle, hv_I; object hv_Width = null, hv_Height = null, hv_DecodedDataStrings = null; object hv_LastChar = null; // Initialize local and output iconic variables Op.GenEmptyObj(out ho_Image); Op.GenEmptyObj(out ho_SymbolRegions); //Read bar codes of type 2/5 Industrial // Op.CreateBarCodeModel(null, null, out hv_BarCodeHandle); if (COMExpWinHandleStack.IsOpen() != 0) { Op.CloseWindow(COMExpWinHandleStack.Pop()); } Op.SetWindowAttr("background_color", "black"); Op.OpenWindow(0, 0, 120, 300, 0, "", "", out hv_WindowHandle); COMExpWinHandleStack.Push(hv_WindowHandle); set_display_font(hv_WindowHandle, 14, "mono", "true", "false"); if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetDraw(COMExpWinHandleStack.GetActive(), "margin"); } if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetLineWidth(COMExpWinHandleStack.GetActive(), 3); } for (hv_I = 1; Convert.ToInt32(hv_I) <= 4; hv_I = Convert.ToInt32(hv_I) + 1) { Marshal.ReleaseComObject(ho_Image); Op.ReadImage(out ho_Image, Tuple.TupleAdd("barcode/25industrial/25industrial0", hv_I)); Op.GetImageSize(ho_Image, out hv_Width, out hv_Height); if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetWindowExtents(COMExpWinHandleStack.GetActive(), 0, 0, Tuple.TupleSub( hv_Width, 1), Tuple.TupleSub(hv_Height, 1)); } if (COMExpWinHandleStack.IsOpen() != 0) { Op.DispObj(ho_Image, COMExpWinHandleStack.GetActive()); } if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetColor(COMExpWinHandleStack.GetActive(), "green"); } //Read bar code, the resulting string includes the check character Op.SetBarCodeParam(hv_BarCodeHandle, "check_char", "absent"); Marshal.ReleaseComObject(ho_SymbolRegions); Op.FindBarCode(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, "2/5 Industrial", out hv_DecodedDataStrings); disp_message(hv_WindowHandle, hv_DecodedDataStrings, "window", 12, 12, "black", "false"); hv_LastChar = Tuple.TupleSub(Tuple.TupleStrlen(hv_DecodedDataStrings), 1); disp_message(hv_WindowHandle, Tuple.TupleAdd(Tuple.TupleSum(Tuple.TupleGenConst( hv_LastChar, " ")), Tuple.TupleStrBitSelect(hv_DecodedDataStrings, hv_LastChar)), "window", 12, 12, "forest green", "false"); HDevelopStop(); //Read bar code using the check character to check the result, i.e., //the check character does not belong to the returned string anymore. //If the check character is not correct, the bar code reading fails if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetColor(COMExpWinHandleStack.GetActive(), "green"); } Op.SetBarCodeParam(hv_BarCodeHandle, "check_char", "present"); Marshal.ReleaseComObject(ho_SymbolRegions); Op.FindBarCode(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, "2/5 Industrial", out hv_DecodedDataStrings); disp_message(hv_WindowHandle, hv_DecodedDataStrings, "window", 36, 12, "black", "false"); if (COMExpWinHandleStack.IsOpen() != 0) { Op.SetColor(COMExpWinHandleStack.GetActive(), "magenta"); } if (Convert.ToInt32(Tuple.TupleLess(hv_I, 4)) != 0) { HDevelopStop(); } } Op.ClearBarCodeModel(hv_BarCodeHandle); Marshal.ReleaseComObject(ho_Image); Marshal.ReleaseComObject(ho_SymbolRegions); }
// 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; }