TeViewNode.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 *************************************************************************************/
00023 /*! \file TeViewNode.h
00024     \brief This file provides TerraLib's tree structure of views
00025 */
00026 #ifndef  __TERRALIB_INTERNAL_VIEWNODE_H
00027 #define  __TERRALIB_INTERNAL_VIEWNODE_H
00028 
00029 #define THEME_GROUP
00030 
00031 #include "TeDefines.h"
00032 #include "TeBox.h"
00033 #include "TeAbstractFactory.h"
00034 
00035 #include <iostream>
00036 #include <string>
00037 #include <vector>
00038 using namespace std;
00039 
00040 class TeProjection;
00041 class TeViewNode;
00042 
00043 //! Type of view node
00044 enum TeViewNodeType
00045 { TeTHEME=0, TeTREE=1, TeEXTERNALTHEME=2, TeFILETHEME=3, TeSFSTHEME=4 }; 
00046 
00047 
00048 //!  A class to represent the view node parameters 
00049 /*!  
00050          This class contains the main view node parameters and it is used 
00051          by the factory responsible for creating view node objects. 
00052          
00053         \sa
00054      TeViewNode
00055 */
00056 class TL_DLL TeViewNodeParams
00057 {
00058 public:
00059         //! Constructor
00060         TeViewNodeParams(const string& name="", const int& id=0, const int& viewId=0, 
00061                 const int nodeType=0, const int& priority=0, TeViewNode* parentNode=0,
00062                 const int parentId=0):
00063                 name_(name),
00064                 id_(id),
00065                 viewId_(viewId),
00066                 nodeType_(nodeType),
00067                 priority_(priority),
00068                 myParent_(parentNode),
00069                 myParentId_(parentId)
00070         { }
00071 
00072         //! Copy constructor
00073         TeViewNodeParams(const TeViewNodeParams& params)
00074         {
00075                 name_ = params.name_;
00076         id_ = params.id_;
00077                 viewId_ = params.viewId_; 
00078         nodeType_ = params.nodeType_; 
00079                 priority_ = params.priority_;
00080                 myParent_ = params.myParent_;
00081                 myParentId_ = params.myParentId_; 
00082         }
00083 
00084         virtual ~TeViewNodeParams();
00085         //! Returns the view node type 
00086         int getProductId() { return nodeType_; }
00087 
00088     //! Node name
00089         string                  name_;          
00090         //! Node identity
00091         int                             id_;
00092         //! View identity that contains this node 
00093         int                             viewId_;        
00094         //! Node type
00095         int                             nodeType_;
00096         //! Precedence when stored in a view
00097         int                             priority_;
00098         //! Pointer to its parent 
00099         TeViewNode*     myParent_;  
00100         //! Node parent id
00101         int                     myParentId_;
00102 };
00103 
00104 
00105 //!  A class to deal with nodes of a view 
00106 /*!  
00107          In Terralib, a view is composed of nodes. This is a base class 
00108          used to specialize view node types. 
00109 
00110         \sa
00111      TeView TeViewNodeParams
00112 */
00113 class TL_DLL TeViewNode
00114 {
00115 public:
00116         //! Empty constructor
00117     TeViewNode(const string& name="", TeViewNode* parent=0, const int& view=0, const int& id=0, const int& nodeType=0): 
00118           viewNodeParams_(name, id, view, nodeType, 0, parent)
00119         { }
00120         
00121         //! Constructor
00122     TeViewNode(const TeViewNodeParams& viewNodeParams): 
00123           viewNodeParams_(viewNodeParams)
00124         { }
00125 
00126         //! Destructor
00127         virtual ~TeViewNode()
00128         {}
00129 
00130         //! Makes a copy of the object
00131         virtual TeViewNode* clone() 
00132         {
00133                 return new TeViewNode(viewNodeParams_);
00134         };
00135 
00136         //! Inserts a new child in the tree hierachy. Fails if the object is a leaf
00137         virtual void add (TeViewNode*, const bool& /*updatePriority*/ = true) {}
00138 
00139     //! Remove an existing child identified by its id from the tree hierarchy
00140     /*! 
00141                 Fails if the object is a leaf
00142             Should be used in conjunction with a delete 
00143         */      
00144         virtual TeViewNode* removeID (int /* id */) { return 0; }
00145  
00146    //!  Remove an existing child identified by its name from the tree hierarchy
00147     /*! 
00148                 Fails if the object is a leaf
00149             Should be used in conjunction with a delete 
00150         */      
00151         virtual TeViewNode* remove (const string& /*name*/) { return 0; }
00152 
00153         //! Retrieve a node identified by its identifier from the tree structure
00154         virtual TeViewNode* retrieve (int)  { return 0; }
00155 
00156         //! Returns a pointer to a parent node
00157         virtual TeViewNode* parent()
00158         { return viewNodeParams_.myParent_; }
00159 
00160         //! Returns the identifier of a node parent
00161         virtual int parentId()
00162         {
00163                 if (viewNodeParams_.myParent_)
00164                         return viewNodeParams_.myParent_->id(); 
00165                 else
00166                         return viewNodeParams_.myParentId_;
00167         }
00168 
00169         //! Sets the identification of the parent node
00170         virtual void parentId(int i) 
00171         {
00172                 if (viewNodeParams_.myParent_)
00173                         viewNodeParams_.myParent_->id(i);
00174                 viewNodeParams_.myParentId_ = i;
00175         }
00176 
00177         //! Sets the parent of node
00178         virtual void setParent ( TeViewNode* node )
00179         { 
00180                 viewNodeParams_.myParent_ = node; 
00181                 viewNodeParams_.myParentId_ = (viewNodeParams_.myParent_)? viewNodeParams_.myParent_->id():0;
00182         }
00183 
00184         //! Returns the identification of a node
00185         virtual int             id () { return viewNodeParams_.id_; }
00186 
00187         //! Sets the identification of a node
00188         virtual void    id (int i){ viewNodeParams_.id_ = i; }
00189 
00190         //! Returns the name of a node
00191         virtual string  name () { return viewNodeParams_.name_; }
00192         //! Sets the name of a node
00193         virtual void    name (const string& s) { viewNodeParams_.name_ = s; }
00194 
00195         //! Returns the priority of a node
00196         virtual int             priority() const { return viewNodeParams_.priority_; }
00197         //! Sets the priority of a node
00198         virtual void    priority(int i) { viewNodeParams_.priority_ = i; }
00199 
00200         //! Sets the view identification of a node
00201         virtual void    view (int viewId) { viewNodeParams_.viewId_ = viewId; }
00202         //! Returns the view identification of a node
00203         virtual int             view () { return viewNodeParams_.viewId_ ; }
00204 
00205         //! Returns the node type
00206         virtual int type() { return viewNodeParams_.nodeType_; };
00207         //! Sets the node type
00208         virtual void type(const int& t) { viewNodeParams_.nodeType_ = t; }
00209 
00210         //! Moves a node up in the tree structure
00211         virtual void moveUp ()
00212         {
00213                 if (viewNodeParams_.myParent_)
00214                         viewNodeParams_.myParent_->moveUp (this);
00215         }
00216         
00217         //! Moves a node down in the tree structure
00218         virtual void moveDown ()
00219         {
00220                 if (viewNodeParams_.myParent_)
00221                         viewNodeParams_.myParent_->moveDown (this);
00222         }
00223 
00224         //! Swaps nodes 
00225         virtual void swap ( unsigned int, unsigned int ) {}
00226 
00227         //! Sets the nodes visibility 
00228         virtual void visibility ( int ){}; 
00229 
00230         //! Returns the nodes visibility 
00231         virtual int visibility(){ return 1; };
00232 
00233         //! Draws a node
00234         virtual void draw() {}
00235 
00236         //! Sorts the node
00237         virtual void sort() {}
00238         
00239         static TeViewNode*      DefaultObject()
00240         {       return 0; }
00241 
00242         virtual int getProductId() const
00243         {       return viewNodeParams_.nodeType_; }
00244 
00245         virtual TeViewNodeParams& viewNodeParams()
00246         {       return viewNodeParams_; }
00247 
00248         virtual void viewNodeParams(TeViewNodeParams& p)
00249         {       viewNodeParams_ = p; }
00250 
00251 
00252 protected:
00253 
00254         virtual void    moveUp (TeViewNode*) {}
00255         virtual void    moveDown (TeViewNode*) {}
00256 
00257         //! Node parameters
00258         TeViewNodeParams        viewNodeParams_;
00259 };
00260 
00261 
00262 //!  This class implements a virtual factory to create view node types. 
00263 /*!  
00264          This class is a base virtual factory used to specialize 
00265          other factories that create particular node view types. 
00266 
00267         \sa
00268      TeAbstractFactory TeViewNode TeViewNodeParams
00269 */
00270 class TL_DLL TeViewNodeFactory : public TeAbstractFactory<TeViewNode,TeViewNodeParams, int>
00271 {
00272 public:
00273         //! Constructor based on the view node type
00274         TeViewNodeFactory(const int& nodeType) : 
00275           TeAbstractFactory<TeViewNode,TeViewNodeParams, int>(nodeType)
00276         { }
00277 };
00278 
00279 
00280 //! A class to deal with branchs in a view tree structure  
00281 class TL_DLL TeViewTree: public TeViewNode
00282 {
00283 public:
00284 
00285         //! Constructor
00286         TeViewTree(const string& name=""): TeViewNode(name, 0, 0, 0, (int)TeTREE)
00287         { }
00288 
00289         //! Constructor
00290     TeViewTree(const TeViewNodeParams& params): 
00291           TeViewNode(params)
00292         { }
00293 
00294 
00295         //! Destructor
00296         virtual ~TeViewTree ();
00297 
00298         //! Sets the nodes visibility 
00299         virtual void visibility (int vis);
00300 
00301         //! Returns the nodes visibility 
00302         virtual int visibility ();
00303 
00304         //! Swap nodes
00305         virtual void swap (unsigned int i, unsigned int j);
00306 
00307         //! Moves a node up in the tree structure
00308         virtual void moveUp (TeViewNode* node);
00309 
00310         //! Moves a node down in the tree structure
00311         virtual void moveDown (TeViewNode* node);
00312 
00313         //! Adds a node to the structure
00314         virtual void add (TeViewNode* node, const bool& updatePriority = true);
00315 
00316     //! Removes a node identified by its name
00317         virtual TeViewNode* remove (const string& name);
00318 
00319     //! Removes a node through its identifier
00320         virtual TeViewNode* removeID (int id) ;
00321 
00322     //! Retrieves a node through its index
00323         virtual TeViewNode* retrieve (unsigned int i) 
00324         { return nodes_[i]; }
00325 
00326         //! Draw a node
00327         virtual void draw ();
00328 
00329         //! Returns the size of the structure
00330         unsigned int size()
00331     { return (unsigned int)nodes_.size(); }
00332 
00333         //! Returns the vector of View nodes
00334         vector<TeViewNode*>& nodes()
00335         { return nodes_; }
00336 
00337         //! Sort the vector of nodes according to their priorities
00338         void sort();
00339 
00340         //! Unlinks the nodes from the view tree
00341         virtual void clear();
00342         
00343         /*! Move the given node to the top of it's tree.
00344           \param node to be moved
00345           \return the number of positions the node has been moved
00346         */
00347         virtual int moveTop (TeViewNode* node);
00348 
00349         /*!     Move the given node to the bottom of it's tree.
00350           \param node to be moved
00351           \return the number of positions the node has been moved
00352         */
00353         int moveBottom(TeViewNode* node);
00354 
00355         /*!
00356         Inserts the given node to at the begin of the view tree.
00357         \param node node to be added
00358         */
00359         virtual void insertFront(TeViewNode* node);
00360 
00361         /*! Look at a View Tree for a node with the given id.
00362                 \param id Id of the node to be found
00363         */
00364         virtual TeViewNode* find (int id);
00365 
00366         /*! Look at a View Tree for a node with the given name.
00367                 \param name name of the node to be found
00368                 \param caseS(optional) true if the given name is case sensitive
00369         */
00370         virtual TeViewNode* find( std::string name, bool caseS = false );
00371 
00372         /*! Returns the boundary box of the tree view themes
00373         \param projection The returned box coordinates will be in the given projection 
00374         */
00375         virtual TeBox box(bool onlyVisible, TeProjection* projection );
00376 
00377         /*!     Asserts the nodes priorities by the positions.
00378                 Returns true if any priority was updated, otherwise returns false.
00379         */
00380         virtual bool assertsPriorities();
00381 
00382 private:
00383         vector<TeViewNode*> nodes_;
00384 };
00385 
00386 
00387 //!  This class implements a factory to create view tree objects. 
00388 /*!  
00389          This class is a factory that create view nodes 
00390          of the type TeTREE, that is, view tree objects.
00391 
00392         \sa
00393      TeViewNodeFactory TeViewNodeParams TeViewTree  
00394 */
00395 class TL_DLL TeViewTreeFactory : public TeViewNodeFactory
00396 {
00397 public:
00398         //! Constructor 
00399         TeViewTreeFactory() : TeViewNodeFactory((int)TeTREE)
00400         {}
00401 
00402         //! Created view tree objects 
00403         TeViewTree* build(TeViewNodeParams* params)
00404         {       
00405                 TeViewNodeParams auxParams = *params;
00406                 return new TeViewTree(auxParams);       
00407         }
00408 };
00409 
00410 #endif
00411 

Generated on Sun Jul 29 04:01:29 2012 for TerraLib - Development Source by  doxygen 1.5.3