Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ColorInfo.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: ColorInfo.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.38 $       $Date: 2020/12/24 04:21:51 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Routines for Tcl to get the color and color category information
00019  *
00020  ***************************************************************************/
00021 
00022 #include <string.h>
00023 
00024 #if defined(ARCH_AIX4)
00025 #include <strings.h>
00026 #endif
00027 
00028 #include "tcl.h"
00029 #include "TclCommands.h"
00030 #include "VMDApp.h"
00031 
00032 // They are:
00033 // colorinfo categories
00034 //   Display, Axes, ..., Structure, ...
00035 // colorinfo category Display
00036 //   Background
00037 // colorinfo category Axes
00038 //   X, Y, Z, Origin, Labels
00039 // colorinfo num
00040 //   value of REGCLRS
00041 // colorinfo max
00042 //   value of MAXCOLORS
00043 // colorinfo colors
00044 //   blue, red, ..., black
00045 // colorinfo index blue
00046 //   0
00047 // colorinfo rgb blue
00048 //   0.25 0.25 1.
00049 // colorinfo scale method
00050 //   0
00051 // colorinfo scale midpoint
00052 //   0.5
00053 // colorinfo scale min
00054 //   0
00055 // colorinfo scale max
00056 //   1
00057 
00058 
00059 // return a list of the top-level categories
00060 int tcl_colorinfo_categories(Tcl_Interp *interp, VMDApp *app, 
00061                              int argc, const char *[]) {
00062   if (argc != 0) {
00063     Tcl_SetResult(interp, (char *) "colorinfo: categories takes no parameters", TCL_STATIC);
00064     return TCL_ERROR;
00065   }
00066   
00067   int num = app->num_color_categories(); 
00068   for (int i=0; i<num; i++) {
00069     Tcl_AppendElement(interp, (char *) app->color_category(i));
00070   }
00071   return TCL_OK;
00072 }
00073 
00074 
00075 // return either a list elements in the category or, given an element
00076 // in the category, return the color associated with it
00077 int tcl_colorinfo_category(Tcl_Interp *interp, VMDApp *app, 
00078                            int argc, const char *argv[])
00079 {
00080   if (argc != 1 && argc !=2) {
00081     Tcl_SetResult(interp, (char *) "colorinfo: category takes one parameter (for a list) or two for a mapping", TCL_STATIC);
00082     return TCL_ERROR;
00083   }
00084 
00085   // One of two possitilities ....
00086   if (argc == 1) { // ... list the categories
00087     for (int i=0; i<app->num_color_category_items(argv[0]); i++) {
00088       Tcl_AppendElement(interp, (char *) app->color_category_item(argv[0], i));
00089     }
00090     return TCL_OK;
00091   }
00092   //  ....  or return a mapping
00093   const char *mapping = app->color_mapping(argv[0], argv[1]);
00094   if (!mapping) {
00095     Tcl_SetResult(interp, (char *) "colorinfo: category: couldn't find category element", TCL_STATIC);
00096     return TCL_ERROR;
00097   }
00098   // return the color mapping
00099   // XXX why is this AppendElement?    
00100   Tcl_AppendElement(interp, (char *) mapping);
00101   return TCL_OK;
00102 }
00103 
00104 int tcl_colorinfo_num(Tcl_Interp *interp, VMDApp *app, int argc, const char *[]) {
00105   if (argc != 0) {
00106     Tcl_SetResult(interp, (char *) "colorinfo: numcolors takes no parameters", TCL_STATIC);
00107     return TCL_ERROR;
00108   }
00109 
00110   char tmpstring[64];
00111   sprintf(tmpstring, "%d", app->num_regular_colors());
00112   Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00113   return TCL_OK;
00114 }
00115 
00116 // ALL of the colors
00117 int tcl_colorinfo_max(Tcl_Interp *interp, VMDApp *app, int argc, const char *[]) {
00118   if (argc != 0) {
00119     Tcl_SetResult(interp, (char *) "colorinfo: maxcolor takes no parameters", TCL_STATIC);
00120     return TCL_ERROR;
00121   }
00122 
00123   char tmpstring[64];
00124   sprintf(tmpstring, "%d", app->num_colors());
00125   Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00126   return TCL_OK;
00127 }
00128 
00129 // return a list of the regular colors
00130 int tcl_colorinfo_colors(Tcl_Interp *interp, VMDApp *app, 
00131                          int argc, const char *[]) {
00132   if (argc != 0) {
00133     Tcl_SetResult(interp, (char *) "colorinfo: colors takes no parameters", TCL_STATIC);
00134     return TCL_ERROR;
00135   }
00136   for (int i=0; i<app->num_regular_colors(); i++) {
00137     Tcl_AppendElement(interp, (char *) app->color_name(i));
00138   }
00139   return TCL_OK;
00140 }
00141 
00143 int tcl_colorinfo_rgb(Tcl_Interp *interp, VMDApp *app, 
00144                       int argc, const char *argv[]) {
00145   if (argc != 1) {
00146     Tcl_SetResult(interp, (char *) "colorinfo: color takes one color name or index", TCL_STATIC);
00147     return TCL_ERROR;
00148   }
00149   float value[3];
00150   if (!app->color_value(argv[0], value, value+1, value+2)) {
00151     // Try to convert it to an int
00152     int id;
00153     if (Tcl_GetInt(interp, argv[0], &id) != TCL_OK ||
00154         !app->color_name(id) || 
00155         !app->color_value(app->color_name(id), value, value+1, value+2)) {
00156       Tcl_SetResult(interp, (char *) "colorinfo: color: couldn't find color name or index", TCL_STATIC);
00157     return TCL_ERROR;
00158     }
00159   }
00160   Tcl_Obj *tcl_result = Tcl_NewListObj(0,NULL);
00161   for (int i=0; i<3; i++)
00162     Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewDoubleObj(value[i]));
00163   Tcl_SetObjResult(interp, tcl_result);
00164   return TCL_OK;
00165 }
00166 
00168 int tcl_colorinfo_index(Tcl_Interp *interp, VMDApp *app, 
00169                         int argc, const char *argv[]) {
00170   if (argc != 1) {
00171     Tcl_SetResult(interp, (char *) "colorinfo: index takes one color name or index", TCL_STATIC);
00172     return TCL_ERROR;
00173   }
00174   
00175   int id = app->color_index(argv[0]); 
00176   if (id < 0) {
00177     Tcl_SetResult(interp, (char *) "colorinfo: index: couldn't find color name or index", TCL_STATIC);
00178     return TCL_ERROR;
00179   }
00180 
00181   char tmpstring[64];
00182   sprintf(tmpstring, "%d", id);
00183   Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
00184   return TCL_OK;
00185 }
00187 int tcl_colorinfo_scale(Tcl_Interp *interp, VMDApp *app, 
00188                         int argc, const char *argv[])
00189 {
00190   if (argc != 1) {
00191     Tcl_SetResult(interp, (char *) "colorinfo: scale takes method|methods|midpoint|min|max", TCL_STATIC);
00192     return TCL_ERROR;
00193   }
00194   if (!strcmp(argv[0], "method")) {
00195     Tcl_SetResult(interp, (char *) app->colorscale_method_name(app->colorscale_method_current()), TCL_VOLATILE);
00196     return TCL_OK;
00197   }
00198   if (!strcmp(argv[0], "methods")) {
00199     for (int i=0; i<app->num_colorscale_methods(); i++) {
00200       Tcl_AppendElement(interp, (char *)app->colorscale_method_name(i));
00201     }
00202     return TCL_OK;
00203   }
00204   float mid, min, max;
00205   int rev, posterize;
00206   app->colorscale_params(&mid, &min, &max, &rev, &posterize);
00207   if (!strcmp(argv[0], "midpoint")) {
00208     Tcl_SetObjResult(interp, Tcl_NewDoubleObj(mid));
00209     return TCL_OK;
00210   }
00211   if (!strcmp(argv[0], "min")) {
00212     Tcl_SetObjResult(interp, Tcl_NewDoubleObj(min));
00213     return TCL_OK;
00214   }
00215   if (!strcmp(argv[0], "max")) {
00216     Tcl_SetObjResult(interp, Tcl_NewDoubleObj(max));
00217     return TCL_OK;
00218   }
00219   if (!strcmp(argv[0], "reverse")) {
00220     Tcl_SetObjResult(interp, Tcl_NewIntObj(rev));
00221     return TCL_OK;
00222   }
00223   if (!strcmp(argv[0], "posterize")) {
00224     Tcl_SetObjResult(interp, Tcl_NewIntObj(rev));
00225     return TCL_OK;
00226   }
00227   Tcl_AppendResult(interp, "colorinfo: scale called with incorrect ",
00228                    "parameter '", argv[0], "'", NULL);
00229   return TCL_ERROR;
00230 }
00231 
00233 int tcl_colorinfo(ClientData cd, Tcl_Interp *interp, int argc, const char *argv[])
00234 {
00235   if (argc < 2) {
00236     Tcl_SetResult(interp, 
00237       (char *)
00238       "colorinfo categories\n"
00239       "colorinfo category <category>\n"
00240       "colorinfo category <category> <element>\n"
00241       "colorinfo [num|max|colors]\n"
00242       "colorinfo [index|rgb] <name|value>\n"
00243       "colorinfo scale [method|methods|midpoint|min|max]",
00244       TCL_STATIC);
00245     return TCL_ERROR;
00246   }
00247 
00248   VMDApp *app = (VMDApp *)cd;
00249 
00250   if (!strcmp(argv[1], "categories")) {
00251     return tcl_colorinfo_categories(interp, app, argc-2, argv+2);
00252   }
00253   if (!strcmp(argv[1], "category")) {
00254     return tcl_colorinfo_category(interp, app, argc-2, argv+2);
00255   }
00256   if (!strcmp(argv[1], "num")) {
00257     return tcl_colorinfo_num(interp, app, argc-2, argv+2);
00258   }
00259   if (!strcmp(argv[1], "max")) {
00260     return tcl_colorinfo_max(interp, app, argc-2, argv+2);
00261   }
00262   if (!strcmp(argv[1], "colors")) {
00263     return tcl_colorinfo_colors(interp, app, argc-2, argv+2);
00264   }
00265   if (!strcmp(argv[1], "index")) {
00266     return tcl_colorinfo_index(interp, app, argc-2, argv+2);
00267   }
00268   if (!strcmp(argv[1], "rgb")) {
00269     return tcl_colorinfo_rgb(interp, app, argc-2, argv+2);
00270   }
00271   // color scale info
00272   if (!strcmp(argv[1], "scale")) {
00273     return tcl_colorinfo_scale(interp, app, argc-2, argv+2);
00274   }
00275 
00276   Tcl_AppendResult(interp, "colorinfo: couldn't understand first parameter: ",
00277                    argv[1], NULL);
00278   return TCL_ERROR;
00279 }
00280 

Generated on Thu Apr 25 02:42:05 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002