Salome HOME
Merge branch 'BR_PYTHON_PLUGIN' of newgeom:newgeom.git into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #include "XGUI_Tools.h"
4
5 #include <TopoDS_Shape.hxx>
6 #include <ModelAPI_Object.h>
7 #include <GeomAPI_Shape.h>
8
9 #include <QDir>
10
11 #include <iostream>
12 #include <sstream>
13
14 namespace XGUI_Tools {
15 //******************************************************************
16 QString dir(const QString& path, bool isAbs)
17 {
18   QDir aDir = QFileInfo(path).dir();
19   QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
20   if (dirPath == QString("."))
21     dirPath = QString();
22   return dirPath;
23 }
24
25 //******************************************************************
26 QString file(const QString& path, bool withExt)
27 {
28   QString fPath = path;
29   while (!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
30     fPath.remove(fPath.length() - 1, 1);
31
32   if (withExt)
33     return QFileInfo(fPath).fileName();
34   else
35     return QFileInfo(fPath).completeBaseName();
36 }
37
38 //******************************************************************
39 QString addSlash(const QString& path)
40 {
41   QString res = path;
42   if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
43       && res.at(res.length() - 1) != QChar('\\'))
44     res += QDir::separator();
45   return res;
46 }
47
48 //******************************************************************
49 bool isModelObject(FeaturePtr theFeature)
50 {
51   return theFeature && !theFeature->data();
52 }
53
54 //******************************************************************
55 std::string featureInfo(FeaturePtr theFeature)
56 {
57   std::ostringstream aStream;
58   if (theFeature)
59     aStream << theFeature.get() << " " << theFeature->getKind();
60   return QString(aStream.str().c_str()).toStdString();
61 }
62
63 //******************************************************************
64 /*FeaturePtr realFeature(const FeaturePtr theFeature)
65  {
66  if (theFeature->data()) {
67  return theFeature;
68  } else {
69  ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
70  return aObject->featureRef();
71  }
72  }*/
73
74 }