Salome HOME
Merge branch 'master' into V9_3_BR
[modules/shaper.git] / src / XGUI / XGUI_Tools.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef XGUI_Tools_H
21 #define XGUI_Tools_H
22
23 #include "XGUI.h"
24 #include <QString>
25 #include <QRect>
26
27 #include <ModelAPI_Feature.h>
28 #include <ModuleBase_ViewerPrs.h>
29
30 #include <ModuleBase_Definitions.h>
31
32 #include <memory>
33
34 class QWidget;
35 class XGUI_Workshop;
36 class ModuleBase_IWorkshop;
37
38 /*!
39  \ingroup GUI
40  \brief Commonly used methods in XGUI package and higher.
41  */
42 namespace XGUI_Tools {
43
44 /**
45  \brief Return directory part of the file path.
46
47  If the file path does not include directory part (the file is in the
48  current directory), null string is returned.
49
50  \param path file path
51  \param isAbs if true (default) \a path parameter is treated as absolute file path
52  \return directory part of the file path
53 */
54 QString XGUI_EXPORT dir(const QString& path, bool isAbs = true);
55
56 /*!
57  \brief Return file name part of the file path.
58
59  \param path file path
60  \param withExt if true (default) complete file name (with all
61  extension except the last) is returned, otherwise only base name
62  is returned
63  \return file name part of the file path
64  */
65 QString XGUI_EXPORT file(const QString& path, bool withExt = true);
66
67 /*!
68  \brief Add a slash (platform-specific) to the end of \a path
69  if it is not already there.
70  \param path directory path
71  \return modified path (with slash added to the end)
72  */
73 QString XGUI_EXPORT addSlash(const QString& path);
74
75 // The model concerning tools
76
77 /*! Unite object names in one string using the separator between values
78  \param theObjects a list of objects
79  \param theSeparator a separator
80  */
81 QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator);
82
83 /*!
84  Returns true if the feature is a model object
85  \param theFeature a feature
86  */
87 bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
88
89 /*!
90  Returns the string presentation of the given feature
91  \param theFeature a feature
92  */
93 std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
94
95 /*!
96  Returns true if there are no parts in the document, which are not activated or
97  all objects in the list are not PartSet document.
98  It shows the warning control if the result is false.
99  \param theParent a parent for the warning control
100  \param theFeatures a list of checked features
101  \return a boolean value
102  */
103 bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const std::set<FeaturePtr>& theFeatures);
104
105 /*! 
106  Check possibility to rename object
107  \param theObject an object to rename
108  \param theName a name
109  */
110 bool canRename(const ObjectPtr& theObject, const QString& theName);
111
112 /*!
113  Checks that the given string contains only ASCII symbols
114  \param theStr a string to check
115  */
116 bool isAscii(const QString& theStr);
117
118 /*!
119  Returns converted workshop
120  \param theWorkshop an interface workshop
121  \return XGUI workshop instance
122 */
123 XGUI_EXPORT XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
124
125
126 /// Generates a presentation name in form: <object_name>/<face>_<face_index>
127 /// \param thePrs a presentation
128 /// \return string value
129 XGUI_EXPORT QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
130
131 /// Creates and returns the temporary directory (with random name) using the environment variable
132 /// path to location of such directories,
133 std::string getTmpDirByEnv( const char* thePathEnv);
134
135 /// Removes files and directory where they are located
136 void removeTemporaryFiles(const std::string& theDirectory,
137   const std::list<std::string>& theFiles);
138 };
139
140 #endif