Changeset 19 for trunk/tmdmcreator/src
- Timestamp:
- 02/22/13 14:37:37 (12 years ago)
- Location:
- trunk/tmdmcreator/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tmdmcreator/src/tmdmcreator.cpp
r18 r19 108 108 109 109 // Process layers 110 TmDmProcessorSimple my LayerProc(m_FileNameUserContent, m_FileNameOutSQL);111 int myThematicLayersStart = my LayerProc.FindBlock(_T("thematic_layers"));110 TmDmProcessorSimple myProc(m_FileNameUserContent, m_FileNameOutSQL); 111 int myThematicLayersStart = myProc.FindBlock(_T("thematic_layers")); 112 112 if (myThematicLayersStart == wxNOT_FOUND) { 113 113 errorsmsg.Add(wxString::Format(_("'thematic_layers' field not found in %s"), m_FileNameUserContent.GetFullPath())); 114 114 return false; 115 115 } 116 if (my LayerProc.ProcessBlock(myThematicLayersStart, _T("thematic_layers"))==false) {116 if (myProc.ProcessBlock(myThematicLayersStart, _T("thematic_layers"))==false) { 117 117 errorsmsg.Add(wxString::Format(_("Processing 'thematic_layers' failed in %s"), m_FileNameUserContent.GetFullPath())); 118 118 return false; 119 119 } 120 121 // Process objects 122 int myObjectStart = myProc.FindBlock(_T("dmn_layer_object")); 123 if (myObjectStart == wxNOT_FOUND) { 124 errorsmsg.Add(wxString::Format(_("'dmn_layer_object' field not found in %s"), m_FileNameUserContent.GetFullPath())); 125 return false; 126 } 127 if (myProc.ProcessBlock(myObjectStart, _T("dmn_layer_object"))==false) { 128 errorsmsg.Add(wxString::Format(_("Processing 'dmn_layer_object' failed in %s"), m_FileNameUserContent.GetFullPath())); 129 return false; 130 } 131 132 // Process attributs 133 TmDmProcessorAttributs myProcAttributs (m_FileNameUserContent, m_FileNameOutSQL); 134 int myAttributStart = myProcAttributs.FindBlock(_T("attributs")); 135 if (myAttributStart == wxNOT_FOUND) { 136 errorsmsg.Add(wxString::Format(_("'attributs' field not found in %s"), m_FileNameUserContent.GetFullPath())); 137 return false; 138 } 139 if (myProcAttributs.ProcessBlock(myAttributStart, wxEmptyString)==false) { 140 errorsmsg.Add(wxString::Format(_("Processing 'attributs' failed in %s"), m_FileNameUserContent.GetFullPath())); 141 return false; 142 } 143 144 120 145 return true; 121 146 } -
trunk/tmdmcreator/src/tmdmprocessor.cpp
r18 r19 64 64 wxArrayString mySQLCols; 65 65 TmDmCopier myCopier(m_FileDst); 66 myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), tablename)); 67 66 68 67 69 wxFileInputStream input(m_FileSrc.GetFullPath()); … … 123 125 } 124 126 127 128 125 129 TmDmProcessorAttributs::~TmDmProcessorAttributs() { 126 130 } 127 131 132 133 134 bool TmDmProcessorAttributs::_ProcessAttributesName(int blockstart) { 135 wxArrayString mySQLCols; 136 TmDmCopier myCopier(m_FileDst); 137 myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), _T("dmn_layer_attribut"))); 138 int NUM_COLS = 3; 139 wxArrayString myPreviousRow; 140 141 wxFileInputStream input(m_FileSrc.GetFullPath()); 142 wxTextInputStream text(input); 143 long myLineIndex = 0; 144 while(input.IsOk() && !input.Eof() ){ 145 wxString myRow = text.ReadLine(); 146 if (myLineIndex <= blockstart) { 147 myLineIndex++; 148 continue; 149 } 150 151 if (myLineIndex == blockstart+1) { 152 mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); 153 myLineIndex++; 154 continue; 155 } 156 157 wxArrayString myValues = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY_ALL); 158 bool bEmpty = true; 159 for (unsigned int i = 0; i< myValues.GetCount(); i++) { 160 if (myValues[i] != wxEmptyString) { 161 bEmpty = false; 162 break; 163 } 164 } 165 if (bEmpty == true) { 166 // ok empty line found 167 return true; 168 } 169 170 // check that this row differs from previous 171 wxArrayString myAttributRow; 172 for (unsigned int i = 0; i< NUM_COLS; i++) { 173 myAttributRow.Add(myValues.Item(i)); 174 } 175 if (myAttributRow == myPreviousRow) { 176 continue; 177 } 178 myPreviousRow = myAttributRow; 179 180 181 wxString myInsert = _T("INSERT INTO `dmn_layer_attribut` VALUES ("); 182 for (unsigned int i = 0; i< myAttributRow.GetCount(); i++) { 183 myInsert.Append(wxString::Format(_T("\"%s\","), myAttributRow.Item(i))); 184 } 185 myInsert.RemoveLast(); 186 myInsert.Append(_T(");\n")); 187 myCopier.CopyFrom(myInsert); 188 myLineIndex++; 189 } 190 return true; 191 } 192 193 194 195 bool TmDmProcessorAttributs::_ProcessAttributesValues(int blockstart) { 196 wxArrayString mySQLCols; 197 TmDmCopier myCopier(m_FileDst); 198 myCopier.CopyFrom(wxString::Format(_T("\n-- %s --\n"), _T("attribut values"))); 199 int START_COL = 3; 200 201 wxFileInputStream input(m_FileSrc.GetFullPath()); 202 wxTextInputStream text(input); 203 long myLineIndex = 0; 204 while(input.IsOk() && !input.Eof() ){ 205 wxString myRow = text.ReadLine(); 206 if (myLineIndex <= blockstart) { 207 myLineIndex++; 208 continue; 209 } 210 211 if (myLineIndex == blockstart+1) { 212 mySQLCols = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY); 213 myLineIndex++; 214 continue; 215 } 216 217 218 wxArrayString myValues = wxStringTokenize(myRow, _T("\t"), wxTOKEN_RET_EMPTY_ALL); 219 bool bEmpty = true; 220 for (unsigned int i = 0; i< myValues.GetCount(); i++) { 221 if (myValues[i] != wxEmptyString) { 222 bEmpty = false; 223 break; 224 } 225 } 226 if (bEmpty == true) { 227 // ok empty line found 228 return true; 229 } 230 231 // query to dmn_catalog 232 wxString myInsert = _T("INSERT INTO `dmn_catalog` VALUES ("); 233 for (unsigned int i = START_COL; i< mySQLCols.GetCount(); i++) { 234 myInsert.Append(wxString::Format(_T("\"%s\","), myValues.Item(i))); 235 } 236 myInsert.RemoveLast(); 237 myInsert.Append(_T(");\n")); 238 239 240 // query to dmn_attribut_value 241 myInsert.Append(wxString::Format(_T("INSERT INTO `dmn_attribut_value` VALUES (%s, %s);\n"), 242 myValues.Item(0), myValues.Item(START_COL))); 243 244 myCopier.CopyFrom(myInsert); 245 myLineIndex++; 246 } 247 return true; 248 } 249 250 251 128 252 bool TmDmProcessorAttributs::ProcessBlock(int blockstart, const wxString & tablename) { 129 return false; 130 } 131 253 if (_ProcessAttributesName(blockstart) == false) { 254 return false; 255 } 256 257 if (_ProcessAttributesValues(blockstart) == false) { 258 return false; 259 } 260 return true; 261 } 262 263 264 -
trunk/tmdmcreator/src/tmdmprocessor.h
r18 r19 62 62 63 63 class TmDmProcessorAttributs : public TmDmProcessor { 64 private: 65 bool _ProcessAttributesName(int blockstart); 66 bool _ProcessAttributesValues(int blockstart); 67 64 68 public: 65 69 TmDmProcessorAttributs(const wxFileName & src, const wxFileName & dest);
Note: See TracChangeset
for help on using the changeset viewer.