Salome HOME
Fix XAO Part uppercase
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_Tools.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <ExchangePlugin_Tools.h>
22
23 #include <sstream>
24
25 std::list<std::string> ExchangePlugin_Tools::split(const std::string& theString, char theDelimiter)
26 {
27   std::list<std::string> theResult;
28   std::istringstream aStream(theString);
29   std::string aSection;
30   while (std::getline(aStream, aSection, theDelimiter))
31     theResult.push_back(aSection);
32   return theResult;
33 }
34
35 std::string ExchangePlugin_Tools::selectionType2xaoDimension(const std::string& theType)
36 {
37   // if the selection is done in the GUI, the type is lower case
38   // if the selection is done in python, the type is in upper case
39   if (theType == "Vertices" || theType == "vertex" || theType == "VERTEX")
40     return "vertex";
41   else if (theType == "Edges" || theType == "edge" || theType == "EDGE")
42     return "edge";
43   else if (theType == "Faces" || theType == "face" || theType == "FACE")
44     return "face";
45   else if (theType == "Solids" || theType == "solid" || theType == "SOLID")
46     return "solid";
47   else if (theType == "Part" || theType == "part" || theType == "PART")
48     return "part";
49
50   return std::string();
51 }
52
53 std::string ExchangePlugin_Tools::xaoDimension2selectionType(const std::string& theDimension)
54 {
55   if (theDimension == "vertex")
56     return "vertex";
57   else if (theDimension == "edge")
58     return "edge";
59   else if (theDimension == "face")
60     return "face";
61   else if (theDimension == "solid")
62     return "solid";
63
64   return std::string();
65 }
66
67
68 std::string ExchangePlugin_Tools::valuesType2xaoType(
69   const ModelAPI_AttributeTables::ValueType& theType)
70 {
71   switch(theType) {
72   case ModelAPI_AttributeTables::BOOLEAN:
73     return "boolean";
74   case ModelAPI_AttributeTables::INTEGER:
75     return "integer";
76   case ModelAPI_AttributeTables::DOUBLE:
77     return "double";
78   case ModelAPI_AttributeTables::STRING:
79     return "string";
80   }
81   return "";
82 }
83
84 ModelAPI_AttributeTables::ValueType ExchangePlugin_Tools::xaoType2valuesType(std::string theType)
85 {
86   if (theType == "boolean")
87     return ModelAPI_AttributeTables::BOOLEAN;
88   if (theType == "integer")
89     return ModelAPI_AttributeTables::INTEGER;
90   if (theType == "double")
91     return ModelAPI_AttributeTables::DOUBLE;
92   if (theType == "string")
93     return ModelAPI_AttributeTables::STRING;
94   return ModelAPI_AttributeTables::DOUBLE;
95 }