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 _useQuadrantShadingMethod;
00148         static bool _noIconLabels;
00149         static bool _outputPedTable;
00150         static bool _outputDataTable;
00151         
00152         static bool _noLabelTruncation;
00153         //
00154         // Output File naming prefix
00155         // (If there is only one pedigree, this 
00156         // _is_ the file name.  Otherwise, it is
00157         // just the prefix):
00158         //
00159         static std::string _drawingFileNamePrefix;
00160         static bool _hasOnlyOnePedigree;
00161         
00162 public:
00163         
00164         static std::set<DrawingMedia,DrawingMedia::compare> media;
00165         //
00166         // 2006.12.22.ET: Default colors used for icon shadings:
00167         //
00168         static std::vector<DrawingColor> monochromat;
00169         static std::vector<DrawingColor> bichromat;
00170         
00171 public:
00172         
00173         //
00174         // Constructors:
00175         //
00176         
00177         //
00178         // Static Methods:
00179         //
00180         // Getters:
00181         static double getHorizontalInterval();
00182         static double getIconInterval();
00183         static double getIconDiameter();
00184         static double getIconRadius();
00185         static double getVerticalDrop1();
00186         static double getVerticalDrop2();
00187         static double getVerticalTick();
00188         
00189         static double      getLineWidth();
00190         static std::string getLineWidthUnit();
00191         
00192         static double getLineHeight();
00193         static double getLabelMargin();
00194         static double getScalingFactor();
00195         static double getPointsToMmConversionFactor();
00196         static void setIconInterval(double iconInterval);
00197         static DrawingMedia getDrawingMedia(std::string name);
00198         
00199         static std::string getFontFamily();
00200         static double getFontSize();
00201         static double getHeaderFontSize();
00202         static std::string getFontSizeUnit();
00203         
00204         static bool getEmbeddedState();
00205         static std::string getDrawingFileNamePrefix();
00206         static bool getHasOnlyOnePedigreeState();
00207         static bool getDisplayBirthOrder();
00208         
00209         static bool getColor();
00210         static bool getBlackAndWhite();
00211         static bool getQuadrantShading();
00212         static bool getNoIconLabels();
00213         static bool getHasOutputPedTable();
00214         static bool getHasOutputDataTable();
00215         //
00216         // Setters:
00217         //
00218         static void setLineWidth(double lineWidth);
00219         static void setLineWidthUnit(const std::string lineWidthUnit);
00220         
00221         static void setFontFamily(const std::string &fontFamily);
00222         static void setFontSize(double fontSize);
00223         static void setHeaderFontSize(double headerFontSize);
00224         static void setFontSizeUnit(const std::string &fontSizeUnit);
00225         
00226         static void setLineMetrics(double lineHeight,double yMaximum,double yMinimum, unsigned labelCount );
00227         
00228         static double getYMaximum();
00229         static double getYMinimum();
00230         
00231         static void setEmbeddedState(bool isEmbedded);
00232         static void setDrawingFileNamePrefix(const std::string &prefix);
00233         static void setHasOnlyOnePedigreeState(bool hasOnlyOne);
00234         static void setDisplayBirthOrder(bool value);
00235         
00236         static void setColor(bool value);
00237         static void setBlackAndWhite(bool value);
00238         static void setQuadrantShading(bool value);
00239         static void setNoIconLabels(bool value);
00240         static void setOutputPedTable(bool value);
00241         static void setOutputDataTable(bool value);
00242         
00243         //
00244         // 2011.11.18.ET Addenda:
00245         //
00246         static bool getNoLabelTruncation();
00247         static void setNoLabelTruncation(bool value);
00248         
00249 };
00250 
00252 //
00253 // DrawingMetricsLoader 
00254 // 
00255 // is the Friend class that 
00256 // initializes the DrawingMetrics 
00257 // class:
00258 //
00260 class DrawingMetricsLoader
00261 {
00262 public:
00263         static DrawingMetricsLoader drawingMetricsLoader;
00264         DrawingMetricsLoader(){
00265                 
00266                 //
00267                 // Basic unit variable -- DON'T CHANGE : CURRENTLY MUST BE MM
00268                 //
00269                 // FIX ME : IN FUTURE, ALLOW ANY UNITS ?  MAYBE NO ? ...
00270                 //
00271                 DrawingMetrics::_unit = "mm";
00272                 //
00273                 // The following variables all share the "_unit" units and must be
00274                 // scaled according to _scalingFactor depending on media output:
00275                 // 
00276                 //DrawingMetrics::_horizontalInterval = 7.5;
00277                 DrawingMetrics::_horizontalInterval = 12;
00278                 DrawingMetrics::_iconInterval = 2*DrawingMetrics::_horizontalInterval;
00279                 DrawingMetrics::_iconDiameter = 6;
00280                 DrawingMetrics::_verticalDrop1=30;
00281                 DrawingMetrics::_verticalDrop2 = 7.5;
00282                 DrawingMetrics::_cellSpacing = 1; // Hmm ... Not used? FIX ME: NOT USED? ONLY _labelMargin USED INSTEAD ?
00283                 DrawingMetrics::_lineHeight = 3; // in mm
00284                 DrawingMetrics::_labelMargin = 1; // one mm margination is good
00285                 DrawingMetrics::_verticalTick=1; // one mm vertical tick drop (used for drawing twins) is good
00286                 
00287                 //
00288                 // LineWidth has its own unit variable:
00289                 //
00290                 DrawingMetrics::_lineWidth = 0.5;
00291                 DrawingMetrics::_lineWidthUnit = "mm";
00292                 //
00293                 // FontSize has its own unit variable ... :
00294                 // 
00295                 // NOTA BENE:  ...but only "mm","px", and "pt" are recognized:
00296                 //
00297                 // 2009.09.01.ET: Changed default font to DejaVu Sans
00298                 // 
00299                 DrawingMetrics::_fontFamily = "DejaVu Sans";
00300                 DrawingMetrics::_fontSize = 12;
00301                 DrawingMetrics::_headerFontSize = 18;
00302                 DrawingMetrics::_fontSizeUnit = "px";
00303                 
00304                 //
00305                 // State flags:
00306                 //
00307                 DrawingMetrics::_isEmbedded=false;
00308                 DrawingMetrics::_displayBirthOrder=false;
00309                 //
00310                 // These two override the automatic settings:
00311                 //
00312                 DrawingMetrics::_blackAndWhite=false;
00313                 DrawingMetrics::_color=false;
00314                 //
00315                 // 2010.09.28.ET addendum:
00316                 // The quadrant shading method is off by default:
00317                 //
00318                 DrawingMetrics::_useQuadrantShadingMethod=false;
00319                 //
00320                 // Icon labels are on by default
00321                 // because this seems the better choice
00322                 // for lab work (but is not the choice
00323                 // for publication):
00324                 // 
00325                 DrawingMetrics::_noIconLabels=false;
00326                 
00327                 //
00328                 // By default labels are truncated to fit
00329                 // within column widths:
00330                 //
00331                 DrawingMetrics::_noLabelTruncation=false;
00332                 
00333                 //
00334                 // This is the default scaling factor used for SVG drawing output to a screen.
00335                 // Assuming a default screen has 96 dots (pixels) per inch, we then have:
00336                 // 
00337                 //  96 dots    1 inch     1 cm
00338                 //  ------- x -------- x ------- = 3.7795 dots per millimeter
00339                 //  1 inch     2.54 cm    10 mm
00340                 //  
00341                 // Although DrawingMetrics makes it look like you could use
00342                 // any units you want, in reality the measurement system is based on SI
00343                 // millimeters
00344                 // 
00345                 DrawingMetrics::_scalingFactor = 3.78;
00346                 //
00347                 // Since LASi was designed for Postscript, LASi returns font metrics
00348                 // in points, defined as 1/72nd of an inch. As Madeline uses SI units,
00349                 // specifically millimeters, we have this conversion factor:
00350                 //
00351                 //    1                     2.54 cm      10 mm
00352                 //  ---- inch / 1 point x ----------- x ------- = 0.35278 mm per point
00353                 //   72                     1 inch        1 cm
00354                 DrawingMetrics::_pointsToMmConversionFactor = 0.3527777778;
00355                 
00356                 //
00357                 // ISO standard paper media sizes
00358                 // ==============================
00359                 // 
00360                 // Markus Kuhn provides a nice overview of the ISO
00361                 // paper sizes at
00362                 // http://www.cl.cam.ac.uk/~mgk25/iso-paper.html 
00363                 // 
00364                 // Note that because the ratio of the sides is 1:sqrt(2),
00365                 // cutting one size in half parallel to the shorter side yields
00366                 // two pages of the next smaller ISO size.  This is not the
00367                 // case with the American and Canadian size standards:
00368                 // 
00369                 DrawingMetrics::media.insert(DrawingMedia("4A0",1682,2378));
00370                 DrawingMetrics::media.insert(DrawingMedia("2A0",1189,1682));
00371                 DrawingMetrics::media.insert(DrawingMedia("A0",841,1189));
00372                 DrawingMetrics::media.insert(DrawingMedia("A2",420,594));
00373                 DrawingMetrics::media.insert(DrawingMedia("A3",297,420));
00374                 DrawingMetrics::media.insert(DrawingMedia("A4",210,297));
00375                 DrawingMetrics::media.insert(DrawingMedia("A5",148,210));
00376                 DrawingMetrics::media.insert(DrawingMedia("A6",105,148));
00377                 DrawingMetrics::media.insert(DrawingMedia("A7",74,105));
00378                 DrawingMetrics::media.insert(DrawingMedia("A8",52,74));
00379                 DrawingMetrics::media.insert(DrawingMedia("A9",37,52));
00380                 DrawingMetrics::media.insert(DrawingMedia("A10",26,37));
00381                 DrawingMetrics::media.insert(DrawingMedia("B0",1000,1414));
00382                 DrawingMetrics::media.insert(DrawingMedia("B1",707,1000));
00383                 DrawingMetrics::media.insert(DrawingMedia("B2",500,707));
00384                 DrawingMetrics::media.insert(DrawingMedia("B3",353,500));
00385                 DrawingMetrics::media.insert(DrawingMedia("B4",250,353));
00386                 DrawingMetrics::media.insert(DrawingMedia("B5",176,250));
00387                 DrawingMetrics::media.insert(DrawingMedia("B6",125,176));
00388                 DrawingMetrics::media.insert(DrawingMedia("B7",88,125));
00389                 DrawingMetrics::media.insert(DrawingMedia("B8",62,88));
00390                 DrawingMetrics::media.insert(DrawingMedia("B9",44,62));
00391                 DrawingMetrics::media.insert(DrawingMedia("B10",31,44));
00392                 DrawingMetrics::media.insert(DrawingMedia("C0",917,1297));
00393                 DrawingMetrics::media.insert(DrawingMedia("C1",648,917));
00394                 DrawingMetrics::media.insert(DrawingMedia("C2",458,648));
00395                 DrawingMetrics::media.insert(DrawingMedia("C3",324,458));
00396                 DrawingMetrics::media.insert(DrawingMedia("C4",229,324));
00397                 DrawingMetrics::media.insert(DrawingMedia("C5",162,229));
00398                 DrawingMetrics::media.insert(DrawingMedia("C6",114,162));
00399                 DrawingMetrics::media.insert(DrawingMedia("C7",81,114));
00400                 DrawingMetrics::media.insert(DrawingMedia("C8",57,81));
00401                 DrawingMetrics::media.insert(DrawingMedia("C9",40,57));
00402                 DrawingMetrics::media.insert(DrawingMedia("C10",28,40));
00403                 //
00404                 // North American standard paper media sizes
00405                 // =========================================
00406                 // 
00407                 DrawingMetrics::media.insert(DrawingMedia("letter",216,279));
00408                 DrawingMetrics::media.insert(DrawingMedia("legal",216,356));
00409                 DrawingMetrics::media.insert(DrawingMedia("executive",190,254));
00410                 DrawingMetrics::media.insert(DrawingMedia("ledger",279,432));
00411                 //
00412                 // Computer screen resolutions for screen-based SVG output
00413                 // =======================================================
00414                 // 
00415                 DrawingMetrics::media.insert(DrawingMedia("VGA",640,480,"px"));
00416                 DrawingMetrics::media.insert(DrawingMedia("SVGA",800,600,"px"));
00417                 DrawingMetrics::media.insert(DrawingMedia("XGA",1024,768,"px"));
00418                 DrawingMetrics::media.insert(DrawingMedia("SXGA",1280,1024,"px"));
00419                 DrawingMetrics::media.insert(DrawingMedia("UXGA",1600,1200,"px"));
00420                 DrawingMetrics::media.insert(DrawingMedia("WXGA",1366,768,"px"));
00421                 DrawingMetrics::media.insert(DrawingMedia("WSXGA",1680,1050,"px"));
00422                 DrawingMetrics::media.insert(DrawingMedia("WUXGA",1920,1200,"px"));
00423                 //DrawingMetrics::media.insert(DrawingMedia("",,));
00424                 
00425                 //
00426                 // Monochromat and bichromatic color series default colors
00427                 // =======================================================
00428                 //
00429                 // => For monochromatic series, just the "monochromat" colors are
00430                 //    used to create ColorSeries.
00431                 //
00432                 // => For bichromatic series, both the "monochromat" and the 
00433                 //    "bichromat" at a given matching index are used.
00434                 //    
00435                 // => The very first color series is used as the default when there is
00436                 //    only one pie section.  Therefore, we force it to be plain black
00437                 //    & white.
00438                 //    
00439                 // => The 2nd, 3rd, 4th, etc. color series are to be used when
00440                 //    there is more than one pie section:
00441                 //    
00442                 //DrawingMetrics::monochromat.push_back(DrawingColor("black","#000")); // DEFAULT
00443                 //DrawingMetrics::bichromat.push_back(  DrawingColor("white","#fff")); // DEFAULT
00444                 
00445                 DrawingMetrics::monochromat.push_back(DrawingColor("navy","#0000a0"));
00446                 DrawingMetrics::bichromat.push_back(  DrawingColor("maize","#ffd803"));
00447                 DrawingMetrics::monochromat.push_back(DrawingColor("red","#800"));
00448                 DrawingMetrics::bichromat.push_back(  DrawingColor("banana","#ffffa2"));
00449                 DrawingMetrics::monochromat.push_back(DrawingColor("forest","#003f00"));
00450                 DrawingMetrics::bichromat.push_back(  DrawingColor("peach","#ffcca2"));
00451                 DrawingMetrics::monochromat.push_back(DrawingColor("ceramicBlue","#768dff"));
00452                 DrawingMetrics::bichromat.push_back(  DrawingColor("lavender","#fcf"));
00453         }
00454 };
00455 
00456 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4