📄 movespline.cpp
字号:
#include "uf.h"
#include "uf_ui.h"
#include "uf_csys.h"
#include "uf_curve.h"
#include "uf_modl.h"
#include "uf_trns.h"
tag_t UF_CURVE_Bspline_point(void);
tag_t UF_move_spline(const double x_move_d, const double y_move_d, const double z_move_d,
const tag_t move_objects_id, const int objects_number_n, const int layre_n);
///////////////////////////////////////////////////////////////////////////////////////////////////
//VC UG接口函数
///////////////////////////////////////////////////////////////////////////////////////////////////
void ufusr(char* param, int* returnCode, int rlen)
{
if (!UF_initialize())
{
uc1601("初始化UG成功!", 1);
tag_t curve_t;
//创建B-spline
curve_t = UF_CURVE_Bspline_point();
//对创建的B-spline在xoy平面进行平移
double x_d = 5; //x轴偏移量
double y_d = 5; //y轴偏移量
double z_d = 0; //z轴偏移量,在xoy平面内平移将其赋值为0
int curve_number_n = 1; //curve_t的数目
int move_to_layer_n = 0; //移动到的层数
tag_t moved_curve_t; //(???)被移动曲线的Tag
moved_curve_t = UF_move_spline(x_d, y_d, z_d, curve_t, curve_number_n, move_to_layer_n);
}
else
{
uc1601("初始化UG失败!", 1);
}
ufusr_ask_unload();
uc1601("结束", 1);
}
//卸载
int ufusr_ask_unload(void)
{
return(UF_UNLOAD_IMMEDIATELY);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//对绘制的B-spline Curve在xoy平面内进行平移
///////////////////////////////////////////////////////////////////////////////////////////////////
//输 入:
//(double)x_move_d = x轴的偏移量
//(double)y_move_d = y轴的偏移量
//(double)z_move_d = z轴的偏移量
//(tag_t)move_objects_id = 要变换的objects的tag
//(int)objects_number_n = 要变换的objects的数目
//(int)layre_n = 变换后的objects显示的层数
//输 出:
//(tag_t) = (???)被移动曲线的Tag
///////////////////////////////////////////////////////////////////////////////////////////////////
tag_t UF_move_spline(const double x_move_d, const double y_move_d, const double z_move_d,
const tag_t move_objects_id, const int objects_number_n, const int layre_n)
{
double xyz_d[3] = {x_move_d, y_move_d, z_move_d}; //x轴,y轴,z轴的偏移量
double translate_matrix_d[16]; //空间变换矩阵
tag_t objects_t = move_objects_id;
int objects_tag_numbers_n = objects_number_n;
int move_or_copy_n = 1;
int dest_layer_n = layre_n;
int trace_curves_n = 2;
tag_t copies_t;
tag_t * trace_curve_group_t = NULL_TAG;
int status_n;
//////////////////////////////////////////////////////////////////////////////
//由x轴,y轴,z轴的偏移量得到空间变换矩阵(Open C API)
//////////////////////////////////////////////////////////////////////////////
//输 入:
//(double*)xyz_d = x轴,y轴,z轴的偏移量
//输 出:
//(double*)translate_matrix_d = 空间变换矩阵
//////////////////////////////////////////////////////////////////////////////
uf5943(xyz_d, translate_matrix_d);
//////////////////////////////////////////////////////////////////////////////
//对object在空间进行变换(Open C API)
//////////////////////////////////////////////////////////////////////////////
//输 入:
//(double*)translate_matrix_d = 空间变换矩阵(必须由uf5942-uf5946定义)
//(tag_t*)objects_t = 进行变换的object的Tag数组
//(int*)objects_tag_numbers_n = objects_t的个数
//(int*)move_or_copy_n = (???)Move/Copy Status. 1 = Move,2 = copy.
//(int*)dest_layer_n = Destination Layer,0 = the original layer,-1 = the work layer
// 1 - 256 = the specified layer
//(int*)trace_curves_n = (???)Trace Curve(虚线) Status, 1 means on, 2 means off.
//输 出:
//(tag_t)copies_t = List of copied object identifiers
//(tag_t*)trace_curve_group_t = Group of trace curves. This is not used when ip6 is set to 2.
//(int*)status_n
//注 意;
//move_or_copy_n = 2(copy)时将会失败
//trace_curves_n = 1(means on)时将会失败,可能是对线的移动无法显示Trace Curve(虚线)
//translate_matrix_d 第四列坐标为乱值,但不影响变换
//////////////////////////////////////////////////////////////////////////////
uf5947(translate_matrix_d, &objects_t, &objects_tag_numbers_n, &move_or_copy_n,
&dest_layer_n, &trace_curves_n, &copies_t, trace_curve_group_t, &status_n);
if (0!=status_n)
{
uc1601("空间变换失败!", 1);
}
return copies_t;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//使用Point绘制B-spline Curve
////////////////////////////////////////////////////////////////////////////////////////////////////////
tag_t UF_CURVE_Bspline_point(void)
{
//B-spline信息
const int NUMBER_POINTS = 5; //选取的生成B-spline曲线的点的个数
double points_d[3*NUMBER_POINTS] = {1.0000, 1.0000, 0.0000, //选取的生成B-spline曲线的点
2.0000, 2.0000, 0.0000,
3.0000, 3.0000, 0.0000,
4.0000, 2.0000, 0.0000,
5.0000, 1.0000, 0.0000};
//B-spline输入参数
int degree_n = 3; //B-spline次数
int periodicity_n = 0; //B-spline周期性,0 = 非周期,1 = 周期
int numPoints_n = NUMBER_POINTS; //B-spline曲线上点的个数
UF_CURVE_pt_slope_crvatr_t point_data[NUMBER_POINTS]; //B-spline的Point即每个slope(斜率)、curvature(曲率)
int save_def_data_n = 1; //1 = 保存B-spline信息,0 = 不保存B-spline信息
tag_t spline_t; //创建B-spline的Tag
for (int i= 0; i<NUMBER_POINTS; i++)
{
point_data[i].point[0] = points_d[3*i]; //选取的生成B-spline曲线的点
point_data[i].point[1] = points_d[3*i+1];
point_data[i].point[2] = points_d[3*i+2];
point_data[i].slope_type = UF_CURVE_SLOPE_NONE; //B-spline曲线点的斜率类型
point_data[i].slope[0] = 0.0;
point_data[i].slope[1] = 0.0;
point_data[i].slope[2] = 0.0;
point_data[i].crvatr_type = UF_CURVE_CRVATR_NONE; //B-spline曲线点的曲率类型
point_data[i].crvatr[0] = 0.0;
point_data[i].crvatr[1] = 0.0;
point_data[i].crvatr[2] = 0.0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//使用Kont Point绘制B-spline curve(UG Open C API)
///////////////////////////////////////////////////////////////////////////////////////////////////
//输 入:
//(int)nDegree = B-spline次数
//(int)nPeriodicity = B-spline周期性,0 = 非周期,1 = 周期
//(int)nNumPoints = B-spline曲线上点的个数
//(UF_CURVE_pt_slope_crvatr_t)point_data = B-spline的Point即每个slope(斜率)、curvature(曲率)
//(double)NULL = Point不需要参数化
//(int)nSaveDefData = 1(保存B-spline信息)、0(不保存B-spline信息)
//输 出:
//(tag_t*)&spline_tag = 创建B-spline的Tag
////////////////////////////////////////////////////////////////////////////////////////////////////
int nError = UF_CURVE_create_spline_thru_pts(degree_n,
periodicity_n,
numPoints_n,
point_data,
NULL,
save_def_data_n,
&spline_t);
if (0!=nError)
{
char cError[133] = "";
UF_get_fail_message(nError, cError);
uc1601(cError, 1);
}
return spline_t;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -