//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void Display::copyData(const Display& org, const bool cc)
{
   BaseClass::copyData(org);
   if (cc) initData();

   if (org.ioHandler != nullptr) {
      Basic::IoHandler* copy = org.ioHandler->clone();
      setSlotIoHandler(copy);
      copy->unref();
   }
   else setSlotIoHandler(nullptr);

   // Item/Channel mapping
   for (unsigned int i = 0; i < TBL_SIZE; i++) {
      types[i] = org.types[i];
      channels[i] = org.channels[i];
      labelFlags[i] = org.labelFlags[i];
      lcStrcpy(labels[i], sizeof(labels[i]), org.labels[i]);
      lcStrcpy(labelBuffs[i], sizeof(labelBuffs[i]), org.labelBuffs[i]);
   }
   item = org.item;

   // Display buffers
   for (unsigned int i = 0; i < TBL_SIZE; i++) {
      table_typeRo[i] = org.table_typeRo[i];
      table_Label[i] = labelBuffs[i];
      table_ai[i] = org.table_ai[i];
   }
}
// Load FtglOutlineFont
void FtglOutlineFont::loadFont()
{
    if (isLoaded()) return;

    // Check for required parameters
    if( filename() == nullptr ) {
        if (isMessageEnabled(MSG_ERROR)) {
        std::cerr << "No ttf file" << std::endl;
        }
        return;
    }

    // Generate filename
    const size_t FONTPATHNAME_LENGTH = 256;
    char fontPathname[FONTPATHNAME_LENGTH];
    if (fontDirectory() != nullptr) lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, fontDirectory());
    else lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, "./");
    lcStrcat(fontPathname, FONTPATHNAME_LENGTH, filename());

    FTGLOutlineFont* ftglFont = new FTGLOutlineFont(fontPathname);
    if (ftglFont != nullptr && !ftglFont->Error()) {
        // set the face size and return the pointer, then tell our base class that we have a loaded font
        ftglFont->FaceSize(getFaceSize());
        ftgl(ftglFont);
        setFontLoaded();
    }
    else {
        if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "FtglOutlineFont::loadFont() - font did not load correctly: file: \"";
            std::cerr << fontPathname << "\"";
            std::cerr << std::endl;
        }
        std::exit(1);
    }
}
//------------------------------------------------------------------------------
// copyData() - 
//------------------------------------------------------------------------------
void BmpTexture::copyData(const BmpTexture& org, const bool cc)
{
    BaseClass::copyData(org);
    if (cc) initData();

   lcStrcpy(texPath, sizeof(texPath), org.texPath);
   lcStrcpy(texFile, sizeof(texFile), org.texFile);
}
//------------------------------------------------------------------------------
// Function collect the data to be displayed
//------------------------------------------------------------------------------
void Display::updateDisplay()
{
   Basic::IoData* ioData = nullptr;
   if (ioHandler != nullptr) ioData = ioHandler->getInputData();

   // Item/channel mapping
   for (unsigned int i = 0; i < TBL_SIZE; i++) {

      bool ok = false;

      if (types[i] != NONE && ioData != nullptr) {

         // Set the data
         if (types[i] == AI) {
            LCreal v = 0;
            ok = ioData->getAnalogInput(channels[i], &v);
            if (ok) {
               table_ai[i] = v;
               table_typeRo[i] = R_AI;
            }
         }
         else if (types[i] == DI) {
            bool flg = false;
            ok = ioData->getDiscreteInput(channels[i], &flg);
            if (ok) {
               if (flg) table_typeRo[i] = R_DI_1;
               else table_typeRo[i] = R_DI_0;
            }
         }

         // Create the label
         {
            // if not provided; make the default label
            if (!labelFlags[i]) {
               char cbuff[32];
               if (types[i] == AI) std::sprintf(cbuff, "AI(%03d)", channels[i]);
               else                std::sprintf(cbuff, "DI(%03d)", channels[i]);
               lcStrcpy(labels[i], sizeof(labels[i]), cbuff);
            }

            // copy the label with a ':'
            lcStrcpy(labelBuffs[i], sizeof(labelBuffs[i]), labels[i]);
            lcStrcat(labelBuffs[i], sizeof(labelBuffs[i]), ":");
         }

      }

      if (!ok) {
         table_ai[i] = 0;
      }

   }
}
Exemple #5
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
TimeReadout::TimeReadout()
{
   STANDARD_CONSTRUCTOR()

   lcStrcpy(format,FORMAT_LENGTH,"%02d:%02d:%04.1f");
   tmode = hhmmss;
} 
Exemple #6
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
DirectionReadout::DirectionReadout()
{
   STANDARD_CONSTRUCTOR()

   lcStrcpy(format,FORMAT_LENGTH,"%+07.2f");
   tmode = dd;
}
WaypointLoader::WaypointKey::WaypointKey(
         const char* id, const char* ccode) : Key(0)
{
   size = WAYPOINT_RECORD_LEN;
   key[0] = '\0';

   if (id != 0)
      lcStrcpy(ident,WP_IDENT_LEN+1,id);
   else
      ident[0] = '\0';

   if (ccode != 0)
      lcStrcpy(countryCode,WP_CCODE_LEN+1,ccode);
   else
      countryCode[0] = '\0';
}
Exemple #8
0
//------------------------------------------------------------------------------
// getInputValue() -- returns the readout as a numeric value
//------------------------------------------------------------------------------
double NumericReadout::getInputValue() const
{
   // copy string to buffer with correct sign character
   const size_t CBUFLOCAL_LEN = 100;
   char cbuf[CBUFLOCAL_LEN];
   const char* p = *this;
   lcStrcpy(cbuf,CBUFLOCAL_LEN,p);
   if (cbuf[0] == plusChar)  cbuf[0] = '+';
   if (cbuf[0] == minusChar) cbuf[0] = '-';

   // Check decimal point character
   if (dpChar != '\0') {
      int i;
      for (i = 0; cbuf[i] != '\0'; i++) {
         if (cbuf[i] == dpChar)  cbuf[i] = '.';
      }
   }

   // Remove spaces
   {
      int i = 0;
      while (cbuf[i] != '\0') {
         if (cbuf[i] == ' ') {
            int j = i + 1;
            while (cbuf[j] != '\0') { cbuf[j-1] = cbuf[j]; j++; }
            cbuf[j-1] = '\0';
         }
         else i++;
      }
   }

   return std::atof(cbuf);
}
Exemple #9
0
//------------------------------------------------------------------------------
// reformat() -- convert the numerical value into an ascii character string
//------------------------------------------------------------------------------
void OctalReadout::reformat(const char* const example)
{
   if (reformatter->convertOctal(example) != Reformat::invalid) {
      setExample(example);
      lcStrcpy(format,FORMAT_LENGTH,reformatter->getFormat());
      postSign = reformatter->isPostSign();
      redisplay();
   }
}
Exemple #10
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
LongitudeReadout::LongitudeReadout()
{
   STANDARD_CONSTRUCTOR()

   lcStrcpy(format,FORMAT_LENGTH,"%+04d@%04.1f");
   tmode = ddmm;
   plusChar = 'E';
   minusChar = 'W';
   postSign = false;
}
Exemple #11
0
//------------------------------------------------------------------------------
// reformat() -- convert the numerical value into an ascii character string
//------------------------------------------------------------------------------
void DirectionReadout::reformat(const char* const example)
{
   DirMode results = reformatter->convertDirection(example);
   if (results != invalid) {
      setExample(example);
      lcStrcpy(format,FORMAT_LENGTH,reformatter->getFormat());
      tmode = results;
      postSign = reformatter->isPostSign();
      redisplay();
   }
}
Exemple #12
0
void NumericReadout::copyData(const NumericReadout& org, const bool)
{
   BaseClass::copyData(org);

   // copy the display buffer, example format, and the sprintf format
   lcStrcpy(cbuf,CBUF_LENGTH,org.cbuf);
   lcStrcpy(format,FORMAT_LENGTH,org.format);

   // copy other member variables
   plusChar  = org.plusChar;
   minusChar = org.minusChar;
   dpChar    = org.dpChar;
   undefinedChar = org.undefinedChar;
   overflowChar  = org.overflowChar;
   postSign  = org.postSign;
   num = org.num;
   maxNum = org.maxNum;
   maxValid = org.maxValid;
   minValid = org.minValid;
   blankZero = org.blankZero;
}
Exemple #13
0
void FileWriter::setFullFilename(const char* const name)
{
   if (fullFilename != nullptr) {
      delete[] fullFilename;
      fullFilename = nullptr;
   }
   if (name != nullptr) {
      size_t n = std::strlen(name) + 1;
      fullFilename = new char[n];
      lcStrcpy(fullFilename, n, name);
   }
}
Exemple #14
0
void PrintHandler::setFullFilename(const char* const name)
{
   if (fullFilename != 0) {
      delete[] fullFilename;
      fullFilename = 0;
   }
   if (name != 0) {
      size_t n = strlen(name) + 1;
      fullFilename = new char[n];
      lcStrcpy(fullFilename, n, name);
   }
}
Exemple #15
0
void NumericReadout::deleteData()
{
   cbuf[0]   = '\0';
   lcStrcpy(format,FORMAT_LENGTH,"%.0f");
   plusChar  = '\0';
   minusChar = '\0';
   dpChar    = '\0';
   undefinedChar = '-';
   overflowChar  = '*';
   postSign = false;
   num  = 0.0;
   blankZero = false;
}
Exemple #16
0
//------------------------------------------------------------------------------
// getInputValue() -- returns the readout as a numeric value
//------------------------------------------------------------------------------
double OctalReadout::getInputValue() const
{
   int value = 0;

   // copy string to buffer with correct sign character
   const size_t CBUFLOCAL_LEN = 100;
   char cbuf[CBUFLOCAL_LEN];
   const char* p = *this;
   lcStrcpy(cbuf,CBUFLOCAL_LEN,p);
   if (cbuf[0] == plusChar)  cbuf[0] = '+';
   if (cbuf[0] == minusChar) cbuf[0] = '-';

   sscanf(cbuf, format, &value);
   return double(value);
}
Exemple #17
0
//------------------------------------------------------------------------------
// setStr() -- sets this string to a copy of 'string'
//------------------------------------------------------------------------------
void String::setStr(const char* string)
{
   // copy the new text string
   if (string != 0) {
      size_t l = strlen(string);
      if (l >= nn || str == 0) {
         if (str != 0) delete[] str;
         nn = (l+1);
         str = new char[nn];
      }
      lcStrcpy(str,nn,string);
      n = l;
   }
   else {
      // remove the old text string
      n = 0;
   }
}
bool Display::setSlotLabel(const Basic::String* const msg)
{
   bool ok = false;
   if (item >= 1 && item <= TBL_SIZE) {
      if (msg != nullptr) {
         lcStrcpy(labels[item-1], sizeof(labels[item-1]), *msg);
         labelFlags[item-1] = true;
      }
      else {
         labelFlags[item-1] = false;
      }
      ok = true;
   }
   else {
      std::cerr << "Display::setSlotAiChannel(): Invalid item number; set using slot 'item'" << std::endl;
   }
   return ok;
}
Exemple #19
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
NumericReadout::NumericReadout()
{
   STANDARD_CONSTRUCTOR()

   num  = 0.0;
   maxNum = UNDEFINED_VALUE;
   cbuf[0]   = '\0';
   format[0] = '\0';
   lcStrcpy(format,FORMAT_LENGTH,"%.0f");
   justification(Basic::String::RIGHT);
   plusChar = '\0';
   minusChar = '\0';
   dpChar    = '\0';
   undefinedChar = '-';
   overflowChar  = '*';
   postSign = false;
   maxValid = UNDEFINED_VALUE;
   minValid = UNDEFINED_VALUE;
   blankZero = false;
}
Exemple #20
0
//------------------------------------------------------------------------------
// getInputValue() -- returns the readout as a numeric value
//------------------------------------------------------------------------------
double DirectionReadout::getInputValue() const
{
   double value = 0.0;

   // copy string to buffer with correct sign character
   const size_t CBUFLOCAL_LEN = 100;
   char cbuf[CBUFLOCAL_LEN];
   const char* p = *this;
   lcStrcpy(cbuf,CBUFLOCAL_LEN,p);
   if (cbuf[0] == plusChar)  cbuf[0] = '+';
   if (cbuf[0] == minusChar) cbuf[0] = '-';

   switch (tmode) {

      case ddmmss : {   // Degrees, Minutes, and seconds
         double degs = 0.0;
         double min = 0.0;
         double sec = 0.0;
         sscanf(cbuf, "%lf@%lf'%lf", &degs, &min, &sec);
         min += sec/60.0f;
         if (degs >= 0.0) value = degs + min/60.0f;
         else value = degs - min/60.0f;
      }
      break;

      case ddmm : { // Degrees and minutes
         double degs = 0.0;
         double min = 0.0;
         sscanf(cbuf, "%lf@%lf", &degs, &min);
         if (degs >= 0.0) value = degs + min/60.0f;
         else value = degs - min/60.0f;
      }
      break;

      case dd : {   // Degrees only
         sscanf(cbuf, "%lf", &value);
      }
      break;
   }
   return double(value);
}
Exemple #21
0
//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void SlSymbol::copyData(const SlSymbol& org, const bool cc)
{
    BaseClass::copyData(org);
    if (cc) initData();

    visibility = org.visibility;
    llFlg = org.llFlg;
    acFlg = org.acFlg;
    scrnFlg = org.scrnFlg;

    type = org.type;
    lcStrcpy(id, sizeof(id), org.id);

    xPos = org.xPos;
    yPos = org.yPos;

    xScreenPos = org.xScreenPos;
    yScreenPos = org.yScreenPos;

    hdg = org.hdg;
    hdgValid = org.hdgValid;
    setHdgGraphics(0);
    setHdgAngleObj(0);

    {
        Basic::Object* copy = 0;
        if (org.value != 0) copy = org.value->clone();
        setValue(copy);
        if (copy != 0) copy->unref();
    }

    {
        Basic::Pair* copy = 0;
        if (org.pntr != 0) copy = org.pntr->clone();
        setSymbolPair(copy);
        if (copy != 0) copy->unref();
    }
}
Exemple #22
0
//------------------------------------------------------------------------------
// catStr() -- appends a copy of 's' to the end of this string.
//------------------------------------------------------------------------------
void String::catStr(const char* s)
{
   // early out if nothing to append
   if (s == 0) return;

   // if this string was empty then we're really just setStr()
   if ( isEmpty() ) {
      setStr(s);
      return;
   }

   // Have new text to append to the original text
   size_t l = n + strlen(s);
   if (l >= nn) {
      char* t = str;
      nn = (l+1);
      str = new char[nn];
      lcStrcpy(str,nn,t);
      delete[] t;
   }
   lcStrcat(str,nn,s);
   n = l;
}
Exemple #23
0
// Sets the type ID
bool RfSensor::setTypeId(const char* const str)
{
    lcStrcpy(typeId, TYPE_ID_LENGTH, str);
    return true;
}
Exemple #24
0
// Load the font for one character
GLubyte* BitmapFont::loadTypeFace(const GLint index, const GLenum reverse)
{
   // If no font to load, return
   if (fontMap[index] == 0)
      return 0;

   // Create the font file name
   const size_t FONTPATHNAME_LENGTH = 256;
   char fontPathname[FONTPATHNAME_LENGTH];
   if (fontDirectory() != 0)
      lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, fontDirectory());
   else
      lcStrcpy(fontPathname, FONTPATHNAME_LENGTH, "./");
   lcStrcat(fontPathname, FONTPATHNAME_LENGTH, fontMap[index]);

   // Open the font file
   FILE* fp = 0;
   if( (fp = fopen(fontPathname, "r")) ==0 ) {
      if (isMessageEnabled(MSG_ERROR)) {
         std::cerr << "BitmapFont::loadTypeFace: unable to open font file: " << fontPathname << std::endl;
      }
      return 0;
   }

   // used to store the num of input items successfully matched and assigned
   // by fscanf function
   int nItemsMatched;

   // Calculate the size of the font
   unsigned int width1;
   nItemsMatched = fscanf(fp, "%u\n", &width1);
   unsigned int height1;
   nItemsMatched = fscanf(fp, "%u\n", &height1);

   unsigned int numBytesWide = int(ceil(double(width1) / 8.0));
   unsigned int numFileBytes = numBytesWide * height1;
   unsigned int numFontBytes = numBytesWide * getBitmapHeight();

   GLubyte* bitmap = new GLubyte[numFontBytes];

   unsigned int i;  // index

   // Pad rest of the height
   unsigned int diff = numFontBytes - numFileBytes;
   for (i = 0; i < diff; i++) {
      bitmap[i] = reverse ? 255 : 0;
   }

   // Read in the bitmap bytes
   for (; i < numFontBytes; i++) {
      int value;
      nItemsMatched = fscanf(fp, "0x%x\n", &value);
      bitmap[i] = reverse ? GLubyte(~value) : GLubyte(value);
   }

   fclose(fp);

   // Reverse the bitmap
   reverseBitmapOrder(bitmap, numFontBytes, numBytesWide);

   return bitmap;
}
Exemple #25
0
//------------------------------------------------------------------------------
// Open the data file
//------------------------------------------------------------------------------
bool PrintHandler::openFile()
{
   // When we're already open, just return
   if (isOpen()) return true;

   // If we don't have a file name then we're using the standard output
   if (filename == 0 || filename->len() ==  0) return true;

   // clear the old 'full' file name
   setFullFilename(0);

   // local flags (default is success)
   bool tOpened = true;
   bool tFailed = false;


   //---
   // Allocate space for the full file name
   //---
   size_t nameLength = 0;
   if (pathname != 0) {
      nameLength += pathname->len();     // add the length of the path name
      nameLength += 1;                         // add a character for the slash
   }
   nameLength += filename->len();           // add the length of the file name
   nameLength += 4;                         // add characters for possible version number, "_V99"
   nameLength += 1;                         // Add one for the null(0) at the end of the string

   char* fullname = new char[nameLength];
   fullname[0] = '\0';


   //---
   // Create the (initial) full file name
   //---
   if (pathname != 0 && pathname->len() > 0) {
      lcStrcat(fullname, nameLength ,*pathname);
      lcStrcat(fullname, nameLength, "/");
   }
   lcStrcat(fullname,nameLength,*filename);


   //---
   // Make sure that it doesn't already exist (we don't want to over write good data).
   //---
   bool validName = !doesFileExist(fullname);
   if ( !validName ) {
      // If the file already exists, try appending a version number "v99" ..

      char* origname = new char[nameLength];
      lcStrcpy(origname, nameLength, fullname);

      validName = false;
      for (unsigned int i = 1; i <= 99 && !validName; i++) {
         std::sprintf(fullname, "%s_v%02d", origname, i);
         validName = !doesFileExist(fullname);
      }

      if ( !validName ) {
         if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "PrintHandler::openFile(): All version of the data file already exists: " << origname << std::endl;
         }
         tOpened = false;
         tFailed = true;
      }
      delete[] origname;
   }


   //---
   // When we have a valid file name ...
   //---
   if ( validName ) {

      // The file name with the path and version number
      setFullFilename(fullname);

      //---
      // Make sure we have an output stream
      //---
      if (sout == 0) sout = new std::ofstream();

      //---
      // Open the file
      //---
      sout->open(fullname, std::ios_base::out);

      if (isMessageEnabled(MSG_INFO)) {
         std::cout << "PrintHandler::openFile() Opening data file = " << fullname << std::endl;
      }

      if (sout->fail()) {
         if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "PrintHandler::openFile(): Failed to open data file: " << fullname << std::endl;
         }
         tOpened = false;
         tFailed = true;
      }

   }

   delete[] fullname;

   fileOpened = tOpened;
   fileFailed = tFailed;

   return fileOpened;
}
Exemple #26
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
OctalReadout::OctalReadout()
{
   STANDARD_CONSTRUCTOR()
   lcStrcpy(format,FORMAT_LENGTH,"%o");
}
Exemple #27
0
//------------------------------------------------------------------------------
// updateData() -- Update the log file
//------------------------------------------------------------------------------
bool Logger::openFile()
{
    // local flags (default is success)
    bool tOpened = true;
    bool tFailed = false;

    // Need a file name
    if (filename->len() ==  0) {
        if (isMessageEnabled(MSG_ERROR)) {
           std::cerr << "Logger::openFile(): Unable to open logger file: no file name" << std::endl;
        }
        tOpened = false;
        tFailed = true;
    }
    else {

        //---
        // Allocate space for the full file name
        //---
        size_t len = pathname->len();   // start with the length of the path name
        len += 1;   // add a character for the slash
        len += filename->len(); // add the length of the file name
        len += 4;  // add characters for possible version number, "_V99"
        len += 1;  // Add one for the null(0) at the end of the string
		const size_t NAME_LENGTH = len;

        char* fullname = new char[NAME_LENGTH];
        fullname[0] = '\0';

        //---
        // Create the (initial) full file name
        //---
        if (pathname->len() > 0) {
            lcStrcat(fullname,NAME_LENGTH,*pathname);
            lcStrcat(fullname,NAME_LENGTH,"/");
        }
        lcStrcat(fullname,NAME_LENGTH,*filename);

        //---
        // Make sure that it doesn't already exist (we don't want to over write good data).
        //---
        bool validName = !doesFileExist(fullname);
        if ( !validName ) {
            // If the file already exists, try appending a version number "v99" ..

            char* origname = new char[NAME_LENGTH];
            lcStrcpy(origname, NAME_LENGTH, fullname);

            validName = false;
            for (unsigned int i = 1; i <= 99 && !validName; i++) {
                sprintf(fullname, "%s_v%02d", origname, i);
                validName = !doesFileExist(fullname);
            }

            if ( !validName ) {
                if (isMessageEnabled(MSG_ERROR)) {
                  std::cerr << "Logger::openFile(): All version of the logger file already exists: " << origname << std::endl;
                }
                tOpened = false;
                tFailed = true;
            }
            delete[] origname;
        }

        if ( validName ) {
            //---
            // Make sure we have an output stream
            //---
            if (lout == 0) lout = new std::ofstream();

            //---
            // Open the file
            //---
            if (isMessageEnabled(MSG_INFO)) {
               std::cout << "Logger::openFile() Opening log file = " << fullname << std::endl;
            }
            lout->open(fullname);
            if (lout->fail()) {
                if (isMessageEnabled(MSG_ERROR)) {
                  std::cerr << "Logger::openFile(): Failed to open log file: " << fullname << std::endl;
                }
                tOpened = false;
                tFailed = true;
            }
            else if (topLine != 0) {
                *lout << *topLine << std::endl;
            }
                
        }

        delete[] fullname;
    }

    opened = tOpened;
    failed = tFailed;
    return opened;
}
Exemple #28
0
//--------------------------------------------------------------------------
// initialize() - Checks to see we have valid data, then goes through and
// opens all the files that are required (from the input language), and then
// creates Toc Entries for each one.  It then fills each Toc with its frames.
//--------------------------------------------------------------------------
bool CadrgFile::initialize(const char* dir)
{
    numBoundaries = 0;

    // Remove all of our previous entries, if any
    for (int yy = 0; yy < MAX_TOC_ENTRIES; yy++) entries[yy] = 0;

    // Our header
    Header          head;
    // Physical locations of our boundary rectangles
    Location        locations[4];
    // Number of boundary records
    ushort          numBndryRecords = 0;
    ushort          ffPathLength = 0;
    int i = 0;
    int j = 0;
    std::streamoff currTocPos = 0;
    //char            filename[80];
    // Boundary record number
    ushort          boundaryRecNum = 0;
    // Frame row number
    ushort          frameRow = 0;
    // Frame column number
    ushort          frameCol = 0;
    // # of frame file index records
    uint            numFFIdxRec = 0;
    // Offset of frame file pathname
    uint            ffPathOff = 0;
    // Boundary record length
    ushort          bndryRecLength = 0;
    // # frame file pathname records
    ushort          numPathNameRecs = 0;
    // Frame file index record length
    ushort          idxRecLength = 0;
    // TOC NITF header length, if there
    uint            nitfHdrLength = 410;
    // Boundary rectangle table offset
    uint            bndryRecTableOffset = 0;
    // Frame file index table offset (not used)
    uint            ffIdxTableOff = 0;

    // Try to find and open our a.toc file
    std::ifstream    toc;
    Basic::String* string = new Basic::String(dir);
    if (originalDir != 0) originalDir->setStr(dir);
    else originalDir = new Basic::String(dir);
    string->catStr("A.TOC");

    #if defined(WIN32)
        toc.open(*string, std::ios::in | std::ios::binary);
    #else
        toc.open(*string, std::ios::in);
    #endif


    // We didn't make it, so either we have a bad location, or the filename is lower case.  Let's try lowercase.
    if (toc.fail()) {
        // Clear out our input stream
        toc.clear();
        string->empty();
        string->setStr(dir);
        string->catStr("a.toc");
        #if defined(WIN32)
            toc.open(*string, std::ios::in | std::ios::binary);
        #else
            toc.open(*string, std::ios::in);
        #endif
        // If we still failed again, we know it's the directory that is misspelled or doesn't exist, so we print an error
        // and return.
        if (toc.fail()) {
            std::cout << "Could not open the A.TOC or a.toc file in location " << dir << std::endl;
            return false;
        }
    }
    else std::cout << "file = " << dir << std::endl;

    string->unref();


    // Let's read the header section length.
    // We seek right to position 31, to determine our governing spec date, which may or may not be there.  We
    // are going to see if it is there, because if it is, then we don't have an NITF message to worry about.
    toc.seekg(31, std::ios::beg);
    toc.read(head.govSpecdate, sizeof(head.govSpecdate));

    // Now move back to the beginning
    toc.seekg(0, std::ios::beg);

    // If we don't have a standard date of 199... then we know
    // that we have an National Imagery Transmission Format (NITF) message, so we should skip over the message and search
    // for the Raster Product Format Header (RPFHDR).
    if (strncmp(head.govSpecdate, "199", 3) != 0) {
        // Make a large set of characters to read from
        char buf[1024];
        // Read in some of the file
        toc.read(buf,1024);

        // Look for the RPFHDR indicator
        char* ptr = strstr(buf, "RPFHDR");

        // Found it!
        if (ptr) {
            // Distance from where we found RPFHDR to the beginning of the file (sizeof the NITF message, basically)
            int dist = int(ptr - &buf[0]);
            // Padding 11 for some reason.
            nitfHdrLength = dist + 11;
        }
        // Move to where our header starts!
        toc.seekg(nitfHdrLength, std::ios::beg);
    }

    // Ok, we are now at the header portion of the A.TOC file.
    // The Header file is setup like this (according to MIL-PRF-89038 6 OCTOBER 1994)
    // Name                             Type    Size (Bytes)    Position in file
    // <little/big endian indicator>    bool:    1                  1
    // <header section length>          uint:    2                  2
    // <filename>                       ascii:  12                  4
    // <replacement/update indicator>   uint:    1                  15
    // <governing specification num>    ascii:  15                  16
    // <governing spec. date>           ascii:   8                  31
    // <security classification>        ascii:   1                  39
    // <country/intntl code>            ascii:   2                  41
    // <security release marking>       ascii:   2                  43
    // <location section location>      uint:    4                  45

    // endian indicator
    unsigned char byte;
    toc.read((char *) &byte, sizeof(byte));
    head.endian = (byte != 0);

    toc.read((char *) &head.hdrSectionLength, sizeof(head.hdrSectionLength));
    // If we are using big endian encoding, we swap our bytes on uints and ushorts
    if (!head.endian) swap((unsigned char *) &head.hdrSectionLength, sizeof(head.hdrSectionLength));
    toc.read((char *) head.filename, sizeof(head.filename));
    toc.read((char *) &head.nruInd, sizeof(head.nruInd));
    toc.read((char *) head.govSpecNum, sizeof(head.govSpecNum));
    toc.read((char *) head.govSpecdate, sizeof(head.govSpecdate));
    toc.read((char *) &head.secClass, sizeof(head.secClass));
    toc.read((char *) head.secCountryCode, sizeof(head.secCountryCode));
    toc.read((char *) head.secRelease, sizeof(head.secRelease));
    toc.read((char *) &head.locSecLoc, sizeof(head.locSecLoc));
    if (!head.endian) swap((unsigned char *) &head.locSecLoc, sizeof(head.locSecLoc));

    // seek to start of location section:
    toc.seekg(head.locSecLoc, std::ios::beg);

    // We need four different sections to get all of our boundary, frame data and
    // The location section boundary rectangle sub header.
    locations[0].componentId = LOC_BOUNDARY_SECTION_SUBHEADER;     // 148
    // The actual boundary rectangle table
    locations[1].componentId = LOC_BOUNDARY_RECTANGLE_TABLE;       // 149
    // The frame file index section subheader
    locations[2].componentId = LOC_FRAME_FILE_INDEX_SUBHEADER;     // 150
    // The frame file index subsection, which holds the frame index table and records.
    locations[3].componentId = LOC_FRAME_FILE_INDEX_SUBSECTION;    // 151

    // GO through and find the physical locations in the file of each one of our locations we need (see above).
    parseLocations(toc, locations, 4);

    if (locations[0].physicalIdx == ~0) {
        std::cout << "Can't find the LOC_BOUNDARY_SECTION_SUBHEADER in the TOC!" << std::endl;
        return false;
    }
    else if (locations[1].physicalIdx == ~0) {
        std::cout << "Can't find the LOC_BOUNDARY_RECTANGLE_TABLE in the TOC!" << std::endl;
        return false;
    }
    else if (locations[2].physicalIdx == ~0) {
        std::cout << "Can't find the LOC_FRAME_FILE_INDEX_SUBHEADER in the TOC!" << std::endl;
        return false;
    }
    else if (locations[3].physicalIdx == ~0) {
        std::cout << "Can't find the LOC_FRAME_FILE_INDEX_SUBSECTION in the TOC!" << std::endl;
        return false;
    }

    // Our first location is the boundary rectangle section, which lays out the coverage area
    // Seek to the physical offset of the boundary rectangle section subheader
    toc.seekg(locations[0].physicalIdx, std::ios::beg);

    // Skip our boundary table record offset
    toc.read((char *) &bndryRecTableOffset, sizeof(bndryRecTableOffset));
    swap((unsigned char *) &bndryRecTableOffset, 4);

    // Read in the number of boundary rectangle records!
    toc.read((char *) &numBndryRecords, sizeof(numBndryRecords));
    swap((unsigned char *) &numBndryRecords, sizeof(numBndryRecords));

    // Skip the boundary record length
    toc.read((char *) &bndryRecLength, sizeof(bndryRecLength));
    swap((unsigned char *) &bndryRecLength, sizeof(bndryRecLength));

    // Now we have parsed all the header information from the boundary rectangle section subheader.
    // Let's seek to the actual position of the boundary rectangle table and read the data in.
    toc.seekg(locations[1].physicalIdx, std::ios::beg);

    // ------------------------------------------------------------------------------------
    // Our boundaries are setup like this (MIL-STD-2411, pg 45,46)
    // Name                             Type    Size (Bytes)
    // <product data type>              char     5
    // <compression ratio>              char     5
    // <scale>                          char    12
    // <zone>                           char     1
    // <producer>                       char     5
    // <NW/upper left lat>              real     8
    // <NW/upper left lon>              real     8
    // <SW/lower left lat>              real     8
    // <SW/lower left lon>              real     8
    // <NE/upper right lat>             real     8
    // <NE/upper right lon>             real     8
    // <SE/lower right lat>             real     8
    // <SE/lower right lon>             real     8
    // <vertical resolution>            real     8
    // <horizontal resolution>          real     8
    // <vertical interval>              real     8
    // <horizontal interval>            real     8
    // <# of frames vertically>         uint     4
    // <# of frames horizontally>       uint     4
    // ------------------------------------------------------------------------------------

    // Set the number of boundary records
    numBoundaries = numBndryRecords;
    for (i = 0; i < numBndryRecords; i++) {
        // Create a new entry
        entries[i] = new CadrgTocEntry();

        char type[5];
        //strncpy(type, entries[i]->getType(), 5);
        // Read the type in
        toc.read(type, 5);

        if (strncmp(type, "CADRG", 5) == 0)
            cib = false;
        else
            cib = true;

        // Skip the compression ratio
        toc.seekg(5, std::ios::cur);
        // Scale of our map (1:250k, etc...)
        char scale[12];
        strncpy(scale, entries[i]->getScale(), 12);
        toc.read(scale, 12);

        // Read the zone we are in.
        char zone[2];
        strncpy(zone, entries[i]->getZone(), 1);
        toc.read(zone, 1);

        // Skip producer (5 chars)
        toc.seekg(5, std::ios::cur);

        double nwLat = 0, nwLon = 0, swLat = 0, swLon = 0, neLat = 0, neLon = 0, seLat = 0, seLon = 0;
        double vertResolution = 0, horzResolution = 0;
        double vertInterval = 0, horzInterval = 0;
        int vertFrames = 0, horzFrames = 0;

        // Read all of our geodetic data.
        toc.read((char *) &nwLat, sizeof(double));
        toc.read((char *) &nwLon, sizeof(double));
        toc.read((char *) &swLat, sizeof(double));
        toc.read((char *) &swLon, sizeof(double));
        toc.read((char *) &neLat, sizeof(double));
        toc.read((char *) &neLon, sizeof(double));
        toc.read((char *) &seLat, sizeof(double));
        toc.read((char *) &seLon, sizeof(double));
        toc.read((char *) &vertResolution, sizeof(double));
        toc.read((char *) &horzResolution, sizeof(double));
        toc.read((char *) &vertInterval, sizeof(double));
        toc.read((char *) &horzInterval, sizeof(double));
        toc.read((char *) &vertFrames, sizeof(uint));
        toc.read((char *) &horzFrames, sizeof(uint));

        swap((unsigned char *) &nwLat, sizeof(double));
        swap((unsigned char *) &nwLon, sizeof(double));
        swap((unsigned char *) &swLat, sizeof(double));
        swap((unsigned char *) &swLon, sizeof(double));
        swap((unsigned char *) &neLat, sizeof(double));
        swap((unsigned char *) &neLon, sizeof(double));
        swap((unsigned char *) &seLat, sizeof(double));
        swap((unsigned char *) &seLon, sizeof(double));
        swap((unsigned char *) &vertResolution, sizeof(double));
        swap((unsigned char *) &horzResolution, sizeof(double));
        swap((unsigned char *) &vertInterval, sizeof(double));
        swap((unsigned char *) &horzInterval, sizeof(double));
        swap((unsigned char *) &vertFrames, sizeof(uint));
        swap((unsigned char *) &horzFrames, sizeof(uint));

        // Set our values back now
        entries[i]->setNWLat(nwLat);
        entries[i]->setNWLon(nwLon);
        entries[i]->setSWLat(swLat);
        entries[i]->setSWLon(swLon);
        entries[i]->setNELat(neLat);
        entries[i]->setNELon(neLon);
        entries[i]->setSELat(seLat);
        entries[i]->setSELon(seLon);
        entries[i]->setVertResolution(vertResolution);
        entries[i]->setHorizResolution(horzResolution);
        entries[i]->setVertInterval(vertInterval);
        entries[i]->setHorizInterval(horzInterval);
        entries[i]->setVertFrames(vertFrames);
        entries[i]->setHorizFrames(horzFrames);

        if (cib) entries[i]->setType(type, 3);
        else entries[i]->setType(type, 5);
        entries[i]->setScale(scale, 12);
        entries[i]->setZone(zone, 1);

        #if defined (PRINT_MAP_LOCATIONS)
            scale[8] = '\0';
            zone[1] = '\0';
            std::cout << "ZONE #" << zone << ", SCALE = " << scale << ", LATS = " << swLat << ", " << neLat << ", LONS = " << swLon << ", " <<  neLon << std::endl;
        #endif
        vertFrames = entries[i]->getVertFrames();
        horzFrames = entries[i]->getHorizFrames();

        CadrgFrameEntry** frames = new CadrgFrameEntry*[vertFrames];

        for (j = 0; j < vertFrames; j++) {
            frames[j] = new CadrgFrameEntry[horzFrames];
        }
        entries[i]->generateItems();
        entries[i]->setEntries(frames);
    }


    // Read # of frame file index records
    // Skip 1 byte highest security classification
    // locations[2] + 1 is the physical location of frame file index section subheader + we skip one byte
    // for the security classification
    toc.seekg(locations[2].physicalIdx + 1, std::ios::beg);

    // The frame file index table offset
    toc.read((char *) &ffIdxTableOff, sizeof(ffIdxTableOff));
    swap((unsigned char *) &ffIdxTableOff, 4);

    // Number of frame file index records
    toc.read((char *) &numFFIdxRec, sizeof(numFFIdxRec));
    swap((unsigned char *) &numFFIdxRec, sizeof(numFFIdxRec));

    // Number of pathname records
    toc.read((char *) &numPathNameRecs, sizeof(numPathNameRecs));
    swap((unsigned char *) &numPathNameRecs, sizeof(numPathNameRecs));

    // Frame file index record length
    toc.read((char *) &idxRecLength, sizeof(idxRecLength));
    swap((unsigned char *) &idxRecLength, sizeof(idxRecLength));

    // Here is a temp pointer to our TOC entries
    CadrgTocEntry* entry = 0;

    // Temp point to our TOC entries frame file
    CadrgFrameEntry* frame = 0;

    // Read through all of our frame files.
    for (i = 0; i < static_cast<int>(numFFIdxRec); i++) {

        // Locations[3] is frame file index table subsection * the record we are on.
        toc.seekg(locations[3].physicalIdx + idxRecLength * i, std::ios::beg);

        toc.read(reinterpret_cast<char*>(&boundaryRecNum), sizeof(boundaryRecNum));
        swap(reinterpret_cast<unsigned char*>(&boundaryRecNum), sizeof(boundaryRecNum));


        // If we are outside of our boundaries, print an error!
        if (entries[boundaryRecNum] != 0 && boundaryRecNum <= numBoundaries - 1) {
            // Get our toc entry from our list
            entry = entries[boundaryRecNum];
            if (entry != 0) {
                entry->ref();

                // Read in the starting frame row and column of this frame
                toc.read((char *) &frameRow, sizeof(frameRow));
                toc.read((char *) &frameCol, sizeof(frameCol));
                swap((unsigned char *) &frameRow, sizeof(frameRow));
                swap((unsigned char *) &frameCol, sizeof(frameCol));

                // We already know how many vertical and horizontal frames we have
                int vertFrames = entry->getVertFrames();
                int horzFrames = entry->getHorizFrames();

                // If our row is greater than the # of frame we have, print out an error and return!
                if (frameRow > vertFrames - 1) {
                    std::cout << "Frame Row #" << frameRow << " is greater than the # of vertical frames, which = " << vertFrames << std::endl;
                    return false;
                }

                // If our frame column is greater than the # of horizontal frames we have, print out error and return.
                if (frameCol > horzFrames - 1) {
                    std::cout << "Frame Col #" << frameCol << " is greater than the # of horizontal frames, which = " << horzFrames << std::endl;
                    return false;
                }

                // Get our frames
                CadrgFrameEntry** frames = entry->getFrames();

                // Set a local frame to manipulate
                if (frames != 0) frame = &frames[(vertFrames - 1) - frameRow][frameCol];
                if (frame != 0 && !frame->doIExist()) {
                    // Get our path name byte offset
                    toc.read((char *) &ffPathOff, sizeof(ffPathOff));
                    swap((unsigned char *) &ffPathOff, sizeof(ffPathOff));

                    // Save file position for later
                    currTocPos = toc.tellg();

                    // Go to start of pathname record, which is our LOC_FRAME_FILE_INDEX_SUBSECTION + the path offset
                    toc.seekg(locations[3].physicalIdx + ffPathOff, std::ios::beg);

                    toc.read((char *) &ffPathLength, sizeof(ffPathLength));
                    swap((unsigned char *) &ffPathLength, sizeof(ffPathLength));

                    // Allocate our frame file directory path, which is our path name length + 1 + string length of the directory name passed in

                    size_t size = ffPathLength + 1 + strlen(dir);
                    #if defined(WIN32)
                        char* directory = (char *) malloc(size);
                    #else
                        char* directory = (char *) alloca(size);
                    #endif

                    // 1st part of directory name is passed as our initial parameter "projects/data/maps/gncjncn/RPF/"
                    lcStrcpy(directory, size, dir);


                    // Read rest of directory name from Toc
                    // Skip 1st 2 chars, because they are the root characters (./), and are ignored since we are creating
                    // our own directory string
                    toc.read(&directory[strlen(dir)], 2);

                    // We read the rest, minus the first 2 characters
                    toc.read(&directory[strlen(dir)], ffPathLength - 2);
                    directory[ffPathLength - 2 + strlen(dir)] = '\0';

                    // Go back to get filename tail
                    toc.seekg(currTocPos, std::ios::beg);

                    // Get the actual frame file name!
                    char frameFilename[16];
                    toc.read(frameFilename, 12);
                    frameFilename[12] = '\0';

                    // Set our final path name, and file name!
                    frame->setPathName(directory, frameFilename);
                    frame->setCib(cib);
                }
                else {
                    std::cout << "Frame File #" << i << " is a duplicate!" << std::endl;
                    return false;
                }
                // Get rid of our entry and reset
                entry->unref();
                entry = 0;
            }
            else std::cout << "No TOC entry available at position " << boundaryRecNum << std::endl;
        }
        else {
            std::cout << "Bad boundary id in frame file index record " << std::endl;
            return false;
        }
    }
    // Clear out our entries
    toc.close();

    return true;
}
Exemple #29
0
//------------------------------------------------------------------------------
// getInputValue() -- returns the readout as a numeric value
//------------------------------------------------------------------------------
double TimeReadout::getInputValue() const
{
   double value = 0.0;

   // copy string to buffer with correct sign character
   const size_t CBUFLOCAL_LEN = 100;
   char cbuf[CBUFLOCAL_LEN];
   const char* p = *this;
   lcStrcpy(cbuf,CBUFLOCAL_LEN,p);
   if (cbuf[0] == plusChar)  cbuf[0] = '+';
   if (cbuf[0] == minusChar) cbuf[0] = '-';

   // Modify the output format statement for use with the sscanf
   char format1[32];
   int i = 0;
   int j = 0;
   bool skipIt = false;
   for (i = 0;  i < 31 && format[i] != '\0'; i++) {
      if (skipIt && format[i] == 'f') skipIt = false;
      if (format[i] == '.') {
         skipIt = true;
      }
      else if ((format[i] != '+' && format[i] != '-' && format[i] != '0')
         && !skipIt) {
            format1[j++] = format[i];
      }
   }
   format1[j] = '\0';

   switch (tmode) {

      case hhmmss : {        // Hours, Minutes, and seconds
         int   hrs = 0;
         int   min = 0;
         float sec = 0.0f;
         sscanf(cbuf, format1, &hrs, &min, &sec);
         value = hrs*60.0f;
         if (value >= 0.0) value += min;
         else value -= min;
         value *= 60.0;
         if (value >= 0.0) value += sec;
         else value -= sec;
      }
      break;

      case hhmm : { // Hours and minutes
         int   hrs = 0;
         float min = 0.0f;
         sscanf(cbuf, format1, &hrs, &min);
         value = hrs*60.0f;
         if (value >= 0.0) value += min;
         else value -= min;
         value *= 60.0;
      }
      break;

      case hh : {   // Hours only
         float hrs = 0.0f;
         sscanf(cbuf, format1, &hrs);
         value = hrs*3600.0f;
      }
      break;

      case mmss : { // Minutes and seconds
         int   min = 0;
         float sec = 0.0f;
         sscanf(cbuf, format1, &min, &sec);
         value = min*60.0f;
         if (value >= 0.0) value += sec;
         else value -= sec;
      }
      break;

      case mm : {   // Minutes only
         float min = 0.0;
         sscanf(cbuf, format1, &min);
         value = min*60.0f;
      }
      break;

      case ss : {   // Seconds only
         float sec = 0.0;
         sscanf(cbuf, format1, &sec);
         value = sec;
      }
      break;
   }
   return double(value);
}
Exemple #30
0
//------------------------------------------------------------------------------
// Class support functions
//------------------------------------------------------------------------------
HexReadout::HexReadout()
{
   STANDARD_CONSTRUCTOR()
   lcStrcpy(format,FORMAT_LENGTH,"%X");
}