Esempio n. 1
0
// Trimmed (parametric) surface entity (Type 144)
bool
InputIges::read_144(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  locateParamEntry(de);

  int i;
  int int_fld, int_fldb[1];
  char chr_fld;

  istrstream* data_line;

  readDataLine(lineBuffer, dataBuffer);
  data_line = new istrstream(dataBuffer);

  int srf_entry;
  int obnd_entry;
  int nof_ibnds;

  *data_line >> int_fld >> chr_fld;     //-Entry-number
  *data_line >> srf_entry >> chr_fld;   //-Pointer to surface
  *data_line >> int_fld >> chr_fld;     //-Type of bounded surface
                                          // 0=the outer bndr is the bndr of D
                                          // 1=otherwise
  *data_line >> nof_ibnds >> chr_fld;   //-Nof inner bndrs defined by simple closed curves
  *data_line >> obnd_entry >> chr_fld;  //-Pointer to outer bndr of the surface
                                        // defining the inner bndr of the srf.

  IgesDirectoryEntry* comp_de;

  //-Read outer boundary on the surface (if defined!)
  if (obnd_entry > 0) {
    comp_de = getDirectoryEntry(obnd_entry);
    comp_de->referingId = de->id;
  }

  //-Read inner boundary defining curves (if defined!)
  if (nof_ibnds > 0) {

    int* bnd_id_table = new int[nof_ibnds];
    int ibnd_entry;

    //-Read component row-ids and corresponding data-rows
    for(i = 0; i < nof_ibnds; i++) {
      readIntFields(data_line, 1, int_fldb);
      bnd_id_table[i] = int_fldb[0];

      comp_de = getDirectoryEntry(int_fldb[0]);
      comp_de->referingId = de->id;
    }

    delete [] bnd_id_table;
  }

  return result;
}
Esempio n. 2
0
// Curve on a parametric surface entity (Type 142)
bool
InputIges::read_142(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  locateParamEntry(de);

  int int_fld;
  char chr_fld;
  istrstream* data_line;

  readDataLine(lineBuffer, dataBuffer);
  data_line = new istrstream(dataBuffer);

  int prmc_entry;
  int srf_entry;
  int srfc_entry;
  *data_line >> int_fld >> chr_fld;     //-Entry-number
  *data_line >> int_fld >> chr_fld;     //-Type of the curve
  *data_line >> srf_entry >> chr_fld;   //-Pointer to surface
  *data_line >> prmc_entry >> chr_fld;  //-Pointer to crv in param space
  *data_line >> srfc_entry >> chr_fld;  //-Pointer to crv on the surface
  *data_line >> int_fld >> chr_fld;     //-Preferred format

  // Update reference to the component
  IgesDirectoryEntry* comp_de = getDirectoryEntry(srfc_entry);
  comp_de->referingId = de->id;

  return result;
}
/**
  * Creates a new directory with the given name and location
  *
  * @param name The fully qualified name of the new directory.
  * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if the path is invalid, or MICROBT_NO_RESOURCES if the FileSystem is full.
  */
int MicroBitFileSystem::createDirectory(char const *name)
{
    DirectoryEntry* directory;        // Directory holding this file.
    DirectoryEntry* dirent;            // Entry in the direcoty of this file.

    // Protect against accidental re-initialisation
    if ((status & MBFS_STATUS_INITIALISED) == 0)
        return MICROBIT_NOT_SUPPORTED;

    // Reject invalid filenames.
    if (!isValidFilename(name))
        return MICROBIT_INVALID_PARAMETER;

    // Determine the directory for this file.
    directory = getDirectoryOf(name);

    if (directory == NULL)
        return MICROBIT_INVALID_PARAMETER;

    // Find the DirectoryEntry associated with the given name (if it exists).
    // We don't permit files or directories with the same name.
    dirent = getDirectoryEntry(name, directory);

    if (dirent)
        return MICROBIT_INVALID_PARAMETER;

    dirent = createFile(name, directory, true);
    if (dirent == NULL)
        return MICROBIT_NO_RESOURCES;

    return MICROBIT_OK;
}
Esempio n. 4
0
 void resetGlobalRegionDictionary() {
    destroyDictionary();
    if ( _registeredObject != NULL ) {
       _object = NEW GlobalRegionDictionary( *_registeredObject );
       _object->setRegisteredObject( _registeredObject );
       NewNewDirectoryEntryData *entry = getDirectoryEntry( *_object, 1 );
       if ( entry == NULL ) {
          entry = NEW NewNewDirectoryEntryData();
          _object->setRegionData( 1, entry ); //resetGlobalRegionDictionary
       }
    }
 }
Esempio n. 5
0
// This entry defines a bounded surface entity (Type 143)
// It points to the surface and to the entry which defines the
// bounding curves (fex. to an entry 141)
bool
InputIges::read_143(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  locateParamEntry(de);

  int i;
  int int_fld;
  char chr_fld;
  istrstream* data_line;

  readDataLine(lineBuffer, dataBuffer);
  data_line = new istrstream(dataBuffer);

  int nof_srfs, nof_bnds, nof_values;

  *data_line >> int_fld >> chr_fld;   // entry-number

  *data_line >> nof_srfs >> chr_fld;    // Nof surface entities
  int* srf_id_table = new int[nof_srfs];
  nof_values = readIntFields(data_line, nof_srfs, srf_id_table);

  *data_line >> nof_bnds >> chr_fld;     // Nof boundary entities
  int* bnd_id_table = new int[nof_bnds];
  nof_values = readIntFields(data_line, nof_bnds, bnd_id_table);

  IgesDirectoryEntry* comp_de;
  int nof_refs;
  int* refs_table;

  // In 2D boundaries
  if ( modelDimension == ECIF_2D ) {
    nof_refs = nof_bnds;
    refs_table = bnd_id_table;

  // In 3D surfaces
  } else {
    nof_refs = nof_srfs;
    refs_table = srf_id_table;
  }

  for(i = 0; i < nof_refs; i++) {
    comp_de = getDirectoryEntry(refs_table[i]);
    comp_de->referingId = de->id;
  }

  delete [] bnd_id_table;
  delete [] srf_id_table;

  return result;
}
Esempio n. 6
0
// Boundary entity (Type 141)
// This entry point to a untrimmed surface and to all curve elements
// which define this surface as boundaries.
bool
InputIges::read_141(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  locateParamEntry(de);

  int i, j;
  int int_fld, int_fldb[1];
  char chr_fld;

  istrstream* data_line;

  readDataLine(lineBuffer, dataBuffer);
  data_line = new istrstream(dataBuffer);

   //-Skip 4 (nbr sep) pairs:
   // Entry id
   // Type of srf representation (0=in trimmimg space, 1=in model space)
   // Preferred representation (0=unspec., 1=model space, 2=param. spcace, 3=equal)
   // Pointer to the DE of the untrimmed surface
  for(i = 0; i < 4; i++) {
    *data_line >> int_fld >> chr_fld;
  }

  //-Read number of curves in the boundary
  int nof_crvs;
  *data_line >> nof_crvs >> chr_fld;
  int* crv_id_table = new int[nof_crvs];

  IgesDirectoryEntry* comp_de;

  //-Read component ids and update references
  for(i = 0; i < nof_crvs; i++) {
    for(j = 0; j < 4; j++) {

      readIntFields(data_line, 1, int_fldb);

      if (j == 0) {
        crv_id_table[i] = int_fldb[0];
        comp_de = getDirectoryEntry(int_fldb[0]);
        comp_de->referingId = de->id;
      }
    }
  }

  delete [] crv_id_table;
  return result;
}
Esempio n. 7
0
bool
InputIges::createBodies()
{
  IgesDirectory::iterator pos;

  // First create bodies
  pos = directory->begin();
  while (pos != directory->end()) {

    IgesDirectoryEntry* de = (*pos++).second;

    if ( !de->canBeBody || de->referingId > 0 ) {
      continue;
    }

    Body* body;

    if ( modelDimension == ECIF_2D ) {
      body = new Body2D();
    } else {
      body = new Body3D();
    }

    model->addBody(body);
    de->body = body;
  }

  // Next set parent bodies for the component elements
  pos = directory->begin();
  while (pos != directory->end()) {

    IgesDirectoryEntry* de = (*pos++).second;

    if ( de->referingId <= 0 ) {
      continue;
    }

    IgesDirectoryEntry* ref_de = getDirectoryEntry(de->referingId);

    de->body = ref_de->body;
  }

  return true;
}
Esempio n. 8
0
// Composite curve entity (Type 102)
bool
InputIges::read_102(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  locateParamEntry(de);

  int i;
  int int_fld, int_fldb[1];
  char chr_fld;

  istrstream* data_line;

  readDataLine(lineBuffer, dataBuffer);
  data_line = new istrstream(dataBuffer);


  //-Read number of curves in the composite
  int nof_crvs;
  *data_line >> int_fld >> chr_fld; // Entry-id
  *data_line >> nof_crvs >> chr_fld;

  int* crv_id_table = new int[nof_crvs];

  IgesDirectoryEntry* comp_de;

  //-Read component dir-ids and update the reference
  for(i = 0; i < nof_crvs; i++) {
    readIntFields(data_line, 1, int_fldb);
    crv_id_table[i] = int_fldb[0];

    comp_de = getDirectoryEntry(int_fldb[0]);
    comp_de->referingId = de->id;
  }

  delete [] crv_id_table;

  return result;
}
/**
  * Retrieve the DirectoryEntry for the given filename.
  *
  * @param filename A fully qualified filename, from the root. Should be end with a "/" if no filename is provided.
  *
  * @return A pointer to the DirectoryEntry for the given file, or NULL if no entry is found.
  */
DirectoryEntry* MicroBitFileSystem::getDirectoryOf(char const * filename)
{
    DirectoryEntry* directory;

    // If not path is provided, return the root diretory.
    if (filename == NULL || filename[0] == 0)
        return rootDirectory;

    char s[MBFS_FILENAME_LENGTH + 1];

    uint8_t i = 0;

    directory = rootDirectory;

    while (*filename != '\0') {
        if (*filename == '/') {
            s[i] = '\0';

            // Ensure each level of the filename is valid
            if (i == 0 || i > MBFS_FILENAME_LENGTH + 1)
                return NULL;

            // Extract the relevant entry from the directory.
            directory = getDirectoryEntry(s, directory);

            // If file / directory does not exist, then there's nothing more we can do.
            if (!directory)
                return NULL;

            i = 0;
        }
        else
            s[i++] = *filename;

        filename++;
    }

    return directory;
}
/**
  * Open a new file, and obtain a new file handle (int) to
  * read/write/seek the file. The flags are:
  *  - MB_READ : read from the file.
  *  - MB_WRITE : write to the file.
  *  - MB_CREAT : create a new file, if it doesn't already exist.
  *
  * If a file is opened that doesn't exist, and MB_CREAT isn't passed,
  * an error is returned, otherwise the file is created.
  *
  * @param filename name of the file to open, must contain only printable characters.
  * @param flags One or more of MB_READ, MB_WRITE or MB_CREAT. 
  * @return return the file handle,MICROBIT_NOT_SUPPORTED if the file system has
  *         not been initialised MICROBIT_INVALID_PARAMETER if the filename is
  *         too large, MICROBIT_NO_RESOURCES if the file system is full.
  *
  * @code
  * MicroBitFileSystem f();
  * int fd = f.open("test.txt", MB_WRITE|MB_CREAT);
  * if(fd<0)
  *    print("file open error");
  * @endcode
  */
int MicroBitFileSystem::open(char const * filename, uint32_t flags)
{
    FileDescriptor *file;               // File Descriptor of this file.
    DirectoryEntry* directory;          // Directory holding this file.
    DirectoryEntry* dirent;             // Entry in the direcoty of this file.
    int id;                             // FileDescriptor id to be return to the caller.

    // Protect against accidental re-initialisation
    if ((status & MBFS_STATUS_INITIALISED) == 0)
        return MICROBIT_NOT_SUPPORTED;

    // Reject invalid filenames.
    if(!isValidFilename(filename))
        return MICROBIT_INVALID_PARAMETER;

    // Determine the directory for this file.
    directory = getDirectoryOf(filename);

    if (directory == NULL)
        return MICROBIT_INVALID_PARAMETER;

    // Find the DirectoryEntry assoviate with the given file (if it exists).
    dirent = getDirectoryEntry(filename, directory);

    // Only permit files to be opened once... 
    // also, detemrine a valid ID for this open file as we go.
    file = openFiles;
    id = 0;
    
    while (file && dirent)
    {
        if (file->dirent == dirent)
            return MICROBIT_NOT_SUPPORTED;

        if (file->id == id)
        {
            id++;
            file = openFiles;
            continue;
        }

        file = file->next;
    }

    if (dirent == NULL)
    {
        // If the file doesn't exist, and we haven't been asked to create it, then there's nothing we can do.
        if (!(flags & MB_CREAT))
            return MICROBIT_INVALID_PARAMETER;

        dirent = createFile(filename, directory, false);
        if (dirent == NULL)
            return MICROBIT_NO_RESOURCES;
    }

    // Try to add a new FileDescriptor into this directory.
    file = new FileDescriptor;
    if (file == NULL)
        return MICROBIT_NO_RESOURCES;

    // Populate the FileDescriptor
    file->flags = (flags & ~(MB_CREAT));
    file->id = id;
    file->length = dirent->flags == MBFS_DIRECTORY_ENTRY_NEW ? 0 : dirent->length;
    file->seek = (flags & MB_APPEND) ? file->length : 0;
    file->dirent = dirent;
    file->directory = directory;
    file->cacheLength = 0;

    // Add the file descriptor to the chain of open files.
    file->next = openFiles;
    openFiles = file;

    // Return the FileDescriptor id to the user
    return file->id;
}