Пример #1
0
int set_Cmiss_region_or_group(struct Parse_state *state,
	void *region_address_void, void *group_address_void)
{
	Cmiss_region_id *region_address = reinterpret_cast<Cmiss_region_id*>(region_address_void);
	Cmiss_field_group_id *group_address = reinterpret_cast<Cmiss_field_group_id*>(group_address_void);
	if (!(state && region_address && *region_address && group_address && !*group_address))
		return 0;
	const char *current_token = state->current_token;
	int return_code = 1;
	if (!current_token)
	{
		display_message(WARNING_MESSAGE, "Missing region/group path");
		display_parse_state_location(state);
		return_code =  0;
	}
	else if (Parse_state_help_mode(state))
	{
		display_message(INFORMATION_MESSAGE, " REGION_PATH/GROUP");
	}
	else
	{
		char *region_path = 0;
		char *field_name = 0;
		Cmiss_region_id output_region = 0;
		if (Cmiss_region_get_partial_region_path(*region_address, current_token,
			&output_region, &region_path, &field_name) && output_region)
		{
			REACCESS(Cmiss_region)(region_address, output_region);
			if (field_name)
			{
				Cmiss_field *field = FIND_BY_IDENTIFIER_IN_MANAGER(Computed_field,name)(
					field_name, Cmiss_region_get_Computed_field_manager(output_region));
				*group_address = Cmiss_field_cast_group(field);
				if (0 == *group_address)
				{
					return_code = 0;
				}
			}
			if (return_code)
			{
				shift_Parse_state(state, 1);
			}
		}
		else
		{
			return_code = 0;
		}
		if (!return_code)
		{
			display_message(ERROR_MESSAGE, "Invalid region or group path: %s", current_token);
			display_parse_state_location(state);
		}
		DEALLOCATE(region_path);
		DEALLOCATE(field_name);
	}
	return return_code;
}
Пример #2
0
int set_Cmiss_region(struct Parse_state *state, void *region_address_void,
	void *root_region_void)
{
	const char *current_token;
	int return_code;
	struct Cmiss_region *region, **region_address, *root_region;

	ENTER(set_Cmiss_region);
	if (state && (root_region = static_cast<struct Cmiss_region *>(root_region_void)) &&
		(region_address = static_cast<struct Cmiss_region **>(region_address_void)))
	{
		if ((current_token = state->current_token))
		{
			if (!Parse_state_help_mode(state))
			{
				region = Cmiss_region_find_subregion_at_path(root_region, current_token);
				if (region)
				{
					//-- REACCESS(Cmiss_region)(region_address, region);
					return_code = shift_Parse_state(state, 1);
				}
				else
				{
					display_message(ERROR_MESSAGE,
						"set_Cmiss_region:  Could not find subregion %s", current_token);
					display_parse_state_location(state);
					return_code = 0;
				}
			}
			else
			{
				display_message(INFORMATION_MESSAGE," PATH_TO_REGION");
				if (*region_address)
				{
					char *path = Cmiss_region_get_path(*region_address);
					display_message(INFORMATION_MESSAGE, "[%s]", path);
					DEALLOCATE(path);
				}
				return_code = 1;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE, "Missing region path");
			display_parse_state_location(state);
			return_code = 0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE, "set_Cmiss_region.  Missing state");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
}
Пример #3
0
/***************************************************************************//**
 * Modifier function to set the region, region path and field name.
 * Fields must not be the same name as a child region.
 *
 * Examples:
 *   /heart/coordinates = region path and field name
 *   heart              = region path only
 *   coordinates        = field name only
 * @param region_path_and_name a struct Cmiss_region_path_and_name which if
 *   set contains an ACCESSed region and allocated path and name which caller
 *   is required to clean up. Name may be NULL if path is fully resolved.
 */
static int set_region_path_and_or_field_name(struct Parse_state *state,
	void *region_path_and_name_void, void *root_region_void)
{
	const char *current_token;
	int return_code;
	struct Cmiss_region_path_and_name *name_data;
	struct Cmiss_region *root_region;

	ENTER(set_region_path_and_or_field_name);
	if (state && (name_data = (struct Cmiss_region_path_and_name *)region_path_and_name_void) &&
		(root_region = (struct Cmiss_region *)root_region_void))
	{
		current_token = state->current_token;
		if (!current_token)
		{
			display_message(WARNING_MESSAGE, "Missing region path and/or field name");
			display_parse_state_location(state);
			return_code = 0;
		}
		else if (Parse_state_help_mode(state))
		{
			display_message(INFORMATION_MESSAGE, " REGION_PATH|REGION_PATH/FIELD_NAME|FIELD_NAME");
			return_code = 1;
		}
		else if (Cmiss_region_get_partial_region_path(root_region, current_token,
			&name_data->region, &name_data->region_path, &name_data->name))
		{
			ACCESS(Cmiss_region)(name_data->region);
			if (!name_data->name || (NULL == strchr(name_data->name, CMISS_REGION_PATH_SEPARATOR_CHAR)))
			{
				return_code = shift_Parse_state(state, 1);
			}
			else
			{
				display_message(ERROR_MESSAGE, "Bad region path and/or field name: %s",current_token);
				display_parse_state_location(state);
				return_code = 0;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE,
				"set_region_path_and_or_field_name.  Failed to get path and name");
			return_code = 0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"set_region_path_and_or_field_name.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
}
Пример #4
0
/**
 * Executes a GFX DEFINE GLYPH command.
 */
int gfx_define_glyph(struct Parse_state *state,
	void *glyph_name_void, void *define_glyph_data_void)
{
	int return_code = 1;
	Define_glyph_data *define_glyph_data = static_cast<Define_glyph_data *>(define_glyph_data_void);
	if ((state) && (define_glyph_data))
	{
		if (state->current_token)
		{
			const char *glyph_name = static_cast<char *>(glyph_name_void);
			bool process = false;
			if (glyph_name)
			{
				process = true;
			}
			else
			{
				if (Parse_state_help_mode(state))
				{
					glyph_name = "GLYPH_NAME";
					Option_table *option_table = CREATE(Option_table)();
					Option_table_add_entry(option_table, "GLYPH_NAME",
						(void *)glyph_name, define_glyph_data_void, gfx_define_glyph);
					return_code = Option_table_parse(option_table, state);
					DESTROY(Option_table)(&option_table);
				}
				else
				{
					glyph_name = state->current_token;
					shift_Parse_state(state, 1);
					process = true;
				}
			}
			if (process)
			{
				char *scene_path_name = 0;
				struct Option_table *option_table = CREATE(Option_table)();
				Option_table_add_help(option_table,
					"The 'scene' option defines a static glyph from the named graphics "
					"at the region/scene path.");
				/* scene (graphics) */
				Option_table_add_string_entry(option_table, "scene",
					&scene_path_name, " [/REGION_PATH.]GRAPHICS_NAME");

				return_code = Option_table_multi_parse(option_table, state);
				if (return_code)
				{
					cmzn_graphics* graphics = 0;
					const char *scene_name = 0;
					const char *graphics_name = 0;
					if (scene_path_name)
						export_object_name_parser(scene_path_name, &scene_name, &graphics_name);
					cmzn_region *input_region =
						cmzn_region_find_subregion_at_path(define_glyph_data->root_region, scene_name);
					if (input_region && graphics_name)
					{
						cmzn_scene_id scene = cmzn_region_get_scene(input_region);
						graphics = cmzn_scene_find_graphics_by_name(scene, graphics_name);
						cmzn_scene_destroy(&scene);
					}
					if (!graphics)
					{
						display_message(ERROR_MESSAGE,
							"gfx_define_glyph.  Invalid scene region path or graphics name");
						return_code = 0;
					}
					else
					{
						cmzn_glyphmodule_begin_change(define_glyph_data->glyphmodule);
						cmzn_glyph_id glyph = cmzn_glyphmodule_find_glyph_by_name(define_glyph_data->glyphmodule, glyph_name);
						if (glyph)
						{
							struct GT_object *graphics_object = cmzn_graphics_copy_graphics_object(
								graphics);
							if (!cmzn_glyph_set_graphics_object(glyph, graphics_object))
							{
								display_message(ERROR_MESSAGE, "gfx_define_glyph.  Unable to change glyph");
								return_code = 0;
							}
							DEACCESS(GT_object)(&graphics_object);
						}
						else
						{
							glyph = cmzn_glyphmodule_create_static_glyph_from_graphics(define_glyph_data->glyphmodule,
								graphics);
							if ((CMZN_OK != cmzn_glyph_set_name(glyph, glyph_name)) ||
								(CMZN_OK != cmzn_glyph_set_managed(glyph, true)))
							{
								display_message(ERROR_MESSAGE, "gfx_define_glyph.  Failed");
								return_code = 0;
							}
						}
						cmzn_glyph_destroy(&glyph);
						cmzn_glyphmodule_end_change(define_glyph_data->glyphmodule);
					}
					cmzn_graphics_destroy(&graphics);
					cmzn_region_destroy(&input_region);
					if (scene_name)
						DEALLOCATE(scene_name);
					if (graphics_name)
						DEALLOCATE(graphics_name);
				}
				if (scene_path_name)
					DEALLOCATE(scene_path_name);
				DESTROY(Option_table)(&option_table);
			}
		}
		else
		{
			display_message(ERROR_MESSAGE, "Missing glyph name");
			display_parse_state_location(state);
			return_code=0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE, "gfx_define_glyph.  Invalid argument(s)");
		return_code = 0;
	}
	return (return_code);
}
Пример #5
0
int set_Glyph(struct Parse_state *state, void *glyphAddress_void,
	void *glyphmodule_void)
{
	int return_code;
	cmzn_glyph **glyphAddress = reinterpret_cast<cmzn_glyph **>(glyphAddress_void);
	cmzn_glyphmodule *glyphmodule = reinterpret_cast<cmzn_glyphmodule *>(glyphmodule_void);
	if (state && glyphAddress && glyphmodule)
	{
		const char *current_token = state->current_token;
		if (current_token)
		{
			if (!Parse_state_help_mode(state))
			{
				if (fuzzy_string_compare(current_token, "NONE"))
				{
					if (*glyphAddress)
					{
						cmzn_glyph_destroy(glyphAddress);
					}
					return_code=1;
				}
				else
				{
					cmzn_glyph *glyph = cmzn_glyphmodule_find_glyph_by_name(glyphmodule, current_token);
					if (glyph)
					{
						if (*glyphAddress)
						{
							cmzn_glyph_destroy(glyphAddress);
						}
						*glyphAddress = glyph;
						return_code = 1;
					}
					else
					{
						display_message(ERROR_MESSAGE, "Unknown glyph : %s", current_token);
						return_code = 0;
					}
				}
				shift_Parse_state(state, 1);
			}
			else
			{
				display_message(INFORMATION_MESSAGE," GLYPH_NAME|none");
				/* if possible, then write the name */
				cmzn_glyph *glyph = *glyphAddress;
				if (glyph)
				{
					display_message(INFORMATION_MESSAGE, "[%s]", glyph->getName());
				}
				else
				{
					display_message(INFORMATION_MESSAGE, "[none]");
				}
				return_code = 1;
			}
		}
		else
		{
			display_message(WARNING_MESSAGE, "Missing glyph name");
			display_parse_state_location(state);
			return_code = 0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE, "set_Glyph.  Invalid argument(s)");
		return_code = 0;
	}
	return (return_code);
}
Пример #6
0
int set_Cmiss_region_path(struct Parse_state *state, void *path_address_void,
	void *root_region_void)
/*******************************************************************************
LAST MODIFIED : 13 January 2003

DESCRIPTION :
Modifier function for entering a path to a Cmiss_region, starting at
<root_region>.
==============================================================================*/
{
	const char *current_token;
	char **path_address;
	int return_code;
	struct Cmiss_region *region, *root_region;

	ENTER(set_Cmiss_region_path);
	if (state && (root_region = (struct Cmiss_region *)root_region_void))
	{
		if ((current_token = state->current_token))
		{
			if (!Parse_state_help_mode(state))
			{
				region = Cmiss_region_find_subregion_at_path(
					root_region, current_token);
				if (region)
				{
					if ((path_address = (char **)path_address_void))
					{
						if (*path_address)
						{
							DEALLOCATE(*path_address);
						}
						if ((*path_address = duplicate_string(current_token)))
						{
							return_code = shift_Parse_state(state, 1);
						}
						else
						{
							display_message(ERROR_MESSAGE,
								"set_Cmiss_region_path.  Could not allocate memory for path");
							return_code = 0;
						}
					}
					else
					{
						display_message(ERROR_MESSAGE,
							"set_Cmiss_region_path.  Missing path_address");
						return_code = 0;
					}
					DEACCESS(Cmiss_region)(&region);
				}
				else
				{
					display_message(ERROR_MESSAGE, "Invalid region path: %s",
						current_token);
					display_parse_state_location(state);
					return_code = 0;
				}
			}
			else
			{
				display_message(INFORMATION_MESSAGE," PATH_TO_REGION");
				if ((path_address = (char **)path_address_void) && (*path_address))
				{
					display_message(INFORMATION_MESSAGE, "[%s]", *path_address);
				}
				return_code = 1;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE, "Missing region path");
			display_parse_state_location(state);
			return_code = 0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE, "set_Cmiss_region_path.  Missing state");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* set_Cmiss_region_path */