Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
1 #include "XGUI_Tools.h"
2
3 #include <TopoDS_Shape.hxx>
4 #include <ModelAPI_Feature.h>
5
6 #include <QDir>
7
8 #include <iostream>
9 #include <sstream>
10
11 //******************************************************************
12 QString dir(const QString& path, bool isAbs)
13 {
14   QDir aDir = QFileInfo(path).dir();
15   QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
16   if (dirPath == QString("."))
17     dirPath = QString();
18   return dirPath;
19 }
20
21 //******************************************************************
22 QString file(const QString& path, bool withExt)
23 {
24   QString fPath = path;
25   while(!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
26     fPath.remove(fPath.length() - 1, 1);
27
28   if (withExt)
29     return QFileInfo(fPath).fileName();
30   else
31     return QFileInfo(fPath).completeBaseName();
32 }
33
34 //******************************************************************
35 QString extension(const QString& path, bool full)
36 {
37   return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix();
38 }
39
40 //******************************************************************
41 QString addSlash(const QString& path)
42 {
43   QString res = path;
44   if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
45       && res.at(res.length() - 1) != QChar('\\'))
46     res += QDir::separator();
47   return res;
48 }
49
50 //******************************************************************
51 QRect makeRect(const int x1, const int y1, const int x2, const int y2)
52 {
53   return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
54 }
55
56 //******************************************************************
57 std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
58 {
59   std::ostringstream aStream; 
60   if (theFeature)
61     aStream << theFeature.get();
62   return QString(aStream.str().c_str()).toStdString();
63 }
64