geom/src/XAO/XaoUtils.cxx

160 lines
4.2 KiB
C++
Raw Normal View History

// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#include <cstring>
#include <sstream>
#include <iosfwd>
#include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx"
#include "XaoUtils.hxx"
using namespace XAO;
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::intToString(const int& value)
2013-08-27 11:27:42 +00:00
{
std::ostringstream str;
str << value;
return str.str();
}
2013-08-28 15:22:43 +00:00
const int XaoUtils::stringToInt(const std::string& value)
2013-08-27 11:27:42 +00:00
{
int res;
std::istringstream convert(value);
if ( !(convert >> res) )
2013-09-04 16:08:50 +00:00
throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
2013-08-27 11:27:42 +00:00
return res;
}
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::doubleToString(const double& value)
2013-08-27 11:27:42 +00:00
{
std::ostringstream str;
str << value;
return str.str();
}
2013-08-28 15:22:43 +00:00
const double XaoUtils::stringToDouble(const std::string& value)
{
double res;
std::istringstream convert(value);
if ( !(convert >> res) )
2013-09-04 16:08:50 +00:00
throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
2013-08-28 15:22:43 +00:00
return res;
}
2013-09-04 16:08:50 +00:00
const std::string XaoUtils::booleanToString(const bool& value)
{
if (value)
return "true";
return "false";
}
const bool XaoUtils::stringToBoolean(const std::string& value)
{
if (value == "true" || value == "1")
return true;
if (value == "false" || value == "0")
return false;
throw SALOME_Exception(MsgBuilder() << "Invalid boolean value: " << value);
2013-09-04 16:08:50 +00:00
}
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
{
2013-08-30 14:13:47 +00:00
if (dimension == XAO::VERTEX)
return "vertex";
2013-08-30 14:13:47 +00:00
if (dimension == XAO::EDGE)
return "edge";
2013-08-30 14:13:47 +00:00
if (dimension == XAO::FACE)
return "face";
2013-08-30 14:13:47 +00:00
if (dimension == XAO::SOLID)
return "solid";
2013-08-30 14:13:47 +00:00
if (dimension == XAO::WHOLE)
2013-08-27 11:27:42 +00:00
return "whole";
throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
}
2013-08-28 15:22:43 +00:00
const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
{
2013-08-28 15:22:43 +00:00
if (dimension == "vertex")
2013-08-30 14:13:47 +00:00
return XAO::VERTEX;
2013-08-28 15:22:43 +00:00
if (dimension == "edge")
2013-08-30 14:13:47 +00:00
return XAO::EDGE;
2013-08-28 15:22:43 +00:00
if (dimension == "face")
2013-08-30 14:13:47 +00:00
return XAO::FACE;
2013-08-28 15:22:43 +00:00
if (dimension == "solid")
2013-08-30 14:13:47 +00:00
return XAO::SOLID;
2013-08-28 15:22:43 +00:00
if (dimension == "whole")
2013-08-30 14:13:47 +00:00
return XAO::WHOLE;
throw SALOME_Exception(MsgBuilder() << "Bad dimension: " << dimension);
}
2013-08-27 11:27:42 +00:00
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
2013-08-27 11:27:42 +00:00
{
2013-08-30 14:13:47 +00:00
if (type ==XAO:: BOOLEAN)
2013-08-27 11:27:42 +00:00
return "boolean";
2013-08-30 14:13:47 +00:00
if (type == XAO::INTEGER)
2013-08-27 11:27:42 +00:00
return "integer";
2013-08-30 14:13:47 +00:00
if (type == XAO::DOUBLE)
2013-08-27 11:27:42 +00:00
return "double";
2013-08-30 14:13:47 +00:00
if (type == XAO::STRING)
2013-08-27 11:27:42 +00:00
return "string";
throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
2013-08-27 11:27:42 +00:00
}
2013-08-28 15:22:43 +00:00
const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
2013-08-27 11:27:42 +00:00
{
2013-08-28 15:22:43 +00:00
if (type == "boolean")
2013-08-30 14:13:47 +00:00
return XAO::BOOLEAN;
2013-08-28 15:22:43 +00:00
if (type == "integer")
2013-08-30 14:13:47 +00:00
return XAO::INTEGER;
2013-08-28 15:22:43 +00:00
if (type == "double")
2013-08-30 14:13:47 +00:00
return XAO::DOUBLE;
2013-08-28 15:22:43 +00:00
if (type == "string")
2013-08-30 14:13:47 +00:00
return XAO::STRING;
throw SALOME_Exception(MsgBuilder() << "Bad type: " << type);
2013-08-27 11:27:42 +00:00
}
2013-08-30 14:13:47 +00:00
const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
{
if (format == XAO::BREP)
return "BREP";
if (format == XAO::STEP)
return "STEP";
throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
2013-08-30 14:13:47 +00:00
}
const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
{
if (format == "BREP")
return XAO::BREP;
if (format == "STEP")
return XAO::STEP;
throw SALOME_Exception(MsgBuilder() << "Bad format: " << format);
2013-08-30 14:13:47 +00:00
}