Accounting Software
Small Business Software Estimating Software
Construction Estimating SoftwareBookkeeping SoftwareInventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareBusiness Management Software

Calculated Dimensions Viewer
(Source Code)

Link to: header | record viewer directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

CCalcDimensionViewer and CCalcLocationViewer

This class manages calculated estimating dimensions for the Goldenseal accounting software,
small business management software, construction project management software and
construction estimating software.

It's a viewer for the calculated dimension list. These provide most of the unit
cost quantities in the Goldenseal estimating software.

SUPERCLASS = DB_RecordViewer

Constructor

/*********************************************************************************
constructor
*********************************************************************************/
CCalcLocationViewer::CCalcLocationViewer(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: DB_RecordViewer(inPaneInfo, inViewInfo)
{
mDimensionType = 0;
}

Source Code

/*********************************************************************************

GetReadyToUpdateFields TCS 8/23/01

get ready to update the fields from the object. We need to prep our cv
fields

*********************************************************************************/
void CCalcLocationViewer::GetReadyToUpdateFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
TCS_FailNILMsg(viewerObject, TCS_GetErrString(errID_BadObject));

UInt8 calcMenuValue, calcClass;
DBid calculatorID = 0;

// set up the starting dimension cv field rev TCS 10/25/01
if (viewerObject->GetMemberValue(tag_startdimensiontype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_startdimension, calcClass);
}

// check the first calculator and store the dimension type
viewerObject->GetMemberValue(tag_startdimension, type_objectid, &calculatorID);
SetDimensionType(calcClass, calculatorID);

// prepare menus in the adjuster popups
PrepAdjusterPopups();

// set up each of the adjuster cv fields rev TCS 10/25/01
if (viewerObject->GetMemberValue(tag_firstadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_firstadjuster, calcClass);
}
if (viewerObject->GetMemberValue(tag_secondadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_secondadjuster, calcClass);
}
if (viewerObject->GetMemberValue(tag_thirdadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_thirdadjuster, calcClass);
}
if (viewerObject->GetMemberValue(tag_fourthadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_fourthadjuster, calcClass);
}
if (viewerObject->GetMemberValue(tag_fifthadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_fifthadjuster, calcClass);
}
if (viewerObject->GetMemberValue(tag_sixthadjusttype, type_enum, &calcMenuValue))
{
calcClass = CCalcLocation::GetCalculatorClassID(calcMenuValue, IsCalcLocation());
SetCVClassID(tag_sixthadjuster, calcClass);
}

if (viewerObject->GetMemberValue(tag_usedbyclass, type_enum, &calcMenuValue)) // TCS 9/2/02
{
SetCVClassID(tag_usedby, calcClass);
}


// inherited method does the usual
THE_SUPERCLASS::GetReadyToUpdateFields(creationMethod, viewerObject);
}
/*********************************************************************************

FinishUpdatingFields split TCS 4/17/00

Finish prep work after updating fields from an object, but before displaying them

*********************************************************************************/
void CCalcLocationViewer::FinishUpdatingFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
// the superclass handles basic field updating
THE_SUPERCLASS::FinishUpdatingFields(creationMethod, viewerObject);

// set up formats for the popup menus
FinishAdjusterPopupPrep();

// set up menus and visibility for calc fields
UInt8 startDimensionType = GetPopupValue(tag_startdimensiontype);
SetupMenu(tag_startdimension, startDimensionType); // rev TCS 5/9/01

SetupMenu(tag_firstadjuster, GetPopupValue(tag_firstadjusttype));
SetupCalcDisplay(tag_firstadjuster, tag_firstadjustamount, GetPopupValue(tag_firstadjusttype));

SetupMenu(tag_secondadjuster, GetPopupValue(tag_secondadjusttype));
SetupCalcDisplay(tag_secondadjuster, tag_secondadjustamount, GetPopupValue(tag_secondadjusttype));

SetupMenu(tag_thirdadjuster, GetPopupValue(tag_thirdadjusttype));
SetupCalcDisplay(tag_thirdadjuster, tag_thirdadjustamount, GetPopupValue(tag_thirdadjusttype));

SetupMenu(tag_fourthadjuster, GetPopupValue(tag_fourthadjusttype)); // TCS 8/24/01
SetupCalcDisplay(tag_fourthadjuster, tag_fourthadjustamount, GetPopupValue(tag_fourthadjusttype));

SetupMenu(tag_fifthadjuster, GetPopupValue(tag_fifthadjusttype)); // TCS 12/14/01
SetupCalcDisplay(tag_fifthadjuster, tag_fifthadjustamount, GetPopupValue(tag_fifthadjusttype));

SetupMenu(tag_sixthadjuster, GetPopupValue(tag_sixthadjusttype));
SetupCalcDisplay(tag_sixthadjuster, tag_sixthadjustamount, GetPopupValue(tag_sixthadjusttype));
}

#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

HandleCVChanged

a cv field has changed, act accordingly. We need to check for
circular references.

*********************************************************************************/
void CCalcLocationViewer::HandleCVChanged(CTCS_CVField *cvField)
{
TCS_FailNILMsg(cvField, TCS_GetErrString(errID_BadClairvoyant));

switch (cvField->GetPaneID())
{
case tag_startdimension:
{
UInt8 priorDimensionType = mDimensionType; // TCS 12/4/01
CheckCircularity(tag_startdimensiontype, tag_startdimension);
SetDimensionType(GetPopupValue(tag_startdimensiontype), cvField->GetValue());
PrepAdjusterPopups(true);
FinishAdjusterPopupPrep(priorDimensionType);
}
break;

case tag_firstadjuster:
CheckCircularity(tag_firstadjusttype, tag_firstadjuster);
break;

case tag_secondadjuster:
CheckCircularity(tag_secondadjusttype, tag_secondadjuster);
break;

case tag_thirdadjuster:
CheckCircularity(tag_thirdadjusttype, tag_thirdadjuster);
break;

case tag_fourthadjuster: // TCS 8/24/01
CheckCircularity(tag_fourthadjusttype, tag_fourthadjuster);
break;

case tag_fifthadjuster: // TCS 12/14/01
CheckCircularity(tag_fifthadjusttype, tag_fifthadjuster);
break;

case tag_sixthadjuster: // TCS 12/14/01
CheckCircularity(tag_sixthadjusttype, tag_sixthadjuster);
break;

default:
break;
}

THE_SUPERCLASS::HandleCVChanged(cvField);
}
/*********************************************************************************

HandlePopupChanged

a popup menu has been clicked, act accordingly

*********************************************************************************/
void CCalcLocationViewer::HandlePopupChanged(CTCS_StdPopupMenu *popupMenu)
{
UInt8 value = popupMenu->GetValue();
TCS_FailNILMsg(popupMenu, TCS_GetErrString(errID_BadPopup));
switch (popupMenu->GetPaneID())
{
case tag_startdimensiontype: // TCS 5/9/01
{
SetupMenu(tag_startdimension, value, true);
UInt8 priorDimensionType = mDimensionType; // TCS 12/4/01

// clear out any setup for checkboxes or lists TCS 11/7/01
mDimensionType = dimension_number;
PrepAdjusterPopups(true);
FinishAdjusterPopupPrep(priorDimensionType);
}
break;

case tag_firstadjusttype:
SetupMenu(tag_firstadjuster, value, true);
SetupCalcDisplay(tag_firstadjuster, tag_firstadjustamount, value);
break;

case tag_secondadjusttype:
SetupMenu(tag_secondadjuster, value, true);
SetupCalcDisplay(tag_secondadjuster, tag_secondadjustamount, value);
break;

case tag_thirdadjusttype:
SetupMenu(tag_thirdadjuster, value, true);
SetupCalcDisplay(tag_thirdadjuster, tag_thirdadjustamount, value);
break;

case tag_fourthadjusttype: // TCS 8/24/01
SetupMenu(tag_fourthadjuster, value, true);
SetupCalcDisplay(tag_fourthadjuster, tag_fourthadjustamount, value);
break;

case tag_fifthadjusttype: // TCS 12/14/01
SetupMenu(tag_fifthadjuster, value, true);
SetupCalcDisplay(tag_fifthadjuster, tag_fifthadjustamount, value);
break;

case tag_sixthadjusttype: // TCS 12/14/01
SetupMenu(tag_sixthadjuster, value, true);
SetupCalcDisplay(tag_sixthadjuster, tag_sixthadjustamount, value);
break;

default:
break;
}

THE_SUPERCLASS::HandlePopupChanged(popupMenu);
}
/*********************************************************************************

HandleDBButtonClicked TCS 9/30/02

a button in the layout was clicked.

*********************************************************************************/
void CCalcLocationViewer::HandleDBButtonClicked(const TagType btnID)
{
switch (btnID)
{
case button_calcreport:
case button_usereport:
{
CCalcLocation *dimension = TCS_SAFE_CAST(mCurrViewerObject, CCalcLocation);
TCS_FailNILMsg(dimension, TCS_GetErrString(errID_BadObject));

SInt32 useCount = dimension->GetDependentCount();
CTextString msgString;

if (btnID == button_usereport)
{
msgString = TCS_GetMsgString(msgID_CalculatorUseCount);
msgString.ReplaceStdTokens(dimension->GetDependentCount());
msgString.SetSingular(useCount == 1);
}
else // TCS 3/11/03
{
msgString = TCS_GetMsgString(msgID_CalculatorReport);
}

if (!TCS_OKCancelDialog(msgString))
return;

// make a report of the dimensions this depends on
TCS_StdFileReply chosenFile = TCS_SaveFileDialog(TCS_GetStockString(stockID_SaveCalcReport));
if (!chosenFile.sfGood)
return;
if (chosenFile.sfReplacing)
{
if (TCS_DeleteFile(&chosenFile.sfFile) != noErr)
{
TCS_InfoAlert(TCS_GetMsgString(msgID_FileInUse));
return;
}
}

// create the file
TCS_CreateDataFile(&chosenFile.sfFile, file_TextCreator, file_TextFileType, chosenFile.sfScript);

// Set up the stream
CFileContainer buffer;
UInt8 fileFormat = DB_PersistentObject::GetPrefsEnum(id_FilePrefs, tag_exportformat);
CTextOutputStream stream(&buffer, fileFormat);

// Fill the stream with data. The object can handle that
if (buffer.SetFile(chosenFile.sfFile))
{
DBid estID = DB_ListManager::GetCurrentRecordID(id_Estimate);
CEstimate *estimate =
TCS_SAFE_CAST(gDBFile->GetOneObject(id_Estimate, estID), CEstimate);

if (estimate) // TCS 1/26/04
{
DB_ObjectWatcher watcher (estimate);

SInt32 counter = 0;

if (btnID == button_calcreport)
mCurrViewerObject->FillCalculationReport(stream, estimate, 0, counter);
else
mCurrViewerObject->FillUseReport(stream, estimate, 0, counter); // TCS 1/8/03
}
}
}
break;

default:
THE_SUPERCLASS::HandleDBButtonClicked(btnID);
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

SetDimensionType TCS 11/7/01

store the dimension type, which we fetch from the starting calculator

*********************************************************************************/
void CCalcLocationViewer::SetDimensionType(const DBClass calcClass, const DBid calcID)
{
if (calcClass == id_Dimension || calcClass == id_LocationDimension)
{
CDimension *dimension = TCS_SAFE_CAST(gDBFile->GetOneObject(calcClass, calcID),
CDimension);
if (dimension)
{
DB_ObjectWatcher watcher(dimension);
mDimensionType = dimension->GetDimensionType();
return;
}
}

// if no starting dimension, it must be just a number
mDimensionType = dimension_number;
}
/*********************************************************************************

PrepAdjusterPopups TCS 11/7/01

prepare the popup menus for the 6 adjuster popups. We use different menus
if the basic dimension is a list or checkbox

*********************************************************************************/
void CCalcLocationViewer::PrepAdjusterPopups(const Boolean /*resetValues*/)
{
if (mDimensionType == dimension_checkbox)
{
SetPopupMenuID(tag_firstadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_secondadjusttype, MENU_CalcDimensionLists);

SetPopupMenuID(tag_thirdadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_fourthadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_fifthadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_sixthadjusttype, MENU_CalcDimensionMathTypes);
}
else if (mDimensionType == dimension_list)
{
SetPopupMenuID(tag_firstadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_secondadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_thirdadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_fourthadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_fifthadjusttype, MENU_CalcDimensionLists);
SetPopupMenuID(tag_sixthadjusttype, MENU_CalcDimensionLists);
}
else
{
SetPopupMenuID(tag_firstadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_secondadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_thirdadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_fourthadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_fifthadjusttype, MENU_CalcDimensionMathTypes);
SetPopupMenuID(tag_sixthadjusttype, MENU_CalcDimensionMathTypes);
}
}
/*********************************************************************************

FinishAdjusterPopupPrep TCS 11/7/01

finish set up popup for the 6 adjuster popups. We handle enablement here.

*********************************************************************************/
void CCalcLocationViewer::FinishAdjusterPopupPrep(const UInt8 priorDimensionType)
{
Boolean needsUpdate = priorDimensionType && priorDimensionType != mDimensionType; // TCS 12/4/01

if (mDimensionType == dimension_checkbox)
{
SetFieldEnabled(tag_thirdadjusttype, false);
SetFieldEnabled(tag_fourthadjusttype, false);
SetFieldEnabled(tag_fifthadjusttype, false);
SetFieldEnabled(tag_sixthadjusttype, false);

if (needsUpdate)
{
SetPopupValue(tag_firstadjusttype, calc_listconstant);
SetPopupValue(tag_secondadjusttype, calc_listconstant);
SetPopupValue(tag_thirdadjusttype, calc_none);
SetPopupValue(tag_fourthadjusttype, calc_none);
SetPopupValue(tag_fifthadjusttype, calc_none);
SetPopupValue(tag_sixthadjusttype, calc_none);
}
}
else if (mDimensionType == dimension_list)
{
SetFieldEnabled(tag_thirdadjusttype, true);
SetFieldEnabled(tag_fourthadjusttype, true);
SetFieldEnabled(tag_fifthadjusttype, true);
SetFieldEnabled(tag_sixthadjusttype, true);

if (needsUpdate)
{
SetPopupValue(tag_firstadjusttype, calc_listconstant);
SetPopupValue(tag_secondadjusttype, calc_listconstant);
SetPopupValue(tag_thirdadjusttype, calc_listconstant);
SetPopupValue(tag_fourthadjusttype, calc_listconstant);
SetPopupValue(tag_fifthadjusttype, calc_listconstant);
SetPopupValue(tag_sixthadjusttype, calc_listconstant);
}
}
else
{
SetFieldEnabled(tag_thirdadjusttype, true);
SetFieldEnabled(tag_fourthadjusttype, true);
SetFieldEnabled(tag_fifthadjusttype, true);
SetFieldEnabled(tag_sixthadjusttype, true);

if (needsUpdate)
{
SetPopupValue(tag_firstadjusttype, calc_none);
SetPopupValue(tag_secondadjusttype, calc_none);
SetPopupValue(tag_thirdadjusttype, calc_none);
SetPopupValue(tag_fourthadjusttype, calc_none);
SetPopupValue(tag_fifthadjusttype, calc_none); // bugfix TCS 3/25/02
SetPopupValue(tag_sixthadjusttype, calc_none);
}
}

// we may also need to reset display of cv's and value fields
if (needsUpdate)
{
SetupCalcDisplay(tag_firstadjuster, tag_firstadjustamount, GetPopupValue(tag_firstadjusttype));
SetupCalcDisplay(tag_secondadjuster, tag_secondadjustamount, GetPopupValue(tag_secondadjusttype));
SetupCalcDisplay(tag_thirdadjuster, tag_thirdadjustamount, GetPopupValue(tag_thirdadjusttype));
SetupCalcDisplay(tag_fourthadjuster, tag_fourthadjustamount, GetPopupValue(tag_fourthadjusttype));
SetupCalcDisplay(tag_fifthadjuster, tag_fifthadjustamount, GetPopupValue(tag_fifthadjusttype));
SetupCalcDisplay(tag_sixthadjuster, tag_sixthadjustamount, GetPopupValue(tag_sixthadjusttype));
}
}
/*********************************************************************************

SetupMenu rev TCS 11/7/01

set up the menu for a cv field

*********************************************************************************/
void CCalcLocationViewer::SetupMenu(const TagType fieldTag, const UInt8 inValue,
const Boolean fieldChanged)
{
// first get the clairvoyant
TCS_FailNILMsg(fieldTag, TCS_GetErrString(errID_BadTag));
DB_Clairvoyant *cvField = TCS_SAFE_CAST(FindPaneByID(fieldTag), DB_Clairvoyant);
TCS_FailNILMsg(cvField, TCS_GetErrString(errID_BadClairvoyant));

UInt8 calcClass = CCalcLocation::GetCalculatorClassID(inValue, IsCalcLocation());

cvField->SetDisplayClassID(calcClass);

if (fieldChanged)
cvField->SetValue(0);
}
/*********************************************************************************

SetupCalcDisplay

set up the calculator display for an adjuster amount and adjuster fields

*********************************************************************************/
void CCalcLocationViewer::SetupCalcDisplay(const TagType calcTag, const TagType adjTag,
const UInt8 inValue)
{
switch (inValue)
{
case calc_add: // show a constant field
case calc_subtract:
case calc_multiply:
case calc_divide:
case calc_greaterof:
case calc_lesserof:
case calc_listconstant:
SetFieldVisible(adjTag, true);
SetCVFieldVisible(calcTag, false);
break;

case calc_adddimension: // show a cv field for dimensions
case calc_subtractdimension:
case calc_multiplydimension:
case calc_dividedimension:
case calc_greaterofdimension: // TCS 5/9/01
case calc_lesserofdimension:
case calc_listdimension:

case calc_addcalcdimension: // show a cv field for calc dimensions
case calc_subtractcalcdimension:
case calc_multiplycalcdimension:
case calc_dividecalcdimension:
case calc_greaterofcalcdimension:
case calc_lesserofcalcdimension: // TCS 5/9/01
case calc_listcalculation:
SetFieldVisible(adjTag, false); // reversed TCS 11/7/01
SetCVFieldVisible(calcTag, true);
break;

case calc_addlocationcount: // show no fields at all
case calc_subtractlocationcount:
case calc_multiplylocationcount:
case calc_dividelocationcount:
case calc_maxoflocationcount:
case calc_minoflocationcount:
case calc_squarerootof: // TCS 12/3/01
case calc_absolutevalue:
case calc_none:
case calc_projectcost: // 12/14/01
SetFieldVisible(adjTag, false);
SetCVFieldVisible(calcTag, false);
break;

default:
TCS_DebugAlert("Oops, invalid calc dimension type in SetupCalcDisplay!");
break;
}
}

#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
CheckCircularity TCS 3/8/01

check for circular refs in the given calculated dimension field

*********************************************************************************/
void CCalcLocationViewer::CheckCircularity(const TagType classTag, const TagType itemTag)
{
// sanity check
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));

// fetch field values
UInt8 calcClass = CCalcDimension::GetCalculatorClassID(GetPopupValue(classTag), IsCalcLocation());

if (calcClass != id_Dimension && calcClass != id_CalcDimension &&
calcClass != id_LocationDimension && calcClass != id_CalcLocation)
return;

DBid calcID = GetFieldValue(itemTag);
DBClass thisClass = mCurrViewerObject->GetDBClassID();
DBid thisID = mCurrViewerObject->GetDBID();

if (CCalcLocation::HasCircularReference(calcClass, calcID, thisClass, thisID)) // rev TCS 5/21/03
{
TCS_ErrorAlert(TCS_GetErrString(errID_CircularRef));
SetFieldValue(itemTag, 0);
}

// tidy up memory // TCS 11/25/03
gDBFile->ForcePurge();
}