00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CmdMaterial.h"
00022 #include "MaterialList.h"
00023 #include "config.h"
00024 #include "VMDApp.h"
00025 #include <stdlib.h>
00026 #include <ctype.h>
00027 #include <tcl.h>
00028
00029 int text_cmd_material(ClientData cd, Tcl_Interp *interp, int argc,
00030 const char *argv[]) {
00031
00032 VMDApp *app = (VMDApp *)cd;
00033 MaterialList *mlist = app->materialList;
00034
00035 if (argc < 2) {
00036 Tcl_SetResult(interp,
00037 (char *)
00038 "material list\n"
00039 "material settings <name>\n"
00040 "material add [<newname>] [copy <copyfrom>]\n"
00041 "material rename <oldname> <newname>\n"
00042 "material change [ambient|specular|diffuse|shininess|opacity|outline|outlinewidth|transmode] "
00043 "<name> <value>\n",
00044 TCL_STATIC);
00045 return TCL_ERROR;
00046 }
00047 if (!strupncmp(argv[1], "list", CMDLEN)) {
00048
00049 for (int i=0; i<mlist->num(); i++)
00050 Tcl_AppendElement(interp, mlist->material_name(i));
00051
00052 } else if (!strupncmp(argv[1], "settings", CMDLEN) && argc >= 3) {
00053 int ind = mlist->material_index(argv[2]);
00054 if (ind < 0) {
00055 Tcl_AppendResult(interp,
00056 "material settings: material '", argv[2],
00057 "' has not been defined", NULL);
00058 return TCL_OK;
00059 }
00060 char buf[20];
00061 sprintf(buf,"%f",mlist->get_ambient(ind));
00062 Tcl_AppendElement(interp, buf);
00063 sprintf(buf,"%f",mlist->get_specular(ind));
00064 Tcl_AppendElement(interp, buf);
00065 sprintf(buf,"%f",mlist->get_diffuse(ind));
00066 Tcl_AppendElement(interp, buf);
00067 sprintf(buf,"%f",mlist->get_shininess(ind));
00068 Tcl_AppendElement(interp, buf);
00069 sprintf(buf,"%f",mlist->get_opacity(ind));
00070 Tcl_AppendElement(interp, buf);
00071 sprintf(buf,"%f",mlist->get_outline(ind));
00072 Tcl_AppendElement(interp, buf);
00073 sprintf(buf,"%f",mlist->get_outlinewidth(ind));
00074 Tcl_AppendElement(interp, buf);
00075 sprintf(buf,"%f",mlist->get_transmode(ind));
00076 Tcl_AppendElement(interp, buf);
00077 } else if (!strupncmp(argv[1], "add", CMDLEN) && argc >= 2) {
00078
00079 const char *newname = NULL;
00080 const char *copyfrom = NULL;
00081 if (argc == 3) {
00082
00083 newname = argv[2];
00084 } else if (argc == 4) {
00085
00086 copyfrom = argv[3];
00087 } else if (argc == 5) {
00088
00089 newname = argv[2];
00090 copyfrom = argv[4];
00091 }
00092 const char *result = app->material_add(newname, copyfrom);
00093 if (!result) {
00094 Tcl_AppendResult(interp, "Unable to add material.", NULL);
00095 return TCL_ERROR;
00096 }
00097 Tcl_AppendResult(interp, result, NULL);
00098
00099 } else if (!strupncmp(argv[1], "rename", CMDLEN) && argc >= 4) {
00100 if (!app->material_rename(argv[2], argv[3])) {
00101 Tcl_AppendResult(interp, "Unable to rename material '", argv[2],
00102 "' to '", argv[3], "'.", NULL);
00103 return TCL_ERROR;
00104 }
00105 } else if (!strupncmp(argv[1], "change", CMDLEN) && argc >= 5) {
00106 const char *prop = argv[2];
00107 const char *name = argv[3];
00108 const char *value = argv[4];
00109 int matprop = -1;
00110 if (!strupcmp(prop, "ambient")) matprop = MAT_AMBIENT;
00111 else if (!strupcmp(prop, "specular")) matprop = MAT_SPECULAR;
00112 else if (!strupcmp(prop, "diffuse")) matprop = MAT_DIFFUSE;
00113 else if (!strupcmp(prop, "shininess")) matprop = MAT_SHININESS;
00114 else if (!strupcmp(prop, "opacity")) matprop = MAT_OPACITY;
00115 else if (!strupcmp(prop, "outline")) matprop = MAT_OUTLINE;
00116 else if (!strupcmp(prop, "outlinewidth")) matprop = MAT_OUTLINEWIDTH;
00117 else if (!strupcmp(prop, "transmode")) matprop = MAT_TRANSMODE;
00118 if (!app->material_change(name, matprop, (float) atof(value))) {
00119 Tcl_AppendResult(interp, "Unable to change property ", prop,
00120 " of material ", name, " to ", value, NULL);
00121 return TCL_ERROR;
00122 }
00123 } else if (!strupncmp(argv[1], "delete", CMDLEN) && argc == 3) {
00124 if (!app->material_delete(argv[2])) {
00125 Tcl_AppendResult(interp, "Unable to delete material: ", argv[2], NULL);
00126 return TCL_ERROR;
00127 }
00128 } else if (!strupncmp(argv[1], "default", CMDLEN) && argc ==3) {
00129 int id;
00130 if (Tcl_GetInt(interp, argv[2], &id) != TCL_OK) return TCL_ERROR;
00131 if (!app->material_restore_default(id)) {
00132 Tcl_AppendResult(interp, "Unable to restore default for material ",
00133 argv[2], NULL);
00134 return TCL_ERROR;
00135 }
00136 } else
00137 return TCL_ERROR;
00138 return TCL_OK;
00139 }
00140