QString UBExportAdaptor::askForFileName(UBDocumentProxy* pDocument, const QString& pDialogTitle) { QString defaultName; if (pDocument->metaData(UBSettings::documentGroupName).toString().length() > 0) { defaultName += pDocument->metaData(UBSettings::documentGroupName).toString() + QString(" "); } defaultName += pDocument->metaData(UBSettings::documentName).toString() + exportExtention(); defaultName = UBFileSystemUtils::cleanName(defaultName); QString defaultPath = UBSettings::settings()->lastExportFilePath->get().toString() + "/" + defaultName; QString filename = QFileDialog::getSaveFileName(UBApplication::mainWindow, pDialogTitle, defaultPath); if (filename.size() == 0) { return filename; } // add extension if needed QFileInfo fileNameInfo(filename); if (fileNameInfo.suffix() != exportExtention().mid(1, exportExtention().length() - 1)) { filename += exportExtention(); } UBSettings::settings()->lastExportFilePath->set(QVariant(fileNameInfo.absolutePath())); QApplication::processEvents(); return filename; }
void CSourceDataGenerator::SaveCharmap(const CharMap &charmap, bool compress, enum OutputFormat format, const wxString &fileName) { wxFileName fileNameInfo(fileName, wxPATH_NATIVE); wxString hFilePath, cFilePath; if (fileNameInfo.GetExt() == "h") { hFilePath = fileName; fileNameInfo.SetExt("c"); if (fileNameInfo.Exists() && wxMessageBox(_("Also the file \"") + fileNameInfo.GetFullName() + _("\" will be generated. Do you want to overwrite it?"), _("Confirm"), wxYES_NO) == wxNO) { return; } cFilePath = fileNameInfo.GetFullPath(); } else if (fileNameInfo.GetExt() == "c") { cFilePath = fileName; fileNameInfo.SetExt("h"); if (fileNameInfo.Exists() && wxMessageBox(_("The file \"") + fileNameInfo.GetFullName() + _("\" will be generated. Do you want to overwrite it?"), _("Confirm"), wxYES_NO) == wxNO) { return; } hFilePath = fileNameInfo.GetFullPath(); } wxFFileOutputStream hFile(hFilePath); wxFFileOutputStream cFile(cFilePath); wxTextOutputStream hOut(hFile); wxTextOutputStream cOut(cFile); EMGL_font_t *font = LoadEMGLFont(charmap, compress, format); hOut << GetHeaderFile(fileNameInfo.GetName()); cOut << GetSourceFile(font, fileNameInfo.GetName()); DeleteEMGLFont(font); }
Texture *newTexture(const char *name, uintf value, uintf flags) // value = depth for volume textures, and dimensions for cubemap textures { // This is the base 'newtexture' function which all others call Texture *tex; char flname[1024]; if (name) { if ((flags & texture_currentImporter) && (name[0])) { // Try to find a texture with a matching name and return a pointer to that fileNameInfo(name); tprintf(flname,sizeof(flname),"%s.%s",fileactualname,fileextension); Texture *tex = usedTexture; while (tex) { if (txticmp(flname,tex->name)==0) { // Texture already loaded tex->refcount++; return tex; } tex = tex->next; } } } allocbucket(Texture,tex,flags,Generic_MemoryFlag32,texturealloc,"Texture Cache"); tex->flags |= flags; if (!name) tprintf(tex->name,sizeof(tex->name),"Unnamed (0x%04x)",(long)tex); // ### Typecast pointer to int else txtcpy(tex->name, sizeof(tex->name), name); // if (!(tex->flags & texture_dontlog)) texturelog->log("Created 0: %s",tex->name); tex->refcount = 1; tex->oemdata=NULL; tex->texmemused = 0; tex->flags |= flags | texture_inuse; tex->UVscale.x = 1.0f; tex->UVscale.y = 1.0f; tex->mapping = texmapping_default; switch (flags & texture_typemask) { case texture_2D: tex->depth = 0; break; case texture_cubemap: tex->width = value; tex->height = value; tex->depth = value; break; case texture_volumemap: tex->depth = value; break; } tex->levels = 0; return tex; }
Texture *newTextureFromFile(const char *texname,uintf flags) { // Search the current texture directory to locate a suitable texture file bitmap *bm; char flname[1024]; if (!texname) return NULL; if (!texname[0]) return NULL; // Look for an already loaded texture with the same name fileNameInfo(texname); tprintf(flname,sizeof(flname),"%s.%s",fileactualname,fileextension); Texture *tex = usedTexture; while (tex) { if (txticmp(flname,tex->name)==0) { // Texture already loaded tex->refcount++; return tex; } tex = tex->next; } // Allocate a new texture cell tex = newTexture(flname, 0, 0); // ### This forces the texture to be 2D!!! tex->flags &= texture_clearmask; tex->flags |= flags; if (fileExists(texname)) // Check to see if the path + filename is valid ... txtcpy(flname, sizeof(flname), texname); // if so, load that else fileFindInPath(flname, sizeof(flname), tex->name, texpath); // Find the texture with our texture path if (!flname[0]) // nothing found ... fail { texturelog->log("*** %s *** Missing texture. Looked in %s",tex->name,texpath); if (!bm_MissingTexture) { bm_MissingTexture = newbitmap("Missing Texture Standin",1,1,bitmap_ARGB32); *(uint32 *)(bm_MissingTexture->pixel) = 0xFFFF00FF; // Purple } textureFromBitmap(bm_MissingTexture, tex); estimatedtexmemused += 4; } else { bm = newbitmap(flname,0); textureFromBitmap(bm, tex); deleteBitmap(bm); } if (tex->oemdata) texturelog->log("Create %i: %s",tex->texmemused/1024,flname); return tex; }
QString UBExportAdaptor::askForFileName(UBDocumentProxy* pDocument, const QString& pDialogTitle) { QString defaultName; defaultName += pDocument->metaData(UBSettings::documentName).toString() + exportExtention(); defaultName = UBFileSystemUtils::cleanName(defaultName); QString defaultPath = UBSettings::settings()->lastExportFilePath->get().toString() + "/" + defaultName; bool useNativeDialog = true; #ifdef Q_OS_MAC int versionMac = qMacVersion(); if (versionMac == QSysInfo::MV_Unknown || versionMac >= 11){ // version 11 is MacOSX 10.9 Mavericks useNativeDialog = false; } #endif QString filename = QFileDialog::getSaveFileName(UBApplication::mainWindow, pDialogTitle, defaultPath, QString(), 0, useNativeDialog?(QFileDialog::Option)0:QFileDialog::DontUseNativeDialog); if (filename.size() == 0) { return filename; } // add extension if needed QFileInfo fileNameInfo(filename); if (fileNameInfo.suffix() != exportExtention().mid(1, exportExtention().length() - 1)) { filename += exportExtention(); } UBSettings::settings()->lastExportFilePath->set(QVariant(fileNameInfo.absolutePath())); QApplication::processEvents(); return filename; }
//-------------------------------------------------------------------------------------------------- /// Loads input property data from the gridFile and additional files /// Creates new InputProperties if necessary, and flags the unused ones as obsolete //-------------------------------------------------------------------------------------------------- void RimEclipseInputCase::loadAndSyncronizeInputProperties() { // Make sure we actually have reservoir data CVF_ASSERT(this->reservoirData()); CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0,0,0)); // Then read the properties from all the files referenced by the InputReservoir std::vector<QString> filenames = m_additionalFileNames; filenames.push_back(m_gridFileName); size_t inputPropCount = this->m_inputPropertyCollection()->inputProperties.size(); caf::ProgressInfo progInfo(static_cast<int>(filenames.size() * inputPropCount), "Reading Input properties" ); int progress = 0; for_all(filenames, i) { progress = static_cast<int>(i*inputPropCount); // Find all the keywords present on the file progInfo.setProgressDescription(filenames[i]); QFileInfo fileNameInfo(filenames[i]); bool isExistingFile = fileNameInfo.exists(); std::set<QString> fileKeywordSet; if (isExistingFile) { std::vector< RifKeywordAndFilePos > fileKeywords; RifEclipseInputFileTools::findKeywordsOnFile(filenames[i], &fileKeywords); for_all(fileKeywords, fkIt) fileKeywordSet.insert(fileKeywords[fkIt].keyword); } // Find the input property objects referring to the file std::vector<RimEclipseInputProperty*> ipsUsingThisFile = this->m_inputPropertyCollection()->findInputProperties(filenames[i]); // Read property data for each inputProperty for_all(ipsUsingThisFile, ipIdx) { if (!isExistingFile) { ipsUsingThisFile[ipIdx]->resolvedState = RimEclipseInputProperty::FILE_MISSING; } else { QString kw = ipsUsingThisFile[ipIdx]->eclipseKeyword(); ipsUsingThisFile[ipIdx]->resolvedState = RimEclipseInputProperty::KEYWORD_NOT_IN_FILE; if (fileKeywordSet.count(kw)) { if (RifEclipseInputFileTools::readProperty(filenames[i], this->reservoirData(), kw, ipsUsingThisFile[ipIdx]->resultName )) { ipsUsingThisFile[ipIdx]->resolvedState = RimEclipseInputProperty::RESOLVED; } } fileKeywordSet.erase(kw); } progInfo.setProgress(static_cast<int>(progress + ipIdx) ); } progInfo.setProgress(static_cast<int>(progress + inputPropCount)); // Check if there are more known property keywords left on file. If it is, read them and create inputProperty objects for (const QString fileKeyword : fileKeywordSet) { { QString resultName = this->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeyword); if (RifEclipseInputFileTools::readProperty(filenames[i], this->reservoirData(), fileKeyword, resultName)) { RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty; inputProperty->resultName = resultName; inputProperty->eclipseKeyword = fileKeyword; inputProperty->fileName = filenames[i]; inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED; m_inputPropertyCollection->inputProperties.push_back(inputProperty); } } progInfo.setProgress(static_cast<int>(progress + inputPropCount)); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimEclipseInputCaseOpm::loadAndSyncronizeInputProperties() { // Make sure we actually have reservoir data CVF_ASSERT(this->reservoirData()); CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0, 0, 0)); // Then read the properties from all the files referenced by the InputReservoir for (QString filename : m_additionalFileNames()) { QFileInfo fileNameInfo(filename); bool isExistingFile = fileNameInfo.exists(); // Find the input property objects referring to the file std::vector<RimEclipseInputProperty*> ipsUsingThisFile = this->m_inputPropertyCollection()->findInputProperties(filename); if (!isExistingFile) { for (auto inputProperty : ipsUsingThisFile) { inputProperty->resolvedState = RimEclipseInputProperty::FILE_MISSING; } } else { RifReaderOpmParserPropertyReader propertyReader(filename); std::set<std::string> fileKeywordSet = propertyReader.keywords(); for (auto inputProperty : ipsUsingThisFile) { QString kw = inputProperty->eclipseKeyword(); inputProperty->resolvedState = RimEclipseInputProperty::KEYWORD_NOT_IN_FILE; if (fileKeywordSet.count(kw.toStdString())) { if (propertyReader.copyPropertyToCaseData(kw.toStdString(), this->reservoirData(), inputProperty->resultName)) { inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED; } } fileKeywordSet.erase(kw.toStdString()); } if (!fileKeywordSet.empty()) { std::vector<std::string> knownKeywords = RifReaderOpmParserInput::knownPropertyKeywords(); for (auto knownKeyword : knownKeywords) { if (fileKeywordSet.count(knownKeyword) > 0) { QString qtKnownKeyword = QString::fromStdString(knownKeyword); QString resultName = this->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(qtKnownKeyword); if (propertyReader.copyPropertyToCaseData(knownKeyword, this->reservoirData(), resultName)) { RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty; inputProperty->resultName = resultName; inputProperty->eclipseKeyword = qtKnownKeyword; inputProperty->fileName = filename; inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED; m_inputPropertyCollection->inputProperties.push_back(inputProperty); } } } } } } for(auto inputProperty : m_inputPropertyCollection->inputProperties()) { if (inputProperty->resolvedState() == RimEclipseInputProperty::UNKNOWN) { inputProperty->resolvedState = RimEclipseInputProperty::FILE_MISSING; } } }