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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROGUI_TOOL_H
20 #define HYDROGUI_TOOL_H
22 #include <HYDROData_Image.h>
24 #include <GraphicsView_Defs.h>
25 #include <GraphicsView_ViewPort.h>
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TCollection_HAsciiString.hxx>
30 #include <TCollection_HExtendedString.hxx>
32 #include <Image_PixMap.hxx>
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(GEOM_Gen)
38 class SUIT_ViewManager;
39 class OCCViewer_ViewFrame;
41 class HYDROGUI_DataModel;
42 class HYDROGUI_Module;
46 class Handle(HYDROData_Document);
49 * \class HYDROGUI_Tool
50 * \brief This class contains several useful methods.
56 * \brief Convert \a TCollection_AsciiString to \a QString
58 static QString ToQString( const TCollection_AsciiString& );
61 * \brief Convert \a TCollection_ExtendedString to \a QString
63 static QString ToQString( const TCollection_ExtendedString& );
66 * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
68 static QString ToQString( const Handle(TCollection_HAsciiString)& );
71 * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
73 static QString ToQString( const Handle(TCollection_HExtendedString)& );
76 * \brief Convert \a QString to \a TCollection_AsciiString
78 static TCollection_AsciiString ToAsciiString( const QString& );
81 * \brief Convert \a QString to \a TCollection_ExtendedString
83 static TCollection_ExtendedString ToExtString( const QString& );
86 * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
88 static Handle(TCollection_HAsciiString) ToHAsciiString( const QString& );
91 * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
93 static Handle(TCollection_HExtendedString) ToHExtString( const QString& );
96 * \brief Get the active study id.
97 * \return active study id
99 static int GetActiveStudyId();
102 * \brief Get path to the temporary directory.
103 * \param theToCreate flag used to create a directory if it doesn't exist
106 static QString GetTempDir( const bool theToCreate );
109 * \brief Set the specified view manager to be active on the desktop.
110 * \param theModule module
111 * \param theViewManager view manager
113 static void SetActiveViewManager( HYDROGUI_Module* theModule,
114 SUIT_ViewManager* theViewManager );
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
121 static bool IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
122 const QString& theViewerType = "" );
125 * \brief Get sub-objects to build presentations.
126 * \param theModule module
127 * \param theSeq sequence of sub-objects
129 static void GetPrsSubObjects( HYDROGUI_Module* theModule,
130 HYDROData_SequenceOfObjects& theSeq );
133 * \brief Get presentation built for specified data object.
134 * \param theObj data object
135 * \param theObjects list of existing presentations
136 * \return presentation
138 static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Entity)& theObj,
139 const GraphicsView_ObjectList& theObjects );
142 * \brief Get list of HYDRO presentations from the specified viewport.
143 * \param theViewPort viewport
144 * \return list of HYDRO presentations
146 static GraphicsView_ObjectList GetPrsList( GraphicsView_ViewPort* theViewPort );
149 * \brief Get list of the selected data objects.
150 * \param theModule module
151 * \return list of the selected data objects
153 static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
156 * \brief Get the selected data object (first in the selected list).
157 * \param theModule module
158 * \return selected data object
160 static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
163 * \brief Get the geometry data objects from document.
164 * \param theModule module
165 * \return sequence of data objects
167 static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
170 * \brief Get kind of objects the selected partition contains.
171 * \param theModule module
172 * \return object kind
174 static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
177 * \brief Find the data object with the specified name.
178 * \param theModule module
179 * \param theName name
180 * \param theObjectKind kind of object
181 * \return data object
183 static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
184 const QString& theName,
185 const ObjectKind theObjectKind = KIND_UNKNOWN );
188 * \brief Find the data objects with the specified names.
189 * \param theModule module
190 * \param theNames list of names
191 * \param theObjectKind kind of object
192 * \return list of data objects
194 static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module* theModule,
195 const QStringList& theNames,
196 const ObjectKind theObjectKind = KIND_UNKNOWN );
199 * \brief Generate name for new object.
200 * \param theModule module
201 * \param thePrefix name prefix
202 * \param theUsedNames list of already used names
203 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
204 * \return generated name
206 static QString GenerateObjectName( HYDROGUI_Module* theModule,
207 const QString& thePrefix,
208 const QStringList& theUsedNames = QStringList(),
209 const bool theIsTryToUsePurePrefix = false );
212 * \brief Get id of the active view.
213 * \param theModule module
216 static size_t GetActiveViewId( HYDROGUI_Module* theModule,
217 const QString& theViewId = QString() );
220 * \brief Get id of the active GraphicsView view.
221 * \param theModule module
224 static size_t GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
227 * \brief Get id of the active OCC view.
228 * \param theModule module
231 static size_t GetActiveOCCViewId( HYDROGUI_Module* theModule );
234 * \brief Get list of ids of existing GraphicsView views.
235 * \param theModule module
236 * \return list of view ids
238 static QList<size_t> GetGraphicsViewIdList( HYDROGUI_Module* theModule );
241 * \brief Get list of ids of existing OCC views.
242 * \param theModule module
243 * \return list of view ids
245 static QList<size_t> GetOCCViewIdList( HYDROGUI_Module* theModule );
249 * \brief Change OCC viewer action visibility.
250 * \param theViewFrame OCC viewer frame
251 * \param theActionId an action index, which state should be changed
252 * \param isShown the action visibility state
254 static void setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
255 const int theActionId,
256 const bool isShown );
259 * \brief Change OCC viewer action visibility for all opened views.
260 * \param theActionId an action index, which state should be changed
261 * \param isShown the action visibility state
263 static void setOCCActionShown( HYDROGUI_Module* theModule,
264 const int theActionId,
265 const bool isShown );
268 * \brief Get the list of references (recursively) for the specified data object
269 * \param theObj data object
270 * \param theRefObjects list of reference objects
271 * \param theRefNames list of reference object names
273 static void GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
274 HYDROData_SequenceOfObjects& theRefObjects,
275 QStringList& theRefNames );
278 * \brief Get the list of back-references for the specified object
279 * \param theModule module
280 * \param theObj data object
281 * \return list of back-reference objects
283 static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module* theModule,
284 const Handle(HYDROData_Entity)& theObj );
287 * \brief Get the map of back-references for the specified list of objects
288 * \param theModule module
289 * \param theObjectNames names of objects
290 * \return map of back-reference objects
292 static QMap<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module* theModule,
293 const QStringList& theObjectNames );
296 * \brief Get father dock window for widget
298 * \return dock window
300 static QDockWidget* WindowDock( QWidget* wid );
303 * \brief Generates the filling color for intersected zone
304 * \param theModule module
305 * \param theZoneNames list of intersected zones
306 * \return result color
308 static QColor GenerateFillingColor( HYDROGUI_Module* theModule,
309 const QStringList& theZoneNames );
312 * \brief Generates the filling color for intersected zone
313 * \param theDoc model document
314 * \param theZoneNames list of intersected zones
315 * \return result color
317 static QColor GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
318 const QStringList& theZoneNames );
321 * \brief Find names of existing objects of the given kind.
322 * \param theDoc model document
323 * \param theObjectKind kind of object
324 * \return list of names
326 static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
327 const ObjectKind theObjectKind,
328 bool isCheckValidProfile = false );
331 * \brief Converts coordinate value to string.
332 * \param theNumber coordinate as a number
333 * \return coordinate as a string
335 static QString GetCoordinateString( const double theNumber, bool isInLocale );
338 * \brief Converts Qt QImage object to OCCT Image_PixMap object.
339 * \param theImage QImage object
340 * \return Image_PixMap object
342 static Handle(Image_PixMap) Pixmap( const QImage& theImage );
345 * \brief Get the selected GEOM objects.
346 * \param theModule the module
347 * \param theTypes the acceptable GEOM object types
348 * \return list of GEOM objects entries
350 static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule,
351 QList<GEOM::shape_type> theTypes );
354 * \brief Delete the GEOM objects.
355 * \param theModule the module
356 * \param theEntries the GEOM objects entries
358 static void DeleteGeomObjects( HYDROGUI_Module* theModule, const QStringList& theEntries );