int main(int , char** ) { // force console output #else int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { // prevent console output #endif setlocale(LC_ALL, ".OCP"); // we set default locale for console output (useful only for debug) #else int main(int , char** ) { #endif StOutPageFlip::initGlobalsAsync(); if(!StVersionInfo::checkTimeBomb("sView")) { return 1; } // setup environment variables const StString ST_ENV_NAME_STCORE_PATH = #if defined(_WIN64) || defined(_LP64) || defined(__LP64__) "StCore64"; #else "StCore32"; #endif const StString aProcessPath = StProcess::getProcessFolder(); StString aProcessUpPath = StFileNode::getFolderUp(aProcessPath); if(!aProcessUpPath.isEmpty()) { aProcessUpPath += SYS_FS_SPLITTER; } StProcess::setEnv(ST_ENV_NAME_STCORE_PATH, aProcessPath); if(StFolder::isFolder(aProcessPath + "textures")) { StProcess::setEnv("StShare", aProcessPath); } else if(StFolder::isFolder(aProcessUpPath + "textures")) { StProcess::setEnv("StShare", aProcessUpPath); } StString aResDir = StProcess::getStShareFolder(); StProcess::setEnv("CSF_UnitsLexicon", aResDir + "UnitsAPI" ST_FILE_SPLITTER "Lexi_Expr.dat"); StProcess::setEnv("CSF_UnitsDefinition", aResDir + "UnitsAPI" ST_FILE_SPLITTER "Units.dat"); StProcess::setEnv("CSF_ShadersDirectory", aResDir + "shaders" ST_FILE_SPLITTER "StCADViewer"); StProcess::setEnv("CSF_SHMessage", aResDir + "lang"); StProcess::setEnv("CSF_MDTVTexturesDirectory", aResDir + "textures"); StHandle<StOpenInfo> anInfo; if(anInfo.isNull() || (!anInfo->hasPath() && !anInfo->hasArgs())) { anInfo = StApplication::parseProcessArguments(); } if(anInfo.isNull()) { // show help StString aShowHelpString = getAbout(); st::cout << aShowHelpString; stInfo(aShowHelpString); return 0; } StHandle<StResourceManager> aResMgr = new StResourceManager(); StHandle<StCADViewer> anApp = new StCADViewer(aResMgr, NULL, anInfo); if(!anApp->open()) { return 1; } return anApp->exec(); }
void StTranslations::setLanguage(const int32_t theNewLang) { if(size_t(theNewLang) >= params.language->getValues().size()) { return; } // save global setting const StString& aFolderName = myLangFolderList[theNewLang]; StSettings aGlobalSettings(myResMgr, ST_GLOBAL_SETTINGS_GROUP); aGlobalSettings.saveString(ST_SETTING_LANGUAGE, aFolderName); updateLangCode(theNewLang); // reload translation file StLangMap::clear(); const StString aResName = StString() + "lang" ST_FILE_SPLITTER + aFolderName + SYS_FS_SPLITTER + myModuleName + StTranslations::DEFAULT_SUFFIX; StHandle<StResource> aRes = myResMgr->getResource(aResName); if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const int aLen = aRes->getSize(); read(aSrc, aLen); } myWasReloaded = true; }
void StImageFileCounter::createReference(StHandle<StBufferCounter>& theOther) const { StHandle<StImageFileCounter> anImgFileRef = StHandle<StImageFileCounter>::downcast(theOther); if(anImgFileRef.isNull()) { anImgFileRef = new StImageFileCounter(); theOther = anImgFileRef; } anImgFileRef->myImageFile = myImageFile; }
ST_LOCAL StGLMenuActionItem(StGLMenu* theParent, const StHandle<StAction>& theAction, StGLMenu* theSubMenu) : StGLMenuItem(theParent, 0, 0, theSubMenu), myAction(theAction) { ST_ASSERT(!theAction.isNull(), "StGLMenuActionItem - Unexpected empty action makes no sense!"); StGLMenuItem::signals.onItemClick.connect(this, &StGLMenuActionItem::doItemClick); }
void StJpegParser::fillDictionary(StDictionary& theDict, const bool theToShowUnknown) const { for(StHandle<StJpegParser::Image> anImg = myImages; !anImg.isNull(); anImg = anImg->Next) { for(size_t anExifId = 0; anExifId < anImg->Exif.size(); ++anExifId) { anImg->Exif[anExifId]->fillDictionary(theDict, theToShowUnknown); } } }
bool StJpegParser::insertSection(const uint8_t theMarker, const uint16_t theSectLen, const ptrdiff_t theOffset) { const size_t aDiff = size_t(theSectLen) + 2; // 2 bytes for marker const size_t aNewSize = myLength + aDiff; if(aNewSize > myBuffSize) { myBuffSize = aNewSize + 256; stUByte_t* aNewData = stMemAllocAligned<stUByte_t*>(myBuffSize); if(aNewData == NULL) { return false; } stMemCpy(aNewData, myBuffer, myLength); if(myIsOwnData) { stMemFreeAligned(myBuffer); } myIsOwnData = true; // update pointers of image(s) data for(StHandle<StJpegParser::Image> anImg = myImages; !anImg.isNull(); anImg = anImg->Next) { ptrdiff_t anOffset = anImg->Data - myBuffer; if(anOffset >= theOffset) { anOffset += aDiff; } anImg->Data = aNewData + anOffset; if(!anImg->Thumb.isNull()) { anOffset = anImg->Thumb->Data - myBuffer; if(anOffset >= theOffset) { anOffset += aDiff; } anImg->Thumb->Data = aNewData + anOffset; } } myBuffer = aNewData; } myLength = aNewSize; // update offset table for(size_t anIter = 0; anIter < OffsetsNb; ++anIter) { if(myOffsets[anIter] >= theOffset) { myOffsets[anIter] += aDiff; } } // initialize new section const size_t aTailSize = myLength - theOffset; std::memmove(myBuffer + theOffset + 2 + size_t(theSectLen), myBuffer + theOffset, aTailSize); stUByte_t* aData = myBuffer + theOffset; aData[0] = 0xFF; aData[1] = theMarker; StAlienData::Set16uBE(aData + 2, theSectLen); return true; }
void StApplication::addAction(const int theActionId, const StHandle<StAction>& theAction) { myActions[theActionId] = theAction; if(!theAction.isNull()) { StString aNameLower = theAction->getName(); aNameLower.toLowerCase(); const std::string aName(aNameLower.toCString()); myActionLookup[aName] = theActionId; } }
void StApplication::registerHotKeys() { myKeyActions.clear(); for(std::map< int, StHandle<StAction> >::iterator anIter = myActions.begin(); anIter != myActions.end(); ++anIter) { const StHandle<StAction>& anAction = anIter->second; if(anAction->getHotKey1() != 0) { StHandle<StAction> anOldAction = getActionForKey(anAction->getHotKey1()); if(!anOldAction.isNull()) { anOldAction->setHotKey1(0); } myKeyActions[anAction->getHotKey1()] = anAction; } if(anAction->getHotKey2() != 0) { StHandle<StAction> anOldAction = getActionForKey(anAction->getHotKey2()); if(!anOldAction.isNull()) { anOldAction->setHotKey2(0); } myKeyActions[anAction->getHotKey2()] = anAction; } } }
void StApplication::addRenderer(const StHandle<StWindow>& theRenderer) { if(theRenderer.isNull()) { return; } StHandle<StWindow> aRenderer = theRenderer; aRenderer->params.VSyncMode = params.VSyncMode; // share VSync mode between renderers aRenderer->setMessagesQueue(myMsgQueue); myRenderers.add(aRenderer); size_t aDevIter = myDevices.size(); aRenderer->getDevices(myDevices); for(; aDevIter < myDevices.size(); ++aDevIter) { params.ActiveDevice->changeValues().add(myDevices[aDevIter]->Name); } }
bool StJpegParser::parse() { if(myBuffer == NULL) { return false; } int aCount = 0; myImages = parseImage(++aCount, 1, myBuffer, false); if(myImages.isNull()) { return false; } // continue reading the file (MPO may contains more than 1 image) for(StHandle<StJpegParser::Image> anImg = myImages; !anImg.isNull(); anImg = anImg->Next) { anImg->Next = parseImage(++aCount, 1, anImg->Data + anImg->Length, true); } return true; }
void StPlayList::loadRecentList(const StString theString) { StMutexAuto anAutoLock(myMutex); StArgumentsMap aMap; aMap.parseString(theString); myRecent.clear(); for(size_t anIter = 0; anIter < myRecentLimit; ++anIter) { const StArgument anArgFile = aMap[StString("file") + anIter]; const StArgument anArgLeft = aMap[StString("left") + anIter]; const StArgument anArgRight = aMap[StString("right") + anIter]; const StArgument anArgTime = aMap[StString("time") + anIter]; StHandle<StRecentItem> aRecent; if(anArgLeft.isValid() && anArgRight.isValid()) { StHandle<StFileNode> aFileNode = new StFileNode(StString()); aFileNode->add(new StFileNode(anArgLeft.getValue(), aFileNode.access())); aFileNode->add(new StFileNode(anArgRight.getValue(), aFileNode.access())); aRecent = addRecentFile(*aFileNode, false); } else if(anArgFile.isValid()) { StHandle<StFileNode> aFileNode = new StFileNode(anArgFile.getValue()); const StArgument anArgPos = aMap[StString("pos") + anIter]; if(anArgPos.isValid()) { aFileNode->add(new StFileNode(anArgPos.getValue(), aFileNode.access())); } aRecent = addRecentFile(*aFileNode, false); } if(aRecent.isNull()) { continue; } if(anArgTime.isValid()) { if(aRecent->Params.isNull()) { aRecent->Params = new StStereoParams(); } std::stringstream aStream; aStream.imbue(std::locale("C")); aStream << anArgTime.getValue().toCString(); aStream >> aRecent->Params->Timestamp; } } }
void StPlayList::updateRecent(const StHandle<StFileNode>& theFile, const StHandle<StStereoParams>& theParams) { if(theFile.isNull()) { return; } StMutexAuto anAutoLock(myMutex); if(!myPlsFile.isNull() && myPlsFile->File == theFile) { // remember properties of last played file myPlsFile->Params = theParams; return; } for(size_t anIter = 0; anIter < myRecent.size(); ++anIter) { StHandle<StRecentItem>& aRecent = myRecent[anIter]; if(stAreSameRecent(*theFile, *aRecent->File)) { aRecent->Params = theParams; return; } } }
void StCADViewerGUI::doOpenFile(const size_t ) { StGLOpenFile* aDialog = new StGLOpenFile(this, tr(DIALOG_OPEN_FILE), tr(BUTTON_CLOSE)); aDialog->setMimeList(StCADLoader::ST_CAD_MIME_LIST); #if defined(_WIN32) // #else aDialog->addHotItem("/", "Root"); #endif aDialog->addHotItem(getResourceManager()->getFolder(StResourceManager::FolderId_SdCard)); aDialog->addHotItem(getResourceManager()->getFolder(StResourceManager::FolderId_Downloads)); aDialog->addHotItem(getResourceManager()->getFolder(StResourceManager::FolderId_Pictures)); aDialog->addHotItem(getResourceManager()->getFolder(StResourceManager::FolderId_Photos)); aDialog->signals.onFileSelected = stSlot(myPlugin, &StCADViewer::doOpen1FileFromGui); if(myPlugin->params.LastFolder.isEmpty()) { StHandle<StFileNode> aCurrFile = myPlugin->myPlayList->getCurrentFile(); if(!aCurrFile.isNull()) { myPlugin->params.LastFolder = aCurrFile->isEmpty() ? aCurrFile->getFolderPath() : aCurrFile->getValue(0)->getFolderPath(); } } aDialog->openFolder(myPlugin->params.LastFolder); setModalDialog(aDialog); }
/** * Copy OCCT resource file. */ ST_LOCAL bool copyResource(const StHandle<StResourceManager>& theResMgr, const StString& theResFolder, const StString& theDestFolder, const StString& theFileName) { StString aFileResPath = theResFolder + SYS_FS_SPLITTER + theFileName; StHandle<StResource> aRes = theResMgr->getResource(aFileResPath); if( aRes.isNull() || !aRes->read()) { ST_ERROR_LOG(StString("Can not read resource file ") + aFileResPath); return false; } StRawFile aFileOut; StString aFileOutPath = theDestFolder + SYS_FS_SPLITTER + theFileName; if(!aFileOut.openFile(StRawFile::WRITE, aFileOutPath)) { ST_ERROR_LOG(StString("Can not create resource file ") + aFileOutPath); return false; } if(!aFileOut.write((const char* )aRes->getData(), aRes->getSize()) != aRes->getSize()) { ST_ERROR_LOG(StString("Can not write resource file ") + aFileOutPath); return false; } return true; }
void StTranslations::reload() { params.language->changeValues().clear(); // detect available translations StArrayList<StString> aFolders; myResMgr->listSubFolders("lang", aFolders); for(size_t aNodeId = 0; aNodeId < aFolders.size(); ++aNodeId) { myLangFolderList.add(aFolders[aNodeId]); const StString aNameFile = StString("lang" ST_FILE_SPLITTER) + aFolders[aNodeId] + ST_FILE_SPLITTER "language.lng"; StHandle<StResource> aRes = myResMgr->getResource(aNameFile); StString aName; if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const size_t aLen = (size_t )aRes->getSize(); aName = StString(aSrc, aLen); } params.language->changeValues().add(aName.isEmpty() ? aFolders[aNodeId] : aName); } #if defined(__ANDROID__) if(params.language->getValues().isEmpty()) { // no way to list sub-folder on Android - check known translations if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "English" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("English"); myLangFolderList.add("English"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Russian" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("русский"); myLangFolderList.add("Russian"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "French" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("français"); myLangFolderList.add("French"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "German" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("Deutsch"); myLangFolderList.add("German"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Korean" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("한국어"); myLangFolderList.add("Korean"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "ChineseS" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("简体中文"); myLangFolderList.add("ChineseS"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Czech" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("Čeština"); myLangFolderList.add("Czech"); } } #endif if(params.language->getValues().isEmpty()) { // add built-in language params.language->changeValues().add("English"); myLangFolderList.add("English"); } size_t anIdInList = 0; StString aLangParam("English"); StSettings aGlobalSettings(myResMgr, ST_GLOBAL_SETTINGS_GROUP); bool isLangSet = false; if(!aGlobalSettings.loadString(ST_SETTING_LANGUAGE, aLangParam)) { // try to use system-wide language settings const StString& aLang = myResMgr->getSystemLanguage(); if(aLang.isEqualsIgnoreCase(stCString("ru"))) { if(myLangFolderList.contains(stCString("Russian"), anIdInList) || myLangFolderList.contains(stCString("русский"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("de"))) { if(myLangFolderList.contains(stCString("German"), anIdInList) || myLangFolderList.contains(stCString("Deutsch"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("fr"))) { if(myLangFolderList.contains(stCString("French"), anIdInList) || myLangFolderList.contains(stCString("français"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("ko"))) { if(myLangFolderList.contains(stCString("Korean"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("zh"))) { if(myLangFolderList.contains(stCString("ChineseS"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("cs"))) { if(myLangFolderList.contains(stCString("Čeština"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } } if(!isLangSet) { if(myLangFolderList.contains(aLangParam, anIdInList) || myLangFolderList.contains(stCString("English"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); } } updateLangCode(int32_t(anIdInList)); const StString& aFolderName = myLangFolderList[anIdInList]; const StString aResName = StString() + "lang" + SYS_FS_SPLITTER + aFolderName + SYS_FS_SPLITTER + myModuleName + StTranslations::DEFAULT_SUFFIX; StHandle<StResource> aRes = myResMgr->getResource(aResName); if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const int aLen = aRes->getSize(); read(aSrc, aLen); } // connect signal params.language->signals.onChanged.connect(this, &StTranslations::setLanguage); }
bool StOutIZ3D::create() { StWindow::show(); if(!StWindow::create()) { return false; } // initialize GL context myContext = StWindow::getContext(); myContext->setMessagesQueue(myMsgQueue); const StHandle<StResourceManager>& aResMgr = getResourceManager(); if(!myContext->isGlGreaterEqual(2, 0)) { myMsgQueue->pushError(stCString("OpenGL 2.0 is required by iZ3D Output")); myIsBroken = true; return true; } StWindow::stglMakeCurrent(ST_WIN_MASTER); myContext->stglSetVSync((StGLContext::VSync_Mode )StWindow::params.VSyncMode->getValue()); StWindow::params.VSyncMode->signals.onChanged += stSlot(this, &StOutIZ3D::doSwitchVSync); // INIT iZ3D tables textures StAVImage aTableImg; StHandle<StResource> aTableOld = aResMgr->getResource(StString("textures") + SYS_FS_SPLITTER + "iz3dTableOld.png"); uint8_t* aData = NULL; int aDataSize = 0; if(!aTableOld.isNull() && !aTableOld->isFile() && aTableOld->read()) { aData = (uint8_t* )aTableOld->getData(); aDataSize = aTableOld->getSize(); } if(!aTableImg.load(!aTableOld.isNull() ? aTableOld->getPath() : StString(), StImageFile::ST_TYPE_PNG, aData, aDataSize)) { myMsgQueue->pushError(StString("iZ3D output - critical error:\n") + aTableImg.getState()); myIsBroken = true; return true; } myTexTableOld.setMinMagFilter(*myContext, GL_NEAREST); // we need not linear filtrating for lookup-table! if(!myTexTableOld.init(*myContext, aTableImg.getPlane())) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nLookup-table initalization failed!")); myIsBroken = true; return true; } StHandle<StResource> aTableNew = aResMgr->getResource(StString("textures") + SYS_FS_SPLITTER + "iz3dTableNew.png"); aData = NULL; aDataSize = 0; if(!aTableNew.isNull() && !aTableNew->isFile() && aTableNew->read()) { aData = (uint8_t* )aTableNew->getData(); aDataSize = aTableNew->getSize(); } if(!aTableImg.load(!aTableNew.isNull() ? aTableNew->getPath() : StString(), StImageFile::ST_TYPE_PNG, aData, aDataSize)) { myMsgQueue->pushError(StString("iZ3D output - critical error:\n") + aTableImg.getState()); myIsBroken = true; return true; } myTexTableNew.setMinMagFilter(*myContext, GL_NEAREST); // we need not linear filtrating for lookup-table! if(!myTexTableNew.init(*myContext, aTableImg.getPlane())) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nLookup-table initalization failed!")); myIsBroken = true; return true; } // INIT shaders if(!myShaders.init(*myContext)) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nShaders initialization failed!")); myIsBroken = true; return true; } myIsBroken = false; return true; }