Salome HOME
Issue #2556: "What is" window
[modules/shaper.git] / src / XGUI / XGUI_Tools.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_Tools_H
22 #define XGUI_Tools_H
23
24 #include "XGUI.h"
25 #include <QString>
26 #include <QRect>
27
28 #include <ModelAPI_Feature.h>
29 #include <ModuleBase_ViewerPrs.h>
30
31 #include <ModuleBase_Definitions.h>
32
33 #include <memory>
34
35 class QWidget;
36 class XGUI_Workshop;
37 class ModuleBase_IWorkshop;
38
39 /*!
40  \ingroup GUI
41  \brief Commonly used methods in XGUI package and higher.
42  */
43 namespace XGUI_Tools {
44
45 /**
46  \brief Return directory part of the file path.
47
48  If the file path does not include directory part (the file is in the
49  current directory), null string is returned.
50
51  \param path file path
52  \param isAbs if true (default) \a path parameter is treated as absolute file path
53  \return directory part of the file path
54 */
55 QString XGUI_EXPORT dir(const QString& path, bool isAbs = true);
56
57 /*!
58  \brief Return file name part of the file path.
59
60  \param path file path
61  \param withExt if true (default) complete file name (with all
62  extension except the last) is returned, otherwise only base name
63  is returned
64  \return file name part of the file path
65  */
66 QString XGUI_EXPORT file(const QString& path, bool withExt = true);
67
68 /*!
69  \brief Add a slash (platform-specific) to the end of \a path
70  if it is not already there.
71  \param path directory path
72  \return modified path (with slash added to the end)
73  */
74 QString XGUI_EXPORT addSlash(const QString& path);
75
76 // The model concerning tools
77
78 /*! Unite object names in one string using the separator between values
79  \param theObjects a list of objects
80  \param theSeparator a separator
81  */
82 QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator);
83
84 /*!
85  Returns true if the feature is a model object
86  \param theFeature a feature
87  */
88 bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
89
90 /*!
91  Returns the string presentation of the given feature
92  \param theFeature a feature
93  */
94 std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
95
96 /*!
97  Returns true if there are no parts in the document, which are not activated or
98  all objects in the list are not PartSet document.
99  It shows the warning control if the result is false.
100  \param theParent a parent for the warning control
101  \param theFeatures a list of checked features
102  \return a boolean value
103  */
104 bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const std::set<FeaturePtr>& theFeatures);
105
106 /*! 
107  Check possibility to rename object
108  \param theObject an object to rename
109  \param theName a name
110  */
111 bool canRename(const ObjectPtr& theObject, const QString& theName);
112
113 /*!
114  Returns converted workshop
115  \param theWorkshop an interface workshop
116  \return XGUI workshop instance
117 */
118 XGUI_EXPORT XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
119
120
121 /// Generates a presentation name in form: <object_name>/<face>_<face_index>
122 /// \param thePrs a presentation
123 /// \return string value
124 XGUI_EXPORT QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
125 };
126
127 #endif