UG二次开发---UF_MODL_create_fitted_spline();函数的应用
UG二次开发,VC6.0 UG6.0 通过点生成样条曲线 采用函数UF_MODL_create_fitted_spline(SPLINE_FIT_p_t spline_data,double *max_err,int *max_err_pt ,tag_p_t obj_id)。
但是SPLINE_FIT_p_t 这种数据结构不会用,请指导。
附录 源程序
// ugopen.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "ugopen.h"
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_curve.h>
#include<uf_modl.h> //建模
#define NUMBER_POINTS 5
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CUgopenApp
BEGIN_MESSAGE_MAP(CUgopenApp, CWinApp)
//{{AFX_MSG_MAP(CUgopenApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUgopenApp construction
CUgopenApp::CUgopenApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CUgopenApp object
CUgopenApp theApp;
// ufusr()是直接激活的用户出口
// param retcode 是输出参数,rlen是指参数param的长度,由NX系统自动处理
//给出了一个函数的范例 可以写成子函数的形式 也方便调试 自己先定义一个子函数
static void do_ugopen_api(void)
{
SPLINE_FIT_p_t spdata; //截面点数据
double sp1;
double pt[15]={1.1000, 0.5320, 2.0000,
1.5240, 0.6789, 2.3000,
2.0000, 0.9000, 3.5956,
2.3456, 1.3456, 3.7890,
3.1000, 2.4567, 3.3214};
int err_pt;
int i;
tag_p_t curved_id;
spdata->degree=3;
spdata->num_of_points=5;
spdata->num_of_segments=1;
//spdata坐标的注释
// points
// double *
//
// coordinates for the points to be fitted.
// points[0~2] = (x, y, z) for the 1st point,
// points[3~5] = (x, y, z) for the 2nd point,
// ...
for(i=0;i<15;i++)
{
spdata->points[i]=pt[i]; //这个不会用? 求指导
}
//通过点的样条曲线
UF_MODL_create_fitted_spline(spdata,&sp1,&err_pt,curved_id);
}
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
/* Initialize the API environment */
int errorCode = UF_initialize(); //初始化 获得权限
if ( 0 == errorCode )
{
/* TODO: Add your application code here 添加如下代码*/
AFX_MANAGE_STATE(AfxGetStaticModuleState()); //切换模块状态
do_ugopen_api(); //调用该程序
/* Terminate the API environment */
errorCode = UF_terminate(); //释放NX执行许可权限
}
/* Print out any error messages */
PrintErrorMessage( errorCode );
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void ) //卸载函数
{
return( UF_UNLOAD_IMMEDIATELY );
}
/* PrintErrorMessage
**
** Prints error messages to standard error and the Unigraphics status
** line. */
static void PrintErrorMessage( int errorCode ) //错误输出
{
if ( 0 != errorCode )
{
/* Retrieve the associated error message */
char message[133];
UF_get_fail_message( errorCode, message );
/* Print out the message */
UF_UI_set_status( message );
fprintf( stderr, "%s\n", message );
}
}