Salome HOME
18a3d587e4df9c2034c03cffbc23543d192cf73b
[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 Get sub-objects to build presentations.
116    * \param theModule module
117    * \param theSeq sequence of sub-objects
118    */
119   static void                     GetPrsSubObjects( HYDROGUI_Module* theModule,
120                                                     HYDROData_SequenceOfObjects& theSeq );
121
122   /**
123    * \brief Get presentation built for specified data object.
124    * \param theObj data object
125    * \param theObjects list of existing presentations
126    * \return presentation
127    */
128   static HYDROGUI_Prs*            GetPresentation( const Handle(HYDROData_Entity)& theObj,
129                                                    const GraphicsView_ObjectList& theObjects );
130
131   /**
132    * \brief Get list of HYDRO presentations from the specified viewport.
133    * \param theViewPort viewport
134    * \return list of HYDRO presentations
135    */
136   static GraphicsView_ObjectList  GetPrsList( GraphicsView_ViewPort* theViewPort );
137
138   /**
139    * \brief Get list of the selected data objects.
140    * \param theModule module
141    * \return list of the selected data objects
142    */
143   static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
144
145   /**
146    * \brief Get the selected data object (first in the selected list).
147    * \param theModule module
148    * \return selected data object
149    */
150   static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
151
152   /**
153    * \brief Get the geometry data objects from document.
154    * \param theModule module
155    * \return sequence of data objects
156    */
157   static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
158
159   /**
160    * \brief Get kind of objects the selected partition contains.
161    * \param theModule module
162    * \return object kind
163    */
164   static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
165
166   /**
167    * \brief Get the selected GEOM objects.
168    * \param theModule module
169    * \return list of GEOM objects entries
170    */
171   static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule );
172
173   /**
174    * \brief Find the data object with the specified name.
175    * \param theModule module
176    * \param theName name
177    * \param theObjectKind kind of object
178    * \return data object
179    */
180   static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
181                                                     const QString& theName,
182                                                     const ObjectKind theObjectKind = KIND_UNKNOWN );
183
184   /**
185    * \brief Find the data objects with the specified names.
186    * \param theModule module
187    * \param theNames list of names
188    * \param theObjectKind kind of object
189    * \return list of data objects
190    */
191   static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module*   theModule,
192                                                          const QStringList& theNames,
193                                                          const ObjectKind   theObjectKind = KIND_UNKNOWN );
194
195   /**
196    * \brief Generate name for new object.
197    * \param theModule module
198    * \param thePrefix name prefix
199    * \param theUsedNames list of already used names
200    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
201    * \return generated name
202    */
203   static QString                  GenerateObjectName( HYDROGUI_Module*   theModule,
204                                                       const QString&     thePrefix,
205                                                       const QStringList& theUsedNames = QStringList(),
206                                                       const bool         theIsTryToUsePurePrefix = false );
207
208   /**
209    * \brief Get id of the active view.
210    * \param theModule module
211    * \return view id
212    */
213   static size_t                   GetActiveViewId( HYDROGUI_Module* theModule,
214                                                    const QString&   theViewId = QString() );
215
216   /**
217    * \brief Get id of the active GraphicsView view.
218    * \param theModule module
219    * \return view id
220    */
221   static size_t                   GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
222
223   /**
224    * \brief Get id of the active OCC view.
225    * \param theModule module
226    * \return view id
227    */
228   static size_t                   GetActiveOCCViewId( HYDROGUI_Module* theModule );
229
230   /**
231    * \brief Get list of ids of existing GraphicsView views.
232    * \param theModule module
233    * \return list of view ids
234    */
235   static QList<size_t>            GetGraphicsViewIdList( HYDROGUI_Module* theModule );
236
237   /**
238    * \brief Get list of ids of existing OCC views.
239    * \param theModule module
240    * \return list of view ids
241    */
242   static QList<size_t>            GetOCCViewIdList( HYDROGUI_Module* theModule );
243
244
245   /**
246    * \brief Change OCC viewer action visibility.
247    * \param theViewFrame OCC viewer frame
248    * \param theActionId an action index, which state should be changed
249    * \param isShown the action visibility state
250    */
251   static void                     setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
252                                                      const int theActionId,
253                                                      const bool isShown );
254
255   /**
256    * \brief Change OCC viewer action visibility for all opened views.
257    * \param theActionId an action index, which state should be changed
258    * \param isShown the action visibility state
259    */
260   static void                     setOCCActionShown( HYDROGUI_Module* theModule,
261                                                      const int theActionId,
262                                                      const bool isShown );
263
264   /**
265    * \brief Get the list of references (recursively) for the specified image object
266    * \param theImage image data object
267    * \param theRefObjects list of reference objects
268    * \param theRefNames list of reference object names
269    */
270   static void                     GetObjectReferences( const Handle(HYDROData_Image)& theImage,
271                                                        HYDROData_SequenceOfObjects& theRefObjects,
272                                                        QStringList& theRefNames );
273
274   /**
275    * \brief Get the list of back-references for the specified object
276    * \param theModule module
277    * \param theObj data object
278    * \param theBackRefObjects list of back-reference objects
279    * \param theBackRefNames list of back-reference object names
280    */
281   static void                     GetObjectBackReferences( HYDROGUI_Module* theModule,
282                                                            const Handle(HYDROData_Entity)& theObj,
283                                                            HYDROData_SequenceOfObjects& theBackRefObjects,
284                                                            QStringList& theBackRefNames );
285
286   /**
287    * \brief Get father dock window for widget 
288    * \param wid widget
289    * \return dock window
290    */
291   static QDockWidget*             WindowDock( QWidget* wid );
292
293   /**
294    * \brief Generates the filling color for intersected zone
295    * \param theModule module
296    * \param theZoneNames list of intersected zones
297    * \return result color
298    */
299   static QColor                   GenerateFillingColor( HYDROGUI_Module*   theModule,
300                                                         const QStringList& theZoneNames );
301
302   /**
303    * \brief Generates the filling color for intersected zone
304    * \param theDoc model document
305    * \param theZoneNames list of intersected zones
306    * \return result color
307    */
308   static QColor                   GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
309                                                         const QStringList&                theZoneNames );
310
311   /**
312    * \brief Find names of existing objects of the given kind.
313    * \param theDoc model document
314    * \param theObjectKind kind of object
315    * \return list of names
316    */
317   static QStringList              FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc, 
318                                                             const ObjectKind theObjectKind );
319
320   /**
321    * \brief Converts coordinate value to string.
322    * \param theNumber coordinate as a number
323    * \return coordinate as a string
324    */
325   static QString                  GetCoordinateString( const double theNumber );
326 };
327
328 #endif