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|mirror|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_mirror(ind));
00070 Tcl_AppendElement(interp, buf);
00071 sprintf(buf,"%f",mlist->get_opacity(ind));
00072 Tcl_AppendElement(interp, buf);
00073 sprintf(buf,"%f",mlist->get_outline(ind));
00074 Tcl_AppendElement(interp, buf);
00075 sprintf(buf,"%f",mlist->get_outlinewidth(ind));
00076 Tcl_AppendElement(interp, buf);
00077 sprintf(buf,"%f",mlist->get_transmode(ind));
00078 Tcl_AppendElement(interp, buf);
00079 } else if (!strupncmp(argv[1], "add", CMDLEN) && argc >= 2) {
00080
00081 const char *newname = NULL;
00082 const char *copyfrom = NULL;
00083 if (argc == 3) {
00084
00085 newname = argv[2];
00086 } else if (argc == 4) {
00087
00088 copyfrom = argv[3];
00089 } else if (argc == 5) {
00090
00091 newname = argv[2];
00092 copyfrom = argv[4];
00093 }
00094 const char *result = app->material_add(newname, copyfrom);
00095 if (!result) {
00096 Tcl_AppendResult(interp, "Unable to add material.", NULL);
00097 return TCL_ERROR;
00098 }
00099 Tcl_AppendResult(interp, result, NULL);
00100
00101 } else if (!strupncmp(argv[1], "rename", CMDLEN) && argc >= 4) {
00102 if (!app->material_rename(argv[2], argv[3])) {
00103 Tcl_AppendResult(interp, "Unable to rename material '", argv[2],
00104 "' to '", argv[3], "'.", NULL);
00105 return TCL_ERROR;
00106 }
00107 } else if (!strupncmp(argv[1], "change", CMDLEN) && argc >= 5) {
00108 const char *prop = argv[2];
00109 const char *name = argv[3];
00110 const char *value = argv[4];
00111 int matprop = -1;
00112 if (!strupcmp(prop, "ambient")) matprop = MAT_AMBIENT;
00113 else if (!strupcmp(prop, "specular")) matprop = MAT_SPECULAR;
00114 else if (!strupcmp(prop, "diffuse")) matprop = MAT_DIFFUSE;
00115 else if (!strupcmp(prop, "shininess")) matprop = MAT_SHININESS;
00116 else if (!strupcmp(prop, "mirror")) matprop = MAT_MIRROR;
00117 else if (!strupcmp(prop, "opacity")) matprop = MAT_OPACITY;
00118 else if (!strupcmp(prop, "outline")) matprop = MAT_OUTLINE;
00119 else if (!strupcmp(prop, "outlinewidth")) matprop = MAT_OUTLINEWIDTH;
00120 else if (!strupcmp(prop, "transmode")) matprop = MAT_TRANSMODE;
00121 if (!app->material_change(name, matprop, (float) atof(value))) {
00122 Tcl_AppendResult(interp, "Unable to change property ", prop,
00123 " of material ", name, " to ", value, NULL);
00124 return TCL_ERROR;
00125 }
00126 } else if (!strupncmp(argv[1], "delete", CMDLEN) && argc == 3) {
00127 if (!app->material_delete(argv[2])) {
00128 Tcl_AppendResult(interp, "Unable to delete material: ", argv[2], NULL);
00129 return TCL_ERROR;
00130 }
00131 } else if (!strupncmp(argv[1], "default", CMDLEN) && argc ==3) {
00132 int id;
00133 if (Tcl_GetInt(interp, argv[2], &id) != TCL_OK) return TCL_ERROR;
00134 if (!app->material_restore_default(id)) {
00135 Tcl_AppendResult(interp, "Unable to restore default for material ",
00136 argv[2], NULL);
00137 return TCL_ERROR;
00138 }
00139 } else
00140 return TCL_ERROR;
00141 return TCL_OK;
00142 }
00143