[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

553.0. "COLOR PROBLEM WITH GKS" by 48284::DAN_M (Maya DAN) Fri Apr 07 1989 07:00

    I try to run a GKS Software on DECwindows-GKS V4.0.I have a color
    problem.If I run a color DECwindows application first (DECBURGER
    for ex) then the GKS Software fail.What I have to change, please
    to fix it?Thanks.
    Maya DAN @PAO

T.RTitleUserPersonal
Name
DateLines
553.1Do you think we are mind readers???OSLACT::OLAVDo it in parallel!Fri Apr 07 1989 07:548
> If I run a color DECwindows application first (DECBURGER for ex) then the
> GKS Software fail.What I have to change, please to fix it

You should start by giving us a clue by describing the problem (error messages
etc.)

Olav

553.2You are probably using up your color mapsAGBEAR::HORNERA.G.Bear, Low tech teddy bearSun Apr 09 1989 12:2813
    You really didn't give any details about your environment, but if you
    have a four plane color system (many VS2000's are 4 plane), then you
    really have to be careful what color applications that you run.  The
    four plane systems have only 16 color maps, and your default color
    settings can easily use 8 or more of these.  Once a color map has been
    allocated and used, it stays there.  If you run several programs that
    display things in color, you can easily use up your maps.  I've
    found that running a single color program on our systems here leaves
    insufficient color maps for GKS.  The most drastic result is a black
    on black window.

                   Dave

553.3"You are probably using up your color cells"EPIK::BUEHLERTact. At all times: tact.Mon Apr 10 1989 23:1110
    Minor correction in terminology to -.1
    
    There is a default color map on your workstation which applications
    typically share.  Applications may allocate their own colormaps so that
    they always have the most color resources possible available to them. 
    A color map is composed of cells.  It is the 'cells' of the default
    color map that Dave is refering to in 553.2 as 'color maps'.
    
John

553.4CURIE::CREANTue Apr 11 1989 17:55570
    I'm trying to write a DECwindows/GKS program to circumvent the "full
    colormap" problem.  It was suggested to me, by the GKS gurus, that
    I define a smaller colormap associated with the widget that is passed
    to GKS.  As I understand it, GKS takes the definitions in the
    associated colormap and appends them to the default device colormap.
    
    In the call to XCreateColorMap, I'm getting a stack dump with the 
    following error message:   "not a valid window ID".  
    
    If I substitute RootWindow(dpy,0) for XtWindow(toplevel)
    in that call, I get a stack dump on the call to DwtFetchWidget with 
    the same error message.

    I'd appreciate any suggestions.
    
    The code follows the formfeed (also posted in DECWINDOWS_PROGRAMMING).


    Thanks,

    - Terry

#module decw_gks "V1.0"
/*
**  AUTHOR:
**
**      Terry L. Crean, ISWS/Marlborough
**
**
*/
#include <stdio.h>
#include <gksdefs.h>
#include <descrip.h>
#include <decw$include/DECwDwtApplProg.h>
/* #include <dvr$public.h>  */
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>

#define	k_mainwindow			0
#define	k_menubar		 	1
#define	k_file_pulldown			2
#define k_file_menu			3

#define	GKS$_SUCCESS	0
#define FUNC_SUCCESS	0
#define MIN_X  0.000000
#define MAX_X  0.800000
#define MIN_Y  0.000000
#define MAX_Y  0.609524
#define MIN_PIC_X  0.019048
#define MIN_PIC_Y  -.000495
#define MAX_PIC_X  0.780952
#define MAX_PIC_Y  0.590476
#define color1_num  0
#define color2_num  1
#define color3_num  2
#define num_planes  0	/* number of planes in plane mask for XAllocColorCells */
#define num_colors  3	/* number of colors to be set in the color map */

char			*UID_database[] = { "decw_gks.uid" };
static 	int 		doDefineColor( ), alloc = AllocNone;
static	DRMHierarchy	Hierarchy;
static	DRMType		*dummy;
static 	DwtCallback 	callback_arg[2];
static  char 		*color1_name="blue", *color2_name="red", *color3_name="green";
static	unsigned int	status_return;	/* return value from XAllocColorCells */

static	unsigned long	plane_masks_return, pixels_return[num_colors];

Widget		toplevel, mainwidget, WidgetID[ 50 ];
Display 	*dpy;
GC 		gc;
Screen 		*screen;
XGCValues 	xgcv;
Window 		work_area;
Colormap 	colormap_id_return;
XColor		color_defs[num_colors], scratch;
Bool		contig = FALSE;

/*
 * Forward declarations
 */
static	void	error ();
static	void	exitproc ();
static	void	WidgetCreated ();

$DESCRIPTOR (item1_text_13, "A Sample Text String");

main( argc, argv)
    int	    argc;
    char    *argv[];
{
	float	ratio_x = 0.0, 	ratio_y = 0.0;
 
	int   	wsid = 1,
		ret_val,
		ws_type,
		largest_viewport = 2,
		stat;

	char	conid_buffer[256];

	struct	dsc$descriptor_s conid = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 
					   conid_buffer };
	DRMCount	callback_num = 2;
	DRMRegisterArg  callback_namevec[] = 
   	{  
			{ "exitproc", exitproc },
			{ "WidgetCreated", WidgetCreated }
	};

	DwtInitializeDRM();

	toplevel = XtInitialize("CASE Engineering Demonstration",
				"TopLevel",
				NULL,
				0,
				&argc,
				&argv );
	dpy = XtDisplay(toplevel);
	screen = XDefaultScreenOfDisplay(dpy);

	if ( DwtOpenHierarchy(	1,
				UID_database,
				NULL,
				&Hierarchy ) != DRMSuccess )
				error( "Can't open hierarchy!" );



/*
** Create a new blank colormap to be associated with the shell widget
*/
	colormap_id_return = XCreateColormap ( 
			     dpy, 		/* display */
			     XtWindow(toplevel), /* window for which the colormap will be created */
			     XDefaultVisualOfScreen(screen),
			     alloc );		/* allocation mode */
/*
** Allocate color cells in the newly created colormap
*/
	status_return = XAllocColorCells (
			dpy,
			colormap_id_return,
			contig,
			&plane_masks_return,
			num_planes,
			pixels_return,
			num_colors );
	if (status_return == 0 )
	   printf ("\n error allocating color cells; return = %d",
		   status_return);
	else	/* Store colors in allocated color cells */
	   {
/*
** Get the values for our colors from the default color map
*/
		if (!XAllocNamedColor (dpy, 
				       DefaultColormapOfScreen (screen),
	                               color1_name, 
			 	       &scratch, 
				       &color_defs[color1_num] )) 
	           printf ("\n Can't get color %d", color1_num);
		else
		   {
			color_defs[color1_num].pixel = pixels_return[color1_num];
			color_defs[color1_num].flags = DoRed|DoGreen|DoBlue;
		   }

		if (!XAllocNamedColor (dpy, 
				       DefaultColormapOfScreen (screen),
	                               color2_name, 
			 	       &scratch, 
				       &color_defs[color2_num] )) 
	           printf ("\n Can't get color %d", color2_num);
		else
		   {
			color_defs[color2_num].pixel = pixels_return[color2_num];
			color_defs[color2_num].flags = DoRed|DoGreen|DoBlue;
		   }

		if (!XAllocNamedColor (dpy, 
				       DefaultColormapOfScreen (screen),
	                               color3_name, 
			 	       &scratch, 
				       &color_defs[color3_num] )) 
	           printf ("\n Can't get color %d", color3_num);
		else
		   {
			color_defs[color3_num].pixel = pixels_return[color3_num];
			color_defs[color3_num].flags = DoRed|DoGreen|DoBlue;
		   }
	   }

	   XStoreColors (dpy,
			colormap_id_return,
			color_defs,
			num_colors );
/*
** Set the colormap for the shell widget
*/
	XSetWindowColormap (dpy,
			   XtWindow(toplevel),
			   colormap_id_return );


	DwtRegisterDRMNames(    callback_namevec, callback_num );

	if ( DwtFetchWidget(	Hierarchy,
				"mainWindow",
				toplevel,
				&mainwidget,
				&dummy ) != DRMSuccess )
				error( "Can't fetch window!" );

/*	work_area = XtWindow(mainwidget);
	xgcv.background = doDefineColor(2); 
	xgcv.foreground = doDefineColor(3); 
	gc = XCreateGC(dpy, work_area, GCForeground | GCBackground, &xgcv);   
*/
	XtManageChild( mainwidget );

	XtRealizeWidget( toplevel );
/*
 * Build the connection identifier
 */
  	sprintf (conid.dsc$a_pointer, "%d", mainwidget );
	conid.dsc$w_length = strlen ( conid.dsc$a_pointer );

	ret_val = set_up ( &wsid, &largest_viewport, &ratio_x, &ratio_y,
			   &ws_type, &conid );

	if (ret_val == FUNC_SUCCESS)
	   {
	   display_pic ( &wsid, &largest_viewport, &ratio_x, &ratio_y, 
			   &ws_type );
	   }

	XtMainLoop ();

	end_program 	( &wsid );

}

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**	This is just an error reporting procedure.
**
**--
*/

void error( char    *error_string )
{
    printf( "%s\n", error_string );
}

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**	This is the exitproc callback routine.
**
**      Just exits the program.
**--
*/

void	exitproc( w, tag )
	Widget *w;
	int *tag;
{
	exit(1);
}

/*
**++
**  FUNCTIONAL DESCRIPTION:
**
**	This is the WidgetCreated  callback routine.
**
**      Registers the widget ID's in an array when the widget is created.
**
**--
*/

static void WidgetCreated ( w, tag )
    Widget	*w;
    int *tag;
{
    WidgetID[ *tag ] = w;
}

/*============================================================================*/
/*	Set Up Module							      */
/*									      */
/*	This routine does the initial set-up necessary to access GKS:  open   */
/*	GKS, open the workstation, activate the workstation, and establish    */
/*	the workstation window & viewport				      */
/*============================================================================*/

set_up	( wsid_ptr, largest_viewport_ptr, ratio_x_ptr, ratio_y_ptr, 
	  ws_type_ptr, conid_ptr )
int	*wsid_ptr,
	*largest_viewport_ptr,
	*ws_type_ptr;

float	*ratio_x_ptr,
	*ratio_y_ptr;

struct	dsc$descriptor_s *conid_ptr;  /* !!! */
{
	int 	error_status, 
		category,
		item_data_length,
		dummy_int,
		def_mode, regen_flag;

	float	display_x, display_y,
		min_display_x, min_display_y,
		max_display_x, max_display_y;

	$DESCRIPTOR (error_file, "sys$error:");
	$DESCRIPTOR (dummy_dsc, "dsc$descriptor_s");

/******************************************************************************/
/*	open GKS 						      	      */
/******************************************************************************/
	gks$open_gks	( &error_file );
/******************************************************************************/
/*	check the workstation category; if it is not OUTIN, then abort        */
/******************************************************************************/
/*	gks$inq_ws_category ( &GKS$K_WSTYPE_DEFAULT, &error_status, &category);*/
	/* check the widget one - not just the default !!! */
	gks$inq_ws_category ( &GKS$K_DECWINDOWS_WIDGET, &error_status, &category);

/*	if ( category != GKS$K_WSCAT_OUTIN ) 
	   {
	   printf ("\n The workstation type is not OUTIN; program aborting");
	   return 1;
	   } */
/******************************************************************************/
/*	open & activate the workstation			      		      */
/******************************************************************************/
/*	gks$open_ws 	( wsid_ptr, &GKS$K_CONID_DEFAULT,
			&GKS$K_WSTYPE_DEFAULT );  */
	gks$open_ws 	( wsid_ptr, conid_ptr, &GKS$K_DECWINDOWS_WIDGET ); 
	gks$activate_ws ( wsid_ptr );
/******************************************************************************/
/*	get the workstation type; this information is needed for the call     */
/*	to gks$inq_max_ds_size						      */
/******************************************************************************/
	gks$inq_ws_type ( wsid_ptr, &error_status, &dummy_dsc, ws_type_ptr,
			  &dummy_int);
	if ( error_status != GKS$_SUCCESS ) 
	   {
	   printf("\n Error checking workstation type; error: %d",error_status); 
	   return 1;
	   }
/******************************************************************************/
/*	make sure that the deferral mode and regeneration flag are properly   */
/*	set.								      */
/******************************************************************************/
/*	gks$inq_def_defer_state ( ws_type_ptr, &error_status, &def_mode, 
				  &regen_flag );
	if ( error_status != GKS$_SUCCESS ) 
	   {
	   printf("\n Error checking defer state; error: %d",error_status); 
	   return 1;
	   } */
/******************************************************************************/
/*	defer output as long as possible and suppress implicit regenerations  */
/******************************************************************************/
/*	if ( ( def_mode != GKS$K_ASTI ) ||
	     ( regen_flag != GKS$K_IRG_SUPPRESSED ))
	   {
	   gks$set_defer_state ( wsid_ptr, &GKS$K_ASTI, &GKS$K_IRG_SUPPRESSED);
	   } */
/******************************************************************************/
/*	check the maximum X & Y for this device				      */
/******************************************************************************/
	gks$inq_max_ds_size ( ws_type_ptr, &error_status, &dummy_int, 
			      &display_x, &display_y, &dummy_int, 
			      &dummy_int);
	if ( error_status != GKS$_SUCCESS)
	   {
	   printf("\n Error checking max_ds_size; error: %d",error_status); 
	   return 1;
	   }
	printf("\n max_display_x: %f max_display_y: %f",display_x,display_y);
/******************************************************************************/
/*	Calculate the normalized display ratio based on the physical device   */
/*	size								      */
/******************************************************************************/
/*	display_x = 900;
	display_y = 800; */
	*ratio_y_ptr = ( ( display_x > display_y ) ? 
			 ( display_y / display_x ) : 1.0 );
	*ratio_x_ptr = ( ( display_x > display_y) ? 
			 1.0 : ( display_x / display_y ) );

	gks$select_xform( largest_viewport_ptr ); 
/******************************************************************************/
/*	use the UIL defined window as the viewport		      	      */
/******************************************************************************/
	min_display_x = 0.0;						      
	min_display_y = 0.0;						      
	max_display_x = display_x;
	max_display_y = display_y; 					      
	gks$set_ws_window ( wsid_ptr, &0.0, ratio_x_ptr, &0.0, 
			    ratio_y_ptr );
	gks$set_ws_viewport ( wsid_ptr, &min_display_x, &max_display_x, 
			      &min_display_y, &max_display_y );

	return 0;
}    
/*============================================================================*/
/*	Display Picture Module						      */
/*									      */
/*	This routine sets the workstation window & viewport and displays the  */
/*	picture.							      */
/*============================================================================*/
display_pic	( wsid_ptr, largest_viewport_ptr, ratio_x_ptr, ratio_y_ptr,
		  ws_type_ptr )
int	*wsid_ptr,
	*largest_viewport_ptr,
	*ws_type_ptr;

float	*ratio_x_ptr,
	*ratio_y_ptr;
{
	float 	item1_x_13 = 0.228571,
		item1_y_13 = 0.409524,
	 	item1_x_11[5] = { 0.019048, 0.019048, 0.780952, 0.780952, 
				  0.019048 },
      		item1_y_11[5] = { 0.019048, 0.590476, 0.590476, 0.019048, 
				  0.019048 },
		text_height = { 0.075561 },
	 	linewidth = 1.966942;

	int   	linetype = 1,
		text_font_prec[1][2] = { -15, 2 };

	float	view_min_x, view_max_x, view_min_y, view_max_y,
		win_min_x, win_max_x, win_min_y, win_max_y,
		xform_matrix[6], xform_matrix2[6];
/*****************************************************************************/
/*	set the window & viewport					     */	
/*****************************************************************************/
	win_min_x = 0.0;
	win_max_x = MAX_X;
	win_min_y = 0.0;
	win_max_y = MAX_Y;

	gks$set_window ( largest_viewport_ptr, &win_min_x, &win_max_x, 
			 &win_min_y, &win_max_y);

	view_min_x = 0.0;
	view_max_x = *ratio_x_ptr;
	view_min_y = 0.0;
	view_max_y = *ratio_y_ptr;
	gks$set_viewport ( largest_viewport_ptr, &view_min_x, &view_max_x,
			   &view_min_y, &view_max_y);
/*****************************************************************************/
/*	create a segment and display all polylines, text and GDPs in this    */
/*	segment   							     */
/*****************************************************************************/
	set_transformation ( ratio_x_ptr, ratio_y_ptr, &xform_matrix2 );

	gks$create_seg ( &1 ); 

	gks$set_pline_linewidth ( &linewidth );
	gks$set_pline_linetype ( &linetype );
	gks$polyline ( &5, item1_x_11, item1_y_11 ); 

	gks$set_text_height ( &text_height );
/*	gks$set_text_fontprec ( &text_font_prec[1][0], &text_font_prec[1][1] ); */
	gks$text ( &item1_x_13, &item1_y_13, &item1_text_13 );

	gks$close_seg ( &1 ); 
	return;

}
/*============================================================================*/
/*	set segment transformation module				      */
/*									      */
/*	create the segment transformation matrix			      */
/*	use the center of the picture as the fixed point		      */
/*	translate the center of the picture, to the center of the viewport    */
/*============================================================================*/
set_transformation ( ratio_x_ptr, ratio_y_ptr, xform_matrix2_ptr )
float	*ratio_x_ptr, *ratio_y_ptr,
	*xform_matrix2_ptr;
{
	float	fixed_pt_x, fixed_pt_y,
		scale_x, scale_y,
		translation_x, translation_y,
		zoom_x, zoom_y, zoom_factor,
		xform_matrix[6];


	fixed_pt_x = 0.0;
	fixed_pt_y = 0.0;
	scale_x = MAX_X / *ratio_x_ptr;
	scale_y = MAX_Y / *ratio_y_ptr;
	translation_x = (*ratio_x_ptr / 2.0) -
			(((MAX_PIC_X - MIN_PIC_X) / 2.0) + MIN_PIC_X);
	translation_y = (*ratio_y_ptr / 2.0) -
			(((MAX_PIC_Y - MIN_PIC_Y) / 2.0) + MIN_PIC_Y);
	gks$eval_xform_matrix ( &fixed_pt_x, &fixed_pt_y, &translation_x, 
			&translation_y, &0.0, &scale_x, &scale_y, 
			&GKS$K_COORDINATES_NDC, &xform_matrix );

	fixed_pt_x = *ratio_x_ptr / 2.0;
	fixed_pt_y = *ratio_y_ptr / 2.0;
	zoom_x = *ratio_x_ptr / scale_x;
	zoom_y = *ratio_y_ptr / scale_y;
	if ( zoom_x > zoom_y )
   	   zoom_factor = zoom_x;
	else
   	   zoom_factor = zoom_y;
	gks$accum_xform_matrix ( &xform_matrix, &fixed_pt_x, 
		&fixed_pt_y, &0.0, &0.0, &0.0, &zoom_factor, 
		&zoom_factor, &GKS$K_COORDINATES_NDC, xform_matrix2_ptr ); 

	return;
}
/*============================================================================*/
/*	End Program Module						      */
/*									      */
/*	This routine deactivates the workstation, closes the workstation      */
/*	and closes GKS							      */
/*============================================================================*/
end_program ( wsid_ptr )
int 	*wsid_ptr;
{
	gks$deactivate_ws ( wsid_ptr );

/*	gks$close_ws ( wsid_ptr ); */

	gks$close_gks ( );
}
/******* Create color ************************/
static int doDefineColor(n)
{
    int pixel;
    XColor exact_color,screen_color;
    char *colors[] = {
	"dark slate blue",
	"light grey",
	"black"
	};

    if ((XDefaultVisualOfScreen(screen))->class == PseudoColor 
        ||  (XDefaultVisualOfScreen(screen))->class == DirectColor)
        if (XAllocNamedColor(dpy, XDefaultColormapOfScreen(screen),
            colors[n-1], &screen_color, &exact_color))
                return screen_color.pixel; 
            else
	        printf("Color not allocated!");
     else 
        switch (n) {
            case 1:		return XBlackPixelOfScreen(screen); break; 
	    case 2:		return XWhitePixelOfScreen(screen); break;
            case 3:		return XBlackPixelOfScreen(screen); break;
        }
}   


553.5More details about the COLOR PROBLEM WITH GKS!EVOAI2::DAN_MMaya DANMon Apr 17 1989 10:4319
    Thank you all for the answers.I am sorry to give so few information.In
    fact it was a customer question and I was waiting to have more details.
    So what I know about the problem:
    - The workstation type is 211.The customer told me the following:
    The GKS application hetried use 7 colors, DECwindows 2, so he tried
    to use the same.But he had an error message:'X Toolkit Warning:
    DwtDrm_realizeColorTable detected errorCouldn't load color 'blue''-
    Not found (DRM not Found).There is no error message for the second
    color, which is well displayed.Sometimes , the GKS application return
    when starting:X Tollkit warning:WINDOW MANAGER IS CONFUSED.He asks
    if to use the same colors for the 2 applications, he must find the
    'correpondance' between the GKS description from 0 to 1 and the
    DECwindows one from 0 to 35280?he would like to know what he has
    to put in the GKS and the DECwindows application to use the colors
    already in the color table?
    Thank you for the help and sorry for the bad problem description.
     
    

553.6STAR::ORGOVANVince OrgovanMon Apr 17 1989 20:1024
    RE: .5 correspondence between DECwindows and GKS colors
    
    My understanding of the GKS implementation is that GKS allocates
    read/write colormap cells from the default color map. In the X
    protocol, when a client allocates color cells there are no guarantees
    about which cells the server will allocate. This makes it very hard
    to establish any correspondence between the DECwindows and GKS color 
    numbers. 
    
    For example, suppose you have a 4-plane color system and 5 colors
    have already been allocated for other clients (background color,
    foreground color, root window color, white and black). Then you run
    your GKS program which allocates 8 color map cells. Since 0-4 are
    taken, GKS might get 5-12. If you run the same GKS program tomorrow
    after running some other client that allocated two color cells, GKS
    might get 7-14. If you run the same GKS program with a third party
    server that allocates the color map pixels in reverse order (which 
    is perfectly legal in X) you would get a third answer.
    
    The bottom line is that there is no way in the current GKS product
    to ask it to use the color map cells that are already allocated, 
    and there is no easy way to find out from another X client which
    ones were allocated to GKS.