Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
AbstractLayer.h
1 //
2 // AbstractLayer.h
3 //
4 // Copyright (c) 2006-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef ABSTRACTLAYERH
9 #define ABSTRACTLAYERH
10 
11 #include "TerrainLayers.h"
12 #include "vtdata/Features.h"
13 
14 class vtTerrain;
15 
16 class vtVisual
17 {
18 public:
19  vtVisual() : m_xform(NULL) {}
20  std::vector<vtMesh*> m_meshes;
21  vtTransform *m_xform;
22 };
23 
24 typedef std::map<vtFeature*,vtVisual*> VizMap;
25 
72 class vtAbstractLayer : public vtLayer
73 {
74 public:
75  vtAbstractLayer(vtTerrain *pTerr);
76  ~vtAbstractLayer();
77 
78  void SetLayerName(const vtString &fname);
79  vtString GetLayerName();
80  void SetVisible(bool vis);
81  bool GetVisible();
82 
83  void SetFeatureSet(vtFeatureSet *pSet);
84  vtFeatureSet *GetFeatureSet() const { return pSet; }
85  vtGroup *GetLabelGroup() const { return pLabelGroup; }
86  vtGroup *GetContainer() const { return pContainer; }
87  vtVisual *GetViz(vtFeature *feat);
88  vtMultiTexture *GetMultiTexture() const { return pMultiTexture; }
89  void CreateContainer();
90 
91  // Create for all features
92  void CreateStyledFeatures();
93  bool CreateTextureOverlay();
95 
96  // Create for a single feature
97  void CreateStyledFeature(int iIndex);
98  void CreateObjectGeometry(uint iIndex);
99  void CreateLineGeometry(uint iIndex);
100  void CreateFeatureLabel(uint iIndex);
101 
102  void ReleaseGeometry();
104 
105  // When the underlying feature changes, we need to rebuild the visual
106  void Rebuild();
107  void RebuildFeature(uint iIndex);
108  void UpdateVisualSelection();
109  void Reload();
110 
111  // To make sure all edits are fully reflected in the visual, call these
112  // methods around any editing of style or geometry.
113  void EditBegin();
114  void EditEnd();
115  void DeleteFeature(vtFeature *f);
116 
118  void SetProperties(const vtTagArray &props) { m_StyleProps = props; }
120  vtTagArray &GetProperties() { return m_StyleProps; }
121 
122 protected:
123  void CreateGeomGroup();
124  void CreateLabelGroup();
125  int GetObjectMaterialIndex(vtTagArray &style, uint iIndex);
126 
127  // A set of properties that can provide additional information, such as
128  // style information for visual display.
129  vtTagArray m_StyleProps;
130 
131  vtTerrain *m_pTerr;
132 
135  vtGroupPtr pContainer;
136  vtGroup *pGeomGroup;
137  vtGroup *pLabelGroup;
138  vtMultiTexture *pMultiTexture;
139 
140  // Handy pointers to disambiguate pSet
141  vtFeatureSetPoint2D *pSetP2;
142  vtFeatureSetPoint3D *pSetP3;
143  vtFeatureSetLineString *pSetLS2;
144  vtFeatureSetLineString3D *pSetLS3;
145  vtFeatureSetPolygon *pSetPoly;
146 
147  // Used to create the visual features
148  vtFontPtr m_pFont;
149  vtMaterialArrayPtr pGeomMats;
150 
151  int material_index_object;
152  int material_index_line;
153  int material_index_yellow;
154  vtGeode *pGeodeObject;
155  vtGeode *pGeodeLine;
156 
157  VizMap m_Map;
158 
159  // Edit tracking
160  bool CreateAtOnce();
161  bool m_bNeedRebuild;
162 };
163 
164 #endif // ABSTRACTLAYERH
165