Salome HOME
refs #207 - "Help" button doesn't work
[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 class OCCViewer_ViewFrame;
38
39 class HYDROGUI_DataModel;
40 class HYDROGUI_Module;
41 class HYDROGUI_Prs;
42
43 class QDockWidget;
44 class Handle(HYDROData_Document);
45
46 /**
47  * \class HYDROGUI_Tool
48  * \brief This class contains several useful methods.
49  */
50 class HYDROGUI_Tool
51 {
52 public:
53   /**
54    * \brief Convert \a TCollection_AsciiString to \a QString
55    */
56   static QString                                  ToQString( const TCollection_AsciiString& );
57
58   /**
59    * \brief Convert \a TCollection_ExtendedString to \a QString
60    */
61   static QString                                  ToQString( const TCollection_ExtendedString& );
62
63   /**
64    * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
65    */
66   static QString                                  ToQString( const Handle(TCollection_HAsciiString)& );
67
68   /**
69    * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
70    */
71   static QString                                  ToQString( const Handle(TCollection_HExtendedString)& );
72
73   /**
74    * \brief Convert \a QString to \a TCollection_AsciiString
75    */
76   static TCollection_AsciiString                  ToAsciiString( const QString& );
77
78   /**
79    * \brief Convert \a QString to \a TCollection_ExtendedString
80    */
81   static TCollection_ExtendedString               ToExtString( const QString& );
82
83   /**
84    * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
85    */
86   static Handle(TCollection_HAsciiString)         ToHAsciiString( const QString& );
87
88   /**
89    * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
90    */
91   static Handle(TCollection_HExtendedString)      ToHExtString( const QString& );
92
93   /**
94    * \brief Get the active study id.
95    * \return active study id
96    */
97   static int                      GetActiveStudyId();
98
99   /**
100    * \brief Get path to the temporary directory.
101    * \param theToCreate flag used to create a directory if it doesn't exist
102    * \return path
103    */
104   static QString                  GetTempDir( const bool theToCreate );
105
106   /**
107    * \brief Set the specified view manager to be active on the desktop.
108    * \param theModule module
109    * \param theViewManager view manager
110    */
111   static void                     SetActiveViewManager( HYDROGUI_Module* theModule,
112                                                         SUIT_ViewManager* theViewManager );
113
114   /**
115    * \brief Returns TRUE if object can be shown on the viewer.
116    * \param theObject data model object to check
117    * \param theViewerType viewer type
118    */
119   static bool                     IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
120                                                            const QString&                  theViewerType = "" );
121
122 /**
123    * \brief Get sub-objects to build presentations.
124    * \param theModule module
125    * \param theSeq sequence of sub-objects
126    */
127   static void                     GetPrsSubObjects( HYDROGUI_Module* theModule,
128                                                     HYDROData_SequenceOfObjects& theSeq );
129
130   /**
131    * \brief Get presentation built for specified data object.
132    * \param theObj data object
133    * \param theObjects list of existing presentations
134    * \return presentation
135    */
136   static HYDROGUI_Prs*            GetPresentation( const Handle(HYDROData_Entity)& theObj,
137                                                    const GraphicsView_ObjectList& theObjects );
138
139   /**
140    * \brief Get list of HYDRO presentations from the specified viewport.
141    * \param theViewPort viewport
142    * \return list of HYDRO presentations
143    */
144   static GraphicsView_ObjectList  GetPrsList( GraphicsView_ViewPort* theViewPort );
145
146   /**
147    * \brief Get list of the selected data objects.
148    * \param theModule module
149    * \return list of the selected data objects
150    */
151   static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
152
153   /**
154    * \brief Get the selected data object (first in the selected list).
155    * \param theModule module
156    * \return selected data object
157    */
158   static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
159
160   /**
161    * \brief Get the geometry data objects from document.
162    * \param theModule module
163    * \return sequence of data objects
164    */
165   static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
166
167   /**
168    * \brief Get kind of objects the selected partition contains.
169    * \param theModule module
170    * \return object kind
171    */
172   static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
173
174   /**
175    * \brief Get the selected GEOM objects.
176    * \param theModule module
177    * \return list of GEOM objects entries
178    */
179   static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule );
180
181   /**
182    * \brief Find the data object with the specified name.
183    * \param theModule module
184    * \param theName name
185    * \param theObjectKind kind of object
186    * \return data object
187    */
188   static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
189                                                     const QString& theName,
190                                                     const ObjectKind theObjectKind = KIND_UNKNOWN );
191
192   /**
193    * \brief Find the data objects with the specified names.
194    * \param theModule module
195    * \param theNames list of names
196    * \param theObjectKind kind of object
197    * \return list of data objects
198    */
199   static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module*   theModule,
200                                                          const QStringList& theNames,
201                                                          const ObjectKind   theObjectKind = KIND_UNKNOWN );
202
203   /**
204    * \brief Generate name for new object.
205    * \param theModule module
206    * \param thePrefix name prefix
207    * \param theUsedNames list of already used names
208    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
209    * \return generated name
210    */
211   static QString                  GenerateObjectName( HYDROGUI_Module*   theModule,
212                                                       const QString&     thePrefix,
213                                                       const QStringList& theUsedNames = QStringList(),
214                                                       const bool         theIsTryToUsePurePrefix = false );
215
216   /**
217    * \brief Get id of the active view.
218    * \param theModule module
219    * \return view id
220    */
221   static size_t                   GetActiveViewId( HYDROGUI_Module* theModule,
222                                                    const QString&   theViewId = QString() );
223
224   /**
225    * \brief Get id of the active GraphicsView view.
226    * \param theModule module
227    * \return view id
228    */
229   static size_t                   GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
230
231   /**
232    * \brief Get id of the active OCC view.
233    * \param theModule module
234    * \return view id
235    */
236   static size_t                   GetActiveOCCViewId( HYDROGUI_Module* theModule );
237
238   /**
239    * \brief Get list of ids of existing GraphicsView views.
240    * \param theModule module
241    * \return list of view ids
242    */
243   static QList<size_t>            GetGraphicsViewIdList( HYDROGUI_Module* theModule );
244
245   /**
246    * \brief Get list of ids of existing OCC views.
247    * \param theModule module
248    * \return list of view ids
249    */
250   static QList<size_t>            GetOCCViewIdList( HYDROGUI_Module* theModule );
251
252
253   /**
254    * \brief Change OCC viewer action visibility.
255    * \param theViewFrame OCC viewer frame
256    * \param theActionId an action index, which state should be changed
257    * \param isShown the action visibility state
258    */
259   static void                     setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
260                                                      const int theActionId,
261                                                      const bool isShown );
262
263   /**
264    * \brief Change OCC viewer action visibility for all opened views.
265    * \param theActionId an action index, which state should be changed
266    * \param isShown the action visibility state
267    */
268   static void                     setOCCActionShown( HYDROGUI_Module* theModule,
269                                                      const int theActionId,
270                                                      const bool isShown );
271
272   /**
273    * \brief Get the list of references (recursively) for the specified data object
274    * \param theObj data object
275    * \param theRefObjects list of reference objects
276    * \param theRefNames list of reference object names
277    */
278   static void                     GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
279                                                        HYDROData_SequenceOfObjects& theRefObjects,
280                                                        QStringList& theRefNames );
281
282   /**
283    * \brief Get the list of back-references for the specified object
284    * \param theModule module
285    * \param theObj data object
286    * \return list of back-reference objects
287    */
288   static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module*                theModule,
289                                                               const Handle(HYDROData_Entity)& theObj );
290
291   /**
292    * \brief Get the map of back-references for the specified list of objects
293    * \param theModule module
294    * \param theObjectNames names of objects
295    * \return map of back-reference objects
296    */
297   static QMap<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module*   theModule,
298                                                                              const QStringList& theObjectNames );
299
300   /**
301    * \brief Get father dock window for widget 
302    * \param wid widget
303    * \return dock window
304    */
305   static QDockWidget*             WindowDock( QWidget* wid );
306
307   /**
308    * \brief Generates the filling color for intersected zone
309    * \param theModule module
310    * \param theZoneNames list of intersected zones
311    * \return result color
312    */
313   static QColor                   GenerateFillingColor( HYDROGUI_Module*   theModule,
314                                                         const QStringList& theZoneNames );
315
316   /**
317    * \brief Generates the filling color for intersected zone
318    * \param theDoc model document
319    * \param theZoneNames list of intersected zones
320    * \return result color
321    */
322   static QColor                   GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
323                                                         const QStringList&                theZoneNames );
324
325   /**
326    * \brief Find names of existing objects of the given kind.
327    * \param theDoc model document
328    * \param theObjectKind kind of object
329    * \return list of names
330    */
331   static QStringList              FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, 
332                                                             const ObjectKind theObjectKind );
333
334   /**
335    * \brief Converts coordinate value to string.
336    * \param theNumber coordinate as a number
337    * \return coordinate as a string
338    */
339   static QString                  GetCoordinateString( const double theNumber );
340 };
341
342 #endif