From ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kalzium/src/spectrum.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 kalzium/src/spectrum.cpp (limited to 'kalzium/src/spectrum.cpp') diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp new file mode 100644 index 00000000..4b74eadb --- /dev/null +++ b/kalzium/src/spectrum.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * Copyright (C) 2005 by Carsten Niehaus * + * cniehaus@kde.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "spectrum.h" + +#include "element.h" + +#include + +#include + +double Spectrum::minBand() +{ + double value = ( *m_bandlist.begin() ).wavelength; + QValueList::const_iterator it = m_bandlist.begin(); + const QValueList::const_iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + if ( value > ( *it ).wavelength ) + value = ( *it ).wavelength; + } + return value; +} + +double Spectrum::maxBand() +{ + double value = ( *m_bandlist.begin() ).wavelength; + QValueList::const_iterator it = m_bandlist.begin(); + const QValueList::const_iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + if ( value < ( *it ).wavelength ) + value = ( *it ).wavelength; + } + return value; +} + + +Spectrum* Spectrum::adjustToWavelength( double min, double max ) +{ + Spectrum *spec = new Spectrum(); + + QValueList::const_iterator it = m_bandlist.begin(); + const QValueList::const_iterator itEnd = m_bandlist.end(); + + for ( ; it != itEnd; ++it ) + { + if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) + continue; + + spec->addBand( *it ); + } + + spec->adjustMinMax(); + + return spec; +} + +void Spectrum::adjustIntensities() +{ + int maxInt = 0; + QValueList::Iterator it = m_bandlist.begin(); + const QValueList::Iterator itEnd = m_bandlist.end(); + + //find the highest intensity + for ( ; it != itEnd; ++it ) + { + if ( ( *it ).intensity > maxInt ) + maxInt = ( *it ).intensity; + } + + //check if an adjustment is needed or not + if ( maxInt == 1000 ) return; + + double max = ( double ) maxInt; + + //now adjust the intensities. + it = m_bandlist.begin(); + for ( ; it != itEnd; ++it ) + { + double curInt = ( ( double )( *it ).intensity ); + + double newInt = max*1000/curInt; + ( *it ).intensity = qRound( newInt ); + } +} + +QValueList Spectrum::wavelengths( double min, double max ) +{ + QValueList list; + + QValueList::const_iterator it = m_bandlist.begin(); + const QValueList::const_iterator itEnd = m_bandlist.end(); + + for ( ; it != itEnd; ++it ) + { + if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) + continue; + + list.append( ( *it ).wavelength ); + } + + return list; +} + +QString Spectrum::bandsAsHtml() +{ + QString html = "Chemical datai"; + + html += ""; + + QValueList::const_iterator it = m_bandlist.begin(); + const QValueList::const_iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + html += QString( "" ) + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "\n"; + } + + html += "
" + i18n( "Wavelength: %1 nm" ).arg( ( *it ).wavelength ) + "" + i18n( "Intensity: %1" ).arg( ( *it ).intensity ) + "" + i18n( "Probability: %1 108s-1" ).arg( ( *it ).aki ) + "" + i18n( "Energy 1: %1" ).arg( ( *it ).energy1 ) + "" + i18n( "Energy 2: %1" ).arg( ( *it ).energy2 ) + "" + i18n( "Electron Configuration 1: %1" ).arg( ( *it ).electronconfig1 ) + "" + i18n( "Electron Configuration 2: %1" ).arg( ( *it ).electronconfig2 ) + "" + i18n( "Term 1: %1" ).arg( ( *it ).term1 ) + "" + i18n( "Term 2: %1" ).arg( ( *it ).term2 ) + "" + i18n( "J 1: %1" ).arg( ( *it ).J1 ) + "" + i18n( "J 2: %1" ).arg( ( *it ).J2 ) + "
"; + + html += ""; + return html; +} -- cgit v1.2.1