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, ®ion_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; }
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); }
/***************************************************************************//** * 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); }
static int set_Cmiss_mesh(struct Parse_state *state, void *region_void, void *mesh_address_void) { Cmiss_region_id region = reinterpret_cast<Cmiss_region_id>(region_void); Cmiss_mesh_id *mesh_address = reinterpret_cast<Cmiss_mesh_id*>(mesh_address_void); if (!(state && region && mesh_address)) return 0; const char *current_token = state->current_token; int return_code = 1; if (!current_token) { display_message(WARNING_MESSAGE, "Missing mesh name"); display_parse_state_location(state); return_code = 0; } else if ((0 == strcmp(PARSER_HELP_STRING, current_token)) || (0 == strcmp(PARSER_RECURSIVE_HELP_STRING, current_token))) { display_message(INFORMATION_MESSAGE, " ELEMENT_GROUP_FIELD_NAME|[GROUP_NAME.]cmiss_mesh_1d|cmiss_mesh_2d|cmiss_mesh_3d["); if (*mesh_address) { char *mesh_name = Cmiss_mesh_get_name(*mesh_address); make_valid_token(&mesh_name); display_message(INFORMATION_MESSAGE, "%s]", mesh_name); DEALLOCATE(mesh_name); } else { display_message(INFORMATION_MESSAGE, "none]"); } } else { Cmiss_field_module_id field_module = Cmiss_region_get_field_module(region); Cmiss_mesh_id new_mesh = Cmiss_field_module_find_mesh_by_name(field_module, current_token); if (new_mesh) { if (*mesh_address) Cmiss_mesh_destroy(mesh_address); *mesh_address = new_mesh; shift_Parse_state(state, 1); } else { display_message(ERROR_MESSAGE, "Invalid mesh: %s", current_token); display_parse_state_location(state); return_code = 0; } Cmiss_field_module_destroy(&field_module); } return return_code; }
/** * 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); }
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); }
int gfx_define_font(struct Parse_state *state, void *dummy_to_be_modified,void *graphics_module_void) /******************************************************************************* LAST MODIFIED : 12 March 2008 DESCRIPTION : Executes a GFX DEFINE FONT command. ==============================================================================*/ { const char *current_token, *font_name; int return_code; Cmiss_graphics_module_id graphics_module = 0; if (state && (graphics_module = (Cmiss_graphics_module_id)graphics_module_void)) { if (NULL != (current_token = state->current_token)) { if (strcmp(PARSER_HELP_STRING,current_token)&& strcmp(PARSER_RECURSIVE_HELP_STRING,current_token)) { font_name = current_token; if (shift_Parse_state(state,1)&& (current_token=state->current_token)) { Cmiss_graphics_font_id font = Cmiss_graphics_module_find_font_by_name( graphics_module, font_name); if (!font) { font = Cmiss_graphics_module_create_font(graphics_module); Cmiss_graphics_font_set_name(font, font_name); } Cmiss_graphics_font_type font_type = Cmiss_graphics_font_get_type(font); Cmiss_graphics_font_true_type true_type = Cmiss_graphics_font_get_true_type(font); char *font_type_string = 0; char *true_type_string = 0; int number_of_valid_strings_font_type = 0; int number_of_valid_strings_true_type = 0; const char **valid_font_type_strings = ENUMERATOR_GET_VALID_STRINGS(Cmiss_graphics_font_type)( &number_of_valid_strings_font_type, (ENUMERATOR_CONDITIONAL_FUNCTION(Cmiss_graphics_font_type) *)NULL, (void *)NULL); std::string all_font_types = " "; for (int i = 0; i < number_of_valid_strings_font_type; i++) { if (i) all_font_types += "|"; all_font_types += valid_font_type_strings[i]; } const char *all_font_types_help = all_font_types.c_str(); const char **valid_font_true_type_strings = ENUMERATOR_GET_VALID_STRINGS(Cmiss_graphics_font_true_type)( &number_of_valid_strings_true_type, (ENUMERATOR_CONDITIONAL_FUNCTION(Cmiss_graphics_font_true_type) *)NULL, (void *)NULL); std::string all_font_true_types = " "; for (int i = 0; i < number_of_valid_strings_true_type; i++) { if (i) all_font_true_types += "|"; all_font_true_types += valid_font_true_type_strings[i]; } const char *all_font_true_types_help = all_font_true_types.c_str(); struct Option_table *option_table = CREATE(Option_table)(); int bold_flag = 0; int italic_flag = 0; float depth = (float)Cmiss_graphics_font_get_depth(font); int size = Cmiss_graphics_font_get_size(font); /* bold */ Option_table_add_entry(option_table, "bold", (void *)&bold_flag, NULL, set_char_flag); Option_table_add_entry(option_table, "italic", (void *)&italic_flag, NULL, set_char_flag); Option_table_add_entry(option_table,"depth", &(depth),NULL,set_float); Option_table_add_entry(option_table,"size", &(size),NULL,set_int_non_negative); Option_table_add_string_entry(option_table, "font_type", &font_type_string, all_font_types_help); Option_table_add_string_entry(option_table, "true_type", &true_type_string, all_font_true_types_help); return_code = Option_table_multi_parse(option_table, state); if (return_code) { if (font_type_string) { STRING_TO_ENUMERATOR(Cmiss_graphics_font_type)(font_type_string, &font_type); if (CMISS_GRAPHICS_FONT_TYPE_INVALID == font_type) { display_message(ERROR_MESSAGE, "gfx_define_font: Invalid font type %s", font_type_string); return_code = 0; } } else { display_message(ERROR_MESSAGE, "gfx_define_font: Missing font_type argument"); return_code = 0; } if (true_type_string) { STRING_TO_ENUMERATOR(Cmiss_graphics_font_true_type)(true_type_string, &true_type); if (CMISS_GRAPHICS_FONT_TRUE_TYPE_INVALID == true_type) { display_message(ERROR_MESSAGE, "gfx_define_font: Invalid true type %s", true_type_string); return_code = 0; } } else { display_message(ERROR_MESSAGE, "gfx_define_font: Missing true_type argument"); return_code = 0; } if (font) { Cmiss_graphics_font_set_bold(font, bold_flag); Cmiss_graphics_font_set_italic(font, italic_flag); Cmiss_graphics_font_set_depth(font, depth); Cmiss_graphics_font_set_size(font, size); Cmiss_graphics_font_set_true_type(font, true_type); Cmiss_graphics_font_set_type(font, font_type); } } Cmiss_graphics_font_destroy(&font); DEALLOCATE(font_type_string); DEALLOCATE(true_type_string); DESTROY(Option_table)(&option_table); } else { display_message(WARNING_MESSAGE,"Missing font string."); display_parse_state_location(state); return_code=0; } }
int gfx_modify_rendition_general(struct Parse_state *state, void *cmiss_region_void, void *group_void) { int return_code = 0; ENTER(gfx_modify_rendition_general); Cmiss_region_id cmiss_region = reinterpret_cast<Cmiss_region_id>(cmiss_region_void); Cmiss_field_group_id group = reinterpret_cast<Cmiss_field_group_id>(group_void); if (state && cmiss_region) { /* if possible, get defaults from element_group on default scene */ Cmiss_rendition_id rendition = Cmiss_region_get_rendition_internal(cmiss_region); if (rendition) { Cmiss_field_id default_coordinate_field = rendition->default_coordinate_field; if (default_coordinate_field) { Cmiss_field_access(default_coordinate_field); } int clear_flag = 0; Option_table *option_table = CREATE(Option_table)(); Option_table_add_help(option_table, "The clear option removes all graphics from the rendition. " "Option 'circle_discretization' is deprecated: use circle_discretization option on cylinders instead. " "Option 'default_coordinate' is deprecated: use coordinate option on individual graphics instead. " "Option 'element_discretization' is deprecated: use tessellation option on individual graphics instead. " "Option 'native_discretization' is deprecated: use native_discretization option on individual graphics instead. "); /* circle_discretization */ Option_table_add_entry(option_table, "circle_discretization", (void *)&rendition->circle_discretization, (void *)NULL, set_Circle_discretization); /* clear */ Option_table_add_entry(option_table, "clear", (void *)&clear_flag, NULL, set_char_flag); /* default_coordinate */ Set_Computed_field_conditional_data set_coordinate_field_data; set_coordinate_field_data.computed_field_manager= Cmiss_region_get_Computed_field_manager(cmiss_region); set_coordinate_field_data.conditional_function= Computed_field_has_up_to_3_numerical_components; set_coordinate_field_data.conditional_function_user_data=(void *)NULL; Option_table_add_entry(option_table, "default_coordinate", (void *)&default_coordinate_field, (void *)&set_coordinate_field_data, set_Computed_field_conditional); /* element_discretization */ Option_table_add_divisions_entry(option_table, "element_discretization", &(rendition->element_divisions), &(rendition->element_divisions_size)); /* native_discretization */ Set_FE_field_conditional_FE_region_data native_discretization_field_conditional_data; native_discretization_field_conditional_data.conditional_function = (LIST_CONDITIONAL_FUNCTION(FE_field) *)NULL; native_discretization_field_conditional_data.user_data = (void *)NULL; native_discretization_field_conditional_data.fe_region = Cmiss_region_get_FE_region(cmiss_region); Option_table_add_entry(option_table, "native_discretization", (void *)&rendition->native_discretization_field, (void *)&native_discretization_field_conditional_data, set_FE_field_conditional_FE_region); return_code = Option_table_multi_parse(option_table, state); DESTROY(Option_table)(&option_table); if (return_code) { if (clear_flag) { if (group) { // remove only graphics using group as subgroup field Cmiss_rendition_begin_change(rendition); Cmiss_field_id group_field = Cmiss_field_group_base_cast(group); // support legacy command files by changing visibility of each graphic using group as its subgroup field Cmiss_graphic_id graphic = Cmiss_rendition_get_first_graphic(rendition); while (graphic) { Cmiss_graphic_id this_graphic = graphic; graphic = Cmiss_rendition_get_next_graphic(rendition, this_graphic); Cmiss_field_id subgroup_field = 0; Cmiss_graphic_get_subgroup_field(this_graphic, &subgroup_field); if (subgroup_field == group_field) { Cmiss_rendition_remove_graphic(rendition, this_graphic); } Cmiss_graphic_destroy(&this_graphic); } Cmiss_rendition_end_change(rendition); } else { return_code = Cmiss_rendition_remove_all_graphics(rendition); } } if (default_coordinate_field) { if (rendition->default_coordinate_field && default_coordinate_field && (rendition->default_coordinate_field != default_coordinate_field)) { display_message(WARNING_MESSAGE, "Change of default_coordinate field can have unexpected results. " "Please specify coordinate field for each graphic instead."); display_parse_state_location(state); } Cmiss_rendition_set_default_coordinate_field(rendition, default_coordinate_field); } } if (default_coordinate_field) { DEACCESS(Computed_field)(&default_coordinate_field); } Cmiss_rendition_destroy(&rendition); } else {
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)(®ion); } 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 */