From fc9e953554517f845314e48022752724d4409c02 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Tue, 25 Oct 2022 07:25:58 -0700 Subject: [PATCH] Fix Vector3 Property, enum work --- Blocks3D.vcproj | 20 ++++++++++ src/include/DataModelV2/Instance.h | 1 + src/include/DataModelV2/PVInstance.h | 3 ++ src/include/DataModelV2/PartInstance.h | 4 ++ src/include/Enum.h | 26 +++++++++++++ src/include/Enum/B3DEnum.h | 24 ++++++++++++ src/include/PropertiesV2/Color3Property.h | 24 ++++++++++++ src/include/PropertiesV2/Property.h | 3 ++ src/include/PropertiesV2/Vector3Property.h | 26 +++++++++++++ src/include/PropertyWindow.h | 1 + src/source/DataModelV2/PVInstance.cpp | 27 +++++++++++++ src/source/DataModelV2/PartInstance.cpp | 43 +++++++++++++++++++++ src/source/PropertiesV2/Color3Property.cpp | 21 ++++++++++ src/source/PropertiesV2/Vector3Property.cpp | 33 ++++++++++++++++ src/source/PropertyWindow.cpp | 22 ++++++++++- 15 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 src/include/Enum/B3DEnum.h create mode 100644 src/include/PropertiesV2/Color3Property.h create mode 100644 src/include/PropertiesV2/Vector3Property.h create mode 100644 src/source/PropertiesV2/Color3Property.cpp create mode 100644 src/source/PropertiesV2/Vector3Property.cpp diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index 19cc2cb..474298d 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -266,6 +266,10 @@ RelativePath=".\src\source\CameraController.cpp" > + + @@ -310,6 +314,10 @@ RelativePath=".\src\source\TextureHandler.cpp" > + + @@ -715,6 +723,10 @@ RelativePath=".\src\include\ax.h" > + + @@ -723,6 +735,10 @@ RelativePath=".\src\include\CameraController.h" > + + @@ -779,6 +795,10 @@ RelativePath=".\src\include\ToolEnum.h" > + + diff --git a/src/include/DataModelV2/Instance.h b/src/include/DataModelV2/Instance.h index fa75e7a..d644ffb 100644 --- a/src/include/DataModelV2/Instance.h +++ b/src/include/DataModelV2/Instance.h @@ -2,6 +2,7 @@ #include #include "propertyGrid.h" #include "PropertiesV2/StringProperty.h" +#include "PropertiesV2/BoolProperty.h" #include "map" class Instance diff --git a/src/include/DataModelV2/PVInstance.h b/src/include/DataModelV2/PVInstance.h index c5723f3..2df130c 100644 --- a/src/include/DataModelV2/PVInstance.h +++ b/src/include/DataModelV2/PVInstance.h @@ -13,10 +13,13 @@ public: virtual void postRender(RenderDevice* rd); virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); + virtual std::vector collectProperties(); bool nameShown; bool controllerFlagShown; Enum::Controller::Value controller; virtual void makeJoints(); + virtual void setNameShown(bool nameShown); + virtual void setControllerFlagShown(bool controllerFlagShown); protected: CoordinateFrame cFrame; static G3D::Color3 getControllerColor(int controller) diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index ffbfce4..7c180d5 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -1,6 +1,8 @@ #pragma once #include "PVInstance.h" #include "Enum.h" +#include "PropertiesV2/Color3Property.h" +#include "PropertiesV2/Vector3Property.h" #define _USE_MATH_DEFINES #include @@ -59,6 +61,7 @@ public: //Setters void setParent(Instance* parent); void setPosition(Vector3); + void setColor(Color3 color); void setVelocity(Vector3); void setRotVelocity(Vector3); void setCFrame(CoordinateFrame); @@ -83,6 +86,7 @@ public: //Properties virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); + virtual std::vector collectProperties(); private: bool anchored; Vector3 position; diff --git a/src/include/Enum.h b/src/include/Enum.h index 0643d95..66c7741 100644 --- a/src/include/Enum.h +++ b/src/include/Enum.h @@ -1,4 +1,6 @@ #pragma once +#include +#include namespace Enum { @@ -7,6 +9,30 @@ namespace Enum enum Value { Smooth = 0, Bumps = 1, Hinge = 2, Motor = 3, StepperMotor = 4, Spawn = 5 }; + static std::pair map_data[] = { + std::make_pair("Smooth", Smooth), + std::make_pair("Bumps", Bumps), + std::make_pair("Hinge", Hinge), + std::make_pair("Motor", Motor), + std::make_pair("StepperMotor", StepperMotor), + std::make_pair("Spawn", Spawn) + }; + static std::map nameMap(map_data, + map_data + sizeof map_data / sizeof map_data[0]); + + static Value getByName(std::string name) { + if(nameMap.find(name) != nameMap.end()){ + return nameMap[name]; + } + return Smooth; + } + + static std::string getName(Value value) { + for (std::map::iterator it = nameMap.begin(); it != nameMap.end(); ++it) + if (it->second == value) + return it->first; + return ""; + } } namespace Shape { diff --git a/src/include/Enum/B3DEnum.h b/src/include/Enum/B3DEnum.h new file mode 100644 index 0000000..64893fe --- /dev/null +++ b/src/include/Enum/B3DEnum.h @@ -0,0 +1,24 @@ +#pragma once + +namespace Enum +{ + class B3DEnum { + public: + B3DEnum(int id, std::string name) + { + this->id = id; + this->name = name; + } + const int getId() { + return id; + } + const std::string getName() { + return name; + } + virtual B3DEnum getByName(std::string name); + virtual B3DEnum getById(int id); + private: + int id; + std::string name; + } +} \ No newline at end of file diff --git a/src/include/PropertiesV2/Color3Property.h b/src/include/PropertiesV2/Color3Property.h new file mode 100644 index 0000000..59aca34 --- /dev/null +++ b/src/include/PropertiesV2/Color3Property.h @@ -0,0 +1,24 @@ +#pragma once +#include "Property.h" + +class Color3Property : public Property +{ +public: + typedef void (Instance::*instanceSetter)(Color3); + ~Color3Property(void){}; + Color3Property(LPSTR name, LPSTR desc, LPSTR catalog, Color3 value, Instance * owner, instanceSetter setterFunc) + :Property(name, desc, catalog, &_value, owner) + { + this->_value = value; + this->setterFunc = setterFunc; + } + const void setValue(Color3 val){ + (_owner->*setterFunc)(val); + _value = val; + } + PROPGRIDITEM getPropGridItem(); + void setProperty(LPPROPGRIDITEM &pItem); +private: + Color3 _value; + instanceSetter setterFunc; +}; diff --git a/src/include/PropertiesV2/Property.h b/src/include/PropertiesV2/Property.h index 6d8c5de..3ed1f2b 100644 --- a/src/include/PropertiesV2/Property.h +++ b/src/include/PropertiesV2/Property.h @@ -24,6 +24,9 @@ public: const void* getValue() { return _value; } + const LPSTR getName() { + return _name; + } virtual PROPGRIDITEM getPropGridItem(); virtual void setProperty(LPPROPGRIDITEM &pItem); protected: diff --git a/src/include/PropertiesV2/Vector3Property.h b/src/include/PropertiesV2/Vector3Property.h new file mode 100644 index 0000000..de36f1d --- /dev/null +++ b/src/include/PropertiesV2/Vector3Property.h @@ -0,0 +1,26 @@ +#pragma once +#include "Property.h" +#include + +class Vector3Property : public Property +{ +public: + typedef void (Instance::*instanceSetter)(Vector3); + ~Vector3Property(void){}; + Vector3Property(LPSTR name, LPSTR desc, LPSTR catalog, Vector3 value, Instance * owner, instanceSetter setterFunc) + :Property(name, desc, catalog, &_value, owner) + { + this->_value = value; + this->setterFunc = setterFunc; + } + const void setValue(Vector3 val){ + (_owner->*setterFunc)(val); + _value = val; + } + PROPGRIDITEM getPropGridItem(); + void setProperty(LPPROPGRIDITEM &pItem); +private: + Vector3 _value; + std::string stringRep; + instanceSetter setterFunc; +}; diff --git a/src/include/PropertyWindow.h b/src/include/PropertyWindow.h index f402b02..6d57ddb 100644 --- a/src/include/PropertyWindow.h +++ b/src/include/PropertyWindow.h @@ -15,4 +15,5 @@ private: HWND _explorerComboBox; void _resize(); void clearExplorer(); + void deleteProperties(); }; \ No newline at end of file diff --git a/src/source/DataModelV2/PVInstance.cpp b/src/source/DataModelV2/PVInstance.cpp index 48d4372..77bafe5 100644 --- a/src/source/DataModelV2/PVInstance.cpp +++ b/src/source/DataModelV2/PVInstance.cpp @@ -63,6 +63,33 @@ static Enum::Controller::Value strEnum(TCHAR * tval) } +std::vector PVInstance::collectProperties() +{ + std::vector properties = Instance::collectProperties(); + properties.push_back(new BoolProperty( + "NameShown", + "This chooses whether the item name is shown", + "Item", + nameShown, + this, + (BoolProperty::instanceSetter)&PVInstance::setNameShown)); + properties.push_back(new BoolProperty( + "ControllerFlagShown", + "This chooses whether the item's ControllerFlag is shown", + "Item", + controllerFlagShown, + this, + (BoolProperty::instanceSetter)&PVInstance::setControllerFlagShown)); + return properties; +} + + +void PVInstance::setNameShown(bool nameShown){ + this->nameShown = nameShown; +} +void PVInstance::setControllerFlagShown(bool controllerFlagShown){ + this->controllerFlagShown = controllerFlagShown; +} std::vector PVInstance::getProperties() { diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 8463f2b..43eabf4 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -674,6 +674,49 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) else PVInstance::PropUpdate(item); } +void PartInstance::setColor(Color3 color) +{ + this->color = color; + changed = true; +} + +std::vector PartInstance::collectProperties() +{ + std::vector properties = PVInstance::collectProperties(); + properties.push_back(new Color3Property( + "Color3", + "The color of the selected part", + "Properties", + color, + this, + (Color3Property::instanceSetter)&PartInstance::setColor)); + + properties.push_back(new BoolProperty( + "Anchored", + "Whether the block can move or not", + "Item", + anchored, + this, + (BoolProperty::instanceSetter)&PartInstance::setAnchored)); + + properties.push_back(new Vector3Property( + "Offset", + "The position of the object in the workspace", + "Item", + position, + this, + (Vector3Property::instanceSetter)&PartInstance::setPosition)); + + properties.push_back(new Vector3Property( + "Size", + "The size of the object in the workspace", + "Item", + size, + this, + (Vector3Property::instanceSetter)&PartInstance::setSize)); + return properties; +} + // This needs to be changed, buffer size of 12 is way too small // Crash occurs if you put a huge number in char changeTimerTxt[12]; diff --git a/src/source/PropertiesV2/Color3Property.cpp b/src/source/PropertiesV2/Color3Property.cpp new file mode 100644 index 0000000..98e2670 --- /dev/null +++ b/src/source/PropertiesV2/Color3Property.cpp @@ -0,0 +1,21 @@ +#include "PropertiesV2/Color3Property.h" + +PROPGRIDITEM Color3Property::getPropGridItem(){ + PROPGRIDITEM pItem; + PropGrid_ItemInit(pItem); + pItem.lpszCatalog=_catalog; + pItem.lpszPropName=_name; + pItem.lpszPropDesc=_desc; + pItem.lpCurValue=RGB((_value.r*255),(_value.g*255),(_value.b*255)); + pItem.iItemType=PIT_COLOR; + return pItem; +} + +void Color3Property::setProperty(LPPROPGRIDITEM &pItem){ + + setValue(Color3( + GetRValue(pItem->lpCurValue)/255.0F, + GetGValue(pItem->lpCurValue)/255.0F, + GetBValue(pItem->lpCurValue)/255.0F + )); +} \ No newline at end of file diff --git a/src/source/PropertiesV2/Vector3Property.cpp b/src/source/PropertiesV2/Vector3Property.cpp new file mode 100644 index 0000000..b524bd1 --- /dev/null +++ b/src/source/PropertiesV2/Vector3Property.cpp @@ -0,0 +1,33 @@ +#include "PropertiesV2/Vector3Property.h" + +PROPGRIDITEM Vector3Property::getPropGridItem(){ + std::stringstream s; + s << _value.x << ", " << _value.y << ", " << _value.z; + stringRep = s.str(); + PROPGRIDITEM pItem; + PropGrid_ItemInit(pItem); + pItem.lpszCatalog=_catalog; + pItem.lpszPropName=_name; + pItem.lpszPropDesc=_desc; + pItem.lpCurValue=(LPARAM)stringRep.c_str(); + pItem.iItemType=PIT_EDIT; + return pItem; +} + +void Vector3Property::setProperty(LPPROPGRIDITEM &pItem){ + + std::string str = (LPTSTR)pItem->lpCurValue; + std::vector vect; + std::stringstream ss(str); + float i; + while (ss >> i) + { + vect.push_back(i); + if (ss.peek() == ',') + ss.ignore(); + } + if(vect.size() == 3) + { + setValue(Vector3(vect.at(0),vect.at(1),vect.at(2))); + } +} \ No newline at end of file diff --git a/src/source/PropertyWindow.cpp b/src/source/PropertyWindow.cpp index 243afd0..383924d 100644 --- a/src/source/PropertyWindow.cpp +++ b/src/source/PropertyWindow.cpp @@ -186,8 +186,15 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LPNMHDR pnm = (LPNMHDR)lParam; LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm; LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex); - selectedInstance->PropUpdate(item); - //propWind->UpdateSelected(selectedInstance); + for(size_t i = 0; i < prop.size(); i++) + { + if(strcmp(item->lpszPropName, prop[i]->getName()) == 0) + { + prop[i]->setProperty(item); + } + } + //selectedInstance->PropUpdate(item); + propWind->UpdateSelected(g_dataModel->getSelectionService()->getSelection()); } } break; @@ -342,6 +349,7 @@ void PropertyWindow::_resize() void PropertyWindow::UpdateSelected(std::vector instances) { + deleteProperties(); if(instances.size() <= 0) { ClearProperties(); @@ -371,6 +379,16 @@ void PropertyWindow::UpdateSelected(std::vector instances) void PropertyWindow::ClearProperties() { + deleteProperties(); clearExplorer(); PropGrid_ResetContent(_propGrid); +} + +void PropertyWindow::deleteProperties() +{ + while(prop.size() > 0) { + Property * toDelete = prop.back(); + prop.pop_back(); + delete toDelete; + } } \ No newline at end of file