Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

DrawingMetrics.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 //
00023 // 2005.11.18.ET.
00024 //
00025 
00026 //
00027 // DrawingMetrics.h
00028 //
00029 // -- Container for the default pedigree drawing metrics
00030 // 
00031 #ifndef DrawingMetrics_INCLUDED
00032 #define DrawingMetrics_INCLUDED
00033 
00034 #include <string>
00035 #include <set>
00036 // For operator << :
00037 #include <ostream>
00038 // For debugging, at least:
00039 #include <iostream>
00040 
00041 #include <iomanip>
00042 #include <sstream>
00043 
00044 #include <string.h>
00045 #include <stdlib.h>
00046 
00047 #include "DrawingColor.h"
00048 #include <vector>
00049 
00050 class DrawingMetricsLoader;
00052 //
00053 // DrawingMedia class
00054 // 
00056 class DrawingMedia{
00057 public:
00058         //
00059         // Constructor.  Note that units default to millimeters.
00060         //               Recognized units are the same as for CSS: pt px mm cm in
00061         //               
00062         DrawingMedia(const char *name="a4",double width=210.0,double height=297.0,const char *unit="mm" );
00063         const std::string getName();
00064         const std::string getUnit();
00065         double            getWidth() const;
00066         double            getHeight() const;
00067         
00068         //
00069         // 
00070         //
00071         struct compare
00072         {
00073                 bool operator()(const DrawingMedia & m1, const DrawingMedia & m2) const
00074                 {
00075                         return strcasecmp(m1._name.c_str(), m2._name.c_str() ) < 0;
00076                 }
00077         };
00078         
00079 private:
00080         
00081         friend class DrawingMetricsLoader;
00082         
00083         std::string _name;
00084         double _width;
00085         double _height;
00086         std::string _unit;
00087         
00088 };
00089 
00090 
00092 //
00093 // DrawingMetrics class
00094 // 
00096 class DrawingMetrics
00097 {
00098 public:
00099         
00100 private:
00101         
00102         friend class DrawingMetricsLoader;
00103         friend class DrawingLabel;
00104         
00105         //
00106         // Basic unit variable:
00107         //
00108         static std::string _unit;
00109         //
00110         // The following all use the basic unit variable, _unit:
00111         //
00112         static double _horizontalInterval;
00113         static double _iconInterval;
00114         static double _iconDiameter;
00115         static double _verticalDrop1;
00116         static double _verticalDrop2;
00117         static double _cellSpacing;   // Apparently not used => _labelMargin is used instead.
00118         static double _lineHeight;
00119         static double _yMaximum;
00120         static double _yMinimum;      // Is this needed / used ?
00121         static double _labelMargin;
00122         static double _verticalTick;
00123         
00124         //
00125         // Line width has its own unit variable:
00126         //
00127         static double _lineWidth;
00128         static std::string _lineWidthUnit;
00129         //
00130         // Font stuff:
00131         //
00132         static std::string _fontFamily;
00133         static double _fontSize;
00134         static double _headerFontSize;
00135         static std::string _fontSizeUnit;
00136         
00137         static double _scalingFactor;
00138         static double _pointsToMmConversionFactor;
00139         
00140         //
00141         // State flags which control output:
00142         //
00143         static bool _isEmbedded;
00144         static bool _displayBirthOrder;
00145         static bool _blackAndWhite;
00146         static bool _color;
00147         static bool _noIconLabels;
00148         
00149         //
00150         // Output File naming prefix
00151         // (If there is only one pedigree, this 
00152         // _is_ the file name.  Otherwise, it is
00153         // just the prefix):
00154         //
00155         static std::string _drawingFileNamePrefix;
00156         static bool _hasOnlyOnePedigree;
00157         
00158 public:
00159         
00160         static std::set<DrawingMedia,DrawingMedia::compare> media;
00161         //
00162         // 2006.12.22.ET: Default colors used for icon shadings:
00163         //
00164         static std::vector<DrawingColor> monochromat;
00165         static std::vector<DrawingColor> bichromat;
00166         
00167 public:
00168         
00169         //
00170         // Constructors:
00171         //
00172         
00173         //
00174         // Static Methods:
00175         //
00176         // Getters:
00177         static double getHorizontalInterval();
00178         static double getIconInterval();
00179         static double getIconDiameter();
00180         static double getIconRadius();
00181         static double getVerticalDrop1();
00182         static double getVerticalDrop2();
00183         static double getVerticalTick();
00184         
00185         static double      getLineWidth();
00186         static std::string getLineWidthUnit();
00187         
00188         static double getLineHeight();
00189         static double getLabelMargin();
00190         static double getScalingFactor();
00191         static double getPointsToMmConversionFactor();
00192         static void setIconInterval(double iconInterval);
00193         static DrawingMedia getDrawingMedia(std::string name);
00194         
00195         static std::string getFontFamily();
00196         static double getFontSize();
00197         static double getHeaderFontSize();
00198         static std::string getFontSizeUnit();
00199         
00200         static bool getEmbeddedState();
00201         static std::string getDrawingFileNamePrefix();
00202         static bool getHasOnlyOnePedigreeState();
00203         static bool getDisplayBirthOrder();
00204         
00205         static bool getColor();
00206         static bool getBlackAndWhite();
00207         static bool getNoIconLabels();
00208         
00209         //
00210         // Setters:
00211         //
00212         static void setLineWidth(double lineWidth);
00213         static void setLineWidthUnit(const std::string lineWidthUnit);
00214         
00215         static void setFontFamily(const std::string &fontFamily);
00216         static void setFontSize(double fontSize);
00217         static void setHeaderFontSize(double headerFontSize);
00218         static void setFontSizeUnit(const std::string &fontSizeUnit);
00219         
00220         static void setLineMetrics(double lineHeight,double yMaximum,double yMinimum, unsigned labelCount );
00221         
00222         static double getYMaximum();
00223         static double getYMinimum();
00224         
00225         static void setEmbeddedState(bool isEmbedded);
00226         static void setDrawingFileNamePrefix(const std::string &prefix);
00227         static void setHasOnlyOnePedigreeState(bool hasOnlyOne);
00228         static void setDisplayBirthOrder(bool value);
00229         
00230         static void setColor(bool value);
00231         static void setBlackAndWhite(bool value);
00232         static void setNoIconLabels(bool value);
00233         
00234 };
00235 
00237 //
00238 // DrawingMetricsLoader 
00239 // 
00240 // is the Friend class that 
00241 // initializes the DrawingMetrics 
00242 // class:
00243 //
00245 class DrawingMetricsLoader
00246 {
00247 public:
00248         static DrawingMetricsLoader drawingMetricsLoader;
00249         DrawingMetricsLoader(){
00250                 
00251                 //
00252                 // Basic unit variable -- DON'T CHANGE : CURRENTLY MUST BE MM
00253                 //
00254                 // FIX ME : IN FUTURE, ALLOW ANY UNITS ?  MAYBE NO ? ...
00255                 //
00256                 DrawingMetrics::_unit = "mm";
00257                 //
00258                 // The following variables all share the "_unit" units and must be
00259                 // scaled according to _scalingFactor depending on media output:
00260                 // 
00261                 //DrawingMetrics::_horizontalInterval = 7.5;
00262                 DrawingMetrics::_horizontalInterval = 12;
00263                 DrawingMetrics::_iconInterval = 2*DrawingMetrics::_horizontalInterval;
00264                 DrawingMetrics::_iconDiameter = 6;
00265                 DrawingMetrics::_verticalDrop1=30;
00266                 DrawingMetrics::_verticalDrop2 = 7.5;
00267                 DrawingMetrics::_cellSpacing = 1; // Hmm ... Not used? FIX ME: NOT USED? ONLY _labelMargin USED INSTEAD ?
00268                 DrawingMetrics::_lineHeight = 3; // in mm
00269                 DrawingMetrics::_labelMargin = 1; // one mm margination is good
00270                 DrawingMetrics::_verticalTick=1; // one mm vertical tick drop (used for drawing twins) is good
00271                 
00272                 //
00273                 // LineWidth has its own unit variable:
00274                 //
00275                 DrawingMetrics::_lineWidth = 0.5;
00276                 DrawingMetrics::_lineWidthUnit = "mm";
00277                 //
00278                 // FontSize has its own unit variable ... :
00279                 // 
00280                 // NOTE BENE:  ...but only "mm","px", and "pt" are recognized:
00281                 //
00282                 DrawingMetrics::_fontFamily = "Bitstream Vera Sans";
00283                 DrawingMetrics::_fontSize = 12;
00284                 DrawingMetrics::_headerFontSize = 18;
00285                 DrawingMetrics::_fontSizeUnit = "px";
00286                 
00287                 //
00288                 // State flags:
00289                 //
00290                 DrawingMetrics::_isEmbedded=false;
00291                 DrawingMetrics::_displayBirthOrder=false;
00292                 //
00293                 // These two override the automatic settings:
00294                 //
00295                 DrawingMetrics::_blackAndWhite=false;
00296                 DrawingMetrics::_color=false;
00297                 
00298                 //
00299                 // Icon labels are on by default
00300                 // because this seems the better choice
00301                 // for lab work (but is not the choice
00302                 // for publication):
00303                 // 
00304                 DrawingMetrics::_noIconLabels=false;
00305                 
00306                 //
00307                 // This is the default scaling factor used for SVG drawing output to a screen.
00308                 // Assuming a default screen has 96 dots (pixels) per inch, we then have:
00309                 // 
00310                 //  96 dots    1 inch     1 cm
00311                 //  ------- x -------- x ------- = 3.7795 dots per millimeter
00312                 //  1 inch     2.54 cm    10 mm
00313                 //  
00314                 // Although DrawingMetrics makes it look like you could use
00315                 // any units you want, in reality the measurement system is based on SI
00316                 // millimeters
00317                 // 
00318                 DrawingMetrics::_scalingFactor = 3.78;
00319                 //
00320                 // Since LASi was designed for Postscript, LASi returns font metrics
00321                 // in points, defined as 1/72nd of an inch. As Madeline uses SI units,
00322                 // specifically millimeters, we have this conversion factor:
00323                 //
00324                 //    1                     2.54 cm      10 mm
00325                 //  ---- inch / 1 point x ----------- x ------- = 0.35278 mm per point
00326                 //   72                     1 inch        1 cm
00327                 DrawingMetrics::_pointsToMmConversionFactor = 0.3527777778;
00328                 
00329                 //
00330                 // ISO standard paper media sizes
00331                 // ==============================
00332                 // 
00333                 // Markus Kuhn provides a nice overview of the ISO
00334                 // paper sizes at
00335                 // http://www.cl.cam.ac.uk/~mgk25/iso-paper.html 
00336                 // 
00337                 // Note that because the ratio of the sides is 1:sqrt(2),
00338                 // cutting one size in half parallel to the shorter side yields
00339                 // two pages of the next smaller ISO size.  This is not the
00340                 // case with the American and Canadian size standards:
00341                 // 
00342                 DrawingMetrics::media.insert(DrawingMedia("4A0",1682,2378));
00343                 DrawingMetrics::media.insert(DrawingMedia("2A0",1189,1682));
00344                 DrawingMetrics::media.insert(DrawingMedia("A0",841,1189));
00345                 DrawingMetrics::media.insert(DrawingMedia("A2",420,594));
00346                 DrawingMetrics::media.insert(DrawingMedia("A3",297,420));
00347                 DrawingMetrics::media.insert(DrawingMedia("A4",210,297));
00348                 DrawingMetrics::media.insert(DrawingMedia("A5",148,210));
00349                 DrawingMetrics::media.insert(DrawingMedia("A6",105,148));
00350                 DrawingMetrics::media.insert(DrawingMedia("A7",74,105));
00351                 DrawingMetrics::media.insert(DrawingMedia("A8",52,74));
00352                 DrawingMetrics::media.insert(DrawingMedia("A9",37,52));
00353                 DrawingMetrics::media.insert(DrawingMedia("A10",26,37));
00354                 DrawingMetrics::media.insert(DrawingMedia("B0",1000,1414));
00355                 DrawingMetrics::media.insert(DrawingMedia("B1",707,1000));
00356                 DrawingMetrics::media.insert(DrawingMedia("B2",500,707));
00357                 DrawingMetrics::media.insert(DrawingMedia("B3",353,500));
00358                 DrawingMetrics::media.insert(DrawingMedia("B4",250,353));
00359                 DrawingMetrics::media.insert(DrawingMedia("B5",176,250));
00360                 DrawingMetrics::media.insert(DrawingMedia("B6",125,176));
00361                 DrawingMetrics::media.insert(DrawingMedia("B7",88,125));
00362                 DrawingMetrics::media.insert(DrawingMedia("B8",62,88));
00363                 DrawingMetrics::media.insert(DrawingMedia("B9",44,62));
00364                 DrawingMetrics::media.insert(DrawingMedia("B10",31,44));
00365                 DrawingMetrics::media.insert(DrawingMedia("C0",917,1297));
00366                 DrawingMetrics::media.insert(DrawingMedia("C1",648,917));
00367                 DrawingMetrics::media.insert(DrawingMedia("C2",458,648));
00368                 DrawingMetrics::media.insert(DrawingMedia("C3",324,458));
00369                 DrawingMetrics::media.insert(DrawingMedia("C4",229,324));
00370                 DrawingMetrics::media.insert(DrawingMedia("C5",162,229));
00371                 DrawingMetrics::media.insert(DrawingMedia("C6",114,162));
00372                 DrawingMetrics::media.insert(DrawingMedia("C7",81,114));
00373                 DrawingMetrics::media.insert(DrawingMedia("C8",57,81));
00374                 DrawingMetrics::media.insert(DrawingMedia("C9",40,57));
00375                 DrawingMetrics::media.insert(DrawingMedia("C10",28,40));
00376                 //
00377                 // North American standard paper media sizes
00378                 // =========================================
00379                 // 
00380                 DrawingMetrics::media.insert(DrawingMedia("letter",216,279));
00381                 DrawingMetrics::media.insert(DrawingMedia("legal",216,356));
00382                 DrawingMetrics::media.insert(DrawingMedia("executive",190,254));
00383                 DrawingMetrics::media.insert(DrawingMedia("ledger",279,432));
00384                 //
00385                 // Computer screen resolutions for screen-based SVG output
00386                 // =======================================================
00387                 // 
00388                 DrawingMetrics::media.insert(DrawingMedia("VGA",640,480,"px"));
00389                 DrawingMetrics::media.insert(DrawingMedia("SVGA",800,600,"px"));
00390                 DrawingMetrics::media.insert(DrawingMedia("XGA",1024,768,"px"));
00391                 DrawingMetrics::media.insert(DrawingMedia("SXGA",1280,1024,"px"));
00392                 DrawingMetrics::media.insert(DrawingMedia("UXGA",1600,1200,"px"));
00393                 DrawingMetrics::media.insert(DrawingMedia("WXGA",1366,768,"px"));
00394                 DrawingMetrics::media.insert(DrawingMedia("WSXGA",1680,1050,"px"));
00395                 DrawingMetrics::media.insert(DrawingMedia("WUXGA",1920,1200,"px"));
00396                 //DrawingMetrics::media.insert(DrawingMedia("",,));
00397                 
00398                 //
00399                 // Monochromat and bichromatic color series default colors
00400                 // =======================================================
00401                 //
00402                 // => For monochromatic series, just the "monochromat" colors are
00403                 //    used to create ColorSeries.
00404                 //
00405                 // => For bichromatic series, both the "monochromat" and the 
00406                 //    "bichromat" at a given matching index are used.
00407                 //    
00408                 // => The very first color series is used as the default when there is
00409                 //    only one pie section.  Therefore, we force it to be plain black
00410                 //    & white.
00411                 //    
00412                 // => The 2nd, 3rd, 4th, etc. color series are to be used when
00413                 //    there is more than one pie section:
00414                 //    
00415                 //DrawingMetrics::monochromat.push_back(DrawingColor("black","#000")); // DEFAULT
00416                 //DrawingMetrics::bichromat.push_back(  DrawingColor("white","#fff")); // DEFAULT
00417                 
00418                 DrawingMetrics::monochromat.push_back(DrawingColor("navy","#0000a0"));
00419                 DrawingMetrics::bichromat.push_back(  DrawingColor("maize","#ffd803"));
00420                 DrawingMetrics::monochromat.push_back(DrawingColor("red","#800"));
00421                 DrawingMetrics::bichromat.push_back(  DrawingColor("banana","#ffffa2"));
00422                 DrawingMetrics::monochromat.push_back(DrawingColor("forest","#003f00"));
00423                 DrawingMetrics::bichromat.push_back(  DrawingColor("peach","#ffcca2"));
00424                 DrawingMetrics::monochromat.push_back(DrawingColor("ceramicBlue","#768dff"));
00425                 DrawingMetrics::bichromat.push_back(  DrawingColor("lavender","#fcf"));
00426         }
00427 };
00428 
00429 #endif

Generated on Tue Feb 27 14:39:23 2007 for MINIMADELINE by  doxygen 1.4.4