From 841933dc4a26f84ee2f9ce32b27c8c8e5327faf1 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 26 Dec 2014 16:40:58 +0300 Subject: [PATCH] "Export to NewGeom" enabled only in SALOME mode. --- src/Config/Config_Common.cpp | 17 +++++++++-- src/Config/Config_Common.h | 7 +++++ src/Config/Config_Keywords.h | 6 ++++ src/Config/Config_ModuleReader.cpp | 37 ++++++++++++++++++++++- src/Config/Config_ModuleReader.h | 7 +++++ src/Config/plugins.xml | 2 +- src/ConnectorPlugin/plugin-Connector.xml | 2 +- src/PartSet/PartSet_icons.qrc | 1 + src/PartSet/icons/geom_export.png | Bin 0 -> 892 bytes 9 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/PartSet/icons/geom_export.png diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index 634a4337f..2da152dcc 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -130,8 +130,7 @@ std::string getProperty(xmlNodePtr theNode, const char* thePropName) bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault) { - std::string prop = getProperty(theNode, theAttributeName); - std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower); + std::string prop = normalize(getProperty(theNode, theAttributeName)); bool result = theDefault; if (prop == "true" || prop == "1") { result = true; @@ -140,3 +139,17 @@ bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool } return result; } + +CONFIG_EXPORT std::string normalize(const char* theString) +{ + if (!theString) + return std::string(); + return normalize(std::string(theString)); +} + +CONFIG_EXPORT std::string normalize(const std::string& theString) +{ + std::string result = theString; + std::transform(result.begin(), result.end(), result.begin(), ::tolower); + return result; +} diff --git a/src/Config/Config_Common.h b/src/Config/Config_Common.h index 05e2024fd..a2cc78843 100644 --- a/src/Config/Config_Common.h +++ b/src/Config/Config_Common.h @@ -93,4 +93,11 @@ CONFIG_EXPORT bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault); +/* + * Returns normalized (lower case) version of string. + * Should be used for case insensitive string matching. + */ +CONFIG_EXPORT std::string normalize(const char* theString); +CONFIG_EXPORT std::string normalize(const std::string& theString); + #endif diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index bc9f4e419..9fe94e769 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -84,5 +84,11 @@ const static char* PLUGINS_MODULE = "module"; const static char* PLUGIN_CONFIG = "configuration"; const static char* PLUGIN_LIBRARY = "library"; const static char* PLUGIN_SCRIPT = "script"; +const static char* PLUGIN_PLATFORM = "platform"; + +const static char* PLUGIN_PLATFORM_SALOME = "salome"; +const static char* PLUGIN_PLATFORM_NEWGEOM = "openparts"; + + #endif /* CONFIG_KEYWORDS_H_ */ diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 21925af59..d0da80ba0 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -21,9 +21,11 @@ //Necessary for cerr #include +#include #ifdef WIN32 #include +#pragma warning(disable : 4996) // for getenv #else #include #endif @@ -34,6 +36,13 @@ Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated) : Config_XMLReader(PLUGIN_FILE), myEventGenerated(theEventGenerated) { + myHaveSalome = false; + char* anEnv = getenv("SALOME_ROOT_DIR"); + std::string value = normalize(anEnv); + if (!value.empty()) { + myHaveSalome = true; + } + } Config_ModuleReader::~Config_ModuleReader() @@ -61,6 +70,9 @@ std::string Config_ModuleReader::getModuleName() void Config_ModuleReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_PLUGIN, NULL)) { + bool isAvailable = isAvaliableOnThisPlatform(getProperty(theNode, PLUGIN_PLATFORM)); + if (!isAvailable) + return; std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG); std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY); std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); @@ -111,8 +123,8 @@ std::string Config_ModuleReader::addPlugin(const std::string& aPluginLibrary, } if(!aPluginName.empty()) { myPluginTypes[aPluginName] = aType; - } + return aPluginName; } @@ -134,6 +146,29 @@ void Config_ModuleReader::loadPlugin(const std::string thePluginName) } } +bool Config_ModuleReader::isAvaliableOnThisPlatform(const std::string& thePluginPlatform) +{ + bool result = true; + PluginPlatform aPlatform = All; + std::string aPlatformName = normalize(thePluginPlatform) ; + if (aPlatformName == PLUGIN_PLATFORM_SALOME) { + aPlatform = Salome; + } else if (aPlatformName == PLUGIN_PLATFORM_NEWGEOM) { + aPlatform = OpenParts; + } else if (!thePluginPlatform.empty()) { + Events_Error::send("Unknown platform: " + thePluginPlatform); + } + if (aPlatform == All) { + result = true; + } else if (myHaveSalome) { + result = aPlatform == Salome; + } else { + result = aPlatform == OpenParts; + } + return result; + +} + void Config_ModuleReader::loadScript(const std::string theFileName) { /* aquire python thread */ diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index 2281eb5cd..c32eb37d9 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -24,6 +24,11 @@ class Config_ModuleReader : public Config_XMLReader Intrenal = 1, Python = 2 }; + enum PluginPlatform { + All = 0, + OpenParts = 1, + Salome = 2 + }; public: CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0); @@ -43,6 +48,7 @@ class Config_ModuleReader : public Config_XMLReader void processNode(xmlNodePtr aNode); bool processChildren(xmlNodePtr aNode); + bool isAvaliableOnThisPlatform(const std::string& thePluginPlatform); std::list importPlugin(const std::string& thePluginLibrary, const std::string& thePluginFile); std::string addPlugin(const std::string& aPluginLibrary, @@ -53,6 +59,7 @@ class Config_ModuleReader : public Config_XMLReader std::map myFeaturesInFiles; static std::map myPluginTypes; const char* myEventGenerated; + bool myHaveSalome; }; diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 00f45dba9..0f4a25586 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -6,7 +6,7 @@ - + diff --git a/src/ConnectorPlugin/plugin-Connector.xml b/src/ConnectorPlugin/plugin-Connector.xml index 2ba73b203..638d4ecb7 100644 --- a/src/ConnectorPlugin/plugin-Connector.xml +++ b/src/ConnectorPlugin/plugin-Connector.xml @@ -5,7 +5,7 @@ id="ExportToGEOM" title="Export to GEOM" tooltip="Exports all bodies into GEOM module" - icon=":pictures/part_ico.png"/> + icon=":icons/geom_export.png"/> \ No newline at end of file diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index b0bffcc5a..796ec88ef 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -28,5 +28,6 @@ icons/shape_group.png icons/fixed.png icons/placement.png + icons/geom_export.png diff --git a/src/PartSet/icons/geom_export.png b/src/PartSet/icons/geom_export.png new file mode 100644 index 0000000000000000000000000000000000000000..07ec5ddcd878de8148da033631ea69582b667247 GIT binary patch literal 892 zcmV-?1B3jDP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5dZ)S5dnW>Uy%R+00(qQO+^RT1Oo^c z3rWr~Y5)KL7<5HgbW?9;ba!ELWdLwtX>N2bZe?^JG%heMGmPe!Pyhe|+DSw~R5(w~ zlX*x~Q5eN%s1e1+TqdQ=!Q3VtC!KU$Ce&OiowPKUTtjgo$ucDuaIX{%rJ_(6mr*nX zmmyPfaKX{kOeqQyQqruz&>}^1qw;j`BZL0y&kh_uxbHi^``!26W&JQ5y^B}&)v}g%RlSR-?EQ?hv6(MOy9u!d6Wozs#AW2khj8c79BPNYp-3@`D<#cH zFIS>MIgNYW^C+yJKzx1!_!hSHBtj?I&4kH_A@2Sc5S3Pe#9TR&3l+HCF^k4$KcN`e zKz{Wg;&bGP$*h8RL zo&_Z3)uP?<2vnrEhi`#)f!!Jd;9Co890Je7>0A_UG)+J;x{3Z%fhcQzgZrv^)D5qr zUlxP`69HaxbTH-Oh8~~ObOIL!VB_JV_RYSD;Bq;9(+kk$=!O|XF&^4DAg_7|kDZU> z$$l$LYahT&a1=W1U1+$}m~ZMu^K7BV2}N|B5{b$|r1ZT+8yR!Sz!@r$E7~kXc&jVG zd#*XgyaUkbG6JqgQWo*zlBf>=rcR5}N(ZHr|&rHgURsvi`vX6TMpo)pXa5`59KL#w$hGM<0H z$;|6(ntQlvk|`jzW70$%VjDJ_eTl>2JfMILBTuXo$O_LDOZtu&Idl}=HWHAYF48L} zj%Wk6W85vhMf zA#@U5bxZ>D9y-L*KUR`2(qbm0VSy>1Z%nF2YHqPEssAjx0lh@j%q3&7Sgc>06IrHJ S2F>~a0000