File indexing completed on 2024-04-14 03:40:21

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Pino Toscano <toscano.pino@tiscali.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KALZIUMGRADIENTTYPE_H
0008 #define KALZIUMGRADIENTTYPE_H
0009 
0010 class KalziumGradientType;
0011 
0012 #include <QByteArray>
0013 #include <QColor>
0014 
0015 /**
0016  * Factory for KalziumGradientType classes.
0017  *
0018  * @author Pino Toscano
0019  */
0020 class KalziumGradientTypeFactory
0021 {
0022 public:
0023     enum KalziumGradientTypes {
0024         SOMGradientType = 0,
0025         CovalentRadiusGradientType,
0026         VanDerWaalsRadiusGradientType,
0027         MassGradientType,
0028         BoilingPointGradientType,
0029         MeltingPointGradientType,
0030         ElectronaffinityGradientType,
0031         DiscoverydateGradientType,
0032         IonizationGradientType
0033     };
0034 
0035     /**
0036      * Get the instance of this factory.
0037      */
0038     static KalziumGradientTypeFactory *instance();
0039 
0040     /**
0041      * Returns the KalziumGradientType with the @p id specified.
0042      * It will gives 0 if none found.
0043      */
0044     KalziumGradientType *build(int id) const;
0045     /**
0046      * Returns the KalziumGradientType whose name is the @p id
0047      * specified.
0048      * It will gives 0 if none found.
0049      */
0050     KalziumGradientType *build(const QByteArray &id) const;
0051 
0052     /**
0053      * Returns a list with the names of the gradients we support.
0054      */
0055     QStringList gradients() const;
0056 
0057     void setCurrentGradient(int newGradient);
0058 
0059 private:
0060     KalziumGradientTypeFactory();
0061 
0062     QList<KalziumGradientType *> m_gradients;
0063 };
0064 
0065 /**
0066  * Base class representing a gradient.
0067  * Inherit it and add its instance to the factory to add it globally.
0068  *
0069  * @author Pino Toscano
0070  */
0071 class KalziumGradientType
0072 {
0073 public:
0074     /**
0075      * Get its instance.
0076      */
0077     static KalziumGradientType *instance();
0078 
0079     virtual ~KalziumGradientType();
0080 
0081     /**
0082      * Returns the ID of this gradient.
0083      * Mainly used when saving/loading.
0084      */
0085     virtual QByteArray name() const = 0;
0086     /**
0087      * Returns the description of this gradient.
0088      * Used in all the visible places.
0089      */
0090     virtual QString description() const = 0;
0091 
0092     /**
0093      * Calculate the coefficient of the element with atomic number
0094      * @p el according to this gradient. The calculated coefficient
0095      * will be always in the range [0, 1].
0096      */
0097     virtual double elementCoeff(int el) const;
0098     /**
0099      * Return the value, related to the current gradient, of the
0100      * element with atomic number @p el.
0101      * It will return -1 if the data is not available.
0102      */
0103     virtual double value(int el) const = 0;
0104     /**
0105      * Gives back the unit of the current value.
0106      */
0107     virtual QString unit() const = 0; // TODO How can i get the unit from?
0108     /**
0109      * Returns the minimum value of the data this gradient
0110      * represents.
0111      */
0112     virtual double minValue() const = 0;
0113     /**
0114      * Returns the maximum value of the data this gradient
0115      * represents.
0116      */
0117     virtual double maxValue() const = 0;
0118     /**
0119      * Returns the numbers of decimal in which the gradient values
0120      * look the best
0121      */
0122     virtual int decimals() const = 0;
0123     /**
0124      * Returns whether to use a logarithmic gradient
0125      * instead of a linear one.
0126      */
0127     virtual bool logarithmicGradient() const = 0;
0128     /**
0129      * Returns the first color of the gradient.
0130      */
0131     virtual QColor firstColor() const;
0132     /**
0133      * Returns the second color of the gradient.
0134      */
0135     virtual QColor secondColor() const;
0136     /**
0137      * Returns the color used to represent an element whose data is
0138      * not available.
0139      */
0140     virtual QColor notAvailableColor() const;
0141 
0142     /**
0143      * Calculates the color of an element which has a @p coeff which
0144      * is a percentage of the maximum value.
0145      * @param coeff is the coefficient in the range [0, 1], usually
0146      * calculated with elementCoeff()
0147      */
0148     QColor calculateColor(const double coeff) const;
0149 
0150 protected:
0151     KalziumGradientType();
0152 };
0153 
0154 /**
0155  * The gradient by covalent radius.
0156  *
0157  * @author Pino Toscano
0158  */
0159 class KalziumCovalentRadiusGradientType : public KalziumGradientType
0160 {
0161 public:
0162     static KalziumCovalentRadiusGradientType *instance();
0163 
0164     QByteArray name() const override;
0165     QString description() const override;
0166 
0167     double value(int el) const override;
0168     QString unit() const override;
0169 
0170     double minValue() const override;
0171     double maxValue() const override;
0172     int decimals() const override;
0173 
0174     bool logarithmicGradient() const override;
0175 
0176 private:
0177     KalziumCovalentRadiusGradientType();
0178 };
0179 
0180 /**
0181  * The gradient by van Der Waals radius.
0182  *
0183  * @author Pino Toscano
0184  */
0185 class KalziumVanDerWaalsRadiusGradientType : public KalziumGradientType
0186 {
0187 public:
0188     static KalziumVanDerWaalsRadiusGradientType *instance();
0189 
0190     QByteArray name() const override;
0191     QString description() const override;
0192 
0193     double value(int el) const override;
0194     QString unit() const override;
0195 
0196     double minValue() const override;
0197     double maxValue() const override;
0198     int decimals() const override;
0199 
0200     bool logarithmicGradient() const override;
0201 
0202 private:
0203     KalziumVanDerWaalsRadiusGradientType();
0204 };
0205 
0206 /**
0207  * The gradient by atomic mass.
0208  *
0209  * @author Pino Toscano
0210  */
0211 class KalziumMassGradientType : public KalziumGradientType
0212 {
0213 public:
0214     static KalziumMassGradientType *instance();
0215 
0216     QByteArray name() const override;
0217     QString description() const override;
0218 
0219     double value(int el) const override;
0220     QString unit() const override;
0221 
0222     double minValue() const override;
0223     double maxValue() const override;
0224     int decimals() const override;
0225 
0226     bool logarithmicGradient() const override;
0227 
0228 private:
0229     KalziumMassGradientType();
0230 };
0231 
0232 /**
0233  * The gradient by boiling point.
0234  *
0235  * @author Pino Toscano
0236  */
0237 class KalziumBoilingPointGradientType : public KalziumGradientType
0238 {
0239 public:
0240     static KalziumBoilingPointGradientType *instance();
0241 
0242     QByteArray name() const override;
0243     QString description() const override;
0244 
0245     double value(int el) const override;
0246     QString unit() const override;
0247 
0248     double minValue() const override;
0249     double maxValue() const override;
0250     int decimals() const override;
0251 
0252     bool logarithmicGradient() const override;
0253 
0254 private:
0255     KalziumBoilingPointGradientType();
0256 };
0257 
0258 /**
0259  * The gradient by melting point.
0260  *
0261  * @author Pino Toscano
0262  */
0263 class KalziumMeltingPointGradientType : public KalziumGradientType
0264 {
0265 public:
0266     static KalziumMeltingPointGradientType *instance();
0267 
0268     QByteArray name() const override;
0269     QString description() const override;
0270 
0271     double value(int el) const override;
0272     QString unit() const override;
0273 
0274     double minValue() const override;
0275     double maxValue() const override;
0276     int decimals() const override;
0277 
0278     bool logarithmicGradient() const override;
0279 
0280 private:
0281     KalziumMeltingPointGradientType();
0282 };
0283 
0284 /**
0285  * The gradient for SOM Widget
0286  *
0287  * @author Etienne Rebetez
0288  */
0289 class KalziumSOMGradientType : public KalziumGradientType
0290 {
0291 public:
0292     static KalziumSOMGradientType *instance();
0293 
0294     QByteArray name() const override;
0295     QString description() const override;
0296 
0297     double value(int el) const override;
0298     QString unit() const override;
0299 
0300     double minValue() const override;
0301     double maxValue() const override;
0302     int decimals() const override;
0303 
0304     bool logarithmicGradient() const override;
0305 
0306 private:
0307     KalziumSOMGradientType();
0308 };
0309 
0310 /**
0311  * The gradient by electronegativity.
0312  *
0313  * @author Pino Toscano
0314  */
0315 class KalziumElectronegativityGradientType : public KalziumGradientType
0316 {
0317 public:
0318     static KalziumElectronegativityGradientType *instance();
0319 
0320     QByteArray name() const override;
0321     QString description() const override;
0322 
0323     double value(int el) const override;
0324     QString unit() const override;
0325 
0326     double minValue() const override;
0327     double maxValue() const override;
0328     int decimals() const override;
0329 
0330     bool logarithmicGradient() const override;
0331 
0332 private:
0333     KalziumElectronegativityGradientType();
0334 };
0335 
0336 /**
0337  * The gradient by discoverydate.
0338  *
0339  * @author Carsten Niehaus
0340  */
0341 class KalziumDiscoverydateGradientType : public KalziumGradientType
0342 {
0343 public:
0344     static KalziumDiscoverydateGradientType *instance();
0345 
0346     QByteArray name() const override;
0347     QString description() const override;
0348 
0349     double value(int el) const override;
0350     QString unit() const override;
0351 
0352     double minValue() const override;
0353     double maxValue() const override;
0354     int decimals() const override;
0355 
0356     bool logarithmicGradient() const override;
0357 
0358 private:
0359     KalziumDiscoverydateGradientType();
0360 };
0361 
0362 /**
0363  * The gradient by electronaffinity.
0364  *
0365  * @author Carsten Niehaus
0366  */
0367 class KalziumElectronaffinityGradientType : public KalziumGradientType
0368 {
0369 public:
0370     static KalziumElectronaffinityGradientType *instance();
0371 
0372     QByteArray name() const override;
0373     QString description() const override;
0374 
0375     double value(int el) const override;
0376     QString unit() const override;
0377 
0378     double minValue() const override;
0379     double maxValue() const override;
0380     int decimals() const override;
0381 
0382     bool logarithmicGradient() const override;
0383 
0384 private:
0385     KalziumElectronaffinityGradientType();
0386 };
0387 
0388 /**
0389  * The gradient by the first ionization energy.
0390  *
0391  * @author Carsten Niehaus
0392  */
0393 class KalziumIonizationGradientType : public KalziumGradientType
0394 {
0395 public:
0396     static KalziumIonizationGradientType *instance();
0397 
0398     QByteArray name() const override;
0399     QString description() const override;
0400 
0401     double value(int el) const override;
0402     QString unit() const override;
0403 
0404     double minValue() const override;
0405     double maxValue() const override;
0406     int decimals() const override;
0407 
0408     bool logarithmicGradient() const override;
0409 
0410 private:
0411     KalziumIonizationGradientType();
0412 };
0413 
0414 #endif // KALZIUMGRADIENTTYPE_H