| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TePieBar.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00026 #ifndef TEPIEBAR_H
    00027 #define TEPIEBAR_H
    00028
    00029 #include "TeDefines.h"
    00030
    00032 class TL_DLL TePieBar
    00033 {
    00034 public:
    00035            enum                             TePieBarInput {ALL, TABSEL, QUERYSEL, LEGEND, NOTTABSEL, NOTQUERYSEL, NOTLEGEND};
    00036            string                           type_; // PIECHART or BARCHART
    00037            int                                         themeId_;
    00038            double                           maxDiameter_;
    00039            double                           minDiameter_;
    00040            double                           diameter_;
    00041            string                           dimensionAttr_;
    00042            vector<string>        attrVector_;
    00043            vector<TeColor> colorVector_;
    00044            double                           maxHeight_;
    00045            double                           minHeight_;
    00046            double                           width_;
    00047            double                           maxValue_;
    00048            double                           minValue_;
    00049            bool                             keepDimension_;
    00050            int                                         inputType_;
    00051            TeDatabase            *db_;
    00052            string                           keyMove_;
    00053
    00054            TePieBar() {}
    00055
    00056            TePieBar(int themeId, TeDatabase* db)
    00057            {
    00058                       themeId_ = themeId;
    00059                       db_ = db;
    00060            }
    00061
    00062            TePieBar (const TePieBar& pb )
    00063            {
    00064                       type_ = pb.type_;
    00065                       themeId_ = pb.themeId_;
    00066                       maxDiameter_ = pb.maxDiameter_;
    00067                       minDiameter_ = pb.minDiameter_;
    00068                       diameter_ = pb.diameter_;
    00069                       dimensionAttr_ = pb.dimensionAttr_;
    00070                       maxHeight_ = pb.maxHeight_;
    00071                       minHeight_ = pb.minHeight_;
    00072                       width_ = pb.width_;
    00073                       maxValue_ = pb.maxValue_;
    00074                       minValue_ = pb.minValue_;
    00075                       keepDimension_ = pb.keepDimension_;
    00076                       inputType_ = pb.inputType_;
    00077                       db_ = pb.db_;
    00078                       keyMove_ = pb.keyMove_;
    00079
    00080                       attrVector_.clear();
    00081                       colorVector_.clear();
    00082                       int size = pb.attrVector_.size();
    00083                       int i = 0;
    00084                       while(i < size)
    00085                       {          attrVector_.push_back(pb.attrVector_[i]);
    00086                                  colorVector_.push_back(pb.colorVector_[i]);
    00087                                  i++;
    00088                       }
    00089            }
    00090
    00091            TePieBar& operator=(const TePieBar& pb)
    00092            {
    00093                       type_ = pb.type_;
    00094                       themeId_ = pb.themeId_;
    00095                       maxDiameter_ = pb.maxDiameter_;
    00096                       minDiameter_ = pb.minDiameter_;
    00097                       diameter_ = pb.diameter_;
    00098                       dimensionAttr_ = pb.dimensionAttr_;
    00099                       maxHeight_ = pb.maxHeight_;
    00100                       minHeight_ = pb.minHeight_;
    00101                       width_ = pb.width_;
    00102                       maxValue_ = pb.maxValue_;
    00103                       minValue_ = pb.minValue_;
    00104                       keepDimension_ = pb.keepDimension_;
    00105                       inputType_ = pb.inputType_;
    00106                       db_ = pb.db_;
    00107                       keyMove_ = pb.keyMove_;
    00108
    00109                       attrVector_.clear();
    00110                       colorVector_.clear();
    00111                       int size = pb.attrVector_.size();
    00112                       int i = 0;
    00113                       while(i < size)
    00114                       {          attrVector_.push_back(pb.attrVector_[i]);
    00115                                  colorVector_.push_back(pb.colorVector_[i]);
    00116                                  i++;
    00117                       }
    00118                       return *this;
    00119            }
    00120
    00121            ~TePieBar() {}
    00122
    00123            void init(int themeId, TeDatabase* db)
    00124            {
    00125                       themeId_ = themeId;
    00126                       db_ = db;
    00127            }
    00128
    00129            bool locate(TeCoord2D pt, double delta)
    00130            {
    00131                       keyMove_.clear();
    00132                       string     TS = "AuxTheme" + Te2String(themeId_);
    00133                       string xmin = Te2String(pt.x()-delta);
    00134                       string xmax = Te2String(pt.x()+delta);
    00135                       string ymin = Te2String(pt.y()-delta);
    00136                       string ymax = Te2String(pt.y()+delta);
    00137
    00138                       TeDatabasePortal* portal = db_->getPortal();
    00139                       string sel = "SELECT SELKEY FROM " + TS + " WHERE ";
    00140                       sel += "PIEBARX > " + xmin + " AND ";
    00141                       sel += "PIEBARX < " + xmax + " AND ";
    00142                       sel += "PIEBARY > " + ymin + " AND ";
    00143                       sel += "PIEBARY < " + ymax;
    00144                       if(portal->query(sel) == false)
    00145                       {
    00146                                  delete portal;
    00147                                  return false;
    00148                       }
    00149
    00150                       bool b = portal->fetchRow(0);
    00151                       if(b == true)
    00152                                  keyMove_ = portal->getData(0);
    00153                       delete portal;
    00154
    00155                       if(keyMove_.empty() == false)
    00156                                  return true;
    00157                       return false;
    00158            }
    00159
    00160            void move(TeCoord2D pt)
    00161            {
    00162                       if(keyMove_.empty() == true)
    00163                                  return;
    00164
    00165                       string     x = Te2String(pt.x());
    00166                       string     y = Te2String(pt.y());
    00167                       string     TS = "AuxTheme" + Te2String(themeId_);
    00168                       string mover = "UPDATE " + TS + " SET PIEBARX = " + x + ", PIEBARY = " + y;
    00169                       mover += " WHERE SELKEY = '" + keyMove_ + "'";
    00170                       db_->execute(mover);
    00171            }
    00172
    00173            bool load()
    00174            {
    00175                       TeDatabasePortal* portal = db_->getPortal();
    00176                       string sel = "SELECT * FROM piebars WHERE themeId = " + Te2String(themeId_);
    00177                       if(portal->query(sel))
    00178                       {
    00179                                  bool b = portal->fetchRow(0);
    00180                                  if(b == false)
    00181                                  {
    00182                                             delete portal;
    00183                                             return false;
    00184                                  }
    00185                                  type_ = portal->getData("type");
    00186                                  maxDiameter_ = portal->getDouble("maxDiameter");
    00187                                  minDiameter_ = portal->getDouble("minDiameter");
    00188                                  diameter_ = portal->getDouble("diameter"));
    00189                                  string     attr = portal->getData("dimensionAttr");
    00190                                  dimensionAttr_ = attr;
    00191                                  maxHeight_ = portal->getDouble("maxHeight");
    00192                                  minHeight_ = portal->getDouble("minHeight");
    00193                                  width_ = portal->getDouble("width"));
    00194                                  maxValue_ = portal->getDouble("maxValue");
    00195                                  minValue_ = atof(portal->getData("minValue");
    00196                                  keepDimension_ = portal->getDouble("keepDimension");
    00197                                  inputType_ = portal->getDouble("inputType");
    00198                                  int i;
    00199                                  for(i=0; i<10; i++)
    00200                                  {
    00201                                             string attr = "attr" + Te2String(i+1);
    00202                                             string vattr = portal->getData(attr);
    00203                                             if(vattr.empty() == true)
    00204                                                        break;
    00205                                             attrVector_.push_back(vattr);
    00206
    00207                                             string red = "red" + Te2String(i+1);
    00208                                             string green = "green" + Te2String(i+1);
    00209                                             string blue = "blue" + Te2String(i+1);
    00210                                             TeColor cor;
    00211                                             cor.red_ = atoi(portal->getData(red));
    00212                                             cor.green_ = atoi(portal->getData(green));
    00213                                             cor.blue_ = atoi(portal->getData(blue));
    00214                                             colorVector_.push_back(cor);
    00215                                  }
    00216                                  delete portal;
    00217                                  return true;
    00218                       }
    00219                       delete portal;
    00220                       return false;
    00221            }
    00222
    00223            void save()
    00224            {
    00225                       int        i;
    00226                       TeDatabasePortal* portal = db_->getPortal();
    00227                       bool b = portal->query("SELECT * FROM piebars");
    00228                       delete portal;
    00229                       if(b == false)
    00230                       {
    00231                                  string criar = "CREATE TABLE piebars (themeId INTEGER,";
    00232                                  criar += "type VARCHAR(16) DEFAULT NULL,";
    00233                                  criar += "maxDiameter DOUBLE DEFAULT NULL,";
    00234                                  criar += "minDiameter DOUBLE DEFAULT NULL,";
    00235                                  criar += "diameter DOUBLE DEFAULT NULL,";
    00236                                  criar += "dimensionAttr  VARCHAR(64) DEFAULT NULL,";
    00237                                  criar += "maxHeight DOUBLE DEFAULT NULL,";
    00238                                  criar += "minHeight DOUBLE DEFAULT NULL,";
    00239                                  criar += "width DOUBLE DEFAULT NULL,";
    00240                                  criar += "maxValue DOUBLE DEFAULT NULL,";
    00241                                  criar += "minValue DOUBLE DEFAULT NULL,";
    00242                                  criar += "keepDimension INTEGER DEFAULT 0,";
    00243                                  criar += "inputType INTEGER DEFAULT 0,";
    00244                                  for (i=0; i<10; i++)
    00245                                  {
    00246                                             criar += "attr" + Te2String(i+1) + " VARCHAR(64) DEFAULT NULL,";
    00247                                             criar += "red" + Te2String(i+1) + " INTEGER DEFAULT NULL,";
    00248                                             criar += "green" + Te2String(i+1) + " INTEGER DEFAULT NULL,";
    00249                                             criar += "blue" + Te2String(i+1) + " INTEGER DEFAULT NULL,";
    00250                                  }
    00251                                  criar.erase(criar.size()-1, 1);
    00252                                  criar += ")";
    00253                                  db_->execute(criar);
    00254                       }
    00255
    00256                       string del = "DELETE FROM piebars WHERE themeId = " + Te2String(themeId_);
    00257                       db_->execute(del);
    00258
    00259                       if(attrVector_.size() == 0)
    00260                                  return;
    00261                       string up = "INSERT INTO piebars (themeId, type, maxDiameter, ";
    00262                       up += "minDiameter, diameter, dimensionAttr, maxHeight, minHeight, ";
    00263                       up += "width, maxValue, minValue, keepDimension, inputType, ";
    00264                       for (i=0; i<attrVector_.size() && i<10; i++)
    00265                       {
    00266                                  up += "attr" + Te2String(i+1) + ", ";
    00267                                  up += "red" + Te2String(i+1) + ", ";
    00268                                  up += "green" + Te2String(i+1) + ", ";
    00269                                  up += "blue" + Te2String(i+1) + ", ";
    00270                       }
    00271                       up.erase(up.size()-2, 2);
    00272                       up += ")";
    00273
    00274                       up += " VALUES (" + Te2String(themeId_) + ", ";
    00275                       up += "'" + type_ + "', ";
    00276                       up += Te2String(maxDiameter_) + ", ";
    00277                       up += Te2String(minDiameter_) + ", ";
    00278                       up += Te2String(diameter_) + ", ";
    00279                       up += "'" + dimensionAttr_ + "', ";
    00280                       up += Te2String(maxHeight_) + ", ";
    00281                       up += Te2String(minHeight_) + ", ";
    00282                       up += Te2String(width_) + ", ";
    00283                       up += Te2String(maxValue_) + ", ";
    00284                       up += Te2String(minValue_) + ", ";
    00285                       up += Te2String(keepDimension_) + ", ";
    00286                       up += Te2String(inputType_) + ", ";
    00287                       for (i=0; i<attrVector_.size() && i<10; i++)
    00288                       {
    00289                                  up += "'" + attrVector_[i] + "', ";
    00290                                  up += Te2String(colorVector_[i].red_) + ", ";
    00291                                  up += Te2String(colorVector_[i].green_) + ", ";
    00292                                  up += Te2String(colorVector_[i].blue_) + ", ";
    00293                       }
    00294                       up.erase(up.size()-2, 2);
    00295                       up += ")";
    00296                       db_->execute(up);
    00297            }
    00298
    00299            void remove()
    00300            {
    00301                       TeDatabasePortal* portal = db_->getPortal();
    00302                       bool b = portal->query("SELECT * FROM piebars");
    00303                       delete portal;
    00304                       if(b == false)
    00305                                  return;
    00306
    00307                       string del = "DELETE FROM piebars WHERE themeId = " + Te2String(themeId_);
    00308                       db_->execute(del);
    00309            }
    00310 };
    00311
    00312 #endif
    00313
    00314
    00315
    00316
    00317

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines