//--------------------------------------------------------- bool CSG_Table::_Save_Text(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator) { int iField, iRecord; CSG_File Stream; if( Get_Field_Count() > 0 ) { if( Stream.Open(File_Name, SG_FILE_W, false) ) { for(iField=0; iField<Get_Field_Count(); iField++) { Stream.Printf(SG_T("%s%s"), Get_Field_Name(iField), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n")); } for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++) { for(iField=0; iField<Get_Field_Count(); iField++) { Stream.Printf(SG_T("%s"), Get_Record(iRecord)->asString(iField)); Stream.Printf(SG_T("%s"), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n")); } } SG_UI_Process_Set_Ready(); return( true ); } } return( false ); }
//--------------------------------------------------------- bool CSG_PointCloud::is_Compatible(CSG_PointCloud *pPointCloud) const { if( Get_Field_Count() == pPointCloud->Get_Field_Count() ) { for(int i=0; i<Get_Field_Count(); i++) { if( Get_Field_Type(i) != pPointCloud->Get_Field_Type(i) ) { return( false ); } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_Table::_Save_Text(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator) { int iField, iRecord; CSG_File Stream; if( Get_Field_Count() > 0 ) { if( Stream.Open(File_Name, SG_FILE_W, false) ) { for(iField=0; iField<Get_Field_Count(); iField++) { Stream.Printf(SG_T("%s%s"), Get_Field_Name(iField), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n")); } for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++) { for(iField=0; iField<Get_Field_Count(); iField++) { if( !Get_Record(iRecord)->is_NoData(iField) ) { switch( Get_Field_Type(iField) ) { case SG_DATATYPE_String: case SG_DATATYPE_Date: Stream.Printf(SG_T("\"%s\""), Get_Record(iRecord)->asString(iField)); break; default: Stream.Printf(SG_T("%s") , Get_Record(iRecord)->asString(iField)); break; } } Stream.Printf(SG_T("%s"), iField < Get_Field_Count() - 1 ? Separator : SG_T("\n")); } } SG_UI_Process_Set_Ready(); return( true ); } } return( false ); }
//--------------------------------------------------------- CSG_Shape * CSG_PointCloud::Add_Shape(CSG_Table_Record *pCopy, TSG_ADD_Shape_Copy_Mode mCopy) { Add_Point(0.0, 0.0, 0.0); if( pCopy && (mCopy == SHAPE_COPY_ATTR || mCopy == SHAPE_COPY) ) { for(int iField=0; iField<Get_Field_Count() && iField<pCopy->Get_Table()->Get_Field_Count(); iField++) { if( Get_Field_Type(iField) == pCopy->Get_Table()->Get_Field_Type(iField) ) { Set_Value(iField, pCopy->asDouble(iField)); } } } return( _Set_Shape(Get_Count() - 1) ); }
//--------------------------------------------------------- CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint) { SG_UI_Progress_Lock(true); CSG_Shape *pShape = m_Shapes.Get_Shape(0); if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() ) { m_Cursor = m_Points[m_Shapes_Index]; for(int i=0; i<Get_Field_Count(); i++) { switch( Get_Field_Type(i) ) { default: Set_Value(i, pShape->asDouble(i)); break; case SG_DATATYPE_Date: case SG_DATATYPE_String: Set_Value(i, pShape->asString(i)); break; } } Set_Value(0, pShape->Get_Point(0).x); Set_Value(1, pShape->Get_Point(0).y); Set_Value(2, pShape->Get_Z (0) ); } if( iPoint >= 0 && iPoint < Get_Count() ) { if(1|| iPoint != m_Shapes_Index ) { m_Cursor = m_Points[iPoint]; pShape->Set_Point(Get_X(), Get_Y(), 0, 0); pShape->Set_Z (Get_Z() , 0, 0); for(int i=0; i<Get_Field_Count(); i++) { switch( Get_Field_Type(i) ) { default: pShape->Set_Value(i, Get_Value(i)); break; case SG_DATATYPE_Date: case SG_DATATYPE_String: { CSG_String s; Get_Value(i, s); pShape->Set_Value(i, s); } break; } } m_Shapes_Index = iPoint; pShape->m_Index = iPoint; pShape->Set_Selected(is_Selected(iPoint)); } m_Shapes.Set_Modified(false); SG_UI_Progress_Lock(false); return( pShape ); } m_Shapes_Index = -1; SG_UI_Progress_Lock(false); return( NULL ); }
//--------------------------------------------------------- bool CSG_Table::_Save_DBase(const CSG_String &File_Name) { int iField, iRecord, nBytes; CSG_Table_DBase dbf; //----------------------------------------------------- CSG_Table_DBase::TFieldDesc *dbfFields = new CSG_Table_DBase::TFieldDesc[Get_Field_Count()]; for(iField=0; iField<Get_Field_Count(); iField++) { strncpy(dbfFields[iField].Name, SG_STR_SGTOMB(Get_Field_Name(iField)), 11); switch( Get_Field_Type(iField) ) { case SG_DATATYPE_String: default: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)((nBytes = Get_Field_Length(iField)) > 255 ? 255 : nBytes); break; case SG_DATATYPE_Date: dbfFields[iField].Type = DBF_FT_DATE; dbfFields[iField].Width = (BYTE)8; break; case SG_DATATYPE_Char: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)1; break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: case SG_DATATYPE_Long: case SG_DATATYPE_Color: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)0; break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)8; break; } } if( !dbf.Open(File_Name, Get_Field_Count(), dbfFields) ) { delete[](dbfFields); SG_UI_Msg_Add_Error(LNG("[ERR] dbase file could not be opened")); return( false ); } delete[](dbfFields); //----------------------------------------------------- for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++) { CSG_Table_Record *pRecord = Get_Record(iRecord); dbf.Add_Record(); for(iField=0; iField<Get_Field_Count(); iField++) { switch( dbf.Get_FieldType(iField) ) { case DBF_FT_DATE: case DBF_FT_CHARACTER: dbf.Set_Value(iField, SG_STR_SGTOMB(pRecord->asString(iField))); break; case DBF_FT_NUMERIC: dbf.Set_Value(iField, pRecord->asDouble(iField)); break; } } dbf.Flush_Record(); } SG_UI_Process_Set_Ready(); return( true ); }
//--------------------------------------------------------- bool CSG_Table::_Load_DBase(const CSG_String &File_Name) { int iField; CSG_Table_DBase dbf; CSG_Table_Record *pRecord; //----------------------------------------------------- if( dbf.Open(File_Name) ) { Destroy(); for(iField=0; iField<dbf.Get_FieldCount(); iField++) { TSG_Data_Type Type; switch( dbf.Get_FieldType(iField) ) { case DBF_FT_LOGICAL: Type = SG_DATATYPE_Char; break; case DBF_FT_CHARACTER: default: Type = SG_DATATYPE_String; break; case DBF_FT_DATE: Type = SG_DATATYPE_Date; break; case DBF_FT_NUMERIC: Type = dbf.Get_FieldDecimals(iField) > 0 ? SG_DATATYPE_Double : SG_DATATYPE_Long; break; } Add_Field(SG_STR_MBTOSG(dbf.Get_FieldName(iField)), Type); } //------------------------------------------------- if( dbf.Move_First() && dbf.Get_Record_Count() > 0 ) { m_nRecords = m_nBuffer = dbf.Get_Record_Count(); m_Records = (CSG_Table_Record **)SG_Malloc(m_nRecords * sizeof(CSG_Table_Record *)); for(int iRecord=0; iRecord<m_nRecords && SG_UI_Process_Set_Progress(iRecord, m_nRecords); iRecord++) { m_Records[iRecord] = pRecord = _Get_New_Record(iRecord); for(iField=0; iField<Get_Field_Count(); iField++) { switch( Get_Field_Type(iField) ) { case SG_DATATYPE_Char: pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) ); break; case SG_DATATYPE_String: default: pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) ); break; case SG_DATATYPE_Date: pRecord->Set_Value(iField, dbf.asDouble(iField) ); break; case SG_DATATYPE_Long: pRecord->Set_Value(iField, dbf.asInt(iField) ); break; case SG_DATATYPE_Double: pRecord->Set_Value(iField, dbf.asDouble(iField) ); break; } } dbf.Move_Next(); } SG_UI_Process_Set_Ready(); Set_Modified(false); Set_Update_Flag(); _Stats_Invalidate(); } return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_Table::_Load_Text(const CSG_String &File_Name, bool bHeadline, const SG_Char *Separator) { int i, iField, fLength; CSG_String sLine, sField; CSG_File Stream; CSG_Table Table; //----------------------------------------------------- if( Stream.Open(File_Name, SG_FILE_R, false) == false ) { return( false ); } if( !Stream.Read_Line(sLine) ) { return( false ); } //----------------------------------------------------- sLine += Separator; while( (i = sLine.Find(Separator)) >= 0 ) { sField = bHeadline ? sLine.Left(i) : CSG_String::Format(SG_T("FIELD_%02d"), Table.Get_Field_Count() + 1); if( sField[0] == SG_T('\"') && sField[(int)(sField.Length() - 1)] == SG_T('\"') ) // remove quota { sField = sField.AfterFirst('\"').BeforeLast('\"'); } Table.Add_Field(sField, SG_DATATYPE_String); sLine.Remove(0, i + 1); } //----------------------------------------------------- TSG_Data_Type *Type = new TSG_Data_Type[Table.Get_Field_Count()]; for(iField=0; iField<Table.Get_Field_Count(); iField++) { Type[iField] = SG_DATATYPE_Int; } if( !bHeadline ) { Stream.Seek_Start(); } fLength = Stream.Length(); while( Stream.Read_Line(sLine) && sLine.Length() > 0 && SG_UI_Process_Set_Progress(Stream.Tell(), fLength) ) { CSG_Table_Record *pRecord = Table._Add_Record(); sLine += Separator; for(iField=0; iField<Table.Get_Field_Count(); iField++) { if( (i = sLine.Find(Separator)) >= 0 ) { sField = sLine.Left(i); if( sField[0] == SG_T('\"') && sField[(int)(sField.Length() - 1)] == SG_T('\"') ) // remove quota { sField = sField.AfterFirst('\"').BeforeLast('\"'); } if( Type[iField] != SG_DATATYPE_String ) { double Value; if( SG_SSCANF(sField, SG_T("%lf"), &Value) != 1 ) { Type[iField] = SG_DATATYPE_String; } else if( Type[iField] != SG_DATATYPE_Double && Value - (int)Value != 0.0 ) { Type[iField] = SG_DATATYPE_Double; } } pRecord->Set_Value(iField, sField); sLine.Remove(0, i + 1); } else { break; } } } //----------------------------------------------------- if( Table.Get_Count() > 0 ) { for(iField=0; iField<Table.Get_Field_Count(); iField++) { Add_Field(Table.Get_Field_Name(iField), Type[iField]); } for(int iRecord=0; iRecord<Table.Get_Count() && SG_UI_Process_Set_Progress(iRecord, Table.Get_Count()); iRecord++) { CSG_Table_Record *pRecord = _Add_Record(); for(iField=0; iField<Get_Field_Count(); iField++) { switch( Get_Field_Type(iField) ) { default: pRecord->Set_Value(iField, Table[iRecord].asString(iField)); break; case SG_DATATYPE_Int: pRecord->Set_Value(iField, Table[iRecord].asInt (iField)); break; case SG_DATATYPE_Double: pRecord->Set_Value(iField, Table[iRecord].asDouble(iField)); break; } } } } delete[](Type); SG_UI_Process_Set_Ready(); return( Get_Field_Count() > 0 ); }