std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::string defVal) const { //finds variable in same manner as SetVariable, but if not found doesn't create, just returns default value std::list<ZCF_Section>::const_iterator secIter; std::list<ZCF_Variable>::const_iterator varIter; sec = CleanString(sec); var = CleanString(var); if(Exists(sec)) { for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) { if(CleanString((*secIter).section) == sec) //if this is the section { if(Exists(sec,var)) { for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) { if(CleanString((*varIter).var) == var) //if this is the variable return (*varIter).val; //return now } break; //done in the for loop, time to go } else { return defVal; break; } } } } return defVal; //if it gets to the end just return the default }
boolean DEH_ParseAssignment(char *line, char **variable_name, char **value) { char *p; // find the equals p = strchr(line, '='); if (p == NULL) { return false; } // variable name at the start // turn the '=' into a \0 to terminate the string here *p = '\0'; *variable_name = CleanString(line); // value immediately follows the '=' *value = CleanString(p+1); return true; }
bool ZConfigFile::Exists(std::string sec) const { std::list<ZCF_Section>::const_iterator secIter; sec = CleanString(sec); //check list for 'cleaned' version of string for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) { if(CleanString((*secIter).section) == sec) return true; } return false; }
int PDSDataset::ParseCompressedImage() { CPLString osFileName = GetKeyword( "COMPRESSED_FILE.FILE_NAME", "" ); CleanString( osFileName ); CPLString osPath = CPLGetPath(GetDescription()); CPLString osFullFileName = CPLFormFilename( osPath, osFileName, NULL ); int iBand; poCompressedDS = (GDALDataset*) GDALOpen( osFullFileName, GA_ReadOnly ); if( poCompressedDS == NULL ) return FALSE; nRasterXSize = poCompressedDS->GetRasterXSize(); nRasterYSize = poCompressedDS->GetRasterYSize(); for( iBand = 0; iBand < poCompressedDS->GetRasterCount(); iBand++ ) { SetBand( iBand+1, new PDSWrapperRasterBand( poCompressedDS->GetRasterBand( iBand+1 ) ) ); } return TRUE; }
std::string FilterStopwords(std::string& fstr){ // this only works with -std=c++11, change to char**. std::vector<std::string> stopwords = {" a ", " I ", " has ", " was ", " had ", " which ", " so ", " it ", " who ", "who ", " that ", ",", "\n", "."}; for(std::vector<std::string>::iterator i = stopwords.begin(); i != stopwords.end(); i++){ CleanString(fstr, *i); } return fstr; }
int ZConfigFile::GetInt(std::string section, std::string var, int defVal) const { std::string val; char tmp[20]; section = CleanString(section); var = CleanString(var); section = '[' + section + ']'; sprintf(tmp,"%d",defVal); val = GetVariable(section,var,tmp); if(!atoi(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero return defVal; else return atoi(val.c_str()); }
//each get* gets the variable (stored as a string) from using GetVariable, then converts it to the desired format float ZConfigFile::GetFloat(std::string section, std::string var, float defVal) const { std::string val; char tmp[20]; section = CleanString(section); var = CleanString(var); section = '[' + section + ']'; sprintf(tmp,"%f",defVal); val = GetVariable(section,var,tmp); if(!atof(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero return defVal; else return static_cast<float>(atof(val.c_str())); //atof returns a double(?!) }
bool ZConfigFile::GetBool(std::string section, std::string var, bool defVal) const { std::string val,tmp; section = CleanString(section); var = CleanString(var); section = '[' + section + ']'; tmp = defVal ? "true" : "false"; val = CleanString(GetVariable(section,var,tmp)); if(val == "true" || val == "1") return true; else if(val == "false" || val == "0") return false; else return defVal; }
std::string ZConfigFile::GetString(std::string section, std::string var, std::string defVal) const { std::string val; section = CleanString(section); var = CleanString(var); section = '[' + section + ']'; val = CleanString(GetVariable(section,var,defVal)); if(val == CleanString(defVal)) val = defVal; if(val[0] == '\"' && val[val.length()-1] == '\"') return val.substr(1,val.length()-2); //chop off quotes else return val; }
void CData::LevelMetricTypeAsync( const std::string& type, const std::string name, const std::string& level, int day, int month, int year, RequestDelegate targetDelegate ) { std::string cleanName(name); std::string cleanLevel(level); CleanString(cleanName); CleanString(cleanLevel); char date[60]; sprintf_s(date,59,"%d", gPlaytomic->GameId()); std::string url(kDataLevelUrl1); url += gPlaytomic->GetGameGuid() + kDataLevelUrl2 + type + kDataLevelUrl3; url += date; url += kDataLevelUrl4 + cleanName ; url += kDataLevelUrl5 + cleanLevel ; sprintf_s(date,59,"%d%s%d%s%d", day, kDataLevelUrl7, month, kDataLevelUrl8, year); url += kDataLevelUrl6;url += date; GetDataAsync(url, targetDelegate); }
void ZConfigFile::SetVariable(std::string sec, std::string var, std::string val) { std::list<ZCF_Section>::iterator secIter; std::list<ZCF_Variable>::iterator varIter; if(Exists(CleanString(sec))) //if section exists find it { sec = CleanString(sec); for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) { if(CleanString((*secIter).section) == sec) //if this is the section { if(Exists(sec,var)) //if variable exists find it { var = CleanString(var); for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) { if(CleanString((*varIter).var) == var) //once variable found, set value { (*varIter).val = val; break; //break from this loop } } break; //done in the for loop, time to go } else { ZCF_Variable tempVar; tempVar.var = var; (*secIter).varList.push_back(tempVar); SetVariable(sec,var,val); } } } } else { ZCF_Section tempSec; tempSec.section = sec; rFileLayout.push_back(tempSec); SetVariable(sec,var,val); } }
CPlaytomicResponsePtr CData::LevelMetricType( const std::string& type, const std::string name, const std::string& level, int day, int month, int year ) { std::string cleanName(name); std::string cleanLevel(level); CleanString(cleanName); CleanString(cleanLevel); char date[60]; sprintf_s(date,59,"%d", gPlaytomic->GameId()); std::string url(kDataLevelUrl1); url += gPlaytomic->GetGameGuid() + kDataLevelUrl2 + type + kDataLevelUrl3; url += date; url += kDataLevelUrl4 + cleanName ; url += kDataLevelUrl5 + cleanLevel ; sprintf_s(date,59,"%d%s%d%s%d", day, kDataLevelUrl7, month, kDataLevelUrl8, year); url += kDataLevelUrl6;url += date; return GetData(url); }
void ZConfigFile::Flush() { std::list<ZCF_Section>::iterator secIter; std::list<ZCF_Variable>::iterator varIter; std::string secName; //in case the filename is already cleared somehow if(rFilename.length()) { //open the file blanked out, to not duplicate entries std::ofstream cfile(rFilename.c_str(), std::ios::out|std::ios::trunc); if(cfile) { //iteration through sections for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) { //ensure that section is valid secName = CleanString((*secIter).section); if(secName.length() && secName[0] == '[' && secName[secName.length()-1] == ']') { cfile << (*secIter).section << std::endl; //write out raw section title //for each variable in section, write out variable=value for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) { if((*varIter).var[0] == '_') { if( ((*varIter).var).substr(2,7) == "comment") cfile << (*varIter).val << std::endl; else if( ((*varIter).var).substr(2,7) == "newline") cfile << std::endl; } else if(CleanString((*varIter).var).length()) //ensures that variable is valid cfile << (*varIter).var << '=' << (*varIter).val << std::endl; } } } cfile.close(); } } }
/** * Clean a string and write it to the Port. */ static bool WriteCleanString(Port &port, const TCHAR *p, OperationEnvironment &env, unsigned timeout_ms) { NarrowString<256> buffer; buffer.SetASCII(p); CleanString(buffer.buffer()); return port.FullWriteString(buffer, env, timeout_ms); }
bool ZConfigFile::Exists(std::string sec, std::string var) const { std::list<ZCF_Section>::const_iterator secIter; std::list<ZCF_Variable>::const_iterator varIter; sec = CleanString(sec); var = CleanString(var); //first find section, then do same search for variable for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) { if(CleanString((*secIter).section) == sec) { for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) { if(CleanString((*varIter).var) == var) return true; } } } return false; }
void CData::CustomMetricAsync( const std::string& name, int day, int month, int year, RequestDelegate targetDelegate ) { std::string cleanName = name; CleanString(cleanName); char date[60]; sprintf_s(date,59,"%d", gPlaytomic->GameId()); std::string url(kDataCustomUrl1); url += gPlaytomic->GetGameGuid() + kDataCustomUrl2 +date + kDataCustomUrl3 + cleanName + kDataCustomUrl4; sprintf_s(date,59,"%d%s%d%s%d", day, kDataCustomUrl5, month, kDataCustomUrl6, year); url += date; url += kDataCustomUrl6; GetDataAsync(url, targetDelegate); }
CPlaytomicResponsePtr CData::CustomMetric( const std::string& name, int day/*=0*/, int month/*=0*/, int year/*=0*/ ) { std::string cleanName = name; CleanString(cleanName); char date[60]; sprintf_s(date,59,"%d", gPlaytomic->GameId()); std::string url(kDataCustomUrl1); url += gPlaytomic->GetGameGuid() + kDataCustomUrl2 +date + kDataCustomUrl3 + cleanName + kDataCustomUrl4; sprintf_s(date,59,"%d%s%d%s%d", day, kDataCustomUrl5, month, kDataCustomUrl6, year); url += date; url += kDataCustomUrl6; return GetData(url); }
/** * Clean a string and write it to the Port. */ static bool WriteCleanString(Port &port, const TCHAR *p, unsigned timeout_ms) { char buffer[256]; #ifdef _UNICODE if (::WideCharToMultiByte(CP_ACP, 0, p, -1, buffer, sizeof(buffer), NULL, NULL) <= 0) return false; #else CopyString(buffer, p, sizeof(buffer)); #endif CleanString(buffer); return port.FullWriteString(buffer, timeout_ms); }
void ZConfigFile::Process(std::string filename) { rFilename = filename; int commentNum,newlineNum; char commentStr[15],newlineStr[15]; std::string section, str, var, tmp; std::ifstream cfile(rFilename.c_str()); commentNum = newlineNum = 0; //comment/newline support is a bit of a hack rFileLayout.clear(); //layout must be cleared, in case variable is being used multiple times while(!cfile.eof() && cfile.is_open()) //parses entire file { std::getline(cfile,str); //read in a line tmp = CleanString(str); //get a clean version //if std::string is bracketed it is a section, if it begins in a letter it is a variable if(tmp[0] == '[' && tmp[tmp.length()-1] == ']') section = str; else if(std::isalpha(tmp[0])) //variables must start with a letter { var = str.substr(0,str.find('=')); //split the std::string at the equals sign SetVariable(section,var,str.substr(str.find('=')+1,str.length()-var.length()-1)); } else if(tmp[0] == '#' || tmp[0] == ';') //acceptable comment characters { sprintf(commentStr,"__comment%d",commentNum); SetVariable(section,commentStr,str); ++commentNum; } else if(tmp.length() == 0 && !cfile.eof()) //avoid adding a line to end of file each time { sprintf(newlineStr,"__newline%d",newlineNum); SetVariable(section,newlineStr,str); ++newlineNum; } } cfile.close(); }
void CLogRequest::SaveToFile() { const char *currentFileName = GetLogFileName(); m.lock(); CFile backupData(currentFileName); if(backupData.GetSize() < kMaxFileSize) { if(!mHasDate) { boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time(); std::string strDate("&date="); std::string date = boost::posix_time::to_simple_string(now); CleanString(date); strDate += date; mData += strDate; } backupData.WriteLine(mData); } backupData.Close(); m.unlock(); }
int OGRPDSDataSource::Open( const char * pszFilename ) { pszName = CPLStrdup( pszFilename ); // -------------------------------------------------------------------- // Does this appear to be a .PDS table file? // -------------------------------------------------------------------- VSILFILE* fp = VSIFOpenL(pszFilename, "rb"); if (fp == NULL) return FALSE; char szBuffer[512]; int nbRead = (int)VSIFReadL(szBuffer, 1, sizeof(szBuffer) - 1, fp); szBuffer[nbRead] = '\0'; const char* pszPos = strstr(szBuffer, "PDS_VERSION_ID"); int bIsPDS = (pszPos != NULL); if (!bIsPDS) { VSIFCloseL(fp); return FALSE; } if (!oKeywords.Ingest(fp, pszPos - szBuffer)) { VSIFCloseL(fp); return FALSE; } VSIFCloseL(fp); CPLString osRecordType = oKeywords.GetKeyword( "RECORD_TYPE", "" ); CPLString osFileRecords = oKeywords.GetKeyword( "FILE_RECORDS", "" ); CPLString osRecordBytes = oKeywords.GetKeyword( "RECORD_BYTES", "" ); int nRecordSize = atoi(osRecordBytes); if (osRecordType.size() == 0 || osFileRecords.size() == 0 || osRecordBytes.size() == 0 || nRecordSize <= 0) { CPLError(CE_Failure, CPLE_NotSupported, "One of RECORD_TYPE, FILE_RECORDS or RECORD_BYTES is missing"); return FALSE; } CleanString(osRecordType); if (osRecordType.compare("FIXED_LENGTH") != 0) { CPLError(CE_Failure, CPLE_NotSupported, "Only RECORD_TYPE=FIXED_LENGTH is supported"); return FALSE; } CPLString osTable = oKeywords.GetKeyword( "^TABLE", "" ); if (osTable.size() != 0) LoadTable(pszFilename, nRecordSize, "TABLE"); else { VSILFILE* fp = VSIFOpenL(pszFilename, "rb"); if (fp == NULL) return FALSE; while(TRUE) { CPLPushErrorHandler(CPLQuietErrorHandler); const char* pszLine = CPLReadLine2L(fp, 256, NULL); CPLPopErrorHandler(); CPLErrorReset(); if (pszLine == NULL) break; char** papszTokens = CSLTokenizeString2( pszLine, " =", CSLT_HONOURSTRINGS ); int nTokens = CSLCount(papszTokens); if (nTokens == 2 && papszTokens[0][0] == '^' && strstr(papszTokens[0], "TABLE") != NULL) { LoadTable(pszFilename, nRecordSize, papszTokens[0] + 1); } CSLDestroy(papszTokens); papszTokens = NULL; } VSIFCloseL(fp); } return nLayers != 0; }
int OGRPDSDataSource::LoadTable(const char* pszFilename, int nRecordSize, CPLString osTableID ) { CPLString osTableFilename; int nStartBytes; CPLString osTableLink = "^"; osTableLink += osTableID; CPLString osTable = oKeywords.GetKeyword( osTableLink, "" ); if( osTable[0] == '(' ) { osTableFilename = GetKeywordSub(osTableLink, 1, ""); CPLString osStartRecord = GetKeywordSub(osTableLink, 2, ""); nStartBytes = (atoi(osStartRecord.c_str()) - 1) * nRecordSize; if (osTableFilename.size() == 0 || osStartRecord.size() == 0 || nStartBytes < 0) { CPLError(CE_Failure, CPLE_NotSupported, "Cannot parse %s line", osTableLink.c_str()); return FALSE; } CPLString osTPath = CPLGetPath(pszFilename); CleanString( osTableFilename ); osTableFilename = CPLFormCIFilename( osTPath, osTableFilename, NULL ); } else { osTableFilename = oKeywords.GetKeyword( osTableLink, "" ); if (osTableFilename.size() != 0 && osTableFilename[0] >= '0' && osTableFilename[0] <= '9') { nStartBytes = atoi(osTableFilename.c_str()) - 1; if (strstr(osTableFilename.c_str(), "<BYTES>") == NULL) nStartBytes *= nRecordSize; osTableFilename = pszFilename; } else { CPLString osTPath = CPLGetPath(pszFilename); CleanString( osTableFilename ); osTableFilename = CPLFormCIFilename( osTPath, osTableFilename, NULL ); nStartBytes = 0; } } CPLString osTableName = oKeywords.GetKeyword( MakeAttr(osTableID, "NAME"), "" ); if (osTableName.size() == 0) { if (GetLayerByName(osTableID.c_str()) == NULL) osTableName = osTableID; else osTableName = CPLSPrintf("Layer_%d", nLayers+1); } CleanString(osTableName); CPLString osTableInterchangeFormat = oKeywords.GetKeyword( MakeAttr(osTableID, "INTERCHANGE_FORMAT"), "" ); CPLString osTableRows = oKeywords.GetKeyword( MakeAttr(osTableID, "ROWS"), "" ); int nRecords = atoi(osTableRows); if (osTableInterchangeFormat.size() == 0 || osTableRows.size() == 0 || nRecords < 0) { CPLError(CE_Failure, CPLE_NotSupported, "One of TABLE.INTERCHANGE_FORMAT or TABLE.ROWS is missing"); return FALSE; } CleanString(osTableInterchangeFormat); if (osTableInterchangeFormat.compare("ASCII") != 0 && osTableInterchangeFormat.compare("BINARY") != 0) { CPLError(CE_Failure, CPLE_NotSupported, "Only INTERCHANGE_FORMAT=ASCII or BINARY is supported"); return FALSE; } VSILFILE* fp = VSIFOpenL(osTableFilename, "rb"); if (fp == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", osTableFilename.c_str()); return FALSE; } CPLString osTableStructure = oKeywords.GetKeyword( MakeAttr(osTableID, "^STRUCTURE"), "" ); if (osTableStructure.size() != 0) { CPLString osTPath = CPLGetPath(pszFilename); CleanString( osTableStructure ); osTableStructure = CPLFormCIFilename( osTPath, osTableStructure, NULL ); } GByte* pabyRecord = (GByte*) VSIMalloc(nRecordSize + 1); if (pabyRecord == NULL) { VSIFCloseL(fp); return FALSE; } pabyRecord[nRecordSize] = 0; papoLayers = (OGRLayer**) CPLRealloc(papoLayers, (nLayers + 1) * sizeof(OGRLayer*)); papoLayers[nLayers] = new OGRPDSLayer(osTableID, osTableName, fp, pszFilename, osTableStructure, nRecords, nStartBytes, nRecordSize, pabyRecord, osTableInterchangeFormat.compare("ASCII") == 0); nLayers++; return TRUE; }
int PDSDataset::ParseImage( CPLString osPrefix ) { /* ------------------------------------------------------------------- */ /* We assume the user is pointing to the label (ie. .lbl) file. */ /* ------------------------------------------------------------------- */ // IMAGE can be inline or detached and point to an image name // ^IMAGE = 3 // ^IMAGE = "GLOBAL_ALBEDO_8PPD.IMG" // ^IMAGE = "MEGT90N000CB.IMG" // ^IMAGE = ("BLAH.IMG",1) -- start at record 1 (1 based) // ^IMAGE = ("BLAH.IMG") -- still start at record 1 (equiv of "BLAH.IMG") // ^IMAGE = ("BLAH.IMG", 5 <BYTES>) -- start at byte 5 (the fifth byte in the file) // ^IMAGE = 10851 <BYTES> // ^SPECTRAL_QUBE = 5 for multi-band images CPLString osImageKeyword = osPrefix + "^IMAGE"; CPLString osQube = GetKeyword( osImageKeyword, "" ); CPLString osTargetFile = GetDescription(); if (EQUAL(osQube,"")) { osImageKeyword = "^SPECTRAL_QUBE"; osQube = GetKeyword( osImageKeyword ); } int nQube = atoi(osQube); int nDetachedOffset = 0; int bDetachedOffsetInBytes = FALSE; if( osQube.size() && osQube[0] == '(' ) { osQube = "\""; osQube += GetKeywordSub( osImageKeyword, 1 ); osQube += "\""; nDetachedOffset = atoi(GetKeywordSub( osImageKeyword, 2, "1")) - 1; // If this is not explicitly in bytes, then it is assumed to be in // records, and we need to translate to bytes. if (strstr(GetKeywordSub(osImageKeyword,2),"<BYTES>") != NULL) bDetachedOffsetInBytes = TRUE; } if( osQube.size() && osQube[0] == '"' ) { CPLString osTPath = CPLGetPath(GetDescription()); CPLString osFilename = osQube; CleanString( osFilename ); osTargetFile = CPLFormCIFilename( osTPath, osFilename, NULL ); osExternalCube = osTargetFile; } GDALDataType eDataType = GDT_Byte; //image parameters int nRows, nCols, nBands = 1; int nSkipBytes = 0; int itype; int record_bytes; char chByteOrder = 'M'; //default to MSB double dfNoData = 0.0; /* -------------------------------------------------------------------- */ /* Checks to see if this is raw PDS image not compressed image */ /* so ENCODING_TYPE either does not exist or it equals "N/A". */ /* Compressed types will not be supported in this routine */ /* -------------------------------------------------------------------- */ const char *value; CPLString osEncodingType = GetKeyword(osPrefix+"IMAGE.ENCODING_TYPE","N/A"); CleanString(osEncodingType); if ( !EQUAL(osEncodingType.c_str(),"N/A") ) { CPLError( CE_Failure, CPLE_OpenFailed, "*** PDS image file has an ENCODING_TYPE parameter:\n" "*** gdal pds driver does not support compressed image types\n" "found: (%s)\n\n", osEncodingType.c_str() ); return FALSE; } /**************** end ENCODING_TYPE check ***********************/ /*********** Grab layout type (BSQ, BIP, BIL) ************/ // AXIS_NAME = (SAMPLE,LINE,BAND) /*********** Grab samples lines band **************/ /** if AXIS_NAME = "" then Bands=1 and Sample and Lines **/ /** are there own keywords "LINES" and "LINE_SAMPLES" **/ /** if not NULL then CORE_ITEMS keyword i.e. (234,322,2) **/ /***********************************************************/ char szLayout[10] = "BSQ"; //default to band seq. value = GetKeyword( osPrefix+"IMAGE.AXIS_NAME", "" ); if (EQUAL(value,"(SAMPLE,LINE,BAND)") ) { strcpy(szLayout,"BSQ"); nCols = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",1)); nRows = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",2)); nBands = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",3)); } else if (EQUAL(value,"(BAND,LINE,SAMPLE)") ) { strcpy(szLayout,"BIP"); nBands = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",1)); nRows = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",2)); nCols = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",3)); } else if (EQUAL(value,"(SAMPLE,BAND,LINE)") ) { strcpy(szLayout,"BIL"); nCols = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",1)); nBands = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",2)); nRows = atoi(GetKeywordSub(osPrefix+"IMAGE.CORE_ITEMS",3)); } else if ( EQUAL(value,"") ) { strcpy(szLayout,"BSQ"); nCols = atoi(GetKeyword(osPrefix+"IMAGE.LINE_SAMPLES","")); nRows = atoi(GetKeyword(osPrefix+"IMAGE.LINES","")); nBands = atoi(GetKeyword(osPrefix+"IMAGE.BANDS","1")); } else { CPLError( CE_Failure, CPLE_OpenFailed, "%s layout not supported. Abort\n\n", value); return FALSE; } /*********** Grab Qube record bytes **********/ record_bytes = atoi(GetKeyword(osPrefix+"IMAGE.RECORD_BYTES")); if (record_bytes == 0) record_bytes = atoi(GetKeyword(osPrefix+"RECORD_BYTES")); // this can happen with "record_type = undefined". if( record_bytes == 0 ) record_bytes = 1; if( nQube >0 && osQube.find("<BYTES>") != CPLString::npos ) nSkipBytes = nQube - 1; else if (nQube > 0 ) nSkipBytes = (nQube - 1) * record_bytes; else if( nDetachedOffset > 0 ) { if (bDetachedOffsetInBytes) nSkipBytes = nDetachedOffset; else nSkipBytes = nDetachedOffset * record_bytes; } else nSkipBytes = 0; nSkipBytes += atoi(GetKeyword(osPrefix+"IMAGE.LINE_PREFIX_BYTES","")); /*********** Grab SAMPLE_TYPE *****************/ /** if keyword not found leave as "M" or "MSB" **/ CPLString osST = GetKeyword( osPrefix+"IMAGE.SAMPLE_TYPE" ); if( osST.size() >= 2 && osST[0] == '"' && osST[osST.size()-1] == '"' ) osST = osST.substr( 1, osST.size() - 2 ); if( (EQUAL(osST,"LSB_INTEGER")) || (EQUAL(osST,"LSB")) || // just incase (EQUAL(osST,"LSB_UNSIGNED_INTEGER")) || (EQUAL(osST,"LSB_SIGNED_INTEGER")) || (EQUAL(osST,"UNSIGNED_INTEGER")) || (EQUAL(osST,"VAX_REAL")) || (EQUAL(osST,"VAX_INTEGER")) || (EQUAL(osST,"PC_INTEGER")) || //just incase (EQUAL(osST,"PC_REAL")) ) { chByteOrder = 'I'; } /**** Grab format type - pds supports 1,2,4,8,16,32,64 (in theory) **/ /**** I have only seen 8, 16, 32 (float) in released datasets **/ itype = atoi(GetKeyword(osPrefix+"IMAGE.SAMPLE_BITS","")); switch(itype) { case 8 : eDataType = GDT_Byte; dfNoData = NULL1; break; case 16 : if( strstr(osST,"UNSIGNED") != NULL ) eDataType = GDT_UInt16; else eDataType = GDT_Int16; dfNoData = NULL2; break; case 32 : eDataType = GDT_Float32; dfNoData = NULL3; break; case 64 : eDataType = GDT_Float64; dfNoData = NULL3; break; default : CPLError( CE_Failure, CPLE_AppDefined, "Sample_bits of %d is not supported in this gdal PDS reader.", itype); return FALSE; } /* -------------------------------------------------------------------- */ /* Is there a specific nodata value in the file? Either the */ /* MISSING or MISSING_CONSTANT keywords are nodata. */ /* -------------------------------------------------------------------- */ if( GetKeyword( osPrefix+"IMAGE.MISSING", NULL ) != NULL ) dfNoData = CPLAtofM( GetKeyword( osPrefix+"IMAGE.MISSING", "" ) ); if( GetKeyword( osPrefix+"IMAGE.MISSING_CONSTANT", NULL ) != NULL ) dfNoData = CPLAtofM( GetKeyword( osPrefix+"IMAGE.MISSING_CONSTANT","")); /* -------------------------------------------------------------------- */ /* Did we get the required keywords? If not we return with */ /* this never having been considered to be a match. This isn't */ /* an error! */ /* -------------------------------------------------------------------- */ if( nRows < 1 || nCols < 1 || nBands < 1 ) { CPLError( CE_Failure, CPLE_AppDefined, "File %s appears to be a PDS file, but failed to find some required keywords.", GetDescription() ); return FALSE; } /* -------------------------------------------------------------------- */ /* Capture some information from the file that is of interest. */ /* -------------------------------------------------------------------- */ nRasterXSize = nCols; nRasterYSize = nRows; /* -------------------------------------------------------------------- */ /* Open target binary file. */ /* -------------------------------------------------------------------- */ if( eAccess == GA_ReadOnly ) { fpImage = VSIFOpenL( osTargetFile, "rb" ); if( fpImage == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to open %s.\n%s", osTargetFile.c_str(), VSIStrerror( errno ) ); return FALSE; } } else { fpImage = VSIFOpenL( osTargetFile, "r+b" ); if( fpImage == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to open %s with write permission.\n%s", osTargetFile.c_str(), VSIStrerror( errno ) ); return FALSE; } } /* -------------------------------------------------------------------- */ /* Compute the line offset. */ /* -------------------------------------------------------------------- */ int nItemSize = GDALGetDataTypeSize(eDataType)/8; int nLineOffset = record_bytes; int nPixelOffset, nBandOffset; if( EQUAL(szLayout,"BIP") ) { nPixelOffset = nItemSize * nBands; nBandOffset = nItemSize; nLineOffset = ((nPixelOffset * nCols + record_bytes - 1)/record_bytes) * record_bytes; } else if( EQUAL(szLayout,"BSQ") ) { nPixelOffset = nItemSize; nLineOffset = ((nPixelOffset * nCols + record_bytes - 1)/record_bytes) * record_bytes; nBandOffset = nLineOffset * nRows; } else /* assume BIL */ { nPixelOffset = nItemSize; nBandOffset = nItemSize * nCols; nLineOffset = ((nBandOffset * nCols + record_bytes - 1)/record_bytes) * record_bytes; } /* -------------------------------------------------------------------- */ /* Create band information objects. */ /* -------------------------------------------------------------------- */ int i; for( i = 0; i < nBands; i++ ) { RawRasterBand *poBand; poBand = new RawRasterBand( this, i+1, fpImage, nSkipBytes + nBandOffset * i, nPixelOffset, nLineOffset, eDataType, #ifdef CPL_LSB chByteOrder == 'I' || chByteOrder == 'L', #else chByteOrder == 'M', #endif TRUE ); if( nBands == 1 ) { const char* pszMin = GetKeyword(osPrefix+"IMAGE.MINIMUM", NULL); const char* pszMax = GetKeyword(osPrefix+"IMAGE.MAXIMUM", NULL); const char* pszMean = GetKeyword(osPrefix+"IMAGE.MEAN", NULL); const char* pszStdDev= GetKeyword(osPrefix+"IMAGE.STANDARD_DEVIATION", NULL); if (pszMin != NULL && pszMax != NULL && pszMean != NULL && pszStdDev != NULL) { poBand->SetStatistics( CPLAtofM(pszMin), CPLAtofM(pszMax), CPLAtofM(pszMean), CPLAtofM(pszStdDev)); } } poBand->SetNoDataValue( dfNoData ); SetBand( i+1, poBand ); // Set offset/scale values at the PAM level. poBand->SetOffset( CPLAtofM(GetKeyword(osPrefix+"IMAGE.OFFSET","0.0"))); poBand->SetScale( CPLAtofM(GetKeyword(osPrefix+"IMAGE.SCALING_FACTOR","1.0"))); } return TRUE; }
void PDSDataset::ParseSRS() { const char *pszFilename = GetDescription(); /* ==================================================================== */ /* Get the geotransform. */ /* ==================================================================== */ /*********** Grab Cellsize ************/ //example: //MAP_SCALE = 14.818 <KM/PIXEL> //added search for unit (only checks for CM, KM - defaults to Meters) const char *value; //Georef parameters double dfULXMap=0.5; double dfULYMap = 0.5; double dfXDim = 1.0; double dfYDim = 1.0; double xulcenter = 0.0; double yulcenter = 0.0; value = GetKeyword("IMAGE_MAP_PROJECTION.MAP_SCALE"); if (strlen(value) > 0 ) { dfXDim = atof(value); dfYDim = atof(value) * -1; CPLString unit = GetKeywordUnit("IMAGE_MAP_PROJECTION.MAP_SCALE",2); //KM //value = GetKeywordUnit("IMAGE_MAP_PROJECTION.MAP_SCALE",3); //PIXEL if((EQUAL(unit,"M")) || (EQUAL(unit,"METER")) || (EQUAL(unit,"METERS"))) { // do nothing } else if (EQUAL(unit,"CM")) { // convert from cm to m dfXDim = dfXDim / 100.0; dfYDim = dfYDim / 100.0; } else { //defaults to convert km to m dfXDim = dfXDim * 1000.0; dfYDim = dfYDim * 1000.0; } } /* -------------------------------------------------------------------- */ /* Calculate upper left corner of pixel in meters from the */ /* upper left center pixel sample/line offsets. It doesn't */ /* mean the defaults will work for every PDS image, as these */ /* values are used inconsistantly. Thus we have included */ /* conversion options to allow the user to override the */ /* documented PDS3 default. Jan. 2011, for known mapping issues */ /* see GDAL PDS page or mapping within ISIS3 source (USGS) */ /* $ISIS3DATA/base/translations/pdsProjectionLineSampToXY.def */ /* -------------------------------------------------------------------- */ // defaults should be correct for what is documented in the PDS3 standard double dfSampleOffset_Shift; double dfLineOffset_Shift; double dfSampleOffset_Mult; double dfLineOffset_Mult; dfSampleOffset_Shift = atof(CPLGetConfigOption( "PDS_SampleProjOffset_Shift", "-0.5" )); dfLineOffset_Shift = atof(CPLGetConfigOption( "PDS_LineProjOffset_Shift", "-0.5" )); dfSampleOffset_Mult = atof(CPLGetConfigOption( "PDS_SampleProjOffset_Mult", "-1.0") ); dfLineOffset_Mult = atof( CPLGetConfigOption( "PDS_LineProjOffset_Mult", "1.0") ); /*********** Grab LINE_PROJECTION_OFFSET ************/ value = GetKeyword("IMAGE_MAP_PROJECTION.LINE_PROJECTION_OFFSET"); if (strlen(value) > 0) { yulcenter = atof(value); dfULYMap = ((yulcenter + dfLineOffset_Shift) * -dfYDim * dfLineOffset_Mult); //notice dfYDim is negative here which is why it is again negated here } /*********** Grab SAMPLE_PROJECTION_OFFSET ************/ value = GetKeyword("IMAGE_MAP_PROJECTION.SAMPLE_PROJECTION_OFFSET"); if( strlen(value) > 0 ) { xulcenter = atof(value); dfULXMap = ((xulcenter + dfSampleOffset_Shift) * dfXDim * dfSampleOffset_Mult); } /* ==================================================================== */ /* Get the coordinate system. */ /* ==================================================================== */ int bProjectionSet = TRUE; double semi_major = 0.0; double semi_minor = 0.0; double iflattening = 0.0; double center_lat = 0.0; double center_lon = 0.0; double first_std_parallel = 0.0; double second_std_parallel = 0.0; OGRSpatialReference oSRS; /*********** Grab TARGET_NAME ************/ /**** This is the planets name i.e. MARS ***/ CPLString target_name = GetKeyword("TARGET_NAME"); CleanString( target_name ); /********** Grab MAP_PROJECTION_TYPE *****/ CPLString map_proj_name = GetKeyword( "IMAGE_MAP_PROJECTION.MAP_PROJECTION_TYPE"); CleanString( map_proj_name ); /****** Grab semi_major & convert to KM ******/ semi_major = atof(GetKeyword( "IMAGE_MAP_PROJECTION.A_AXIS_RADIUS")) * 1000.0; /****** Grab semi-minor & convert to KM ******/ semi_minor = atof(GetKeyword( "IMAGE_MAP_PROJECTION.C_AXIS_RADIUS")) * 1000.0; /*********** Grab CENTER_LAT ************/ center_lat = atof(GetKeyword( "IMAGE_MAP_PROJECTION.CENTER_LATITUDE")); /*********** Grab CENTER_LON ************/ center_lon = atof(GetKeyword( "IMAGE_MAP_PROJECTION.CENTER_LONGITUDE")); /********** Grab 1st std parallel *******/ first_std_parallel = atof(GetKeyword( "IMAGE_MAP_PROJECTION.FIRST_STANDARD_PARALLEL")); /********** Grab 2nd std parallel *******/ second_std_parallel = atof(GetKeyword( "IMAGE_MAP_PROJECTION.SECOND_STANDARD_PARALLEL")); /*** grab PROJECTION_LATITUDE_TYPE = "PLANETOCENTRIC" ****/ // Need to further study how ocentric/ographic will effect the gdal library. // So far we will use this fact to define a sphere or ellipse for some projections // Frank - may need to talk this over char bIsGeographic = TRUE; value = GetKeyword("IMAGE_MAP_PROJECTION.COORDINATE_SYSTEM_NAME"); if (EQUAL( value, "PLANETOCENTRIC" )) bIsGeographic = FALSE; /** Set oSRS projection and parameters --- all PDS supported types added if apparently supported in oSRS "AITOFF", ** Not supported in GDAL?? "ALBERS", "BONNE", "BRIESEMEISTER", ** Not supported in GDAL?? "CYLINDRICAL EQUAL AREA", "EQUIDISTANT", "EQUIRECTANGULAR", "GNOMONIC", "HAMMER", ** Not supported in GDAL?? "HENDU", ** Not supported in GDAL?? "LAMBERT AZIMUTHAL EQUAL AREA", "LAMBERT CONFORMAL", "MERCATOR", "MOLLWEIDE", "OBLIQUE CYLINDRICAL", "ORTHOGRAPHIC", "SIMPLE CYLINDRICAL", "SINUSOIDAL", "STEREOGRAPHIC", "TRANSVERSE MERCATOR", "VAN DER GRINTEN", ** Not supported in GDAL?? "WERNER" ** Not supported in GDAL?? **/ CPLDebug( "PDS","using projection %s\n\n", map_proj_name.c_str()); if ((EQUAL( map_proj_name, "EQUIRECTANGULAR" )) || (EQUAL( map_proj_name, "SIMPLE_CYLINDRICAL" )) || (EQUAL( map_proj_name, "EQUIDISTANT" )) ) { oSRS.SetEquirectangular2 ( 0.0, center_lon, center_lat, 0, 0 ); } else if (EQUAL( map_proj_name, "ORTHOGRAPHIC" )) { oSRS.SetOrthographic ( center_lat, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "SINUSOIDAL" )) { oSRS.SetSinusoidal ( center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "MERCATOR" )) { oSRS.SetMercator ( center_lat, center_lon, 1, 0, 0 ); } else if (EQUAL( map_proj_name, "STEREOGRAPHIC" )) { oSRS.SetStereographic ( center_lat, center_lon, 1, 0, 0 ); } else if (EQUAL( map_proj_name, "POLAR_STEREOGRAPHIC")) { oSRS.SetPS ( center_lat, center_lon, 1, 0, 0 ); } else if (EQUAL( map_proj_name, "TRANSVERSE_MERCATOR" )) { oSRS.SetTM ( center_lat, center_lon, 1, 0, 0 ); } else if (EQUAL( map_proj_name, "LAMBERT_CONFORMAL_CONIC" )) { oSRS.SetLCC ( first_std_parallel, second_std_parallel, center_lat, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "LAMBERT_AZIMUTHAL_EQUAL_AREA" )) { oSRS.SetLAEA( center_lat, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "CYLINDRICAL_EQUAL_AREA" )) { oSRS.SetCEA ( first_std_parallel, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "MOLLWEIDE" )) { oSRS.SetMollweide ( center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "ALBERS" )) { oSRS.SetACEA ( first_std_parallel, second_std_parallel, center_lat, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "BONNE" )) { oSRS.SetBonne ( first_std_parallel, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "GNOMONIC" )) { oSRS.SetGnomonic ( center_lat, center_lon, 0, 0 ); } else if (EQUAL( map_proj_name, "OBLIQUE_CYLINDRICAL" )) { // hope Swiss Oblique Cylindrical is the same oSRS.SetSOC ( center_lat, center_lon, 0, 0 ); } else { CPLDebug( "PDS", "Dataset projection %s is not supported. Continuing...", map_proj_name.c_str() ); bProjectionSet = FALSE; } if (bProjectionSet) { //Create projection name, i.e. MERCATOR MARS and set as ProjCS keyword CPLString proj_target_name = map_proj_name + " " + target_name; oSRS.SetProjCS(proj_target_name); //set ProjCS keyword //The geographic/geocentric name will be the same basic name as the body name //'GCS' = Geographic/Geocentric Coordinate System CPLString geog_name = "GCS_" + target_name; //The datum and sphere names will be the same basic name aas the planet CPLString datum_name = "D_" + target_name; CPLString sphere_name = target_name; // + "_IAU_IAG"); //Might not be IAU defined so don't add //calculate inverse flattening from major and minor axis: 1/f = a/(a-b) if ((semi_major - semi_minor) < 0.0000001) iflattening = 0; else iflattening = semi_major / (semi_major - semi_minor); //Set the body size but take into consideration which proj is being used to help w/ compatibility //Notice that most PDS projections are spherical based on the fact that ISIS/PICS are spherical //Set the body size but take into consideration which proj is being used to help w/ proj4 compatibility //The use of a Sphere, polar radius or ellipse here is based on how ISIS does it internally if ( ( (EQUAL( map_proj_name, "STEREOGRAPHIC" ) && (fabs(center_lat) == 90)) ) || (EQUAL( map_proj_name, "POLAR_STEREOGRAPHIC" ))) { if (bIsGeographic) { //Geograpraphic, so set an ellipse oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_major, iflattening, "Reference_Meridian", 0.0 ); } else { //Geocentric, so force a sphere using the semi-minor axis. I hope... sphere_name += "_polarRadius"; oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_minor, 0.0, "Reference_Meridian", 0.0 ); } } else if ( (EQUAL( map_proj_name, "SIMPLE_CYLINDRICAL" )) || (EQUAL( map_proj_name, "EQUIDISTANT" )) || (EQUAL( map_proj_name, "ORTHOGRAPHIC" )) || (EQUAL( map_proj_name, "STEREOGRAPHIC" )) || (EQUAL( map_proj_name, "SINUSOIDAL" )) ) { //isis uses the spherical equation for these projections so force a sphere oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_major, 0.0, "Reference_Meridian", 0.0 ); } else if (EQUAL( map_proj_name, "EQUIRECTANGULAR" )) { //isis uses local radius as a sphere, which is pre-calculated in the PDS label as the semi-major sphere_name += "_localRadius"; oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_major, 0.0, "Reference_Meridian", 0.0 ); } else { //All other projections: Mercator, Transverse Mercator, Lambert Conformal, etc. //Geographic, so set an ellipse if (bIsGeographic) { oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_major, iflattening, "Reference_Meridian", 0.0 ); } else { //Geocentric, so force a sphere. I hope... oSRS.SetGeogCS( geog_name, datum_name, sphere_name, semi_major, 0.0, "Reference_Meridian", 0.0 ); } } // translate back into a projection string. char *pszResult = NULL; oSRS.exportToWkt( &pszResult ); osProjection = pszResult; CPLFree( pszResult ); } /* ==================================================================== */ /* Check for a .prj and world file to override the georeferencing. */ /* ==================================================================== */ { CPLString osPath, osName; VSILFILE *fp; osPath = CPLGetPath( pszFilename ); osName = CPLGetBasename(pszFilename); const char *pszPrjFile = CPLFormCIFilename( osPath, osName, "prj" ); fp = VSIFOpenL( pszPrjFile, "r" ); if( fp != NULL ) { char **papszLines; OGRSpatialReference oSRS; VSIFCloseL( fp ); papszLines = CSLLoad( pszPrjFile ); if( oSRS.importFromESRI( papszLines ) == OGRERR_NONE ) { char *pszResult = NULL; oSRS.exportToWkt( &pszResult ); osProjection = pszResult; CPLFree( pszResult ); } CSLDestroy( papszLines ); } } if( dfULYMap != 0.5 || dfULYMap != 0.5 || dfXDim != 1.0 || dfYDim != 1.0 ) { bGotTransform = TRUE; adfGeoTransform[0] = dfULXMap; adfGeoTransform[1] = dfXDim; adfGeoTransform[2] = 0.0; adfGeoTransform[3] = dfULYMap; adfGeoTransform[4] = 0.0; adfGeoTransform[5] = dfYDim; } if( !bGotTransform ) bGotTransform = GDALReadWorldFile( pszFilename, "psw", adfGeoTransform ); if( !bGotTransform ) bGotTransform = GDALReadWorldFile( pszFilename, "wld", adfGeoTransform ); }
// int ReadINIFile(char *Fname, RS_232 *COMM232eeee) int ReadINIFile(char *Fname) { FILE *fptr; #define MAXLINE 1000 char Work[MAXLINE]; char *Line; char *Parms = "PORTNUM BAUDRATE NUMEROBIT STOPBIT PARITYBIT"; enum {PORTNUM=1, BAUDRATE, NUMEROBIT, STOPBIT, PARITYBIT} ParmKey; char *KeyName; char *KeyValue; int Rcode = 0; // Set DEFAULT Values if (FileExists(Fname) < 0) { /* if file doesn't exist. Create it (return FileSize */ if (WriteINIFile(Fname) == FALSE) return FALSE; } // ------------------------- // Read the .ini File // ------------------------- if ((fptr = fopen(Fname, "r")) == NULL) { MessageBox(NULL, "Errore nella apertura del File", "Error!", MB_ICONEXCLAMATION | MB_OK); Rcode = FALSE; } /* End if */ while (GetFileLine(Work, MAXLINE, fptr, 'u') != EOF) { Line = CleanString(Work, "=", ' '); /* togli '=' */ KeyName = Word(Line, 1); /* get parameter name */ KeyValue = Word(Line, 2); /* get parameter value */ ParmKey = WordPos(KeyName, Parms); /* get value for switch */ switch (ParmKey) { case PORTNUM: //COMM232->PortNum = atoi(KeyValue); //COMM232->PortName[3] = COMM232->PortNum+'0'; break; case BAUDRATE: //COMM232->BaudRate = atoi(KeyValue); break; case NUMEROBIT: //COMM232->NumeroBits = atoi(KeyValue); break; case STOPBIT: //COMM232->StopBit = atoi(KeyValue); break; case PARITYBIT: //COMM232->ParityBit = atoi(KeyValue); break; default: break; } /* End switch */ } /* End while */ fclose(fptr); /* close file.ini */ return TRUE; }
// Log skin data including materials to file. int SceneIFC::LogSkinInfo( VActor *Thing, TCHAR* SkinName ) // char* ModelName ) { if( !LogPath[0] ) { return 1; // Prevent logs getting lost in root. } TCHAR LogFileName[MAX_PATH]; _stprintf(LogFileName,_T("\\X_ModelInfo_%s%s"),SkinName,_T(".LOG")); DLog.Open(LogPath,LogFileName,DOLOGFILE); if( DLog.Error() ) return 0; DLog.Logf("\n\n Unreal skeletal exporter for " PRODUCT " - Model information for [%s.psk] \n\n",SkinName ); DLog.Logf(" Skin faces: %6i\n",Thing->SkinData.Faces.Num()); DLog.Logf(" Skin vertices: %6i\n",Thing->SkinData.Points.Num()); DLog.Logf(" Skin wedges (vertices with unique U,V): %6i\n",Thing->SkinData.Wedges.Num()); DLog.Logf(" Total bone-to-vertex linkups: %6i\n",Thing->SkinData.RawWeights.Num()); DLog.Logf(" Reference bones: %6i\n",Thing->RefSkeletonBones.Num()); DLog.Logf(" Unique materials: %6i\n",Thing->SkinData.Materials.Num()); DLog.Logf("\n = materials =\n"); // Print out smoothing groups ? if(0) for( INT f=0; f< Thing->SkinData.Faces.Num(); f++) { DLog.Logf(" Smoothing group for face %i is [ %d ] [%X] \n",f,Thing->SkinData.Faces[f].SmoothingGroups,Thing->SkinData.Faces[f].SmoothingGroups ); } DebugBox("Start printing skins"); for( INT i=0; i < Thing->SkinData.Materials.Num(); i++) { DebugBox("Start printing skin [%i]",i); TCHAR MaterialName[256]; #if _UNICODE TCHAR tmp[256]; mbstowcs(tmp, Thing->SkinData.Materials[i].MaterialName, 256); _tcscpy(MaterialName, CleanString(tmp)); #else strcpy(MaterialName, CleanString( Thing->SkinData.Materials[i].MaterialName )); #endif DebugBox("Start printing bitmap"); // Find bitmap: TCHAR BitmapName[MAX_PATH]; TCHAR BitmapPath[MAX_PATH]; if( (Thing->SkinData.RawMaterials.Num()>i) && Thing->SkinData.RawMaterials[i] ) { _tcscpy( BitmapName,Thing->SkinData.RawBMPaths[i].RawBitmapName ); _tcscpy( BitmapPath,Thing->SkinData.RawBMPaths[i].RawBitmapPath ); } else { _stprintf(BitmapName,_T("[Internal material]")); } DebugBox("Retrieved bitmapname"); // Log. DLog.Logf(" * Index: [%2i] name: %s \n",i, MaterialName); if( BitmapName[0] ) DLog.Logf(_T(" Original bitmap: %s Path: %s\n "),BitmapName,BitmapPath); DLog.Logf(" - Skin Index: %2i\n",Thing->SkinData.Materials[i].TextureIndex ); DebugBox("End printing bitmap"); DWORD Flags = Thing->SkinData.Materials[i].PolyFlags; DLog.Logf(" - render mode flags:\n"); if( Flags & MTT_NormalTwoSided ) DLog.Logf(" - Twosided\n"); if( Flags & MTT_Unlit ) DLog.Logf(" - Unlit\n"); if( Flags & MTT_Translucent ) DLog.Logf(" - Translucent\n"); if( (Flags & MTT_Masked) == MTT_Masked ) DLog.Logf(" - Masked\n"); if( Flags & MTT_Modulate ) DLog.Logf(" - Modulated\n"); if( Flags & MTT_Placeholder ) DLog.Logf(" - Invisible\n"); if( Flags & MTT_Alpha ) DLog.Logf(" - Per-pixel alpha.\n"); //if( Flags & MTT_Flat ) DLog.Logf(" - Flat\n"); if( Flags & MTT_Environment ) DLog.Logf(" - Environment mapped\n"); if( Flags & MTT_NoSmooth ) DLog.Logf(" - Nosmooth\n"); } //#DEBUG print out smoothing groups /* for( INT f=0; f < Thing->SkinData.Faces.Num(); f++ ) { DLog.Logf(" Face [%4i] Smoothing group: %4i mat: %4i \n ", f, Thing->SkinData.Faces[f].SmoothingGroups, Thing->SkinData.Faces[f].MatIndex ); } */ // Print out bones list DLog.Logf(" \n\n"); DLog.Logf(" BONE LIST [%i] total bones in reference skeleton. \n",Thing->RefSkeletonBones.Num()); DLog.Logf(" number name (parent) \n"); for( INT b=0; b < Thing->RefSkeletonBones.Num(); b++) { DLog.Logf(" [%3i ] [%s] (%3i ) \n",b, Thing->RefSkeletonBones[b].Name, Thing->RefSkeletonBones[b].ParentIndex ); } DLog.Logf(" \n\n"); DLog.Close(); return 1; }
void FillMenu( HWND hwndMenu ) { char szPidPath[1024]; char szBuffer[1024]; char* pBuf; QSPTRREC* pRecHead; QSPREC* pApp; int numItems, iCounter; PVOID pBuffer; PSWBLOCK pSB; TASKDATA* data; SHORT id = ID_ITEM_FIRST; // Delete all current items numItems = LONGFROMMR( WinSendMsg( hwndMenu, MM_QUERYITEMCOUNT, 0, 0 )); while( numItems-- ) { MENUITEM mi; SHORT id = LONGFROMMR( WinSendMsg( hwndMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(0), 0 )); if( WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT( id, FALSE ), MPFROMP( &mi ))) { if( mi.hItem ) { data = (TASKDATA*)mi.hItem; free( data->szTitle ); free( data ); } } WinSendMsg( hwndMenu, MM_DELETEITEM, MPFROM2SHORT( id, FALSE ), 0 ); } if( bType ) { // Ctrl is pressed, get the processes in the system. pBuf = (char*)malloc( 0x8000 ); // Get processes DosQuerySysState( QS_PROCESS, 0, 0, 0, (char*)pBuf, 0x8000 ); // Point to first process pRecHead = (QSPTRREC*)pBuf; pApp = pRecHead->pProcRec; // While its a process record while( pApp->RecType == 1 ) { // Get module name for process memset( szPidPath, 0, _MAX_PATH ); DosQueryModuleName( pApp->hMte, 512, szPidPath ); if( strlen( szPidPath ) == 0 ) { // If no hit is the kernel if( pApp->type == 1 ) { sprintf( szPidPath, "VDM (%d)", pApp->pid ); } else { strcpy ( szPidPath, "*SYSINIT" ); } } else { // Else trim the path strcpy ( szBuffer, FileGetFileExt( szPidPath )); sprintf( szPidPath, "%s (%d)", szBuffer, pApp->pid ); } // add to menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( szPidPath ); data->hWindow = NULLHANDLE; data->pid = pApp->pid; switch( pApp->type ) { case 0: data->hIcon = ico_os2fs; break; case 1: data->hIcon = ico_dos; break; case 2: data->hIcon = ico_os2vio; break; case 3: data->hIcon = ico_pm; break; case 4: data->hIcon = ico_detach; break; default: data->hIcon = NULLHANDLE; break; } winhInsertMenuItem( hwndMenu, MIT_END, id++, szPidPath, MIS_OWNERDRAW, 0, data ); // get next record pApp=(QSPREC *)((pApp->pThrdRec) + pApp->cTCB); } free(pBuf); } else { // Get number of items in switchlist numItems = WinQuerySwitchList( WinQueryAnchorBlock( hwndMenu ), NULL, 0 ); // Get all items into buffer pBuffer = malloc(( numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); WinQuerySwitchList( WinQueryAnchorBlock(hwndMenu), (SWBLOCK*)pBuffer, (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); pSB = (PSWBLOCK)(pBuffer); for( iCounter = 0; iCounter < numItems; iCounter++ ) { // Should be JUMPABLE and VISIBLE to show in list if( pSB->aswentry[iCounter].swctl.uchVisibility == SWL_VISIBLE ) { // Put in menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( pSB->aswentry[iCounter].swctl.szSwtitle ); data->hWindow = pSB->aswentry[iCounter].swctl.hwnd; data->pid = pSB->aswentry[iCounter].swctl.idProcess; CleanString( data->szTitle ); if( pSB->aswentry[iCounter].swctl.hwndIcon != NULLHANDLE ) { data->hIcon = pSB->aswentry[iCounter].swctl.hwndIcon; } else { data->hIcon = (HPOINTER)WinSendMsg( data->hWindow, WM_QUERYICON, 0, 0 ); } winhInsertMenuItem( hwndMenu, MIT_END, id++, pSB->aswentry[iCounter].swctl.szSwtitle, MIS_OWNERDRAW, 0, data ); } } free(pBuffer); } }
wstring var::strclean(void) { return CleanString(strbuff()); }