コード例 #1
0
ファイル: GwsFdoCommandInsert.cpp プロジェクト: kanbang/Colt
EGwsStatus CGwsFdoInsertCommand::Execute (CGwsMutableFeature & feat)
{
    Clear ();

    EGwsStatus fdoes = eGwsOk;
    if(!m_bIsPrepared) {
        PushStatus (eGwsFdoCommandIsNotPrepared);
        return eGwsFdoCommandIsNotPrepared;
    }

    try
    {
        GetPropertyValues (); // initialize property value collection
        eGwsOkThrow(SetProperties (feat, true)) ;

        FdoPtr<FdoIFeatureReader> pReader = ((FdoIInsert*)m_pCommand.p)->Execute();

        //!FDO may return null pointer even if the command succeed. So remove the following assert.
        //assert (pReader != NULL);

        // Read assigned Id
        if( pReader !=  NULL )
        {
            if (pReader->ReadNext()) {

                // Read the key of just inserted record
                //
                CGwsDataValueCollection  *  keyvals = NULL;

                for (FdoInt32 idx = 0; m_identity != NULL && idx < m_identity->GetCount (); idx ++) {
                    FdoPtr<FdoDataPropertyDefinition>  keyprop =
                        m_identity->GetItem (idx);
                    FdoPtr<FdoDataValue>               val =
                        GwsQueryUtils::GetDataPropertyValue (pReader,
                        keyprop->GetDataType (),
                        keyprop->GetName ());
                    if (val == NULL)
                        continue;
                    if (keyvals == NULL)
                        keyvals = (CGwsDataValueCollection *) CGwsDataValueCollection::Create ();
                    keyvals->Add (val);
                    feat.SetValue (keyprop->GetName (),val);
                }

#ifdef OBJECT_PROPERTIES
                //insert object property values that were cached in SetProperties()
                if(!m_objPropNames.empty())
                {
                    //Get object property class instance array that was cached in SetProperties()
                    int numProps = m_objPropNames.size();
                    for( int i = 0; i<numProps; i++)
                    {
                        const std::wstring strPropName = m_objPropNames[i];
                        const std::wstring objectClassName =
                            acmapFdoUtils::constructObjectClassName(aTOw(m_classname.Class()),strPropName.c_str());

                        //get the object property values
                        AcMapFdoFeatureIterator* featIter = NULL;
                        eGwsOkThrow(feature.GetFeature(wTOa(strPropName.c_str()),featIter));
                        assert(featIter != NULL);
                        //insert the primary keys of the parent feature and the object property values
                        eGwsOkThrow(InsertObjectProperties(objectClassName.c_str(), valList, featIter));
                    }
                }
#endif

                // long ver;
                // Read sequence number
                if (!m_revisionprop.empty()) {
                    FdoInt32 revnum = pReader->GetInt32 (m_revisionprop.c_str ());
                    feat.SetRevisionNumber (revnum);
                }
                feat.SetFeatureId (GWSFeatureId (keyvals));
            }
            pReader->Close();
        }

    } catch(FdoException *e) {
        PushFdoException (eGwsFailedToExecuteCommand, e);
        e->Release();
        fdoes = eGwsFailedToExecuteCommand;

    } catch(EGwsStatus es) {
        PushStatus (es);
        fdoes = es;
    }
    ReleasePropertyValues (); // releases property value collection

    return fdoes;
}
コード例 #2
0
void RfpTestRasterConversion::testRgbToPalette()
{
	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Palette);
	dataModel->SetBitsPerPixel(8);
	dataModel->SetTileSizeX(256);
	dataModel->SetTileSizeY(256);
        try 
        { 
            m_raster->SetDataModel(dataModel);
        }
        catch(FdoException*){/* Ok, expected exception was caught.*/}
        catch(...) { CPPUNIT_ASSERT_MESSAGE ("FdoException expected but got none.", false); }

#ifdef notdef
// this might be useful later when palette support is implemented.
	// get the palette
	FdoPtr<FdoIRasterPropertyDictionary> propDict = m_raster->GetAuxiliaryProperties();
	FdoPtr<FdoDataValue> pal = propDict->GetProperty(L"Palette");
	CPPUNIT_ASSERT(pal->GetDataType() == FdoDataType_BLOB);
	FdoLOBValue* palLOB = static_cast<FdoLOBValue*>(pal.p);
	struct RgbColor
	{
		union {
			struct { FdoByte red; FdoByte green; FdoByte blue; FdoByte alpha; } rgba;
			FdoInt32 packed;
		};
	};
	
	FdoPtr<FdoByteArray> palArray = palLOB->GetData();
	RgbColor* palette = reinterpret_cast<RgbColor*>(palArray->GetData());
	FdoPtr<FdoDataValue> num = propDict->GetProperty(L"NumOfPaletteEntries");
	FdoInt32Value* numInt32 = static_cast<FdoInt32Value*>(num.p);
	FdoInt32 numEntries = numInt32->GetInt32();

    CPPUNIT_ASSERT(numEntries == 61);
    
	// get the data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	// read the strips (black, red, green, blue, white)
	FdoInt32 pixelInStrip[] = {0x00000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00ffffff};
	for (int strip = 0; strip < 5; strip++)
	{
		// read the data pixel by pixel
		for (int row = 0; row < 40; row++)
		{
			for (int i = 0; i < 200; i++)
			{
				FdoByte pal;
				reader->ReadNext(&pal, 0, 1);
				FdoInt32 pixel = palette[pal].packed;
				FdoInt32 colorDiff = (FdoInt32)RGB_COLOR_DIFF(pixel, pixelInStrip[strip]);
				CPPUNIT_ASSERT(colorDiff < 209);
			}
			reader->Skip(56);
		}
	}

	reader->Skip(56 * 256);

	// there is no data left
	FdoByte dummy;
	CPPUNIT_ASSERT(reader->ReadNext(&dummy, 0, 1) == 0);
#endif
}