Skip to content

Commit da833cb

Browse files
Refactored UI Framework
1 parent 037781e commit da833cb

File tree

10 files changed

+168
-13
lines changed

10 files changed

+168
-13
lines changed

Framework/HeadersCore/CppDynamic/libmc_dynamic.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ class ELibMCException : public std::exception {
767767
case LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON: return "INVALIDCUSTOMOPENAPIJSON";
768768
case LIBMC_ERROR_USEDMODULEISLEGACY: return "USEDMODULEISLEGACY";
769769
case LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS: return "TRIEDTOACCESSNULLCLIENTPARAMETERS";
770+
case LIBMC_ERROR_INVALIDFRONTENDMODULEPATH: return "INVALIDFRONTENDMODULEPATH";
771+
case LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME: return "INVALIDFRONTENDATTRIBUTENAME";
772+
case LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME: return "DUPLICATEFRONTENDATTRIBUTENAME";
770773
}
771774
return "UNKNOWN";
772775
}
@@ -1368,6 +1371,9 @@ class ELibMCException : public std::exception {
13681371
case LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON: return "Invalid Custom OpenAPI JSON.";
13691372
case LIBMC_ERROR_USEDMODULEISLEGACY: return "Used module is legacy.";
13701373
case LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS: return "Tried to access null client parameters.";
1374+
case LIBMC_ERROR_INVALIDFRONTENDMODULEPATH: return "Invalid frontend module path.";
1375+
case LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME: return "Invalid frontend attribute name.";
1376+
case LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME: return "Duplicate frontend attribute name.";
13711377
}
13721378
return "unknown error";
13731379
}

Framework/HeadersCore/CppDynamic/libmc_types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ typedef void * LibMC_pvoid;
689689
#define LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON 673 /** Invalid Custom OpenAPI JSON. */
690690
#define LIBMC_ERROR_USEDMODULEISLEGACY 674 /** Used module is legacy. */
691691
#define LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS 675 /** Tried to access null client parameters. */
692+
#define LIBMC_ERROR_INVALIDFRONTENDMODULEPATH 676 /** Invalid frontend module path. */
693+
#define LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME 677 /** Invalid frontend attribute name. */
694+
#define LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME 678 /** Duplicate frontend attribute name. */
692695

693696
/*************************************************************************************************************************
694697
Error strings for LibMC
@@ -1290,6 +1293,9 @@ inline const char * LIBMC_GETERRORSTRING (LibMCResult nErrorCode) {
12901293
case LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON: return "Invalid Custom OpenAPI JSON.";
12911294
case LIBMC_ERROR_USEDMODULEISLEGACY: return "Used module is legacy.";
12921295
case LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS: return "Tried to access null client parameters.";
1296+
case LIBMC_ERROR_INVALIDFRONTENDMODULEPATH: return "Invalid frontend module path.";
1297+
case LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME: return "Invalid frontend attribute name.";
1298+
case LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME: return "Duplicate frontend attribute name.";
12931299
default: return "unknown error";
12941300
}
12951301
}

Framework/InterfacesCore/libmc_types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ typedef void * LibMC_pvoid;
689689
#define LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON 673 /** Invalid Custom OpenAPI JSON. */
690690
#define LIBMC_ERROR_USEDMODULEISLEGACY 674 /** Used module is legacy. */
691691
#define LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS 675 /** Tried to access null client parameters. */
692+
#define LIBMC_ERROR_INVALIDFRONTENDMODULEPATH 676 /** Invalid frontend module path. */
693+
#define LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME 677 /** Invalid frontend attribute name. */
694+
#define LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME 678 /** Duplicate frontend attribute name. */
692695

693696
/*************************************************************************************************************************
694697
Error strings for LibMC
@@ -1290,6 +1293,9 @@ inline const char * LIBMC_GETERRORSTRING (LibMCResult nErrorCode) {
12901293
case LIBMC_ERROR_INVALIDCUSTOMOPENAPIJSON: return "Invalid Custom OpenAPI JSON.";
12911294
case LIBMC_ERROR_USEDMODULEISLEGACY: return "Used module is legacy.";
12921295
case LIBMC_ERROR_TRIEDTOACCESSNULLCLIENTPARAMETERS: return "Tried to access null client parameters.";
1296+
case LIBMC_ERROR_INVALIDFRONTENDMODULEPATH: return "Invalid frontend module path.";
1297+
case LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME: return "Invalid frontend attribute name.";
1298+
case LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME: return "Duplicate frontend attribute name.";
12931299
default: return "unknown error";
12941300
}
12951301
}

Implementation/UI/amc_ui_frontenddefinition.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,50 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131
#include "amc_ui_frontenddefinition.hpp"
3232
#include "libmc_exceptiontypes.hpp"
33+
#include "common_utils.hpp"
3334

3435
using namespace AMC;
3536

37+
38+
39+
CUIFrontendDefinitionAttribute::CUIFrontendDefinitionAttribute(const std::string& sName, eUIFrontendDefinitionAttributeType attributeType)
40+
: m_sName(sName), m_AttributeType(attributeType)
41+
{
42+
if (!AMCCommon::CUtils::stringIsValidAlphanumericNameString(sName))
43+
throw ELibMCCustomException(LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME, sName);
44+
}
45+
46+
CUIFrontendDefinitionAttribute::~CUIFrontendDefinitionAttribute()
47+
{
48+
49+
}
50+
51+
52+
std::string CUIFrontendDefinitionAttribute::getName()
53+
{
54+
return m_sName;
55+
}
56+
57+
eUIFrontendDefinitionAttributeType CUIFrontendDefinitionAttribute::getAttributeType()
58+
{
59+
return m_AttributeType;
60+
}
61+
62+
CUIFrontendDefinitionExpressionAttribute::CUIFrontendDefinitionExpressionAttribute(const std::string& sName, eUIFrontendDefinitionAttributeType attributeType, const CUIExpression& valueExpression)
63+
: CUIFrontendDefinitionAttribute(sName, attributeType), m_ValueExpression(valueExpression)
64+
{
65+
}
66+
67+
CUIFrontendDefinitionExpressionAttribute::~CUIFrontendDefinitionExpressionAttribute()
68+
{
69+
70+
}
71+
3672
CUIFrontendDefinitionModuleStore::CUIFrontendDefinitionModuleStore(const std::string& sModuleUUID, const std::string& sModulePath)
73+
: m_sUUID(AMCCommon::CUtils::normalizeUUIDString(sModuleUUID)), m_sPath(sModulePath)
3774
{
75+
if (!AMCCommon::CUtils::stringIsValidAlphanumericPathString (sModulePath))
76+
throw ELibMCCustomException(LIBMC_ERROR_INVALIDFRONTENDMODULEPATH, sModulePath);
3877

3978
}
4079

@@ -43,6 +82,21 @@ CUIFrontendDefinitionModuleStore::~CUIFrontendDefinitionModuleStore()
4382

4483
}
4584

85+
PUIFrontendDefinitionAttribute CUIFrontendDefinitionModuleStore::registerValue (const std::string& sName, eUIFrontendDefinitionAttributeType attributeType, const CUIExpression& valueExpression)
86+
{
87+
if (!AMCCommon::CUtils::stringIsValidAlphanumericNameString(sName))
88+
throw ELibMCCustomException(LIBMC_ERROR_INVALIDFRONTENDATTRIBUTENAME, sName);
89+
90+
if (m_Attributes.find(sName) != m_Attributes.end())
91+
throw ELibMCCustomException(LIBMC_ERROR_DUPLICATEFRONTENDATTRIBUTENAME, sName);
92+
93+
auto pAttribute = std::make_shared<CUIFrontendDefinitionExpressionAttribute>(sName, attributeType, valueExpression);
94+
m_Attributes.insert(std::make_pair(sName, pAttribute));
95+
96+
return pAttribute;
97+
}
98+
99+
46100
CUIFrontendDefinition::CUIFrontendDefinition(AMCCommon::PChrono pGlobalChrono)
47101
: m_pGlobalChrono (pGlobalChrono)
48102
{

Implementation/UI/amc_ui_frontenddefinition.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ namespace AMC {
4747
atNumber = 2,
4848
atInteger = 3,
4949
atBoolean = 4,
50-
atUUID = 5
50+
atUUID = 5,
51+
atArray = 6,
52+
atObjet = 7
5153
};
5254

5355
class CUIFrontendDefinitionAttribute {
@@ -70,6 +72,19 @@ namespace AMC {
7072
typedef std::shared_ptr<CUIFrontendDefinitionAttribute> PUIFrontendDefinitionAttribute;
7173

7274

75+
class CUIFrontendDefinitionExpressionAttribute : public CUIFrontendDefinitionAttribute {
76+
private:
77+
CUIExpression m_ValueExpression;
78+
79+
public:
80+
81+
CUIFrontendDefinitionExpressionAttribute(const std::string& sName, eUIFrontendDefinitionAttributeType attributeType, const CUIExpression& valueExpression);
82+
83+
virtual ~CUIFrontendDefinitionExpressionAttribute();
84+
85+
};
86+
87+
7388
class CUIFrontendDefinitionModuleStore {
7489
private:
7590

@@ -83,6 +98,8 @@ namespace AMC {
8398

8499
virtual ~CUIFrontendDefinitionModuleStore();
85100

101+
PUIFrontendDefinitionAttribute registerValue (const std::string& sName, eUIFrontendDefinitionAttributeType attributeType, const CUIExpression & valueExpression);
102+
86103
};
87104

88105
typedef std::shared_ptr<CUIFrontendDefinitionModuleStore> PUIFrontendDefinitionModuleStore;

Implementation/UI/amc_ui_module.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,34 @@ bool CUIModule::isVersion2FrontendModule()
157157

158158
void CUIModule::frontendWriteModuleStatusToJSON(CJSONWriter& writer, CJSONWriterObject& moduleObject, CUIFrontendState* pFrontendState)
159159
{
160-
throw ELibMCCustomException(LIBMC_ERROR_USEDMODULEISLEGACY, m_sName);
161160
}
162161

163162
std::string CUIModule::getModulePath()
164163
{
165164
return m_sModulePath;
166165
}
167166

167+
PUIFrontendDefinitionAttribute CUIModule::registerUUIDAttribute(const std::string& sAttributeName, const CUIExpression& expression)
168+
{
169+
return m_pModuleStore->registerValue(sAttributeName, eUIFrontendDefinitionAttributeType::atUUID, expression);
170+
}
171+
172+
PUIFrontendDefinitionAttribute CUIModule::registerIntegerAttribute(const std::string& sAttributeName, const CUIExpression& expression)
173+
{
174+
return m_pModuleStore->registerValue(sAttributeName, eUIFrontendDefinitionAttributeType::atInteger, expression);
175+
}
176+
177+
PUIFrontendDefinitionAttribute CUIModule::registerNumberAttribute(const std::string& sAttributeName, const CUIExpression& expression)
178+
{
179+
return m_pModuleStore->registerValue(sAttributeName, eUIFrontendDefinitionAttributeType::atNumber, expression);
180+
}
181+
182+
PUIFrontendDefinitionAttribute CUIModule::registerStringAttribute(const std::string& sAttributeName, const CUIExpression& expression)
183+
{
184+
return m_pModuleStore->registerValue(sAttributeName, eUIFrontendDefinitionAttributeType::atString, expression);
185+
}
186+
187+
PUIFrontendDefinitionAttribute CUIModule::registerBoolAttribute(const std::string& sAttributeName, const CUIExpression& expression)
188+
{
189+
return m_pModuleStore->registerValue(sAttributeName, eUIFrontendDefinitionAttributeType::atBoolean, expression);
190+
}

Implementation/UI/amc_ui_module.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ namespace AMC {
138138
virtual void frontendWriteModuleStatusToJSON(CJSONWriter& writer, CJSONWriterObject& moduleObject, CUIFrontendState* pFrontendState);
139139

140140
std::string getModulePath();
141+
142+
PUIFrontendDefinitionAttribute registerUUIDAttribute(const std::string& sAttributeName, const CUIExpression & expression);
143+
PUIFrontendDefinitionAttribute registerIntegerAttribute(const std::string& sAttributeName, const CUIExpression& expression);
144+
PUIFrontendDefinitionAttribute registerNumberAttribute(const std::string& sAttributeName, const CUIExpression& expression);
145+
PUIFrontendDefinitionAttribute registerStringAttribute(const std::string& sAttributeName, const CUIExpression& expression);
146+
PUIFrontendDefinitionAttribute registerBoolAttribute(const std::string& sAttributeName, const CUIExpression& expression);
141147
};
142148

143149

Implementation/UI/amc_ui_module_custom.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ CUIModule_Custom::CUIModule_Custom(pugi::xml_node& xmlNode, const std::string& s
5858
if (sPath.empty())
5959
throw ELibMCCustomException(LIBMC_ERROR_INVALIDMODULEPATH, m_sName);
6060

61-
m_pCustomItem = std::make_shared<CUIModuleCustomItem_Properties>(m_sUUID, getModulePath (), pUIModuleEnvironment);
61+
m_sParentPath = sPath;
62+
63+
m_pCustomItem = std::make_shared<CUIModuleCustomItem_Properties>(m_sUUID, m_sParentPath, pUIModuleEnvironment);
6264

6365
pugi::xml_node propertiesNode = xmlNode.child("properties");
6466
if (!propertiesNode.empty()) {
@@ -99,7 +101,7 @@ CUIModule_Custom::CUIModule_Custom(pugi::xml_node& xmlNode, const std::string& s
99101
if (iIter != m_EventItemNameMap.end ())
100102
throw ELibMCCustomException(LIBMC_ERROR_DUPLICATECUSTOMPAGEVENTNAME, m_sName + "/" + sName);
101103

102-
auto pEventItem = std::make_shared<CUIModuleCustomItem_Event>(sName, getModulePath (), pUIModuleEnvironment);
104+
auto pEventItem = std::make_shared<CUIModuleCustomItem_Event>(sName, m_sParentPath, pUIModuleEnvironment);
103105

104106
m_EventItemNameMap.insert(std::make_pair (pEventItem->getEventName (), pEventItem));
105107
m_EventItemUUIDMap.insert(std::make_pair(pEventItem->getUUID(), pEventItem));

Implementation/UI/amc_ui_module_custom.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace AMC {
6363

6464
PUIModuleCustomItem_Properties m_pCustomItem;
6565

66+
std::string m_sParentPath;
67+
6668
std::map<std::string, PUIModuleCustomItem_Event> m_EventItemNameMap;
6769
std::map<std::string, PUIModuleCustomItem_Event> m_EventItemUUIDMap;
6870

Implementation/UI/amc_ui_module_layerview.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ void CUIModule_LayerViewPlatformItem::addLegacyContentToJSON(CJSONWriter& writer
145145
nLayerCount = pToolpathEntity->getLayerCount();
146146
}
147147
}
148-
149148
}
149+
150150
object.addInteger(AMC_API_KEY_UI_LAYERCOUNT, nLayerCount);
151151

152152
object.addInteger(AMC_API_KEY_UI_LABELVISIBLE, pGroup->getIntParameterValueByName(AMC_API_KEY_UI_LABELVISIBLE));
@@ -253,36 +253,69 @@ CUIModule_LayerView::CUIModule_LayerView(pugi::xml_node& xmlNode, const std::str
253253
CUIExpression baseImage(platformNode, "baseimage");
254254
CUIExpression layerIndex(platformNode, "layerindex", false);
255255

256+
CUIExpression buildUUID;
257+
CUIExpression executionUUID;
258+
CUIExpression scatterplotUUID;
259+
CUIExpression currentLayer;
260+
261+
CUIExpression labelVisible;
262+
CUIExpression labelCaption;
263+
CUIExpression labelIcon;
264+
265+
CUIExpression sliderChangeEvent;
266+
CUIExpression sliderFixed;
256267

257268
m_PlatformItem = std::make_shared<CUIModule_LayerViewPlatformItem>(m_sModulePath, sizeX, sizeY, originX, originY, layerIndex, baseImage, pUIModuleEnvironment);
258269

259270
auto labelNode = xmlNode.child("label");
260271
if (!labelNode.empty()) {
261-
CUIExpression labelVisible(labelNode, "visible");
262-
CUIExpression labelCaption(labelNode, "caption");
263-
CUIExpression labelIcon(labelNode, "icon");
272+
labelVisible = CUIExpression(labelNode, "visible");
273+
labelCaption = CUIExpression(labelNode, "caption");
274+
labelIcon = CUIExpression(labelNode, "icon");
264275

265276
m_PlatformItem->setLabelExpressions(labelVisible, labelCaption, labelIcon);
266277

267278
}
279+
268280

269281
auto referencesNode = xmlNode.child("references");
270282
if (!referencesNode.empty()) {
271-
CUIExpression buildUUID(platformNode, "builduuid", false);
272-
CUIExpression executionUUID(platformNode, "executionuuid", false);
273-
CUIExpression scatterplotUUID(platformNode, "scatterplotuuid", false);
283+
buildUUID = CUIExpression (platformNode, "builduuid", false);
284+
executionUUID = CUIExpression (platformNode, "executionuuid", false);
285+
scatterplotUUID = CUIExpression (platformNode, "scatterplotuuid", false);
286+
274287
m_PlatformItem->setBuildReference(buildUUID, executionUUID, scatterplotUUID);
288+
289+
290+
275291
}
276292

277293
auto sliderNode = xmlNode.child("slider");
278294
if (!sliderNode.empty()) {
279-
CUIExpression sliderChangeEvent(sliderNode, "changeevent");
280-
CUIExpression sliderFixed(sliderNode, "fixed");
295+
sliderChangeEvent = CUIExpression(sliderNode, "changeevent");
296+
sliderFixed = CUIExpression(sliderNode, "fixed");
281297

282298
m_PlatformItem->setSliderExpressions(sliderChangeEvent, sliderFixed);
283299

284300
}
285301

302+
/////////////////////////////////////////////////////////////////////////////////////
303+
// New UI Frontend System
304+
/////////////////////////////////////////////////////////////////////////////////////
305+
registerUUIDAttribute(AMC_API_KEY_UI_BUILDUUID, buildUUID);
306+
registerUUIDAttribute(AMC_API_KEY_UI_EXECUTIONUUID, executionUUID);
307+
registerUUIDAttribute(AMC_API_KEY_UI_SCATTERPLOTUUID, scatterplotUUID);
308+
registerIntegerAttribute(AMC_API_KEY_UI_CURRENTLAYER, currentLayer);
309+
registerNumberAttribute(AMC_API_KEY_UI_SIZEX, sizeX);
310+
registerNumberAttribute(AMC_API_KEY_UI_SIZEY, sizeY);
311+
registerNumberAttribute(AMC_API_KEY_UI_ORIGINX, originX);
312+
registerNumberAttribute(AMC_API_KEY_UI_ORIGINY, originY);
313+
registerStringAttribute(AMC_API_KEY_UI_BASEIMAGERESOURCE, baseImage);
314+
registerBoolAttribute(AMC_API_KEY_UI_LABELVISIBLE, labelVisible);
315+
registerStringAttribute(AMC_API_KEY_UI_LABELCAPTION, labelCaption);
316+
registerStringAttribute(AMC_API_KEY_UI_LABELICON, labelIcon);
317+
registerStringAttribute(AMC_API_KEY_UI_SLIDERCHANGEEVENT, sliderChangeEvent);
318+
registerBoolAttribute(AMC_API_KEY_UI_SLIDERFIXED, sliderFixed);
286319
}
287320

288321

0 commit comments

Comments
 (0)