00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "DrawMolecule.h"
00023 #include "DispCmds.h"
00024 #include "PickMode.h"
00025
00026
00027 #define MGMAXDATASIZE 30
00028
00029 class JString;
00030 struct Material;
00031
00033 class MoleculeGraphics : public Displayable {
00034 public:
00036 enum Shapes {NONE, POINT, PICKPOINT, TRIANGLE, TRINORM, TRICOLOR,
00037 LINE, CYLINDER, CONE, SPHERE, TEXT,
00038 SPHERETUBE, COLOR, MATERIALS, MATERIAL};
00039
00040 private:
00042 struct ShapeClass {
00043 int id;
00044 Shapes shape;
00045 float data[MGMAXDATASIZE];
00046 int numdata;
00047 void *extradata;
00048
00049 ShapeClass(Shapes s=NONE, int ndata=0, int newid=-1)
00050 : id(newid), shape(s), numdata(ndata), extradata(NULL) { }
00051
00052 void clear() {
00053 shape = NONE;
00054 if (extradata != NULL)
00055 free(extradata);
00056 }
00057
00058 int operator==(const ShapeClass&) {return 1;}
00059 };
00060
00062 ResizeArray<ShapeClass> shapes;
00063
00067 ResizeArray<char *> shapetext;
00068
00069 char graphics_info[250];
00070 JString *graphics_info_xl;
00071
00072 int colorID;
00073 int molid;
00074 int max_id;
00075 int next_id;
00076 int next_index;
00077 int delete_count;
00078 int needRegenerate;
00079 int added(void);
00080 float cov_scale, cov_pos[3];
00081
00082 void find_bounds(void);
00083 void delete_shapetext();
00084 virtual void create_cmdlist(void);
00085
00086 public:
00087 MoleculeGraphics(DrawMolecule *d) :
00088 Displayable(d) {
00089 molid = d->id();
00090 max_id = 0;
00091 next_id = 0;
00092 next_index = 0;
00093 needRegenerate = 1;
00094 delete_count = 0;
00095 colorID = 0;
00096 graphics_info_xl = NULL;
00097 }
00098 virtual ~MoleculeGraphics(void){
00099 delete_shapetext();
00100 }
00101 virtual void prepare() {
00102 if (needRegenerate) create_cmdlist();
00103 }
00104
00106 virtual void cov(float &x, float &y, float &z) {
00107 find_bounds(); x = cov_pos[0]; y = cov_pos[1]; z = cov_pos[2];
00108 }
00109 virtual float scale_factor(void) {
00110 find_bounds(); return cov_scale;
00111 }
00112
00113
00114 int add_point(const float *x);
00115 int add_pickpoint(const float *x);
00116 int add_triangle(const float *x1, const float *x2, const float *x3);
00117 int add_trinorm(const float *x1, const float *x2, const float *x3,
00118 const float *nx1, const float *nx2, const float *nx3);
00119 int add_tricolor(const float *x1, const float *x2, const float *x3,
00120 const float *nx1, const float *nx2, const float *nx3,
00121 int c1, int c2, int c3);
00122 int add_line(const float *x, const float *y, int line_style, int width);
00123 int add_cylinder(const float *x, const float *y,
00124 float radius, int res, int filled);
00125 int add_cone(const float *x, const float *y,
00126 float radius, float radius2, int res);
00127 int add_sphere(const float *x, float r, int res);
00128 int add_text(const float *x, const char *text, float size, float thickness);
00129 int add_spheretube(const int numcoords, const float *xyz3fv,
00130 const int numradii, const float *radii1fv,
00131 const int numcolors,
00132 const float *rgb3fv, const int *colorids,
00133 int drawtubes, int res);
00134 int use_materials(int yes_no);
00135 int use_color(int index);
00136 int use_material(const Material *);
00137
00138 void delete_id(int id);
00139 void delete_all(void);
00140 int replace_id(int id);
00141 int index_id(int id);
00142 int num_elements(void){ return int(shapes.num()); }
00143 int element_id(int index) { return shapes[index].shape != NONE ? shapes[index].id : -1; }
00144
00149 const char *info_id(int id);
00150
00151 virtual void pick_start(PickMode *pm, DisplayDevice *d,
00152 int btn, int tag,
00153 const int *cell ,
00154 int , const float *) {
00155
00156 pm->pick_graphics(molid, tag, btn, d);
00157 }
00158
00159 };
00160