00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <tcl.h>
00022 #include <stdlib.h>
00023 #include "VMDApp.h"
00024 #include "TclCommands.h"
00025 #include "config.h"
00026
00027 int text_cmd_color(ClientData cd, Tcl_Interp *interp, int argc, const char *argv[]) {
00028
00029 VMDApp *app = (VMDApp *)cd;
00030
00031 if (argc < 2) {
00032
00033 Tcl_SetResult(interp,
00034 (char *)
00035 "color change rgb <color> [<grayscale> | <r g b>]\n"
00036 " (when no value is specified, the color is reset to its default value)\n"
00037 "color rgb <color>\n"
00038 "color scale [method|midpoint|min|max] <value>\n"
00039 "color scale colors <method> [<mincolor> <midcolor> <maxcolor>]\n"
00040 "color <category> <name> [new color]",
00041 TCL_STATIC);
00042 return TCL_ERROR;
00043 }
00044
00045 if (!strupncmp(argv[1], "change", CMDLEN) && argc > 3) {
00046 float r = 0.5, g = 0.5, b = 0.5;
00047 if (app->color_index(argv[3]) < 0) {
00048 Tcl_SetResult(interp, (char *) "color change: invalid color specified", TCL_STATIC);
00049 return TCL_ERROR;
00050 }
00051 if (argc == 4) {
00052
00053 if (!app->color_default_value(argv[3], &r, &g, &b)) {
00054 Tcl_SetResult(interp, (char *) "Unable to get default values for color", TCL_STATIC);
00055 return TCL_ERROR;
00056 }
00057 app->color_changevalue(argv[3], r, g, b);
00058 return TCL_OK;
00059 } else {
00060 double rr;
00061 if (Tcl_GetDouble(interp, argv[4], &rr) != TCL_OK) {
00062 Tcl_AppendResult(interp, " in color change", NULL);
00063 return TCL_ERROR;
00064 }
00065 r = (float) rr;
00066 if (argc == 5) {
00067 if (!app->color_changevalue(argv[3], r, r, r)) {
00068 Tcl_SetResult(interp, (char *) "Unable to change color", TCL_STATIC);
00069 return TCL_ERROR;
00070 }
00071 } else if (argc == 7) {
00072 double gg, bb;
00073 if (Tcl_GetDouble(interp, argv[5], &gg) != TCL_OK ||
00074 Tcl_GetDouble(interp, argv[6], &bb) != TCL_OK) {
00075 Tcl_AppendResult(interp, " in color change", NULL);
00076 return TCL_ERROR;
00077 }
00078 g = (float) gg;
00079 b = (float) bb;
00080 if (!app->color_changevalue(argv[3], r, g, b)) {
00081 Tcl_SetResult(interp, (char *) "Unable to change color", TCL_STATIC);
00082 return TCL_ERROR;
00083 }
00084 } else {
00085 Tcl_SetResult(interp, (char *) "color change needs 1 (or 3) parameters", TCL_STATIC);
00086 return TCL_ERROR;
00087 }
00088 return TCL_OK;
00089 }
00090 }
00091
00092 else if (!strupncmp(argv[1], "scale", CMDLEN)) {
00094 if (argc >= 4 && !strupncmp(argv[2], "colors", CMDLEN)) {
00095 if (argc == 4) {
00096 int ind = app->colorscale_method_index(argv[3]);
00097 float vals[3][3];
00098 if (!app->get_colorscale_colors(ind, vals[0], vals[1], vals[2])) {
00099 Tcl_AppendResult(interp, "no colors available for method '", argv[3], "'.", NULL);
00100 return TCL_ERROR;
00101 }
00102 Tcl_Obj *result = Tcl_NewListObj(0,NULL);
00103 for (int i=0; i<3; i++) {
00104 Tcl_Obj *elem = Tcl_NewListObj(0, NULL);
00105 for (int j=0; j<3; j++) {
00106 Tcl_ListObjAppendElement(interp,elem,Tcl_NewDoubleObj(vals[i][j]));
00107 }
00108 Tcl_ListObjAppendElement(interp, result, elem);
00109 }
00110 Tcl_SetObjResult(interp, result);
00111 return TCL_OK;
00112 } else if (argc == 7) {
00113 int ind = app->colorscale_method_index(argv[3]);
00114 float vals[3][3];
00115 for (int i=0; i<3; i++) {
00116
00117 int rc = tcl_get_vector(argv[4+i], vals[i], interp);
00118 if (rc != TCL_OK) {
00119 if (!app->color_value(argv[4+i], vals[i]+0, vals[i]+1, vals[i]+2)) {
00120 return TCL_ERROR;
00121 }
00122
00123 Tcl_ResetResult(interp);
00124 }
00125 }
00126 if (!app->set_colorscale_colors(ind, vals[0], vals[1], vals[2])) {
00127 Tcl_AppendResult(interp, "Unable to set colorscale colors for method '", argv[3], "'.", NULL);
00128 return TCL_ERROR;
00129 }
00130 return TCL_OK;
00131 }
00132 }
00133 if (argc == 4) {
00134 if (!strupncmp(argv[2], "method", CMDLEN)) {
00135 int ind = app->colorscale_method_index(argv[3]);
00136 if (ind < 0) {
00137 char tmpstring[1024];
00138 sprintf(tmpstring, "color scale method '%s' not recognized", argv[3]);
00139 Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00140 return TCL_ERROR;
00141 }
00142 app->colorscale_setmethod(ind);
00143 }
00144 else {
00145 float mid=0, min=0, max=0;
00146 app->colorscale_info(&mid, &min, &max);
00147 float newval = (float) atof(argv[3]);
00148 if (!strupncmp(argv[2], "midpoint", CMDLEN)) mid = newval;
00149 else if (!strupncmp(argv[2], "min", CMDLEN)) min = newval;
00150 else if (!strupncmp(argv[2], "max", CMDLEN)) max = newval;
00151 else {
00152 char tmpstring[1024];
00153 sprintf(tmpstring, "color scale option '%s' not recognized", argv[2]);
00154 Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00155 return TCL_ERROR;
00156 }
00157 app->colorscale_setvalues(mid, min, max);
00158 }
00159 }
00160 else {
00161 Tcl_SetResult(interp, (char *) "color scale [method|midpoint|min|max] <value>", TCL_STATIC);
00162 return TCL_ERROR;
00163 }
00164 }
00165
00166 else if ((argc == 3 || argc == 4) && !strupncmp(argv[1], "restype", CMDLEN)) {
00167 if (argc == 3) {
00168 const char *result = app->color_get_restype(argv[2]);
00169 if (!result) {
00170 Tcl_AppendResult(interp, "No restype for residue '", argv[2], "'",
00171 NULL);
00172 return TCL_ERROR;
00173 }
00174 Tcl_SetResult(interp, (char *)result, TCL_STATIC);
00175 } else {
00176 if (!app->color_set_restype(argv[2], argv[3])) {
00177 Tcl_AppendResult(interp, "Unable to set restype: invalid restype '",
00178 argv[3], "' specified.", NULL);
00179 return TCL_ERROR;
00180 }
00181 }
00182
00183 }
00184
00185
00186 else if(argc == 3) {
00187 const char *colorname;
00188 if (app->color_get_from_name(argv[1], argv[2], &colorname)) {
00189 Tcl_SetResult(interp, (char*) colorname, TCL_STATIC);
00190 return TCL_OK;
00191 }
00192 else {
00193 Tcl_SetResult(interp, (char *) "Unable to get color name", TCL_STATIC);
00194 return TCL_ERROR;
00195 }
00196 }
00197
00198 else if(argc == 4) {
00199 if (!app->color_changename(argv[1], argv[2], argv[3])) {
00200 Tcl_SetResult(interp, (char *) "Unable to change color name", TCL_STATIC);
00201 return TCL_ERROR;
00202 }
00203 }
00204
00205 else if (argc == 6 && !strupncmp(argv[1], "add", CMDLEN)
00206 && !strupncmp(argv[2], "item", CMDLEN)) {
00207 if (!app->color_add_item(argv[3], argv[4], argv[5])) {
00208 Tcl_SetResult(interp, "Error adding color item.", TCL_STATIC);
00209 return TCL_ERROR;
00210 }
00211
00212 }
00213
00214 else return TCL_ERROR;
00215
00216
00217 return TCL_OK;
00218 }
00219