Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

xygrapl.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /* Módulo: xygrppl.cpp                                                       */
00003 /* Autores: Camilo da Fonseca Freire                                         */
00004 /* Data: 11 jul 96                                                           */
00005 /* Comentário:                                                               */
00006 /*    Implementação de métodos da classe especializada, responsável pelo de- */
00007 /* senho de gráficos do tipo polar que tem como principal característica um  */
00008 /* eixo polar (XYPolarAxis).                                                 */
00009 /*****************************************************************************/
00010 
00011 #include <stdlib.h>
00012 #include <stdarg.h>
00013  
00014 #include "xygrapl.h"
00015 
00016 const char* xy_id_xypolar_cpp="$Id: xygrapl.cpp,v 1.17 1999/12/09 21:47:46 rborges Exp $";
00017                                                                 
00018 #ifndef NOIUP
00019 XYPolar::XYPolar (Ihandle* canvas,
00020                   XYCoordinate x,
00021                   XYCoordinate y,
00022                   double width,
00023                   double height,
00024                       XYRadialGrid* gridr,
00025                       XYAngGrid* grida,
00026                       xybool visible)
00027                       : XYGraph(canvas, x, y, width, height, visible),
00028                             _gridr(gridr),
00029                           _grida(grida)
00030 {
00031    distortion(xyfalse);
00032 }
00033 #endif
00034 
00035 XYPolar::XYPolar (cdCanvas* cdcanvas,
00036                   XYCoordinate x,
00037                   XYCoordinate y,
00038                   double width,
00039                   double height,
00040                       XYRadialGrid* gridr,
00041                       XYAngGrid* grida,
00042                       xybool visible)
00043                       : XYGraph(cdcanvas, x, y, width, height, visible),
00044                             _gridr(gridr),
00045                           _grida(grida)
00046 {
00047    distortion(xyfalse);
00048 }
00049 
00050 XYPolar::~XYPolar (void)
00051 {
00052    // liberar listas de textos, eixos e máscaras alocadas
00053 }
00054 
00055 void XYPolar::setGridR (XYRadialGrid *gridr)
00056 {
00057    _gridr = gridr;
00058 }
00059 
00060 XYRadialGrid* XYPolar::getGridR (void) const
00061 {
00062    return _gridr;
00063 }
00064 
00065 void XYPolar::setGridA (XYAngGrid *grida)
00066 {
00067    _grida = grida;
00068 }
00069 
00070 XYAngGrid* XYPolar::getGridA (void) const
00071 {
00072    return _grida;
00073 }
00074 
00075 XYObject* XYPolar::pick (int px, int py)
00076 {
00077    XYObject* obj;
00078 
00079    // verifica objetos gráficos
00080    obj = XYGraph::pick(px, py);
00081 
00082    if (obj != NULL) return obj;
00083 
00084    // testa grade angular
00085    if (_grida -> pick(px, py))  
00086           return _grida;
00087 
00088    // testa grade radial
00089    if (_gridr -> pick(px, py))  
00090       return _gridr;
00091 
00092    return NULL;
00093 }
00094 
00095 XYList<XYObject>* XYPolar::fence (int x0, int y0, int x1, int y1)
00096 {
00097    XYList<XYObject>* obj;
00098 
00099    obj = XYGraph::fence(x0, y0, x1, y1);
00100 
00101    // testa grade angular
00102    if (_grida -> fence(x0, y0, x1, y1)) 
00103        obj -> insert(_grida);
00104 
00105    // testa grade radial
00106    if (_gridr -> fence(x0, y0,  x1, y1))        
00107       obj -> insert(_gridr);
00108 
00109    return obj;
00110 }
00111 
00112 void XYPolar::calcMaskArea (void)
00113 {
00114    activateCanvas ();
00115 
00116    XYListIterator<XYAxis> in(&_axes);
00117 
00118    // inicializa coordenadas mínimas com valores máximos possíveis, coordenadas
00119    // máximas com valores mínimos possíveis
00120    _ma_xmin = 1.0;
00121    _ma_xmax = 0.0;
00122    _ma_ymin = 1.0;
00123    _ma_ymax = 0.0;
00124 
00125    XYAxis* cont;
00126    double x, y;
00127    double size;
00128 
00129    while (!in.End())
00130    {
00131       cont = in.Next();
00132 
00133       // consulta posição e tamanho do eixo
00134       cont -> position(&x, &y);
00135       size = cont -> size();
00136 
00137       // cálculo da área útil
00138       _ma_xmin = x - size;
00139       _ma_xmax = x + size;
00140       _ma_ymin = y - size;
00141       _ma_ymax = y + size;
00142    }
00143 }
00144 
00145 void XYPolar::draw(void)
00146 {
00147    if (visible() == xyfalse)    // invisível!!!
00148       return;
00149 
00150    activateCanvas();
00151    defineViewport();
00152 
00153    int x1, y1, x2, y2;
00154    getViewport (x1, x2, y1, y2);
00155 
00156    draw(x1, y1, x2, y2);
00157 }
00158 
00159 void XYPolar::draw(int xmin, int ymin, int xmax, int ymax) const
00160 {
00161    if (visible() == xyfalse)    // invisível!!!
00162       return;
00163 
00164    activateCanvas();
00165    propagateViewport();
00166 
00167    XYGraph::maskAreaClear();
00168 
00169    int mode = cdClip(CD_CLIPON);
00170 
00171    // guarda a região de clip corrente
00172    int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00173    cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00174    // define nova região de clip
00175    cdClipArea(xmin, xmax, ymin, ymax);
00176 
00177    if (_grida)  // desenha grade angular
00178    {
00179       _grida -> size ((_ma_xmax - _ma_xmin) / 2.);
00180       _grida -> draw (xmin, ymin, xmax, ymax);
00181    }
00182 
00183    if (_gridr)  // desenha grade radial
00184    {
00185       _gridr -> size ((_ma_xmax - _ma_xmin) / 2.);
00186       _gridr -> draw (xmin, ymin, xmax, ymax);
00187    }
00188 
00189    XYGraph::draw(xmin, ymin, xmax, ymax);
00190 
00191    cdClip(mode);
00192    // restaura a região de clip anterior
00193    cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00194 
00195    XYGraph::flush();
00196 }
00197 
00198 void XYPolar::propagateViewport (void) const
00199 {
00200    // define as áreas de desenho para todos os textos, eixos, máscaras,
00201    // marcadores, "slices" e legenda que existirem
00202    XYGraph::propagateViewport();
00203 
00204    int x1, x2, y1, y2;
00205    getViewport(x1, x2, y1, y2);
00206 
00207    if (_grida)  // define área gráfica para a grade angular
00208       _grida -> setViewport(x1, x2, y1, y2);
00209 
00210    if (_gridr)  // define área gráfica para a grade radial
00211       _gridr -> setViewport(x1, x2, y1, y2);
00212 }
00213 
00214 void XYPolar::drawMaskArea (void) const
00215 {
00216    int x1, y1, x2, y2;
00217    getMaskArea (x1, y1, x2, y2);
00218 
00219    drawMaskArea (x1, y1, x2, y2);
00220 }
00221 
00222 void XYPolar::drawMaskArea (int xmin, int ymin, int xmax, int ymax) const
00223 {
00224    int mode = cdClip(CD_CLIPON);
00225 
00226    // guarda a região de clip corrente
00227    int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00228    cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00229    // define nova região de clip
00230    cdClipArea(xmin, xmax, ymin, ymax);
00231 
00232    if (_grida)  // desenha grade angular
00233       _grida -> draw (xmin, ymin, xmax, ymax);
00234 
00235    if (_gridr)  // desenha grade radial
00236       _gridr -> draw (xmin, ymin, xmax, ymax);
00237 
00238    XYGraph::drawMaskArea(xmin, ymin, xmax, ymax);
00239 
00240    cdClip(mode);
00241    // restaura a região de clip anterior
00242    cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00243 }
00244 

XY
Tecgraf / PUC-Rio - Computer Graphics Technology Group