void WTemplateFormView::setFormWidget(WFormModel::Field field, Wt::WWidget *formWidget) { fields_[field] = FieldData(); fields_[field].formWidget = formWidget; bindWidget(field, formWidget); }
/** * Writes out the crossings to file. * @param pFields Field storage expansion list. * @param time Current time. */ void FilterBenchmark::v_Finalise( const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) { for (int i = 0; i < m_threshold.size() - 1; ++i) { std::stringstream vOutputFilename; vOutputFilename << m_outputFile << "_" << i << ".fld"; std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = pFields[0]->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs()); pFields[0]->FwdTrans_IterPerExp(m_threshold[i], vCoeffs); // copy Data into FieldData and set variable for(int i = 0; i < FieldDef.size(); ++i) { // Could do a search here to find correct variable FieldDef[i]->m_fields.push_back("m"); pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs); } m_fld->Write(vOutputFilename.str(),FieldDef,FieldData); } }
EditTagDialog::EditTagDialog(Application* app, QWidget* parent) : QDialog(parent), ui_(new Ui_EditTagDialog), app_(app), album_cover_choice_controller_(new AlbumCoverChoiceController(this)), loading_(false), ignore_edits_(false), tag_fetcher_(new TagFetcher(this)), cover_art_id_(0), cover_art_is_set_(false), results_dialog_(new TrackSelectionDialog(this)) { cover_options_.default_output_image_ = AlbumCoverLoader::ScaleAndPad(cover_options_, QImage(":nocover.png")); connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64,QImage,QImage)), SLOT(ArtLoaded(quint64,QImage,QImage))); connect(tag_fetcher_, SIGNAL(ResultAvailable(Song, SongList)), results_dialog_, SLOT(FetchTagFinished(Song, SongList)), Qt::QueuedConnection); connect(tag_fetcher_, SIGNAL(Progress(Song,QString)), results_dialog_, SLOT(FetchTagProgress(Song,QString))); connect(results_dialog_, SIGNAL(SongChosen(Song, Song)), SLOT(FetchTagSongChosen(Song, Song))); connect(results_dialog_, SIGNAL(finished(int)), tag_fetcher_, SLOT(Cancel())); album_cover_choice_controller_->SetApplication(app_); ui_->setupUi(this); ui_->splitter->setSizes(QList<int>() << 200 << width() - 200); ui_->loading_label->hide(); // An editable field is one that has a label as a buddy. The label is // important because it gets turned bold when the field is changed. foreach (QLabel* label, findChildren<QLabel*>()) { QWidget* widget = label->buddy(); if (widget) { // Store information about the field fields_ << FieldData(label, widget, widget->objectName()); // Connect the Reset signal if (dynamic_cast<ExtendedEditor*>(widget)) { connect(widget, SIGNAL(Reset()), SLOT(ResetField())); } // Connect the edited signal if (qobject_cast<QLineEdit*>(widget)) { connect(widget, SIGNAL(textChanged(QString)), SLOT(FieldValueEdited())); } else if (qobject_cast<QPlainTextEdit*>(widget)) { connect(widget, SIGNAL(textChanged()), SLOT(FieldValueEdited())); } else if (qobject_cast<QSpinBox*>(widget)) { connect(widget, SIGNAL(valueChanged(int)), SLOT(FieldValueEdited())); } } }
void WTemplateFormView ::setFormWidget(WFormModel::Field field, WWidget *formWidget, FieldView *fieldView) { fields_[field] = FieldData(); fields_[field].formWidget = formWidget; fields_[field].updateFunctions = fieldView; bindWidget(field, formWidget); }
void FilterCheckpointCellModel::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) { if (m_index++ % m_outputFrequency > 0) { return; } std::stringstream vOutputFilename; vOutputFilename << m_outputFile << "_" << m_outputIndex << ".chk"; SpatialDomains::MeshGraphSharedPtr vGraph = pFields[0]->GetGraph(); std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = pFields[0]->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); // copy Data into FieldData and set variable std::string varName; for(int j = 1; j < m_cell->GetNumCellVariables(); ++j) { varName = m_cell->GetCellVarName(j); for(int i = 0; i < FieldDef.size(); ++i) { // Retrieve data from cell model Array<OneD, NekDouble> data = m_cell->GetCellSolutionCoeffs(j); // Could do a search here to find correct variable FieldDef[i]->m_fields.push_back(varName); pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], data); } } // Update time in field info if required LibUtilities::FieldMetaDataMap fieldMetaDataMap; fieldMetaDataMap["Time"] = boost::lexical_cast<std::string>(time); m_fld->Write(vOutputFilename.str(),FieldDef,FieldData,fieldMetaDataMap); m_outputIndex++; }
EditTagDialog::EditTagDialog(Application* app, QWidget* parent) : QDialog(parent), ui_(new Ui_EditTagDialog), app_(app), album_cover_choice_controller_(new AlbumCoverChoiceController(this)), loading_(false), ignore_edits_(false), tag_fetcher_(new TagFetcher(this)), cover_art_id_(0), cover_art_is_set_(false), results_dialog_(new TrackSelectionDialog(this)) { cover_options_.default_output_image_ = AlbumCoverLoader::ScaleAndPad(cover_options_, QImage(":nocover.png")); connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage, QImage)), SLOT(ArtLoaded(quint64, QImage, QImage))); connect(tag_fetcher_, SIGNAL(ResultAvailable(Song, SongList)), results_dialog_, SLOT(FetchTagFinished(Song, SongList)), Qt::QueuedConnection); connect(tag_fetcher_, SIGNAL(Progress(Song, QString)), results_dialog_, SLOT(FetchTagProgress(Song, QString))); connect(results_dialog_, SIGNAL(SongChosen(Song, Song)), SLOT(FetchTagSongChosen(Song, Song))); connect(results_dialog_, SIGNAL(finished(int)), tag_fetcher_, SLOT(Cancel())); album_cover_choice_controller_->SetApplication(app_); ui_->setupUi(this); ui_->splitter->setSizes(QList<int>() << 200 << width() - 200); ui_->loading_label->hide(); // An editable field is one that has a label as a buddy. The label is // important because it gets turned bold when the field is changed. for (QLabel* label : findChildren<QLabel*>()) { QWidget* widget = label->buddy(); if (widget) { // Store information about the field fields_ << FieldData(label, widget, widget->objectName()); // Connect the Reset signal if (dynamic_cast<ExtendedEditor*>(widget)) { connect(widget, SIGNAL(Reset()), SLOT(ResetField())); } // Connect the edited signal if (qobject_cast<QLineEdit*>(widget)) { connect(widget, SIGNAL(textChanged(QString)), SLOT(FieldValueEdited())); } else if (qobject_cast<QPlainTextEdit*>(widget)) { connect(widget, SIGNAL(textChanged()), SLOT(FieldValueEdited())); } else if (qobject_cast<QSpinBox*>(widget)) { connect(widget, SIGNAL(valueChanged(int)), SLOT(FieldValueEdited())); } } } // Set the colour of all the labels on the summary page const bool light = palette().color(QPalette::Base).value() > 128; const QColor color = palette().color(QPalette::Dark); QPalette summary_label_palette(palette()); summary_label_palette.setColor( QPalette::WindowText, light ? color.darker(150) : color.lighter(125)); for (QLabel* label : ui_->summary_tab->findChildren<QLabel*>()) { if (label->property("field_label").toBool()) { label->setPalette(summary_label_palette); } } // Pretend the summary text is just a label ui_->summary->setMaximumHeight(ui_->art->height() - ui_->summary_art_button->height() - 4); connect(ui_->song_list->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(SelectionChanged())); connect(ui_->button_box, SIGNAL(clicked(QAbstractButton*)), SLOT(ButtonClicked(QAbstractButton*))); connect(ui_->rating, SIGNAL(RatingChanged(float)), SLOT(SongRated(float))); connect(ui_->playcount_reset, SIGNAL(clicked()), SLOT(ResetPlayCounts())); connect(ui_->fetch_tag, SIGNAL(clicked()), SLOT(FetchTag())); // Set up the album cover menu cover_menu_ = new QMenu(this); QList<QAction*> actions = album_cover_choice_controller_->GetAllActions(); connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); connect(album_cover_choice_controller_->cover_from_url_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); connect(album_cover_choice_controller_->search_for_cover_action(), SIGNAL(triggered()), this, SLOT(SearchForCover())); connect(album_cover_choice_controller_->unset_cover_action(), SIGNAL(triggered()), this, SLOT(UnsetCover())); connect(album_cover_choice_controller_->show_cover_action(), SIGNAL(triggered()), this, SLOT(ShowCover())); cover_menu_->addActions(actions); ui_->summary_art_button->setMenu(cover_menu_); ui_->art->installEventFilter(this); ui_->art->setAcceptDrops(true); // Add the next/previous buttons previous_button_ = new QPushButton(IconLoader::Load("go-previous"), tr("Previous"), this); next_button_ = new QPushButton(IconLoader::Load("go-next"), tr("Next"), this); ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole); ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole); connect(previous_button_, SIGNAL(clicked()), SLOT(PreviousSong())); connect(next_button_, SIGNAL(clicked()), SLOT(NextSong())); // Set some shortcuts for the buttons new QShortcut(QKeySequence::Back, previous_button_, SLOT(click())); new QShortcut(QKeySequence::Forward, next_button_, SLOT(click())); new QShortcut(QKeySequence::MoveToPreviousPage, previous_button_, SLOT(click())); new QShortcut(QKeySequence::MoveToNextPage, next_button_, SLOT(click())); // Show the shortcuts as tooltips previous_button_->setToolTip(QString("%1 (%2 / %3)").arg( previous_button_->text(), QKeySequence(QKeySequence::Back).toString(QKeySequence::NativeText), QKeySequence(QKeySequence::MoveToPreviousPage) .toString(QKeySequence::NativeText))); next_button_->setToolTip(QString("%1 (%2 / %3)").arg( next_button_->text(), QKeySequence(QKeySequence::Forward).toString(QKeySequence::NativeText), QKeySequence(QKeySequence::MoveToNextPage) .toString(QKeySequence::NativeText))); new TagCompleter(app_->library_backend(), Playlist::Column_Artist, ui_->artist); new TagCompleter(app_->library_backend(), Playlist::Column_Album, ui_->album); new TagCompleter(app_->library_backend(), Playlist::Column_AlbumArtist, ui_->albumartist); new TagCompleter(app_->library_backend(), Playlist::Column_Genre, ui_->genre); new TagCompleter(app_->library_backend(), Playlist::Column_Composer, ui_->composer); new TagCompleter(app_->library_backend(), Playlist::Column_Performer, ui_->performer); new TagCompleter(app_->library_backend(), Playlist::Column_Grouping, ui_->grouping); }
void WFormModel::addField(Field field, const WString& info) { fields_[field] = FieldData(); fields_[field].validation = WValidator::Result(WValidator::Invalid, info); }
/** * Main function. * * Usage: VtkToFld session.xml input.vtk output.fld [options] */ int main(int argc, char* argv[]) { // Set up available options po::options_description desc("Available options"); desc.add_options() ("help,h", "Produce this help message.") ("name,n", po::value<string>()->default_value("Intensity"), "Name of field in VTK file to use for intensity.") ("outname,m", po::value<string>()->default_value("intensity"), "Name of field in output FLD file.") ("precision,p", po::value<double>()->default_value(1), "Precision of vertex matching."); po::options_description hidden("Hidden options"); hidden.add_options() ("file", po::value<vector<string> >(), "Input filename"); po::options_description cmdline_options; cmdline_options.add(desc).add(hidden); po::positional_options_description p; p.add("file", -1); po::variables_map vm; // Parse command-line options try { po::store(po::command_line_parser(argc, argv). options(cmdline_options).positional(p).run(), vm); po::notify(vm); } catch (const std::exception& e) { cerr << e.what() << endl; cerr << desc; return 1; } if ( vm.count("help") || vm.count("file") == 0 || vm["file"].as<vector<string> >().size() != 3) { cerr << "Usage: VtkToFld session.xml intensity.vtk output.fld [options]" << endl; cerr << desc; return 1; } // Extract command-line argument values std::vector<std::string> vFiles = vm["file"].as<vector<string> >(); const string infile = vFiles[1]; const string outfile = vFiles[2]; const double factor = vm["precision"].as<double>(); const string name = vm["name"].as<string>(); const string outname = vm["outname"].as<string>(); std::vector<std::string> vFilenames; LibUtilities::SessionReaderSharedPtr vSession; SpatialDomains::MeshGraphSharedPtr graph2D; MultiRegions::ExpList2DSharedPtr Exp; vFilenames.push_back(vFiles[0]); vSession = LibUtilities::SessionReader::CreateInstance(2, argv, vFilenames); try { //---------------------------------------------- // Read in mesh from input file graph2D = MemoryManager<SpatialDomains::MeshGraph2D>:: AllocateSharedPtr(vSession); //---------------------------------------------- //---------------------------------------------- // Define Expansion Exp = MemoryManager<MultiRegions::ExpList2D>:: AllocateSharedPtr(vSession,graph2D); //---------------------------------------------- //---------------------------------------------- // Set up coordinates of mesh int coordim = Exp->GetCoordim(0); int nq = Exp->GetNpoints(); Array<OneD, NekDouble> xc0(nq,0.0); Array<OneD, NekDouble> xc1(nq,0.0); Array<OneD, NekDouble> xc2(nq,0.0); switch(coordim) { case 2: Exp->GetCoords(xc0,xc1); break; case 3: Exp->GetCoords(xc0,xc1,xc2); break; default: ASSERTL0(false,"Coordim not valid"); break; } //---------------------------------------------- vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New(); vtkMeshReader->SetFileName(infile.c_str()); vtkMeshReader->Update(); vtkPolyData *vtkMesh = vtkMeshReader->GetOutput(); vtkCellDataToPointData* c2p = vtkCellDataToPointData::New(); #if VTK_MAJOR_VERSION <= 5 c2p->SetInput(vtkMesh); #else c2p->SetInputData(vtkMesh); #endif c2p->PassCellDataOn(); c2p->Update(); vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput(); vtkPoints *vtkPoints = vtkMesh->GetPoints(); ASSERTL0(vtkPoints, "ERROR: cannot get points from mesh."); vtkCellArray *vtkPolys = vtkMesh->GetPolys(); ASSERTL0(vtkPolys, "ERROR: cannot get polygons from mesh."); vtkPointData *vtkPData = vtkDataAtPoints->GetPointData(); ASSERTL0(vtkPolys, "ERROR: cannot get point data from file."); VertexSet points; VertexSet::iterator vIter; double p[3]; double val; double x, y, z; int coeff_idx; int i,j,n; if (!vtkDataAtPoints->GetPointData()->HasArray(name.c_str())) { n = vtkDataAtPoints->GetPointData()->GetNumberOfArrays(); cerr << "Input file '" << infile << "' does not have a field named '" << name << "'" << endl; cerr << "There are " << n << " arrays in this file." << endl; for (int i = 0; i < n; ++i) { cerr << " " << vtkDataAtPoints->GetPointData()->GetArray(i)->GetName() << endl; } return 1; } // Build up an unordered set of vertices from the VTK file. For each // vertex a hashed value of the coordinates is generated to within a // given tolerance. n = vtkPoints->GetNumberOfPoints(); for (i = 0; i < n; ++i) { vtkPoints->GetPoint(i,p); val = vtkPData->GetScalars(name.c_str())->GetTuple1(i); boost::shared_ptr<Vertex> v(new Vertex(p[0],p[1],p[2],val,factor)); points.insert(v); } // Now process each vertex of each element in the mesh SpatialDomains::PointGeomSharedPtr vert; for (i = 0; i < Exp->GetNumElmts(); ++i) { StdRegions::StdExpansionSharedPtr e = Exp->GetExp(i); for (j = 0; j < e->GetNverts(); ++j) { // Get the index of the coefficient corresponding to this vertex coeff_idx = Exp->GetCoeff_Offset(i) + e->GetVertexMap(j); // Get the coordinates of the vertex vert = e->as<LocalRegions::Expansion2D>()->GetGeom2D() ->GetVertex(j); vert->GetCoords(x,y,z); // Look up the vertex in the VertexSet boost::shared_ptr<Vertex> v(new Vertex(x,y,z,0.0,factor)); vIter = points.find(v); // If not found, maybe the tolerance should be reduced? // If found, record the scalar value from the VTK file in the // corresponding coefficient. if (vIter == points.end()) { cerr << "Vertex " << i << " not found. Looking for (" << x << ", " << y << ", " << z << ")" << endl; } else { Exp->UpdateCoeffs()[coeff_idx] = (*vIter)->scalar; } } } Exp->SetPhysState(false); //----------------------------------------------- // Write solution to file std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = Exp->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); for(i = 0; i < FieldDef.size(); ++i) { FieldDef[i]->m_fields.push_back(outname); Exp->AppendFieldData(FieldDef[i], FieldData[i]); } LibUtilities::FieldIO vFld(vSession->GetComm()); vFld.Write(outfile, FieldDef, FieldData); //----------------------------------------------- } catch (...) { cout << "An error occurred." << endl; } }
void ProcessAddFld::Process(po::variables_map &vm) { if (m_f->m_verbose) { cout << "ProcessAddFld: Adding new fld to input fld" << endl; } ASSERTL0(m_f->m_data.size() != 0,"No input data defined"); string scalestr = m_config["scale"].as<string>(); NekDouble scale = boost::lexical_cast<NekDouble>(scalestr); string fromfld = m_config["fromfld"].as<string>(); FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field()); if(m_f->m_exp.size()) { // Set up ElementGIDs in case of parallel processing Array<OneD,int> ElementGIDs(m_f->m_exp[0]->GetExpSize()); for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i) { ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID(); } m_f->m_fld->Import(fromfld,fromField->m_fielddef, fromField->m_data, LibUtilities::NullFieldMetaDataMap, ElementGIDs); } else { m_f->m_fld->Import(fromfld,fromField->m_fielddef, fromField->m_data, LibUtilities::NullFieldMetaDataMap); } bool samelength = true; if(fromField->m_data.size() != m_f->m_data.size()) { samelength = false; } // scale input field for(int i = 0; i < fromField->m_data.size(); ++i) { int datalen = fromField->m_data[i].size(); Vmath::Smul(datalen, scale, &(fromField->m_data[i][0]), 1, &(fromField->m_data[i][0]), 1); if(samelength) { if(datalen != m_f->m_data[i].size()) { samelength = false; } } } if(samelength == true) { for(int i = 0; i < m_f->m_data.size(); ++i) { int datalen = m_f->m_data[i].size(); Vmath::Vadd(datalen, &(m_f->m_data[i][0]), 1, &(fromField->m_data[i][0]), 1, &(m_f->m_data[i][0]), 1); } } else { ASSERTL0(m_f->m_exp.size() != 0 , "Input fields have partitions of different length and so xml " "file needs to be specified"); int nfields = m_f->m_fielddef[0]->m_fields.size(); int ncoeffs = m_f->m_exp[0]->GetNcoeffs(); Array<OneD, NekDouble> SaveFld(ncoeffs); for (int j = 0; j < nfields; ++j) { Vmath::Vcopy(ncoeffs,m_f->m_exp[j]->GetCoeffs(),1, SaveFld,1); // load new field for (int i = 0; i < fromField->m_data.size(); ++i) { m_f->m_exp[j]->ExtractDataToCoeffs( fromField->m_fielddef[i], fromField->m_data[i], fromField->m_fielddef[i]->m_fields[j], m_f->m_exp[j]->UpdateCoeffs()); } Vmath::Vadd(ncoeffs, m_f->m_exp[j]->GetCoeffs(), 1, SaveFld, 1, m_f->m_exp[j]->UpdateCoeffs(), 1); } std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = m_f->m_exp[0]->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); for(int i = 0; i < nfields; ++i) { for (int j = 0; j < FieldDef.size(); ++j) { FieldDef[j]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[i]); m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]); } } m_f->m_fielddef = FieldDef; m_f->m_data = FieldData; } }