Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
[modules/shaper.git] / src / XGUI / XGUI_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_Tools_H
4 #define XGUI_Tools_H
5
6 #include "XGUI.h"
7 #include <QString>
8 #include <QRect>
9
10 #include <ModelAPI_Feature.h>
11
12 #include <ModuleBase_Definitions.h>
13
14 #include <memory>
15
16 class QWidget;
17 class XGUI_Workshop;
18 class ModuleBase_IWorkshop;
19
20 /*!
21  \ingroup GUI
22  \brief Return directory part of the file path.
23
24  If the file path does not include directory part (the file is in the
25  current directory), null string is returned.
26
27  \param path file path
28  \param abs if true (default) \a path parameter is treated as absolute file path
29  \return directory part of the file path
30  */
31 namespace XGUI_Tools {
32
33 /**
34 * Returns directory name from name of file
35 * \param path a path to a file
36 * \param isAbs is absolute or relative path
37 */
38 QString XGUI_EXPORT dir(const QString& path, bool isAbs = true);
39
40 /*!
41  \brief Return file name part of the file path.
42
43  \param path file path
44  \param withExt if true (default) complete file name (with all
45  extension except the last) is returned, otherwise only base name
46  is returned
47  \return file name part of the file path
48  */
49 QString XGUI_EXPORT file(const QString& path, bool withExt = true);
50
51 /*!
52  \brief Add a slash (platform-specific) to the end of \a path
53  if it is not already there.
54  \param path directory path
55  \return modified path (with slash added to the end)
56  */
57 QString XGUI_EXPORT addSlash(const QString& path);
58
59 // The model concerning tools
60
61 /*! Unite object names in one string using the separator between values
62  \param theObjects a list of objects
63  \param theSeparator a separator
64  */
65 QString unionOfObjectNames(const QObjectPtrList& theObjects, const QString& theSeparator);
66
67 /*!
68  Returns true if the feature is a model object
69  \param theFeature a feature
70  */
71 bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
72
73 /*!
74  Returns the string presentation of the given feature
75  \param theFeature a feature
76  */
77 std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
78
79 /*!
80  Returns true if there are no parts in the document, which are not activated or
81  all objects in the list are not PartSet document.
82  It shows the warning control if the result is false.
83  \param theParent a parent for the warning control
84  \param aList a list of object
85  \return a boolean value
86  */
87 bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const QObjectPtrList& aList);
88
89 /*! 
90  Check possibility to rename object
91  \param theObject an object to rename
92  \param theName a name
93  */
94 bool canRename(const ObjectPtr& theObject, const QString& theName);
95
96 /*!
97  Returns true if there are no parts in the document, which are not activated
98  \param theNotActivatedNames out string which contains not activated names
99  \return a boolean value
100  */
101 bool XGUI_EXPORT allDocumentsActivated(QString& theNotActivatedNames);
102
103 /*!
104   Returns a container of referenced feature to the current object in the object document.
105   \param theObject an object, which will be casted to a feature type
106   \param theRefFeatures an output container
107  */
108 void XGUI_EXPORT refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
109                                                 std::set<FeaturePtr>& theRefFeatures);
110
111 /*!
112  Returns true if the object if a sub child of the feature. The feature is casted to the
113  composite one. If it is possible, the sub object check happens. The method is applyed
114  recursively to the feature subs.
115  \param theObject a candidate to be a sub object
116  \param theFeature a candidate to be a composite feature
117  \return a boolean value
118  */
119 bool XGUI_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature);
120
121 /*!
122 */
123 void refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject, const ObjectPtr& theObject,
124                                  const QObjectPtrList& theIgnoreList,
125                                  std::set<FeaturePtr>& theDirectRefFeatures, 
126                                  std::set<FeaturePtr>& theAlreadyProcessed);
127
128 /*!
129  Returns a container of references feature to the source object. The search happens in the object
130  document and in other Part documents if the object belongs to the PartSet. The search is recursive,
131  in other words it is applyed to set of the found objects until it is possible.
132  It do not returns the referenced features to the object if this references is a composite feature
133  which has the object as a sub object.
134  \param theSourceObject an object, which references are searched
135  \param theObject an intermediate recursive object, should be set in the source object
136  \param theIgnoreList an ignore list, the found referernces which coincide with the objects are ignored
137  \param theDirectRefFeatures direct references
138  \param theIndirectRefFeatures indirect references. These are features that refers to the direct features
139  \param theAlreadyProcessed set of processed elements, used for optimization (do not reanalyse processed)
140  \return a boolean value
141  */
142 void XGUI_EXPORT refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject,
143                                              const ObjectPtr& theObject,
144                                              const QObjectPtrList& theIgnoreList,
145                                              std::set<FeaturePtr>& theDirectRefFeatures,
146                                              std::set<FeaturePtr>& theIndirectRefFeatures,
147                                              std::set<FeaturePtr>& theAlreadyProcessed);
148
149 /*!
150 * Returns true if the result is a sub object of some composite object
151 * \param theObject a result object
152 * \returns boolean value
153 */
154 bool XGUI_EXPORT isSubOfComposite(const ObjectPtr& theObject);
155
156 /*!
157  Returns converted workshop
158  \param theWorkshop an interface workshop
159  \return XGUI workshop instance
160 */
161 XGUI_EXPORT XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
162
163 };
164
165 #endif