UG二次开发 定向视图窗口 C++源代码
时间: 2023-09-04 10:07:59 浏览: 259
以下是UG二次开发定向视图窗口的C语言源代码:
```
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_view.h>
#include <uf_disp.h>
static int my_initialize(void);
static int my_terminate(void);
static int my_initialize(void)
{
int error_code = 0;
// 初始化UG环境
error_code = UF_initialize();
if(error_code != 0)
{
printf("Error: Failed to initialize UG environment.\n");
return error_code;
}
// 初始化UG界面
error_code = UF_UI_initialize();
if(error_code != 0)
{
printf("Error: Failed to initialize UG UI.\n");
return error_code;
}
return error_code;
}
static int my_terminate(void)
{
int error_code = 0;
// 结束UG界面
error_code = UF_UI_terminate();
if(error_code != 0)
{
printf("Error: Failed to terminate UG UI.\n");
return error_code;
}
// 结束UG环境
error_code = UF_terminate();
if(error_code != 0)
{
printf("Error: Failed to terminate UG environment.\n");
return error_code;
}
return error_code;
}
int main(int argc, char *argv[])
{
int error_code = 0;
tag_t work_part_tag = NULL_TAG;
tag_t display_part_tag = NULL_TAG;
char part_name[MAX_FSPEC_SIZE+1] = "";
char display_part_name[MAX_FSPEC_SIZE+1] = "";
tag_t view_tag = NULL_TAG;
char view_name[MAX_ENTITY_NAME_SIZE+1] = "";
UF_VIEW_display_parms_t display_parms;
UF_DISP_view_display_t view_display;
// 初始化UG环境和界面
error_code = my_initialize();
if(error_code != 0)
{
return error_code;
}
// 获取工作部件
error_code = UF_PART_ask_display_part(&display_part_tag);
if(error_code != 0)
{
printf("Error: Failed to get display part.\n");
my_terminate();
return error_code;
}
error_code = UF_PART_ask_part_name(display_part_tag, display_part_name);
if(error_code != 0)
{
printf("Error: Failed to get display part name.\n");
my_terminate();
return error_code;
}
printf("Display Part: %s\n", display_part_name);
// 获取视图
error_code = UF_VIEW_ask_tag_of_view_name("Top", &view_tag);
if(error_code != 0)
{
printf("Error: Failed to get view tag.\n");
my_terminate();
return error_code;
}
error_code = UF_VIEW_ask_view_name(view_tag, view_name);
if(error_code != 0)
{
printf("Error: Failed to get view name.\n");
my_terminate();
return error_code;
}
printf("View: %s\n", view_name);
// 设置显示参数
display_parms.draw_edges = true;
display_parms.draw_faces = true;
display_parms.draw_edges_only = false;
display_parms.draw_hidden_edges = true;
display_parms.draw_silhouettes = true;
display_parms.shaded_display = false;
display_parms.color_display = true;
display_parms.show_axes = true;
display_parms.show_coordinate_system = true;
display_parms.show_xyz_axes = true;
display_parms.show_grid = true;
display_parms.show_solid_body_edges = true;
display_parms.show_edges = true;
display_parms.show_faces = true;
display_parms.show_hidden_edges = true;
display_parms.show_silhouettes = true;
display_parms.show_section_edges = true;
display_parms.show_section_faces = true;
display_parms.show_section_silhouettes = true;
display_parms.show_section_grids = true;
display_parms.show_section_symbols = true;
display_parms.show_shaded_faces = true;
display_parms.show_visible_edges = true;
// 设置视图显示
view_display.view_tag = view_tag;
view_display.display_parms = display_parms;
view_display.override_all = true;
view_display.override_color = false;
view_display.override_linetype = false;
view_display.override_line_width = false;
view_display.color = 0;
view_display.linetype = 0;
view_display.line_width = 0;
// 显示视图
error_code = UF_DISP_set_display_of_view(work_part_tag, &view_display);
if(error_code != 0)
{
printf("Error: Failed to display view.\n");
my_terminate();
return error_code;
}
// 结束UG环境和界面
my_terminate();
return error_code;
}
```
阅读全文