SAGA API  v9.2
data_manager.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // data_manager.cpp //
15 // //
16 // Copyright (C) 2013 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Hamburg //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
49 
50 //---------------------------------------------------------
51 #include "data_manager.h"
52 #include "tool_library.h"
53 
54 
56 // //
57 // //
58 // //
60 
61 //---------------------------------------------------------
63 
64 //---------------------------------------------------------
66 {
67  return( g_Data_Manager );
68 }
69 
70 
72 // //
73 // //
74 // //
76 
77 //---------------------------------------------------------
79 {
80  m_pManager = pManager;
81  m_Type = Type;
82 }
83 
84 //---------------------------------------------------------
86 {
87  Delete_All();
88 }
89 
90 //---------------------------------------------------------
91 CSG_Data_Object * CSG_Data_Collection::Get(const CSG_String &File, bool bNative) const
92 {
93  for(size_t i=0; i<Count(); i++)
94  {
95  if( !File.Cmp(Get(i)->Get_File_Name(bNative)) )
96  {
97  return( Get(i) );
98  }
99  }
100 
101  return( NULL );
102 }
103 
104 //---------------------------------------------------------
106 {
107  for(size_t i=0; i<Count(); i++)
108  {
109  if( pObject == Get(i) )
110  {
111  return( true );
112  }
113  }
114 
115  return( false );
116 }
117 
118 //---------------------------------------------------------
120 {
121  if( pObject != DATAOBJECT_NOTSET && pObject != DATAOBJECT_CREATE )
122  {
123  if( Exists(pObject) )
124  {
125  return( true );
126  }
127 
128  if( m_Objects.Inc_Array() )
129  {
130  m_Objects[Count() - 1] = pObject;
131 
132  if( m_pManager == &g_Data_Manager )
133  {
135  }
136 
137  return( true );
138  }
139  }
140 
141  return( false );
142 }
143 
144 //---------------------------------------------------------
145 bool CSG_Data_Collection::Delete(CSG_Data_Object *pObject, bool bDetach)
146 {
148 
149  size_t i, n;
150 
151  for(i=0, n=0; i<Count(); i++)
152  {
153  if( pObject == Get(i) )
154  {
155  if( !bDetach )
156  {
157  delete(Get(i));
158 
159  bDetach = true; // just in case the same object has been added more than once
160  }
161  }
162  else
163  {
164  pObjects[n++] = pObjects[i];
165  }
166  }
167 
168  if( n < m_Objects.Get_uSize() )
169  {
170  m_Objects.Set_Array(n);
171 
172  return( true );
173  }
174 
175  return( false );
176 }
177 
178 //---------------------------------------------------------
179 bool CSG_Data_Collection::Delete(size_t i, bool bDetach)
180 {
181  return( Delete(Get(i), bDetach) );
182 }
183 
184 //---------------------------------------------------------
185 bool CSG_Data_Collection::Delete(bool bDetach, bool bUnsaved)
186 {
187  if( bUnsaved )
188  {
189  for(size_t i=Count(); i>0; i--)
190  {
191  if( !SG_File_Exists(Get(i - 1)->Get_File_Name()) )
192  {
193  Delete(i, bDetach);
194  }
195  }
196  }
197  else
198  {
199  if( !bDetach )
200  {
201  for(size_t i=0; i<Count(); i++)
202  {
203  delete(Get(i));
204  }
205  }
206 
207  m_Objects.Set_Array(0);
208  }
209 
210  return( true );
211 }
212 
213 //---------------------------------------------------------
215 {
216  return( Delete(bDetach, false) );
217 }
218 
219 //---------------------------------------------------------
221 {
222  for(size_t i=Count(); i>0; i--)
223  {
224  if( !SG_File_Exists(Get(i - 1)->Get_File_Name()) )
225  {
226  Delete(i, bDetach);
227  }
228  }
229 
230  return( true );
231 }
232 
233 
235 // //
236 // //
237 // //
239 
240 //---------------------------------------------------------
243 {}
244 
245 //---------------------------------------------------------
247 {
248  if( pObject == DATAOBJECT_NOTSET || pObject == DATAOBJECT_CREATE )
249  {
250  return( false );
251  }
252 
253  for(size_t i=0; i<Count(); i++)
254  {
255  if( pObject == Get(i) )
256  {
257  return( true );
258  }
259  else if( Get(i)->Get_ObjectType() == SG_DATAOBJECT_TYPE_Grids )
260  { // does object (CSG_Grid) belong to a grid collection (CSG_Grids)
261  CSG_Grids *pGrids = (CSG_Grids *)Get(i);
262 
263  for(int j=0; j<pGrids->Get_NZ(); j++)
264  {
265  if( pObject == pGrids->Get_Grid_Ptr(j) )
266  {
267  return( true );
268  }
269  }
270  }
271  }
272 
273  return( false );
274 }
275 
276 //---------------------------------------------------------
278 {
279  if( pObject != DATAOBJECT_NOTSET && pObject != DATAOBJECT_CREATE )
280  {
281  CSG_Grid_System System;
282 
283  switch( pObject->Get_ObjectType() )
284  {
285  case SG_DATAOBJECT_TYPE_Grid : System = ((CSG_Grid *)pObject)->Get_System(); break;
286  case SG_DATAOBJECT_TYPE_Grids: System = ((CSG_Grids *)pObject)->Get_System(); break;
287 
288  default: return( false );
289  }
290 
291  if( System.is_Valid() )
292  {
293  if( Count() == 0 || !m_System.is_Valid() )
294  {
295  m_System = System;
296  }
297 
298  if( m_System == System )
299  {
300  return( CSG_Data_Collection::Add(pObject) );
301  }
302  }
303  }
304 
305  return( false );
306 }
307 
308 
310 // //
311 // //
312 // //
314 
315 //---------------------------------------------------------
317 {
318  m_pTable = new CSG_Data_Collection(this, SG_DATAOBJECT_TYPE_Table );
319  m_pTIN = new CSG_Data_Collection(this, SG_DATAOBJECT_TYPE_TIN );
320  m_pPoint_Cloud = new CSG_Data_Collection(this, SG_DATAOBJECT_TYPE_PointCloud);
321  m_pShapes = new CSG_Data_Collection(this, SG_DATAOBJECT_TYPE_Shapes );
322 }
323 
324 //---------------------------------------------------------
326 {
327  Delete_All();
328 
329  delete(m_pTable );
330  delete(m_pTIN );
331  delete(m_pPoint_Cloud);
332  delete(m_pShapes );
333 }
334 
335 
337 // //
339 
340 //---------------------------------------------------------
341 CSG_Data_Collection * CSG_Data_Manager::_Get_Collection(CSG_Data_Object *pObject) const
342 {
343  if( pObject != DATAOBJECT_NOTSET && pObject != DATAOBJECT_CREATE )
344  {
345  switch( pObject->Get_ObjectType() )
346  {
347  case SG_DATAOBJECT_TYPE_Table : return( m_pTable );
348  case SG_DATAOBJECT_TYPE_TIN : return( m_pTIN );
349  case SG_DATAOBJECT_TYPE_PointCloud: return( m_pPoint_Cloud );
350  case SG_DATAOBJECT_TYPE_Shapes : return( m_pShapes );
351  case SG_DATAOBJECT_TYPE_Grid : return( Get_Grid_System(((CSG_Grid *)pObject)->Get_System()) );
352  case SG_DATAOBJECT_TYPE_Grids : return( Get_Grid_System(((CSG_Grids *)pObject)->Get_System()) );
353 
354  default: break;
355  }
356  }
357 
358  return( NULL );
359 }
360 
361 
363 // //
365 
366 //---------------------------------------------------------
368 {
369  for(size_t i=0; i<Grid_System_Count(); i++)
370  {
371  CSG_Grid_Collection *pSystem = Get_Grid_System(i);
372 
373  if( pSystem->is_Equal(System) )
374  {
375  return( pSystem );
376  }
377  }
378 
379  return( NULL );
380 }
381 
382 //---------------------------------------------------------
383 bool CSG_Data_Manager::Exists(const CSG_Grid_System &System) const
384 {
385  return( Get_Grid_System(System) != NULL );
386 }
387 
388 //---------------------------------------------------------
390 {
391  if( m_pTable ->Exists(pObject) ) return( true );
392  if( m_pTIN ->Exists(pObject) ) return( true );
393  if( m_pPoint_Cloud->Exists(pObject) ) return( true );
394  if( m_pShapes ->Exists(pObject) ) return( true );
395 
396  for(size_t i=0; i<Grid_System_Count(); i++)
397  {
398  if( Get_Grid_System(i)->Exists(pObject) ) return( true );
399  }
400 
401  return( false );
402 }
403 
404 //---------------------------------------------------------
405 CSG_Data_Object * CSG_Data_Manager::Find(const CSG_String &File, bool bNative) const
406 {
407  CSG_Data_Object *pObject;
408 
409  if( (pObject = m_pTable ->Get(File, bNative)) != NULL ) return( pObject );
410  if( (pObject = m_pTIN ->Get(File, bNative)) != NULL ) return( pObject );
411  if( (pObject = m_pPoint_Cloud->Get(File, bNative)) != NULL ) return( pObject );
412  if( (pObject = m_pShapes ->Get(File, bNative)) != NULL ) return( pObject );
413 
414  for(size_t i=0; i<Grid_System_Count(); i++)
415  {
416  if( (pObject = Get_Grid_System(i)->Get(File, bNative)) != NULL ) return( pObject );
417  }
418 
419  return( NULL );
420 }
421 
422 
424 // //
426 
427 //---------------------------------------------------------
429 {
430  CSG_Data_Collection *pCollection = _Get_Collection(pObject);
431 
432  if( pCollection == NULL && pObject != DATAOBJECT_NOTSET && pObject != DATAOBJECT_CREATE && (pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Grid || pObject->Get_ObjectType() == SG_DATAOBJECT_TYPE_Grids) && m_Grid_Systems.Inc_Array() )
433  {
434  pCollection = new CSG_Grid_Collection(this);
435 
436  m_Grid_Systems[m_Grid_Systems.Get_Size() - 1] = pCollection;
437  }
438 
439  return( pCollection && pCollection->Add(pObject) );
440 }
441 
442 //---------------------------------------------------------
444 {
445  //-----------------------------------------------------
446  if( Type == SG_DATAOBJECT_TYPE_Undefined )
447  {
448  if( SG_File_Cmp_Extension(File, "txt" )
449  || SG_File_Cmp_Extension(File, "csv" )
450  || SG_File_Cmp_Extension(File, "dbf" ) )
451  {
453  }
454 
455  if( SG_File_Cmp_Extension(File, "shp" ) )
456  {
458  }
459 
460  if( SG_File_Cmp_Extension(File, "sg-pts-z")
461  || SG_File_Cmp_Extension(File, "sg-pts" )
462  || SG_File_Cmp_Extension(File, "spc" ) )
463  {
465  }
466 
467  if( SG_File_Cmp_Extension(File, "sg-grd-z")
468  || SG_File_Cmp_Extension(File, "sg-grd" )
469  || SG_File_Cmp_Extension(File, "sgrd" )
470  || SG_File_Cmp_Extension(File, "dgm" )
471  || SG_File_Cmp_Extension(File, "grd" ) )
472  {
474  }
475 
476  if( SG_File_Cmp_Extension(File, "sg-gds-z")
477  || SG_File_Cmp_Extension(File, "sg-gds" ) )
478  {
480  }
481  }
482 
483  //-----------------------------------------------------
484  CSG_Data_Object *pObject;
485 
486  switch( Type )
487  {
488  case SG_DATAOBJECT_TYPE_Table : pObject = new CSG_Table (File); break;
489  case SG_DATAOBJECT_TYPE_Shapes : pObject = new CSG_Shapes (File); break;
490  case SG_DATAOBJECT_TYPE_TIN : pObject = new CSG_TIN (File); break;
491  case SG_DATAOBJECT_TYPE_PointCloud: pObject = new CSG_PointCloud(File); break;
492  case SG_DATAOBJECT_TYPE_Grid : pObject = new CSG_Grid (File); break;
493  case SG_DATAOBJECT_TYPE_Grids : pObject = new CSG_Grids (File); break;
494  default : pObject = NULL ; break;
495  }
496 
497  if( pObject )
498  {
499  if( pObject->is_Valid() && Add(pObject) )
500  {
501  return( pObject );
502  }
503 
504  delete(pObject);
505  }
506 
507  //-----------------------------------------------------
508  return( _Add_External(File) );
509 }
510 
511 //---------------------------------------------------------
512 CSG_Data_Object * CSG_Data_Manager::_Add_External(const CSG_String &File)
513 {
514  CSG_Data_Object *pData = NULL;
515 
516  if( !SG_File_Exists(File) )
517  {
518  return( pData );
519  }
520 
521  CSG_Tool *pImport = NULL;
522 
523  SG_UI_Msg_Lock(true);
524 
525  //-----------------------------------------------------
526  // Image Import
527 
528  if( ( SG_File_Cmp_Extension(File, "bmp")
529  || SG_File_Cmp_Extension(File, "gif")
530  || SG_File_Cmp_Extension(File, "jpg")
531  || SG_File_Cmp_Extension(File, "png")
532  || SG_File_Cmp_Extension(File, "pcx")
533  || SG_File_Cmp_Extension(File, "xpm") )
534  && (pImport = SG_Get_Tool_Library_Manager().Create_Tool("io_grid_image", 1)) != NULL
535  && pImport->Set_Parameter("FILE", File, PARAMETER_TYPE_FilePath) )
536  {
537  pImport->Set_Manager(this);
538 
539  if( pImport->Execute() )
540  {
541  pData = pImport->Get_Parameter("OUT_GRID")->asDataObject();
542  }
543  }
544 
546 
547  //-----------------------------------------------------
548  // GDAL Import
549 
550  if( !pData
551  && (pImport = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 0)) != NULL
552  && pImport->Set_Parameter("FILES", File, PARAMETER_TYPE_FilePath) )
553  {
554  pImport->Set_Manager(this);
555 
556  if( pImport->Execute() )
557  {
558  pData = pImport->Get_Parameter("GRIDS")->asList()->Get_Item(0);
559  }
560  }
561 
563 
564  //-----------------------------------------------------
565  // OGR Import
566 
567  if( !pData
568  && (pImport = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 3)) != NULL
569  && pImport->Set_Parameter("FILES", File, PARAMETER_TYPE_FilePath) )
570  {
571  pImport->Set_Manager(this);
572 
573  if( pImport->Execute() )
574  {
575  pData = pImport->Get_Parameter("SHAPES")->asList()->Get_Item(0);
576  }
577  }
578 
580 
581  //-----------------------------------------------------
582  // LAZ Import
583 
584  if( !pData && (SG_File_Cmp_Extension(File, "las") || SG_File_Cmp_Extension(File, "laz"))
585  && (pImport = SG_Get_Tool_Library_Manager().Create_Tool("io_pdal", 0)) != NULL
586  && pImport->Set_Parameter("FILES", File, PARAMETER_TYPE_FilePath) )
587  {
588  pImport->Set_Manager(this);
589 
590  if( pImport->Execute() )
591  {
592  pData = pImport->Get_Parameter("POINTS")->asList()->Get_Item(0);
593  }
594  }
595 
597 
598  //-----------------------------------------------------
599  SG_UI_Msg_Lock(false);
600 
601  return( pData );
602 }
603 
604 
606 // //
608 
609 //---------------------------------------------------------
611 {
612  CSG_Table *pObject = new CSG_Table();
613 
614  if( pObject && !Add(pObject) )
615  {
616  delete(pObject); pObject = NULL;
617  }
618 
619  return( pObject );
620 }
621 
622 //---------------------------------------------------------
624 {
625  CSG_TIN *pObject = new CSG_TIN();
626 
627  if( pObject && !Add(pObject) )
628  {
629  delete(pObject); pObject = NULL;
630  }
631 
632  return( pObject );
633 }
634 
635 //---------------------------------------------------------
637 {
638  CSG_PointCloud *pObject = new CSG_PointCloud();
639 
640  if( pObject && !Add(pObject) )
641  {
642  delete(pObject); pObject = NULL;
643  }
644 
645  return( pObject );
646 }
647 
648 //---------------------------------------------------------
650 {
651  CSG_Shapes *pObject = new CSG_Shapes(Type);
652 
653  if( pObject && !Add(pObject) )
654  {
655  delete(pObject); pObject = NULL;
656  }
657 
658  return( pObject );
659 }
660 
661 //---------------------------------------------------------
663 {
664  CSG_Grid *pObject = System.is_Valid() ? new CSG_Grid(System, Type) : NULL;
665 
666  if( pObject && !Add(pObject) )
667  {
668  delete(pObject); pObject = NULL;
669  }
670 
671  return( pObject );
672 }
673 
674 //---------------------------------------------------------
675 CSG_Grid * CSG_Data_Manager::Add_Grid(int NX, int NY, double Cellsize, double xMin, double yMin, TSG_Data_Type Type)
676 {
677  return( Add_Grid(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY), Type) );
678 }
679 
680 
682 // //
684 
685 //---------------------------------------------------------
686 bool CSG_Data_Manager::Delete(CSG_Data_Collection *pCollection, bool bDetach)
687 {
688  if( pCollection == NULL || pCollection->m_pManager != this )
689  {
690  return( false );
691  }
692 
693  //-----------------------------------------------------
694  if( pCollection == m_pTable ) { return( pCollection->Delete_All(bDetach) ); }
695  if( pCollection == m_pTIN ) { return( pCollection->Delete_All(bDetach) ); }
696  if( pCollection == m_pPoint_Cloud ) { return( pCollection->Delete_All(bDetach) ); }
697  if( pCollection == m_pShapes ) { return( pCollection->Delete_All(bDetach) ); }
698 
699  //-----------------------------------------------------
700  if( pCollection->m_Type == SG_DATAOBJECT_TYPE_Grid )
701  {
702  CSG_Grid_Collection **pSystems = (CSG_Grid_Collection **)m_Grid_Systems.Get_Array();
703 
704  size_t i, n;
705 
706  for(i=0, n=0; i<m_Grid_Systems.Get_uSize(); i++)
707  {
708  if( pCollection == pSystems[i] )
709  {
710  if( bDetach )
711  {
712  pSystems[i]->Delete_All(bDetach);
713  }
714 
715  delete(pSystems[i]);
716  }
717  else
718  {
719  pSystems[n++] = pSystems[i];
720  }
721  }
722 
723  if( n < m_Grid_Systems.Get_uSize() )
724  {
725  m_Grid_Systems.Set_Array(n);
726 
727  return( true );
728  }
729  }
730 
731  //-----------------------------------------------------
732  return( false );
733 }
734 
735 //---------------------------------------------------------
736 bool CSG_Data_Manager::Delete(CSG_Data_Object *pObject, bool bDetach)
737 {
738  CSG_Data_Collection *pCollection = _Get_Collection(pObject);
739 
740  if( pCollection && pCollection->Delete(pObject, bDetach) )
741  {
742  if( pCollection->m_Type == SG_DATAOBJECT_TYPE_Grid && pCollection->Count() == 0 )
743  {
744  Delete(pCollection, bDetach);
745  }
746 
747  return( true );
748  }
749 
750  return( false );
751 }
752 
753 //---------------------------------------------------------
754 bool CSG_Data_Manager::Delete(const CSG_Grid_System &System, bool bDetach)
755 {
756  return( Delete(Get_Grid_System(System), bDetach) );
757 }
758 
759 //---------------------------------------------------------
760 bool CSG_Data_Manager::Delete(bool bDetach, bool bUnsaved)
761 {
762  m_pTable ->Delete(bDetach, bUnsaved);
763  m_pTIN ->Delete(bDetach, bUnsaved);
764  m_pPoint_Cloud->Delete(bDetach, bUnsaved);
765  m_pShapes ->Delete(bDetach, bUnsaved);
766 
767  for(size_t i=0; i<Grid_System_Count(); i++)
768  {
769  CSG_Grid_Collection *pSystem = Get_Grid_System(i);
770 
771  pSystem->Delete(bDetach, bUnsaved);
772 
773  delete(pSystem);
774  }
775 
776  m_Grid_Systems.Set_Array(0);
777 
778  return( true );
779 }
780 
781 //---------------------------------------------------------
783 {
784  return( Delete(bDetach, false) );
785 }
786 
787 //---------------------------------------------------------
789 {
790  return( Delete(bDetach, true) );
791 }
792 
793 
795 // //
797 
798 //---------------------------------------------------------
800 {
801  CSG_String s;
802 
803  //-----------------------------------------------------
804  if( Get_Table()->Count() > 0 )
805  {
806  s += CSG_String::Format("___\n%s [%zu %s]\n", _TL("Table"), Get_Table()->Count(), _TL("objects"));
807 
808  for(size_t i=0; i<Get_Table()->Count(); i++)
809  {
810  CSG_Table *pObject = (CSG_Table *)Get_Table()->Get(i);
811 
812  s += CSG_String::Format("- [%d %s] %s\n",
813  pObject->Get_Count(), _TL("records"),
814  pObject->Get_Name()
815  );
816  }
817  }
818 
819  //-----------------------------------------------------
820  if( Get_Shapes()->Count() > 0 )
821  {
822  s += CSG_String::Format("___\n%s [%zu %s]\n", _TL("Shapes"), Get_Shapes()->Count(), _TL("objects"));
823 
824  for(size_t i=0; i<Get_Shapes()->Count(); i++)
825  {
826  CSG_Shapes *pObject = (CSG_Shapes *)Get_Shapes()->Get(i);
827 
828  s += CSG_String::Format("- [%s; %d %s] %s\n",
829  pObject->Get_Type() == SHAPE_TYPE_Point ? _TL("point" ) :
830  pObject->Get_Type() == SHAPE_TYPE_Points ? _TL("points" ) :
831  pObject->Get_Type() == SHAPE_TYPE_Line ? _TL("line" ) :
832  pObject->Get_Type() == SHAPE_TYPE_Polygon ? _TL("polygon") : _TL("unknown"),
833  pObject->Get_Count(), _TL("records"),
834  pObject->Get_Name()
835  );
836  }
837  }
838 
839  //-----------------------------------------------------
840  if( Get_Point_Cloud()->Count() > 0 )
841  {
842  s += CSG_String::Format("___\n%s [%zu %s]\n", _TL("Point Cloud"), Get_Point_Cloud()->Count(), _TL("objects"));
843 
844  for(size_t i=0; i<Get_Point_Cloud()->Count(); i++)
845  {
846  CSG_PointCloud *pObject = (CSG_PointCloud *)Get_Point_Cloud()->Get(i);
847 
848  s += CSG_String::Format("- [%d %s] %s\n",
849  pObject->Get_Count(), _TL("records"),
850  pObject->Get_Name()
851  );
852  }
853  }
854 
855  //-----------------------------------------------------
856 // if( Get_TIN()->Count() > 0 )
857 // {
858 // s += CSG_String::Format("___\n%s [%zu %s]\n", _TL("TIN"), Get_TIN()->Count(), _TL("objects"));
859 //
860 // for(size_t i=0; i<Get_TIN()->Count(); i++)
861 // {
862 // CSG_TIN *pObject = (CSG_TIN *)Get_TIN()->Get(i);
863 //
864 // s += CSG_String::Format("- [%d %s] %s\n",
865 // pObject->Get_Count(), _TL("nodes"),
866 // pObject->Get_Name()
867 // );
868 // }
869 // }
870 
871  //-----------------------------------------------------
872  if( Grid_System_Count() > 0 )
873  {
874  sLong memory = 0;
875 
876  for(size_t i=0; i<Grid_System_Count(); i++)
877  {
878  CSG_Grid_Collection *pSystem = Get_Grid_System(i);
879 
880  s += CSG_String::Format("___\n%s [%s; %zu %s]\n", _TL("Grid System"), pSystem->m_System.Get_Name(), pSystem->Count(), _TL("objects"));
881 
882  for(size_t j=0; j<pSystem->Count(); j++)
883  {
884  if( pSystem->Get(j)->Get_ObjectType() == SG_DATAOBJECT_TYPE_Grid )
885  {
886  CSG_Grid *pObject = (CSG_Grid *)pSystem->Get(j);
887 
888  s += CSG_String::Format("- [%s; %.1fmb] %s\n",
889  SG_Data_Type_Get_Name(pObject->Get_Type()).c_str(),
890  pObject->Get_Memory_Size() / (double)N_MEGABYTE_BYTES,
891  pObject->Get_Name()
892  );
893 
894  memory += pObject->Get_Memory_Size();
895  }
896 
897  if( pSystem->Get(j)->Get_ObjectType() == SG_DATAOBJECT_TYPE_Grids )
898  {
899  CSG_Grids *pObject = (CSG_Grids *)pSystem->Get(j);
900 
901  s += CSG_String::Format("- [%s; %d %s; %.1fmb] %s\n",
902  SG_Data_Type_Get_Name(pObject->Get_Type()).c_str(),
903  pObject->Get_NZ(), _TL("grids"),
904  pObject->Get_Memory_Size() / (double)N_MEGABYTE_BYTES,
905  pObject->Get_Name()
906  );
907 
908  memory += pObject->Get_Memory_Size();
909  }
910  }
911  }
912 
913  s += CSG_String::Format("_\n%s: %.1fmb\n", _TL("Total memory in use by grids"), memory / (double)N_MEGABYTE_BYTES);
914  }
915 
916  //-----------------------------------------------------
917  if( s.is_Empty() )
918  {
919  s += CSG_String::Format("%s - %s\n--- %s ---\n", _TL("Data Manager"), _TL("Summary"), _TL("no data"));
920  }
921  else
922  {
923  s.Prepend(CSG_String::Format("%s - %s\n", _TL("Data Manager"), _TL("Summary")));
924  }
925 
926  //-----------------------------------------------------
927  return( s );
928 }
929 
930 
932 // //
933 // //
934 // //
936 
937 //---------------------------------------------------------
CSG_Grid::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grid.h:519
CSG_Grid_Collection::is_Equal
bool is_Equal(const CSG_Grid_System &System) const
Definition: data_manager.h:140
CSG_Data_Collection::CSG_Data_Collection
CSG_Data_Collection(class CSG_Data_Manager *pManager, TSG_Data_Object_Type Type)
Definition: data_manager.cpp:78
PARAMETER_TYPE_FilePath
@ PARAMETER_TYPE_FilePath
Definition: parameters.h:136
CSG_Data_Manager::Get_Shapes
CSG_Data_Collection * Get_Shapes(void) const
Definition: data_manager.h:172
CSG_Data_Manager::Get_Table
CSG_Data_Collection * Get_Table(void) const
Definition: data_manager.h:169
_TL
#define _TL(s)
Definition: api_core.h:1480
g_Data_Manager
CSG_Data_Manager g_Data_Manager
Definition: data_manager.cpp:62
CSG_Data_Collection::Get
CSG_Data_Object * Get(size_t i) const
Definition: data_manager.h:96
CSG_Data_Collection::Count
size_t Count(void) const
Definition: data_manager.h:94
CSG_Data_Collection::Add
virtual bool Add(CSG_Data_Object *pObject)
Definition: data_manager.cpp:119
data_manager.h
CSG_Array_Pointer::Get_Size
sLong Get_Size(void) const
Definition: api_core.h:381
TSG_Shape_Type
TSG_Shape_Type
Definition: shapes.h:100
CSG_Grid_System
Definition: grid.h:200
SG_File_Cmp_Extension
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
Definition: api_file.cpp:928
CSG_Parameter_List::Get_Item
CSG_Data_Object * Get_Item(int Index) const
Definition: parameters.h:1368
CSG_Data_Manager::Add_PointCloud
CSG_PointCloud * Add_PointCloud(void)
Definition: data_manager.cpp:636
SHAPE_TYPE_Polygon
@ SHAPE_TYPE_Polygon
Definition: shapes.h:105
CSG_Data_Collection::Delete_All
bool Delete_All(bool bDetach=false)
Definition: data_manager.cpp:214
CSG_Tool
Definition: tool.h:149
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:290
CSG_Tool::Execute
bool Execute(bool bAddHistory=false)
Definition: tool.cpp:246
CSG_Data_Collection
Definition: data_manager.h:89
SG_Get_Data_Manager
CSG_Data_Manager & SG_Get_Data_Manager(void)
Definition: data_manager.cpp:65
SG_DATAOBJECT_TYPE_Grids
@ SG_DATAOBJECT_TYPE_Grids
Definition: dataobject.h:119
CSG_Grids::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grids.h:169
CSG_Data_Manager::Add_Shapes
CSG_Shapes * Add_Shapes(TSG_Shape_Type Type=SHAPE_TYPE_Undefined)
Definition: data_manager.cpp:649
CSG_Data_Manager::Exists
bool Exists(CSG_Data_Object *pObject) const
Definition: data_manager.cpp:389
CSG_Data_Object::Get_ObjectType
virtual TSG_Data_Object_Type Get_ObjectType(void) const =0
Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
CSG_Parameter::asDataObject
CSG_Data_Object * asDataObject(void) const
Definition: parameter.cpp:972
CSG_String::Prepend
CSG_String & Prepend(const CSG_String &String)
Definition: api_string.cpp:347
CSG_Data_Manager::Get_Grid_System
CSG_Grid_Collection * Get_Grid_System(size_t i) const
Definition: data_manager.h:175
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:726
CSG_Array_Pointer::Inc_Array
bool Inc_Array(sLong nValues=1)
Definition: api_core.h:388
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
CSG_Tool::Set_Parameter
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition: tool.cpp:1144
CSG_Grid_Collection::Add
virtual bool Add(CSG_Data_Object *pObject)
Definition: data_manager.cpp:277
SG_UI_DATAOBJECT_UPDATE
@ SG_UI_DATAOBJECT_UPDATE
Definition: api_core.h:1509
CSG_TIN
Definition: tin.h:222
SG_File_Exists
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
Definition: api_file.cpp:834
CSG_Grid_System::Get_Name
const SG_Char * Get_Name(bool bShort=true)
Definition: grid_system.cpp:249
CSG_Data_Collection::Get
CSG_Data_Object * Get(const CSG_String &File, bool bNative=true) const
Definition: data_manager.cpp:91
CSG_Data_Object
Definition: dataobject.h:180
CSG_Data_Collection::Exists
virtual bool Exists(CSG_Data_Object *pObject) const
Definition: data_manager.cpp:105
CSG_Grid_Collection::CSG_Grid_Collection
CSG_Grid_Collection(class CSG_Data_Manager *pManager)
Definition: data_manager.cpp:241
CSG_Data_Manager::Add_TIN
CSG_TIN * Add_TIN(void)
Definition: data_manager.cpp:623
CSG_Data_Manager::Add_Grid
CSG_Grid * Add_Grid(const CSG_Grid_System &System, TSG_Data_Type Type=SG_DATATYPE_Undefined)
Definition: data_manager.cpp:662
CSG_Data_Manager::Delete_All
bool Delete_All(bool bDetach=false)
Definition: data_manager.cpp:782
CSG_Grid_Collection::m_System
CSG_Grid_System m_System
Definition: data_manager.h:153
DATAOBJECT_CREATE
#define DATAOBJECT_CREATE
Definition: dataobject.h:130
CSG_Array_Pointer::Get_uSize
size_t Get_uSize(void) const
Definition: api_core.h:382
SG_UI_Msg_Lock
int SG_UI_Msg_Lock(bool bOn)
Definition: api_callback.cpp:465
CSG_Grid::Get_Memory_Size
sLong Get_Memory_Size(void) const
Definition: grid.h:601
CSG_Data_Manager::Delete
bool Delete(CSG_Data_Collection *pCollection, bool bDetach=false)
Definition: data_manager.cpp:686
sLong
signed long long sLong
Definition: api_core.h:158
SG_Get_Tool_Library_Manager
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
Definition: tool_library.cpp:286
SG_UI_DataObject_Add
bool SG_UI_DataObject_Add(CSG_Data_Object *pDataObject, int Show)
Definition: api_callback.cpp:598
CSG_Grids::Get_Grid_Ptr
CSG_Grid * Get_Grid_Ptr(int i) const
Definition: grids.h:248
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:385
CSG_Data_Manager::Add_Table
CSG_Table * Add_Table(void)
Definition: data_manager.cpp:610
SG_Data_Type_Get_Name
CSG_String SG_Data_Type_Get_Name(TSG_Data_Type Type, bool bShort)
Definition: api_core.cpp:122
CSG_Data_Manager::Get_Point_Cloud
CSG_Data_Collection * Get_Point_Cloud(void) const
Definition: data_manager.h:171
CSG_Data_Manager::~CSG_Data_Manager
virtual ~CSG_Data_Manager(void)
Definition: data_manager.cpp:325
SG_DATAOBJECT_TYPE_TIN
@ SG_DATAOBJECT_TYPE_TIN
Definition: dataobject.h:122
SG_DATAOBJECT_TYPE_Grid
@ SG_DATAOBJECT_TYPE_Grid
Definition: dataobject.h:118
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_Grids::Get_Memory_Size
sLong Get_Memory_Size(void) const
Definition: grids.h:251
SHAPE_TYPE_Line
@ SHAPE_TYPE_Line
Definition: shapes.h:104
CSG_Table
Definition: table.h:283
SG_DATAOBJECT_TYPE_Shapes
@ SG_DATAOBJECT_TYPE_Shapes
Definition: dataobject.h:121
SG_DATAOBJECT_TYPE_Undefined
@ SG_DATAOBJECT_TYPE_Undefined
Definition: dataobject.h:124
CSG_Data_Collection::m_pManager
class CSG_Data_Manager * m_pManager
Definition: data_manager.h:116
CSG_Grid_Collection
Definition: data_manager.h:131
TSG_Data_Object_Type
TSG_Data_Object_Type
Definition: dataobject.h:117
CSG_String
Definition: api_core.h:557
CSG_Data_Manager::Add
bool Add(CSG_Data_Object *pObject)
Definition: data_manager.cpp:428
CSG_Tool::Set_Manager
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition: tool.cpp:549
SHAPE_TYPE_Point
@ SHAPE_TYPE_Point
Definition: shapes.h:102
SG_DATAOBJECT_TYPE_Table
@ SG_DATAOBJECT_TYPE_Table
Definition: dataobject.h:120
CSG_Data_Manager
Definition: data_manager.h:164
CSG_String::is_Empty
bool is_Empty(void) const
Definition: api_string.cpp:178
CSG_Grid_Collection::Exists
virtual bool Exists(CSG_Data_Object *pObject) const
Definition: data_manager.cpp:246
CSG_Data_Manager::Get_Summary
CSG_String Get_Summary(void) const
Definition: data_manager.cpp:799
CSG_Array_Pointer::Set_Array
bool Set_Array(sLong nValues, bool bShrink=true)
Definition: api_core.h:387
N_MEGABYTE_BYTES
#define N_MEGABYTE_BYTES
Definition: mat_tools.h:117
CSG_Tool::Get_Parameter
CSG_Parameter * Get_Parameter(const CSG_String &ID) const
Definition: tool.h:183
CSG_Data_Manager::Find
CSG_Data_Object * Find(const CSG_String &File, bool bNative=true) const
Definition: data_manager.cpp:405
CSG_Grid
Definition: grid.h:473
CSG_Array_Pointer::Get_Array
void ** Get_Array(void) const
Definition: api_core.h:384
CSG_Data_Manager::Grid_System_Count
size_t Grid_System_Count(void) const
Definition: data_manager.h:174
CSG_Shapes
Definition: shapes.h:773
CSG_Data_Manager::CSG_Data_Manager
CSG_Data_Manager(void)
Definition: data_manager.cpp:316
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
tool_library.h
SHAPE_TYPE_Points
@ SHAPE_TYPE_Points
Definition: shapes.h:103
CSG_PointCloud
Definition: pointcloud.h:105
CSG_Data_Manager::Delete_Unsaved
bool Delete_Unsaved(bool bDetach=false)
Definition: data_manager.cpp:788
TSG_Data_Type
TSG_Data_Type
Definition: api_core.h:985
CSG_Shapes::Get_Type
virtual TSG_Shape_Type Get_Type(void) const
Definition: shapes.h:807
CSG_Data_Collection::m_Objects
CSG_Array_Pointer m_Objects
Definition: data_manager.h:120
CSG_Data_Collection::m_Type
TSG_Data_Object_Type m_Type
Definition: data_manager.h:118
CSG_Grids
Definition: grids.h:119
CSG_Data_Collection::Delete
bool Delete(CSG_Data_Object *pObject, bool bDetach=false)
Definition: data_manager.cpp:145
CSG_Parameter::asList
class CSG_Parameter_List * asList(void) const
Definition: parameter.cpp:1046
SG_DATAOBJECT_TYPE_PointCloud
@ SG_DATAOBJECT_TYPE_PointCloud
Definition: dataobject.h:123
CSG_Data_Object::is_Valid
virtual bool is_Valid(void) const =0
CSG_Data_Collection::Delete_Unsaved
bool Delete_Unsaved(bool bDetach=false)
Definition: data_manager.cpp:220
CSG_Grid_System::is_Valid
bool is_Valid(void) const
Definition: grid_system.cpp:243
CSG_Data_Collection::~CSG_Data_Collection
virtual ~CSG_Data_Collection(void)
Definition: data_manager.cpp:85
CSG_Grids::Get_NZ
int Get_NZ(void) const
Definition: grids.h:187
DATAOBJECT_NOTSET
#define DATAOBJECT_NOTSET
Definition: dataobject.h:129