1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef HYDROGUI_TOOL_H
24 #define HYDROGUI_TOOL_H
26 #include <HYDROData_Image.h>
28 #include <GraphicsView_Defs.h>
29 #include <GraphicsView_ViewPort.h>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
33 #include <TCollection_HAsciiString.hxx>
34 #include <TCollection_HExtendedString.hxx>
36 class SUIT_ViewManager;
37 class OCCViewer_ViewFrame;
39 class HYDROGUI_DataModel;
40 class HYDROGUI_Module;
44 class Handle(HYDROData_Document);
47 * \class HYDROGUI_Tool
48 * \brief This class contains several useful methods.
54 * \brief Convert \a TCollection_AsciiString to \a QString
56 static QString ToQString( const TCollection_AsciiString& );
59 * \brief Convert \a TCollection_ExtendedString to \a QString
61 static QString ToQString( const TCollection_ExtendedString& );
64 * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
66 static QString ToQString( const Handle(TCollection_HAsciiString)& );
69 * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
71 static QString ToQString( const Handle(TCollection_HExtendedString)& );
74 * \brief Convert \a QString to \a TCollection_AsciiString
76 static TCollection_AsciiString ToAsciiString( const QString& );
79 * \brief Convert \a QString to \a TCollection_ExtendedString
81 static TCollection_ExtendedString ToExtString( const QString& );
84 * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
86 static Handle(TCollection_HAsciiString) ToHAsciiString( const QString& );
89 * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
91 static Handle(TCollection_HExtendedString) ToHExtString( const QString& );
94 * \brief Get the active study id.
95 * \return active study id
97 static int GetActiveStudyId();
100 * \brief Get path to the temporary directory.
101 * \param theToCreate flag used to create a directory if it doesn't exist
104 static QString GetTempDir( const bool theToCreate );
107 * \brief Set the specified view manager to be active on the desktop.
108 * \param theModule module
109 * \param theViewManager view manager
111 static void SetActiveViewManager( HYDROGUI_Module* theModule,
112 SUIT_ViewManager* theViewManager );
115 * \brief Returns TRUE if object can be shown on the viewer.
116 * \param theObject data model object to check
117 * \param theViewerType viewer type
119 static bool IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
120 const QString& theViewerType = "" );
123 * \brief Get sub-objects to build presentations.
124 * \param theModule module
125 * \param theSeq sequence of sub-objects
127 static void GetPrsSubObjects( HYDROGUI_Module* theModule,
128 HYDROData_SequenceOfObjects& theSeq );
131 * \brief Get presentation built for specified data object.
132 * \param theObj data object
133 * \param theObjects list of existing presentations
134 * \return presentation
136 static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Entity)& theObj,
137 const GraphicsView_ObjectList& theObjects );
140 * \brief Get list of HYDRO presentations from the specified viewport.
141 * \param theViewPort viewport
142 * \return list of HYDRO presentations
144 static GraphicsView_ObjectList GetPrsList( GraphicsView_ViewPort* theViewPort );
147 * \brief Get list of the selected data objects.
148 * \param theModule module
149 * \return list of the selected data objects
151 static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
154 * \brief Get the selected data object (first in the selected list).
155 * \param theModule module
156 * \return selected data object
158 static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
161 * \brief Get the geometry data objects from document.
162 * \param theModule module
163 * \return sequence of data objects
165 static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
168 * \brief Get kind of objects the selected partition contains.
169 * \param theModule module
170 * \return object kind
172 static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
175 * \brief Get the selected GEOM objects.
176 * \param theModule module
177 * \return list of GEOM objects entries
179 static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule );
182 * \brief Find the data object with the specified name.
183 * \param theModule module
184 * \param theName name
185 * \param theObjectKind kind of object
186 * \return data object
188 static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
189 const QString& theName,
190 const ObjectKind theObjectKind = KIND_UNKNOWN );
193 * \brief Find the data objects with the specified names.
194 * \param theModule module
195 * \param theNames list of names
196 * \param theObjectKind kind of object
197 * \return list of data objects
199 static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module* theModule,
200 const QStringList& theNames,
201 const ObjectKind theObjectKind = KIND_UNKNOWN );
204 * \brief Generate name for new object.
205 * \param theModule module
206 * \param thePrefix name prefix
207 * \param theUsedNames list of already used names
208 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
209 * \return generated name
211 static QString GenerateObjectName( HYDROGUI_Module* theModule,
212 const QString& thePrefix,
213 const QStringList& theUsedNames = QStringList(),
214 const bool theIsTryToUsePurePrefix = false );
217 * \brief Get id of the active view.
218 * \param theModule module
221 static size_t GetActiveViewId( HYDROGUI_Module* theModule,
222 const QString& theViewId = QString() );
225 * \brief Get id of the active GraphicsView view.
226 * \param theModule module
229 static size_t GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
232 * \brief Get id of the active OCC view.
233 * \param theModule module
236 static size_t GetActiveOCCViewId( HYDROGUI_Module* theModule );
239 * \brief Get list of ids of existing GraphicsView views.
240 * \param theModule module
241 * \return list of view ids
243 static QList<size_t> GetGraphicsViewIdList( HYDROGUI_Module* theModule );
246 * \brief Get list of ids of existing OCC views.
247 * \param theModule module
248 * \return list of view ids
250 static QList<size_t> GetOCCViewIdList( HYDROGUI_Module* theModule );
254 * \brief Change OCC viewer action visibility.
255 * \param theViewFrame OCC viewer frame
256 * \param theActionId an action index, which state should be changed
257 * \param isShown the action visibility state
259 static void setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
260 const int theActionId,
261 const bool isShown );
264 * \brief Change OCC viewer action visibility for all opened views.
265 * \param theActionId an action index, which state should be changed
266 * \param isShown the action visibility state
268 static void setOCCActionShown( HYDROGUI_Module* theModule,
269 const int theActionId,
270 const bool isShown );
273 * \brief Get the list of references (recursively) for the specified data object
274 * \param theObj data object
275 * \param theRefObjects list of reference objects
276 * \param theRefNames list of reference object names
278 static void GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
279 HYDROData_SequenceOfObjects& theRefObjects,
280 QStringList& theRefNames );
283 * \brief Get the list of back-references for the specified object
284 * \param theModule module
285 * \param theObj data object
286 * \return list of back-reference objects
288 static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module* theModule,
289 const Handle(HYDROData_Entity)& theObj );
292 * \brief Get the map of back-references for the specified list of objects
293 * \param theModule module
294 * \param theObjectNames names of objects
295 * \return map of back-reference objects
297 static QMap<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module* theModule,
298 const QStringList& theObjectNames );
301 * \brief Get father dock window for widget
303 * \return dock window
305 static QDockWidget* WindowDock( QWidget* wid );
308 * \brief Generates the filling color for intersected zone
309 * \param theModule module
310 * \param theZoneNames list of intersected zones
311 * \return result color
313 static QColor GenerateFillingColor( HYDROGUI_Module* theModule,
314 const QStringList& theZoneNames );
317 * \brief Generates the filling color for intersected zone
318 * \param theDoc model document
319 * \param theZoneNames list of intersected zones
320 * \return result color
322 static QColor GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
323 const QStringList& theZoneNames );
326 * \brief Find names of existing objects of the given kind.
327 * \param theDoc model document
328 * \param theObjectKind kind of object
329 * \return list of names
331 static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
332 const ObjectKind theObjectKind );
335 * \brief Converts coordinate value to string.
336 * \param theNumber coordinate as a number
337 * \return coordinate as a string
339 static QString GetCoordinateString( const double theNumber );