int define_Computed_field_type_format_output(struct Parse_state *state, void *field_modify_void,void *computed_field_arithmetic_operators_package_void) /******************************************************************************* LAST MODIFIED : 15 May 2008 DESCRIPTION : Converts <field> into type COMPUTED_FIELD_FORMAT_OUTPUT (if it is not already) and allows its contents to be modified. ==============================================================================*/ { int return_code; char *format_string; struct Computed_field *source_field; Computed_field_modify_data *field_modify; struct Option_table *option_table; struct Set_Computed_field_conditional_data set_source_field_data; ENTER(define_Computed_field_type_format_output); USE_PARAMETER(computed_field_arithmetic_operators_package_void); if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void)) { return_code=1; source_field = (struct Computed_field *)NULL; format_string = NULL; if ((NULL != field_modify->get_field()) && (computed_field_format_output_type_string == Computed_field_get_type_string(field_modify->get_field()))) { return_code=Computed_field_get_type_format_output(field_modify->get_field(), &source_field, &format_string); } if (return_code) { /* must access objects for set functions */ if (source_field) { ACCESS(Computed_field)(source_field); } option_table = CREATE(Option_table)(); /* fields */ set_source_field_data.computed_field_manager= field_modify->get_field_manager(); set_source_field_data.conditional_function= Computed_field_has_numerical_components; set_source_field_data.conditional_function_user_data=(void *)NULL; Option_table_add_Computed_field_conditional_entry(option_table,"field", &source_field, &set_source_field_data); Option_table_add_string_entry(option_table, "format_string", &format_string, "C style formatting string"); return_code=Option_table_multi_parse(option_table,state); /* no errors,not asking for help */ if (return_code) { return_code = field_modify->update_field_and_deaccess( Computed_field_create_format_output(field_modify->get_field_module(), source_field, format_string)); } if (!return_code) { if ((!state->current_token)|| (strcmp(PARSER_HELP_STRING,state->current_token)&& strcmp(PARSER_RECURSIVE_HELP_STRING,state->current_token))) { /* error */ display_message(ERROR_MESSAGE, "define_Computed_field_type_format_output. Failed"); } } if (source_field) { DEACCESS(Computed_field)(&source_field); } if (format_string) DEALLOCATE(format_string); DESTROY(Option_table)(&option_table); } else { display_message(ERROR_MESSAGE, "define_Computed_field_type_format_output. Not enough memory"); return_code = 0; } } else { display_message(ERROR_MESSAGE, "define_Computed_field_type_format_output. Invalid argument(s)"); return_code = 0; } LEAVE; return (return_code); } /* define_Computed_field_type_format_output */
int define_Computed_field_type_integration(Parse_state *state, void *field_modify_void,void *computed_field_integration_package_void) /******************************************************************************* LAST MODIFIED : 24 August 2006 DESCRIPTION : Converts <field> into type COMPUTED_FIELD_INTEGRATION (if it is not already) and allows its contents to be modified. ==============================================================================*/ { int return_code = 1; ENTER(define_Computed_field_type_integration); Computed_field_modify_data *field_modify = reinterpret_cast<Computed_field_modify_data *>(field_modify_void); USE_PARAMETER(computed_field_integration_package_void); if (state && field_modify) { cmzn_region_id region = field_modify->get_region(); cmzn_mesh_id mesh = 0; cmzn_field_id coordinate_field = 0; cmzn_field_id integrand = 0; int magnitude_coordinates_flag = 0; int seed_element_identifier = 0; float time_update = 0; if ((NULL != field_modify->get_field()) && Computed_field_is_type_integration(field_modify->get_field())) { cmzn_element_id seed_element; return_code = Computed_field_get_type_integration(field_modify->get_field(), &mesh, &seed_element, &integrand, &magnitude_coordinates_flag, &coordinate_field); if (seed_element) { seed_element_identifier = cmzn_element_get_identifier(seed_element); cmzn_element_destroy(&seed_element); } } if (coordinate_field) { ACCESS(Computed_field)(coordinate_field); } if (integrand) { ACCESS(Computed_field)(integrand); } else { /* Make a default integrand of one */ double value = 1.0; // use temporary field module to supply different defaults cmzn_fieldmodule *temp_field_module = cmzn_region_get_fieldmodule(region); cmzn_fieldmodule_set_field_name(temp_field_module, "constant_1.0"); integrand = Computed_field_create_constant(temp_field_module, /*number_of_components*/1, &value); if (NULL == integrand) { display_message(ERROR_MESSAGE, "define_Computed_field_type_integration. Unable to create constant integrand"); return_code = 0; } cmzn_fieldmodule_destroy(&temp_field_module); } char *group_name = 0; Option_table *option_table = CREATE(Option_table)(); /* coordinate */ Set_Computed_field_conditional_data set_coordinate_field_data; set_coordinate_field_data.computed_field_manager = field_modify->get_field_manager(); set_coordinate_field_data.conditional_function = Computed_field_has_up_to_3_numerical_components; set_coordinate_field_data.conditional_function_user_data = 0; Option_table_add_Computed_field_conditional_entry(option_table, "coordinate", &coordinate_field, &set_coordinate_field_data); /* integrand */ Set_Computed_field_conditional_data set_integrand_field_data; set_integrand_field_data.computed_field_manager = field_modify->get_field_manager(); set_integrand_field_data.conditional_function = Computed_field_is_scalar; set_integrand_field_data.conditional_function_user_data = 0; Option_table_add_Computed_field_conditional_entry(option_table, "integrand", &integrand, &set_integrand_field_data); /* magnitude_coordinates|no_magnitude_coordinates */ Option_table_add_switch(option_table, "magnitude_coordinates", "no_magnitude_coordinates", &magnitude_coordinates_flag); // mesh Option_table_add_mesh_entry(option_table, "mesh", region, &mesh); /* region - legacy group name */ Option_table_add_string_entry(option_table, "region", &group_name, " GROUP_NAME(DEPRECATED)"); /* seed_element */ Option_table_add_int_non_negative_entry(option_table, "seed_element", &seed_element_identifier); /* update_time_integration */ Option_table_add_entry(option_table,"update_time_integration", &time_update, NULL, set_float); return_code = Option_table_multi_parse(option_table,state); DESTROY(Option_table)(&option_table); if (return_code && !mesh) { int dimension = FE_region_get_highest_dimension(cmzn_region_get_FE_region(region)); mesh = cmzn_fieldmodule_find_mesh_by_dimension(field_modify->get_field_module(), dimension); if (group_name) { cmzn_field_id group_field = cmzn_fieldmodule_find_field_by_name(field_modify->get_field_module(), group_name); cmzn_field_group_id group = cmzn_field_cast_group(group_field); cmzn_field_element_group_id element_group = cmzn_field_group_get_field_element_group(group, mesh); cmzn_mesh_destroy(&mesh); mesh = cmzn_mesh_group_base_cast(cmzn_field_element_group_get_mesh_group(element_group)); cmzn_field_element_group_destroy(&element_group); cmzn_field_group_destroy(&group); cmzn_field_destroy(&group_field); } } if (return_code && !mesh) { display_message(ERROR_MESSAGE, "You must specify a mesh."); return_code = 0; } if (return_code && !coordinate_field) { display_message(ERROR_MESSAGE, "You must specify a coordinate field."); return_code = 0; } if (return_code && !integrand) { display_message(ERROR_MESSAGE, "You must specify an integrand field."); return_code = 0; } cmzn_element_id seed_element = 0; if (return_code) { seed_element = cmzn_mesh_find_element_by_identifier(mesh, seed_element_identifier); if (!seed_element) { display_message(ERROR_MESSAGE, "Could not find seed_element %d in mesh.", seed_element_identifier); return_code = 0; } } if (return_code) { if (time_update && (NULL != field_modify->get_field()) && Computed_field_is_type_integration(field_modify->get_field())) { display_message(ERROR_MESSAGE, "The update_time_integration code has not been updated" "with the latest changes."); return_code=0; } else { return_code = field_modify->update_field_and_deaccess( Computed_field_create_integration(field_modify->get_field_module(), mesh, seed_element, integrand, magnitude_coordinates_flag, coordinate_field)); } } if (group_name) { DEALLOCATE(group_name); } cmzn_element_destroy(&seed_element); cmzn_mesh_destroy(&mesh); cmzn_field_destroy(&coordinate_field); cmzn_field_destroy(&integrand); } else { display_message(ERROR_MESSAGE, "define_Computed_field_type_integration. Invalid argument(s)"); return_code=0; } LEAVE; return (return_code); }
int gfx_modify_rendition_graphic(struct Parse_state *state, enum Cmiss_graphic_type graphic_type, const char *help_text, struct Modify_rendition_data *modify_rendition_data, struct Rendition_command_data *rendition_command_data) { if (!(state && rendition_command_data && modify_rendition_data)) { display_message(ERROR_MESSAGE, "gfx_modify_rendition_graphic. Invalid argument(s)"); return 0; } Cmiss_graphic *graphic = 0; if (modify_rendition_data->modify_this_graphic) { graphic = Cmiss_graphic_access(modify_rendition_data->graphic); graphic_type = Cmiss_graphic_get_graphic_type(graphic); } else { graphic = get_graphic_for_gfx_modify(rendition_command_data->rendition, graphic_type, modify_rendition_data->graphic); if (modify_rendition_data->group && (!graphic->subgroup_field)) { graphic->subgroup_field = Cmiss_field_access(Cmiss_field_group_base_cast(modify_rendition_data->group)); } } if (!graphic) { display_message(ERROR_MESSAGE, "gfx_modify_rendition_graphic. Could not create graphic"); return 0; } REACCESS(Cmiss_graphic)(&(modify_rendition_data->graphic), graphic); int return_code = 1; Cmiss_graphics_coordinate_system coordinate_system = Cmiss_graphic_get_coordinate_system(graphic); char *font_name = (char *)NULL; Cmiss_field_id orientation_scale_field = 0; Cmiss_field_id variable_scale_field = 0; Cmiss_field_id xi_point_density_field = 0; GT_object *glyph = 0; Triple glyph_offset, glyph_scale_factors, glyph_size; enum Graphic_glyph_scaling_mode glyph_scaling_mode = GRAPHIC_GLYPH_SCALING_GENERAL; const char *glyph_scaling_mode_string = 0; if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_GLYPH)) { Cmiss_graphic_get_glyph_parameters(graphic, &glyph, &glyph_scaling_mode, glyph_offset, glyph_size, &orientation_scale_field, glyph_scale_factors, &variable_scale_field); if (glyph) ACCESS(GT_object)(glyph); if (orientation_scale_field) { ACCESS(Computed_field)(orientation_scale_field); } if (variable_scale_field) { ACCESS(Computed_field)(variable_scale_field); } glyph_scaling_mode_string = ENUMERATOR_STRING(Graphic_glyph_scaling_mode)(glyph_scaling_mode); } enum Use_element_type use_element_type; const char *use_element_type_string = 0; if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_USE_ELEMENT_TYPE)) { use_element_type = graphic->use_element_type; use_element_type_string = ENUMERATOR_STRING(Use_element_type)(use_element_type); } enum Xi_discretization_mode xi_discretization_mode; const char *xi_discretization_mode_string = 0; if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_XI_DISCRETIZATION_MODE)) { Cmiss_graphic_get_xi_discretization(graphic, &xi_discretization_mode, &xi_point_density_field); if (xi_point_density_field) { ACCESS(Computed_field)(xi_point_density_field); } xi_discretization_mode_string = ENUMERATOR_STRING(Xi_discretization_mode)(xi_discretization_mode); } int number_of_components = 3; int visibility = graphic->visibility_flag; int number_of_valid_strings; const char **valid_strings; enum Cmiss_graphics_render_type render_type = graphic->render_type; const char *render_type_string = ENUMERATOR_STRING(Cmiss_graphics_render_type)(render_type); /* The value stored in the graphic is an integer rather than a char */ char reverse_track = (graphic->reverse_track) ? 1 : 0; char *seed_nodeset_name = 0; if (graphic->seed_nodeset) { seed_nodeset_name = Cmiss_nodeset_get_name(graphic->seed_nodeset); } Option_table *option_table = CREATE(Option_table)(); if (help_text) { Option_table_add_help(option_table, help_text); } /* as */ Option_table_add_entry(option_table,"as",&(graphic->name), (void *)1,set_name); /* cell_centres/cell_corners/cell_density/exact_xi */ if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_XI_DISCRETIZATION_MODE)) { valid_strings = ENUMERATOR_GET_VALID_STRINGS(Xi_discretization_mode)( &number_of_valid_strings, (ENUMERATOR_CONDITIONAL_FUNCTION(Xi_discretization_mode) *)NULL, (void *)NULL); Option_table_add_enumerator(option_table,number_of_valid_strings, valid_strings,&xi_discretization_mode_string); DEALLOCATE(valid_strings); } /* centre */ if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_GLYPH)) { Option_table_add_entry(option_table,"centre",glyph_offset, &(number_of_components),set_reversed_float_vector); } /* circle_discretization */ if (graphic_type == CMISS_GRAPHIC_CYLINDERS) { Option_table_add_entry(option_table, "circle_discretization", (void *)&(graphic->circle_discretization), (void *)NULL, set_Circle_discretization); } /* constant_radius */ if (graphic_type == CMISS_GRAPHIC_CYLINDERS) { Option_table_add_entry(option_table,"constant_radius", &(graphic->constant_radius),NULL,set_float); } /* coordinate */ Set_Computed_field_conditional_data set_coordinate_field_data; set_coordinate_field_data.computed_field_manager = rendition_command_data->computed_field_manager; 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_Computed_field_conditional_entry(option_table, "coordinate", &(graphic->coordinate_field), &set_coordinate_field_data); /* coordinate system */ const char *coordinate_system_string = ENUMERATOR_STRING(Cmiss_graphics_coordinate_system)(coordinate_system); valid_strings = ENUMERATOR_GET_VALID_STRINGS(Cmiss_graphics_coordinate_system)( &number_of_valid_strings, (ENUMERATOR_CONDITIONAL_FUNCTION(Cmiss_graphics_coordinate_system) *)NULL, (void *)NULL); Option_table_add_enumerator(option_table, number_of_valid_strings, valid_strings, &coordinate_system_string); DEALLOCATE(valid_strings); /* data */ Set_Computed_field_conditional_data set_data_field_data; set_data_field_data.computed_field_manager = rendition_command_data->computed_field_manager; set_data_field_data.conditional_function = Computed_field_has_numerical_components; set_data_field_data.conditional_function_user_data = (void *)NULL; Option_table_add_Computed_field_conditional_entry(option_table, "data", &(graphic->data_field), &set_data_field_data); /* decimation_threshold */ if (graphic_type == CMISS_GRAPHIC_ISO_SURFACES) { Option_table_add_double_entry(option_table, "decimation_threshold", &(graphic->decimation_threshold)); } /* delete */ Option_table_add_entry(option_table,"delete", &(modify_rendition_data->delete_flag),NULL,set_char_flag); /* density */ Set_Computed_field_conditional_data set_xi_point_density_field_data; set_xi_point_density_field_data.computed_field_manager = rendition_command_data->computed_field_manager; set_xi_point_density_field_data.conditional_function = Computed_field_is_scalar; set_xi_point_density_field_data.conditional_function_user_data = (void *)NULL; if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_XI_DISCRETIZATION_MODE)) { Option_table_add_Computed_field_conditional_entry(option_table, "density", &xi_point_density_field, &set_xi_point_density_field_data); } /* discretization */ if (Cmiss_graphic_type_uses_attribute(graphic_type, CMISS_GRAPHIC_ATTRIBUTE_DISCRETIZATION)) { Option_table_add_entry(option_table,"discretization", &(graphic->discretization),NULL, set_Element_discretization); } /* ellipse/line/rectangle/ribbon */ Streamline_type streamline_type = STREAM_LINE; const char *streamline_type_string = ENUMERATOR_STRING(Streamline_type)(streamline_type); if (graphic_type == CMISS_GRAPHIC_STREAMLINES) { valid_strings = ENUMERATOR_GET_VALID_STRINGS(Streamline_type)( &number_of_valid_strings, (ENUMERATOR_CONDITIONAL_FUNCTION(Streamline_type) *)NULL, (void *)NULL); Option_table_add_enumerator(option_table,number_of_valid_strings, valid_strings,&streamline_type_string); DEALLOCATE(valid_strings); }