/* Include files */
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include <uf_disp.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <uf_vec.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_defs.h>
#include <uf_mtx.h>
static FILE* prterr;
static int errorCode;
static tag_t part;
#define PRTERR if(errorCode)\
{PrintErrorMessage(errorCode,__LINE__);errorCode=0;goto term;}
//процедура расшифровки кода ошибки
static void PrintErrorMessage(int errorCode, int line)
{
if(errorCode)
{
char message[133];
UF_get_fail_message(errorCode,message);
UF_UI_set_status(message);
fprintf(prterr,"errorCode=%d\tmessage=%s\tline=%d\n",errorCode,message,line);
fflush(prterr);
}
}
void do_it()
{
goto label_acr_3p;
//построение дуги по системе координат, центр и угол
{
tag_t arc_tag45;
UF_CURVE_arc_t arc_coord45;
double mat45[9];
/* Use X-axis for rotation. */
double rot_axis[3] = {1.0,0.0,0.0};
/* Use 45 degrees as rotation angle */
double angle45 = 45 * DEGRA;
/* Center of arc with respect to (0,0,0) of Absolute CSYS. */
double vec[3] = {3.0,-2.0,1.5};
/* Create 45 degree orientation matrix. */
UF_MTX3_rotate_about_axis(rot_axis,angle45,mat45);
/* Obtain mapped coordinates. */
UF_MTX3_vec_multiply(vec,mat45,arc_coord45.arc_center);
/* Fill out the data structure for the arc */
errorCode=UF_CSYS_create_matrix(mat45,&arc_coord45.matrix_tag);PRTERR;
arc_coord45.start_angle = 0.0;
arc_coord45.end_angle = 360.0 * DEGRA;
arc_coord45.radius = 2.0;/* Create the arc. */
errorCode=UF_CURVE_create_arc(&arc_coord45,&arc_tag45);PRTERR;
}
label_acr_3p:
//построение дуги по 3-м точкам
{
int create_flag=1;
double first_point[ 3 ]={1,0,0};
double second_point[ 3 ]={0,1,0};
double third_point[ 3 ]={1,1,1};
tag_t arc_tag;
errorCode=UF_CURVE_create_arc_thru_3pts
(create_flag,first_point,second_point,third_point,&arc_tag);PRTERR;
}
goto term;
term:
return;
}
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* 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 )
{
836
b8a
//переменные обработки времени
struct tm* newtime;
time_t acloc
7a4
k,start_time,finish_time;
double work_time;
int min,sec;
time(&start_time);
//попытка открыть файл ошибок на D:
if((prterr=fopen("D:\\prterr.txt","w"))!=NULL)
{
//uc1601("жми ОК и работай дальше",1);
goto label_clock;
}
//попытка открыть файл ошибок на C:\TEMP
if((prterr=fopen("C:\\temp\\prterr.txt","w"))!=NULL)
{
//uc1601("жми ОК и работай дальше",1);
goto label_clock;
}
//файл ошибок разместить не удалось
uc1601("не могу разместить файл ошибок",1);
return;
label_clock:
time(&aclock);
newtime=localtime(&aclock);
fprintf(prterr,"\n<create_arc> HAS STARTED line=%d\n\n",__LINE__);
fprintf(prterr,"время начала работы программы: %s\n\n",asctime(newtime));
errorCode=UF_initialize();PRTERR;
//проверь открытие файла модели или сборки
part=UF_PART_ask_display_part();
if(part==NULL_TAG)
{
uc1601("открой непустой файл!",1);
fprintf(prterr,"\n открой непустой файл line=%d\n",__LINE__);
goto term;
}
/* TODO: Add your application code here */
do_it();
errorCode=UF_terminate();PRTERR;
term:
time(&finish_time);
work_time=difftime(finish_time,start_time);
min=(int)work_time/60;
sec=(int)(work_time-min*60);
fprintf(prterr,"\n<create_arc> HAS ENDED line=%d\n\n",__LINE__);
fprintf(prterr,"working time is %u min %u sec\n",min,sec);
fflush(prterr);
fclose(prterr);
return;
}
/*****************************************************************************
** 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 );
}