Beispiel #1
0
void CBMP2TXT::OnOK() 
{
  if (strSaveTXTName.IsEmpty() || strOpenBMPName.IsEmpty ())
	{
		AfxMessageBox("\n 抱歉,请选择位图文件名和另存为的文本文件名! ");
		return;
	}
  
  CString strTemp;
    strTemp="文本文件:"+strSaveTXTName+"转换成功!";
	if (!ConvertToText(strOpenBMPName,strSaveTXTName))
	{
		AfxMessageBox("抱歉, 转换失败!");
	}
	else
        AfxMessageBox(strTemp);
	
//	CDialog::OnOK();
}
Beispiel #2
0
void CObjektPool::WriteBack(bool fStatus)
{
CTriasObjekt *pTO;
CGeoObj *pGO;
CPunktFolge *pPF;
CPunkt *pPT;
CString text, id, key;
POSITION pos, posMM;
int a, j, nr, anzahl;
long l, z, max, kp = 1L;
long *pkp = NULL;

CString strPrepared;

	VERIFY(strPrepared.LoadString(IDS_OBJECTSPREPARED));
	anzahl = m_omGeoObjekte.GetCount();
	((CEDBSExtension*)g_pTE) -> SetDefaultStatusTexte(strPrepared, NULL, NULL, "  ");

CString strPrepare;

	VERIFY(strPrepare.LoadString(IDS_PREPAREOBJECTS));
	((CEDBSExtension*)g_pTE) -> InitStatusDialog(strPrepare, (ULONG)anzahl, NULL );

	if (PrepareObjTeile()) {
	// nicht abgebrochen
	CString strSaved;

		VERIFY(strSaved.LoadString(IDS_OBJECTSSAVED));
		((CEDBSExtension*)g_pTE) -> SetDefaultStatusTexte(strSaved, NULL, NULL, "  ");

	CString strSave;

		VERIFY(strSave.LoadString(IDS_SAVEOBJECTS));
		nr = 0;
		anzahl = m_omGeoObjekte.GetCount();			// sind jetzt u.U. weniger
		((CEDBSExtension*)g_pTE) -> InitStatusDialog(strSave, (ULONG)anzahl, NULL );

		for (pos = m_omGeoObjekte.GetStartPosition(); pos != NULL; /**/)
		{
			m_omGeoObjekte.GetNextAssoc(pos, id, (CObject *&)pGO);

		//	------------------------------------------------------------------------------------
		//	Hier ansetzen um Objekte mit Löchern zu identifizieren!
		//	------------------------------------------------------------------------------------
			((CEDBSExtension *)g_pTE) -> SetupStatus((ULONG)nr++);
			if (((CEDBSExtension *)g_pTE) -> NutzerAbbruch())
				break;		// abgebrochen

		//	------------------------------------------------------------------------------------
		//	Fallunterscheidung: Linienobjekte mit mehreren, nicht verbundenen Linienabschnitten
		//						werden in mehrere Objekte gesplittet!
		//	------------------------------------------------------------------------------------
			if (( pGO -> AnzahlLinien() == 1 ) && ( pGO -> ObjTyp() != 'L' ))
				if ( pGO -> Punkte(0) -> Geschlossen())
					pGO -> ObjTyp() = 'F';

			if (( pGO -> ObjTyp() == 'F' ) && ( pGO -> AnzahlLinien() > 1 ))
			{
				// Flächen mit nicht geschlossenen Konturen aussondern!
				for ( j = 0; j < pGO -> AnzahlLinien(); j++ )
					if ( !pGO -> Punkte( j ) -> Geschlossen())
						pGO -> ObjTyp() = 'L';
			}
			if (( pGO -> ObjTyp() == 'L' ) && ( pGO -> AnzahlLinien() > 1 ))
			{
			CxString strUID;

				for (int loop = 0; loop < pGO -> AnzahlLinien(); loop++)
				{
					pTO = new CTriasObjekt();
					pkp = &kp;

					if ( pTO ) {
						pTO -> ONr() = 0L;				// neues Objekt!
						pTO -> Neu() = TRUE;

						pTO -> Ident() = g_pTriasInterface -> GetIdent (pGO -> Folie(), pGO -> ObjektArt(), pGO -> Merkmale());
						max = z = 0L;
						a = 0;
						z = pGO -> AnzahlPunkte( loop );
						pTO -> AnzahlPunkte() = z;
						pTO -> XKoord( new double[z+1]);
						pTO -> YKoord( new double[z+1]);
						pTO -> KonturPunkte( pkp );
						pkp[0] = z;
						z = 0L;

						pPF = pGO -> Punkte( loop );
						for ( l = 0; l < pPF -> GetSize(); l++ )
						{	
							pPT = (CPunkt*)pPF -> GetAt( (int)l );
							*((double*)pTO -> XKoord() + z) = pPT -> Rechts();
							*((double*)pTO -> YKoord() + z) = pPT -> Hoch();
							z++;
						}

						pTO -> ObjTyp() = OGLinie;
						pTO -> AnzahlKonturen() = 1;
						strUID.Empty();
						strUID.printf( "%s_%d", (const char*)pGO -> UniqueIdent(), loop );
						pTO -> UniqueIdent() = strUID;

						if (!pGO -> Folie().IsEmpty())
							pTO -> AddTextMerkmal ("ATKIS-Folie", pGO -> Folie());
						if (!pGO -> ObjektArt().IsEmpty())
							pTO -> AddTextMerkmal ("ATKIS-Objektart", pGO -> ObjektArt());
						pTO -> AddTextMerkmal ("ATKIS-Dateiname", g_pTriasInterface -> GetActFileName());

						posMM = pGO -> GetMMStartPos();
						while ( posMM )
						{	
							pGO -> GetMMNext( posMM, key, text );
							pTO -> AddTextMerkmal( key, text );
						}

						pTO -> WriteBack();
						pTO -> KonturPunkte( NULL );	// weil: &kp nicht freigeben!!!
						delete pTO;
					}	
				}	
			}
			else {
				pTO = new CTriasObjekt();
				if ( pGO -> AnzahlLinien() || pGO -> ObjNr())
				{	
					if ( pGO -> AnzahlLinien() > 1 )	
						pkp = new long[pGO -> AnzahlLinien()];
					else
						pkp = &kp;

					if ( pTO )
					{	
						if ( pGO -> ObjNr())
							pTO -> ONr() = pGO -> ObjNr();
						else
							pTO -> ONr() = 0L;				// neues Objekt!

						pTO -> Ident() = g_pTriasInterface -> GetIdent(pGO -> Folie(), pGO -> ObjektArt(), pGO -> Merkmale());
						max = z = 0L;
						a = 0;

					// Gesamtzahl Punkte und Hypothese für Aussenkontur ermitteln
						for ( j = 0; j < pGO -> AnzahlLinien(); j++)
						{	
							z += pGO -> AnzahlPunkte( j );
							if (pGO -> AnzahlPunkte(j) > max)
							{
								max = pGO -> AnzahlPunkte( j );
								a = j;
							}	
						}

						pTO -> AnzahlPunkte() = z;
						pTO -> XKoord(new double[z+1]);
						pTO -> YKoord(new double[z+1]);
						pTO -> KonturPunkte(pkp);
						z = 0L;

						if (pGO -> AnzahlLinien())
						{	
						// zuerst die Aussenkontur eintragen!
							pPF = pGO -> Punkte( a );
							for ( l = 0; l < pPF -> GetSize(); l++ )
							{
								pPT = (CPunkt*)pPF -> GetAt( (int)l );
								*((double*)pTO -> XKoord() + z) = pPT -> Rechts();
								*((double*)pTO -> YKoord() + z) = pPT -> Hoch();
								z++;
							}	
						}
						pkp[0] = max;

						if ( pGO -> ObjTyp() == 'F' )
						{	
							if ( pGO -> AnzahlLinien())
							{	if ( pGO -> AnzahlPunkte( 0 ) == 1 )
									pTO -> ObjTyp() = OGPunkt;
								else
									pTO -> ObjTyp() = OGFlaeche;
							}	
						}
						else if (pGO -> ObjTyp() == 'L')
							pTO -> ObjTyp() = OGLinie;
						else if (pGO -> ObjTyp() == 'P') {
						// ggf. Textobjekt draus machen
							if (!g_pTriasInterface -> MakeText(pGO -> ObjektArt())) 
								pTO -> ObjTyp() = OGPunkt;
							else 
								ConvertToText (pGO, pTO);

						} else if (pGO -> AnzahlLinien()) {	
							if (pGO -> AnzahlPunkte( 0 ) == 1) {
							// ggf. Textobjekt draus machen
								if (!g_pTriasInterface -> MakeText(pGO -> ObjektArt())) 
									pTO -> ObjTyp() = OGPunkt;
								else 
									ConvertToText (pGO, pTO);
							} else {
								if (pGO -> Punkte(0) -> Geschlossen())
									pTO -> ObjTyp() = OGFlaeche;
								else
									pTO -> ObjTyp() = OGLinie;
							}
						}

						pTO -> AnzahlKonturen() = pGO -> AnzahlLinien();
						pTO -> UniqueIdent() = pGO -> UniqueIdent();

					// Standard-Attribute erzeugen
						if (!pGO -> ObjNr())
						{	
							pTO -> Neu() = TRUE;
							if (!pGO -> Folie().IsEmpty())
								pTO -> AddTextMerkmal ("ATKIS-Folie", pGO -> Folie());
							if (!pGO -> ObjektArt().IsEmpty())
								pTO -> AddTextMerkmal ("ATKIS-Objektart", pGO -> ObjektArt());
							pTO -> AddTextMerkmal ("ATKIS-Dateiname", g_pTriasInterface -> GetActFileName());
						}

					// alle sonstigen Attribute übernehmen
						posMM = pGO -> GetMMStartPos();
						while ( posMM )
						{
							text.Empty();
							pGO -> GetMMNext( posMM, key, text );
							pTO -> AddTextMerkmal( key, text );
						}

						for ( j = 0; j < pGO -> AnzahlLinien(); j++ ) {	
							if ( j != a ) {	
								if ( j < a )
									pkp[j+1] = pGO -> AnzahlPunkte( j );
								else
									pkp[j]   = pGO -> AnzahlPunkte( j );

								pPF = pGO -> Punkte( j );
								for ( l = 0; l < pPF -> GetSize(); l++ )
								{	
									pPT = (CPunkt*)pPF -> GetAt( (int)l );
									*((double*)pTO -> XKoord() + z) = pPT -> Rechts();
									*((double*)pTO -> YKoord() + z) = pPT -> Hoch();
									z++;
								}	
							}	
						}
					}	
				}
				else if (pGO -> IsFloeDelta()) { 
				HOBJECT lONr = g_pTriasInterface -> FindObject(pGO -> UniqueIdent());

					if (INVALID_HOBJECT != lONr) {
					// ggf. reine Attributkorrektur (#HK011114)
					// war in einem FLOE-Satz (DLTA1001) und muß Bezug haben
						pTO -> UniqueIdent() = pGO -> UniqueIdent();

					// Standard-Attribute erzeugen
//						pTO -> ONr() = pGO -> ObjNr();
						if (!pGO -> Folie().IsEmpty())
							pTO -> AddTextMerkmal ("ATKIS-Folie", pGO -> Folie());
						if (!pGO -> ObjektArt().IsEmpty())
							pTO -> AddTextMerkmal ("ATKIS-Objektart", pGO -> ObjektArt());
						pTO -> AddTextMerkmal ("ATKIS-Dateiname", g_pTriasInterface -> GetActFileName());

					// alle sonstigen Attribute übernehmen
						posMM = pGO -> GetMMStartPos();
						while (posMM)
						{
							text.Empty();
							pGO -> GetMMNext( posMM, key, text );
							pTO -> AddTextMerkmal( key, text );
						}

						pTO -> ONr() = lONr;
						pTO -> Neu() = FALSE;
					}
				}

				if ((pTO -> ObjTyp() == OGLinie) && (pTO -> AnzahlKonturen() > 1))
				{
				CString	text = "Nicht verbundene Linienabschnitte! UID: ";

					text += pTO -> UniqueIdent();
					AfxMessageBox(text);
				}

				pTO -> WriteBack();
				pTO -> KonturPunkte( NULL );	// weil: &kp nicht freigeben!!!
				if ( pGO -> AnzahlLinien() > 1 )
					delete pkp;
				delete pTO;
			}
		}
	}

	for (pos = m_omGeoObjekte.GetStartPosition(); pos != NULL; )
	{	
		m_omGeoObjekte.GetNextAssoc( pos, id, (CObject*&)pGO );
		delete pGO;
	}
	m_omGeoObjekte.RemoveAll();
}	// WriteBack
Datum serialize_record( PG_FUNCTION_ARGS )
{
//	FILE* log;

//	log = fopen("/var/lib/postgresql/serializer.log", "a");
	HeapTupleHeader rec = PG_GETARG_HEAPTUPLEHEADER(0);

	HeapTupleData tuple;
	bool		needComma = false;
	int		 i;
	Datum	  *values;
	bool	   *nulls;
	StringInfoData buf;
	char *conversion_buf;

	/* Extract type info from the tuple itself */
	Oid tupType = HeapTupleHeaderGetTypeId(rec);
	int32 tupTypmod = HeapTupleHeaderGetTypMod(rec);
	TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
	int ncolumns = tupdesc->natts;

	/* Build a temporary HeapTuple control structure */
	tuple.t_len = HeapTupleHeaderGetDatumLength(rec);
	ItemPointerSetInvalid(&(tuple.t_self));
	tuple.t_tableOid = InvalidOid;
	tuple.t_data = rec;

//	fprintf(log, "Doing serialize_record\n");
//	fflush(log);

	values = (Datum *) palloc(ncolumns * sizeof(Datum));
	nulls = (bool *) palloc(ncolumns * sizeof(bool));

	/* Break down the tuple into fields */
	heap_deform_tuple(&tuple, tupdesc, values, nulls);

	/* And build the result string */
	initStringInfo(&buf);

	appendStringInfoChar(&buf, '{');

	for (i = 0; i < ncolumns; i++)
	{
		Oid		 column_type = tupdesc->attrs[ i ]->atttypid;
		char	   *value;
		char	   *column_name;
		char 		type_category;
		HeapTuple 	type_tuple;
		FmgrInfo flinfo;

		/* Ignore dropped columns in datatype */
		if (tupdesc->attrs[i]->attisdropped)
			continue;

		if (nulls[i])
		{
			/* emit nothing... */
			continue;
		}

		if (needComma)
			appendStringInfoChar(&buf, ',');

		needComma = true;


		/* obtain column name */
		column_name = SPI_fname( tupdesc, i + 1 );

		/* obtain type information from pg_catalog */
		type_tuple = SearchSysCache1( TYPEOID, ObjectIdGetDatum(column_type) );
		if (!HeapTupleIsValid( type_tuple ))
			elog(ERROR, "cache lookup failed for relation %u", column_type);

		type_category = ((Form_pg_type) GETSTRUCT( type_tuple ))->typcategory;

		ReleaseSysCache( type_tuple );

		/* append column name */
		appendStringInfoChar(&buf, '"');
		appendStringInfoString(&buf, column_name);
		appendStringInfoString(&buf, "\":");

		switch( type_category )
		{
			// http://www.postgresql.org/docs/current/static/catalog-pg-type.html#CATALOG-TYPCATEGORY-TABLE

			case 'A': //array
				//call to serialize_array( ... )

				MemSet( &flinfo, 0, sizeof( flinfo ) );
				flinfo.fn_addr = serialize_array;
				flinfo.fn_nargs = 1;
				flinfo.fn_mcxt = fcinfo->flinfo->fn_mcxt;

				value = PG_TEXT_DATUM_GET_CSTR( FunctionCall1( &flinfo, values[ i ] ) );

				appendStringInfoString(&buf, value);
			break;

			case 'C': //composite
				//recursive call to serialize_record( ... )
				MemSet( &flinfo, 0, sizeof( flinfo ) );
				flinfo.fn_addr = serialize_record;
				flinfo.fn_nargs = 1;
				flinfo.fn_mcxt = fcinfo->flinfo->fn_mcxt;

				value = PG_TEXT_DATUM_GET_CSTR( FunctionCall1( &flinfo, values[ i ] ) );

				appendStringInfoString(&buf, value);
			break;

			case 'N': //numeric

				conversion_buf = NULL;
				// get column text value
//				fprintf(log, "Calling ConvertToText\n");
//				fflush(log);
				value = ConvertToText( values[ i ], column_type, fcinfo->flinfo->fn_mcxt, &conversion_buf );
//				fprintf(log, "ConvertToText succeded\n");
//				fflush(log);

				appendStringInfoString(&buf, value);
//				fprintf(log, "append.... succeded\n");
//				fflush(log);

				if(conversion_buf != NULL) {
					pfree(conversion_buf);
					conversion_buf = NULL;
				}

			break;

			case 'B': //boolean
				appendStringInfoString(&buf,
					// get column boolean value
					DatumGetBool( values[ i ] ) ? "true" : "false"
				);
			break;

			default: //another

				conversion_buf = NULL;
				// get column text value
//				fprintf(log, "Calling ConvertToText\n");
//				fflush(log);
				value = ConvertToText( values[ i ], column_type, fcinfo->flinfo->fn_mcxt, &conversion_buf );
//				fprintf(log, "ConvertToText succeded\n");
//				fflush(log);

				appendStringInfoQuotedString(&buf, value);
//				fprintf(log, "append.... succeded\n");
//				fflush(log);

				if(conversion_buf != NULL) {
					pfree(conversion_buf);
					conversion_buf = NULL;
				}
		}
	}

	appendStringInfoChar(&buf, '}');

	pfree(values);
	pfree(nulls);
	ReleaseTupleDesc(tupdesc);

//	fclose(log);

	PG_RETURN_TEXT_P( PG_CSTR_GET_TEXT( buf.data ) );
}