BioInfWeb - TreeGraph / Version 1 / Show File - tgf-tree.h

TreeGraph subversion repository

sventon subversion web client - http://www.sventon.org
[show recent changes]
 
  Help
Rev: HEAD (2) - https://secure.bioinfweb.info/Code/svn/TreeGraph / trunk / main / tgf-tree.h
Show File - tgf-tree.h  [show properties]
spinner
/*
 tgf-tree.h, part of
 treegraph
 Tree formatting program
 Generates vector graphics (SVG,EPS) from .tgf-tree description files.
10   Copyright (c) 2003-04 by Joern Mueller
11 
12 
13   This program is free software; you can redistribute it and/or
14   modify it under the terms of the GNU General Public License
15   as published by the Free Software Foundation; either version 2
16   of the License, or (at your option) any later version.
17 
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21   GNU General Public License for more details.
22 
23   You should have received a copy of the GNU General Public License
24   along with this program (GPL.html); if not, write to the Free Software
25   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26   (also: http://www.gnu.org)
27  */
28 
29 
30 
31 
32 
33 
34 
35 
36  #ifndef __TGF_TREE_H__
37  #define __TGF_TREE_H__
38 
39  #include <iostream>
40  #include <fstream>
41  #include <string>
42  #include <vector>
43  #include <list>
44 
45  #include <cmath>
46  #include <cctype>
47  #include <cstdio>
48 
49  #include "tgf-utils.h"
50  #include "tgf-parser.h"
51  #include "tgf-gostream.h"
52 
53  using namespace std;
54 
55 
56  struct pscommand {
57   bool drawfirst;
58   string text;
59 
60   pscommand(){drawfirst=true;}
61 
62  };
63 
64  struct tree_desc
65  {
66   bool uselength;
67   bool forceauto; //Trotz Laengenangaben ...
68   bool variablelength; //Zweiglaenge proportional zu Baumtiefe
69   bool shownumbers;
70   float extrasep; //Abstand zwischen Randknoten und Randtext
71   float thickness;
72   float min_treewidth;//nur Baum, durch Beschriftung/minlength vorgegeben
73   float min_treeheight;//nur Baum, durch Beschriftung/minlength vorgegeben
74   float treewidth;//nur Baum
75   float klammerrand;//breite des klammerrands.
76   float maxrund;//maximaler Rundungsradius
77   float picwidth;
78   float picheight;
79   float scale;
80   float roundness; //0 eckig, 1 maximal rund
81   float bracketcolwidth; //Platz fuer Klammern am rechten Rand
82   float lenscale; //lenscale*node->len ergibt zweiglaenge in pt (wenn uselength)
83   fontstyle rstyle;
84   fontstyle ustyle[4];
85   fontstyle dstyle[4];
86   fontstyle brstyle;
87   string colsep; //Trennung zwischen Spalten ueber Ast
88   fRect Rand;
89 
90   tree_desc(void);
91   void setstyle(const string& ident,const string& typ, float sz);
92   void showstyle(const std::string& id,const fontstyle& f) const;
93   void show(void) const;
94  };
95 
96 
97 
98 
99  class tnode
100  {
101  public:
102   char *lbl;
103   fstring r;
104   fstring u[4];
105   fstring d[4];
106   fPoint pos;
107   float len;// \len{...} (oder autolength)
108   float minlen;//erst: 0, dann: (wenn autolength: Textbreite, dann ggf. \minlen)
109   float minabove;
110   float minbelow;
111   bool userset[3]; //minlen,minabove,minbelow wurden explizit angegeben
112 
113   int depth;
114   bool prune;
115 
116   tnode *prev;
117   tnode *next;
118   tnode *down;
119 
120 
121   tnode(tnode *prv, float l=autolength);
122 
123   void selection_sort_children(int);
124   void swap_children(void);
125   bool permute(list<int>& perm);
126   void collapse(void);
127   bool leaf(void) const { return next==0;}
128   bool terminal(void) const { return next==0 || prune;}
129   bool root(void) const { return prev==0;}
130   int nchildren(void) const;
131   int nterminals(void) const;
132   void removechild(tnode *ch);
133   void insertchild(tnode *ch);
134 
135   bool has_label(void) const { return lbl!=0;}
136   void setlabel(const string &a);
137   const char *label(void) const {return lbl;}
138 
139 
140 
141   void ladderize_sichtbare(int);
142   void symladderize(int);
143   void calcdepth_sichtbar(void);
144   const tnode *unterster_sichtbarer(void) const;
145   const tnode *oberster_sichtbarer(void) const;
146   void sethpos(float,float);
147   float sethpos_fixed(float x0,float w,float stdl);
148   void sethpos_len(float x0,float sc);
149   float optlen(std::vector<float>& x,int tief,float w);
150   void getoptlenscale(float, float& smin, float& smax, const tree_desc&);
151   float normlen_fixed(std::vector<float>& x,int tief,float w);
152   float maxrund(void) const;
153  };
154 
155 
156 
157  struct klammer
158  {
159   fstring text;
160   string lb[2];//label-namen
161   float sp;
162   int style;
163 
164  enum
165  {
166   geschweift=0,
167   eckig=1,
168   gedreht=2
169  };
170 
171   klammer(){ sp=0; style=geschweift;}
172   static float breite;
173  };
174 
175 
176 
177 
178  class label_list
179  {
180   tnode **nd; //Knoten, nach labeln sortiert
181   int nlabel;
182   int nnodes;
183   int autovar;
184  public:
185 
186   void random_label(char[]);
187 
188   label_list();
189   ~label_list();
190 
191   int total_nodes(void) const {return nnodes;}
192   void init(int a);
193   void einsortiere_label(tnode*);
194   void kill_label(const char *s);
195   const tnode *bfind_label(const char *s) const;
196 
197  };
198 
199 
200 
201  class tree : public tnode
202  {
203   tree_desc dsc;
204   list<klammer> kl;
205   list<pscommand> pcl;
206   label_list lb;
207   bool drty;
208   string definition_part;//alles zwischen \begindef und \enddef
209 
210   void read_definitions(parser&);
211   void fill_labels(int); //Labels in sortierte Liste lb packen
212   void user_labels(tnode*, label_list&);
213   void auto_labels(tnode*, label_list&);
214 
215 
216   void vrescale(float);
217   void affine_transform(float m[4], float v[2]);
218   void calcvpos(void);
219   int calchpos(void);
220   int calchpos_fixed(void);
221   int calchpos_len(void);
222   void calcpos(void);
223   void calc_treewidth(void);
224   void calc_mindimensions(void);
225 
226   bool reroot(tnode *);
227 
228   void remove_subtree(tnode *);
229 
230 
231   void renderNode(const tnode*, gostream*) const;
232   void renderRandklammern(gostream *) const;
233 
234   void writenodes(ostream& aus,const tnode* =0) const;
235 
236  public:
237 
238   tree();
239   ~tree();
240 
241   void write(ostream&,const tnode* =0);
242   void read(istream&);
243   void render(gostream*) const;
244 
245   void edit(void);
246   void show_dsc(void) const { dsc.show();};
247 
248   bool dirty(void) const {return drty;}
249 
250   void importNEXUS(ifstream&);
251   void exportNEXUS(ostream&);
252  };
253 
254  class fehler {};
255  class missing_length : public fehler {};
256  class label_err : public fehler {};
257  class string_err : public fehler {};
258  class file_err : public fehler {};
259 
260 
261  float helv_stringwidth(const fstring& s);
262  float min_node_width(const tnode *p, const string& colsep);
263 
264 
265  #endif //__TGF_TREE_H__


feed icon

sventon 2.5.1

Valid XHTML 1.0 Strict   CSS ist valide!
TreeGraph icon
bioinfweb RSS feed TreeGraph 2 on ResearchGate bioinfweb on twitter bioinfweb on GitHub
bioinfweb - Biology & Informatics Website