| 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/drivers/qt/TePlotTheme.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  __TERRALIB_INTERNAL_PLOTTHEME_H
    00027 #define  __TERRALIB_INTERNAL_PLOTTHEME_H
    00028
    00029 #include "TeAppTheme.h"
    00030 #include "TeExternalTheme.h"
    00031 #include "TeDatabase.h"
    00032 #include "TeGeometryAlgorithms.h"
    00033 #include "TeVectorRemap.h"
    00034 #include "TeDecoderMemory.h"
    00035 #include <time.h>
    00036 #include <set>
    00037 #include "TeApplicationUtils.h"
    00038 #include <TeDatabaseUtils.h>
    00039
    00040 #include <TeThemeFunctions.h>
    00041 #include <PluginsSignal.h>
    00042
    00043 template<class Canvas, class Progress>
    00044 void TePlotTextWV(TeAppTheme* appTheme, Canvas* canvas, Progress * progress, TeBox box = TeBox())
    00045 {
    00046            TeAbstractTheme* theme = appTheme->getTheme();
    00047
    00048            if(theme->minScale() != 0 && theme->maxScale() != 0 && theme->minScale() > theme->maxScale())
    00049            {
    00050                       if(theme->minScale() < canvas->scaleApx() || theme->maxScale() > canvas->scaleApx())
    00051                                  return;
    00052            }
    00053            if ((theme->visibleRep() & TeTEXT) == 0)
    00054                       return;
    00055
    00056            if(appTheme->textTable().empty())
    00057                       return;
    00058
    00059            TeDatabase* db = appTheme->getLocalDatabase();
    00060
    00061            if(!db || !db->tableExist(appTheme->textTable()))
    00062                       return;
    00063            canvas->setDataProjection(theme->getThemeProjection());
    00064            TeDatabasePortal* plot = db->getPortal();
    00065
    00066            string     tabtx = appTheme->textTable();
    00067            string     tabs = appTheme->getLocalCollectionTable();
    00068
    00069            string wherebox;
    00070            if(box.isValid())
    00071            {
    00072                       wherebox = "NOT (x >= " + Te2String(box.x2()+4*box.width());
    00073                       wherebox += " OR y >= " + Te2String(box.y2()+2*box.height());
    00074                       wherebox += " OR x <= " + Te2String(box.x1()-4*box.width());
    00075                       wherebox += " OR y <= " + Te2String(box.y1()-2*box.height()) + ")";
    00076            }
    00077            else
    00078            {
    00079                       wherebox = getWhereBox(plot, appTheme, canvas, TeTEXT, box);
    00080                       if(wherebox.empty())
    00081                       {
    00082                                  TeBox box = canvas->getDataWorld();
    00083                                  wherebox = " x >= " + Te2String(box.x1());
    00084                                  wherebox += " AND x <= " + Te2String(box.x2());
    00085                                  wherebox += " AND y >= " + Te2String(box.y1());
    00086                                  wherebox += " AND y <= " + Te2String(box.y2());
    00087                       }
    00088            }
    00089
    00090            // calculate initial filed number for collection and legenda (sind and vind)
    00091            int sind=0, vind=0;
    00092            string ind = "SELECT * FROM " + tabtx + " WHERE object_id < ' '";
    00093            plot->freeResult();
    00094            if (plot->query (ind))
    00095                       sind = plot->getAttributeList().size();
    00096
    00097            ind = "SELECT * FROM " + tabs + " WHERE c_object_id < ' '";
    00098            plot->freeResult();
    00099            if (plot->query (ind))
    00100                       vind = plot->getAttributeList().size() + sind;
    00101
    00102            int numrows = 0;
    00103            string conta = "SELECT COUNT(*) FROM " + tabs;
    00104            plot->freeResult();
    00105            if (plot->query (conta))
    00106            {
    00107                       if(plot->fetchRow())
    00108                                  numrows = atoi(plot->getData(0));
    00109            }
    00110            delete plot;
    00111
    00112            string tabv = tabtx + "_txvisual";
    00113            string sa = "SELECT " + tabtx + ".*, " + tabv + ".*, " + tabs + ".* ";
    00114            sa += "FROM " + tabtx + ", " + tabv + ", " + tabs;
    00115            sa += " WHERE (" + tabs + ".c_object_id = " + tabtx + ".object_id";
    00116            sa += " AND " + tabtx + ".geom_id = " + tabv + ".geom_id)";
    00117            string squery;
    00118            squery = sa + " AND (" + wherebox + ")";
    00119            plotTextWV(appTheme, canvas, squery, progress);
    00120
    00121            string othersQuery = "SELECT " + tabtx + ".*, " + tabv + ".* ";
    00122            othersQuery += "FROM " + tabtx + ", " + tabv;
    00123            othersQuery += " WHERE " + tabtx + ".geom_id = " + tabv + ".geom_id";
    00124            othersQuery += " AND " + tabtx + ".object_id = 'TE_NONE_ID'";
    00125            plotTextWV(appTheme, canvas, othersQuery, progress);
    00126 }
    00127
    00128 template<class Canvas, class Progress>
    00129 void plotTextWV(TeAppTheme *appTheme, Canvas *canvas, string query, Progress *progress)
    00130 {
    00131            TeText     text;
    00132            int        np = 0;
    00133            int dt = CLOCKS_PER_SEC/4;
    00134            int dt2 = CLOCKS_PER_SEC * 5;
    00135            clock_t    t0, t1, t2;
    00136
    00137            TeAbstractTheme* theme = appTheme->getTheme();
    00138            TeDatabase* db = appTheme->getLocalDatabase();
    00139            if(!db)
    00140                       return;
    00141
    00142            TeDatabasePortal* plot = db->getPortal();
    00143
    00144            if(progress == 0)
    00145            {
    00146                       if(plot->query(query) && plot->fetchRow())
    00147                       {
    00148                                  t1 = clock();
    00149                                  t2 = t1;
    00150                                  bool flag = true;
    00151                                  do
    00152                                  {
    00153                                             bool bold = false, italic = false;
    00154                                             int        size;
    00155                                             int dot_height = atoi(plot->getData(10));
    00156                                             bool fixedSize = atoi(plot->getData(11));
    00157                                             int rgb = atoi(plot->getData(12));
    00158                                             TeColor    cor((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
    00159                                             string     family = plot->getData(13);
    00160                                             if(atoi(plot->getData(14)))
    00161                                                        bold = true;
    00162                                             if(atoi(plot->getData(15)))
    00163                                                        italic = true;
    00164
    00165                                             flag = plot->fetchGeometry(text);
    00166                                             if(fixedSize == false && text.height() > 0.)
    00167                                             {
    00168                                                        TeBox wbox = canvas->getDataWorld();
    00169                                                        TeCoord2D p1(wbox.x1_, wbox.y1_);
    00170                                                        TeCoord2D p2(p1.x() + text.height(), p1.y() + text.height());
    00171                                                        TeBox box(p1, p2);
    00172                                                        canvas->mapDWtoV(box);
    00173                                                        size = int(box.height());
    00174                                             }
    00175                                             else
    00176                                                        size = dot_height;
    00177
    00178                                             canvas->setTextColor(cor.red_, cor.green_, cor.blue_);
    00179                                             canvas->setTextStyle (family, size, bold, italic );
    00180                                             TeVisual visual;
    00181                                             visual.size(size);
    00182                                             visual.family(family);
    00183                                             visual.bold(bold);
    00184                                             visual.italic(italic);
    00185                                             visual.fixedSize(fixedSize);
    00186                                             visual.ptAngle((int)text.angle());
    00187
    00188                                             canvas->plotText (text, visual);
    00189                                             np++;
    00190                                             t2 = clock();
    00191                                             if (int(t2-t1) > dt)
    00192                                             {
    00193                                                        t1 = t2;
    00194                                                        canvas->copyPixmapToWindow();
    00195                                             }
    00196                                  } while (flag);
    00197                                  canvas->copyPixmapToWindow();
    00198                       }
    00199            }
    00200            else
    00201            {
    00202                       int steps = 0;
    00203                       string conta = query;
    00204                       int ff;
    00205                       if((ff=conta.find(" FROM ")) >= 0)
    00206                                  conta.replace(0, ff, "SELECT COUNT(*)");
    00207                       if((ff=conta.find("ORDER BY")) >= 0)
    00208                                  conta = conta.substr(0, ff);
    00209                       plot->freeResult();
    00210                       if(plot->query(conta) && plot->fetchRow())
    00211                                  steps = atoi(plot->getData(0));
    00212
    00213                       plot->freeResult();
    00214                       if(plot->query(query) && plot->fetchRow())
    00215                       {
    00216                                  string caption = "Plotando tema: " + theme->name();
    00217                                  progress->setCaption(caption.c_str());
    00218                                  progress->setLabelText("      Plotagem de textos em andamento, aguarde...      ");
    00219                                  progress->setTotalSteps(steps);
    00220                                  t2 = clock();
    00221                                  t0 = t1 = t2;
    00222                                  bool flag = true;
    00223                                  do
    00224                                  {
    00225                                             bool bold = false, italic = false;
    00226                                             int        size;
    00227                                             int dot_height = atoi(plot->getData(10));
    00228                                             bool fixedSize = atoi(plot->getData(11));
    00229                                             int rgb = atoi(plot->getData(12));
    00230                                             TeColor    cor((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
    00231                                             string     family = plot->getData(13);
    00232                                             if(atoi(plot->getData(14)))
    00233                                                        bold = true;
    00234                                             if(atoi(plot->getData(15)))
    00235                                                        italic = true;
    00236
    00237                                             flag = plot->fetchGeometry(text);
    00238                                             if(fixedSize == false && text.height() > 0.)
    00239                                             {
    00240                                                        TeBox wbox = canvas->getDataWorld();
    00241                                                        TeCoord2D p1(wbox.x1_, wbox.y1_);
    00242                                                        TeCoord2D p2(p1.x() + text.height(), p1.y() + text.height());
    00243                                                        TeBox box(p1, p2);
    00244                                                        canvas->mapDWtoV(box);
    00245                                                        size = int(box.height());
    00246                                                        size = (int)((double)size / canvas->printerFactor() +.5);
    00247                                             }
    00248                                             else
    00249                                                        size = dot_height;
    00250
    00251                                             canvas->setTextColor(cor.red_, cor.green_, cor.blue_);
    00252                                             canvas->setTextStyle (family, size, bold, italic );
    00253                                             TeVisual visual;
    00254                                             visual.size(size);
    00255                                             visual.family(family);
    00256                                             visual.bold(bold);
    00257                                             visual.italic(italic);
    00258                                             visual.fixedSize(fixedSize);
    00259                                             visual.ptAngle((int)text.angle());
    00260
    00261                                             canvas->plotText (text, visual);
    00262                                             np++;
    00263                                             t2 = clock();
    00264                                             if (int(t2-t1) > dt)
    00265                                             {
    00266                                                        t1 = t2;
    00267                                                        canvas->copyPixmapToWindow();
    00268                                                        if(progress->wasCancelled())
    00269                                                        {
    00270                                                                   progress->reset();
    00271                                                                   break;
    00272                                                        }
    00273                                                        if((int)(t2-t0) > dt2)
    00274                                                                   progress->setProgress(np);
    00275                                             }
    00276                                  } while (flag);
    00277                                  canvas->copyPixmapToWindow();
    00278                       }
    00279                       progress->reset();
    00280            }
    00281            delete plot;
    00282 }
    00283
    00284 template<class Canvas, class Progress>
    00285 void TePlotTexts(TeAppTheme* appTheme, Canvas* canvas, Progress * progress)
    00286 {
    00287            TeTheme* theme = appTheme->getTheme();
    00288            TeDatabase* db = appTheme->getLocalDatabase();
    00289            if(!db)
    00290                       return;
    00291
    00292            if(theme->minScale() != 0 && theme->maxScale() != 0 && theme->minScale() > theme->maxScale())
    00293            {
    00294                       if(theme->minScale() < canvas->scaleApx() || theme->maxScale() > canvas->scaleApx())
    00295                                  return;
    00296            }
    00297            if ((theme->visibleRep() & TeTEXT) == 0)
    00298                       return;
    00299
    00300            if(appTheme->textTable().empty())
    00301                       return;
    00302
    00303            if(db->tableExist(appTheme->textTable()) == false)
    00304                       return;
    00305            canvas->setDataProjection (theme->layer()->projection());
    00306            TeDatabasePortal* plot = db->getPortal();
    00307
    00308            string     tabtx = appTheme->textTable();
    00309            string     tabs = appTheme->getLocalCollectionTable();
    00310            if(tabs.empty())
    00311                       return false;
    00312
    00313            string wherebox = getWhereBox(plot, theme, canvas, TeTEXT);
    00314            if(wherebox.empty())
    00315            {
    00316                       TeBox box = canvas->getDataWorld();
    00317                       wherebox = " x >= " + Te2String(box.x1());
    00318                       wherebox += " AND x <= " + Te2String(box.x2());
    00319                       wherebox += " AND y >= " + Te2String(box.y1());
    00320                       wherebox += " AND y <= " + Te2String(box.y2());
    00321            }
    00322
    00323            // calculate initial filed number for collection and legenda (sind and vind)
    00324            int sind=0, vind=0;
    00325            string ind = "SELECT * FROM " + tabtx + " WHERE object_id < ' '";
    00326            plot->freeResult();
    00327            if (plot->query (ind))
    00328                       sind = plot->getAttributeList().size();
    00329
    00330            ind = "SELECT * FROM " + tabs + " WHERE c_object_id < ' '";
    00331            plot->freeResult();
    00332            if (plot->query (ind))
    00333                       vind = plot->getAttributeList().size() + sind;
    00334
    00335            int numrows = 0;
    00336            string conta = "SELECT COUNT(*) FROM " + tabs;
    00337            plot->freeResult();
    00338            if (plot->query (conta))
    00339            {
    00340                       if(plot->fetchRow())
    00341                                  numrows = atoi(plot->getData(0));
    00342            }
    00343            string sa;
    00344            string sel;
    00345            if(plot->getDatabase()->dbmsName() == "OracleSpatial")
    00346                       sel = " SELECT /*+ ordered */ * ";
    00347            else
    00348                       sel = " SELECT * ";
    00349
    00350            delete plot;
    00351            if(numrows > 0)
    00352                       sa = sel + " FROM (" + tabtx + " INNER JOIN " + tabs;
    00353            else
    00354                       sa = sel + " FROM (" + tabtx + " LEFT JOIN " + tabs;
    00355
    00356            sa += " ON " + tabtx + ".object_id = " + tabs + ".c_object_id) WHERE ";
    00357
    00358            string squery;
    00359            squery = sa + wherebox;
    00360            plotTexts(appTheme, canvas, squery, progress);
    00361
    00362            string othersQuery = "SELECT * FROM " + tabtx + " WHERE object_id = 'TE_NONE_ID'";
    00363            plotTexts(appTheme, canvas, othersQuery, progress);
    00364 }
    00365
    00366 template<class Canvas, class Progress>
    00367 void plotTexts(TeAppTheme *appTheme, Canvas *canvas, string query, Progress *progress)
    00368 {
    00369            TeText     text;
    00370            int        np = 0;
    00371            int dt = CLOCKS_PER_SEC/4;
    00372            int dt2 = CLOCKS_PER_SEC * 5;
    00373            clock_t    t0, t1, t2;
    00374
    00375            TeAbstractTheme* theme = appTheme->getTheme();
    00376            TeDatabase* db = appTheme->getLocalDatabase();
    00377            if(!db)
    00378                       return;
    00379
    00380            TeDatabasePortal* plot = db->getPortal();
    00381
    00382            if(progress == 0)
    00383            {
    00384                       if(plot->query(query) && plot->fetchRow())
    00385                       {
    00386                                  t1 = clock();
    00387                                  t2 = t1;
    00388                                  bool flag = true;
    00389                                  do
    00390                                  {
    00391                                             flag = plot->fetchGeometry(text);
    00392                                             setTextAttributes(theme, canvas, text);
    00393                                             canvas->plotText (text, theme->defaultLegend().visual(TeTEXT));
    00394                                             np++;
    00395                                             t2 = clock();
    00396                                             if (int(t2-t1) > dt)
    00397                                             {
    00398                                                        t1 = t2;
    00399                                                        canvas->copyPixmapToWindow();
    00400                                             }
    00401                                  } while (flag);
    00402                                  canvas->copyPixmapToWindow();
    00403                       }
    00404            }
    00405            else
    00406            {
    00407                       int steps = 0;
    00408                       string conta = query;
    00409                       conta.replace(0, strlen("SELECT *")+1, "SELECT COUNT(*)");
    00410                       int ff;
    00411                       if((ff=conta.find("ORDER BY")) >= 0)
    00412                                  conta = conta.substr(0, ff);
    00413                       plot->freeResult();
    00414                       if(plot->query(conta) && plot->fetchRow())
    00415                                  steps = atoi(plot->getData(0));
    00416
    00417                       plot->freeResult();
    00418                       if(plot->query(query) && plot->fetchRow())
    00419                       {
    00420                                  string caption = "Plotando tema: " + theme->name();
    00421                                  progress->setCaption(caption.c_str());
    00422                                  progress->setLabelText("      Plotagem de textos em andamento, aguarde...      ");
    00423                                  progress->setTotalSteps(steps);
    00424                                  t2 = clock();
    00425                                  t0 = t1 = t2;
    00426                                  bool flag = true;
    00427                                  do
    00428                                  {
    00429                                             flag = plot->fetchGeometry(text);
    00430                                             setTextAttributes(theme, canvas, text);
    00431                                             canvas->plotText (text, theme->defaultLegend().visual(TeTEXT));
    00432                                             np++;
    00433                                             t2 = clock();
    00434                                             if (int(t2-t1) > dt)
    00435                                             {
    00436                                                        t1 = t2;
    00437                                                        canvas->copyPixmapToWindow();
    00438                                                        if(progress->wasCancelled())
    00439                                                        {
    00440                                                                   progress->reset();
    00441                                                                   break;
    00442                                                        }
    00443                                                        if((int)(t2-t0) > dt2)
    00444                                                                   progress->setProgress(np);
    00445                                             }
    00446                                  } while (flag);
    00447                                  canvas->copyPixmapToWindow();
    00448                       }
    00449                       progress->reset();
    00450            }
    00451            delete plot;
    00452 }
    00453
    00454 template<class Canvas>
    00455 void setTextAttributes(TeAppTheme* appTheme, Canvas* canvas, TeText tx)
    00456 {
    00457            TeColor    cor;
    00458            static     TeVisual* snc;
    00459            string     family;
    00460            static int            ssize;
    00461            int                   size = 0;
    00462            bool       bold, italic, fixedSize;
    00463
    00464            if(appTheme == 0)
    00465            {
    00466                       ssize = 0;
    00467                       snc->family("notFamily");
    00468                       return;
    00469            }
    00470
    00471            TeAbstractTheme* theme = appTheme->getTheme();
    00472
    00473            fixedSize = theme->defaultLegend().visual(TeTEXT)->fixedSize(); // font size is fixed
    00474            if(snc == theme->defaultLegend().visual(TeTEXT))
    00475            {
    00476                       if(fixedSize == false && tx.height() > 0.)
    00477                       {
    00478                                  TeBox wbox = canvas->getDataWorld();
    00479                                  TeCoord2D p1(wbox.x1_, wbox.y1_);
    00480                                  TeCoord2D p2(p1.x() + tx.height(), p1.y() + tx.height());
    00481                                  TeBox box(p1, p2);
    00482                                  canvas->mapDWtoV(box);
    00483                                  size = int(box.height());
    00484                       }
    00485                       else
    00486                                  size = theme->defaultLegend().visual(TeTEXT)->size(); // font size
    00487            }
    00488
    00489            if(size == 0)
    00490            {
    00491                       if(fixedSize == false && tx.height() > 0.)
    00492                       {
    00493                                  TeBox wbox = canvas->getDataWorld();
    00494                                  TeCoord2D p1(wbox.x1_, wbox.y1_);
    00495                                  TeCoord2D p2(p1.x() + tx.height(), p1.y() + tx.height());
    00496                                  TeBox box(p1, p2);
    00497                                  canvas->mapDWtoV(box);
    00498                                  size = int(box.height());
    00499                       }
    00500                       else
    00501                                  size = theme->defaultLegend().visual(TeTEXT)->size(); // font size
    00502            }
    00503
    00504            cor = theme->defaultLegend().visual(TeTEXT)->color();
    00505            family = theme->defaultLegend().visual(TeTEXT)->family();
    00506            bold = theme->defaultLegend().visual(TeTEXT)->bold();
    00507            italic = theme->defaultLegend().visual(TeTEXT)->italic();
    00508            fixedSize = theme->defaultLegend().visual(TeTEXT)->fixedSize(); // font size is fixed
    00509
    00510            canvas->setTextColor(cor.red_, cor.green_, cor.blue_);
    00511            canvas->setTextStyle (family, size, bold, italic );
    00512            snc = theme->defaultLegend().visual(TeTEXT);
    00513            ssize = size;
    00514 }
    00515
    00516 template<class Canvas, class Progress>
    00517 void plotPieBars(TeAppTheme *appTheme, Canvas *canvas, Progress *progress, TeBox ebox = TeBox())
    00518 {
    00519            if(        appTheme->getTheme()->getProductId() != TeTHEME &&
    00520                       appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    00521                       return;
    00522
    00523            TeTheme* theme = (TeTheme*)appTheme->getTheme();
    00524            if(theme->minScale() != 0 && theme->maxScale() != 0 && theme->minScale() > theme->maxScale())
    00525            {
    00526                       if(theme->minScale() < canvas->scaleApx() || theme->maxScale() > canvas->scaleApx())
    00527                                  return;
    00528            }
    00529            if((theme->visibleRep() & 0x80000000) == 0)
    00530                       return;
    00531
    00532            int steps = 0;
    00533            int        np = 0;
    00534            int dt = CLOCKS_PER_SEC/4;
    00535            int dt2 = CLOCKS_PER_SEC * 2;
    00536            clock_t    t0, t1, t2;
    00537
    00538            TeDatabase* db = 0;
    00539            TeLayer* layer = 0;
    00540            if(theme->getProductId() == TeTHEME)
    00541                       layer = theme->layer();
    00542            else if(theme->getProductId() == TeEXTERNALTHEME)
    00543                       layer = ((TeExternalTheme*)theme)->getRemoteTheme()->layer();
    00544
    00545                       db = layer->database();
    00546
    00547            if(!db)
    00548                       return;
    00549
    00550            TeDatabasePortal* plot = db->getPortal();
    00551
    00552            canvas->setDataProjection (layer->projection());
    00553
    00554            if(appTheme->chartAttributes_.size() == 0)
    00555            {
    00556                       delete plot;
    00557                       return;
    00558            }
    00559            double     width = appTheme->barWidth();
    00560            double     maxh = appTheme->barMaxHeight();
    00561            double     minh = appTheme->barMinHeight();
    00562            double     maxd = appTheme->pieMaxDiameter();
    00563            double     mind = appTheme->pieMinDiameter();
    00564            double     diameter = appTheme->pieDiameter();
    00565            string FUNC = appTheme->chartFunction();
    00566
    00567            if(appTheme->keepDimension() != 0)
    00568            {
    00569                       width = canvas->mapVtoDW((int)width);
    00570                       maxh = canvas->mapVtoDW((int)maxh);
    00571                       minh = canvas->mapVtoDW((int)minh);
    00572                       maxd = canvas->mapVtoDW((int)maxd);
    00573                       mind = canvas->mapVtoDW((int)mind);
    00574                       diameter = canvas->mapVtoDW((int)diameter);
    00575            }
    00576
    00577            vector<string> itenVec, objVec;
    00578            unsigned int i;
    00579            string     input, cinput, sqlGridFrom, CT, CE;
    00580            TeSelectedObjects  selectedObjects = appTheme->chartObjects();
    00581            if(theme->getProductId() == TeTHEME)
    00582            {
    00583                       sqlGridFrom = theme->sqlGridFrom();
    00584                       CT = theme->collectionTable();
    00585                       CE = theme->collectionAuxTable();
    00586                       if(selectedObjects == TeSelectedByPointing)
    00587                       {
    00588                                  input = "(grid_status = 1 OR grid_status = 3";
    00589                                  input += " OR (grid_status is null AND (c_object_status = 1 OR c_object_status = 3)))";
    00590                                  cinput = "(c_object_status = 1 OR c_object_status = 3)";
    00591                       }
    00592                       else if(selectedObjects == TeNotSelectedByPointing)
    00593                       {
    00594                                  input = "(grid_status = 0 OR grid_status = 2";
    00595                                  input += " OR (grid_status is null AND (c_object_status = 0 OR c_object_status = 2)))";
    00596                                  cinput = "(c_object_status = 0 OR c_object_status = 2)";
    00597                       }
    00598                       else if(selectedObjects == TeSelectedByQuery)
    00599                       {
    00600                                  input = "(grid_status = 2 OR grid_status = 3";
    00601                                  input += " OR (grid_status is null AND (c_object_status = 2 OR c_object_status = 3)))";
    00602                                  cinput = "(c_object_status = 2 OR c_object_status = 3)";
    00603                       }
    00604                       else if(selectedObjects == TeNotSelectedByQuery)
    00605                       {
    00606                                  input = "(grid_status = 0 OR grid_status = 1";
    00607                                  input += " OR (grid_status is null AND (c_object_status = 0 OR c_object_status = 1)))";
    00608                                  cinput = "(c_object_status = 0 OR c_object_status = 1)";
    00609                       }
    00610                       else if(selectedObjects == TeGrouped)
    00611                       {
    00612                                  input = "c_legend_id <> 0";
    00613                                  cinput = "c_legend_id <> 0";
    00614                       }
    00615                       else if(selectedObjects == TeNotGrouped)
    00616                       {
    00617                                  input = "c_legend_id = 0";
    00618                                  cinput = "c_legend_id = 0";
    00619                       }
    00620            }
    00621            else if(theme->getProductId() == TeEXTERNALTHEME)
    00622            {
    00623                       itenVec = getItems(theme, selectedObjects);
    00624                       objVec = getObjects(theme, selectedObjects);
    00625                       sqlGridFrom = ((TeExternalTheme*)theme)->getRemoteTheme()->sqlGridFrom();
    00626                       CT = ((TeExternalTheme*)theme)->getRemoteTheme()->collectionTable();
    00627                       CE = ((TeExternalTheme*)theme)->getRemoteTheme()->collectionAuxTable();
    00628            }
    00629
    00630            canvas->setLineStyle(TeLnTypeContinuous, 0);
    00631            canvas->setLineColor(0, 0, 0);
    00632            TeChartType chartType = (TeChartType)appTheme->chartType();
    00633            if(chartType == TePieChart)
    00634            {
    00635                       string wherebox;
    00636                       double delta = diameter / 2.;
    00637                       if(!(appTheme->pieDimAttribute() == "NONE"))
    00638                                  delta = maxd / 2.;
    00639
    00640                       TeBox box;
    00641                       if(ebox.isValid())
    00642                                  box = ebox;
    00643                       else
    00644                                  box = canvas->getDataWorld();
    00645
    00646                       box.x1_ = box.x1_ - delta;
    00647                       box.x2_ = box.x2_ + delta;
    00648                       box.y1_ = box.y1_ - delta;
    00649                       box.y2_ = box.y2_ + delta;
    00650
    00651                       wherebox = "NOT(label_x > " + Te2String(box.x2_, 10) + " OR ";
    00652                       wherebox = wherebox + "label_x < " + Te2String(box.x1_, 10) + " OR ";
    00653                       wherebox = wherebox + "label_y > " + Te2String(box.y2_, 10) + " OR ";
    00654                       wherebox = wherebox + "label_y < " + Te2String(box.y1_, 10) + ")";
    00655
    00656                       string attrs, q;
    00657                       for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00658                                  attrs += FUNC + "(" + appTheme->chartAttributes_[i] + "),";
    00659                       attrs += "AVG(label_x),AVG(label_y)";
    00660                       if(!(appTheme->pieDimAttribute() == "NONE"))
    00661                                  attrs += "," + FUNC + "(" + appTheme->pieDimAttribute() + ")";
    00662
    00663                       if(theme->getProductId() == TeTHEME)
    00664                       {
    00665                                  if(wherebox.empty() && itenVec.empty())
    00666                                             q = "SELECT " + attrs + sqlGridFrom;
    00667                                  else if(wherebox.empty() && input.empty()==false)
    00668                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + input;
    00669                                  else if(wherebox.empty()==false && input.empty())
    00670                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + wherebox;
    00671                                  else if(wherebox.empty()==false && input.empty()==false)
    00672                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + input + " AND " + wherebox;
    00673                                  q += " GROUP BY " + CT + ".c_object_id";
    00674
    00675                                  string conta = "SELECT COUNT(*) FROM " + CT;
    00676                                  if(wherebox.empty() && cinput.empty()==false)
    00677                                             conta += " WHERE " + cinput;
    00678                                  else if(wherebox.empty()==false && cinput.empty())
    00679                                             conta += " WHERE " + wherebox;
    00680                                  else if(wherebox.empty()==false && cinput.empty()==false)
    00681                                             conta += " WHERE " + cinput + " AND " + wherebox;
    00682
    00683                                  plot->freeResult();
    00684                                  if(plot->query(conta) && plot->fetchRow())
    00685                                             steps = atoi(plot->getData(0));
    00686
    00687                                  plot->freeResult();
    00688                                  if(plot->query(q))
    00689                                  {
    00690                                             if(progress)
    00691                                             {
    00692                                                        string caption = "Plotando tema: " + theme->name();
    00693                                                        progress->setCaption(caption.c_str());
    00694                                                        progress->setLabelText("      Plotagem de tortas em andamento, aguarde...      ");
    00695                                                        progress->setTotalSteps(steps);
    00696                                             }
    00697                                             t2 = clock();
    00698                                             t0 = t1 = t2;
    00699                                             bool b = plot->fetchRow(0);
    00700                                             while(b)
    00701                                             {
    00702                                                        double tot = 0.;
    00703                                                        for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00704                                                        {
    00705                                                                   string v = plot->getData(i);
    00706                                                                   if(v.empty())
    00707                                                                   {
    00708                                                                              tot = 0.;
    00709                                                                              break;
    00710                                                                   }
    00711                                                                   tot += atof(v.c_str());
    00712                                                        }
    00713                                                        if(tot == 0.)
    00714                                                        {
    00715                                                                   b = plot->fetchRow();
    00716                                                                   np++;
    00717                                                                   continue;
    00718                                                        }
    00719
    00720                                                        if(!(appTheme->pieDimAttribute() == "NONE"))
    00721                                                        {
    00722                                                                   if(appTheme->chartMaxVal() - appTheme->chartMinVal() == 0)
    00723                                                                              diameter = 0.;
    00724                                                                   else
    00725                                                                   {
    00726                                                                              double     adim = atof(plot->getData(appTheme->chartAttributes_.size()+2));
    00727                                                                              double a = (adim - appTheme->chartMinVal()) / (appTheme->chartMaxVal() - appTheme->chartMinVal());
    00728                                                                              diameter = a * (maxd - mind) + mind;
    00729                                                                   }
    00730                                                        }
    00731                                                        double     x = atof(plot->getData(appTheme->chartAttributes_.size())) - diameter / 2.;
    00732                                                        double     y = atof(plot->getData(appTheme->chartAttributes_.size()+1)) - diameter / 2.;
    00733
    00734                                                        double     a = 0.;
    00735                                                        for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00736                                                        {
    00737                                                                   double b = atof(plot->getData(i)) / tot * 360.;
    00738                                                                   TeColor    cor = appTheme->chartColors_[i];
    00739                                                                   canvas->setPieColor(cor.red_, cor.green_, cor.blue_);
    00740                                                                   canvas->plotPie(x, y, diameter, diameter, a, b);
    00741                                                                   a += b;
    00742                                                        }
    00743                                                        np++;
    00744                                                        t2 = clock();
    00745                                                        if (int(t2-t1) > dt)
    00746                                                        {
    00747                                                                   t1 = t2;
    00748                                                                   canvas->copyPixmapToWindow();
    00749                                                                   if(progress)
    00750                                                                   {
    00751                                                                              if(progress->wasCancelled())
    00752                                                                              {
    00753                                                                                         progress->reset();
    00754                                                                                         break;
    00755                                                                              }
    00756                                                                              if((int)(t2-t0) > dt2)
    00757                                                                                         progress->setProgress(np);
    00758                                                                   }
    00759                                                        }
    00760                                                        b = plot->fetchRow();
    00761                                             }
    00762                                             canvas->copyPixmapToWindow();
    00763                                  }
    00764                       }
    00765                       else if(theme->getProductId() == TeEXTERNALTHEME)
    00766                       {
    00767                                  string conta = "SELECT COUNT(*) FROM " + CT;
    00768                                  plot->freeResult();
    00769                                  if(plot->query(conta) && plot->fetchRow())
    00770                                             steps = atoi(plot->getData(0));
    00771
    00772       std::vector< std::string >::iterator it_begin = itenVec.begin();
    00773       std::vector< std::string >::iterator it_end = itenVec.end();
    00774
    00775                                  vector<string> sv = generateItemsInClauses(it_begin, it_end, theme);
    00776                                  vector<string>::iterator it;
    00777                                  for(it=sv.begin(); it!=sv.end(); ++it)
    00778                                  {
    00779                                             string s = *it;
    00780                                             string q = "SELECT " + attrs + sqlGridFrom;
    00781                                             if((*it).empty() == false && wherebox.empty())
    00782                                                        q += " WHERE " + CE + ".unique_id IN " + *it;
    00783                                             else if((*it).empty() && wherebox.empty()==false)
    00784                                                        q += " WHERE " + wherebox;
    00785                                             else if((*it).empty()==false && wherebox.empty()==false)
    00786                                                        q += " WHERE " + CE + ".unique_id IN " + *it + " AND " + wherebox;
    00787                                             q += " GROUP BY " + CT + ".c_object_id";
    00788
    00789                                             plot->freeResult();
    00790                                             if(plot->query(q))
    00791                                             {
    00792                                                        if(progress)
    00793                                                        {
    00794                                                                   string caption = "Plotando tema: " + theme->name();
    00795                                                                   progress->setCaption(caption.c_str());
    00796                                                                   progress->setLabelText("      Plotagem de tortas em andamento, aguarde...      ");
    00797                                                                   progress->setTotalSteps(steps);
    00798                                                        }
    00799                                                        t2 = clock();
    00800                                                        t0 = t1 = t2;
    00801                                                        bool b = plot->fetchRow(0);
    00802                                                        while(b)
    00803                                                        {
    00804                                                                   double tot = 0.;
    00805                                                                   for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00806                                                                   {
    00807                                                                              string v = plot->getData(i);
    00808                                                                              if(v.empty())
    00809                                                                              {
    00810                                                                                         tot = 0.;
    00811                                                                                         break;
    00812                                                                              }
    00813                                                                              tot += atof(v.c_str());
    00814                                                                   }
    00815                                                                   if(tot == 0.)
    00816                                                                   {
    00817                                                                              b = plot->fetchRow();
    00818                                                                              np++;
    00819                                                                              continue;
    00820                                                                   }
    00821
    00822                                                                   if(!(appTheme->pieDimAttribute() == "NONE"))
    00823                                                                   {
    00824                                                                              if(appTheme->chartMaxVal() - appTheme->chartMinVal() == 0)
    00825                                                                                         diameter = 0.;
    00826                                                                              else
    00827                                                                              {
    00828                                                                                         double     adim = atof(plot->getData(appTheme->chartAttributes_.size()+2));
    00829                                                                                         double a = (adim - appTheme->chartMinVal()) / (appTheme->chartMaxVal() - appTheme->chartMinVal());
    00830                                                                                         diameter = a * (maxd - mind) + mind;
    00831                                                                              }
    00832                                                                   }
    00833                                                                   double     x = atof(plot->getData(appTheme->chartAttributes_.size())) - diameter / 2.;
    00834                                                                   double     y = atof(plot->getData(appTheme->chartAttributes_.size()+1)) - diameter / 2.;
    00835
    00836                                                                   double     a = 0.;
    00837                                                                   for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00838                                                                   {
    00839                                                                              double b = atof(plot->getData(i)) / tot * 360.;
    00840                                                                              TeColor    cor = appTheme->chartColors_[i];
    00841                                                                              canvas->setPieColor(cor.red_, cor.green_, cor.blue_);
    00842                                                                              canvas->plotPie(x, y, diameter, diameter, a, b);
    00843                                                                              a += b;
    00844                                                                   }
    00845                                                                   np++;
    00846                                                                   t2 = clock();
    00847                                                                   if (int(t2-t1) > dt)
    00848                                                                   {
    00849                                                                              t1 = t2;
    00850                                                                              canvas->copyPixmapToWindow();
    00851                                                                              if(progress)
    00852                                                                              {
    00853                                                                                         if(progress->wasCancelled())
    00854                                                                                         {
    00855                                                                                                    progress->reset();
    00856                                                                                                    break;
    00857                                                                                         }
    00858                                                                                         if((int)(t2-t0) > dt2)
    00859                                                                                                    progress->setProgress(np);
    00860                                                                              }
    00861                                                                   }
    00862                                                                   b = plot->fetchRow();
    00863                                                        }
    00864                                                        canvas->copyPixmapToWindow();
    00865                                             }
    00866                                  }
    00867                       }
    00868            }
    00869            else
    00870            {
    00871                       double     n = appTheme->chartAttributes_.size();
    00872                       double     maxv = appTheme->chartMaxVal();
    00873                       double     minv = appTheme->chartMinVal();
    00874                       double delta = maxh / 2.;
    00875
    00876                       string wherebox;
    00877
    00878                       TeBox box;
    00879                       if(ebox.isValid())
    00880                                  box = ebox;
    00881                       else
    00882                                  box = canvas->getDataWorld();
    00883
    00884                       box.x1_ = box.x1_ - delta;
    00885                       box.x2_ = box.x2_ + delta;
    00886                       box.y1_ = box.y1_ - delta;
    00887                       box.y2_ = box.y2_ + delta;
    00888
    00889                       wherebox = "NOT(label_x > " + Te2String(box.x2_, 10) + " OR ";
    00890                       wherebox = wherebox + "label_x < " + Te2String(box.x1_, 10) + " OR ";
    00891                       wherebox = wherebox + "label_y > " + Te2String(box.y2_, 10) + " OR ";
    00892                       wherebox = wherebox + "label_y < " + Te2String(box.y1_, 10) + ")";
    00893
    00894                       string attrs, q;
    00895                       for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00896                                  attrs += FUNC + "(" + appTheme->chartAttributes_[i] + "),";
    00897                       attrs += "AVG(label_x),AVG(label_y)";
    00898
    00899                       if(theme->getProductId() == TeTHEME)
    00900                       {
    00901                                  if(wherebox.empty() && input.empty())
    00902                                             q = "SELECT " + attrs + sqlGridFrom;
    00903                                  else if (wherebox.empty() == false && input.empty() == false)
    00904                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + input + " AND " + wherebox;
    00905                                  else if (wherebox.empty() == false && input.empty())
    00906                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + wherebox;
    00907                                  else if (wherebox.empty() && input.empty() == false)
    00908                                             q = "SELECT " + attrs + sqlGridFrom + " WHERE " + input;
    00909                                  q += " GROUP BY " + CT + ".c_object_id";
    00910
    00911                                  string conta = "SELECT COUNT(*) FROM " + CT;
    00912                                  if(wherebox.empty() && cinput.empty()==false)
    00913                                             conta += " WHERE " + cinput;
    00914                                  else if(wherebox.empty()==false && cinput.empty())
    00915                                             conta += " WHERE " + wherebox;
    00916                                  else if(wherebox.empty()==false && cinput.empty()==false)
    00917                                             conta += " WHERE " + cinput + " AND " + wherebox;
    00918
    00919                                  plot->freeResult();
    00920                                  if(plot->query(conta) && plot->fetchRow())
    00921                                             steps = atoi(plot->getData(0));
    00922
    00923                                  vector<double> dvec;
    00924                                  plot->freeResult();
    00925                                  if(plot->query(q))
    00926                                  {
    00927                                             if(progress)
    00928                                             {
    00929                                                        string caption = "Plotando tema: " + theme->name();
    00930                                                        progress->setCaption(caption.c_str());
    00931                                                        progress->setLabelText("      Plotagem de barras em andamento, aguarde...      ");
    00932                                                        progress->setTotalSteps(steps);
    00933                                             }
    00934                                             t2 = clock();
    00935                                             t0 = t1 = t2;
    00936                                             bool b = plot->fetchRow(0);
    00937                                             while(b)
    00938                                             {
    00939                                                        double     x = atof(plot->getData(appTheme->chartAttributes_.size())) - n * width / 2.;
    00940                                                        double     y = atof(plot->getData(appTheme->chartAttributes_.size()+1));
    00941
    00942                                                        dvec.clear();
    00943                                                        for(i=0; i<appTheme->chartAttributes_.size(); i++)
    00944                                                        {
    00945                                                                   string val = plot->getData(i);
    00946                                                                   if(val.empty())
    00947                                                                   {
    00948                                                                              dvec.clear();
    00949                                                                              break;
    00950                                                                   }
    00951                                                                   dvec.push_back(atof(val.c_str()));
    00952                                                        }
    00953
    00954                                                        for(i=0; i<dvec.size(); i++)
    00955                                                        {
    00956                                                                   double height;
    00957                                                                   double v = dvec[i];
    00958                                                                   if(maxv - minv == 0)
    00959                                                                              height = 0.;
    00960                                                                   else
    00961                                                                              height = (v - minv) * (maxh - minh) / (maxv - minv) + minh;
    00962                                                                   TeColor    cor = appTheme->chartColors_[i];
    00963                                                                   canvas->setRectColor(cor.red_, cor.green_, cor.blue_);
    00964                                                                   canvas->plotRect(x, y, width, height);
    00965                                                                   x += width;
    00966                                                        }
    00967                                                        np++;
    00968                                                        t2 = clock();
    00969                                                        if (int(t2-t1) > dt)
    00970                                                        {
    00971                                                                   t1 = t2;
    00972                                                                   canvas->copyPixmapToWindow();
    00973                                                                   if(progress)
    00974                                                                   {
    00975                                                                              if(progress->wasCancelled())
    00976                                                                              {
    00977                                                                                         progress->reset();
    00978                                                                                         break;
    00979                                                                              }
    00980                                                                              if((int)(t2-t0) > dt2)
    00981                                                                                         progress->setProgress(np);
    00982                                                                   }
    00983                                                        }
    00984                                                        b = plot->fetchRow();
    00985                                             }
    00986                                             canvas->copyPixmapToWindow();
    00987                                  }
    00988                       }
    00989                       if(theme->getProductId() == TeEXTERNALTHEME)
    00990                       {
    00991                                  string conta = "SELECT COUNT(*) FROM " + CT;
    00992                                  plot->freeResult();
    00993                                  if(plot->query(conta) && plot->fetchRow())
    00994                                             steps = atoi(plot->getData(0));
    00995
    00996       std::vector< std::string >::iterator it_begin = itenVec.begin();
    00997       std::vector< std::string >::iterator it_end = itenVec.end();
    00998
    00999       vector<string> sv = generateItemsInClauses(it_begin, it_end, theme);
    01000
    01001                                  vector<string>::iterator it;
    01002                                  for(it=sv.begin(); it!=sv.end(); ++it)
    01003                                  {
    01004                                             string s = *it;
    01005                                             string q = "SELECT " + attrs + sqlGridFrom;
    01006                                             if((*it).empty() == false && wherebox.empty())
    01007                                                        q += " WHERE " + CE + ".unique_id IN " + *it;
    01008                                             else if((*it).empty() && wherebox.empty()==false)
    01009                                                        q += " WHERE " + wherebox;
    01010                                             else if((*it).empty()==false && wherebox.empty()==false)
    01011                                                        q += " WHERE " + CE + ".unique_id IN " + *it + " AND " + wherebox;
    01012                                             q += " GROUP BY " + CT + ".c_object_id";
    01013
    01014                                             vector<double> dvec;
    01015                                             plot->freeResult();
    01016                                             if(plot->query(q))
    01017                                             {
    01018                                                        if(progress)
    01019                                                        {
    01020                                                                   string caption = "Plotando tema: " + theme->name();
    01021                                                                   progress->setCaption(caption.c_str());
    01022                                                                   progress->setLabelText("      Plotagem de barras em andamento, aguarde...      ");
    01023                                                                   progress->setTotalSteps(steps);
    01024                                                        }
    01025                                                        t2 = clock();
    01026                                                        t0 = t1 = t2;
    01027                                                        bool b = plot->fetchRow(0);
    01028                                                        while(b)
    01029                                                        {
    01030                                                                   double     x = atof(plot->getData(appTheme->chartAttributes_.size())) - n * width / 2.;
    01031                                                                   double     y = atof(plot->getData(appTheme->chartAttributes_.size()+1));
    01032
    01033                                                                   dvec.clear();
    01034                                                                   for(i=0; i<appTheme->chartAttributes_.size(); i++)
    01035                                                                   {
    01036                                                                              string val = plot->getData(i);
    01037                                                                              if(val.empty())
    01038                                                                              {
    01039                                                                                         dvec.clear();
    01040                                                                                         break;
    01041                                                                              }
    01042                                                                              dvec.push_back(atof(val.c_str()));
    01043                                                                   }
    01044
    01045                                                                   for(i=0; i<dvec.size(); i++)
    01046                                                                   {
    01047                                                                              double height;
    01048                                                                              double v = dvec[i];
    01049                                                                              if(maxv - minv == 0)
    01050                                                                                         height = 0.;
    01051                                                                              else
    01052                                                                                         height = (v - minv) * (maxh - minh) / (maxv - minv) + minh;
    01053                                                                              TeColor    cor = appTheme->chartColors_[i];
    01054                                                                              canvas->setRectColor(cor.red_, cor.green_, cor.blue_);
    01055                                                                              canvas->plotRect(x, y, width, height);
    01056                                                                              x += width;
    01057                                                                   }
    01058                                                                   np++;
    01059                                                                   t2 = clock();
    01060                                                                   if (int(t2-t1) > dt)
    01061                                                                   {
    01062                                                                              t1 = t2;
    01063                                                                              canvas->copyPixmapToWindow();
    01064                                                                              if(progress)
    01065                                                                              {
    01066                                                                                         if(progress->wasCancelled())
    01067                                                                                         {
    01068                                                                                                    progress->reset();
    01069                                                                                                    break;
    01070                                                                                         }
    01071                                                                                         if((int)(t2-t0) > dt2)
    01072                                                                                                    progress->setProgress(np);
    01073                                                                              }
    01074                                                                   }
    01075                                                                   b = plot->fetchRow();
    01076                                                        }
    01077                                                        canvas->copyPixmapToWindow();
    01078                                             }
    01079                                  }
    01080                       }
    01081            }
    01082            if(progress)
    01083                       progress->reset();
    01084            delete plot;
    01085 }
    01086
    01087
    01088 template<class Portal, class Canvas>
    01089 string getWhereBox(Portal *plot, TeAppTheme *appTheme, Canvas *canvas, TeGeomRep rep, TeBox bbox = TeBox())
    01090 {
    01091            string wherebox;
    01092            if(        appTheme->getTheme()->getProductId() != TeTHEME &&
    01093                       appTheme->getTheme()->getProductId() != TeEXTERNALTHEME )
    01094                       return wherebox;
    01095
    01096            TeTheme* theme = (TeTheme*)appTheme->getTheme();
    01097            TeLayer* layer = theme->layer();
    01098            std::string tableName = layer->tableName(rep);
    01099
    01100            if(appTheme->chartSelected_.empty() == true)
    01101            {
    01102                       TeBox box;
    01103                       if(bbox.isValid())
    01104                                  box = bbox;
    01105                       else
    01106                       {
    01107                                  if(canvas->canvasAndDataProjectionEqual())
    01108                                  {
    01109                                             box = canvas->getDataWorld();
    01110                                  }
    01111                                  else
    01112                                  {
    01113                                             TeBox canvasBox = TeRemapBoxPC2Geodetic(canvas->getWorld(), canvas->projection());
    01114                                             TeBox layerBox = TeRemapBoxPC2Geodetic(layer->box(), layer->projection());
    01115
    01116                                             TeBox ibox;
    01117                                             if (TeIntersection(canvasBox, layerBox, ibox))
    01118                                                        box = TeRemapBoxGeodetic2PC(ibox, layer->projection());
    01119                                  }
    01120                       }
    01121                       wherebox = plot->getDatabase()->getSQLBoxWhere(box, rep, tableName);
    01122            }
    01123            else
    01124            {
    01125                       if (rep == TePOINTS)
    01126                       {
    01127                                  double     width = appTheme->barWidth();
    01128                                  double     maxh = appTheme->barMaxHeight();
    01129                                  double     minh = appTheme->barMinHeight();
    01130                                  double     maxd = appTheme->pieMaxDiameter();
    01131                                  double     mind = appTheme->pieMinDiameter();
    01132                                  double     diameter = appTheme->pieDiameter();
    01133                                  double     delta;
    01134
    01135                                  if(appTheme->keepDimension() != 0)
    01136                                  {
    01137                                             width = canvas->mapVtoCW((int)width);
    01138                                             maxh = canvas->mapVtoCW((int)maxh);
    01139                                             minh = canvas->mapVtoCW((int)minh);
    01140                                             maxd = canvas->mapVtoCW((int)maxd);
    01141                                             mind = canvas->mapVtoCW((int)mind);
    01142                                             diameter = canvas->mapVtoCW((int)diameter);
    01143                                  }
    01144
    01145                                  TeChartType chartType = (TeChartType)appTheme->chartType();
    01146                                  if(chartType == TePieChart)
    01147                                  {
    01148                                             delta = diameter / 2.;
    01149                                             if(!(appTheme->pieDimAttribute() == "NONE"))
    01150                                                        delta = maxd / 2.;
    01151                                  }
    01152                                  else
    01153                                             delta = maxh / 2.;
    01154
    01155                                  string sel = "SELECT label_x, label_y FROM " + theme->collectionTable();
    01156                                  sel += " WHERE c_object_id = '" + appTheme->chartSelected_ + "'";
    01157                                  plot->freeResult();
    01158                                  if(plot->query(sel))
    01159                                  {
    01160                                             bool b = plot->fetchRow(0);
    01161                                             if(b == false)
    01162                                                        return wherebox;
    01163                                             if(b)
    01164                                             {
    01165                                                        double x = atof(plot->getData(0));
    01166                                                        double y = atof(plot->getData(1));
    01167                                                        string xmin = Te2String(x - delta);
    01168                                                        string xmax = Te2String(x + delta);
    01169                                                        string ymin = Te2String(y - delta);
    01170                                                        string ymax = Te2String(y + delta);
    01171                                                        wherebox = "label_x > " + xmin + " AND ";
    01172                                                        wherebox += "label_x < " + xmax + " AND ";
    01173                                                        wherebox += "label_y > " + ymin + " AND ";
    01174                                                        wherebox += "label_y < " + ymax;
    01175                                             }
    01176                                  }
    01177                       }
    01178                       else if(rep == TePOLYGONS || rep == TeLINES || rep == TeCELLS)
    01179                       {
    01180                                  string tab;
    01181                                  if(rep == TePOLYGONS)
    01182                                             tab = theme->layer()->tableName(TePOLYGONS);
    01183                                  else if (rep == TeLINES)
    01184                                             tab = theme->layer()->tableName(TeLINES);
    01185                                  else if (rep == TeCELLS)
    01186                                             tab = theme->layer()->tableName(TeCELLS);
    01187
    01188                                  plot->freeResult();
    01189
    01190                                  TeBox b;
    01191                                  bool result = plot->getDatabase()->getMBRGeom(tab, appTheme->chartSelected_, b, "spatial_data");
    01192                                  if(!result)
    01193                                             return wherebox;
    01194                                  else
    01195                                             wherebox = plot->getDatabase()->getSQLBoxWhere(b, rep, tableName);
    01196                       }
    01197            }
    01198            return wherebox;
    01199 }
    01200
    01201 template<class Portal>
    01202 TeVisual getVisual(Portal* portal, TeAppTheme* appTheme, TeGeomRep GEOMREP, int resPos, int groPos, int ownPos)
    01203 {
    01204            TeVisual visual;
    01205            TeAbstractTheme* theme = appTheme->getTheme();
    01206            TeDatabase* db = appTheme->getLocalDatabase();
    01207            if(!db)
    01208                       return visual;
    01209
    01210            TeLegendEntry* legendEntry;
    01211
    01212            int status = atoi(portal->getData(resPos));
    01213            int groId = atoi(portal->getData(groPos));
    01214            int ownId = atoi(portal->getData(ownPos));
    01215
    01216            if(groId && (theme->visibleRep()&0x40000000))
    01217                       legendEntry = db->legendMap()[groId];
    01218            else if(ownId != 0)
    01219                       legendEntry = db->legendMap()[ownId];
    01220            else
    01221                       legendEntry = &(theme->defaultLegend());
    01222
    01223 //         if(legendEntry)
    01224 //                    visual = legendEntry->visual(GEOMREP);
    01225 //         else
    01226 //                    visual = TeVisual(GEOMREP);
    01228            TeGeomRepVisualMap& vm = legendEntry->getVisualMap();
    01229            if(legendEntry && vm.find(GEOMREP) != vm.end())
    01230                       visual = *(legendEntry->visual(GEOMREP));
    01231            else
    01232            {
    01233                       if(ownId != 0)
    01234                                  legendEntry = db->legendMap()[ownId];
    01235                       else
    01236                                  legendEntry = &(theme->defaultLegend());
    01237
    01238                       visual = *(legendEntry->visual(GEOMREP));
    01239            }
    01241
    01242            if(status == 1)
    01243                       visual.color((theme->pointingLegend().visual(TePOLYGONS))->color());
    01244            else if(status == 2)
    01245                       visual.color((theme->queryLegend().visual(TePOLYGONS))->color());
    01246            else if(status == 3)
    01247                       visual.color((theme->queryAndPointingLegend().visual(TePOLYGONS))->color());
    01248
    01249            if(status == 0)
    01250            {
    01251                       if(GEOMREP == TePOLYGONS || GEOMREP == TeCELLS)
    01252                       {
    01253                                  if(visual.transparency() == 100 && visual.style() != TePolyTypeTransparent)
    01254                                             visual.style(TePolyTypeTransparent);
    01255                       }
    01256            }
    01257
    01258            return visual;
    01259 }
    01260
    01261 template<class Portal>
    01262 TeVisual getVisualRemote(Portal* /* portal */, TeAppTheme* appTheme, TeGeomRep GEOMREP, string objId)
    01263 {
    01264            TeVisual visual;
    01265            if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01266                       return visual;
    01267
    01268            TeExternalTheme* theme = static_cast<TeExternalTheme*>(appTheme->getTheme());
    01269            TeDatabase* db = theme->getSourceDatabase();
    01270            TeLegendEntry* legendEntry;
    01271
    01272            int status;
    01273            std::map<std::string, int>::iterator itLS = theme->getObjStatusMap().find(objId);
    01274            if( itLS != theme->getObjStatusMap().end())
    01275                       status = itLS->second;
    01276            else
    01277                       status = 0;
    01278
    01279            int groId;
    01280            std::map<std::string, int>::iterator itOL = theme->getObjLegendMap().find(objId);
    01281            if( itOL != theme->getObjLegendMap().end())
    01282                       groId = itOL->second;
    01283            else
    01284                       groId = 0;
    01285
    01286
    01287            int ownId;
    01288            std::map<std::string, int>::iterator itOLO = theme->getObjOwnLegendMap().find(objId);
    01289            if( itOLO != theme->getObjOwnLegendMap().end())
    01290                       ownId= itOLO->second;
    01291            else
    01292                       ownId = 0;
    01293
    01294
    01295            if(groId && (theme->visibleRep()&0x40000000))
    01296                       legendEntry = db->legendMap()[groId];
    01297            else if(ownId != 0)
    01298                       legendEntry = db->legendMap()[ownId];
    01299            else
    01300                       legendEntry = &(theme->defaultLegend());
    01301
    01302 //         if(legendEntry)
    01303 //                    visual = legendEntry->visual(GEOMREP);
    01304 //         else
    01305 //                    visual = TeVisual(GEOMREP);
    01307            TeGeomRepVisualMap& vm = legendEntry->getVisualMap();
    01308            if(legendEntry && vm.find(GEOMREP) != vm.end())
    01309                       visual = *(legendEntry->visual(GEOMREP));
    01310            else
    01311            {
    01312                       if(ownId != 0)
    01313                                  legendEntry = db->legendMap()[ownId];
    01314                       else
    01315                                  legendEntry = &(theme->defaultLegend());
    01316
    01317                       visual = *(legendEntry->visual(GEOMREP));
    01318            }
    01320
    01321            if(status == 1)
    01322                       visual.color((theme->pointingLegend().visual(TePOLYGONS))->color());
    01323            else if(status == 2)
    01324                       visual.color((theme->queryLegend().visual(TePOLYGONS))->color());
    01325            else if(status == 3)
    01326                       visual.color((theme->queryAndPointingLegend().visual(TePOLYGONS))->color());
    01327
    01328            return visual;
    01329 }
    01330
    01331
    01332 template<class Canvas , class Progress>
    01333 void TePlotObjects (TeAppTheme* appTheme, Canvas *canvas, map<int, RepMap>& layerRepMap, Progress *progress = 0, TeBox box = TeBox())
    01334 {
    01335            string tableName, objectId;
    01336            TeColor color;
    01337            TeVisual visual;
    01338            int dt = CLOCKS_PER_SEC/4;
    01339            int dt2 = CLOCKS_PER_SEC * 5;
    01340            clock_t    t0, t1, t2;
    01341            int nSteps, nLoops;
    01342
    01343 /*         if(appTheme->getTheme()->getProductId()==TeFILETHEME)
    01344            {
    01345                       TePlotFileTheme<Canvas, Progress> (appTheme, canvas, progress, box);
    01346                       return;
    01347            }
    01348 */
    01349
    01350            if(        appTheme->getTheme()->getProductId() != TeTHEME &&
    01351                       appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01352            {
    01353                       PluginsSignal sigdraw(PluginsSignal::S_DRAW_THEME);
    01354
    01355                       sigdraw.signalData_.store(PluginsSignal::D_QT_CANVAS, canvas);
    01356                       sigdraw.signalData_.store(PluginsSignal::D_ABSTRACT_THEME, appTheme->getTheme());
    01357
    01358                       PluginsEmitter::instance().send(sigdraw);
    01359
    01360                       return;
    01361            }
    01362
    01363            TeTheme* theme = appTheme->getSourceTheme();
    01364            if (theme == 0)
    01365                       return;
    01366            TeLayer* layer = theme->layer();
    01367            if(appTheme->getTheme()->minScale() != 0 && appTheme->getTheme()->maxScale() != 0 && appTheme->getTheme()->minScale() > appTheme->getTheme()->maxScale())
    01368            {
    01369                       if(appTheme->getTheme()->minScale() < canvas->scaleApx() || appTheme->getTheme()->maxScale() > canvas->scaleApx())
    01370                                  return;
    01371            }
    01372
    01373            TeDatabase *db = layer->database();
    01374            TeDatabasePortal *portal = db->getPortal();
    01375            canvas->setDataProjection (layer->projection());
    01376            map<int, RepMap>::iterator it = layerRepMap.find(layer->id());
    01377
    01378            TeBox vb = box;
    01379            if(box.isValid())
    01380            {
    01381                       canvas->mapDWtoCW(vb);
    01382                       canvas->mapCWtoV(vb);
    01383            }
    01384
    01385            if (((appTheme->getTheme()->visibleRep() & TeRASTER) && layer->hasGeometry(TeRASTER)) ||
    01386                       ((appTheme->getTheme()->visibleRep() & TeRASTERFILE) && layer->hasGeometry(TeRASTERFILE)))
    01387            {
    01388                       TeBox bIn;
    01389                       if (box.isValid())
    01390                       {
    01391                                  canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    01392                                  bIn = vb;
    01393                       }
    01394
    01395                       TeRaster* raster = theme->layer()->raster();
    01396                       if (raster && (raster->params().status_ == TeRasterParams::TeReadyToRead || raster->params().status_ == TeRasterParams::TeReadyToWrite))
    01397                       {
    01398                                  if (!theme->rasterVisual())
    01399                                             theme->createRasterVisual(raster);
    01400                                  canvas->plotRaster(raster,theme->rasterVisual(),progress);
    01401                       }
    01402            }
    01403            if(layer->hasGeometry(TePOLYGONS) && (appTheme->getTheme()->visibleRep() & TePOLYGONS))
    01404            {
    01405                       nLoops = 0;
    01406                       // query the database table containing the polygons� geometry
    01407                       string wherebox = getWhereBox(portal, appTheme, canvas, TePOLYGONS, box);
    01408                       tableName = layer->tableName(TePOLYGONS);
    01409
    01410                       string queryPolygons;
    01411                       if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryPolygons  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    01412                       else                                                                                                                     queryPolygons  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    01413                       queryPolygons += " FROM " + tableName + ", " + theme->collectionTable();
    01414                       queryPolygons += " WHERE object_id = c_object_id";
    01415                       if(wherebox.empty() == false)
    01416                                  queryPolygons += " AND " + wherebox;
    01417
    01418                       queryPolygons += " ORDER BY " + db->getSQLOrderBy(TePOLYGONS);
    01419
    01420                       //Calculate the number of polygons to be drawn
    01421                       string selectPolyCount;
    01422                       if(db->dbmsName()=="SqlServerAdo")
    01423                                  selectPolyCount="SELECT COUNT(DISTINCT(parent_id)) FROM ";
    01424                       else if(db->dbmsName() != "OracleSpatial" && db->dbmsName() != "PostGIS" && db->dbmsName() !="SqlServerAdoSpatial")
    01425                                  selectPolyCount = "SELECT DISTINCT parent_id FROM ";
    01426                       else
    01427                                  selectPolyCount = "SELECT DISTINCT object_id FROM ";
    01428
    01429                       selectPolyCount += tableName + ", " + theme->collectionTable() + " WHERE c_object_id = object_id";
    01430                       if(wherebox.empty() == false)
    01431                                  selectPolyCount += " AND " + wherebox;
    01432
    01433                       string polyCount;
    01434                       if(db->dbmsName() =="SqlServerAdo" || db->dbmsName() == "SqlServerAdoSpatial")
    01435                                  polyCount=selectPolyCount;
    01436                       else if(db->dbmsName() == "PostgreSQL" || db->dbmsName() == "PostGIS")
    01437                                  polyCount = "SELECT COUNT(*) FROM (" + selectPolyCount + ") AS r";
    01438                       else if(db->dbmsName() == "MySQL")
    01439                       {
    01440                                  string createTempTable = "CREATE TEMPORARY TABLE count_table " + selectPolyCount;
    01441                                  db->execute(createTempTable);
    01442                                  polyCount = "SELECT COUNT(*) FROM count_table";
    01443                       }
    01444                       else
    01445                                  polyCount = "SELECT COUNT(*) FROM (" + selectPolyCount + ")";
    01446
    01447                       if (portal->query(polyCount))
    01448                       {
    01449                                  if (portal->fetchRow())
    01450                                             nSteps = atoi(portal->getData(0));
    01451                       }
    01452                       else
    01453                       {
    01454                                  delete portal;
    01455                                  return;
    01456                       }
    01457
    01458                       if (db->dbmsName() == "MySQL")
    01459                                  db->execute("DROP TABLE count_table");
    01460
    01461                       portal->freeResult();
    01462
    01463                       //Plot the polygons whose number was placed in nSteps
    01464                       if(db->dbmsName() == "PostgreSQL" || db->dbmsName() == "PostGIS")
    01465                       {
    01466                                   if(portal->query(queryPolygons, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    01467                                   {
    01468                                             delete portal;
    01469                                             return;
    01470                                   }
    01471                       }
    01472                       else
    01473                       {
    01474                                  if (portal->query(queryPolygons) == false)
    01475                                  {
    01476                                             delete portal;
    01477                                             return;
    01478                                  }
    01479                       }
    01480
    01481                       int        groPos = portal->getAttributeList().size() - 3;
    01482                       int        ownPos = portal->getAttributeList().size() - 2;
    01483                       int        resPos = portal->getAttributeList().size() - 1;
    01484
    01485                       if(progress != NULL)
    01486                       {
    01487                                  progress->setTotalSteps(nSteps);
    01488                       }
    01489                       t2 = clock();
    01490                       t0 = t1 = t2;
    01491                       if(portal->fetchRow())
    01492                       {
    01493                                  bool flag;
    01494                                  flag = true;
    01495                                  do
    01496                                  {
    01497                                             int geomId = atoi(portal->getData(0));
    01498                                             TePolygon poly;
    01499                                             if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01500                                                        visual = getVisual(portal, appTheme, TePOLYGONS, resPos, groPos, ownPos);
    01501                                             else
    01502                                             {
    01503                                                        string objId = portal->getData(1);
    01504                                                        visual = getVisualRemote(portal, appTheme, TePOLYGONS, objId);
    01505                                             }
    01506
    01507                                             color = visual.color();
    01508                                             canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    01509                                             canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    01510                                             color = visual.contourColor();
    01511                                             canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    01512                                             canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    01513                                             if(box.isValid())
    01514                                                        canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    01515                                             if(it == layerRepMap.end())
    01516                                             {
    01517                                                        flag = portal->fetchGeometry(poly);
    01518                                                        canvas->plotPolygon(poly);
    01519                                             }
    01520                                             else
    01521                                             {
    01522                                                        canvas->plotPolygon(layerRepMap[layer->id()].polygonMap_[geomId]);
    01523                                                        int parent_id = atoi(portal->getData(4));
    01524                                                        int parent = parent_id;
    01525                                                        while(parent == parent_id)
    01526                                                        {
    01527                                                                   flag = portal->fetchRow();
    01528                                                                   if(flag)
    01529                                                                              parent = atoi(portal->getData(4));
    01530                                                                   else
    01531                                                                              parent = -1;
    01532                                                        }
    01533                                             }
    01534                                             t2 = clock();
    01535                                             nLoops++;
    01536                                             if (int(t2-t1) > dt)
    01537                                             {
    01538                                                        t1 = t2;
    01539                                                        canvas->copyPixmapToWindow();
    01540                                                        if(progress != NULL)
    01541                                                        {
    01542                                                                   if(progress->wasCancelled())
    01543                                                                   {
    01544                                                                              progress->reset();
    01545                                                                              break;
    01546                                                                   }
    01547                                                                   if((int)(t2-t0) > dt2)
    01548                                                                              progress->setProgress(nLoops);
    01549                                                        }
    01550                                             }
    01551                                  }
    01552                                  while (flag);
    01553                       }
    01554                       if(progress != NULL)
    01555                       {
    01556                                  progress->reset();
    01557                       }
    01558            }
    01559
    01560            if(box.isValid())
    01561                       canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    01562            if(layer->hasGeometry(TeCELLS) && (appTheme->getTheme()->visibleRep() & TeCELLS))
    01563            {
    01564                       nLoops = 0;
    01565                       // query the database table containing the polygons� geometry
    01566                       string wherebox = getWhereBox(portal, appTheme, canvas, TeCELLS, box);
    01567                       tableName = layer->tableName(TeCELLS);
    01568
    01569                       string queryCells;
    01570                       if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryCells  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    01571                       else                                                                                                                     queryCells  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    01572                       queryCells += " FROM " + tableName + ", " + theme->collectionTable();
    01573                       queryCells += " WHERE object_id = c_object_id";
    01574                       if(wherebox.empty() == false)
    01575                                  queryCells += " AND " + wherebox;
    01576
    01577                       string cellsCount = "SELECT COUNT(*) FROM " + tableName + ", " + theme->collectionTable();
    01578                       cellsCount += " WHERE object_id = c_object_id";
    01579                       if(wherebox.empty() == false)
    01580                                  cellsCount += " AND " + wherebox;
    01581
    01582                       portal->freeResult();
    01583                       if (portal->query(cellsCount))
    01584                       {
    01585                                  if (portal->fetchRow())
    01586                                             nSteps = atoi(portal->getData(0));
    01587                       }
    01588                       else
    01589                       {
    01590                                  delete portal;
    01591                                  return;
    01592                       }
    01593
    01594                       portal->freeResult();
    01595                       if (portal->query(queryCells, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    01596                       {
    01597                                  delete portal;
    01598                                  return;
    01599                       }
    01600                       int        groPos = portal->getAttributeList().size() - 3;
    01601                       int        ownPos = portal->getAttributeList().size() - 2;
    01602                       int        resPos = portal->getAttributeList().size() - 1;
    01603
    01604                       if(progress != NULL)
    01605                       {
    01606                                  progress->setTotalSteps(nSteps);
    01607                       }
    01608                       t2 = clock();
    01609                       t0 = t1 = t2;
    01610                       if(portal->fetchRow())
    01611                       {
    01612                                  bool flag;
    01613                                  flag = true;
    01614                                  do
    01615                                  {
    01616                                             TeCell cell;
    01617
    01618                                             if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01619                                                        visual = getVisual(portal, appTheme, TePOLYGONS, resPos, groPos, ownPos);
    01620                                             else
    01621                                             {
    01622                                                        string objId = portal->getData(1);
    01623                                                        visual = getVisualRemote(portal, appTheme, TePOLYGONS, objId);
    01624                                             }
    01625
    01626                                             color = visual.color();
    01627                                             canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    01628                                             canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    01629                                             color = visual.contourColor();
    01630                                             canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    01631                                             canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    01632                                             flag = portal->fetchGeometry(cell);
    01633                                             canvas->plotCell(cell);
    01634                                             t2 = clock();
    01635                                             nLoops++;
    01636                                             if (int(t2-t1) > dt)
    01637                                             {
    01638                                                        t1 = t2;
    01639                                                        canvas->copyPixmapToWindow();
    01640
    01641                                                        if(progress != NULL)
    01642                                                        {
    01643                                                                   if(progress->wasCancelled())
    01644                                                                   {
    01645                                                                              progress->reset();
    01646                                                                              break;
    01647                                                                   }
    01648                                                                   if((int)(t2-t0) > dt2)
    01649                                                                              progress->setProgress(nLoops);
    01650                                                        }
    01651                                             }
    01652                                  }
    01653                                  while (flag);
    01654                       }
    01655                       if(progress != NULL)
    01656                       {
    01657                                  progress->reset();
    01658                       }
    01659            }
    01660
    01661            if (layer->hasGeometry(TeLINES) && (appTheme->getTheme()->visibleRep() & TeLINES))
    01662            {
    01663                       nLoops = 0;
    01664                       string wherebox = getWhereBox(portal, appTheme, canvas, TeLINES, box);
    01665                       // query the database table containing the lines� geometry
    01666                       tableName = layer->tableName(TeLINES);
    01667
    01668                       string queryLines;
    01669                       if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryLines  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    01670                       else                                                                                                                     queryLines  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    01671                       queryLines += " FROM " + tableName + ", " + theme->collectionTable();
    01672                       queryLines += " WHERE object_id = c_object_id";
    01673                       if(wherebox.empty() == false)
    01674                                  queryLines += " AND " + wherebox;
    01675
    01676                       string linesCount = "SELECT COUNT(*) FROM " + tableName + ", " + theme->collectionTable();
    01677                       linesCount += " WHERE object_id = c_object_id";
    01678                       if(wherebox.empty() == false)
    01679                                  linesCount += " AND " + wherebox;
    01680
    01681                       portal->freeResult();
    01682                       if (portal->query(linesCount))
    01683                       {
    01684                                  if (portal->fetchRow())
    01685                                             nSteps = atoi(portal->getData(0));
    01686                       }
    01687                       else
    01688                       {
    01689                                  delete portal;
    01690                                  return;
    01691                       }
    01692
    01693                       portal->freeResult();
    01694                       if (portal->query(queryLines, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    01695                       {
    01696                                  delete portal;
    01697                                  return;
    01698                       }
    01699                       int        groPos = portal->getAttributeList().size() - 3;
    01700                       int        ownPos = portal->getAttributeList().size() - 2;
    01701                       int        resPos = portal->getAttributeList().size() - 1;
    01702
    01703                       if(progress != NULL)
    01704                       {
    01705                                  progress->setTotalSteps(nSteps);
    01706                       }
    01707
    01708                       t2 = clock();
    01709                       t0 = t1 = t2;
    01710                       if(portal->fetchRow())
    01711                       {
    01712                                  bool flag = true;
    01713                                  do
    01714                                  {
    01715                                             int geomId = atoi(portal->getData(0));
    01716                                             TeLine2D line;
    01717                                             if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01718                                                        visual = getVisual(portal, appTheme, TeLINES, resPos, groPos, ownPos);
    01719                                             else
    01720                                             {
    01721                                                        string objId = portal->getData(1);
    01722                                                        visual = getVisualRemote(portal, appTheme, TeLINES, objId);
    01723                                             }
    01724                                             color = visual.color();
    01725                                             canvas->setLineColor(color.red_, color.green_, color.blue_);
    01726                                             canvas->setLineStyle((int)visual.style(),visual.width());
    01727                                             if(it == layerRepMap.end())
    01728                                             {
    01729                                                        flag = portal->fetchGeometry(line);
    01730                                                        canvas->plotLine(line);
    01731                                             }
    01732                                             else
    01733                                             {
    01734                                                        canvas->plotLine(layerRepMap[layer->id()].lineMap_[geomId]);
    01735                                                        flag = portal->fetchRow();
    01736                                             }
    01737                                             t2 = clock();
    01738                                             if (int(t2-t1) > dt)
    01739                                             {
    01740                                                        t1 = t2;
    01741                                                        canvas->copyPixmapToWindow();
    01742
    01743                                                        if(progress != NULL)
    01744                                                        {
    01745                                                                   if(progress->wasCancelled())
    01746                                                                   {
    01747                                                                              progress->reset();
    01748                                                                              break;
    01749                                                                   }
    01750                                                                   if((int)(t2-t0) > dt2)
    01751                                                                              progress->setProgress(int(t2));
    01752                                                        }
    01753                                             }
    01754                                  }
    01755                                  while (flag);
    01756                       }
    01757                       if(progress != NULL)
    01758                       {
    01759                                  progress->reset();
    01760                       }
    01761            }
    01762
    01763            if (layer->hasGeometry(TePOINTS) && (appTheme->getTheme()->visibleRep() & TePOINTS))
    01764            {
    01765                       nLoops = 0;
    01766                       string wherebox = getWhereBox(portal, appTheme, canvas, TePOINTS, box);
    01767                       // query the database table containing the points� geometry
    01768                       tableName = layer->tableName(TePOINTS);
    01769
    01770                       string queryPoints;
    01771                       if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryPoints  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    01772                       else                                                                                                                     queryPoints  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    01773                       queryPoints += " FROM " + tableName + ", " + theme->collectionTable();
    01774                       queryPoints += " WHERE object_id = c_object_id";
    01775                       if(wherebox.empty() == false)
    01776                                  queryPoints += " AND " + wherebox;
    01777
    01778                       string pointsCount = "SELECT COUNT(*) FROM " + tableName + ", " + theme->collectionTable();
    01779                       pointsCount += " WHERE object_id = c_object_id";
    01780                       if(wherebox.empty() == false)
    01781                                  pointsCount += " AND " + wherebox;
    01782
    01783                       portal->freeResult();
    01784                       if (portal->query(pointsCount))
    01785                       {
    01786                                  if (portal->fetchRow())
    01787                                             nSteps = atoi(portal->getData(0));
    01788                       }
    01789                       else
    01790                       {
    01791                                  delete portal;
    01792                                  return;
    01793                       }
    01794
    01795                       portal->freeResult();
    01796                       if (portal->query(queryPoints, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    01797                       {
    01798                                  delete portal;
    01799                                  return;
    01800                       }
    01801                       int        groPos = portal->getAttributeList().size() - 3;
    01802                       int        ownPos = portal->getAttributeList().size() - 2;
    01803                       int        resPos = portal->getAttributeList().size() - 1;
    01804
    01805                       if(progress != NULL)
    01806                       {
    01807                                  progress->setTotalSteps(nSteps);
    01808                       }
    01809                       t2 = clock();
    01810                       t0 = t1 = t2;
    01811                       if(portal->fetchRow())
    01812                       {
    01813                                  bool flag = true;
    01814                                  do
    01815                                  {
    01816                                             TePoint point;
    01817                                             if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01818                                                        visual = getVisual(portal, appTheme, TePOINTS, resPos, groPos, ownPos);
    01819                                             else
    01820                                             {
    01821                                                        string objId = portal->getData(1);
    01822                                                        visual = getVisualRemote(portal, appTheme, TePOINTS, objId);
    01823                                             }
    01824                                             color = visual.color();
    01825                                             canvas->setPointColor(color.red_, color.green_, color.blue_);
    01826                                             canvas->setPointStyle((int)visual.style(),visual.size());
    01827                                             flag = portal->fetchGeometry(point);
    01828                                             canvas->plotPoint(point);
    01829                                             t2 = clock();
    01830                                             if (int(t2-t1) > dt)
    01831                                             {
    01832                                                        t1 = t2;
    01833                                                        canvas->copyPixmapToWindow();
    01834                                                        if(progress != NULL)
    01835                                                        {
    01836                                                                   if(progress->wasCancelled())
    01837                                                                   {
    01838                                                                              progress->reset();
    01839                                                                              break;
    01840                                                                   }
    01841                                                                   if((int)(t2-t0) > dt2)
    01842                                                                              progress->setProgress(int(t2));
    01843                                                        }
    01844                                             }
    01845                                  }
    01846                                  while (flag);
    01847                       }
    01848                       if(progress != NULL)
    01849                       {
    01850                                  progress->reset();
    01851                       }
    01852            }
    01853            delete portal;
    01854
    01855            if(box.isValid())
    01856                       canvas->setClipping(false);
    01857 }
    01858
    01859
    01860
    01861 template<class Canvas , class Progress>
    01862 TeBox TePlotSelectedObjects(TeAppTheme* appTheme, Canvas *canvas, set<string>& drawSet, map<int, RepMap>& layerRepMap, Progress * /* progress */ = 0, TeGeomRepVisualMap* visualMap = 0)
    01863 {
    01864            TeBox      boxRet;
    01865            int i, nLoops;
    01866            int dt = CLOCKS_PER_SEC/4;
    01867            clock_t    t0, t1, t2;
    01868            vector<string> inClauseVector;
    01869
    01870            if(        appTheme->getTheme()->getProductId() != TeTHEME &&
    01871                       appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01872                       return boxRet;
    01873
    01874            TeTheme* theme = appTheme->getSourceTheme();
    01875            if (theme == 0)
    01876                       return boxRet;
    01877            TeLayer* layer = theme->layer();
    01878
    01879            if(theme->minScale() != 0 && theme->maxScale() != 0 && theme->minScale() > theme->maxScale())
    01880            {
    01881                       if(theme->minScale() < canvas->scaleApx() || theme->maxScale() > canvas->scaleApx())
    01882                                  return boxRet;
    01883            }
    01884
    01885            TeDatabase *db = layer->database();
    01886            TeDatabasePortal *portal = db->getPortal();
    01887            canvas->setDataProjection (layer->projection());
    01888            string TC = theme->collectionTable();
    01889
    01890            string tableName, objectId;
    01891            TeColor color;
    01892            TeVisual   visual;
    01893
    01894            set<string>::iterator itB = drawSet.begin();
    01895            set<string>::iterator itE = drawSet.end();
    01896            inClauseVector = generateInClauses(itB,itE, db);
    01897
    01898            if (layer->hasGeometry(TePOLYGONS) && (appTheme->getTheme()->visibleRep() & TePOLYGONS))
    01899            {
    01900                       map<int, RepMap>::iterator it = layerRepMap.find(layer->id());
    01901 //                    nLoops = 0;
    01902 //                    progress->setTotalSteps(drawSet.size());
    01903                       t2 = clock();
    01904                       t0 = t1 = t2;
    01905
    01906                       bool hasVisual = false;
    01907
    01908                       if(visualMap)
    01909                                  hasVisual = (visualMap->find(TePOLYGONS) != visualMap->end());
    01910
    01911                       TeVisual* visualPol;
    01912
    01913                       if(hasVisual)
    01914                                  visualPol = (*visualMap)[TePOLYGONS];
    01915
    01916
    01917                       for (i = 0; i < (int)inClauseVector.size(); ++i)
    01918                       {
    01919                                  // query the database table containing the polygons� geometry
    01920                                  tableName = layer->tableName(TePOLYGONS);
    01921                                  string queryPolygons;
    01922                                  if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryPolygons  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    01923                                  else                                                                                                                     queryPolygons  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    01924                                  queryPolygons += " FROM " + tableName + ", " + theme->collectionTable();
    01925                                  queryPolygons += " WHERE object_id = c_object_id AND object_id IN " + inClauseVector[i];
    01926
    01927                                  queryPolygons += " ORDER BY " + db->getSQLOrderBy(TePOLYGONS);
    01928
    01929                                  portal->freeResult();
    01930                                  if (portal->query(queryPolygons, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    01931                                  {
    01932                                             delete portal;
    01933                                             return boxRet;
    01934                                  }
    01935                                  int        groPos = portal->getAttributeList().size() - 3;
    01936                                  int        ownPos = portal->getAttributeList().size() - 2;
    01937                                  int        resPos = portal->getAttributeList().size() - 1;
    01938
    01939                                  if(portal->fetchRow())
    01940                                  {
    01941                                             bool flag = true;
    01942                                             do
    01943                                             {
    01944                                                        TePolygon poly;
    01945
    01946                                                        if(hasVisual)
    01947                                                        {
    01948                                                                   color = visualPol->color();
    01949                                                                   canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    01950                                                                   canvas->setPolygonStyle((int)visualPol->style(),visualPol->transparency());
    01951                                                                   color = visualPol->contourColor();
    01952                                                                   canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    01953                                                                   canvas->setPolygonLineStyle((int)visualPol->contourStyle(),visualPol->contourWidth());
    01954                                                        }
    01955                                                        else
    01956                                                        {
    01957                                                                   if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    01958                                                                              visual = getVisual(portal, appTheme, TePOLYGONS, resPos, groPos, ownPos);
    01959                                                                   else
    01960                                                                   {
    01961                                                                              string objId = portal->getData(1);
    01962                                                                              visual = getVisualRemote(portal, appTheme, TePOLYGONS, objId);
    01963                                                                   }
    01964
    01965                                                                   color = visual.color();
    01966                                                                   canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    01967                                                                   canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    01968                                                                   color = visual.contourColor();
    01969                                                                   canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    01970                                                                   canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    01971                                                        }
    01972
    01973                                                        if(it == layerRepMap.end())
    01974                                                        {
    01975                                                                   flag = portal->fetchGeometry(poly);
    01976                                                                   boxRet = TeUnion(boxRet, poly.box());
    01977                                                                   canvas->plotPolygon(poly, true);
    01978                                                        }
    01979                                                        else
    01980                                                        {
    01981                                                                   int geomId = atoi(portal->getData(0));
    01982                                                                   int parent_id = atoi(portal->getData(4));
    01983                                                                   int parent = parent_id;
    01984                                                                   while(parent == parent_id)
    01985                                                                   {
    01986                                                                              flag = portal->fetchRow();
    01987                                                                              if(flag)
    01988                                                                                         parent = atoi(portal->getData(4));
    01989                                                                              else
    01990                                                                                         parent = -1;
    01991                                                                   }
    01992                                                                   boxRet = TeUnion(boxRet, layerRepMap[layer->id()].polygonMap_[geomId].box());
    01993                                                                   canvas->plotPolygon(layerRepMap[layer->id()].polygonMap_[geomId], true);
    01994                                                        }
    01995                                                        t2 = clock();
    01996 //                                                     nLoops++;
    01997                                                        if (int(t2-t1) > dt)
    01998                                                        {
    01999                                                                   t1 = t2;
    02000                                                                   canvas->copyPixmap1ToWindow();
    02001 //                                                                if(progress->wasCancelled())
    02002 //                                                                           break;
    02003 //                                                                progress->setProgress(nLoops);
    02004                                                        }
    02005                                             }
    02006                                             while (flag);
    02007                                  }
    02008                       }
    02009 //                    progress->reset();
    02010            }
    02011
    02012            if (layer->hasGeometry(TeCELLS) && (appTheme->getTheme()->visibleRep() & TeCELLS))
    02013            {
    02014 //                    nLoops = 0;
    02015 //                    progress->setTotalSteps(drawSet.size());
    02016                       t2 = clock();
    02017                       t0 = t1 = t2;
    02018
    02019                       bool hasVisual = false;
    02020
    02021                       if(visualMap)
    02022                                  hasVisual = (visualMap->find(TeCELLS) != visualMap->end());
    02023
    02024                       TeVisual* visualCell;
    02025
    02026                       if(hasVisual)
    02027                                  visualCell = (*visualMap)[TeCELLS];
    02028
    02029
    02030                       for (i = 0; i < (int)inClauseVector.size(); ++i)
    02031                       {
    02032                                  // query the database table containing the lines� geometry
    02033                                  tableName = layer->tableName(TeCELLS);
    02034                                  string queryCells;
    02035                                  if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryCells  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    02036                                  else                                                                                                                     queryCells  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    02037                                  queryCells += " FROM " + tableName + ", " + theme->collectionTable();
    02038                                  queryCells += " WHERE object_id = c_object_id AND object_id IN " + inClauseVector[i];
    02039
    02040                                  portal->freeResult();
    02041                                  if (portal->query(queryCells, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02042                                  {
    02043                                             delete portal;
    02044                                             return boxRet;
    02045                                  }
    02046
    02047                                  int        groPos = portal->getAttributeList().size() - 3;
    02048                                  int        ownPos = portal->getAttributeList().size() - 2;
    02049                                  int        resPos = portal->getAttributeList().size() - 1;
    02050
    02051                                  if(portal->fetchRow())
    02052                                  {
    02053                                             bool flag = true;
    02054                                             do
    02055                                             {
    02056                                                        TeCell cell;
    02057
    02058                                                        if(hasVisual)
    02059                                                        {
    02060                                                                   color = visualCell->color();
    02061                                                                   canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    02062                                                                   canvas->setPolygonStyle((int)visualCell->style(),visualCell->transparency());
    02063                                                                   color = visualCell->contourColor();
    02064                                                                   canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    02065                                                                   canvas->setPolygonLineStyle((int)visualCell->contourStyle(),visualCell->contourWidth());
    02066                                                        }
    02067                                                        else
    02068                                                        {
    02069
    02070                                                                   if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    02071                                                                              visual = getVisual(portal, appTheme, TePOLYGONS, resPos, groPos, ownPos);
    02072                                                                   else
    02073                                                                   {
    02074                                                                              string objId = portal->getData(1);
    02075                                                                              visual = getVisualRemote(portal, appTheme, TePOLYGONS, objId);
    02076                                                                   }
    02077                                                                   color = visual.color();
    02078                                                                   canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    02079                                                                   canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    02080                                                                   color = visual.contourColor();
    02081                                                                   canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    02082                                                                   canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    02083                                                        }
    02084
    02085                                                        flag = portal->fetchGeometry(cell);
    02086                                                        boxRet = TeUnion(boxRet, cell.box());
    02087                                                        canvas->plotCell(cell, true);
    02088                                                        t2 = clock();
    02089 //                                                     nLoops++;
    02090                                                        if (int(t2-t1) > dt)
    02091                                                        {
    02092                                                                   t1 = t2;
    02093                                                                   canvas->copyPixmap1ToWindow();
    02094 //                                                                if(progress->wasCancelled())
    02095 //                                                                           break;
    02096 //                                                                progress->setProgress(nLoops);
    02097                                                        }
    02098                                             }
    02099                                             while (flag);
    02100                                  }
    02101                       }
    02102 //                    progress->reset();
    02103            }
    02104
    02105            if (layer->hasGeometry(TeLINES) && (appTheme->getTheme()->visibleRep() & TeLINES))
    02106            {
    02107 //                    nLoops = 0;
    02108 //                    progress->setTotalSteps(drawSet.size());
    02109                       t2 = clock();
    02110                       t0 = t1 = t2;
    02111
    02112                       bool hasVisual = false;
    02113
    02114                       if(visualMap)
    02115                                  hasVisual = (visualMap->find(TeLINES) != visualMap->end());
    02116
    02117                       TeVisual* visualLin;
    02118
    02119                       if(hasVisual)
    02120                                  visualLin = (*visualMap)[TeLINES];
    02121
    02122
    02123                       for (i = 0; i < (int)inClauseVector.size(); ++i)
    02124                       {
    02125                                  // query the database table containing the lines� geometry
    02126                                  tableName = layer->tableName(TeLINES);
    02127                                  string queryLines;
    02128                                  if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryLines  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    02129                                  else                                                                                                                     queryLines  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    02130                                  queryLines += " FROM " + tableName + ", " + theme->collectionTable();
    02131                                  queryLines += " WHERE object_id = c_object_id AND object_id IN " + inClauseVector[i];
    02132
    02133                                  portal->freeResult();
    02134                                  if (portal->query(queryLines, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02135                                  {
    02136                                             delete portal;
    02137                                             return boxRet;
    02138                                  }
    02139                                  int        groPos = portal->getAttributeList().size() - 3;
    02140                                  int        ownPos = portal->getAttributeList().size() - 2;
    02141                                  int        resPos = portal->getAttributeList().size() - 1;
    02142
    02143                                  if(portal->fetchRow())
    02144                                  {
    02145                                             bool flag = true;
    02146                                             do
    02147                                             {
    02148                                                        TeLine2D line;
    02149
    02150                                                        if(hasVisual)
    02151                                                        {
    02152                                                                   color = visualLin->color();
    02153                                                                   canvas->setLineColor(color.red_, color.green_, color.blue_);
    02154                                                                   canvas->setLineStyle((int)visualLin->style(),visualLin->width());
    02155                                                        }
    02156                                                        else
    02157                                                        {
    02158                                                                   if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    02159                                                                              visual = getVisual(portal, appTheme, TeLINES, resPos, groPos, ownPos);
    02160                                                                   else
    02161                                                                   {
    02162                                                                              string objId = portal->getData(1);
    02163                                                                              visual = getVisualRemote(portal, appTheme, TeLINES, objId);
    02164                                                                   }
    02165                                                                   color = visual.color();
    02166                                                                   canvas->setLineColor(color.red_, color.green_, color.blue_);
    02167                                                                   canvas->setLineStyle((int)visual.style(),visual.width());
    02168                                                        }
    02169
    02170                                                        flag = portal->fetchGeometry(line);
    02171                                                        boxRet = TeUnion(boxRet, line.box());
    02172                                                        canvas->plotLine(line);
    02173                                                        t2 = clock();
    02174 //                                                     nLoops++;
    02175                                                        if (int(t2-t1) > dt)
    02176                                                        {
    02177                                                                   t1 = t2;
    02178                                                                   canvas->copyPixmap1ToWindow();
    02179 //                                                                if(progress->wasCancelled())
    02180 //                                                                           break;
    02181 //                                                                progress->setProgress(nLoops);
    02182                                                        }
    02183                                             }
    02184                                             while (flag);
    02185                                  }
    02186                       }
    02187 //                    progress->reset();
    02188            }
    02189
    02190            if (layer->hasGeometry(TePOINTS) && (appTheme->getTheme()->visibleRep() & TePOINTS))
    02191            {
    02192                       nLoops = 0;
    02193 //                    progress->setTotalSteps(drawSet.size());
    02194                       t2 = clock();
    02195                       t0 = t1 = t2;
    02196
    02197                       bool hasVisual = false;
    02198
    02199                       if(visualMap)
    02200                                  hasVisual = (visualMap->find(TePOINTS) != visualMap->end());
    02201
    02202                       TeVisual* visualPt;
    02203
    02204                       if(hasVisual)
    02205                                  visualPt = (*visualMap)[TePOINTS];
    02206
    02207
    02208
    02209                       for (i = 0; i < (int)inClauseVector.size(); ++i)
    02210                       {
    02211                                  // query the database table containing the points� geometry
    02212                                  tableName = layer->tableName(TePOINTS);
    02213                                  string queryLines;
    02214                                  if ( db->dbmsName() == "SqlServerAdoSpatial" )         queryLines  = "SELECT geom_id, object_id, spatial_data.STAsBinary() as spatial_data, c_legend_id, c_legend_own, c_object_status";
    02215                                  else                                                                                                                     queryLines  = "SELECT " + tableName + ".*, c_legend_id, c_legend_own, c_object_status";
    02216                                  queryLines += " FROM " + tableName + ", " + theme->collectionTable();
    02217                                  queryLines += " WHERE object_id = c_object_id AND object_id IN " + inClauseVector[i];
    02218
    02219                                  portal->freeResult();
    02220                                  if (portal->query(queryLines, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02221                                  {
    02222                                             delete portal;
    02223                                             return boxRet;
    02224                                  }
    02225                                  int        groPos = portal->getAttributeList().size() - 3;
    02226                                  int        ownPos = portal->getAttributeList().size() - 2;
    02227                                  int        resPos = portal->getAttributeList().size() - 1;
    02228
    02229                                  if(portal->fetchRow())
    02230                                  {
    02231                                             bool flag = true;
    02232                                             do
    02233                                             {
    02234                                                        TePoint point;
    02235
    02236                                                        if(hasVisual)
    02237                                                        {
    02238                                                                   color = visualPt->color();
    02239                                                                   canvas->setPointColor(color.red_, color.green_, color.blue_);
    02240                                                                   canvas->setPointStyle((int)visualPt->style(),visualPt->size());
    02241                                                        }
    02242                                                        else
    02243                                                        {
    02244                                                                   if(appTheme->getTheme()->getProductId() != TeEXTERNALTHEME)
    02245                                                                              visual = getVisual(portal, appTheme, TePOINTS, resPos, groPos, ownPos);
    02246                                                                   else
    02247                                                                   {
    02248                                                                              string objId = portal->getData(1);
    02249                                                                              visual = getVisualRemote(portal, appTheme, TePOINTS, objId);
    02250                                                                   }
    02251                                                                   color = visual.color();
    02252                                                                   canvas->setPointColor(color.red_, color.green_, color.blue_);
    02253                                                                   canvas->setPointStyle((int)visual.style(),visual.size());
    02254                                                        }
    02255
    02256                                                        flag = portal->fetchGeometry(point);
    02257                                                        double dw = canvas->mapVtoCW(visual.size());
    02258                                                        TeCoord2D p = point.location();
    02259                                                        TeBox b(p.x()-dw, p.y()-dw, p.x()+dw, p.y()+dw);
    02260                                                        boxRet = TeUnion(boxRet, b);
    02261                                                        canvas->plotPoint(point);
    02262                                                        t2 = clock();
    02263                                                        nLoops++;
    02264                                                        if (int(t2-t1) > dt)
    02265                                                        {
    02266                                                                   t1 = t2;
    02267                                                                   canvas->copyPixmap1ToWindow();
    02268 //                                                                if(progress->wasCancelled())
    02269 //                                                                           break;
    02270 //                                                                progress->setProgress(nLoops);
    02271                                                        }
    02272                                             }
    02273                                             while (flag);
    02274                                  }
    02275                       }
    02276 //                    progress->reset();
    02277            }
    02278            delete portal;
    02279            return boxRet;
    02280 }
    02281
    02282 template<class Canvas>
    02283 bool objBoxInCanvas(TeAppTheme* appTheme, Canvas *canvas, set<string>& drawSet, TeGeomRep repType, TeBox& bout, double tol)
    02284 {
    02285            //calculate the box that contains all the objects in objectIdSet.
    02286            //If this box is inside the canvas box, return true to indicate that
    02287            //is enough to paint the objects selected. If this box is not inside
    02288            //the canvas box, center this box in the canvas, and return false
    02289            //to indicate that a plot in the whole canvas area is necessary.
    02290
    02291            TeTheme* theme = (TeTheme*)appTheme->getTheme();
    02292            TeLayer *layer = theme->layer();
    02293            TeDatabase *db = layer->database();
    02294            TeDatabasePortal *portal = db->getPortal();
    02295
    02296            string tableName;
    02297            TeGeomRep rep;
    02298            if (repType & TePOLYGONS)
    02299            {
    02300                       tableName = theme->layer()->tableName(TePOLYGONS);
    02301                       rep = TePOLYGONS;
    02302            }
    02303            else if (repType & TeLINES)
    02304            {
    02305                       tableName = theme->layer()->tableName(TeLINES);
    02306                       rep = TeLINES;
    02307            }
    02308            else if (repType & TePOINTS)
    02309            {
    02310                       tableName = theme->layer()->tableName(TePOINTS);
    02311                       rep = TePOINTS;
    02312            }
    02313            else if (repType & TeCELLS)
    02314            {
    02315         tableName = theme->layer()->tableName(TeCELLS);
    02316                       rep = TeCELLS;
    02317            }
    02318
    02319            set<string>::iterator it, beginIt;
    02320            int i, chunk = 200, size = drawSet.size();
    02321            string inClause, plic, fields, queryString;
    02322
    02323            beginIt = drawSet.begin();
    02324            while (size > 0)
    02325            {
    02326                       portal->freeResult();
    02327                       inClause = "(";
    02328                       plic = "'";
    02329                       i = 0;
    02330                       for (it = beginIt; it != drawSet.end(); ++it)
    02331                       {
    02332                                  if (i >= chunk)
    02333                                             break;
    02334                                  inClause += plic + *it + "',";
    02335                                  ++i;
    02336                       }
    02337                       inClause[inClause.size() - 1] = ')';
    02338                       beginIt = it;
    02339                       size -= chunk;
    02340
    02341                       if((repType & TePOLYGONS) || (repType & TeLINES) || (repType & TeCELLS))
    02342                       {
    02343                                  string where = " object_id IN " + inClause;
    02344                                  string from = " " + tableName;
    02345
    02346                                  TeBox ibox;
    02347
    02348                                  db->getMBRSelectedObjects(tableName, "spatial_data", from, where, "", rep, ibox, tol);
    02349
    02350                                  updateBox(bout, ibox);
    02351                       }
    02352                       else if(repType & TePOINTS)
    02353                       {
    02354                                  string where = " object_id IN " + inClause;
    02355                                  string from = " " + tableName;
    02356
    02357                                  TeBox ibox;
    02358
    02359                                  db->getMBRSelectedObjects(tableName, "spatial_data", from, where, "", rep, ibox, tol);
    02360
    02361                                  double x = ibox.x1();
    02362                                  double y = ibox.y1();
    02363
    02364                                  ibox.x1_ = x - tol;
    02365                                  ibox.y1_ = y - tol;
    02366                                  ibox.x2_ = x + tol;
    02367                                  ibox.y2_ = y + tol;
    02368
    02369                                  updateBox(bout, ibox);
    02370                       }
    02371            }
    02372
    02373            TeBox cbox = canvas->getDataWorld();
    02374            if(TeWithin(bout, cbox) == true)
    02375            {
    02376                       delete portal;
    02377                       return true;
    02378            }
    02379
    02380            //box of the objects selected is not inside the canvas box
    02381            if(bout.width() < cbox.width())
    02382            {
    02383                       double w = cbox.width();
    02384                       double tw = bout.width();
    02385                       double dw = (w - tw) / 2.;
    02386                       bout.x1_ = bout.x1_ - dw;
    02387                       bout.x2_ = bout.x2_ + dw;
    02388            }
    02389
    02390            if(bout.height() < cbox.height())
    02391            {
    02392                       double h = cbox.height();
    02393                       double th = bout.height();
    02394                       double dh = (h - th) / 2.;
    02395                       bout.y1_ = bout.y1_ - dh;
    02396                       bout.y2_ = bout.y2_ + dh;
    02397            }
    02398
    02399            delete portal;
    02400
    02401            // layer to canvas projection
    02402            bout = TeRemapBox(bout, theme->layer()->projection(), canvas->projection());
    02403            return false;
    02404 }
    02405
    02406
    02407 template<class Canvas>
    02408 void TePlotFrame(TeAppTheme* appTheme, Canvas* canvas, map<int, RepMap>& layerRepMap, map<string, TeGeomRepVisualMap*>& objVisualMap)
    02409 {
    02410            string tableName, objectId;
    02411            TeColor color;
    02412            TeVisual visual;
    02413
    02414            TeTheme* theme = (TeTheme*)appTheme->getTheme();
    02415
    02416            if(theme->minScale() != 0 && theme->maxScale() != 0 && theme->minScale() > theme->maxScale())
    02417            {
    02418                       if(theme->minScale() < canvas->scaleApx() || theme->maxScale() > canvas->scaleApx())
    02419                                  return;
    02420            }
    02421
    02422            TeLayer *layer = theme->layer();
    02423            TeDatabase *db = layer->database();
    02424            TeDatabasePortal *portal = db->getPortal();
    02425            canvas->setDataProjection (layer->projection());
    02426            map<int, RepMap>::iterator it = layerRepMap.find(layer->id());
    02427            TeGeomRepVisualMap* vmap;
    02428
    02429            TeBox box;
    02430            TeBox vb = box;
    02431            if(box.isValid())
    02432            {
    02433                       canvas->mapDWtoCW(vb);
    02434                       canvas->mapCWtoV(vb);
    02435            }
    02436
    02437            if (layer->hasGeometry(TeRASTER) || layer->hasGeometry(TeRASTERFILE) && (theme->visibleRep() & TeRASTER))
    02438            {
    02439                       TeBox bIn;
    02440                       if (box.isValid())
    02441                       {
    02442                                  canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    02443                                  bIn = vb;
    02444                       }
    02445
    02446                       TeRaster* raster = theme->layer()->raster();
    02447                       if (!theme->rasterVisual())
    02448                                  theme->createRasterVisual(raster);
    02449
    02450                       canvas->plotRaster(raster,theme->rasterVisual(), 0);
    02451            }
    02452            if(layer->hasGeometry(TePOLYGONS) && (theme->visibleRep() & TePOLYGONS))
    02453            {
    02454                       // query the database table containing the polygons� geometry
    02455                       string wherebox = getWhereBox(portal, appTheme, canvas, TePOLYGONS, box);
    02456                       tableName = layer->tableName(TePOLYGONS);
    02457
    02458                       string queryPolygons  = "SELECT " + tableName + ".*";
    02459                       queryPolygons += " FROM " + tableName + ", " + theme->collectionTable();
    02460                       queryPolygons += " WHERE object_id = c_object_id";
    02461                       if(wherebox.empty() == false)
    02462                                  queryPolygons += " AND " + wherebox;
    02463
    02464                       queryPolygons += " ORDER BY " + db->getSQLOrderBy(TePOLYGONS);
    02465
    02466                       portal->freeResult();
    02467
    02468                       //Plot the polygons whose number was placed in nSteps
    02469                       if (portal->query(queryPolygons, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02470                       {
    02471                                  delete portal;
    02472                                  return;
    02473                       }
    02474
    02475                       if(portal->fetchRow())
    02476                       {
    02477                                  bool flag;
    02478                                  flag = true;
    02479                                  do
    02480                                  {
    02481                                             TePolygon poly;
    02482                                             int geomId = atoi(portal->getData(0));
    02483                                             string oid = portal->getData(1);
    02484                                             if (objVisualMap.find(oid) != objVisualMap.end())
    02485                                                        vmap = objVisualMap[oid];
    02486                                             else
    02487                                             {
    02488                                                        flag = portal->fetchGeometry(poly);
    02489                                                        continue;
    02490                                             }
    02491
    02492                                             visual = *(vmap->operator[](TePOLYGONS));
    02493                                             color = visual.color();
    02494                                             canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    02495                                             canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    02496                                             color = visual.contourColor();
    02497                                             canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    02498                                             canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    02499                                             if(box.isValid())
    02500                                                        canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    02501                                             if(it == layerRepMap.end())
    02502                                             {
    02503                                                        flag = portal->fetchGeometry(poly);
    02504                                                        canvas->plotPolygon(poly);
    02505                                             }
    02506                                             else
    02507                                             {
    02508                                                        canvas->plotPolygon(layerRepMap[layer->id()].polygonMap_[geomId]);
    02509                                                        int parent_id = atoi(portal->getData(4));
    02510                                                        int parent = parent_id;
    02511                                                        while(parent == parent_id)
    02512                                                        {
    02513                                                                   flag = portal->fetchRow();
    02514                                                                   if(flag)
    02515                                                                              parent = atoi(portal->getData(4));
    02516                                                                   else
    02517                                                                              parent = -1;
    02518                                                        }
    02519                                             }
    02520                                  }
    02521                                  while (flag);
    02522                       }
    02523            }
    02524
    02525            if(box.isValid())
    02526                       canvas->setClipRegion((int)vb.x1(), (int)vb.y1(), (int)vb.width(), (int)vb.height());
    02527            if(layer->hasGeometry(TeCELLS) && (theme->visibleRep() & TeCELLS))
    02528            {
    02529                       // query the database table containing the polygons� geometry
    02530                       string wherebox = getWhereBox(portal, appTheme, canvas, TeCELLS, box);
    02531                       tableName = layer->tableName(TeCELLS);
    02532
    02533                       string queryCells  = "SELECT " + tableName + ".*";
    02534                       queryCells += " FROM " + tableName + ", " + theme->collectionTable();
    02535                       queryCells += " WHERE object_id = c_object_id";
    02536                       if(wherebox.empty() == false)
    02537                                  queryCells += " AND " + wherebox;
    02538
    02539                       portal->freeResult();
    02540                       if (portal->query(queryCells, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02541                       {
    02542                                  delete portal;
    02543                                  return;
    02544                       }
    02545
    02546                       if(portal->fetchRow())
    02547                       {
    02548                                  bool flag;
    02549                                  flag = true;
    02550                                  do
    02551                                  {
    02552                                             TeCell cell;
    02553                                             string oid = portal->getData(1);
    02554                                             if (objVisualMap.find(oid) != objVisualMap.end())
    02555                                                        vmap = objVisualMap[oid];
    02556                                             else
    02557                                             {
    02558                                                        flag = portal->fetchGeometry(cell);
    02559                                                        continue;
    02560                                             }
    02561                                             visual = *(vmap->operator[](TePOLYGONS));
    02562                                             color = visual.color();
    02563                                             canvas->setPolygonColor(color.red_, color.green_, color.blue_);
    02564                                             canvas->setPolygonStyle((int)visual.style(),visual.transparency());
    02565                                             color = visual.contourColor();
    02566                                             canvas->setPolygonLineColor (color.red_, color.green_, color.blue_);
    02567                                             canvas->setPolygonLineStyle((int)visual.contourStyle(),visual.contourWidth());
    02568                                             flag = portal->fetchGeometry(cell);
    02569                                             canvas->plotCell(cell);
    02570                                  }
    02571                                  while (flag);
    02572                       }
    02573            }
    02574
    02575            if (layer->hasGeometry(TeLINES) && (theme->visibleRep() & TeLINES))
    02576            {
    02577                       string wherebox = getWhereBox(portal, appTheme, canvas, TeLINES, box);
    02578                       // query the database table containing the lines� geometry
    02579                       tableName = layer->tableName(TeLINES);
    02580
    02581                       string queryLines  = "SELECT " + tableName + ".*";
    02582                       queryLines += " FROM " + tableName + ", " + theme->collectionTable();
    02583                       queryLines += " WHERE object_id = c_object_id";
    02584                       if(wherebox.empty() == false)
    02585                                  queryLines += " AND " + wherebox;
    02586
    02587                       portal->freeResult();
    02588                       if (portal->query(queryLines, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02589                       {
    02590                                  delete portal;
    02591                                  return;
    02592                       }
    02593
    02594                       if(portal->fetchRow())
    02595                       {
    02596                                  bool flag = true;
    02597                                  do
    02598                                  {
    02599                                             TeLine2D line;
    02600                                             int geomId = atoi(portal->getData(0));
    02601                                             string oid = portal->getData(1);
    02602                                             if (objVisualMap.find(oid) != objVisualMap.end())
    02603                                                        vmap = objVisualMap[oid];
    02604                                             else
    02605                                             {
    02606                                                        flag = portal->fetchGeometry(line);
    02607                                                        continue;
    02608                                             }
    02609
    02610                                             visual = *(vmap->operator[](TeLINES));
    02611                                             color = visual.color();
    02612                                             canvas->setLineColor(color.red_, color.green_, color.blue_);
    02613                                             canvas->setLineStyle((int)visual.style(),visual.width());
    02614                                             if(it == layerRepMap.end())
    02615                                             {
    02616                                                        flag = portal->fetchGeometry(line);
    02617                                                        canvas->plotLine(line);
    02618                                             }
    02619                                             else
    02620                                             {
    02621                                                        canvas->plotLine(layerRepMap[layer->id()].lineMap_[geomId]);
    02622                                                        flag = portal->fetchRow();
    02623                                             }
    02624                                  }
    02625                                  while (flag);
    02626                       }
    02627            }
    02628
    02629            if (layer->hasGeometry(TePOINTS) && (theme->visibleRep() & TePOINTS))
    02630            {
    02631                       string wherebox = getWhereBox(portal, appTheme, canvas, TePOINTS, box);
    02632                       // query the database table containing the points� geometry
    02633                       tableName = layer->tableName(TePOINTS);
    02634
    02635                       string queryPoints  = "SELECT " + tableName + ".*";
    02636                       queryPoints += " FROM " + tableName + ", " + theme->collectionTable();
    02637                       queryPoints += " WHERE object_id = c_object_id";
    02638                       if(wherebox.empty() == false)
    02639                                  queryPoints += " AND " + wherebox;
    02640
    02641                       portal->freeResult();
    02642                       if(portal->query(queryPoints, TeSERVERSIDE, TeUNIDIRECTIONAL, TeREADONLY, TeBINARYCURSOR) == false)
    02643                       {
    02644                                  delete portal;
    02645                                  return;
    02646                       }
    02647
    02648                       if(portal->fetchRow())
    02649                       {
    02650                                  bool flag = true;
    02651                                  do
    02652                                  {
    02653                                             TePoint point;
    02654                                             string oid = portal->getData(1);
    02655                                             if (objVisualMap.find(oid) != objVisualMap.end())
    02656                                                        vmap = objVisualMap[oid];
    02657                                             else
    02658                                             {
    02659                                                        flag = portal->fetchGeometry(point);
    02660                                                        continue;
    02661                                             }
    02662
    02663                                             visual = *(vmap->operator[](TePOINTS));
    02664                                             color = visual.color();
    02665                                             canvas->setPointColor(color.red_, color.green_, color.blue_);
    02666                                             canvas->setPointStyle((int)visual.style(),visual.size());
    02667                                             flag = portal->fetchGeometry(point);
    02668                                             canvas->plotPoint(point);
    02669                                  }
    02670                                  while (flag);
    02671                       }
    02672            }
    02673            delete portal;
    02674
    02675            if(box.isValid())
    02676                       canvas->setClipping(false);
    02677 }
    02678
    02679 #endif
    02680

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines