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