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