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

📄 xpig.c

📁 Programs in the irregular grid design package described in this manual are used to carry out five ma
💻 C
📖 第 1 页 / 共 5 页
字号:
	Xwindow[PIG_CONTROL_WIN].y1 = 0;	Xwindow[PIG_CONTROL_WIN].y2 = (int) height - 1;	XtVaGetValues( ProfileXCanvas, 		XtNheight, &height, 		XtNwidth, &width, 		NULL);PIGDBG2("**************ProfileXCanvas: (%i x %i)\n", height, width);	Xwindow[PIG_PROFILE_WIN].x1 = 0;	Xwindow[PIG_PROFILE_WIN].x2 = (int) width - 1;	Xwindow[PIG_PROFILE_WIN].y1 = 0;	Xwindow[PIG_PROFILE_WIN].y2 = (int) height - 1;	XtVaGetValues( MainXCanvas, 		XtNheight, &height, 		XtNwidth, &width, 		NULL);PIGDBG2("**************MainXCanvas: (%i x %i)\n", height, width);	Xwindow[PIG_MAIN_WIN].x1 = 0;	Xwindow[PIG_MAIN_WIN].x2 = (int) width - 1;	Xwindow[PIG_MAIN_WIN].y1 = 0;	Xwindow[PIG_MAIN_WIN].y2 = (int) height - 1;        MainWinSizeX    = (double) (Xwindow[PIG_MAIN_WIN].x2 - Xwindow[PIG_MAIN_WIN].x1);        MainWinSizeY    = (double) (Xwindow[PIG_MAIN_WIN].y2 - Xwindow[PIG_MAIN_WIN].y1);        WorldX2 = (WorldX1 + ( ((WorldY2 - WorldY1)/(MainWinSizeY))                                        /((aspect)/(MainWinSizeX)) ) );}/*----------------------------------------------------------------------------*/static int iXPigUnresolveWindow(Window window){	int return_value;	if (window == XtWindow(MainXCanvas)) {		return_value = PIG_MAIN_WIN;        } else if (window == XtWindow(ControlXCanvas)) {        	return_value = last_ctrl_or_prfl;        }  else {		return_value = NULL_WIN;	}		return return_value;}/*----------------------------------------------------------------------------*/static void iXPigUnresolvePoint(int window, const int in_x, const int in_y, double *out_x, double *out_y){	/* PIGDBG2("in_x\t\t:%f\nWorldX1\t\t:%f\nWorldX2\t\t:%f\nMainXCanvasWidth\t:%i\n", */			/* in_x, WorldX1, WorldX2, MainXCanvasWidth); */	switch(window) {		case PIG_MAIN_WIN:		{			double 		x, y; 			double 		WrldX1, WrldX2, WrldY1, WrldY2;			double		MainWinX1, MainWinSizeX, MainWinSizeY;			x 		= (double) in_x;			y 		= (double) in_y;			WrldX1 		= (double) WorldX1;			WrldX2 		= (double) WorldX2;			WrldY1 		= (double) WorldY1;			WrldY2		= (double) WorldY2;			MainWinX1	= (double) Xwindow[PIG_MAIN_WIN].x1;        		MainWinSizeX    = (double) (Xwindow[PIG_MAIN_WIN].x2 - Xwindow[PIG_MAIN_WIN].x1);        		MainWinSizeY    = (double) (Xwindow[PIG_MAIN_WIN].y2 - Xwindow[PIG_MAIN_WIN].y1);        		*out_x = ( ( ( ( x - MainWinX1 ) / ( MainWinSizeX ) ) * ( WrldX2 - WrldX1 ) ) 					+ WrldX1 );        		*out_y = ( ( ( ( y - MainWinSizeY ) / ( (-1) * MainWinSizeY ) ) * ( WrldY2 - WrldY1 ) ) 					+ WrldY1 );			break;		}		case PIG_CONTROL_WIN:		{			double 		x, y; 			double		CtrlWinX1, CtrlWinY1, CtrlWinSizeX, CtrlWinSizeY;			x 		= (double) in_x;			y 		= (double) in_y;			CtrlWinX1	= (double) Xwindow[PIG_CONTROL_WIN].x1;			CtrlWinY1	= (double) Xwindow[PIG_CONTROL_WIN].y1;        		CtrlWinSizeX    = (double) (Xwindow[PIG_CONTROL_WIN].x2 - Xwindow[PIG_CONTROL_WIN].x1);        		CtrlWinSizeY    = (double) (Xwindow[PIG_CONTROL_WIN].y2 - Xwindow[PIG_CONTROL_WIN].y1);        		*out_x = ( ( ( ( x - CtrlWinX1 ) / ( CtrlWinSizeX ) ) * ( 40 ) ) ); 	        		*out_y = ( ( -1 ) * ( ( ( ( y - CtrlWinY1 ) / ( CtrlWinSizeY ) ) * ( 100 ) ) 					- 100 ) );			break;		}		case PIG_PROFILE_WIN:		{			double 		x, y; 			double 		PrflX1, PrflX2, PrflY1, PrflY2;			double		PrflWinX1, PrflWinSizeX, PrflWinSizeY;			x 		= (double) in_x;			y 		= (double) in_y;			PrflX1 		= (double) ProfileX1;			PrflX2 		= (double) ProfileX2;			PrflY1 		= (double) ProfileY1;			PrflY2		= (double) ProfileY2;			PrflWinX1	= (double) Xwindow[PIG_PROFILE_WIN].x1;        		PrflWinSizeX    = (double) (Xwindow[PIG_PROFILE_WIN].x2 - Xwindow[PIG_PROFILE_WIN].x1);        		PrflWinSizeY    = (double) (Xwindow[PIG_PROFILE_WIN].y2 - Xwindow[PIG_PROFILE_WIN].y1);        		*out_x = ( ( ( ( x - PrflWinX1 ) / ( PrflWinSizeX ) ) * ( PrflX2 - PrflX1 ) ) 					+ PrflX1 );	        		*out_y = ( ( ( ( y - PrflWinSizeY ) / ( (-1) * PrflWinSizeY ) ) * ( PrflY2 - PrflY1 ) ) 					+ PrflY1 );			break;		}	}}/*----------------------------------------------------------------------------*/static void iXPigResolvePoint(const double in_x, const double in_y, short *out_xp, short *out_yp){	/* code to be placed here to resolve PIG co-ordinate system	   to X co-ordinate system conversion				*/	/* long out_x, out_y; */	double out_x, out_y;PIGDBG("iXPigResolvePoint(%g, %g, ...)", in_x, in_y);PIGDBG("current_pig_window=%li", (long)current_pig_window);	switch(current_pig_window) {	case PIG_STATUS_WIN:		iWPigFatal("Invalid window in iXPigResolvePoint");		break;	default:	case PIG_MAIN_WIN:PIGDBG("Xwindow[PIG_MAIN_WIN].x1=%li", (long)Xwindow[PIG_MAIN_WIN].x1);PIGDBG("Xwindow[PIG_MAIN_WIN].x2=%li", (long)Xwindow[PIG_MAIN_WIN].x2);PIGDBG("WorldX1=%g", (double)WorldX1);PIGDBG("WorldX2=%g\n", (double)WorldX2);PIGDBG("Xwindow[PIG_MAIN_WIN].y1=%li", (long)Xwindow[PIG_MAIN_WIN].y1);PIGDBG("Xwindow[PIG_MAIN_WIN].y2=%li", (long)Xwindow[PIG_MAIN_WIN].y2);PIGDBG("WorldY1=%g", (double)WorldY1);PIGDBG("WorldY2=%g\n", (double)WorldY2);		out_x = (Xwindow[PIG_MAIN_WIN].x1 + 			((in_x - WorldX1)/(WorldX2 - WorldX1)) 			* (Xwindow[PIG_MAIN_WIN].x2 - Xwindow[PIG_MAIN_WIN].x1)  );		out_y = (Xwindow[PIG_MAIN_WIN].y2 - Xwindow[PIG_MAIN_WIN].y1) -			( ((in_y - WorldY1)/(WorldY2 - WorldY1)) 			* (Xwindow[PIG_MAIN_WIN].y2 - Xwindow[PIG_MAIN_WIN].y1) );		break;	case PIG_PROFILE_WIN:		out_x = (Xwindow[PIG_PROFILE_WIN].x1 + 			((in_x - ProfileX1)/(ProfileX2 - ProfileX1)) 			* (Xwindow[PIG_PROFILE_WIN].x2 - Xwindow[PIG_PROFILE_WIN].x1)  );		out_y = (Xwindow[PIG_PROFILE_WIN].y2 - Xwindow[PIG_PROFILE_WIN].y1) -			( ((in_y - ProfileY1)/(ProfileY2 - ProfileY1)) 			* (Xwindow[PIG_PROFILE_WIN].y2 - Xwindow[PIG_PROFILE_WIN].y1) );		break;	case PIG_CONTROL_WIN:		out_x = Xwindow[PIG_CONTROL_WIN].x1 + 			((in_x / 40) 			* (Xwindow[PIG_CONTROL_WIN].x2 - Xwindow[PIG_CONTROL_WIN].x1));		out_y = Xwindow[PIG_CONTROL_WIN].y1 + 			(((100 - in_y)/ 100) 			* (Xwindow[PIG_CONTROL_WIN].y2 - Xwindow[PIG_CONTROL_WIN].y1));		break;	}	/* constrain output values to range of int variables */PIGDBG("iXPigResolvePoint(%g, %g, %li, %li)\n", in_x, in_y, (long)out_x, (long)out_y);	*out_xp = ((long)out_x >= SHRT_MAX) ? SHRT_MAX : ( ((long)out_x <= SHRT_MIN) ? SHRT_MIN : out_x);	*out_yp = ((long)out_y >= SHRT_MAX) ? SHRT_MAX : ( ((long)out_y <= SHRT_MIN) ? SHRT_MIN : out_y);	/* X_resolved_SymbolSize = XSymbolSize * StdSymbolSize[XSymbolNumber]; */PIGDBG("iXPigResolvePoint(%g, %g, %li, %li)\n", in_x, in_y, (long)*out_xp, (long)*out_yp);}/*----------------------------------------------------------------------------*/static void iXPigDrawSymbol(float xpos, float ypos){	short		x, y;	int		old_colour;	double xp = (double)xpos;	double yp = (double)ypos;	/* iXPigResolvePoint(xpos, ypos, &x, &y); */	iXPigResolvePoint(xp, yp, &x, &y);PIGDBG4("iXPigDrawSymbol(xpos=%g, ypos=%g)\n", xpos, ypos);	X_resolved_SymbolSize = XSymbolSize * StdSymbolSize[XSymbolNumber];	old_colour = XForegrColour;	XSetForeground(XtDisplay(MainXCanvas), GraphicsContext, CmsColourDefs[XSymbolColour]);	/* load up 'points' */	switch(XSymbolNumber){		case WPCROSS:		{			/* load up 'segments' with 'Cross' data for XDrawSegments */			int		Num = 2;			XSegment	segments[2];			segments[0].x1 = (short) x - X_resolved_SymbolSize;			segments[0].y1 = (short) y;			/* segments[0].x2 = (short) x + X_resolved_SymbolSize + 1; */			segments[0].x2 = (short) x + X_resolved_SymbolSize;			segments[0].y2 = (short) y;			segments[1].x1 = (short) x;			segments[1].y1 = (short) y - X_resolved_SymbolSize;			segments[1].x2 = (short) x;			/* segments[1].y2 = (short) y + X_resolved_SymbolSize + 1; */			segments[1].y2 = (short) y + X_resolved_SymbolSize;			XDrawSegments(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					segments, Num);			break;		}		case WPSPLAT:		{			/* load up 'segments' with 'Splat' data for XDrawSegments */			int		Num = 3;			XSegment	segments[3];			double		RootThree = 1.732;			double		X_offset;			X_offset = (X_resolved_SymbolSize * RootThree);			segments[0].x1 = (short) x;			segments[0].y1 = (short) y - (X_resolved_SymbolSize * 2);			segments[0].x2 = (short) x;			segments[0].y2 = (short) y + (X_resolved_SymbolSize * 2);			segments[1].x1 = (short) x + X_offset;			segments[1].y1 = (short) y + X_resolved_SymbolSize;			segments[1].x2 = (short) x - X_offset;			segments[1].y2 = (short) y - X_resolved_SymbolSize;			segments[2].x1 = (short) x - X_offset;			segments[2].y1 = (short) y + X_resolved_SymbolSize;			segments[2].x2 = (short) x + X_offset;			segments[2].y2 = (short) y - X_resolved_SymbolSize;			XDrawSegments(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					segments, Num);			break;		}		case WPSQUARE:		{			/* load up 'points' with 'Square' data for XDrawLines */			int		Num = 5;			XPoint		points[20];			points[0].x = (short) x - X_resolved_SymbolSize;			points[0].y = (short) y - X_resolved_SymbolSize;			points[1].x = (short) x - X_resolved_SymbolSize;			points[1].y = (short) y + X_resolved_SymbolSize;			points[2].x = (short) x + X_resolved_SymbolSize;			points[2].y = (short) y + X_resolved_SymbolSize;			points[3].x = (short) x + X_resolved_SymbolSize;			points[3].y = (short) y - X_resolved_SymbolSize;			points[4].x = (short) x - X_resolved_SymbolSize;			points[4].y = (short) y - X_resolved_SymbolSize;			XDrawLines(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					points, Num, CoordModeOrigin);			break;		}		case WPEX:		{			/* load up 'segments' with 'Ex' data for XDrawSegments */			int		Num = 2;			XSegment	segments[2];			segments[0].x1 = (short) x - X_resolved_SymbolSize;			segments[0].y1 = (short) y - X_resolved_SymbolSize;			segments[0].x2 = (short) x + X_resolved_SymbolSize;			segments[0].y2 = (short) y + X_resolved_SymbolSize;			segments[1].x1 = (short) x + X_resolved_SymbolSize;			segments[1].y1 = (short) y - X_resolved_SymbolSize;			segments[1].x2 = (short) x - X_resolved_SymbolSize;			segments[1].y2 = (short) y + X_resolved_SymbolSize;			XDrawSegments(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					segments, Num);			break;		}		case WPDIAMOND:		{			/* load up 'points' with 'Diamond' data for XDrawLines */			int		Num = 5;			XPoint		points[20];			points[0].x = (short) (x - X_resolved_SymbolSize);			points[0].y = (short) (y);			points[1].x = (short) (x);			points[1].y = (short) (y - X_resolved_SymbolSize);			points[2].x = (short) (x + X_resolved_SymbolSize);			points[2].y = (short) (y);			points[3].x = (short) (x);			points[3].y = (short) (y + X_resolved_SymbolSize);			points[4].x = (short) (x - X_resolved_SymbolSize);			points[4].y = (short) (y);			XDrawLines(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					points, Num, CoordModeOrigin);			break;		}		case WPPOINT:		{			/* load up 'points' with 'Point' data for XDrawLines */			int		Num = 5;			XPoint		points[20];			points[0].x = (short) x + X_resolved_SymbolSize;			points[0].y = (short) y + X_resolved_SymbolSize;			points[1].x = (short) x + X_resolved_SymbolSize;			points[1].y = (short) y - X_resolved_SymbolSize;			points[2].x = (short) x - X_resolved_SymbolSize;			points[2].y = (short) y - X_resolved_SymbolSize;			points[3].x = (short) x - X_resolved_SymbolSize;			points[3].y = (short) y + X_resolved_SymbolSize;			points[4].x = (short) x + X_resolved_SymbolSize;			points[4].y = (short) y + X_resolved_SymbolSize;			XFillPolygon(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					points, Num, Complex, CoordModeOrigin);			break;		}		case WPCIRCLE:		{			/* already have necessary info to draw a circle */			XDrawArc(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext,					(int) x - X_resolved_SymbolSize,					(int) y - X_resolved_SymbolSize,					(int) 2 * X_resolved_SymbolSize,					(int) 2 * X_resolved_SymbolSize,					0, 360 * 64);			break;		}	}	XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[old_colour]);		return;}static void iXPig_enable_menus(){	if( ! XtIsSensitive(menu_bar) )		XtSetSensitive(menu_bar, True);}static void iXPig_disable_menus(){	if( XtIsSensitive(menu_bar) )		XtSetSensitive(menu_bar, False);}static int blocking_callbacks = FALSE;static int iXPig_blocking_callbacks(void){	if(blocking_callbacks == TRUE) return TRUE;	blocking_callbacks = TRUE;	return FALSE;}static void show_message(const char *message){/* Set the text of the message window to message,  */	XmString xmessage = XmStringCreateLocalized(message);	XtVaSetValues(MessageWindow,		XmNlabelString, xmessage,		0);	XmStringFree(xmessage); 	add_to_command_history(message);	/* try XmUpdateDisplay */	XmUpdateDisplay(MessageWindow);}static void iXPig_unblock_callbacks(void){	blocking_callbacks = FALSE;}static Long iXPig_call_mouse (	Long *last_mainw, 	Long *last_mainb, 	float *last_mainx, 	float *last_mainy){	Long stat = MOUSE_EVENT;	if(FuncPtrs.MousFnc == NULL) 		return stat;	if(iXPig_blocking_callbacks() == TRUE)		return stat;	/* show_message(" "); */	stat = (*(FuncPtrs.MousFnc))		(last_mainw, last_mainb, last_mainx, last_mainy);	iXPig_unblock_callbacks();	return stat;}static void  iXPigDebugToggle(void){PIGDBG4("void  iXPigDebugToggle()\n");	debug_state = !debug_state;}/*----------------------------------------------------------------------------*/static Long iXPig_call_menu (Long *tag){	Long stat = MOUSE_EVENT;	if(FuncPtrs.MenuFnc == NULL) 		return stat;	if(iXPig_blocking_callbacks() == TRUE)		return stat;	/* show_message(" "); */

⌨️ 快捷键说明

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