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 struct Material;
00030
00032 class MoleculeGraphics : public Displayable {
00033 public:
00035 enum Shapes {NONE, POINT, PICKPOINT, TRIANGLE, TRINORM, TRICOLOR, LINE, CYLINDER, CONE,
00036 SPHERE, TEXT, COLOR, MATERIALS, MATERIAL};
00037
00038 private:
00040 struct ShapeClass {
00041 int id;
00042 Shapes shape;
00043 float data[MGMAXDATASIZE];
00044 int numdata;
00045 ShapeClass(Shapes s=NONE, int ndata=0, int newid=-1)
00046 : id(newid), shape(s), numdata(ndata) { }
00047 void clear() { shape = NONE; }
00048 int operator==(const ShapeClass&) {return 1;}
00049 };
00050
00052 ResizeArray<ShapeClass> shapes;
00053
00057 ResizeArray<char *> shapetext;
00058
00059 char graphics_info[250];
00060
00061 int molid;
00062 int max_id, next_id;
00063 int next_index;
00064 int delete_count;
00065 int needRegenerate;
00066 int added(void);
00067 float cov_scale, cov_pos[3];
00068
00069 void find_sizes(void);
00070 void delete_shapetext();
00071 virtual void create_cmdlist(void);
00072
00073 public:
00074 MoleculeGraphics(DrawMolecule *d) :
00075 Displayable(d) {
00076 molid = d->id();
00077 max_id = 0;
00078 next_id = 0;
00079 next_index = 0;
00080 needRegenerate = 1;
00081 delete_count = 0;
00082 }
00083 virtual ~MoleculeGraphics(void){
00084 delete_shapetext();
00085 }
00086 virtual void prepare() {
00087 if (needRegenerate) create_cmdlist();
00088 }
00089
00091 virtual void cov(float &x, float &y, float &z) {
00092 find_sizes(); x = cov_pos[0]; y = cov_pos[1]; z = cov_pos[2];
00093 }
00094 virtual float scale_factor(void) {
00095 find_sizes(); return cov_scale;
00096 }
00097
00098
00099 int add_point(const float *x);
00100 int add_pickpoint(const float *x);
00101 int add_triangle(const float *x1, const float *x2, const float *x3);
00102 int add_trinorm(const float *x1, const float *x2, const float *x3,
00103 const float *nx1, const float *nx2, const float *nx3);
00104 int add_tricolor(const float *x1, const float *x2, const float *x3,
00105 const float *nx1, const float *nx2, const float *nx3,
00106 int c1, int c2, int c3);
00107 int add_line(const float *x, const float *y, int line_style, int width);
00108 int add_cylinder(const float *x, const float *y,
00109 float radius, int res, int filled);
00110 int add_cone(const float *x, const float *y,
00111 float radius, float radius2, int res);
00112 int add_sphere(const float *x, float r, int res);
00113 int add_text(const float *x, const char *text, float size, float thickness);
00114
00115 int use_materials(int yes_no);
00116 int use_color(int index);
00117 int use_material(const Material *);
00118
00119 void delete_id(int id);
00120 void delete_all(void);
00121 int replace_id(int id);
00122 int index_id(int id);
00123 int num_elements(void){return shapes.num();}
00124 int element_id(int index) { return shapes[index].shape != NONE ? shapes[index].id : -1; }
00125
00128 const char *info_id(int id);
00129
00130 virtual void pick_start(PickMode *pm, DisplayDevice *d,
00131 int btn, int tag,
00132 const int *cell ,
00133 int , const float *) {
00134
00135 pm->pick_graphics(molid, tag, btn, d);
00136 }
00137
00138 };
00139