Link to: header | unit cost
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCalcDimension
This class manages calculated estimating dimensions in the Goldenseal accounting software,
estimating software, project management software
and construction estimating software.
Each item is a dimension calculated from other dimensions. It is used for one of the
'padlocked' fields in a dimension layout in an estimate. Its value can come
from other dimension fields, or by summing or otherwise calculating location values.
This class provides many of the quantities for Goldenseal estimating software,
especially for construction companies and other that need to use complex measurements.
SUPERCLASS = CCalcLocation
Constructor
/*********************************************************************************
default constructor
*********************************************************************************/
CCalcDimension::CCalcDimension()
{
mStartDimensionType = id_Dimension;
}
Source Code
/*********************************************************************************
GetMemberValue
return the value of the member with the given tag
*********************************************************************************/
Boolean CCalcDimension::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
case tag_startdimensiontype:
return ConvertEnumMember(mStartDimensionType, MENU_CalcDimensionStart, aValue, aType);
break;
default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}
/*********************************************************************************
GetCalcDimensionValue TCS 6/6/01 rev 10/18/01 moved 11/3/01
get the calculated value of this dimension
*********************************************************************************/
CMoney CCalcDimension::GetCalcDimensionValue(TDimensionArray &dimensionArray,
TDimensionArray &locDimensionArray)
{
TagType thisTag = CCalculatorList::GetCalculatorTag(GetDBClassID(), GetDBID());
DBClass calcClass = GetCalculatorClassID(mStartDimensionType, IsCalcLocation());
SDimensionInfo info = CEstimate::GetDimensionInfo(thisTag, dimensionArray);
if (!info.locked)
{
// this field is unlocked, so we just fetch the current stored value
mCurrentValue = info.value;
}
else if (!info.dirty)
{
// this field is not dirty- presumably it's been recalculated already TCS 2/27/02
mCurrentValue = info.value;
}
else if (mStartDimensionType == calc_projectcost)
{
// it's the overall project cost. We'll need to fetch that from
// the estimate somehow. %%%%%%%%%%%%%%%%%%%%%%%%%%
}
else
{
// this field is locked and dirty. We need to calculate its current value
CMoney total = 0,
itemAmount = 0;
UInt8 dimensionType = dimension_number; // TCS 1/1/02
DB_PersistentObject *calculator = nil;
if (calcClass == id_LocationDimension || calcClass == id_CalcLocation)
{
// it's sum/min/max of location values TCS 1/2/02
total = GetLocationsTotal(locDimensionArray, mStartDimensionType, mStartDimension);
}
else
{
// look at the starting dimension
calculator = gDBFile->GetOneObject(calcClass, mStartDimension);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
total = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
dimensionType = calculator->GetDimensionType();
}
else
ReportMissingObject(calcClass, mStartDimension, GetDBClassID(), GetDBID());
}
if (dimensionType == dimension_list) // TCS 1/1/02
{
SInt32 choice = total.GetIntegerValue();
total = GetListDimensionValue(choice, dimensionArray, locDimensionArray);
}
else if (dimensionType == dimension_checkbox) // TCS 1/1/02
{
if (total.IsPositive())
total = GetListDimensionValue(1, dimensionArray, locDimensionArray); // true
else
total = GetListDimensionValue(2, dimensionArray, locDimensionArray); // false
}
else
{
// apply the first adjuster
calcClass = GetCalculatorClassID(mFirstAdjustType, IsCalcLocation());
if (calcClass)
{
DB_PersistentObject *calculator = gDBFile->GetOneObject(calcClass, mFirstAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mFirstAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mFirstAdjustType, mFirstAdjustAmount, itemAmount, total); // rev TCS 6/20/01
// apply the second adjuster
calcClass = GetCalculatorClassID(mSecondAdjustType, IsCalcLocation());
if (calcClass)
{
calculator = gDBFile->GetOneObject(calcClass, mSecondAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mSecondAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mSecondAdjustType, mSecondAdjustAmount, itemAmount, total); // rev TCS 6/20/01
// apply the third adjuster
calcClass = GetCalculatorClassID(mThirdAdjustType, IsCalcLocation());
if (calcClass)
{
calculator = gDBFile->GetOneObject(calcClass, mThirdAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mThirdAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mThirdAdjustType, mThirdAdjustAmount, itemAmount, total); // rev TCS 6/20/01
// apply the fourth adjuster
calcClass = GetCalculatorClassID(mFourthAdjustType, IsCalcLocation());
if (calcClass)
{
calculator = gDBFile->GetOneObject(calcClass, mFourthAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mFourthAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mFourthAdjustType, mFourthAdjustAmount, itemAmount, total); // rev TCS 6/20/01
// apply the fifth adjuster TCS 1/1/02
calcClass = GetCalculatorClassID(mFifthAdjustType, IsCalcLocation());
if (calcClass)
{
calculator = gDBFile->GetOneObject(calcClass, mFifthAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mFifthAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mFifthAdjustType, mFifthAdjustAmount, itemAmount, total);
// apply the sixth adjuster TCS 1/1/02
calcClass = GetCalculatorClassID(mSixthAdjustType, IsCalcLocation());
if (calcClass)
{
calculator = gDBFile->GetOneObject(calcClass, mSixthAdjuster);
if (calculator)
{
DB_ObjectWatcher watcher(calculator);
itemAmount = calculator->GetCalcDimensionValue(dimensionArray, locDimensionArray);
}
else
{
ReportMissingObject(calcClass, mSixthAdjuster, GetDBClassID(), GetDBID());
itemAmount = 0;
}
}
total = ApplyAdjuster(mSixthAdjustType, mSixthAdjustAmount, itemAmount, total);
}
// apply rounding TCS 7/2/01
total = total.GetRoundedValue(mRoundingType);
// store the value here
mCurrentValue = total;
// store this value in the array, which also sets the dirty bit there
// so this calculator will not be calculated again TCS 2/27/02
CEstimate::SetDimensionValue(thisTag, mCurrentValue, info.locked, dimensionArray);
}
return mCurrentValue;
}
/*********************************************************************************
GetLocationsTotal TCS 1/2/02
fetch min, max or sum from the locations array
*********************************************************************************/
CMoney CCalcDimension::GetLocationsTotal(TDimensionArray &locDimensionArray, const UInt8 calcType,
const DBid calcID) const
{
DBClass calcClass = GetCalculatorClassID(calcType, IsCalcLocation());
TagType searchTag = CCalculatorList::GetCalculatorTag(calcClass, calcID);
TDimensionArrayIterator iterator (locDimensionArray);
SDimensionInfo info;
CMoney outValue = 0;
while (iterator.Next(info))
{
if (info.tag == searchTag)
{
switch (calcType)
{
case calc_sumoflocations:
case calc_sumofcalclocations:
outValue += info.value;
break;
case calc_maxoflocations:
case calc_maxofcalclocations:
outValue = TCS_MAX(outValue, info.value);
break;
case calc_minoflocations:
case calc_minofcalclocations:
if (outValue.IsZero())
outValue = info.value;
else
outValue = TCS_MIN(outValue, info.value);
break;
default:
TCS_DebugAlert("Oops, bad case in CCalcDimension::GetLocationsTotal!");
return 0;
break;
}
}
}
return outValue;
}
|