System* MolecularFileDialog::readMOL2File(String filename, String system_name) { setStatusbarText((String)tr("reading MOL2 file..."), true); System* system = new System(); try { MOL2File mol2_file(filename); mol2_file >> *system; mol2_file.close(); } catch(Exception::GeneralException& e) { setStatusbarText(tr("Reading of MOL2 file failed, see logs!"), true); Log.error() << e << std::endl; delete system; return 0; } if (!finish_(filename, system_name, system)) return 0; return system; }
bool HelpViewer::showHelpFor(const QObject* object) { if (object == 0) return false; HashMap<const QObject*, String>::Iterator to_find; QObject* object2 = (QObject*) object; QWidget* widget = dynamic_cast<QWidget*>(object2); if (widget && widget->parent() != 0) { QToolBar* tb = dynamic_cast<QToolBar*>(widget->parent()); if (tb != 0) { QList<QAction *> acs = widget->actions(); if (acs.size() == 1) { to_find = docu_entries_.find(*acs.begin()); if (to_find != docu_entries_.end()) { showHelp((*to_find).second); return true; } } } } while (object2 != 0) { to_find = docu_entries_.find(object2); if (to_find != docu_entries_.end()) break; object2 = object2->parent(); } if (object2 == 0) { setStatusbarText(tr("No documentation for this widget available!"), true); return false; } showHelp((*to_find).second); return true; }
bool MolecularFileDialog::writeXYZFile(String filename, const System& system) { try { XYZFile file(filename, std::ios::out); file << system; file.close(); } catch(Exception::GeneralException& e) { Log.error() << e << std::endl; setStatusbarText((String)tr("Writing of XYZ file failed, see logs!"), true); return false; } return true; }
/** * Update the status bar if the package list view has loaded all * package details. * * @param totalPackageCount The number of packages in the package list view. */ void PakooView::handleFinishedLoadingPackageInfo( int totalPackageCount ) { QString category = packageView->listView->currentCategory(); QString subcategory = packageView->listView->currentSubcategory(); if( category == QString::null ) category = THEPORTAGETREETEXT; else if( subcategory != QString::null ) category += "-" + subcategory; emit showStatusbarProgress( false ); emit setStatusbarText( PACKAGESINCATEGORYTEXT .arg( totalPackageCount ) .arg( category ) .arg( packageView->listView->installedPackageCount() ) .arg( "" ) ); }
/** * Update the status bar while the package list view is loading * detailed package info. * * @param loadedPackageCount The number of packages loaded so far. * @param totalPackageCount The total number of packages in the list view. */ void PakooView::handleLoadingPackageInfo( int loadedPackageCount, int totalPackageCount ) { QString category = packageView->listView->currentCategory(); QString subcategory = packageView->listView->currentSubcategory(); if( category == QString::null ) category = THEPORTAGETREETEXT; else if( subcategory != QString::null ) category += "-" + subcategory; emit setStatusbarProgress( loadedPackageCount, totalPackageCount, true ); emit setStatusbarText( PACKAGESINCATEGORYTEXT .arg( totalPackageCount ) .arg( category ) .arg( packageView->listView->installedPackageCount() ) .arg( LOADINGPACKAGEDETAILSTEXT ) ); }
void LabelDialog::accept() { list<Composite*> selection = getMainControl()->getMolecularControlSelection(); // no selection present => return if (selection.empty()) return; Representation* rep = new Representation; rep->setProperty(Representation::PROPERTY__ALWAYS_FRONT); rep->setModelType(MODEL_LABEL); LabelModel* model = new LabelModel; model->setText(ascii(text_box->currentText())); model->setColor(custom_color_); model->setFont(font_); if ( all_items->isChecked()) model->setMode(LabelModel::ONE_LABEL); else if ( every_atom->isChecked()) model->setMode(LabelModel::ALL_ATOMS); else if (every_residue->isChecked()) model->setMode(LabelModel::ALL_RESIDUES); else if ( every_item->isChecked()) model->setMode(LabelModel::ALL_ITEMS); rep->setModelProcessor(model); // process all objects in the selection list list<Composite*>::const_iterator list_it = selection.begin(); list<const Composite*> composites; for (; list_it != selection.end(); ++list_it) { composites.push_back(*list_it); } rep->setComposites(composites); getMainControl()->insert(*rep); getMainControl()->update(*rep); text_box->addItem(text_box->currentText()); setStatusbarText(tr("Label added.")); }
void DownloadPDBFile::downloadFinished() { String id = ascii(pdbId->currentText()); String url = prefix_; url += id; url += (checkbox_biounit->isChecked()) ? biounit_suffix_ : suffix_; Log.info() << "Url: " << url << std::endl; if (current_reply_->error() != QNetworkReply::NoError) { Log.error() << "Could not download PDBFile! Reason given was \"" + (String)(current_reply_->errorString()) + "\""<< std::endl; setStatusbarText("Could not download PDBFile! Reason given was \"" + (String)(current_reply_->errorString()) + "\""); error_ = true; } else { System *system = new System(); try { String temp_filename = VIEW::createTemporaryFilename(); QFile outfile(temp_filename.c_str()); outfile.open(QIODevice::ReadWrite); outfile.write(current_reply_->readAll()); outfile.close(); // if we download the biological unit, we have to decompress the pdb.gz file if (checkbox_biounit->isChecked()) { String unzipped_filename = VIEW::createTemporaryFilename(); std::ifstream file(temp_filename.c_str(), std::ios_base::in | std::ios_base::binary); boost::iostreams::filtering_streambuf<boost::iostreams::input> in; in.push(boost::iostreams::gzip_decompressor()); in.push(file); PDBFile pdb_file(unzipped_filename, std::ios::out | std::ios::binary); boost::iostreams::copy(in, pdb_file); pdb_file.reopen(std::ios::in); // the individual units are organized as MODELs // by default PDBFile only reads the first MODEL pdb_file.selectAllModels(); pdb_file >> *system; pdb_file.close(); removeFile_(unzipped_filename); } else { PDBFile pdb_file(temp_filename); pdb_file >> *system; pdb_file.close(); } removeFile_(temp_filename); if (system->countAtoms() == 0) { delete system; show(); setStatusbarText(tr("Could not fetch the given PDBFile"), true); return; } else { setStatusbarText(String("read ") + String(system->countAtoms()) + " atoms for: " + id, true); } if (system->getName() == "") { system->setName(ascii(pdbId->currentText())); } system->setProperty("FROM_FILE", url); close(); pdbId->clearEditText(); getMainControl()->insert(*system, ascii(pdbId->currentText())); notify_(new CompositeMessage(*system, CompositeMessage::CENTER_CAMERA)); download->setDefault(true); pdbId->setFocus(); } catch(...)
bool MolecularFileDialog::writeFile() { list<Composite*>& selection = getMainControl()->getMolecularControlSelection(); if (selection.size() != 1 || !RTTI::isKindOf<System> (*selection.begin())) { setStatusbarText((String)tr("Not a single system selected! Aborting writing..."), true); return false; } const System& system = *(const System*) (*selection.begin()); String file_name = getWorkingDir(); file_name += FileSystem::PATH_SEPARATOR; file_name += system.getName(); file_name += ".pdb"; QString s = QFileDialog::getSaveFileName( 0, tr("Choose a filename to save the selected system"), file_name.c_str(), getSupportedFileFormats().c_str()); if (s == QString::null) return false; setStatusbarText((String)tr("writing file...")); String filename = ascii(s); setWorkingDirFromFilename_(filename); String filter(filename); while (filter.has(FileSystem::PATH_SEPARATOR)) { filter = filter.after(FileSystem::PATH_SEPARATOR); } String filename_without_path = filter; while (filter.has('.')) { filter = filter.after("."); } bool result = false; if (filter == "PDB" || filter == "pdb" || filter == "ent" || filter == "ENT" || filter == "brk" || filter == "BRK") { result = writePDBFile(filename, system); } else if (filter.hasSubstring("HIN") || filter.hasSubstring("hin")) { result = writeHINFile(filename, system); } else if (filter.hasSubstring("MOL2") || filter.hasSubstring("mol2")) { result = writeMOL2File(filename, system); } else if (filter.hasSubstring("MOL") || filter.hasSubstring("mol")) { result = writeMOLFile(filename, system); } else if (filter.hasSubstring("SDF") || filter.hasSubstring("sdf")) { result = writeSDFile(filename, system); } else if (filter.hasSubstring("AC") || filter.hasSubstring("ac")) { result = writeACFile(filename, system); } else if (filter.hasSubstring("XYZ") || filter.hasSubstring("xyz")) { result = writeXYZFile(filename, system); } else { if (filter == filename_without_path) { filename += ".pdb"; result = writePDBFile(filename, system); } else { setStatusbarText((String)tr("Unknown file format, please set the file extension accordingly to type, aborting..."), true); return false; } } if (!result) { return false; } setStatusbarText(String(system.countAtoms()) + " " + (String)tr("atoms written to file") + " \"" + filename + "\"", true); return true; }
System* MolecularFileDialog::openMolecularFile(const String& filename, const String& filetype, const String& system_name) { bool ok = false; try { if (File::isReadable(filename)) ok = true; } catch(...) {} if (!ok || filename == "/" || filename == "\\") { setStatusbarText((String)tr("Could not open file") + " " + filename, true); return 0; } // TODO substitue by GenericMolFile* file = MolFileFactory::open(filename); if (filetype.hasSubstring("pdb") || filetype.hasSubstring("PDB") || filetype.hasSubstring("brk") || filetype.hasSubstring("BRK") || filetype.hasSubstring("ent") || filetype.hasSubstring("ENT")) { return readPDBFile(filename, system_name); } else if (filetype.hasSubstring("HIN") || filetype.hasSubstring("hin")) { return readHINFile(filename, system_name); } else if (filetype.hasSubstring("MOL2") || filetype.hasSubstring("mol2")) { return readMOL2File(filename, system_name); } else if (filetype.hasSubstring("MOL") || filetype.hasSubstring("mol")) { return readMOLFile(filename, system_name); } else if (filetype.hasSubstring("SDF") || filetype.hasSubstring("sdf")) { return readSDFile(filename, system_name); } else if (filetype.hasSubstring("AC") || filetype.hasSubstring("ac")) { return readACFile(filename, system_name); } else if (filetype.hasSubstring("XYZ") || filetype.hasSubstring("xyz")) { return readXYZFile(filename, system_name); } else { setStatusbarText(String(tr("Unknown filetype")) + ": " + filetype, true); } return 0; }
// creates a polygon from a given vector RegularData1D * data void RegularData1DWidget::createPlot() { // no data => no polygon if (data_ == 0 || data_->size() == 0) { return; } // find the data min and max float min = (*data_)[0]; float max = (*data_)[0]; float dif_min = min; float old = min; //last point if (dif_min == 0) dif_min = 1; for (int i=0; i<(int)data_->size(); i++) { if ((*data_)[i] >= max) max = (*data_)[i]; if ((*data_)[i] <= min) min = (*data_)[i]; float dif = (*data_)[i] - old; if ( (dif > 1e-3) && (dif < dif_min) ) { dif_min = dif; } old = (*data_)[i]; } int height_ = (int)ceil(((max-min) / dif_min) * 5); if (height_ > 1000) { // the resulting picture would be much too large height_ = 1000; dif_min = (max - min)/200.; } // resize the canvas to fit the data canvas_.resize(5*(data_->size()+2), height_+10); int x_new; int y_new; int x_old = 5; int y_old = height_+5 - (int)((((*data_)[0]-min)/dif_min)*5); Q3CanvasLine *ql; try { for (int i=0; i<(int)data_->size(); i++) { x_new = 5*(i+1); y_new = height_+5 - (int)(((data_->getData(i)-min)/dif_min)*5); ql = new Q3CanvasLine(&canvas_); ql->setPen(diagram_color_); ql->show(); ql->setPoints(x_old, y_old, x_new, y_new); objects_.push_back(dynamic_cast<Q3CanvasItem*> (ql)); x_old = x_new; y_old = y_new; } } catch(...) { setStatusbarText("Error: Point in dataset out of grid!"); Log.error() << "Error: Point in dataset out of grid!" << std::endl; return; } //add the x-axis ql = new Q3CanvasLine(&canvas_); int startx = 1; int starty = height_+5 - (int)/*round*/(((startx-min)/dif_min)*5); int endx = data_->size()*5; ql->setPoints(startx, starty, endx, starty); ql->setPen(axis_color_); ql->show(); objects_.push_back(dynamic_cast<Q3CanvasItem*> (ql)); //add the y-axis ql = new Q3CanvasLine(&canvas_); startx = 4; starty = 0; int endy = height_+5 - (int)/*round*/((((*data_)[endx]-min)/dif_min)*5); ql->setPoints(startx, starty, startx, endy); ql->setPen(QColor(Qt::red)); ql->show(); objects_.push_back(dynamic_cast<Q3CanvasItem*> (ql)); }
// creates a polygon from a given vector RegularData1D * data void RegularData2DWidget::createPlot() { // no data => no polygon if (data_ == 0 || data_->size() == 0) { return; } // set up the ColorMap... TODO: This should be done by a dialog or something similar ColorRGBA colorList[3]; ColorMap color_table_; colorList[0] = ColorRGBA(1.,0.,0.,1.); colorList[1] = ColorRGBA(0.,1.,0.,1.); colorList[2] = ColorRGBA(0.,0.,1.,1.); color_table_.setBaseColors(colorList, 3); color_table_.setNumberOfColors(100); // determine the minimal and maximal values in data_ float min = (*data_)[0]; float max = (*data_)[0]; for (Position i=1; i < (*data_).size(); i++) { if ((*data_)[i] < min) min = (*data_)[i]; else if ((*data_)[i] > max) max = (*data_)[i]; } color_table_.setRange(min, max); color_table_.createMap(); //maximal number of Lines and Columns Size max_x = (*data_).getSize().x; Size max_y = (*data_).getSize().y; // Draw the points QPixmap pixmap; pixmap.resize(max_x, max_y); pixmap.fill(); // delete the old picture QPainter paint; paint.begin(&pixmap); // set the Painter try { QColor pCol; for (Position y=0; y< max_y; y++) { for (Position x=0; x< max_x; x++) { ColorRGBA mapcolor = color_table_.map(data_->getData(x + y * max_x)); pCol = QColor(mapcolor.getRed(), mapcolor.getGreen(), mapcolor.getBlue()); paint.setPen(pCol); paint.drawPoint(x, y); } } } catch(...) { setStatusbarText("Error: Point in dataset out of grid!"); Log.error() << "Error: Point in dataset out of grid!" << std::endl; return; } paint.end(); //put the pixmapItem into objects PixmapItem* pixItem = new PixmapItem(&canvas_, pixmap); pixItem->show(); objects_.push_back(dynamic_cast<Q3CanvasItem*> (pixItem)); // resize the canvas to fit the data canvas_.resize(max_x, max_y); }