00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "GeometryList.h"
00029 #include "GeometryAtom.h"
00030 #include "GeometryBond.h"
00031 #include "GeometryAngle.h"
00032 #include "GeometryDihedral.h"
00033 #include "GeometrySpring.h"
00034 #include "DisplayDevice.h"
00035 #include "DispCmds.h"
00036 #include "MoleculeList.h"
00037 #include "utilities.h"
00038 #include "VMDApp.h"
00039 #include "Scene.h"
00040 #include "Inform.h"
00041
00042
00043 #define ATOMGEOMCOL REGGREEN
00044 #define BONDGEOMCOL REGWHITE
00045 #define ANGLEGEOMCOL REGYELLOW
00046 #define DIHEGEOMCOL REGCYAN
00047 #define TUGGEOMCOL REGWHITE
00048 #define SPRINGGEOMCOL REGORANGE
00049
00050
00052 GeometryList::GeometryList(VMDApp *vmdapp, Displayable *disp)
00053 : Displayable(disp) {
00054
00055
00056 colorCat = (-1);
00057
00058
00059 app = vmdapp;
00060
00061
00062 labelsize = 1.0f;
00063 labelthickness = 1.0f;
00064
00065
00066 add_geom_list("Atoms", ATOMGEOMCOL);
00067 add_geom_list("Bonds", BONDGEOMCOL);
00068 add_geom_list("Angles", ANGLEGEOMCOL);
00069 add_geom_list("Dihedrals", DIHEGEOMCOL);
00070 add_geom_list("Springs", SPRINGGEOMCOL);
00071
00072 colorCat = scene->add_color_category("Labels");
00073 for (int i=0; i<num_lists(); i++) {
00074 scene->add_color_item(colorCat, geomLists.name(i),
00075 geomLists.data(i)->defaultColor);
00076 }
00077
00078
00079 rot_off();
00080 scale_off();
00081 glob_trans_off();
00082 cent_trans_off();
00083 }
00084
00085
00087 GeometryList::~GeometryList(void) {
00088
00089
00090 for(int i=(num_lists() - 1); i >= 0; i--)
00091 del_geom_list(i);
00092 }
00093
00094
00096
00097 void GeometryList::do_color_changed(int clr) {
00098 if (clr == colorCat) {
00099 for (int i=0; i<num_lists(); i++) {
00100 GeomListPtr glist = geom_list(i);
00101 GeomListStruct *s = geomLists.data(i);
00102 int ind = scene->category_item_index(colorCat, geom_list_name(i));
00103 int c = scene->category_item_value(colorCat, ind);
00104 s->curColor = c;
00105 for (int j=0; j<glist->num(); j++)
00106 (*glist)[j]->set_color(c);
00107 }
00108 }
00109 }
00110
00112
00113
00114
00115 int GeometryList::add_geom_list(const char *nm, int clr) {
00116
00117
00118 int oldlist = geom_list_index(nm);
00119 if(oldlist >= 0)
00120 return oldlist;
00121
00122
00123 GeomListStruct *newlist = new GeomListStruct;
00124 newlist->geomList = new ResizeArray<GeometryMol *>(8);
00125 newlist->defaultColor = clr;
00126 newlist->curColor = clr;
00127
00128
00129 return geomLists.add_name(nm, newlist);
00130 }
00131
00132
00133
00134 int GeometryList::del_geom_list(int n) {
00135 GeomListStruct *oldlist = NULL;
00136
00137
00138 if(n >= 0 && n < num_lists()) {
00139
00140 oldlist = geomLists.data(n);
00141 GeomListPtr glist = oldlist->geomList;
00142
00143
00144 for(int i=(glist->num() - 1); i >= 0; i--) {
00145 delete (*glist)[i];
00146 }
00147
00148
00149 delete glist;
00150 delete oldlist;
00151 geomLists.set_data(n, (GeomListStruct *) NULL);
00152 }
00153
00154
00155 return (oldlist != NULL);
00156 }
00157
00158 int GeometryList::add_geometry(const char *geomcatname, const int *molids,
00159 const int *atomids, const int *cells, float k, int toggle) {
00160
00161
00162 int geomcat = geom_list_index(geomcatname);
00163 GeometryMol *g = NULL;
00164 MoleculeList *mlist = app->moleculeList;
00165 if (geomcat == geom_list_index("Atoms"))
00166 g = new GeometryAtom(*molids, *atomids, cells, mlist, app->commandQueue, this);
00167 else if (geomcat == geom_list_index("Bonds"))
00168 g = new GeometryBond((int *)molids, (int *)atomids, cells, mlist, app->commandQueue, this);
00169 else if (geomcat == geom_list_index("Angles"))
00170 g = new GeometryAngle((int *)molids, (int *)atomids, cells, mlist, app->commandQueue, this);
00171 else if (geomcat == geom_list_index("Dihedrals"))
00172 g = new GeometryDihedral((int *)molids, (int *)atomids, cells, mlist, app->commandQueue, this);
00173 else if (geomcat == geom_list_index("Springs"))
00174 g = new GeometrySpring((int *)molids, (int *)atomids, mlist, app->commandQueue, k, this);
00175 else {
00176 msgErr << "Unknown geometry category '" << geomcatname << "'." << sendmsg;
00177 return -1;
00178 }
00179 if(g && g->ok()) {
00180 GeomListPtr glist = geom_list(geomcat);
00181
00182
00183
00184
00185 for(int i=(glist->num() - 1); i >= 0; i--) {
00186 GeometryMol *g2 = (*glist)[i];
00187 if(!strcmp(g2->unique_name(), g->unique_name())) {
00188
00189 if (toggle) {
00190 if (g2->displayed())
00191 g2->off();
00192 else
00193 g2->on();
00194 }
00195
00196 delete g;
00197 return i;
00198 }
00199 }
00200
00201
00202 msgInfo << "Added new " << geomcatname << " label " << g->name();
00203 if (g->has_value())
00204 msgInfo << " = " << g->calculate();
00205 msgInfo << sendmsg;
00206
00207
00208 glist->append(g);
00209
00210
00211 g->calculate();
00212
00213
00214 g->set_color(geomLists.data(geomcat)->curColor);
00215 g->set_text_size(labelsize);
00216 g->set_text_thickness(labelthickness);
00217
00218
00219 g->set_pick();
00220
00221
00222 return glist->num() - 1;
00223 }
00224
00225
00226 return -1;
00227 }
00228
00229
00230
00231
00232 int GeometryList::del_geometry(int glindex, int n) {
00233
00234
00235 if(glindex >= 0 && glindex < num_lists()) {
00236
00237
00238 GeomListPtr glist = geom_list(glindex);
00239
00240
00241 if(n >= 0 && n < glist->num()) {
00242
00243 delete (*glist)[n];
00244 glist->remove(n);
00245
00246
00247 return TRUE;
00248 } else if(n < 0) {
00249
00250 for(int j=(glist->num() - 1); j >= 0; j--) {
00251 delete (*glist)[j];
00252 glist->remove(j);
00253 }
00254
00255
00256 return TRUE;
00257 }
00258 }
00259
00260
00261 return FALSE;
00262 }
00263
00264
00265
00266 int GeometryList::show_geometry(int glindex, int n, int s) {
00267
00268
00269 if(glindex >= 0 && glindex < num_lists()) {
00270
00271
00272 GeomListPtr glist = geom_list(glindex);
00273
00274
00275 if(n >= 0 && n < glist->num()) {
00276
00277 if (s)
00278 (*glist)[n] -> on();
00279 else
00280 (*glist)[n] -> off();
00281
00282
00283
00284 return TRUE;
00285 } else if(n < 0) {
00286
00287 for(int j=(glist->num() - 1); j >= 0; j--) {
00288 if (s)
00289 (*glist)[j] -> on();
00290 else
00291 (*glist)[j] -> off();
00292 }
00293
00294
00295
00296 return TRUE;
00297 }
00298 }
00299
00300
00301 return FALSE;
00302 }
00303
00304 int GeometryList::setTextSize(float newsize) {
00305 if (newsize <= 0)
00306 return FALSE;
00307
00308 if (newsize == labelsize) return TRUE;
00309
00310 labelsize = newsize;
00311 for(int i=(num_lists() - 1); i >= 0; i--) {
00312 GeomListPtr glist = geom_list(i);
00313 for(int j=(glist->num() - 1); j >= 0; j--) {
00314 GeometryMol *g = (*glist)[j];
00315 g->set_text_size(newsize);
00316 }
00317 }
00318
00319 return TRUE;
00320 }
00321
00322 int GeometryList::setTextThickness(float newthick) {
00323 if (newthick <= 0)
00324 return FALSE;
00325
00326 if (newthick == labelthickness) return TRUE;
00327
00328 labelthickness = newthick;
00329 for(int i=(num_lists() - 1); i >= 0; i--) {
00330 GeomListPtr glist = geom_list(i);
00331 for(int j=(glist->num() - 1); j >= 0; j--) {
00332 GeometryMol *g = (*glist)[j];
00333 g->set_text_thickness(newthick);
00334 }
00335 }
00336
00337 return TRUE;
00338 }
00339
00340 const float *GeometryList::getTextOffset(const char *nm, int n) {
00341 GeomListPtr glist = geom_list(nm);
00342 if (!glist) return NULL;
00343 if (n < 0 || n >= glist->num()) return NULL;
00344 GeometryMol *g = (*glist)[n];
00345 return g->text_offset();
00346 }
00347
00348 int GeometryList::setTextOffset(const char *nm, int n, const float delta[2]) {
00349
00350 GeomListPtr glist = geom_list(nm);
00351 if (!glist) return FALSE;
00352 if (n < 0 || n >= glist->num()) return FALSE;
00353 GeometryMol *g = (*glist)[n];
00354 g->set_text_offset(delta);
00355 return TRUE;
00356 }
00357
00358 const char *GeometryList::getTextFormat(const char *nm, int n) {
00359
00360 GeomListPtr glist = geom_list(nm);
00361 if (!glist) return NULL;
00362 if (n < 0 || n >= glist->num()) return NULL;
00363 GeometryMol *g = (*glist)[n];
00364 return g->text_format();
00365 }
00366
00367 int GeometryList::setTextFormat(const char *nm, int n, const char *format) {
00368 GeomListPtr glist = geom_list(nm);
00369 if (!glist) return FALSE;
00370 if (n < 0 || n >= glist->num()) return FALSE;
00371 GeometryMol *g = (*glist)[n];
00372 g->set_text_format(format);
00373 return TRUE;
00374 }
00375
00377
00378
00379
00380 void GeometryList::prepare() {
00381
00382
00383
00384 for(int i=(num_lists() - 1); i >= 0; i--) {
00385 GeomListPtr glist = geom_list(i);
00386 for(int j=(glist->num() - 1); j >= 0; j--) {
00387 GeometryMol *g = (*glist)[j];
00388 if(!g->ok()) {
00389 del_geometry(i, j);
00390 }
00391 }
00392 }
00393 }
00394