DinverCore/SimpleCondition.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of DinverCore.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created : 2007-02-26
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef SIMPLECONDITION_H
00028 #define SIMPLECONDITION_H
00029 
00030 #include "AbstractCondition.h"
00031 #include "DinverCoreDLLExport.h"
00032 
00033 namespace DinverCore {
00034 
00035 class DINVERCORE_EXPORT SimpleCondition : public AbstractCondition
00036 {
00037 public:
00038   enum Type {NoCondition, LessThan, GreaterThan};
00039 
00040   SimpleCondition(Parameter * p1, Type type, double factor, Parameter * p2, double constant);
00041   virtual bool operator==(const AbstractCondition& o) const;
00042 
00043   virtual const QString& xml_tagName() const {return xmlSimpleConditionTag;}
00044   static const QString xmlSimpleConditionTag;
00045 
00046   inline virtual void getLimits(int paramIndex, double& min, double& max) const;
00047   virtual bool adjustRanges();
00048   virtual void humanInfo() const;
00049 
00050   static QString toString(Type t);
00051   static Type fromString(QString t, bool& ok);
00052 protected:
00053   virtual uint internalChecksum() const;
00054   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00055   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00056   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00057 private:
00058   Type _type;
00059   double _factor;
00060   double _constant;
00061 };
00062 
00063 } // namespace DinverCore
00064 
00065 #include "Parameter.h"
00066 
00067 namespace DinverCore {
00068 
00069 inline void SimpleCondition::getLimits(int paramIndex, double& min, double& max) const
00070 {
00071   TRACE;
00072   double threshold;
00073   switch (paramIndex) {
00074   case 0:
00075     threshold=_factor * parameter(1).realValue() + _constant;
00076     switch (_type) {
00077     case LessThan:
00078       if(threshold < max) {
00079         max=threshold;
00080       }
00081       break;
00082     case GreaterThan:
00083       if(threshold > min) {
00084         min=threshold;
00085       }
00086       break;
00087     case NoCondition:
00088       break;
00089     }
00090     break;
00091   default:
00092     threshold=parameter(0).realValue() - _constant;
00093     switch (_type) {
00094     case LessThan:
00095       if(threshold > _factor * min) {
00096         if(_factor==1.0)
00097           min=threshold;
00098         else
00099           min=threshold/_factor;
00100       }
00101       break;
00102     case GreaterThan:
00103       if(threshold < _factor * max) {
00104         if(_factor==1.0)
00105           max=threshold;
00106         else
00107           max=threshold/_factor;
00108       }
00109       break;
00110     case NoCondition:
00111       break;
00112     }
00113     break;
00114   }
00115 }
00116 
00117 } // namespace DinverCore
00118 
00119 #endif // SIMPLECONDITION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines