Exemple #1
0
/////////////////////////////////////////////////////////////////////////////
// Erzeugen eines VT_UI1-SAFEARRAY aus einem Koordinatenfeld
HRESULT CreateSABlobFromVertices (
	double_v &rX, double_v &rY, POINTBASE *pNormal, void *pData, REFCLSID rClsId, SAFEARRAY **pSA)
{
	if (NULL == pSA)
		return E_POINTER;

	COM_TRY {
	// resultierende Größe feststellen
	unsigned long ulSize = 0;
	CBlobService MakeBlobs;

		_ASSERTE(rX.size() == rY.size());
		THROW_FAILED_HRESULT(MakeBlobs.GetBlobSize (rClsId, rX.size(), pData, &ulSize));

	// SAFEARRAY anlegen und Daten übernehmen
	CSafeArray sa (VT_UI1, ulSize);

		if (!sa) _com_issue_error(E_OUTOFMEMORY);
		{
		CSafeArrayLock<BYTE> lock (sa);

			THROW_FAILED_HRESULT(MakeBlobs.MakeBlob (rClsId, rX.size(), rX.begin(), rY.begin(), pNormal, pData, lock));
		} // lock goes out of scope

		*pSA = sa.Detach();		// Ergebnis liefern

	} COM_CATCH;
	return S_OK;
}
Exemple #2
0
// **************************************************************************
// GetValue ()
//
// Description:
//	Return a string representing the value of a variant.
//
// Parameters:
//  VARIANT		&vtVal		Input variant.
//	TCHAR		*pBuffer	Pointer to buffer for output string.
//	int			nBufLen		Size of output buffer.
//
// Returns:
//  void
// **************************************************************************
void CKItemPropertiesDlg::GetValue (VARIANT &vtVal,	// [in]	
									TCHAR *pBuffer, // [out]
									int nBufLen)	// [in]
	{
	ASSERT (pBuffer != NULL);
	ASSERT (nBufLen > 0);

	// Declare a CString to help construct result string:
	CString strVal;

	// Format string according to data type:
	switch (vtVal.vt)
		{
		case VT_BOOL:
			strVal.Format (_T("%d"), vtVal.boolVal);
			break;

		case VT_UI1:
			strVal.Format (_T("%u"), vtVal.bVal);
			break;

		case VT_I1:
			strVal.Format (_T("%d"), vtVal.cVal);
			break;

		case VT_UI2:
			strVal.Format (_T("%u"), vtVal.uiVal);
			break;

		case VT_I2:
			strVal.Format (_T("%d"), vtVal.iVal);
			break;

		case VT_UI4:
			strVal.Format (_T("%u"), vtVal.ulVal);
			break;

		case VT_I4:
			strVal.Format (_T("%d"), vtVal.lVal);
			break;

		case VT_R4:
			strVal.Format (_T("%G"), vtVal.fltVal);
			break;

		case VT_R8:
			strVal.Format (_T("%G"), vtVal.dblVal);
			break;

		case VT_BSTR:
			strVal = vtVal.bstrVal;
			break;

		case VT_DATE:
			{
			bool bSuccess = false;

			// Cariant time to system time (UTC):
			SYSTEMTIME systime;
			if (VariantTimeToSystemTime (vtVal.dblVal, &systime))
				{
				// Get time zone information:
				TIME_ZONE_INFORMATION tTZI;
				if (GetTimeZoneInformation (&tTZI) != TIME_ZONE_ID_INVALID)
					{
					// Localize system time:
					SYSTEMTIME systimelocal;
					if (SystemTimeToTzSpecificLocalTime (&tTZI, &systime, &systimelocal))
						{
						strVal.Format (_T("%02d:%02d:%02d"), 
							systimelocal.wHour, systimelocal.wMinute, systimelocal.wSecond);			

						bSuccess = true;
						}
					}
				}
			
			if (!bSuccess)
				strVal = _T("???");
			}
			break;

		case VT_UI1	| VT_ARRAY:
		case VT_I1	| VT_ARRAY:
		case VT_UI2	| VT_ARRAY:
		case VT_I2	| VT_ARRAY:
		case VT_UI4	| VT_ARRAY:
		case VT_I4	| VT_ARRAY:
		case VT_R4	| VT_ARRAY:
		case VT_R8	| VT_ARRAY:
			{
			CSafeArray *pSafeArr = (CSafeArray *) vtVal.parray;
			DWORD dwCols = pSafeArr->GetNumCols ();
			DWORD dwSize = pSafeArr->GetByteLength ();
			ULONG cbElements = pSafeArr->cbElements;
			LPBYTE lpByte = (LPBYTE)pSafeArr->pvData;
			DWORD dwCol = 0;

			// Start row delimiter:
			strVal = _T("[ ");

			// Cycle through the elements:
			for (DWORD i = 0; i < dwSize; i += cbElements, lpByte += cbElements)
				{
				TCHAR szNum[32];

				// Format element according to data size:
				if (cbElements == 1)
					{
					if (vtVal.vt ==	(VT_UI1 | VT_ARRAY))
						_stprintf (szNum, _T("%u"), *lpByte);
					else
						_stprintf (szNum, _T("%d"), *(char *)lpByte);
					}
				
				else if (cbElements == 2)
					{
					if (vtVal.vt ==	(VT_UI2 | VT_ARRAY))
						_stprintf (szNum, _T("%u"), *(WORD *)lpByte);
					else 
						_stprintf (szNum, _T("%d"), *(short *)lpByte);
					}
				
				else if (cbElements == 4)
					{
					if (vtVal.vt ==	(VT_R4	| VT_ARRAY))
						_stprintf (szNum, _T("%G"), *(float *)lpByte);
					else if (vtVal.vt ==	(VT_UI4	| VT_ARRAY))
						_stprintf (szNum, _T("%u"), *(DWORD *)lpByte);
					else if (vtVal.vt ==	(VT_I4	| VT_ARRAY))
						_stprintf (szNum, _T("%d"), *(DWORD *)lpByte);
					}

				else if (cbElements == 8)
					_stprintf (szNum, _T("%G"), *(double *)lpByte);

				else
					{
					ASSERT (FALSE);
					}

				// Delimit each element within the row with a comma:
				if (dwCol != 0)
					strVal += _T(", ");

				// Append the formatted element data:
				strVal += szNum;

				// Terminate each row (except the last):
				if (++dwCol == dwCols)
					{
					if (i < dwSize - cbElements) 
						strVal += _T(" ] [ ");

					dwCol = 0;
					}
				}

			// End delimiter:
			strVal += _T(" ]");
			}
			break;

		default:
			// Unsupported datatype:
			strVal = _T ("<Bad VARTYPE>");
			break;
		}

	// Copy value to output buffer:
	lstrcpyn (pBuffer, strVal, nBufLen);
	}
Exemple #3
0
CArcConversion::Convert1(double StartX, double StartY, double OriginX, double OriginY, double EndX, double EndY, SAFEARRAY ** PolyLineArc)
{

//bool KreisbogenApprox (EFlaeche* pBE, double OriginX, double OriginY, double StartX, double StartY, double EndX,
//					   double EndY, DoublePair dUF, double dPrec)

//	TX_ASSERT (pBE != NULL);
//	TX_ASSERT (dPrec > 0);

//	if (! pBE || dPrec <= 0) return false;

//double m_dAnisotropy = dUF.Y() / dUF.X();	// Relation bei geodätischen Koordinaten

	OriginX *= m_dAnisotropy;
	StartX *= m_dAnisotropy;
	EndX *= m_dAnisotropy;
//	dPrec *= dUF.Y();

double dxa = OriginX - EndX;
double dya = OriginY - EndY;
double dxb = StartX - OriginX;
double dyb = StartY - OriginY;
double dxc = EndX - StartX;
double dyc = EndY - StartY;
double cq = dxc*dxc + dyc*dyc;			// c² (c ist die Basis des gleichschenkligen Dreiecks)
// a und b müßten eigentlich beide gleich der Pufferbreite sein; durch die Digitalgeometrie ist
// dies aber nicht garantiert, deshalb nachfolgend die Mittelbildung
double dRadius = (sqrt(dxa*dxa + dya*dya) + sqrt(dxb*dxb + dyb*dyb)) / 2.;

//=== Berechnung des Startwinkels der Strecke (OriginX,OriginY)-(StartX,StartY) ==========================
double dSinStartW = (StartY - OriginY) / dRadius;
	if (dSinStartW > 1.) dSinStartW = 1.;
	if (dSinStartW < -1.) dSinStartW = -1.;

double dStartW = asin (dSinStartW);	// Anstiegswinkels der Strecke (OriginX,OriginY)-(StartX,StartY)											
									// asin liefert Werte zwischen -90° und +90°, deshalb noch
									// evtl. Transformationen entspr. der Quadranten
	if (StartX < OriginX)					
		dStartW = Pi - dStartW;
	else if (StartY < OriginY)
		dStartW = 2.*Pi + dStartW;

//=== Berechnung des Endwinkels der Strecke (OriginX,OriginY)-(EndX,EndY) ==========================
double dSinEndW = (EndY - OriginY) / dRadius;
	if (dSinEndW > 1.) dSinEndW = 1.;
	if (dSinEndW < -1.) dSinEndW = -1.;

double dEndW = asin (dSinEndW);	// Anstiegswinkels der Strecke (OriginX,OriginY)-(StartX,StartY)											
									// asin liefert Werte zwischen -90° und +90°, deshalb noch
									// evtl. Transformationen entspr. der Quadranten
	if (EndX < OriginX)					
		dEndW = Pi - dEndW;
	else if (EndY < OriginY)
		dEndW = 2.*Pi + dEndW;

//==================================================================
/*double dCosSekW = 1. - cq/(2.*dRadius*dRadius);	// Cosinus des Kreisbogenwinkels (mit Kosinussatz)


	if (dCosSekW > 1. )
		dCosSekW = 1.;
	if (dCosSekW < -1. )
		dCosSekW = -1.;

double dSekW = acos(dCosSekW);		// Sektorwinkel (acos liefert 0 ... Pi)
*/
//=== Sektorenwinkel ===============================================================================
double dSekW = dEndW - dStartW;
	if( dSekW < 0 )
		dSekW += 2 * Pi;

double dSegW;
double dBogLaenge;
short iKAnz;

//=== Anzahl der Stützpunkte =======================================================================
	if( m_dPrecision < 0 ) {	// Angabe in Bogenmaß
		iKAnz = (short)ceil(dSekW / ((-m_dPrecision / 360) * 2 * Pi));
	}
	else {
		dBogLaenge = dSekW * dRadius;	// Länge des Kreisbogens
		iKAnz = (short) floor (dBogLaenge/m_dPrecision);	// Anzahl der Kanten
	}

	if( iKAnz  != 0 )  	// sonst braucht nichts mehr berechnet zu werden
		dSegW = dSekW / iKAnz;					// Winkel eines n-Eck-Segmentes

	CSafeArray sa (VT_R8, (iKAnz + 1) * 2 );
	{
		CSafeArrayLock<double> data(sa);
double dWi = dStartW;
		*((double*)data) = StartX;
		*((double*)data+1) = StartY;
		*((double*)data+iKAnz*2) = EndX;
		*((double*)data+iKAnz*2+1) = EndY;
		for (short i = 1; i < iKAnz; i++) {
			dWi += dSegW;
			*((double*)data+i*2) = (OriginX + dRadius*cos(dWi))/m_dAnisotropy;
			*((double*)data+i*2+1) = OriginY + dRadius*sin(dWi);
		}
	}
	*PolyLineArc = sa.Detach();
	return S_OK;
}