Show
Ignore:
Timestamp:
11/27/07 20:09:45 (12 months ago)
Author:
gyuque
Message:

lang/ruby/RubyESRIShape: polyline support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/RubyESRIShape/Shape.cpp

    r2059 r2062  
    55#include "Shape.h" 
    66 
    7 extern "C" VALUE getRubyESRIShapePolygonClass(); 
    8 extern "C" VALUE getRubyESRIShapePointClass(); 
    9 extern "C" VALUE getRubyESRIShapeBoundingBoxClass(); 
     7extern "C" { 
     8VALUE getRubyESRIShapePolygonClass(); 
     9VALUE getRubyESRIShapePolylineClass(); 
     10VALUE getRubyESRIShapePointClass(); 
     11VALUE getRubyESRIShapeBoundingBoxClass(); 
     12} 
    1013 
    1114Shape::Shape(void) 
     
    169172                rv = ESHP_OK; 
    170173        } 
     174        else if (type == ESHT_PolyLine || type == ESHT_PolyLineZ) 
     175        { 
     176                ShpPolyline* pln = new ShpPolyline( 
     177                        (type == ESHT_PolyLineZ) ? SHPRECORD_WITH_Z : 0 
     178                        ); 
     179                rv = pln->readFromMainFile(fp, rctx); 
     180                *pCreated = pln; 
     181                rv = ESHP_OK; 
     182        } 
     183 
    171184        return rv; 
    172185} 
     
    256269        rctx.readRecordContentSize += 4; 
    257270         
    258         mPList.mBounds[0] = Shape::freadLittleDouble(fp); 
    259         mPList.mBounds[1] = Shape::freadLittleDouble(fp); 
    260         mPList.mBounds[2] = Shape::freadLittleDouble(fp); 
    261         mPList.mBounds[3] = Shape::freadLittleDouble(fp); 
    262         rctx.readSize              += 32; 
    263         rctx.readRecordContentSize += 32; 
    264  
    265         mPList.mNParts  = Shape::freadLittle32(fp); 
    266         mPList.mNPoints = Shape::freadLittle32(fp); 
    267         rctx.readSize              += 8; 
    268         rctx.readRecordContentSize += 8; 
    269  
    270         mPList.allocBuffers(); 
    271  
    272         ESInt32 i; 
    273  
    274         for (i = 0;i < mPList.mNParts;i++) 
    275         { 
    276                 mPList.mPartIndexes[i] = Shape::freadLittle32(fp); 
    277                 rctx.readSize              += 4; 
    278                 rctx.readRecordContentSize += 4; 
    279         } 
    280  
    281         for (i = 0;i < mPList.mNPoints;i++) 
    282         { 
    283                 mPList.mPoints[i].x = Shape::freadLittleDouble(fp); 
    284                 mPList.mPoints[i].y = Shape::freadLittleDouble(fp); 
    285                 rctx.readSize              += 16; 
    286                 rctx.readRecordContentSize += 16; 
    287         } 
    288  
    289         if (mOption & SHPRECORD_WITH_Z) 
    290         { 
    291                 // Z 
    292                 mPList.mZRange[0] = Shape::freadLittleDouble(fp); 
    293                 mPList.mZRange[1] = Shape::freadLittleDouble(fp); 
    294                 rctx.readSize              += 16; 
    295                 rctx.readRecordContentSize += 16; 
    296  
    297                 for (i = 0;i < mPList.mNPoints;i++) 
    298                 { 
    299                         mPList.mPoints[i].z = Shape::freadLittleDouble(fp); 
    300                         rctx.readSize              += 8; 
    301                         rctx.readRecordContentSize += 8; 
    302                 } 
    303  
    304                 // Measure 
    305                 mPList.mMRange[0] = Shape::freadLittleDouble(fp); 
    306                 mPList.mMRange[1] = Shape::freadLittleDouble(fp); 
    307                 rctx.readSize              += 16; 
    308                 rctx.readRecordContentSize += 16; 
    309  
    310                 for (i = 0;i < mPList.mNPoints;i++) 
    311                 { 
    312                         mPList.mPoints[i].m = Shape::freadLittleDouble(fp); 
    313                         rctx.readSize              += 8; 
    314                         rctx.readRecordContentSize += 8; 
    315                 } 
    316         } 
     271        mPList.readFromMainFile(fp, rctx, mOption); 
     272 
    317273/* 
    318274        for (i = 0;i < mNPoints;i++) 
     
    341297VALUE ShpPolygon::getPartAt(int index) 
    342298{ 
    343         if (index < 0 || index >= mPList.mNParts) 
    344                 return Qnil; 
    345  
    346         int len = (index == (mPList.mNParts-1)) ? mPList.mNPoints : mPList.mPartIndexes[index+1]; 
    347         len -= mPList.mPartIndexes[index]; 
    348  
    349         int start = mPList.mPartIndexes[index]; 
    350  
    351         VALUE arr = rb_ary_new2(len); 
    352         for (int i = 0;i < len;i++) 
    353         { 
    354                 ESPointEx& p = mPList.mPoints[start+i]; 
    355                 ShpPoint* shp = new ShpPoint(p.x, p.y, p.z, p.m); 
    356                 rb_ary_push(arr, shp->toRubyObject()); 
    357         } 
    358  
    359         return arr; 
     299        return mPList.getPartAsRubyObj(index); 
    360300} 
    361301 
     
    377317 
    378318        return copy; 
     319} 
     320 
     321// Polyline 
     322 
     323ShpPolyline::ShpPolyline(int option) 
     324{ 
     325        mOption = option; 
     326} 
     327 
     328ShpPolyline::~ShpPolyline() 
     329{ 
     330} 
     331 
     332es_error_t ShpPolyline::readFromMainFile(FILE* fp, ShpReadContext& rctx) 
     333{ 
     334        es_error_t rv = ESHP_OK; 
     335 
     336        mType      = Shape::freadLittle32(fp); 
     337        rctx.readSize              += 4; 
     338        rctx.readRecordContentSize += 4; 
     339         
     340        mPList.readFromMainFile(fp, rctx, mOption); 
     341 
     342        return rv; 
     343} 
     344 
     345VALUE ShpPolyline::getPartAt(int index) 
     346{ 
     347        return mPList.getPartAsRubyObj(index); 
     348} 
     349 
     350int ShpPolyline::getPartsLength() 
     351{ 
     352        return mPList.mNParts; 
     353} 
     354 
     355ShpRecordObject* ShpPolyline::clone() 
     356{ 
     357        ShpPolyline* copy = new ShpPolyline(mOption); 
     358        copy->mType = mType; 
     359        copy->mPList.copyFrom(mPList); 
     360 
     361        return copy; 
     362} 
     363 
     364VALUE ShpPolyline::toRubyObject() 
     365{ 
     366        VALUE klass = getRubyESRIShapePolylineClass(); 
     367        VALUE instance = rb_class_new_instance(0, NULL, klass); 
     368 
     369        RPolylineData* indata; 
     370        Data_Get_Struct(instance, RPolylineData, indata); 
     371 
     372        indata->pThis = this; 
     373 
     374        return instance; 
    379375} 
    380376 
     
    447443{return ((ShpPolygon*)pThis)->getBoundingBox();} 
    448444 
    449 void   c_Polyline_delete(void* pThis) 
     445int c_Polyline_getPartsLength(void* pThis) 
     446{return ((ShpPolyline*)pThis)->getPartsLength();} 
     447 
     448VALUE c_Polyline_getPartAt(void* pThis, int index) 
     449{return ((ShpPolyline*)pThis)->getPartAt(index);} 
     450 
     451void c_Polyline_delete(void* pThis) 
    450452{delete (ShpPolyline*)pThis;} 
    451453