void RestartableDataIO::readRestartableData(RestartableDatas & restartable_datas, std::set<std::string> & _recoverable_data) { bool recovering = _fe_problem.getMooseApp().isRecovering(); unsigned int n_threads = libMesh::n_threads(); std::vector<std::string> ignored_data; for (unsigned int tid=0; tid<n_threads; tid++) { std::map<std::string, RestartableDataValue *> & restartable_data = restartable_datas[tid]; if (!_in_file_handles[tid]->is_open()) mooseError("In RestartableDataIO: Need to call readRestartableDataHeader() before calling readRestartableData()"); // number of data unsigned int n_data = 0; _in_file_handles[tid]->read((char *) &n_data, sizeof(n_data)); // data names std::vector<std::string> data_names(n_data); for (unsigned int i=0; i < n_data; i++) { std::string data_name; char ch = 0; do { _in_file_handles[tid]->read(&ch, 1); if (ch != '\0') data_name += ch; } while (ch != '\0'); data_names[i] = data_name; } // Grab this processor's block size unsigned int data_blk_size = 0; _in_file_handles[tid]->read((char *) &data_blk_size, sizeof(data_blk_size)); for (unsigned int i=0; i < n_data; i++) { std::string current_name = data_names[i]; unsigned int data_size = 0; _in_file_handles[tid]->read((char *) &data_size, sizeof(data_size)); if (restartable_data.find(current_name) != restartable_data.end() // Only restore values if they're currently being used && (recovering || (_recoverable_data.find(current_name) == _recoverable_data.end())) // Only read this value if we're either recovering or this hasn't been specified to be recovery only data ) { // Moose::out<<"Loading "<<current_name<<std::endl; RestartableDataValue * current_data = restartable_data[current_name]; current_data->load(*_in_file_handles[tid]); } else { // Skip this piece of data _in_file_handles[tid]->seekg(data_size, std::ios_base::cur); ignored_data.push_back(current_name); } } _in_file_handles[tid]->close(); } if (ignored_data.size()) { std::ostringstream names; for (unsigned int i=0; i<ignored_data.size(); i++) names << ignored_data[i] << "\n"; mooseWarning("The following RestorableData was found in restart file but is being ignored:\n" << names.str()); } }
void RestartableDataIO::deserializeRestartableData(const std::map<std::string, RestartableDataValue *> & restartable_data, std::istream & stream, const std::set<std::string> & recoverable_data) { bool recovering = _fe_problem.getMooseApp().isRecovering(); std::vector<std::string> ignored_data; // number of data unsigned int n_data = 0; stream.read((char *) &n_data, sizeof(n_data)); // data names std::vector<std::string> data_names(n_data); for (unsigned int i=0; i < n_data; i++) { std::string data_name; char ch = 0; do { stream.read(&ch, 1); if (ch != '\0') data_name += ch; } while (ch != '\0'); data_names[i] = data_name; } // Grab this processor's block size unsigned int data_blk_size = 0; stream.read((char *) &data_blk_size, sizeof(data_blk_size)); for (unsigned int i=0; i < n_data; i++) { std::string current_name = data_names[i]; unsigned int data_size = 0; stream.read((char *) &data_size, sizeof(data_size)); // Determine if the current data is recoverable bool is_data_restartable = restartable_data.find(current_name) != restartable_data.end(); bool is_data_recoverable = recoverable_data.find(current_name) != recoverable_data.end(); if (is_data_restartable // Only restore values if they're currently being used && (recovering || !is_data_recoverable)) // Only read this value if we're either recovering or this hasn't been specified to be recovery only data { // Moose::out<<"Loading "<<current_name<<std::endl; try { RestartableDataValue * current_data = restartable_data.at(current_name); current_data->load(stream); } catch(...) { mooseError("restartable_data missing " << current_name << std::endl); } } else { // Skip this piece of data and do not report if restarting and recoverable data is not used stream.seekg(data_size, std::ios_base::cur); if (recovering && !is_data_recoverable) ignored_data.push_back(current_name); } } // Produce a warning if restarting and restart data is being skipped // Do not produce the warning with recovery b/c in cases the parent defines a something as recoverable, // but only certain child classes use the value in recovery (i.e., FileOutput::_num_files is needed by Exodus but not Checkpoint) if (ignored_data.size() && !recovering) { std::ostringstream names; for (unsigned int i=0; i<ignored_data.size(); i++) names << ignored_data[i] << "\n"; mooseWarning("The following RestartableData was found in restart file but is being ignored:\n" << names.str()); } }
void wxGISCatalogMainCmd::OnClick(void) { wxCHECK_RET(m_pGxApp && m_pApp, wxT("Application pointer is null")); wxGxSelection* pSel = m_pGxApp->GetGxSelection(); wxGxCatalogBase* pCat = GetGxCatalog(); switch(m_subtype) { case 0: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); if(!pGxObject) return; wxGxObject* pParentGxObject = pGxObject->GetParent(); if(pParentGxObject) { pSel->Select(pParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } /* if(wxIsKindOf(pParentGxObject, wxGxObjectContainer)) { pSel->Select(pParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } else { wxGxObject* pGrandParentGxObject = pParentGxObject->GetParent(); pSel->Select(pGrandParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } */ } break; case 1:// 1 Connect Folder { wxDirDialog dlg(dynamic_cast<wxWindow*>(m_pApp), wxString(_("Choose a folder to connect"))); if(pSel && pCat && dlg.ShowModal() == wxID_OK) { wxGxCatalog* pGxCatalog = wxDynamicCast(pCat, wxGxCatalog); if(pGxCatalog) { wxGxDiscConnections* pGxDiscConnections = wxDynamicCast(pGxCatalog->GetRootItemByType(wxCLASSINFO(wxGxDiscConnections)), wxGxDiscConnections); if(pGxDiscConnections && pGxDiscConnections->ConnectFolder(dlg.GetPath())) return; else wxMessageBox(_("Cannot connect folder"), _("Error"), wxOK | wxICON_ERROR); } } return; } case 2:// 2 Disconnect Folder - duplicate Delete command { if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); wxGxDiscConnection* pGxDiscConnection = wxDynamicCast(pGxObject, wxGxDiscConnection); if(pGxDiscConnection && pGxDiscConnection->Delete()) return; else wxMessageBox(_("Cannot disconnect folder"), _("Error"), wxOK | wxICON_ERROR); } return; } case 8: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); wxGxView* pGxView = dynamic_cast<wxGxView*>(wxWindow::FindFocus()); if(pGxView && pGxObject) pGxView->BeginRename(pGxObject->GetId()); } break; case 4: if(pSel && pCat) { bool bAskToDelete(true); wxGISAppConfig oConfig = GetConfig(); bAskToDelete = oConfig.ReadBool(enumGISHKCU, m_pApp->GetAppName() + wxString(wxT("/catalog/ask_delete")), bAskToDelete); if(bAskToDelete) { //show ask dialog wxWindow* pWnd = dynamic_cast<wxWindow*>(m_pApp); wxRichMessageDialog dlg(pWnd, wxString::Format(_("Do you really want to delete %d item(s)"), pSel->GetCount()), wxString(_("Delete confirm")), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTRE); dlg.SetExtendedMessage(wxString(_("The result of operation cannot be undone!\nThe deleted items will remove from disk and will not put to the recycled bin."))); dlg.ShowCheckBox("Use my choice and do not show this dialog in future"); int nRes = dlg.ShowModal(); if(oConfig.IsOk()) oConfig.Write(enumGISHKCU, m_pApp->GetAppName() + wxString(wxT("/catalog/ask_delete")), !dlg.IsCheckBoxChecked()); if(nRes == wxID_NO) return; } for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanDelete()) { if(!pGxObjectEdit->Delete()) { wxWindow* pWnd = dynamic_cast<wxWindow*>(m_pApp); if(i == pSel->GetCount() - 1) { wxMessageBox(wxString::Format(_("Delete '%s'failed"), pGxObject->GetName().c_str()), _("Error"), wxOK | wxICON_ERROR, pWnd); return; } int nRes = wxMessageBox(wxString::Format(_("Cannot delete '%s'\nContinue?"), pGxObject->GetName().c_str()), _("Error"), wxYES_NO | wxICON_QUESTION, pWnd); if(nRes == wxNO) return; } } } } return; case 5: if(pSel && pCat) { long nSelId = wxNOT_FOUND; if(pSel->CanUndo()) { nSelId = pSel->Undo(wxNOT_FOUND); } if(pCat->GetRegisterObject(nSelId)) { pSel->Select(nSelId, false, wxGxSelection::INIT_ALL); } } return; case 6: if(pSel && pCat) { long nSelId = wxNOT_FOUND; if(pSel->CanRedo()) { nSelId = pSel->Redo(wxNOT_FOUND); } if(pCat->GetRegisterObject(nSelId)) { pSel->Select(nSelId, false, wxGxSelection::INIT_ALL); } } return; case 9: if(pSel && pCat) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) pGxObject->Refresh(); } } return; case 10: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); IGxObjectEditUI* pGxObjectEdit = dynamic_cast<IGxObjectEditUI*>(pGxObject); if(pGxObjectEdit) pGxObjectEdit->EditProperties(dynamic_cast<wxWindow*>(m_pApp)); } return; case 11://copy if(pSel && pCat) { wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) { wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); } } //! Lock clipboard wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { //! Put data to clipboard if(!wxTheClipboard->AddData(pDragData)) wxMessageBox(_("Can't copy file(s) to the clipboard"), _("Error"), wxOK | wxICON_ERROR); } } return; case 12://cut if(pSel && pCat) { wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); pDragData->Add(new wxTextDataObject(wxT("cut"))); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) { wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); } } //! Lock clipboard wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { //! Put data to clipboard if(!wxTheClipboard->AddData(pDragData)) wxMessageBox(_("Can't copy file(s) to the clipboard"), _("Error"), wxOK | wxICON_ERROR); } } return; case 13://paste if(pSel && pCat) { IGxDropTarget* pTarget = dynamic_cast<IGxDropTarget*>(pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId())); if(!pTarget) return; wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { wxTextDataObject data; bool bMove(false); if(wxTheClipboard->GetData( data )) { if(data.GetText() == wxString(wxT("cut"))) bMove = true; } wxGISStringDataObject data_names(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); if(wxTheClipboard->GetData( data_names )) { pTarget->Drop(data_names.GetStrings(), bMove); return; } wxFileDataObject filedata; if( wxTheClipboard->GetData( filedata ) ) { pTarget->Drop(wxGISDropTarget::PathsToNames(filedata.GetFilenames()), bMove); return; } } } return; case 7: if(pSel && pCat) { //create folder long nSelId = pSel->GetFirstSelectedObjectId(); wxGxObject* pGxObject = pCat->GetRegisterObject(nSelId); wxGxAutoRenamer* pGxFolder = dynamic_cast<wxGxAutoRenamer*>(pGxObject); if(!pGxFolder) return; wxGxView* pGxView = dynamic_cast<wxGxView*>(wxWindow::FindFocus()); CPLString sFolderPath = CheckUniqPath(pGxObject->GetPath(), CPLString(wxString(_("New folder")).mb_str(wxConvUTF8)), true, " "); pGxFolder->BeginRenameOnAdd(pGxView, sFolderPath); if(!CreateDir(sFolderPath)) { wxMessageBox(_("Create folder error!"), _("Error"), wxICON_ERROR | wxOK ); pGxFolder->BeginRenameOnAdd(NULL, ""); return; } } return; case 3: default: return; } }