⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nx3 open wizard1.cpp

📁 是一个G代码转换的源程序
💻 CPP
字号:
/*****************************************************************************
**
** NX3 Open Wizard1.cpp
**
** Description:
**     Contains Unigraphics entry points for the application.
**
*****************************************************************************/

/* Include files */
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
#   include <strstream>
#   include <iostream>
#   include <fstream>
#   include <math.h>
    using std::ostrstream;
    using std::endl;    
    using std::ends;
    using std::cerr;
	using namespace std;

#else
#   include <strstream.h>
#   include <iostream.h>

	using namespace std;
	
#endif
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include "GNode.h"
#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],
             msg[133];

        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
            irc, line, file);
        UF_get_fail_message(irc, err);

        UF_print_syslog(msg, FALSE);
        UF_print_syslog(err, FALSE);
        UF_print_syslog("\n", FALSE);
        UF_print_syslog(call, FALSE);
        UF_print_syslog(";\n", FALSE);

        if (!UF_UI_open_listing_window())
        {
            UF_UI_write_listing_window(msg);
            UF_UI_write_listing_window(err);
            UF_UI_write_listing_window("\n");
            UF_UI_write_listing_window(call);
            UF_UI_write_listing_window(";\n");
        }
    }

    return(irc);
}


//const double pi=3.141592653589793238462643;
void do_ugopen_api_Line(double xq,double yq,double zq,double xz,double yz,double zz,int color=0);
void do_ugopen_api_Arc(double xc,double yc,double zc,double r,double AngleQ,double AngleZ,int color=0);
double arccos(double x,double y);
double Angle(double xq, double yq, double xz, double yz);

/*****************************************************************************
**  Activation Methods
*****************************************************************************/
/*  Unigraphics Startup
**      This entry point activates the application at Unigraphics startup */
extern DllExport void ufsta( char *param, int *returnCode, int rlen )
{
    /* Initialize the API environment */
    if( UF_CALL(UF_initialize()) ) 
    {
        /* Failed to initialize */
        return;
    }
    
    /* TODO: Add your application code here */

	string filename,data;
	vector<string> file,file1;
	vector<Coord> profileValue,contourValue;


	ifstream fin;
	filename="GNode-GGG.txt";
	//filename="GNode-GGR4.txt";
	//filename="26.txt";
	fin.open(filename.c_str());
	if (!fin)
	{
		cerr<<"Cannot open '"<<filename<<"'"<<endl;
		exit(1);
	}
	while (true)
	{
		getline(fin,data,'\n');
		if (!fin)
			break;
		file.push_back(data);
	}

	GNode a(file);
	file1=a.getfile();
	for (int i=0;i<file1.size();i++)
		cout<<file1[i]<<endl;
	cout<<endl;

	contourValue=a.generateContoutLine();
	profileValue=a.generateProfileCurve();


	//for (i=0;i<Value.size();i++)
		//cout<<Value[i]<<endl;
	double xq,yq,zq,xz,yz,xc,yc,zc,zz,r;
	int Typ;
	double Angle1,Angle2;

	for (int i=1;i<contourValue.size();i++)
	{
		xq=contourValue[i-1].x;yq=contourValue[i-1].y;zq=contourValue[i-1].z;
		xz=contourValue[i].x;yz=contourValue[i].y;zz=contourValue[i].z;
		xc=contourValue[i].xc,yc=contourValue[i].yc;zc=contourValue[i].z;
		r=fabs(contourValue[i].r);
		Typ=contourValue[i].Typ;
		if (Typ==1 || Typ==0)
			do_ugopen_api_Line(xq,yq,zq,xz,yz,zz);
		else if (Typ==2)
		{
			Angle1=Angle(xc,yc,xq,yq);
			Angle2=Angle(xc,yc,xz,yz);
			if (Angle1>360)
				Angle1=Angle1-360;
			if (Angle1<0)
				Angle1=Angle1+360;
			if (Angle2>360)
				Angle2=Angle2-360;
			if (Angle2<0)
				Angle2=Angle2+360;
			if (Angle1<Angle2)
				Angle1=Angle1+360;
			do_ugopen_api_Arc(xc,yc,zc,r,Angle2,Angle1);
		}
		else if (Typ==3)
		{
			Angle1=Angle(xc,yc,xq,yq);
			Angle2=Angle(xc,yc,xz,yz);
			if (Angle1>360)
				Angle1=Angle1-360;
			if (Angle1<0)
				Angle1=Angle1+360;
			if (Angle2>360)
				Angle2=Angle2-360;
			if (Angle2<0)
				Angle2=Angle2+360;
			if (Angle2<Angle1)
				Angle2=Angle2+360;
			do_ugopen_api_Arc(xc,yc,zc,r,Angle1,Angle2);
		}			
	}
	
	for (int i=1;i<profileValue.size();i++)
	{
		xq=profileValue[i-1].x;yq=profileValue[i-1].y;zq=profileValue[i-1].z;
		xz=profileValue[i].x;yz=profileValue[i].y;zz=profileValue[i].z;
		xc=profileValue[i].xc,yc=profileValue[i].yc;zc=contourValue[i].z;
		r=fabs(profileValue[i].r);
		Typ=profileValue[i].Typ;
		if (Typ==1 || Typ==0)
			do_ugopen_api_Line(xq,yq,zq,xz,yz,zz,150);
		else if (Typ==2)
		{
			Angle1=Angle(xc,yc,xq,yq);
			Angle2=Angle(xc,yc,xz,yz);
			if (Angle1>360)
				Angle1=Angle1-360;
			if (Angle1<0)
				Angle1=Angle1+360;
			if (Angle2>360)
				Angle2=Angle2-360;
			if (Angle2<0)
				Angle2=Angle2+360;
			if (Angle1<Angle2)
				Angle1=Angle1+360;
			do_ugopen_api_Arc(xc,yc,zc,r,Angle2,Angle1,150);
		}
		else if (Typ==3)
		{
			Angle1=Angle(xc,yc,xq,yq);
			Angle2=Angle(xc,yc,xz,yz);
			if (Angle1>360)
				Angle1=Angle1-360;
			if (Angle1<0)
				Angle1=Angle1+360;
			if (Angle2>360)
				Angle2=Angle2-360;
			if (Angle2<0)
				Angle2=Angle2+360;
			if (Angle2<Angle1)
				Angle2=Angle2+360;
			do_ugopen_api_Arc(xc,yc,zc,r,Angle1,Angle2,150);
		}			
	}

    /* Terminate the API environment */
    UF_CALL(UF_terminate());
}

/*****************************************************************************
**  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 );
}


void do_ugopen_api_Line(double xq,double yq,double zq,double xz,double yz,double zz,int color)
{
	UF_CURVE_line_t line;
	tag_t ObLine;	
	line.start_point[0] =xq ;
	line.start_point[1] =yq ;
	line.start_point[2] =zq ;
	line.end_point[0] = xz ;
	line.end_point[1] = yz;
	line.end_point[2] = zz ;
	UF_CURVE_create_line(&line , &ObLine);
	UF_OBJ_set_color(ObLine,color);
};

void do_ugopen_api_Arc(double xc,double yc,double zc,double r,double AngleQ,double AngleZ,int color)
{
	UF_CURVE_arc_t ARC; 
	tag_t ObArc;	
	tag_t wcs;
	ARC.arc_center[0]=xc;
	ARC.arc_center[1]=yc;
	ARC.arc_center[2]=zc;
	ARC.start_angle=AngleQ*pi/180;
	ARC.end_angle=AngleZ*pi/180;
	ARC.radius=r;
	UF_CSYS_ask_wcs(&wcs);
	UF_CSYS_ask_matrix_of_object(wcs, &ARC.matrix_tag);
	UF_CURVE_create_arc(&ARC,&ObArc);
	UF_OBJ_set_color(ObArc,color);
}

double arccos(double x,double y)
{
	if (y>0)
		return acos(x)*180.0/pi;
	else
		return (2*pi-acos(x))*180.0/pi;
}

double Angle(double xq, double yq, double xz, double yz)
{
	double r,x;
	xz=xz-xq;
	yz=yz-yq;
	r=sqrt(xz*xz+yz*yz);
	x=xz/r;
	if (yz>0)
		return acos(x)*180.0/pi;
	else
		return (2*pi-acos(x))*180.0/pi;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -