// $Id: RepGenSlot.cpp,v 1.15 2010/11/11 01:47:57 philw Exp $ // // class RepGenSlot // // concrete subclasses: // class RepGenSlotHtml : public RepGenSlot // class RepGenSlotText : public RepGenSlot // //-- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- static const char* HeaderBackgroundColor ("#d8d8d8"); static const int MAX_SLOT_DATA_ROWS (300); #ifndef RepGenSlotINCLUDED #include "RepGenSlot.hpp" #endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- #ifndef RwModelReportINCLUDED #include "RwModelReport.hpp" #endif #ifndef RepGenUtilsINCLUDED #include "RepGenUtils.hpp" #endif #ifndef cwfstreamINCLUDED #include "cwfstream.hpp" #endif #ifndef SlotINCLUDED #include "Slot.hpp" #endif #ifndef SeriesSlotINCLUDED #include "SeriesSlot.hpp" #endif #ifndef ListSlotINCLUDED #include "ListSlot.hpp" #endif #ifndef SlotColRefINCLUDED #include "SlotColRef.hpp" #endif #ifndef SimObjINCLUDED #include "SimObj.hpp" #endif #ifndef SlotGUIUtilsINCLUDED #include "SlotGUIUtils.hpp" #endif #include "rwStr.hpp" #include //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // constructor 1 of 1 RepGenSlot::RepGenSlot (RwModelReport* rep, const Slot* slotPtr) : _modelReport (rep), _slot (slotPtr) { } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- RepGenSlot::~RepGenSlot() { _modelReport = NULL; _slot = NULL; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // public bool RepGenSlot::slotDetailSupported() const { if (_slot == NULL) return (false); //------------------------------>> // **************************************************************** // *** Currently Implemented Support for Slot Detail Sections *** // **************************************************************** if (SlotGUIUtils::isScalarLikeSlot (_slot)) return (false); if (SlotGUIUtils::hasSeries (_slot)) return (false); //------------------------------------------------------->> return (true); // Just for now. } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // public void RepGenSlot::writeSlotDetail (cwofstream& os) { writeSlotDetailTitleSection (os); writeSlotDataTable (os); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // ***************************** // *** HTML Slot Utilities *** // ***************************** QString RepGenSlot::slotTypStr (bool verbose /*=false*/) const { if (_slot) { if (verbose) { const IconHandle slotIcon (_slot); const QString longTyp (slotIcon.iconDescStr()); return longTyp; //-------------------->> } const QString slotType = _slot->getType(); return slotType; //--------------------->> } return QString(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotTypStrTerse() const { if (_slot) { const QString slotType = _slot->getType(); QString retStr (slotType); // Remove the text, "Slot" retStr.remove ("Slot"); return (retStr); //------------>> } return (""); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotNameStr() const { if (_slot) { const QString slotName = _slot->getName(); return slotName; //--------------------->> } return QString(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotValStr() const { QString retStr (""); if (_slot && SlotGUIUtils::isScalarLikeSlot (_slot)) { const SlotColRef sref (const_cast (_slot)); Date_Time dummyDt; const double userVal = sref.getUserPrimValue (dummyDt); retStr = sref.formatUserPrimValue (userVal, true, // showNaN false); // forEdit } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotUnitsStr (bool withBrackets) const { QString retStr (""); if (_slot && SlotGUIUtils::singleUnitType (_slot, (-1))) { const ScaledUnitPtr suPtr = SlotGUIUtils::getScaledUnitPtr (_slot, 0); if (suPtr) { const double scale = suPtr->getScale(); const QString unitStr = suPtr->getUsrUnit(); if (scale == 1.0) { retStr = QString (withBrackets ? "[%1]" : "%1") .arg (qPrintable(unitStr)); } else { retStr = QString (withBrackets ? "[%1 %2]" : "%1 %2") .arg (scale) .arg (qPrintable(unitStr)); } } } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotRowsStr() const { const int rowCnt = SlotGUIUtils::getNumSlotRows (_slot); const QString retStr = QString::number (rowCnt); return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotColsStr() const { const int colCnt = SlotGUIUtils::getNumCols (_slot); const QString retStr = QString::number (colCnt); return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::slotLabelsStr() const { QString retStr (""); int labsAdded (0); if (_slot && SlotGUIUtils::supportsMultipleColumns (_slot)) { int labelColCnt = SlotGUIUtils::getNumCols (_slot); if (SlotGUIUtils::supportsBlocks (_slot)) { const int blockSize = SlotGUIUtils::getBlockSize (_slot); labelColCnt = std::max (labelColCnt, blockSize); } for (int col = 0; col < labelColCnt; ++col) { const QString colLabStr = SlotGUIUtils::getColLabel (_slot, col); if (colLabStr.isEmpty()) continue; //------------------------------- if (retStr.size() + colLabStr.length() > 44) { retStr += ",..."; break; //-------- } if (labsAdded > 0) retStr += ", "; retStr += colLabStr; ++labsAdded; } } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::seriesStepStr() const { QString retStr (""); // tentative if (_slot && SlotGUIUtils::hasSeries (_slot)) { const Date_Time* startDT (SlotGUIUtils::getSlotStartDate (_slot)); if (startDT != NULL) { const DeltaTime stepSize = SlotGUIUtils::getStep (_slot); const QString unitsStr (stepSize.singleUnitsAsString()); const int unitMultiple (stepSize.time()); if (unitMultiple > 0) retStr = QString ("%1 %2") .arg (unitMultiple) .arg (unitsStr); } } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::seriesStartStr() const { QString retStr (""); // tentative if (_slot && SlotGUIUtils::hasSeries (_slot)) { const Date_Time* startDT (SlotGUIUtils::getSlotStartDate (_slot)); if (startDT != NULL) { const DeltaTime stepSize = SlotGUIUtils::getStep (_slot); retStr = QString (startDT->shortAsciiAbbrev (stepSize)); } } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::seriesEndStr() const { QString retStr (""); // tentative if (_slot && SlotGUIUtils::hasSeries (_slot)) { const Date_Time* endDT (SlotGUIUtils::getSlotEndDate (_slot)); if (endDT != NULL) { const DeltaTime stepSize = SlotGUIUtils::getStep (_slot); retStr = QString (endDT->shortAsciiAbbrev (stepSize)); } } return (retStr); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::objTypStr() const { const SimObj* simObj = (_slot ? _slot->getSimObj() : NULL); if (simObj) { const QString objType = simObj->getType(); return objType; //-------------------->> } return QString(); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- QString RepGenSlot::objNameStr() const { const SimObj* simObj = (_slot ? _slot->getSimObj() : NULL); if (simObj) { const QString objName = simObj->getCompleteName(); return objName; //-------------------->> } return QString(); } //--- (end RepGenSlot.cpp) ---