int S57Writer::WriteDSPM( int nScale )

{
    if( nScale == 0 )
        nScale = 52000;

/* -------------------------------------------------------------------- */
/*      Add the DSID field.                                             */
/* -------------------------------------------------------------------- */
    DDFRecord *poRec = MakeRecord();
    DDFField *poField;

    poField = poRec->AddField( poModule->FindFieldDefn( "DSPM" ) );

    poRec->SetIntSubfield   ( "DSPM", 0, "RCNM", 0, 20 );
    poRec->SetIntSubfield   ( "DSPM", 0, "RCID", 0, 1 );
    poRec->SetIntSubfield   ( "DSPM", 0, "HDAT", 0, 2 );
    poRec->SetIntSubfield   ( "DSPM", 0, "VDAT", 0, 17 );
    poRec->SetIntSubfield   ( "DSPM", 0, "SDAT", 0, 23 );
    poRec->SetIntSubfield   ( "DSPM", 0, "CSCL", 0, nScale );
    poRec->SetIntSubfield   ( "DSPM", 0, "DUNI", 0, 1 );
    poRec->SetIntSubfield   ( "DSPM", 0, "HUNI", 0, 1 );
    poRec->SetIntSubfield   ( "DSPM", 0, "PUNI", 0, 1 );
    poRec->SetIntSubfield   ( "DSPM", 0, "COUN", 0, 1 );
    poRec->SetIntSubfield   ( "DSPM", 0, "COMF", 0, nCOMF );
    poRec->SetIntSubfield   ( "DSPM", 0, "SOMF", 0, nSOMF );

/* -------------------------------------------------------------------- */
/*      Write out the record.                                           */
/* -------------------------------------------------------------------- */
    poRec->Write();
    delete poRec;

    return TRUE;
}
Exemple #2
0
FObject MakeEnvironment(FObject nam, FObject ctv)
{
    FAssert(sizeof(FEnvironment) == sizeof(EnvironmentFieldsC) + sizeof(FRecord));
    FAssert(BooleanP(ctv));

    FEnvironment * env = (FEnvironment *) MakeRecord(R.EnvironmentRecordType);
    env->HashMap = MakeEqHashMap();
    env->Name = nam;
    env->Interactive = ctv;
    env->Immutable = FalseObject;
    return(env);
}
Exemple #3
0
static FObject MakeGlobal(FObject nam, FObject mod, FObject ctv)
{
    FAssert(sizeof(FGlobal) == sizeof(GlobalFieldsC) + sizeof(FRecord));
    FAssert(SymbolP(nam));

    FGlobal * gl = (FGlobal *) MakeRecord(R.GlobalRecordType);
    gl->Box = MakeBox(NoValueObject);
    gl->Name = nam;
    gl->Module = mod;
    gl->State = GlobalUndefined;
    gl->Interactive = ctv;

    return(gl);
}
Exemple #4
0
static FObject MakeLibrary(FObject nam, FObject exports, FObject proc)
{
    FAssert(sizeof(FLibrary) == sizeof(LibraryFieldsC) + sizeof(FRecord));

    FLibrary * lib = (FLibrary *) MakeRecord(R.LibraryRecordType);
    lib->Name = nam;
    lib->Exports = exports;

    R.LoadedLibraries = MakePair(lib, R.LoadedLibraries);

    if (ProcedureP(proc))
        R.LibraryStartupList = MakePair(List(proc), R.LibraryStartupList);

    return(lib);
}
Exemple #5
0
int main()
{
    Server server {
        ServerId("s1"),
        Interfaces {
            Interface {
                InterfaceId("i1"),
                Ports {
                    { PortId("p11"), PortName("Jolly") },
                    { PortId("p12"), PortName("Billy") }
                }
            },
            Interface {
                InterfaceId("i2"),
                Ports {
                    { PortId("p21"), PortName("Bimbo") },
                    { PortId("p22"), PortName("Luffy") }
                }
            }
        }
    };

    auto interfaces = server.get<Interfaces>();
    std::cout << "InterfaceId: " << interfaces.at(0).get<InterfaceId>() << std::endl;

    auto ports = interfaces.at(0).get<Ports>();
    std::cout << "Port name: " << ports.at(0).get<PortName>() << std::endl;
    Handy<ServerId, InterfaceId, PortId> handy(ServerId("s1"), InterfaceId("i1"), PortId("p1"));
    handy.get<ServerId>() = ServerId{"s2"};
    handy.get<PortId>() = PortId {"p2"};

    auto record = MakeRecord(ServerId("s1"), PortId("p2"));
    std::cout << Get<ServerId>(record) << std::endl;

    std::cout << Get<ServerId>(handy) << std::endl;
    std::cout << handy.get<PortId>() << std::endl;

    std::cout << handy.get(PortId {}) << std::endl;

    handy.get(PortId()) = PortId("Port2");
    std::cout << handy.get(PortId {}) << std::endl;
}
Exemple #6
0
static FObject ImportGlobal(FObject env, FObject nam, FObject gl)
{
    FAssert(sizeof(FGlobal) == sizeof(GlobalFieldsC) + sizeof(FRecord));
    FAssert(EnvironmentP(env));
    FAssert(SymbolP(nam));
    FAssert(GlobalP(gl));

    FGlobal * ngl = (FGlobal *) MakeRecord(R.GlobalRecordType);
    ngl->Box = AsGlobal(gl)->Box;
    ngl->Name = nam;
    ngl->Module =  AsEnvironment(env)->Interactive == TrueObject ? env : AsGlobal(gl)->Module;
    if (AsGlobal(gl)->State == GlobalDefined || AsGlobal(gl)->State == GlobalImported)
        ngl->State = GlobalImported;
    else
    {
        FAssert(AsGlobal(gl)->State == GlobalModified
                || AsGlobal(gl)->State == GlobalImportedModified);

        ngl->State = GlobalImportedModified;
    }

    return(ngl);
}
int S57Writer::WritePrimitive( OGRFeature *poFeature )

{
    DDFRecord *poRec = MakeRecord();
    DDFField *poField;
    OGRGeometry *poGeom = poFeature->GetGeometryRef();

/* -------------------------------------------------------------------- */
/*      Add the VRID field.                                             */
/* -------------------------------------------------------------------- */

    poField = poRec->AddField( poModule->FindFieldDefn( "VRID" ) );

    poRec->SetIntSubfield   ( "VRID", 0, "RCNM", 0, 
                              poFeature->GetFieldAsInteger( "RCNM") );
    poRec->SetIntSubfield   ( "VRID", 0, "RCID", 0, 
                              poFeature->GetFieldAsInteger( "RCID") );
    poRec->SetIntSubfield   ( "VRID", 0, "RVER", 0, 1 );
    poRec->SetIntSubfield   ( "VRID", 0, "RUIN", 0, 1 );

/* -------------------------------------------------------------------- */
/*      Handle simple point.                                            */
/* -------------------------------------------------------------------- */
    if( poGeom != NULL && wkbFlatten(poGeom->getGeometryType()) == wkbPoint )
    {
        double dfX, dfY, dfZ;
        OGRPoint *poPoint = (OGRPoint *) poGeom;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI 
                   || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); 

        dfX = poPoint->getX();
        dfY = poPoint->getY();
        dfZ = poPoint->getZ();
        
        if( dfZ == 0.0 )
            WriteGeometry( poRec, 1, &dfX, &dfY, NULL );
        else
            WriteGeometry( poRec, 1, &dfX, &dfY, &dfZ );
    }

/* -------------------------------------------------------------------- */
/*      For multipoints we assuming SOUNDG, and write out as SG3D.      */
/* -------------------------------------------------------------------- */
    else if( poGeom != NULL 
             && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint )
    {
        OGRMultiPoint *poMP = (OGRMultiPoint *) poGeom;
        int i, nVCount = poMP->getNumGeometries();
        double *padfX, *padfY, *padfZ;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VI 
                   || poFeature->GetFieldAsInteger( "RCNM") == RCNM_VC ); 

        padfX = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfY = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfZ = (double *) CPLMalloc(sizeof(double) * nVCount);

        for( i = 0; i < nVCount; i++ )
        {
            OGRPoint *poPoint = (OGRPoint *) poMP->getGeometryRef( i );
            padfX[i] = poPoint->getX();
            padfY[i] = poPoint->getY();
            padfZ[i] = poPoint->getZ();
        }

        WriteGeometry( poRec, nVCount, padfX, padfY, padfZ );

        CPLFree( padfX );
        CPLFree( padfY );
        CPLFree( padfZ );
    }

/* -------------------------------------------------------------------- */
/*      Handle LINESTRINGs (edge) geometry.                             */
/* -------------------------------------------------------------------- */
    else if( poGeom != NULL 
             && wkbFlatten(poGeom->getGeometryType()) == wkbLineString )
    {
        OGRLineString *poLS = (OGRLineString *) poGeom;
        int i, nVCount = poLS->getNumPoints();
        double *padfX, *padfY;

        CPLAssert( poFeature->GetFieldAsInteger( "RCNM") == RCNM_VE );

        padfX = (double *) CPLMalloc(sizeof(double) * nVCount);
        padfY = (double *) CPLMalloc(sizeof(double) * nVCount);

        for( i = 0; i < nVCount; i++ )
        {
            padfX[i] = poLS->getX(i);
            padfY[i] = poLS->getY(i);
        }

        WriteGeometry( poRec, nVCount, padfX, padfY, NULL );

        CPLFree( padfX );
        CPLFree( padfY );
        
    }

/* -------------------------------------------------------------------- */
/*      edge node linkages.                                             */
/* -------------------------------------------------------------------- */
    if( poFeature->GetDefnRef()->GetFieldIndex( "NAME_RCNM_0" ) >= 0 )
    {
        DDFField *poField;
        char     szName[5];
        int      nRCID;

        CPLAssert( poFeature->GetFieldAsInteger( "NAME_RCNM_0") == RCNM_VC );

        poField = poRec->AddField( poModule->FindFieldDefn( "VRPT" ) );
        
        nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_0");
        szName[0] = RCNM_VC;
        szName[1] = nRCID & 0xff;
        szName[2] = (nRCID & 0xff00) >> 8;
        szName[3] = (nRCID & 0xff0000) >> 16;
        szName[4] = (nRCID & 0xff000000) >> 24;
        
        poRec->SetStringSubfield( "VRPT", 0, "NAME", 0, szName, 5 );
        poRec->SetIntSubfield   ( "VRPT", 0, "ORNT", 0, 
                                  poFeature->GetFieldAsInteger( "ORNT_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "USAG", 0, 
                                  poFeature->GetFieldAsInteger( "USAG_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "TOPI", 0, 
                                  poFeature->GetFieldAsInteger( "TOPI_0") );
        poRec->SetIntSubfield   ( "VRPT", 0, "MASK", 0, 
                                  poFeature->GetFieldAsInteger( "MASK_0") );
        
        nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_1");
        szName[0] = RCNM_VC;
        szName[1] = nRCID & 0xff;
        szName[2] = (nRCID & 0xff00) >> 8;
        szName[3] = (nRCID & 0xff0000) >> 16;
        szName[4] = (nRCID & 0xff000000) >> 24;

        poRec->SetStringSubfield( "VRPT", 0, "NAME", 1, szName, 5 );
        poRec->SetIntSubfield   ( "VRPT", 0, "ORNT", 1, 
                                  poFeature->GetFieldAsInteger( "ORNT_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "USAG", 1, 
                                  poFeature->GetFieldAsInteger( "USAG_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "TOPI", 1, 
                                  poFeature->GetFieldAsInteger( "TOPI_1") );
        poRec->SetIntSubfield   ( "VRPT", 0, "MASK", 1, 
                                  poFeature->GetFieldAsInteger( "MASK_1") );
    }
int S57Writer::WriteDSID( const char *pszDSNM, const char *pszISDT, 
                          const char *pszSTED, int nAGEN, 
                          const char *pszCOMT )

{
/* -------------------------------------------------------------------- */
/*      Default values.                                                 */
/* -------------------------------------------------------------------- */
    if( pszDSNM == NULL )
        pszDSNM = "";
    if( pszISDT == NULL )
        pszISDT = "20030801";
    if( pszSTED == NULL )
        pszSTED = "03.1";
    if( pszCOMT == NULL )
        pszCOMT = "";

/* -------------------------------------------------------------------- */
/*      Add the DSID field.                                             */
/* -------------------------------------------------------------------- */
    DDFRecord *poRec = MakeRecord();
    DDFField *poField;

    poField = poRec->AddField( poModule->FindFieldDefn( "DSID" ) );

    poRec->SetIntSubfield   ( "DSID", 0, "RCNM", 0, 10 );
    poRec->SetIntSubfield   ( "DSID", 0, "RCID", 0, 1 );
    poRec->SetIntSubfield   ( "DSID", 0, "EXPP", 0, 1 );
    poRec->SetIntSubfield   ( "DSID", 0, "INTU", 0, 4 );
    poRec->SetStringSubfield( "DSID", 0, "DSNM", 0, pszDSNM );
    poRec->SetStringSubfield( "DSID", 0, "EDTN", 0, "2" );
    poRec->SetStringSubfield( "DSID", 0, "UPDN", 0, "0" );
    poRec->SetStringSubfield( "DSID", 0, "UADT", 0, pszISDT );
    poRec->SetStringSubfield( "DSID", 0, "ISDT", 0, pszISDT );
    poRec->SetStringSubfield( "DSID", 0, "STED", 0, pszSTED );
    poRec->SetIntSubfield   ( "DSID", 0, "PRSP", 0, 1 );
    poRec->SetStringSubfield( "DSID", 0, "PSDN", 0, "" );
    poRec->SetStringSubfield( "DSID", 0, "PRED", 0, "2.0" );
    poRec->SetIntSubfield   ( "DSID", 0, "PROF", 0, 1 );
    poRec->SetIntSubfield   ( "DSID", 0, "AGEN", 0, nAGEN );
    poRec->SetStringSubfield( "DSID", 0, "COMT", 0, pszCOMT );

/* -------------------------------------------------------------------- */
/*      Add the DSSI record.  Eventually we will need to return and     */
/*      correct these when we are finished writing.                     */
/* -------------------------------------------------------------------- */
    poField = poRec->AddField( poModule->FindFieldDefn( "DSSI" ) );

    poRec->SetIntSubfield   ( "DSSI", 0, "DSTR", 0, 2 );
    poRec->SetIntSubfield   ( "DSSI", 0, "AALL", 0, 1 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NALL", 0, 1 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOMR", 0, 0 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOCR", 0, 0 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOGR", 0, 3 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOLR", 0, 0 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOIN", 0, 3 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOCN", 0, 0 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOED", 0, 0 );
    poRec->SetIntSubfield   ( "DSSI", 0, "NOFA", 0, 0 );

/* -------------------------------------------------------------------- */
/*      Write out the record.                                           */
/* -------------------------------------------------------------------- */
    poRec->Write();
    delete poRec;

    return TRUE;
}