Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6.1' into Dev_0.6.1
[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 QString dir(const QString& path, bool isAbs)
15 {
16   QDir aDir = QFileInfo(path).dir();
17   QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
18   if (dirPath == QString("."))
19     dirPath = QString();
20   return dirPath;
21 }
22
23 //******************************************************************
24 QString file(const QString& path, bool withExt)
25 {
26   QString fPath = path;
27   while (!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
28     fPath.remove(fPath.length() - 1, 1);
29
30   if (withExt)
31     return QFileInfo(fPath).fileName();
32   else
33     return QFileInfo(fPath).completeBaseName();
34 }
35
36 //******************************************************************
37 QString addSlash(const QString& path)
38 {
39   QString res = path;
40   if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
41       && res.at(res.length() - 1) != QChar('\\'))
42     res += QDir::separator();
43   return res;
44 }
45
46 //******************************************************************
47 bool isModelObject(FeaturePtr theFeature)
48 {
49   return theFeature && !theFeature->data();
50 }
51
52 //******************************************************************
53 std::string featureInfo(FeaturePtr theFeature)
54 {
55   std::ostringstream aStream;
56   if (theFeature)
57     aStream << theFeature.get() << " " << theFeature->getKind();
58   return QString(aStream.str().c_str()).toStdString();
59 }
60
61 //******************************************************************
62 /*FeaturePtr realFeature(const FeaturePtr theFeature)
63  {
64  if (theFeature->data()) {
65  return theFeature;
66  } else {
67  ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
68  return aObject->featureRef();
69  }
70  }*/
71
72 }