A simple condition p1<a*p2+b. More...
#include <SimpleCondition.h>
Public Types | |
enum | Type { NoCondition, LessThan, GreaterThan } |
Public Member Functions | |
virtual bool | adjustRanges () |
virtual void | getLimits (int paramIndex, double &min, double &max) const |
virtual void | humanInfo () const |
virtual bool | operator== (const AbstractCondition &o) const |
SimpleCondition (Parameter *p1, Type type, double factor, Parameter *p2, double constant) | |
virtual const QString & | xml_tagName () const |
Static Public Member Functions | |
static Type | fromString (QString t, bool &ok) |
static QString | toString (Type t) |
Static Public Attributes | |
static const QString | xmlSimpleConditionTag = "SimpleCondition" |
Protected Member Functions | |
virtual uint | internalChecksum () const |
virtual XMLMember | xml_member (XML_MEMBER_ARGS) |
virtual bool | xml_setProperty (XML_SETPROPERTY_ARGS) |
virtual void | xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const |
A simple condition p1<a*p2+b.
DinverCore::SimpleCondition::SimpleCondition | ( | Parameter * | p1, |
Type | type, | ||
double | factor, | ||
Parameter * | p2, | ||
double | constant | ||
) |
Define a condition between p1 and p2.
Order of arguments should be read as:
p1 LessThan or GreaterThan (type) factor times p2 plus constant
References DinverCore::AbstractCondition::addParameter(), and TRACE.
{ TRACE; addParameter(p1); addParameter(p2); _type=type; _factor=factor; _constant=constant; }
bool DinverCore::SimpleCondition::adjustRanges | ( | ) | [virtual] |
Return true if original ranges of parameter are touched. Ranges can be reduced, never enlarged
Reimplemented from DinverCore::AbstractCondition.
References getLimits(), GreaterThan, LessThan, DinverCore::Parameter::maximum(), DinverCore::Parameter::minimum(), NoCondition, DinverCore::AbstractCondition::parameter(), DinverCore::Parameter::setMaximum(), DinverCore::Parameter::setMinimum(), DinverCore::Parameter::setRealValue(), and TRACE.
{ TRACE; double min, max; bool modified=false; switch (_type) { case LessThan: { min=-1e99; parameter(0).setRealValue(parameter(0).minimum()); getLimits(1, min, max); Parameter& p1=parameter(1); if(p1.minimum()<min) { p1.setMinimum(min); modified=true; } max=1e99; parameter(1).setRealValue(parameter(1).maximum()); getLimits(0, min, max); Parameter& p0=parameter(0); if(p0.maximum()>max) { p0.setMaximum(max); modified=true; } } break; case GreaterThan: { max=1e99; parameter(0).setRealValue(parameter(0).maximum()); getLimits(1, min, max); Parameter& p1=parameter(1); if(p1.maximum()>max) { p1.setMaximum(max); modified=true; } min=-1e99; parameter(1).setRealValue(parameter(1).minimum()); getLimits(0, min, max); Parameter& p0=parameter(0); if(p0.minimum()<min) { p0.setMinimum(min); modified=true; } } break; case NoCondition: break; } return modified; }
SimpleCondition::Type DinverCore::SimpleCondition::fromString | ( | QString | t, |
bool & | ok | ||
) | [static] |
References GreaterThan, LessThan, and NoCondition.
Referenced by xml_setProperty().
{ if(!t.isEmpty()) { switch(t[0].unicode()) { case 'L': if(t=="LessThan") { return LessThan; } break; case 'G': if(t=="GreaterThan") { return GreaterThan; } break; case 'N': if(t=="NoCondition") { return NoCondition; } break; default: break; } } ok=false; return NoCondition; }
void DinverCore::SimpleCondition::getLimits | ( | int | paramIndex, |
double & | min, | ||
double & | max | ||
) | const [inline, virtual] |
Adjust min or/and max to fulfill the condition. paramIndex must be 0 or 1.
Implements DinverCore::AbstractCondition.
References GreaterThan, LessThan, NoCondition, DinverCore::AbstractCondition::parameter(), DinverCore::Parameter::realValue(), and TRACE.
Referenced by adjustRanges().
{ TRACE; double threshold; switch (paramIndex) { case 0: threshold=_factor * parameter(1).realValue() + _constant; switch (_type) { case LessThan: if(threshold < max) { max=threshold; } break; case GreaterThan: if(threshold > min) { min=threshold; } break; case NoCondition: break; } break; default: threshold=parameter(0).realValue() - _constant; switch (_type) { case LessThan: if(threshold > _factor * min) { if(_factor==1.0) min=threshold; else min=threshold/_factor; } break; case GreaterThan: if(threshold < _factor * max) { if(_factor==1.0) max=threshold; else max=threshold/_factor; } break; case NoCondition: break; } break; } }
void DinverCore::SimpleCondition::humanInfo | ( | ) | const [virtual] |
Print human readable information about condition to stream.
Implements DinverCore::AbstractCondition.
References LessThan, DinverCore::Parameter::name(), DinverCore::AbstractCondition::parameter(), and TRACE.
{ TRACE; App::stream() << " " << parameter(0).name() << " " << (_type==LessThan ? "<" : ">" ) << " "; if(_factor!=1.0) App::stream() << _factor << "*"; App::stream() << parameter(1).name(); if(_constant > 0) App::stream() << "+" << _constant; else if(_constant < 0) App::stream() << _constant; App::stream() << "\n"; }
uint DinverCore::SimpleCondition::internalChecksum | ( | ) | const [protected, virtual] |
Return a number that uniquely identify this condition
Implements DinverCore::AbstractCondition.
References DinverCore::qHash(), and TRACE.
bool DinverCore::SimpleCondition::operator== | ( | const AbstractCondition & | o | ) | const [virtual] |
Reimplemented from DinverCore::AbstractCondition.
References TRACE, DinverCore::AbstractCondition::xml_tagName(), and xml_tagName().
{ TRACE; if(xml_tagName()==o.xml_tagName()) { const SimpleCondition& sc=static_cast<const SimpleCondition&>(o); return _type==sc._type && _factor==sc._factor && _constant==sc._constant && AbstractCondition::operator==(o); } else return false; }
QString DinverCore::SimpleCondition::toString | ( | Type | t | ) | [static] |
References GreaterThan, LessThan, and NoCondition.
Referenced by xml_writeProperties().
{ switch(t) { case LessThan: break; case GreaterThan: return "GreaterThan"; case NoCondition: return "NoCondition"; } return "LessThan"; }
XMLMember DinverCore::SimpleCondition::xml_member | ( | XML_MEMBER_ARGS | ) | [protected, virtual] |
Re-implement this function to offer XML restore (children and properties) support to your class.
From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:
Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):
static const QString tmp("childrenName"); XMLRestoreAttributeIterator it=map.find(tmp); if(it!=map.end()) { // found attribute "childrenName" }
If the map of attributes is not used:
Q_UNUSED(attributes); if(tag=="x1") return XMLMember(0); else if(tag=="y1") return XMLMember(1); else if(tag=="x2") return XMLMember(2); else if(tag=="y2") return XMLMember(3); else return XMLMember(XMLMember::Unknown);
Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.
if(tag=="anInteger") return XMLMember(0); else if(tag=="aString") return XMLMember(1); else if(tag=="aDouble") return XMLMember(2); return AbstractLine::xml_member(tag, attributes, context)+3;
For the arguments of this function use Macro XML_MEMBER_ARGS.
Reimplemented from DinverCore::AbstractCondition.
References TRACE.
{ TRACE; if(tag=="factor" ) return XMLMember(0); else if(tag=="constant" ) return XMLMember(1); else if(tag=="type" ) return XMLMember(2); else return SimpleCondition::xml_member(tag, attributes, context)+3; }
bool DinverCore::SimpleCondition::xml_setProperty | ( | XML_SETPROPERTY_ARGS | ) | [protected, virtual] |
Re-implement this function to offer XML restore properties support to your class.
From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).
For a general case:
Q_UNUSED(attributes); double val=content.toDouble(); switch (memberID) { case 0: _x1=val; return true; case 1: _y1=val; return true; case 2: _x2=val; return true; case 3: _y2=val; return true; default: return false; }
For classes inheriting other classes (see also xml_member())
switch (memberID) { case 0: _anInteger=content.toString(); return true; case 1: _aString=content.toInt(); return true; case 2: _aDouble=content.toDouble(); return true; default: return AbstractLine::xml_setProperty(memberID-3, map, content);
For the arguments of this function use Macro XML_SETPROPERTY_ARGS.
Reimplemented from DinverCore::AbstractCondition.
References fromString(), and TRACE.
{ TRACE; switch (memberID) { case 0: _factor=content.toDouble(); return true; case 1: _constant=content.toDouble(); return true; case 2: { bool ok=true; _type=fromString(content.toString(), ok); return ok; } default: return AbstractCondition::xml_setProperty(memberID-3, tag, attributes, content, context); } }
virtual const QString& DinverCore::SimpleCondition::xml_tagName | ( | ) | const [inline, virtual] |
Reimplemented from DinverCore::AbstractCondition.
Referenced by operator==().
{return xmlSimpleConditionTag;}
void DinverCore::SimpleCondition::xml_writeProperties | ( | XML_WRITEPROPERTIES_ARGS | ) | const [protected, virtual] |
Reimplemented from DinverCore::AbstractCondition.
References toString(), TRACE, and QGpCoreTools::XMLClass::writeProperty().
{ TRACE; Q_UNUSED(context); writeProperty(s, "type", toString(_type)); writeProperty(s, "factor", _factor); writeProperty(s, "constant", _constant); }
const QString DinverCore::SimpleCondition::xmlSimpleConditionTag = "SimpleCondition" [static] |