1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 #include <Image_PixMap.hxx>
39 #include <SALOMEconfig.h>
40 #include CORBA_SERVER_HEADER(GEOM_Gen)
42 class SUIT_ViewManager;
43 class OCCViewer_ViewFrame;
45 class HYDROGUI_DataModel;
46 class HYDROGUI_Module;
50 class Handle(HYDROData_Document);
53 * \class HYDROGUI_Tool
54 * \brief This class contains several useful methods.
60 * \brief Convert \a TCollection_AsciiString to \a QString
62 static QString ToQString( const TCollection_AsciiString& );
65 * \brief Convert \a TCollection_ExtendedString to \a QString
67 static QString ToQString( const TCollection_ExtendedString& );
70 * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
72 static QString ToQString( const Handle(TCollection_HAsciiString)& );
75 * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
77 static QString ToQString( const Handle(TCollection_HExtendedString)& );
80 * \brief Convert \a QString to \a TCollection_AsciiString
82 static TCollection_AsciiString ToAsciiString( const QString& );
85 * \brief Convert \a QString to \a TCollection_ExtendedString
87 static TCollection_ExtendedString ToExtString( const QString& );
90 * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
92 static Handle(TCollection_HAsciiString) ToHAsciiString( const QString& );
95 * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
97 static Handle(TCollection_HExtendedString) ToHExtString( const QString& );
100 * \brief Get the active study id.
101 * \return active study id
103 static int GetActiveStudyId();
106 * \brief Get path to the temporary directory.
107 * \param theToCreate flag used to create a directory if it doesn't exist
110 static QString GetTempDir( const bool theToCreate );
113 * \brief Set the specified view manager to be active on the desktop.
114 * \param theModule module
115 * \param theViewManager view manager
117 static void SetActiveViewManager( HYDROGUI_Module* theModule,
118 SUIT_ViewManager* theViewManager );
121 * \brief Returns TRUE if object can be shown on the viewer.
122 * \param theObject data model object to check
123 * \param theViewerType viewer type
125 static bool IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
126 const QString& theViewerType = "" );
129 * \brief Get sub-objects to build presentations.
130 * \param theModule module
131 * \param theSeq sequence of sub-objects
133 static void GetPrsSubObjects( HYDROGUI_Module* theModule,
134 HYDROData_SequenceOfObjects& theSeq );
137 * \brief Get presentation built for specified data object.
138 * \param theObj data object
139 * \param theObjects list of existing presentations
140 * \return presentation
142 static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Entity)& theObj,
143 const GraphicsView_ObjectList& theObjects );
146 * \brief Get list of HYDRO presentations from the specified viewport.
147 * \param theViewPort viewport
148 * \return list of HYDRO presentations
150 static GraphicsView_ObjectList GetPrsList( GraphicsView_ViewPort* theViewPort );
153 * \brief Get list of the selected data objects.
154 * \param theModule module
155 * \return list of the selected data objects
157 static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
160 * \brief Get the selected data object (first in the selected list).
161 * \param theModule module
162 * \return selected data object
164 static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
167 * \brief Get the geometry data objects from document.
168 * \param theModule module
169 * \return sequence of data objects
171 static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
174 * \brief Get kind of objects the selected partition contains.
175 * \param theModule module
176 * \return object kind
178 static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
181 * \brief Get the selected GEOM objects.
182 * \param theModule module
183 * \param theTypes the acceptable GEOM object types
184 * \return list of GEOM objects entries
186 static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule,
187 QList<GEOM::shape_type> theTypes );
190 * \brief Find the data object with the specified name.
191 * \param theModule module
192 * \param theName name
193 * \param theObjectKind kind of object
194 * \return data object
196 static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
197 const QString& theName,
198 const ObjectKind theObjectKind = KIND_UNKNOWN );
201 * \brief Find the data objects with the specified names.
202 * \param theModule module
203 * \param theNames list of names
204 * \param theObjectKind kind of object
205 * \return list of data objects
207 static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module* theModule,
208 const QStringList& theNames,
209 const ObjectKind theObjectKind = KIND_UNKNOWN );
212 * \brief Generate name for new object.
213 * \param theModule module
214 * \param thePrefix name prefix
215 * \param theUsedNames list of already used names
216 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
217 * \return generated name
219 static QString GenerateObjectName( HYDROGUI_Module* theModule,
220 const QString& thePrefix,
221 const QStringList& theUsedNames = QStringList(),
222 const bool theIsTryToUsePurePrefix = false );
225 * \brief Get id of the active view.
226 * \param theModule module
229 static size_t GetActiveViewId( HYDROGUI_Module* theModule,
230 const QString& theViewId = QString() );
233 * \brief Get id of the active GraphicsView view.
234 * \param theModule module
237 static size_t GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
240 * \brief Get id of the active OCC view.
241 * \param theModule module
244 static size_t GetActiveOCCViewId( HYDROGUI_Module* theModule );
247 * \brief Get list of ids of existing GraphicsView views.
248 * \param theModule module
249 * \return list of view ids
251 static QList<size_t> GetGraphicsViewIdList( HYDROGUI_Module* theModule );
254 * \brief Get list of ids of existing OCC views.
255 * \param theModule module
256 * \return list of view ids
258 static QList<size_t> GetOCCViewIdList( HYDROGUI_Module* theModule );
262 * \brief Change OCC viewer action visibility.
263 * \param theViewFrame OCC viewer frame
264 * \param theActionId an action index, which state should be changed
265 * \param isShown the action visibility state
267 static void setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
268 const int theActionId,
269 const bool isShown );
272 * \brief Change OCC viewer action visibility for all opened views.
273 * \param theActionId an action index, which state should be changed
274 * \param isShown the action visibility state
276 static void setOCCActionShown( HYDROGUI_Module* theModule,
277 const int theActionId,
278 const bool isShown );
281 * \brief Get the list of references (recursively) for the specified data object
282 * \param theObj data object
283 * \param theRefObjects list of reference objects
284 * \param theRefNames list of reference object names
286 static void GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
287 HYDROData_SequenceOfObjects& theRefObjects,
288 QStringList& theRefNames );
291 * \brief Get the list of back-references for the specified object
292 * \param theModule module
293 * \param theObj data object
294 * \return list of back-reference objects
296 static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module* theModule,
297 const Handle(HYDROData_Entity)& theObj );
300 * \brief Get the map of back-references for the specified list of objects
301 * \param theModule module
302 * \param theObjectNames names of objects
303 * \return map of back-reference objects
305 static QMap<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module* theModule,
306 const QStringList& theObjectNames );
309 * \brief Get father dock window for widget
311 * \return dock window
313 static QDockWidget* WindowDock( QWidget* wid );
316 * \brief Generates the filling color for intersected zone
317 * \param theModule module
318 * \param theZoneNames list of intersected zones
319 * \return result color
321 static QColor GenerateFillingColor( HYDROGUI_Module* theModule,
322 const QStringList& theZoneNames );
325 * \brief Generates the filling color for intersected zone
326 * \param theDoc model document
327 * \param theZoneNames list of intersected zones
328 * \return result color
330 static QColor GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
331 const QStringList& theZoneNames );
334 * \brief Find names of existing objects of the given kind.
335 * \param theDoc model document
336 * \param theObjectKind kind of object
337 * \return list of names
339 static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
340 const ObjectKind theObjectKind,
341 bool isCheckValidProfile = false );
344 * \brief Converts coordinate value to string.
345 * \param theNumber coordinate as a number
346 * \return coordinate as a string
348 static QString GetCoordinateString( const double theNumber, bool isInLocale );
351 * \brief Converts Qt QImage object to OCCT Image_PixMap object.
352 * \param theImage QImage object
353 * \return Image_PixMap object
355 static Handle(Image_PixMap) Pixmap( const QImage& theImage );