?? 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 + -