1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
// $Id: cursor.cxx 748 2007-11-03 17:38:32Z martin $
//
// cursor.cxx - routine for DRAWxtl V5.4 - the GUI version
//
// Coded using the FLTK 1.1.6 widget set
//
// Larry W. Finger, Martin Kroeker and Brian Toby
//
// This module includes cursor support routines
//
// routines contained within this file:
//
// display_cursor_text - output the cursor position into the status line
// draw_cursor - put the cursor on the screen
// find_atom - find atom nearest the cursor position
// find_proj_atom - find atom that projects closest to the cursor
// move_cursor - move the cursor position
#include "drawxtl.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "draw_ext.h"
#include <FL/x.H>
#include "DRAWxtlViewUI.h"
#include "CrystalView.h"
#include "DRAWxtl_proto.h"
void display_cursor_text(void)
{
char Text[500];
char text[100];
char text2[100];
char Text2[100];
char Text3[100];
if (!cur_show) return;
strcpy(Text2,"");
strcpy(Text3,"");
if (! ReadFourMap)
sprintf (Text," Cursor: %.4f,%.4f,%.4f (step=%.2fA)",
cur_cen[0], cur_cen[1], cur_cen[2], drvui->cur_step);
else
sprintf (Text," Cursor: %.4f,%.4f,%.4f (step=%.2fA). Rho=%.3f",
cur_cen[0], cur_cen[1], cur_cen[2], drvui->cur_step,
InterpolateMap (cur_cen[0], cur_cen[1], cur_cen[2]));
if (cur_atom[0] > 0) {
sprintf(Text2," Atoms 1.%s",cur_name[0]);
}
if (cur_atom[1] > 0) {
sprintf(text2," 2.%s",cur_name[1]);
strcat(Text2,text2);
sprintf(Text3,"\n d12=%6.3fA",dist12);
if (cur_atom[2] > 0) {
sprintf(text2," 3.%s",cur_name[2]);
strcat(Text2,text2);
sprintf(text,", d23=%6.3fA, a123=%5.2f",dist23,ang123);
strcat(Text3,text);
if (cur_atom[3] > 0) {
sprintf(text2," 4.%s",cur_name[3]);
strcat(Text2,text2);
sprintf(text,", d34=%6.3fA, a234=%5.2f, tor1234=%5.2f",dist34,ang234,torsion_ang);
strcat(Text3,text);
}
}
}
strcat(Text,Text2);
strcat(Text,Text3);
drvui->Cursor_pos->value(Text);
}
void draw_cursor (void)
{
int i,j;
float vert[3];
if (!cur_show) return;
nvert = 0; /* initialize vertex list */
for (i = 0; i <= 2; ++i) {
for (j = 0; j < 3; j++)
vert[j] = cur_cen[j];
vert[i] = cur_cen[i] - 0.5f / drvui->lat_con[i];
add_vert_nc (vert);
vert[i] = cur_cen[i] + 0.5f / drvui->lat_con[i];
add_vert_nc (vert);
}
glPushMatrix ();
glDisable(GL_LIGHTING);
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_LINES);
glVertex3f (s_vert[0], s_vert[1], s_vert[2]);
glVertex3f (s_vert[3], s_vert[4], s_vert[5]);
glVertex3f (s_vert[6], s_vert[7], s_vert[8]);
glVertex3f (s_vert[9], s_vert[10], s_vert[11]);
glVertex3f (s_vert[12], s_vert[13], s_vert[14]);
glVertex3f (s_vert[15], s_vert[16], s_vert[17]);
glEnd ();
glEnable(GL_LIGHTING);
glPopMatrix ();
}
int find_atom(void)
{
int i,j;
double distance = 1000.0,d;
int closest=0;
nvert=0;
for (i=0;i<natom;i++)
find_all_in_box(i);
for (j=0;j<nvert;j++) {
d= (o_vert[3*j]-cur_cen[0])*(o_vert[3*j]-cur_cen[0])
+(o_vert[3*j+1]-cur_cen[1])*(o_vert[3*j+1]-cur_cen[1])
+(o_vert[3*j+2]-cur_cen[2])*(o_vert[3*j+2]-cur_cen[2]);
if (d<distance) {
distance=d;
closest=j;
}
}
cur_cen[0]=o_vert[3*closest];
cur_cen[1]=o_vert[3*closest+1];
cur_cen[2]=o_vert[3*closest+2];
return closest;
}
int find_proj_atom(int x, int y)
{
int j,k;
double distance = 1.0e15,d;
int closest=0;
int clipped=0;
GLdouble winX, winY, winZ;
int saved_nvert = nvert;
for (j = 0; j < natom; ++j) { // get all atoms in display box
find_all_in_box (j);
}
for (j=saved_nvert;j<nvert;j++) { // loop through all atoms
clipped = 0;
if (clipflag == 1) {
for (k=0;k<3;k++)
if (o_vert[3*j+k] < drvui->frames[drvui->frame_no].clip_lim[k] - 0.01f
|| o_vert[3*j+k] >drvui->frames[drvui->frame_no].clip_lim[k+3] + 0.01f) clipped = 1;
}
if (clipped==1) continue;
gluProject(s_vert[3*j], s_vert[3*j + 1], s_vert[3*j + 2],
modelMatrix, projMatrix, viewport,
&winX, &winY, &winZ);
d = ((float)x - winX) * ((float) x - winX) +
((float) y + winY - viewport[3]) * ((float) y + winY - viewport[3]);
if (d<distance) { // find closest atom (in projection
distance=d;
closest=j;
}
}
nvert = saved_nvert;
cur_cen[0]=o_vert[3*closest]; // set cursor to atom coordinates
cur_cen[1]=o_vert[3*closest+1];
cur_cen[2]=o_vert[3*closest+2];
return closest;
}
void move_cursor (int axis, float inc_amt)
{
if (!cur_show) return;
cur_name[0][0]='\0';
cur_cen[axis] += inc_amt * drvui->cur_step / drvui->lat_con[axis];
}
|