1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "XGUI_Tools.h"
5 #include <TopoDS_Shape.hxx>
6 #include <ModelAPI_Object.h>
7 #include <ModelAPI_Result.h>
8 #include <ModelAPI_ResultParameter.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Document.h>
12 #include <ModelAPI_ResultPart.h>
14 #include <GeomAPI_Shape.h>
17 #include <QMessageBox>
22 namespace XGUI_Tools {
23 //******************************************************************
24 QString dir(const QString& path, bool isAbs)
26 QDir aDir = QFileInfo(path).dir();
27 QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
28 if (dirPath == QString("."))
33 //******************************************************************
34 QString file(const QString& path, bool withExt)
37 while (!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
38 fPath.remove(fPath.length() - 1, 1);
41 return QFileInfo(fPath).fileName();
43 return QFileInfo(fPath).completeBaseName();
46 //******************************************************************
47 QString addSlash(const QString& path)
50 if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
51 && res.at(res.length() - 1) != QChar('\\'))
52 res += QDir::separator();
56 //******************************************************************
57 bool isModelObject(FeaturePtr theFeature)
59 return theFeature && !theFeature->data();
62 //******************************************************************
63 std::string featureInfo(FeaturePtr theFeature)
65 std::ostringstream aStream;
67 aStream << theFeature.get() << " " << theFeature->getKind();
68 return QString(aStream.str().c_str()).toStdString();
71 //******************************************************************
72 /*FeaturePtr realFeature(const FeaturePtr theFeature)
74 if (theFeature->data()) {
77 ObjectPtr aObject = std::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
78 return aObject->featureRef();
82 //******************************************************************
83 bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects)
86 QString aNotActivatedNames;
87 if (!XGUI_Tools::allDocumentsActivated(aNotActivatedNames)) {
88 DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
89 bool aFoundPartSetObject = false;
90 foreach (ObjectPtr aObj, theObjects) {
91 if (aObj->groupName() == ModelAPI_ResultPart::group())
93 aFoundPartSetObject = aObj->document() == aModuleDoc;
95 if (aFoundPartSetObject) {
96 QMessageBox::StandardButton aRes = QMessageBox::warning(theParent, QObject::tr("Warning"),
97 QObject::tr("Selected objects can be used in Part documents which are not loaded: \
98 %1. Whould you like to continue?").arg(aNotActivatedNames),
99 QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
100 aResult = aRes == QMessageBox::Yes;
106 //******************************************************************
107 bool allDocumentsActivated(QString& theNotActivatedNames)
109 bool anAllPartActivated = true;
110 QStringList aRefNames;
112 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
113 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
114 for (int i = 0; i < aSize; i++) {
115 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
116 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
117 if (!aPart->isActivated()) {
118 anAllPartActivated = false;
119 aRefNames.append(aObject->data()->name().c_str());
122 theNotActivatedNames = aRefNames.join(", ");
123 return anAllPartActivated;