#include"OtherAssist.h"
MyAssist::MyAssist()
{
}
MyAssist::~MyAssist()
{
}
// Procedures
// External procedures
// Chapter: Develop
// Short Description: Open a new graphics window that preserves the aspect ratio of the given image.
void MyAssist::dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column, HTuple hv_WidthLimit, HTuple hv_HeightLimit, HTuple * hv_WindowHandle)
{
// Local iconic variables
// Local control variables
HTuple hv_MinWidth, hv_MaxWidth, hv_MinHeight;
HTuple hv_MaxHeight, hv_ResizeFactor, hv_ImageWidth, hv_ImageHeight;
HTuple hv_TempWidth, hv_TempHeight, hv_WindowWidth, hv_WindowHeight;
//This procedure opens a new graphics window and adjusts the size
//such that it fits into the limits specified by WidthLimit
//and HeightLimit, but also maintains the correct image aspect ratio.
//
//If it is impossible to match the minimum and maximum extent requirements
//at the same time (f.e. if the image is very long but narrow),
//the maximum value gets a higher priority,
//
//Parse input tuple WidthLimit
if (0 != (HTuple((hv_WidthLimit.TupleLength()) == 0).TupleOr(hv_WidthLimit < 0)))
{
hv_MinWidth = 500;
hv_MaxWidth = 800;
}
else if (0 != ((hv_WidthLimit.TupleLength()) == 1))
{
hv_MinWidth = 0;
hv_MaxWidth = hv_WidthLimit;
}
else
{
hv_MinWidth = ((const HTuple&)hv_WidthLimit)[0];
hv_MaxWidth = ((const HTuple&)hv_WidthLimit)[1];
}
//Parse input tuple HeightLimit
if (0 != (HTuple((hv_HeightLimit.TupleLength()) == 0).TupleOr(hv_HeightLimit < 0)))
{
hv_MinHeight = 400;
hv_MaxHeight = 600;
}
else if (0 != ((hv_HeightLimit.TupleLength()) == 1))
{
hv_MinHeight = 0;
hv_MaxHeight = hv_HeightLimit;
}
else
{
hv_MinHeight = ((const HTuple&)hv_HeightLimit)[0];
hv_MaxHeight = ((const HTuple&)hv_HeightLimit)[1];
}
//
//Test, if window size has to be changed.
hv_ResizeFactor = 1;
GetImageSize(ho_Image, &hv_ImageWidth, &hv_ImageHeight);
//First, expand window to the minimum extents (if necessary).
if (0 != (HTuple(hv_MinWidth > hv_ImageWidth).TupleOr(hv_MinHeight > hv_ImageHeight)))
{
hv_ResizeFactor = (((hv_MinWidth.TupleReal()) / hv_ImageWidth).TupleConcat((hv_MinHeight.TupleReal()) / hv_ImageHeight)).TupleMax();
}
hv_TempWidth = hv_ImageWidth * hv_ResizeFactor;
hv_TempHeight = hv_ImageHeight * hv_ResizeFactor;
//Then, shrink window to maximum extents (if necessary).
if (0 != (HTuple(hv_MaxWidth < hv_TempWidth).TupleOr(hv_MaxHeight < hv_TempHeight)))
{
hv_ResizeFactor = hv_ResizeFactor * ((((hv_MaxWidth.TupleReal()) / hv_TempWidth).TupleConcat((hv_MaxHeight.TupleReal()) / hv_TempHeight)).TupleMin());
}
hv_WindowWidth = hv_ImageWidth * hv_ResizeFactor;
hv_WindowHeight = hv_ImageHeight * hv_ResizeFactor;
//Resize window
SetWindowAttr("background_color", "black");
OpenWindow(hv_Row, hv_Column, hv_WindowWidth, hv_WindowHeight, 0, "", "", &(*hv_WindowHandle));
HDevWindowStack::Push((*hv_WindowHandle));
if (HDevWindowStack::IsOpen())
SetPart(HDevWindowStack::GetActive(), 0, 0, hv_ImageHeight - 1, hv_ImageWidth - 1);
return;
}
void MyAssist::dev_update_off()
{
//This procedure sets different update settings to 'off'.
//This is useful to get the best performance and reduce overhead.
//
// dev_update_pc(...); only in hdevelop
// dev_update_var(...); only in hdevelop
// dev_update_window(...); only in hdevelop
return;
}
// Chapter: Graphics / Text
// Short Description: Set font independent of OS
void MyAssist::set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant)
{
// Local iconic variables
// Local control variables
HTuple hv_OS, hv_BufferWindowHandle, hv_Ascent;
HTuple hv_Descent, hv_Width, hv_Height, hv_Scale, hv_Exception;
HTuple hv_SubFamily, hv_Fonts, hv_SystemFonts, hv_Guess;
HTuple hv_I, hv_Index, hv_AllowedFontSizes, hv_Distances;
HTuple hv_Indices, hv_FontSelRegexp, hv_FontsCourier;
//This procedure sets the text font of the current window with
//the specified attributes.
//It is assumed that following fonts are installed on the system:
//Windows: Courier New, Arial Times New Roman
//Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
//Linux: courier, helvetica, times
//Because fonts are displayed smaller on Linux than on Windows,
//a scaling factor of 1.25 is used the get comparable results.
//For Linux, only a limited number of font sizes is supported,
//to get comparable results, it is recommended to use one of the
//following sizes: 9, 11, 14, 16, 20, 27
//(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
//
//Input parameters:
//WindowHandle: The graphics window for which the font will be set
//Size: The font size. If Size=-1, the default of 16 is used.
//Bold: If set to 'true', a bold font is used
//Slant: If set to 'true', a slanted font is used
//
GetSystem("operating_system", &hv_OS);
// dev_get_preferences(...); only in hdevelop
// dev_set_preferences(...); only in hdevelop
if (0 != (HTuple(hv_Size == HTuple()).TupleOr(hv_Size == -1)))
{
hv_Size = 16;
}
if (0 != ((hv_OS.TupleSubstr(0, 2)) == HTuple("Win")))
{
//Set font on Windows systems
try
{
//Check, if font scaling is switched on
OpenWindow(0, 0, 256, 256, 0, "buffer", "", &hv_BufferWindowHandle);
SetFont(hv_BufferWindowHandle, "-Consolas-16-*-0-*-*-1-");
GetStringExtents(hv_BufferWindowHandle, "test_string", &hv_Ascent, &hv_Descent,
&hv_Width, &hv_Height);
//Expected width is 110
hv_Scale = 110.0 / hv_Width;
hv_Size = (hv_Size*hv_Scale).TupleInt();
CloseWindow(hv_BufferWindowHandle);
}
// catch (Exception)
catch (HalconCpp::HException &HDevExpDefaultException)
{
HDevExpDefaultException.ToHTuple(&hv_Exception);
//throw (Exception)
}
if (0 != (HTuple(hv_Font == HTuple("Courier")).TupleOr(hv_Font == HTuple("courier"))))
{
hv_Font = "Courier New";
}
else if (0 != (hv_Font == HTuple("mono")))
{
hv_Font = "Consolas";
}
else if (0 != (hv_Font == HTuple("sans")))
{
hv_Font = "Arial";
}
else if (0 != (hv_Font == HTuple("serif")))
{
hv_Font = "Times New Roman";
}
if (0 != (hv_Bold == HTuple("true")))
{
hv_Bold = 1;
}
else if (0 != (hv_Bold == HTuple("false")))
{
hv_Bold = 0;
}
else
{
hv_Exception = "Wrong value of control parameter Bold";
throw HalconCpp::HException(hv_Exception);
}
if (0 != (hv_Slant == HTuple("true")))
{
hv_Slant = 1;
}
else if (0 != (hv_Slant == HTuple("false")))
{
hv_Slant = 0;
}
else
{
hv_Exception = "Wrong value of control parameter Slant";
throw HalconCpp::HException(hv_Exception);
}
try
{
SetFont(hv_WindowHandle, ((((((("-" + hv_Font) + "-") + hv_Size) + "-*-") + hv_Slant) + "-*-*-") + hv_Bold) + "-");
}
// catch (Exception)
catch (HalconCpp::HException &HDevExpDefaultException)
{
HDevExpDefaultException.ToHTuple(&hv_Exception);
//throw (Exception)
}
}
else if (0 != ((hv_OS.TupleSubstr(0, 2)) == HTuple("Dar")))
{
//Set font on Mac OS X systems. Since OS X does not have a strict naming
//scheme for font attributes, we use tables to determine the correct font
//name.
hv_SubFamily = 0;
if (0 != (hv_Slant == HTuple("true")))
{
hv_SubFamily = hv_SubFamily | 1;
}
else if (0 != (hv_Slant != HTuple("false")))
{
hv_Exception = "Wrong value of control parameter Slant";
throw HalconCpp::HException(hv_Exception);
}
if (0 != (hv_Bold == HTuple("true")))
{
hv_SubFamily = hv_SubFamily | 2;
}
else if (0 != (hv_Bold != HTuple("false")))
{
hv_Exception = "Wrong value of control parameter Bold";
throw HalconCpp::HException(hv_Exception);
}
if (0 != (hv_Font == HTuple("mono")))
{
hv_Fonts.Clear();
hv_Fonts[0] = "Menlo-Regular";
hv_Fonts[1] = "Menlo-Italic";
hv_Fonts[2] = "Menlo-Bold";
hv_Fonts[3] = "Menlo-BoldItalic";
}
else if (0 != (HTuple(hv_Font == HTuple("Courier")).TupleOr(hv
Halcon联合MFC混合编程之高斯梯度绝对值——用作边缘检测
需积分: 49 170 浏览量
2022-06-27
10:51:09
上传
评论
收藏 136KB RAR 举报
yangyang_z
- 粉丝: 335
- 资源: 8
最新资源
- 2002-2019年地级市城镇人均可支配收入面板数据
- 1990-2019操控性与非操控性应计利润指标数据
- 2009-2020各省单位地区生产总值能耗(等价值)(吨标准煤万元)
- 2000-2020年各省城镇登记失业率面板数据
- Python实现B站视频采集源代码
- 2010-2019分省电力消费量及在能源消费中的占比数据
- 超级好看的AI绘画小程序官网 html源码
- 1989-2020年全国以及各地区人口平均受教育年限
- 本工具是一款小巧自定义功能强大的PECMD/7zSFX单文件制作工具,简化单文件制作程序步骤,默认四步即可制作出一个单文件
- 2006-2019 地级市能源消耗量、煤炭占比、二氧化碳排放量
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0