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