SuperMapLpPropertyDefinition::SuperMapLpPropertyDefinition(SuperMapLpClassDefinition *parentLpClass, UGC::UGDatasetVector* pDatasetVector, UGC::UGFieldInfo* fieldInfo, FdoPropertyDefinition* configLogicalProperty)
:
	m_fieldInfo(fieldInfo),
	m_parentLpClass(parentLpClass) // week reference
{
	if(m_fieldInfo != NULL)
		ConvertPhysicalToLogical(m_fieldInfo);
	else
		ConvertLogicalToPhysical(pDatasetVector,configLogicalProperty);

	// 把逻辑物理属性添加到父逻辑物理类中
	FdoPtr<SuperMapLpPropertyDefinitionCollection> lpProperties = m_parentLpClass->GetLpProperties();
    if (!lpProperties->Contains (GetName ()))
        lpProperties->Add(this);
}
void SuperMapLpPropertyDefinition::ConvertPhysicalToLogical(UGC::UGFieldInfo* fieldInfo)
{
	if(m_fieldInfo == NULL)
	{
		m_fieldInfo = fieldInfo;
	}
    VALIDATE_POINTER(m_fieldInfo);

	// 逻辑的FDO属性名及为物理数据集的字段名
	//FdoStringP pLogicalPropertyName = fieldInfo->m_strName;
	FdoStringP pLogicalPropertyName = SuperMapUtil::StringToWString(fieldInfo->m_strName.Cstr()).c_str(); //modified by majun, 支持汉字字段
	FdoString* logicalPropertyName = (FdoString*)pLogicalPropertyName;

	FdoString* logicalPropertyDescription = L"";
	
	// 创建逻辑属性
	m_logicalProperty = FdoDataPropertyDefinition::Create(logicalPropertyName, logicalPropertyDescription);

	// 属性字段物理属性转换
	FdoDataType data_type ;
	FdoInt32 nType = fieldInfo->m_nType; // ugc的字段类型
	//TRACE(_T("SuperMapLpPropertyDefinition::ConvertPhysicalToLogical..[%ls]...[%d]\n"), logicalPropertyName, nType);
	switch(nType)
	{
	case UGC::UGFieldInfo::Boolean:
		data_type = FdoDataType_Boolean;
		break;
	case UGC::UGFieldInfo::Byte:
	case UGC::UGFieldInfo::Char:
		data_type = FdoDataType_Byte;
		break;
	case UGC::UGFieldInfo::Integer:
		data_type = FdoDataType_Int16;
		break;
	case UGC::UGFieldInfo::Long:   
		data_type = FdoDataType_Int32;
		break;
	case UGC::UGFieldInfo::Single:
	case UGC::UGFieldInfo::Float:
		data_type = FdoDataType_Single;
		break;
	case UGC::UGFieldInfo::Double:
		data_type = FdoDataType_Double;
		break;
	case UGC::UGFieldInfo::Date:
	case UGC::UGFieldInfo::Time:
		data_type = FdoDataType_DateTime;
		break;
	case UGC::UGFieldInfo::Decimal:
		data_type = FdoDataType_Decimal;
		break;
	case UGC::UGFieldInfo::Binary:
	case UGC::UGFieldInfo::LongBinary:
	case UGC::UGFieldInfo::VarBinary:
	case UGC::UGFieldInfo::TimeStamp:
		data_type = FdoDataType_BLOB;
		break;
	case UGC::UGFieldInfo::Text:
	case UGC::UGFieldInfo::Memo:
	case UGC::UGFieldInfo::NVarChar:
		//data_type = FdoDataType_CLOB;
		data_type = FdoDataType_String; 
		break;
	default:
		return;  //其他可能类型字段暂不转换
	}


	m_logicalProperty->SetDataType(data_type);

	// 如果是字符串类型设置长度
	if (data_type == FdoDataType_String)
	{
		if(fieldInfo->m_nType == UGC::UGFieldInfo::NVarChar)
			m_logicalProperty->SetLength(fieldInfo->m_nSize * 2);
		else
			m_logicalProperty->SetLength(fieldInfo->m_nSize);
	}
		
	// 如果是十进制类型设置位数和精度
	if (data_type == FdoDataType_Decimal)
	{
		m_logicalProperty->SetPrecision(fieldInfo->m_nPrecision);
		m_logicalProperty->SetScale(fieldInfo->m_nScale);
	}

	FdoPtr<FdoClassDefinition> logicalClass = m_parentLpClass->GetLogicalClass(); //各种逻辑属性要加入此类中
		
	FdoPtr<FdoPropertyDefinitionCollection> logicalProperties = logicalClass->GetProperties();

	// 如果有重复字段名返回
	if (logicalProperties->Contains (m_logicalProperty->GetName ())) 
		return;

	// modified by zhouxu 2007-12-18
	// 对Sm开头的字段除了SmUserId以外都设为只读。/ 并且加为逻辑类的标识属性
	if((0 == wcscmp (L"SmGeometry", pLogicalPropertyName)) 
	|| (0 == wcscmp(L"SMGEOMETRY",pLogicalPropertyName))) //modified by zhouxu 2007-12-7 //added by majun ,要素类中去掉SmGeometry字段
	{
		return;
	}
	else if((0 == wcscmp(L"SmUserID", pLogicalPropertyName))
	|| (0 == wcscmp(L"SMUSERID", pLogicalPropertyName)))
	{
		m_logicalProperty->SetReadOnly(false);
		m_logicalProperty->SetIsAutoGenerated(false);	
		m_logicalProperty->SetNullable(false);
		logicalProperties->Add(m_logicalProperty);
	}
	else if((0 == wcscmp(L"Sm", pLogicalPropertyName.Mid(0,2)))
		|| (0 == wcscmp(L"SM", pLogicalPropertyName.Mid(0,2))))
	{
		m_logicalProperty->SetReadOnly(true);//m_logicalProperty->SetReadOnly(true);
		m_logicalProperty->SetIsAutoGenerated(true);
		m_logicalProperty->SetNullable(false);
		//// 作为一个标识属性
		//FdoPtr<FdoDataPropertyDefinitionCollection> pIdentityProperties = logicalClass->GetIdentityProperties();
		//VALIDATE_POINTER(pIdentityProperties);
		logicalProperties->Add(m_logicalProperty);
		//pIdentityProperties->Add(m_logicalProperty);
	}
	else
	{
		m_logicalProperty->SetReadOnly(false);
		m_logicalProperty->SetIsAutoGenerated(false);	
		m_logicalProperty->SetNullable(true);
		logicalProperties->Add(m_logicalProperty);
	}

}