Skip to content

Commit

Permalink
Merge pull request #715 from openstudiocoalition/612_displayName
Browse files Browse the repository at this point in the history
#612 - Display Name
  • Loading branch information
jmarrec authored Jul 15, 2024
2 parents 203fd59 + 3289bee commit 43dd06b
Show file tree
Hide file tree
Showing 80 changed files with 2,062 additions and 1,350 deletions.
62 changes: 62 additions & 0 deletions src/model_editor/InspectorGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <openstudio/model/Model.hpp>
#include <openstudio/model/ParentObject.hpp>
#include <openstudio/model/ParentObject_Impl.hpp>
#include <openstudio/model/AdditionalProperties.hpp>

#include "../model_editor/Utilities.hpp"

Expand All @@ -58,6 +59,7 @@

#include <iostream>
#include <limits>
#include <utilities/idd/IddEnums.hpp>
#include <vector>

#include <QDoubleValidator>
Expand Down Expand Up @@ -165,6 +167,7 @@ InspectorGadget::~InspectorGadget() {

void InspectorGadget::connectSignalsAndSlots() {
connect(this, &InspectorGadget::toggleUnitsClicked, this, &InspectorGadget::toggleUnits);
connect(this, &InspectorGadget::toggleDisplayAdditionalPropsClicked, this, &InspectorGadget::toggleDisplayAdditionalProps);
}

void InspectorGadget::rebuild(bool recursive) {
Expand Down Expand Up @@ -367,6 +370,51 @@ void InspectorGadget::layoutItems(QVBoxLayout* masterLayout, QWidget* parent, bo
}
} // if(p)

if (m_displayAdditionalProps) {
// m_workspaceObj->getSources(IddObjectType::OS_AdditionalProperties)
if (auto mo_ = m_workspaceObj->optionalCast<model::ModelObject>(); mo_.has_value() && mo_->hasAdditionalProperties()) {
auto addProps = mo_->additionalProperties();
auto igChildItr = m_childMap.find(addProps);
if (igChildItr != m_childMap.end()) {
InspectorGadget* igchild = igChildItr->second;
layout->addWidget(igchild);
} else {
bool showComment = false;
bool showFields = true;
if (m_recursive) {
showComment = m_showComments;
showFields = m_showAllFields;
}
auto* igChild = new InspectorGadget(addProps, m_indent, m_comboBridge, showComment, showFields, m_recursive, m_locked);

igChild->setUnitSystem(m_unitSystem);
layout->addWidget(igChild);
m_childMap[addProps] = igChild;
}

#if 0
for (const auto& name : addProps.featureNames()) {
auto propType_ = addProps.getFeatureDataType(name);
OS_ASSERT(propType_);
auto propType = std::move(*propType_);
if (propType == "String") {
boost::optional<std::string> val_ = addProps.getFeatureAsString(name);
OS_ASSERT(val_);
} else if (propType == "Double") {
boost::optional<double> val_ = addProps.getFeatureAsDouble(name);
OS_ASSERT(val_);
} else if (propType == "Integer") {
boost::optional<int> val_ = addProps.getFeatureAsInteger(name);
OS_ASSERT(val_);
} else if (propType == "Double") {
boost::optional<bool> val_ = addProps.getFeatureAsBoolean(name);
OS_ASSERT(val_);
}
}
#endif
}
}

if (m_stretch) {
masterLayout->addStretch();
}
Expand Down Expand Up @@ -1148,3 +1196,17 @@ void InspectorGadget::setUnitSystem(const InspectorGadget::UNIT_SYSTEM unitSyste
m_unitSystem = unitSystem;
rebuild(true);
}

void InspectorGadget::toggleDisplayAdditionalProps(bool displayAdditionalProps) {
qDebug() << "InspectorGadget::toggleDisplayAdditionalProps";
setDisplayAdditionalProps(displayAdditionalProps);
}

void InspectorGadget::setDisplayAdditionalProps(bool displayAdditionalProps) {
qDebug() << "InspectorGadget::setDisplayAdditionalProps=" << displayAdditionalProps;
openstudio::OptionalWorkspaceObject currentObject = m_workspaceObj;
clear(true);
m_workspaceObj = currentObject;
m_displayAdditionalProps = displayAdditionalProps;
rebuild(true);
}
7 changes: 7 additions & 0 deletions src/model_editor/InspectorGadget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ class MODELEDITOR_API InspectorGadget

void setUnitSystem(const UNIT_SYSTEM unitSystem);

void setDisplayAdditionalProps(bool displayAdditionalProps);

void removeWorkspaceObject(const openstudio::Handle&); // Middleman nano slot to emit QT signal to simulate signal chaining

public slots:

void toggleUnits(bool displayIP);

void toggleDisplayAdditionalProps(bool displayAdditionalProps);

/*! \brief lays out the last object again.
*
*\param recursive if true, apply the change to the children
Expand Down Expand Up @@ -228,6 +232,8 @@ class MODELEDITOR_API InspectorGadget

void toggleUnitsClicked(bool);

void toggleDisplayAdditionalPropsClicked(bool);

/*!
*This signal is emitted when the IG changes the model. If your program
*uses IG, then you should connect to this so that you know if the file needs saving or not
Expand Down Expand Up @@ -317,6 +323,7 @@ class MODELEDITOR_API InspectorGadget
bool m_recursive;
UNIT_SYSTEM m_unitSystem;
bool m_workspaceObjectChanged;
bool m_displayAdditionalProps = false;

typedef std::map<openstudio::model::ModelObject, InspectorGadget*> MODELMAP;
MODELMAP m_childMap;
Expand Down
49 changes: 46 additions & 3 deletions src/openstudio_lib/BuildingInspectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ void BuildingDefaultScheduleSetVectorController::onDrop(const OSItemId& itemId)

// BuildingInspectorView

BuildingInspectorView::BuildingInspectorView(bool isIP, const openstudio::model::Model& model, QWidget* parent)
: ModelObjectInspectorView(model, true, parent), m_isIP(isIP) {
BuildingInspectorView::BuildingInspectorView(bool isIP, bool displayAdditionalProps, const openstudio::model::Model& model, QWidget* parent)
: ModelObjectInspectorView(model, true, parent), m_isIP(isIP), m_displayAdditionalProps(displayAdditionalProps) {
auto* hiddenWidget = new QWidget();
this->stackedWidget()->insertWidget(0, hiddenWidget);

Expand All @@ -250,9 +250,33 @@ BuildingInspectorView::BuildingInspectorView(bool isIP, const openstudio::model:

m_nameEdit = new OSLineEdit2();
vLayout->addWidget(m_nameEdit);

mainGridLayout->addLayout(vLayout, row, 0, 1, 2);
mainGridLayout->setRowMinimumHeight(row, 30);
++row;

vLayout = new QVBoxLayout();
m_displayNamelabel = new QLabel();
m_displayNamelabel->setText("Display Name: ");
m_displayNamelabel->setStyleSheet("QLabel { font: bold; }");
vLayout->addWidget(m_displayNamelabel);

m_displayNameEdit = new OSLineEdit2();
vLayout->addWidget(m_displayNameEdit);
mainGridLayout->addLayout(vLayout, row, 0, 1, 1);
mainGridLayout->setRowMinimumHeight(row, 30);

vLayout = new QVBoxLayout();
m_cadObjectIdLabel = new QLabel();
m_cadObjectIdLabel->setText("CAD Object Id: ");
m_cadObjectIdLabel->setStyleSheet("QLabel { font: bold; }");
vLayout->addWidget(m_cadObjectIdLabel);

m_cadObjectIdEdit = new OSLineEdit2();
vLayout->addWidget(m_cadObjectIdEdit);
mainGridLayout->addLayout(vLayout, row, 1, 1, 1);
mainGridLayout->setRowMinimumHeight(row, 30);

this->toggleDisplayAdditionalProps(m_displayAdditionalProps);

++row;

Expand Down Expand Up @@ -594,6 +618,12 @@ void BuildingInspectorView::attach(openstudio::model::Building& building) {
*m_building, OptionalStringGetter(std::bind(&model::Building::name, m_building.get_ptr(), true)),
boost::optional<StringSetterOptionalStringReturn>(std::bind(&model::Building::setName, m_building.get_ptr(), std::placeholders::_1)));

m_displayNameEdit->bind(*m_building, OptionalStringGetter(std::bind(&model::Building::displayName, m_building.get_ptr())),
boost::optional<StringSetter>(std::bind(&model::Building::setDisplayName, m_building.get_ptr(), std::placeholders::_1)));

m_cadObjectIdEdit->bind(*m_building, OptionalStringGetter(std::bind(&model::Building::cadObjectId, m_building.get_ptr())),
boost::optional<StringSetter>(std::bind(&model::Building::setCADObjectId, m_building.get_ptr(), std::placeholders::_1)));

populateStandardsTemplates();
populateStandardsBuildingTypes();

Expand Down Expand Up @@ -656,6 +686,10 @@ void BuildingInspectorView::detach() {

m_nameEdit->unbind();

m_displayNameEdit->unbind();

m_cadObjectIdEdit->unbind();

disconnect(m_standardsTemplateComboBox, nullptr, this, nullptr);
m_standardsTemplateComboBox->clear();

Expand Down Expand Up @@ -726,4 +760,13 @@ void BuildingInspectorView::toggleUnits(bool displayIP) {
m_isIP = displayIP;
}

void BuildingInspectorView::toggleDisplayAdditionalProps(bool displayAdditionalProps) {
m_displayAdditionalProps = displayAdditionalProps;

m_displayNamelabel->setVisible(m_displayAdditionalProps);
m_displayNameEdit->setVisible(m_displayAdditionalProps);
m_cadObjectIdLabel->setVisible(m_displayAdditionalProps);
m_cadObjectIdEdit->setVisible(m_displayAdditionalProps);
}

} // namespace openstudio
9 changes: 8 additions & 1 deletion src/openstudio_lib/BuildingInspectorView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BuildingInspectorView : public ModelObjectInspectorView
Q_OBJECT

public:
BuildingInspectorView(bool isIP, const openstudio::model::Model& model, QWidget* parent = nullptr);
BuildingInspectorView(bool isIP, bool displayAdditionalProps, const openstudio::model::Model& model, QWidget* parent = nullptr);

virtual ~BuildingInspectorView() {}

Expand Down Expand Up @@ -152,17 +152,24 @@ class BuildingInspectorView : public ModelObjectInspectorView
OSIntegerEdit2* m_numberLivingUnits = nullptr;
OSIntegerEdit2* m_numberStories = nullptr;
OSLineEdit2* m_nameEdit = nullptr;
QLabel* m_displayNamelabel = nullptr;
OSLineEdit2* m_displayNameEdit = nullptr;
QLabel* m_cadObjectIdLabel = nullptr;
OSLineEdit2* m_cadObjectIdEdit = nullptr;
OSQuantityEdit2* m_northAxisEdit = nullptr;
OSQuantityEdit2* m_floorToCeilingHeight = nullptr;
OSQuantityEdit2* m_floorToFloorHeight = nullptr;
OSSwitch2* m_relocatable = nullptr;
QComboBox* m_standardsTemplateComboBox = nullptr;
QComboBox* m_standardsBuildingTypeComboBox = nullptr;
bool m_isIP;
bool m_displayAdditionalProps;

public slots:

void toggleUnits(bool displayIP) override;

void toggleDisplayAdditionalProps(bool displayAdditionalProps) override;
};

} // namespace openstudio
Expand Down
35 changes: 28 additions & 7 deletions src/openstudio_lib/FacilityExteriorEquipmentGridView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

#define NAME "Name"
#define SELECTED "All"
#define DISPLAYNAME "Display Name"
#define CADOBJECTID "CAD Object ID"

// EXTERIOR LIGHTS
#define EXTERIORLIGHTSDEFINITION "Exterior Lights Definition"
Expand All @@ -93,12 +95,14 @@

namespace openstudio {

FacilityExteriorEquipmentGridView::FacilityExteriorEquipmentGridView(bool isIP, const model::Model& model, QWidget* parent)
: GridViewSubTab(isIP, model, parent) {
FacilityExteriorEquipmentGridView::FacilityExteriorEquipmentGridView(bool isIP, bool displayAdditionalProps, const model::Model& model,
QWidget* parent)
: GridViewSubTab(isIP, displayAdditionalProps, model, parent) {
auto modelObjects = subsetCastVector<model::ModelObject>(model.getConcreteModelObjects<model::ExteriorLights>());
std::sort(modelObjects.begin(), modelObjects.end(), openstudio::WorkspaceObjectNameLess());

m_gridController = new FacilityExteriorEquipmentGridController(isIP, "Exterior Equipment", IddObjectType::OS_Exterior_Lights, model, modelObjects);
m_gridController = new FacilityExteriorEquipmentGridController(isIP, displayAdditionalProps, "Exterior Equipment",
IddObjectType::OS_Exterior_Lights, model, modelObjects);
auto* gridView = new OSGridView(m_gridController, "Exterior Equipment", "Drop\nExterior Equipment", false, parent);

setGridController(m_gridController);
Expand Down Expand Up @@ -163,10 +167,10 @@ void FacilityExteriorEquipmentGridView::clearSelection() {
//m_itemSelectorButtons->disablePurgeButton();
}

FacilityExteriorEquipmentGridController::FacilityExteriorEquipmentGridController(bool isIP, const QString& settingsText, IddObjectType iddObjectType,
const model::Model& model,
FacilityExteriorEquipmentGridController::FacilityExteriorEquipmentGridController(bool isIP, bool displayAdditionalProps, const QString& settingsText,
IddObjectType iddObjectType, const model::Model& model,
const std::vector<model::ModelObject>& modelObjects)
: OSGridController(isIP, settingsText, iddObjectType, model, modelObjects) {
: OSGridController(isIP, settingsText, iddObjectType, model, modelObjects, displayAdditionalProps) {
setCategoriesAndFields();
}

Expand Down Expand Up @@ -218,6 +222,10 @@ void FacilityExteriorEquipmentGridController::onCategorySelected(int index) {
}

void FacilityExteriorEquipmentGridController::addColumns(const QString& category, std::vector<QString>& fields) {

if (isDisplayAdditionalProps()) {
fields.insert(fields.begin(), {DISPLAYNAME, CADOBJECTID});
}
// always show name and selected columns
fields.insert(fields.begin(), {NAME, SELECTED});

Expand All @@ -229,7 +237,20 @@ void FacilityExteriorEquipmentGridController::addColumns(const QString& category

addParentNameLineEditColumn(Heading(QString(NAME), false, false), false, CastNullAdapter<model::ModelObject>(&model::ModelObject::name),
CastNullAdapter<model::ModelObject>(&model::ModelObject::setName));

} else if (field == DISPLAYNAME) {
addNameLineEditColumn(Heading(QString(DISPLAYNAME), false, false), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::ModelObject>(&model::ModelObject::displayName), // getter
DisplayNameAdapter<model::ModelObject>(&model::ModelObject::setDisplayName) // setter
);
} else if (field == CADOBJECTID) {
addNameLineEditColumn(Heading(QString(CADOBJECTID), false, false), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::ModelObject>(&model::ModelObject::cadObjectId), // getter
DisplayNameAdapter<model::ModelObject>(&model::ModelObject::setCADObjectId) // setter
);
} else if (field == SELECTED) {

auto checkbox = QSharedPointer<OSSelectAllCheckBox>(new OSSelectAllCheckBox());
Expand Down
6 changes: 3 additions & 3 deletions src/openstudio_lib/FacilityExteriorEquipmentGridView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FacilityExteriorEquipmentGridView : public GridViewSubTab
Q_OBJECT

public:
FacilityExteriorEquipmentGridView(bool isIP, const model::Model& model, QWidget* parent = 0);
FacilityExteriorEquipmentGridView(bool isIP, bool displayAdditionalProps, const model::Model& model, QWidget* parent = 0);

virtual ~FacilityExteriorEquipmentGridView() {}

Expand All @@ -72,8 +72,8 @@ class FacilityExteriorEquipmentGridController : public OSGridController
Q_OBJECT

public:
FacilityExteriorEquipmentGridController(bool isIP, const QString& settingsText, IddObjectType iddObjectType, const model::Model& model,
const std::vector<model::ModelObject>& modelObjects);
FacilityExteriorEquipmentGridController(bool isIP, bool displayAdditionalProps, const QString& settingsText, IddObjectType iddObjectType,
const model::Model& model, const std::vector<model::ModelObject>& modelObjects);

virtual ~FacilityExteriorEquipmentGridController() = default;

Expand Down
Loading

0 comments on commit 43dd06b

Please sign in to comment.