Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Tool.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_TOOL_H
24 #define HYDROGUI_TOOL_H
25
26 #include <HYDROData_Image.h>
27
28 #include <GraphicsView_Defs.h>
29 #include <GraphicsView_ViewPort.h>
30
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
33 #include <TCollection_HAsciiString.hxx>
34 #include <TCollection_HExtendedString.hxx>
35
36 class SUIT_ViewManager;
37
38 class HYDROGUI_DataModel;
39 class HYDROGUI_Module;
40 class HYDROGUI_Prs;
41
42 class QDockWidget;
43 class Handle(HYDROData_Document);
44
45 /**
46  * \class HYDROGUI_Tool
47  * \brief This class contains several useful methods.
48  */
49 class HYDROGUI_Tool
50 {
51 public:
52   /**
53    * \brief Convert \a TCollection_AsciiString to \a QString
54    */
55   static QString                                  ToQString( const TCollection_AsciiString& );
56
57   /**
58    * \brief Convert \a TCollection_ExtendedString to \a QString
59    */
60   static QString                                  ToQString( const TCollection_ExtendedString& );
61
62   /**
63    * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
64    */
65   static QString                                  ToQString( const Handle(TCollection_HAsciiString)& );
66
67   /**
68    * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
69    */
70   static QString                                  ToQString( const Handle(TCollection_HExtendedString)& );
71
72   /**
73    * \brief Convert \a QString to \a TCollection_AsciiString
74    */
75   static TCollection_AsciiString                  ToAsciiString( const QString& );
76
77   /**
78    * \brief Convert \a QString to \a TCollection_ExtendedString
79    */
80   static TCollection_ExtendedString               ToExtString( const QString& );
81
82   /**
83    * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
84    */
85   static Handle(TCollection_HAsciiString)         ToHAsciiString( const QString& );
86
87   /**
88    * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
89    */
90   static Handle(TCollection_HExtendedString)      ToHExtString( const QString& );
91
92   /**
93    * \brief Get the active study id.
94    * \return active study id
95    */
96   static int                      GetActiveStudyId();
97
98   /**
99    * \brief Get path to the temporary directory.
100    * \param theToCreate flag used to create a directory if it doesn't exist
101    * \return path
102    */
103   static QString                  GetTempDir( const bool theToCreate );
104
105   /**
106    * \brief Set the specified view manager to be active on the desktop.
107    * \param theModule module
108    * \param theViewManager view manager
109    */
110   static void                     SetActiveViewManager( HYDROGUI_Module* theModule,
111                                                         SUIT_ViewManager* theViewManager );
112
113   /**
114    * \brief Get sub-objects to build presentations.
115    * \param theModule module
116    * \param theSeq sequence of sub-objects
117    */
118   static void                     GetPrsSubObjects( HYDROGUI_Module* theModule,
119                                                     HYDROData_SequenceOfObjects& theSeq );
120
121   /**
122    * \brief Get presentation built for specified data object.
123    * \param theObj data object
124    * \param theObjects list of existing presentations
125    * \return presentation
126    */
127   static HYDROGUI_Prs*            GetPresentation( const Handle(HYDROData_Entity)& theObj,
128                                                    const GraphicsView_ObjectList& theObjects );
129
130   /**
131    * \brief Get list of HYDRO presentations from the specified viewport.
132    * \param theViewPort viewport
133    * \return list of HYDRO presentations
134    */
135   static GraphicsView_ObjectList  GetPrsList( GraphicsView_ViewPort* theViewPort );
136
137   /**
138    * \brief Get list of the selected data objects.
139    * \param theModule module
140    * \return list of the selected data objects
141    */
142   static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
143
144   /**
145    * \brief Get the selected data object (first in the selected list).
146    * \param theModule module
147    * \return selected data object
148    */
149   static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
150
151   /**
152    * \brief Get the geometry data objects from document.
153    * \param theModule module
154    * \return sequence of data objects
155    */
156   static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
157
158   /**
159    * \brief Get kind of objects the selected partition contains.
160    * \param theModule module
161    * \return object kind
162    */
163   static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
164
165   /**
166    * \brief Get the selected GEOM objects.
167    * \param theModule module
168    * \return list of GEOM objects entries
169    */
170   static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule );
171
172   /**
173    * \brief Find the data object with the specified name.
174    * \param theModule module
175    * \param theName name
176    * \param theObjectKind kind of object
177    * \return data object
178    */
179   static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
180                                                     const QString& theName,
181                                                     const ObjectKind theObjectKind = KIND_UNKNOWN );
182
183   /**
184    * \brief Find the data objects with the specified names.
185    * \param theModule module
186    * \param theNames list of names
187    * \param theObjectKind kind of object
188    * \return list of data objects
189    */
190   static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module*   theModule,
191                                                          const QStringList& theNames,
192                                                          const ObjectKind   theObjectKind = KIND_UNKNOWN );
193
194   /**
195    * \brief Generate name for new object.
196    * \param theModule module
197    * \param thePrefix name prefix
198    * \param theUsedNames list of already used names
199    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
200    * \return generated name
201    */
202   static QString                  GenerateObjectName( HYDROGUI_Module*   theModule,
203                                                       const QString&     thePrefix,
204                                                       const QStringList& theUsedNames = QStringList(),
205                                                       const bool         theIsTryToUsePurePrefix = false );
206
207   /**
208    * \brief Get id of the active view.
209    * \param theModule module
210    * \return view id
211    */
212   static size_t                   GetActiveViewId( HYDROGUI_Module* theModule,
213                                                    const QString&   theViewId = QString() );
214
215   /**
216    * \brief Get id of the active GraphicsView view.
217    * \param theModule module
218    * \return view id
219    */
220   static size_t                   GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
221
222   /**
223    * \brief Get id of the active OCC view.
224    * \param theModule module
225    * \return view id
226    */
227   static size_t                   GetActiveOCCViewId( HYDROGUI_Module* theModule );
228
229   /**
230    * \brief Get list of ids of existing GraphicsView views.
231    * \param theModule module
232    * \return list of view ids
233    */
234   static QList<size_t>            GetGraphicsViewIdList( HYDROGUI_Module* theModule );
235
236   /**
237    * \brief Get list of ids of existing OCC views.
238    * \param theModule module
239    * \return list of view ids
240    */
241   static QList<size_t>            GetOCCViewIdList( HYDROGUI_Module* theModule );
242
243   /**
244    * \brief Get the list of references (recursively) for the specified image object
245    * \param theImage image data object
246    * \param theRefObjects list of reference objects
247    * \param theRefNames list of reference object names
248    */
249   static void                     GetObjectReferences( const Handle(HYDROData_Image)& theImage,
250                                                        HYDROData_SequenceOfObjects& theRefObjects,
251                                                        QStringList& theRefNames );
252
253   /**
254    * \brief Get the list of back-references for the specified object
255    * \param theModule module
256    * \param theObj data object
257    * \param theBackRefObjects list of back-reference objects
258    * \param theBackRefNames list of back-reference object names
259    */
260   static void                     GetObjectBackReferences( HYDROGUI_Module* theModule,
261                                                            const Handle(HYDROData_Entity)& theObj,
262                                                            HYDROData_SequenceOfObjects& theBackRefObjects,
263                                                            QStringList& theBackRefNames );
264
265   /**
266    * \brief Get father dock window for widget 
267    * \param wid widget
268    * \return dock window
269    */
270   static QDockWidget*             WindowDock( QWidget* wid );
271
272   /**
273    * \brief Generates the filling color for intersected zone
274    * \param theModule module
275    * \param theZoneNames list of intersected zones
276    * \return result color
277    */
278   static QColor                   GenerateFillingColor( HYDROGUI_Module*   theModule,
279                                                         const QStringList& theZoneNames );
280
281   /**
282    * \brief Generates the filling color for intersected zone
283    * \param theDoc model document
284    * \param theZoneNames list of intersected zones
285    * \return result color
286    */
287   static QColor                   GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
288                                                         const QStringList&                theZoneNames );
289
290   /**
291    * \brief Find names of existing objects of the given kind.
292    * \param theDoc model document
293    * \param theObjectKind kind of object
294    * \return list of names
295    */
296   static QStringList              FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, 
297                                                             const ObjectKind theObjectKind );
298 };
299
300 #endif