|
马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
比如要使UG中的一个实体进行旋转变换!
UG open API中说明使用:
uf5947_
Transform objects according to a previously defined matrix.
The upper limit on the number of objects to transform is 32767. The object types supported for non-uniform scaling are the same as those supported by non-uniform scaling in interactive Unigraphics.
函数原型如下:
extern void uf5947_ (
const double * rp1,
const tag_t * np2,
const int * ip3,
const int * ip4,
const int * ip5,
const int * ip6,
tag_t * nr7,
tag_t * nr8,
int * ir9 );
可是在使用此函数时返回值表明成功,但是实际没有完成;郁闷ing!!
程序代码如下:
/*****************************************************************************
**
** test_trans.c
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include <uf_group.h>
#include <uf_eval.h>
#include <uf_process_aid.h>
#include <uf_mtx.h>
#include <uf_layer.h>
#include <uf_trns.h>
#include "test_trans.h"
/*****************************************************************************
** Activation Methods
*****************************************************************************/
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133], messg[300];
UF_get_fail_message(irc, err);
sprintf(messg, "\n%s\nerror %d at line %d in %s\n%s",
err, irc, line, file, call);
printf("%s\n", messg);
strcpy([$messg[129], "...")]
uc1601(messg, TRUE); /* Internal only - remove for external */
UF_terminate();
}
return(irc);
}
void do_it(void)
{
double from_origin[3] = {0.0, 0.0, 0.0};
double from_x_axis[3] = {1.0, 0.0, 0.0};
double from_y_axis[3] = {0.0, 1.0, 0.0};
double to_origin[3] = {0.0, 0.0, 0.0};
double to_x_axis[3] = {0.0, 1.0, 0.0};
double to_y_axis[3] = {1.0, 0.0, 0.0};
double transform[16];
char cc[256];
double bound[6];
//Transform 参数
//input
// double * rp1; //Defined Transformation Matrix
// tag_t * np2; //Array of object identifiers.
int ip3=1; //Number of objects in np2 array
int ip4 = 1; // 1-move, 2-copy
int ip5 = 0; //Destination Layer, 0-the original layer, -1 - the work layer
int ip6 = 1; //Trace Curve Status, 1 means on, 2 means off
//output
tag_t nr7[100]; //List of copied object identifiers
tag_t nr8[100]; //Group of trace curves
int ir9; //Status Code: 0 - Success
tag_t solid_tag[1] = {NULL_TAG};
UF_CALL ( UF_MODL_ask_object( UF_solid_type, UF_solid_body_subtype, [$solid_tag[0]))]
sprintf( cc, "\nthe solid object is : %d\n" , solid_tag[0]);
UF_CALL(UF_UI_open_listing_window());
UF_CALL(UF_UI_write_listing_window(cc));
//* fetch the matrix containing mirro information to move an
//* object around X-Y mirror plane
//得到实体的边界筐
UF_CALL ( UF_MODL_ask_bounding_box ( solid_tag[0], bound ));
/*//使用此函数生产旋转变换的矩阵
extern void uf5945_ ( //Returns a matrix to perform a rotation around an arbitrary axis
double * rp1, //Origin Of The Axis - Absolute Coordinates
double * rp2, //Direction Vector - Absolute Coordinates
double * rp3, //Rotation Angle In Degrees
double * rr4, //Rotation Matrix
int * ir5 ); //Status Code: 0 - Success; 1 - Direction Vector Is A Zero Vector
*/
{
double rp1[3] = {0.0, 1.0 , 0.0};
double rp2[3] = {0.0, 0.0 , 1.0};
double rp3 = 90;
int ir5;
rp1[0] = (bound[0] +bound[3])/2;
rp1[1] = (bound[1] +bound[4])/2;
rp1[2] = (bound[2] +bound[5])/2;
rp2[1] = rp1[1] +1;
uf5945_ ( rp1, rp2, [$rp3, transform, [$ir5)] //生产旋转矩阵
sprintf( cc, "\nthe Matrix Status Code is : %d\n" , ir5);
UF_CALL(UF_UI_open_listing_window());
UF_CALL(UF_UI_write_listing_window(cc));
}
//对实体进行旋转变换:
uf5947_( transform, solid_tag, [$ip3, &ip4, &ip5, &ip6, nr7, nr8, &ir9)]
sprintf( cc, "\nthe trans Status Code is : %d\n" , ir9);
UF_CALL(UF_UI_open_listing_window());
UF_CALL(UF_UI_write_listing_window(cc));
}
/* Explicit Activation
** This entry point is used to activate the application explicitly, as in
** "File->Execute UG/Open->User Function..." */
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 */
do_it();
/* Terminate the API environment */
errorCode = UF_terminate();
}
/* 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_UG_TERMINATE );
} |
|