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_Object.h>
5 #include <GeomAPI_Shape.h>
6
7 #include <QDir>
8
9 #include <iostream>
10 #include <sstream>
11
12 namespace XGUI_Tools
13 {
14 //******************************************************************
15 QString dir(const QString& path, bool isAbs)
16 {
17   QDir aDir = QFileInfo(path).dir();
18   QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
19   if (dirPath == QString("."))
20     dirPath = QString();
21   return dirPath;
22 }
23
24 //******************************************************************
25 QString file(const QString& path, bool withExt)
26 {
27   QString fPath = path;
28   while(!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
29     fPath.remove(fPath.length() - 1, 1);
30
31   if (withExt)
32     return QFileInfo(fPath).fileName();
33   else
34     return QFileInfo(fPath).completeBaseName();
35 }
36
37 //******************************************************************
38 QString extension(const QString& path, bool full)
39 {
40   return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix();
41 }
42
43 //******************************************************************
44 QString addSlash(const QString& path)
45 {
46   QString res = path;
47   if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
48       && res.at(res.length() - 1) != QChar('\\'))
49     res += QDir::separator();
50   return res;
51 }
52
53 //******************************************************************
54 QRect makeRect(const int x1, const int y1, const int x2, const int y2)
55 {
56   return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
57 }
58
59 //******************************************************************
60 bool isModelObject(FeaturePtr theFeature)
61 {
62   return theFeature && !theFeature->data();
63 }
64
65 //******************************************************************
66 std::string featureInfo(FeaturePtr theFeature)
67 {
68   std::ostringstream aStream; 
69   if (theFeature)
70     aStream << theFeature.get() << " " << theFeature->getKind();
71   return QString(aStream.str().c_str()).toStdString();
72 }
73
74 //******************************************************************
75 /*FeaturePtr realFeature(const FeaturePtr theFeature)
76 {
77   if (theFeature->data()) {
78     return theFeature;
79   } else {
80     ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
81     return aObject->featureRef();
82   }
83 }*/
84
85
86 }