NCBI C Toolkit Cross Reference

C/desktop/gtrdraw.c


  1 /*
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE
  5 *               National Center for Biotechnology Information
  6 *
  7 *  This software/database is a "United States Government Work" under the
  8 *  terms of the United States Copyright Act.  It was written as part of
  9 *  the author's official duties as a United States Government employee and
 10 *  thus cannot be copyrighted.  This software/database is freely available
 11 *  to the public for use. The National Library of Medicine and the U.S.
 12 *  Government have not placed any restriction on its use or reproduction.
 13 *
 14 *  Although all reasonable efforts have been taken to ensure the accuracy
 15 *  and reliability of the software and data, the NLM and the U.S.
 16 *  Government do not and cannot warrant the performance or results that
 17 *  may be obtained by using this software or data. The NLM and the U.S.
 18 *  Government disclaim all warranties, express or implied, including
 19 *  warranties of performance, merchantability or fitness for any particular
 20 *  purpose.
 21 *
 22 *  Please cite the author in any work or product based on this material.
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name: gtrdraw.c
 27 *
 28 * Author(s): John Kuzio
 29 *
 30 * Version Creation Date: 98-01-01
 31 *
 32 * $Revision: 6.4 $
 33 *
 34 * File Description: sentinal trees
 35 *
 36 * Modifications:
 37 * --------------------------------------------------------------------------
 38 * Date       Name        Description of modification
 39 * --------------------------------------------------------------------------
 40 * $Log: gtrdraw.c,v $
 41 * Revision 6.4  1999/10/04 17:46:23  kans
 42 * include vibrant.h
 43 *
 44 * Revision 6.3  1998/10/01 16:37:10  kuzio
 45 * cast
 46 *
 47 * Revision 6.2  1998/09/16 19:00:36  kuzio
 48 * cvs logs
 49 *
 50 * ==========================================================================
 51 */
 52 
 53 #include <vibrant.h>
 54 #include <drawingp.h>
 55 #include <gtrdraw.h>
 56 
 57 /* common */
 58 
 59 static void CleanGSP (BigScalar calldata)
 60 {
 61   GraphTreeSentPtr gtp;
 62 
 63   if ((gtp = (GraphTreeSentPtr) calldata) == NULL)
 64     return;
 65   MemFree (gtp->epa);
 66   MemFree (gtp->offsetX);
 67   MemFree (gtp->offsetY);
 68   ValNodeFreeData (gtp->vnpnames);
 69   MemFree (gtp);
 70   return;
 71 }
 72 
 73 static void PlotTheTreePlot (Int4Ptr epa, Int4 numval, ValNodePtr vnp,
 74                              Int2 fontsize, Boolean flagLabelNodes,
 75                              AttPData PNTR curattrib,
 76                              Int2 scrolloffsetX, Int2 scrolloffsetY)
 77 {
 78   Int4    i;
 79   PoinT   point1, point2;
 80   Int2    width, height;
 81   CharPtr name;
 82   FonT    f, fx;
 83   Uint1   curR, curG, curB;
 84 
 85   if (flagLabelNodes)
 86   {
 87     curR = curattrib->color[0];
 88     curG = curattrib->color[1];
 89     curB = curattrib->color[2];
 90     fx = FindNextResidentFont (NULL);
 91     f = CreateFont (Helvetica (fontsize, STYLE_BOLD));
 92     SelectFont (f);
 93   }
 94 
 95   for (i = 0; i < numval; i++)
 96   {
 97     point1.x = scrolloffsetX + (Int2) *epa++;
 98     point1.y = scrolloffsetY + (Int2) *epa++;
 99     point2.x = scrolloffsetX + (Int2) *epa++;
100     point2.y = scrolloffsetY + (Int2) *epa++;
101     DrawLine (point1, point2);
102     if (flagLabelNodes && vnp->data.ptrvalue != NULL)
103     {
104       SelectColor (255, 0, 0);
105       name = (CharPtr) vnp->data.ptrvalue;
106       if (StrLen (name) > 8)
107         name[8] = '\0';
108       width = StringWidth (name);
109       height = FontHeight ();
110       PaintStringEx (name,(Int2)(point2.x-(width/2)),(Int2)(point2.y+height));
111       SelectColor (curR, curG, curB);
112     }
113     vnp = vnp->next;
114   }
115 
116   if (flagLabelNodes)
117   {
118     SelectFont (fx);
119     DeleteFont (f);
120   }
121 
122   return;
123 }
124 
125 static void TreeSentProc (BigScalar calldata, PrimDrawContext pdc)
126 {
127   GraphTreeSentPtr gtp;
128   DrawInfoPtr      dInfoPtr;
129   ScaleInfo        sInfo;
130 
131   if ((gtp = (GraphTreeSentPtr) calldata) == NULL)
132     return;
133   if (gtp->epa == NULL)
134     return;
135 
136   dInfoPtr = (DrawInfoPtr) pdc;
137   sInfo    = dInfoPtr->scale;
138   if (gtp->offsetX == NULL)
139   {
140     gtp->offsetX = (Int4Ptr) MemNew (sizeof (Int4));
141     *(gtp->offsetX) = sInfo.offsetX;
142     gtp->offsetY = (Int4Ptr) MemNew (sizeof (Int4));
143     *(gtp->offsetY) = sInfo.offsetY;
144   }
145   PlotTheTreePlot (gtp->epa, gtp->numval, gtp->vnpnames,
146                    gtp->fontsize, gtp->flagLabelNodes,
147                    &(dInfoPtr->curattrib),
148                    (Int2) (sInfo.offsetX - (*(gtp->offsetX))),
149                    (Int2) (sInfo.offsetY - (*(gtp->offsetY))));
150   return;
151 }
152 
153 static GraphTreeSentPtr AddTreeSentinelToPicture (SegmenT seg,
154                                                   TreeNodePtr ptrNode,
155                                                   Int2 fontsize,
156                                                   Boolean flagLabelNodes)
157 {
158   GraphTreeSentPtr gtp;
159   Int4Ptr          epap;
160   Int4             numval, nwidth, xwidth, ndepth, xdepth;
161   TreeNodePtr      ptrNodeNext;
162   Boolean          flagTakeNext;
163   ValNodePtr       vnp;
164 
165   if ((gtp = (GraphTreeSentPtr) MemNew (sizeof (GraphTreeSentData))) == NULL)
166     return NULL;
167   if ((gtp->epa = (Int4Ptr) MemNew (sizeof (Int4) * 262144)) == NULL)
168     return NULL;
169   gtp->offsetX = NULL;
170   gtp->offsetY = NULL;
171   gtp->flagIsGUI = VibrantIsGUI ();
172   gtp->vnpnames = NULL;
173   gtp->fontsize = fontsize;
174   gtp->flagLabelNodes = flagLabelNodes;
175 
176   epap = gtp->epa;
177   numval = 0;
178   ptrNodeNext = NULL;
179   flagTakeNext = FALSE;
180   while ((ptrNodeNext = ExploreTree (ptrNode, ptrNodeNext,
181           &flagTakeNext)) != NULL)
182   {
183     if (ptrNodeNext->ptrChildLeft != NULL)
184     {
185       *epap++ = ptrNodeNext->xcoord;
186       *epap++ = ptrNodeNext->ycoord;
187       *epap++ = ptrNodeNext->ptrChildLeft->xcoord;
188       *epap++ = ptrNodeNext->ptrChildLeft->ycoord;
189       vnp = ValNodeNew (gtp->vnpnames);
190       if (gtp->vnpnames == NULL)
191         gtp->vnpnames = vnp;
192       if ((ptrNodeNext->ptrChildLeft->ptrChildLeft == NULL) &&
193           (ptrNodeNext->ptrChildLeft->ptrChildRight == NULL))
194       {
195         vnp->data.ptrvalue = (Pointer) StringSave
196                               (ptrNodeNext->ptrChildLeft->name);
197       }
198       numval++;
199     }
200     if (ptrNodeNext->ptrChildRight != NULL)
201     {
202       *epap++ = ptrNodeNext->xcoord;
203       *epap++ = ptrNodeNext->ycoord;
204       *epap++ = ptrNodeNext->ptrChildRight->xcoord;
205       *epap++ = ptrNodeNext->ptrChildRight->ycoord;
206       vnp = ValNodeNew (gtp->vnpnames);
207       if (gtp->vnpnames == NULL)
208         gtp->vnpnames = vnp;
209       if ((ptrNodeNext->ptrChildRight->ptrChildLeft == NULL) &&
210           (ptrNodeNext->ptrChildRight->ptrChildRight == NULL))
211       {
212         vnp->data.ptrvalue = (Pointer) StringSave
213                               (ptrNodeNext->ptrChildRight->name);
214       }
215       numval++;
216     }
217     flagTakeNext = FALSE;
218   }
219   gtp->numval = numval;
220 
221   nwidth = GetMinimumTreeXcoord (ptrNode);
222   ndepth = GetMinimumTreeYcoord (ptrNode);
223   xwidth = GetMaximumTreeXcoord (ptrNode);
224   xdepth = GetMaximumTreeYcoord (ptrNode);
225   xwidth += 32;
226   xdepth += 16;
227   gtp->snt = AddSntRectangle (seg, nwidth, ndepth, xwidth, xdepth,
228                               TreeSentProc, (BigScalar) gtp,
229                               CleanGSP, 0);
230   return gtp;
231 }
232 
233 extern SegmenT DrawTree (TreeNodePtr ptrNode)
234 {
235   SegmenT seg;
236 
237   seg = CreatePicture ();
238   AddTreeSentinelToPicture (seg, ptrNode, 8, TRUE);
239   return seg;
240 }
241 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.