osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTHFEATURES_FEATURE_SOURCE_H 00021 #define OSGEARTHFEATURES_FEATURE_SOURCE_H 1 00022 00023 #include <osgEarthFeatures/Common> 00024 #include <osgEarthFeatures/Feature> 00025 #include <osgEarthFeatures/FeatureCursor> 00026 #include <osgEarthSymbology/Geometry> 00027 #include <osgEarthSymbology/Query> 00028 #include <osgEarthFeatures/Filter> 00029 #include <osgEarthSymbology/Style> 00030 #include <osgEarth/Profile> 00031 #include <osgEarth/GeoData> 00032 #include <osgDB/ReaderWriter> 00033 #include <OpenThreads/Mutex> 00034 #include <list> 00035 00036 namespace osgEarth { namespace Features 00037 { 00038 using namespace osgEarth; 00039 using namespace osgEarth::Symbology; 00040 00044 class OSGEARTHFEATURES_EXPORT FeatureSourceOptions : public DriverConfigOptions 00045 { 00046 public: // properties 00047 00049 optional<std::string>& name() { return _name; } 00050 const optional<std::string>& name() const { return _name; } 00051 00053 FeatureFilterList& filters() { return _filters; } 00054 const FeatureFilterList& filters() const { return _filters; } 00055 00057 optional<bool>& openWrite() { return _openWrite; } 00058 const optional<bool>& openWrite() const { return _openWrite; } 00059 00061 optional<ProfileOptions>& profile() { return _profile; } 00062 const optional<ProfileOptions>& profile() const { return _profile; } 00063 00064 00065 public: 00066 FeatureSourceOptions( const ConfigOptions& options =ConfigOptions() ); 00067 virtual Config getConfig() const; 00068 00069 protected: 00070 virtual void mergeConfig( const Config& conf ) { 00071 DriverConfigOptions::mergeConfig( conf ); 00072 fromConfig( conf ); 00073 } 00074 00075 private: 00076 void fromConfig( const Config& conf ); 00077 00078 FeatureFilterList _filters; 00079 optional<std::string> _name; 00080 optional< bool > _openWrite; 00081 optional<ProfileOptions> _profile; 00082 }; 00083 00088 class OSGEARTHFEATURES_EXPORT FeatureSource : public virtual Revisioned<osg::Object> // public virtual osg::Object 00089 { 00090 public: 00094 FeatureSource( const ConfigOptions& options =ConfigOptions() ); 00095 00101 const FeatureProfile* getFeatureProfile() const; 00102 00106 const FeatureSourceOptions& getFeatureSourceOptions() const { return _options; } 00107 00114 virtual FeatureCursor* createFeatureCursor( const Symbology::Query& query =Symbology::Query() ) =0; 00115 00119 virtual bool isWritable() const { return false; } 00120 00125 virtual bool deleteFeature(FeatureID fid) { return false; } 00126 00132 virtual int getFeatureCount() const { return -1; } 00133 00139 virtual Feature* getFeature( FeatureID fid ) { return 0L; } 00140 00145 virtual const FeatureSchema& getSchema() const; 00146 00152 virtual bool insertFeature(Feature* feature) { return false; } 00153 00159 virtual Geometry::Type getGeometryType() const { return Geometry::TYPE_UNKNOWN; } 00160 00161 00162 public: // Styling 00163 00169 virtual bool hasEmbeddedStyles() const { 00170 return false; } 00171 00172 public: 00173 00178 const FeatureFilterList& getFilters() const; 00179 00180 public: 00181 00182 // META_Object specialization: 00183 virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate 00184 virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate 00185 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const FeatureSource*>(obj)!=NULL; } 00186 virtual const char* className() const { return "FeatureSource"; } 00187 virtual const char* libraryName() const { return "osgEarthFeatures"; } 00188 00189 00193 virtual void initialize( const std::string& referenceURI ) =0; 00194 00195 protected: 00196 00202 virtual const FeatureProfile* createFeatureProfile() =0; 00203 00207 virtual ~FeatureSource() { } 00208 00209 private: 00210 const FeatureSourceOptions _options; 00211 00212 osg::ref_ptr<const FeatureProfile> _featureProfile; 00213 OpenThreads::Mutex _createMutex; 00214 00215 friend class Map; 00216 friend class FeatureSourceFactory; 00217 }; 00218 00219 //-------------------------------------------------------------------- 00220 00221 class OSGEARTHFEATURES_EXPORT FeatureSourceDriver : public osgDB::ReaderWriter 00222 { 00223 public: 00224 virtual const FeatureSourceOptions& getFeatureSourceOptions( const osgDB::ReaderWriter::Options* rwopt ) const; 00225 }; 00226 00227 //-------------------------------------------------------------------- 00228 00232 class OSGEARTHFEATURES_EXPORT FeatureSourceFactory 00233 { 00234 public: 00235 static FeatureSource* create( const FeatureSourceOptions& options ); 00236 }; 00237 00238 } } // namespace osgEarth::Features 00239 00240 #endif // OSGEARTHFEATURES_FEATURE_SOURCE_H 00241