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>
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(GEOM_Gen)
40 class SUIT_ViewManager;
41 class OCCViewer_ViewFrame;
43 class HYDROGUI_DataModel;
44 class HYDROGUI_Module;
48 class Handle(HYDROData_Document);
51 * \class HYDROGUI_Tool
52 * \brief This class contains several useful methods.
58 * \brief Convert \a TCollection_AsciiString to \a QString
60 static QString ToQString( const TCollection_AsciiString& );
63 * \brief Convert \a TCollection_ExtendedString to \a QString
65 static QString ToQString( const TCollection_ExtendedString& );
68 * \brief Convert \a Handle_TCollection_HAsciiString to \a QString
70 static QString ToQString( const Handle(TCollection_HAsciiString)& );
73 * \brief Convert \a Handle_TCollection_HExtendedString to \a QString
75 static QString ToQString( const Handle(TCollection_HExtendedString)& );
78 * \brief Convert \a QString to \a TCollection_AsciiString
80 static TCollection_AsciiString ToAsciiString( const QString& );
83 * \brief Convert \a QString to \a TCollection_ExtendedString
85 static TCollection_ExtendedString ToExtString( const QString& );
88 * \brief Convert \a QString to \a Handle_TCollection_HAsciiString
90 static Handle(TCollection_HAsciiString) ToHAsciiString( const QString& );
93 * \brief Convert \a QString to \a Handle_TCollection_HExtendedString
95 static Handle(TCollection_HExtendedString) ToHExtString( const QString& );
98 * \brief Get the active study id.
99 * \return active study id
101 static int GetActiveStudyId();
104 * \brief Get path to the temporary directory.
105 * \param theToCreate flag used to create a directory if it doesn't exist
108 static QString GetTempDir( const bool theToCreate );
111 * \brief Set the specified view manager to be active on the desktop.
112 * \param theModule module
113 * \param theViewManager view manager
115 static void SetActiveViewManager( HYDROGUI_Module* theModule,
116 SUIT_ViewManager* theViewManager );
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
123 static bool IsObjectHasPresentation( const Handle(HYDROData_Entity)& theObject,
124 const QString& theViewerType = "" );
127 * \brief Get sub-objects to build presentations.
128 * \param theModule module
129 * \param theSeq sequence of sub-objects
131 static void GetPrsSubObjects( HYDROGUI_Module* theModule,
132 HYDROData_SequenceOfObjects& theSeq );
135 * \brief Get presentation built for specified data object.
136 * \param theObj data object
137 * \param theObjects list of existing presentations
138 * \return presentation
140 static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Entity)& theObj,
141 const GraphicsView_ObjectList& theObjects );
144 * \brief Get list of HYDRO presentations from the specified viewport.
145 * \param theViewPort viewport
146 * \return list of HYDRO presentations
148 static GraphicsView_ObjectList GetPrsList( GraphicsView_ViewPort* theViewPort );
151 * \brief Get list of the selected data objects.
152 * \param theModule module
153 * \return list of the selected data objects
155 static HYDROData_SequenceOfObjects GetSelectedObjects( HYDROGUI_Module* theModule );
158 * \brief Get the selected data object (first in the selected list).
159 * \param theModule module
160 * \return selected data object
162 static Handle(HYDROData_Entity) GetSelectedObject( HYDROGUI_Module* theModule );
165 * \brief Get the geometry data objects from document.
166 * \param theModule module
167 * \return sequence of data objects
169 static HYDROData_SequenceOfObjects GetGeometryObjects( HYDROGUI_Module* theModule );
172 * \brief Get kind of objects the selected partition contains.
173 * \param theModule module
174 * \return object kind
176 static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule );
179 * \brief Get the selected GEOM objects.
180 * \param theModule module
181 * \param theTypes the acceptable GEOM object types
182 * \return list of GEOM objects entries
184 static QStringList GetSelectedGeomObjects( HYDROGUI_Module* theModule,
185 QList<GEOM::shape_type> theTypes );
188 * \brief Find the data object with the specified name.
189 * \param theModule module
190 * \param theName name
191 * \param theObjectKind kind of object
192 * \return data object
194 static Handle(HYDROData_Entity) FindObjectByName( HYDROGUI_Module* theModule,
195 const QString& theName,
196 const ObjectKind theObjectKind = KIND_UNKNOWN );
199 * \brief Find the data objects with the specified names.
200 * \param theModule module
201 * \param theNames list of names
202 * \param theObjectKind kind of object
203 * \return list of data objects
205 static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module* theModule,
206 const QStringList& theNames,
207 const ObjectKind theObjectKind = KIND_UNKNOWN );
210 * \brief Generate name for new object.
211 * \param theModule module
212 * \param thePrefix name prefix
213 * \param theUsedNames list of already used names
214 * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
215 * \return generated name
217 static QString GenerateObjectName( HYDROGUI_Module* theModule,
218 const QString& thePrefix,
219 const QStringList& theUsedNames = QStringList(),
220 const bool theIsTryToUsePurePrefix = false );
223 * \brief Get id of the active view.
224 * \param theModule module
227 static size_t GetActiveViewId( HYDROGUI_Module* theModule,
228 const QString& theViewId = QString() );
231 * \brief Get id of the active GraphicsView view.
232 * \param theModule module
235 static size_t GetActiveGraphicsViewId( HYDROGUI_Module* theModule );
238 * \brief Get id of the active OCC view.
239 * \param theModule module
242 static size_t GetActiveOCCViewId( HYDROGUI_Module* theModule );
245 * \brief Get list of ids of existing GraphicsView views.
246 * \param theModule module
247 * \return list of view ids
249 static QList<size_t> GetGraphicsViewIdList( HYDROGUI_Module* theModule );
252 * \brief Get list of ids of existing OCC views.
253 * \param theModule module
254 * \return list of view ids
256 static QList<size_t> GetOCCViewIdList( HYDROGUI_Module* theModule );
260 * \brief Change OCC viewer action visibility.
261 * \param theViewFrame OCC viewer frame
262 * \param theActionId an action index, which state should be changed
263 * \param isShown the action visibility state
265 static void setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
266 const int theActionId,
267 const bool isShown );
270 * \brief Change OCC viewer action visibility for all opened views.
271 * \param theActionId an action index, which state should be changed
272 * \param isShown the action visibility state
274 static void setOCCActionShown( HYDROGUI_Module* theModule,
275 const int theActionId,
276 const bool isShown );
279 * \brief Get the list of references (recursively) for the specified data object
280 * \param theObj data object
281 * \param theRefObjects list of reference objects
282 * \param theRefNames list of reference object names
284 static void GetObjectReferences( const Handle(HYDROData_Entity)& theObj,
285 HYDROData_SequenceOfObjects& theRefObjects,
286 QStringList& theRefNames );
289 * \brief Get the list of back-references for the specified object
290 * \param theModule module
291 * \param theObj data object
292 * \return list of back-reference objects
294 static HYDROData_SequenceOfObjects GetObjectBackReferences( HYDROGUI_Module* theModule,
295 const Handle(HYDROData_Entity)& theObj );
298 * \brief Get the map of back-references for the specified list of objects
299 * \param theModule module
300 * \param theObjectNames names of objects
301 * \return map of back-reference objects
303 static QMap<QString,HYDROData_SequenceOfObjects> GetObjectsBackReferences( HYDROGUI_Module* theModule,
304 const QStringList& theObjectNames );
307 * \brief Get father dock window for widget
309 * \return dock window
311 static QDockWidget* WindowDock( QWidget* wid );
314 * \brief Generates the filling color for intersected zone
315 * \param theModule module
316 * \param theZoneNames list of intersected zones
317 * \return result color
319 static QColor GenerateFillingColor( HYDROGUI_Module* theModule,
320 const QStringList& theZoneNames );
323 * \brief Generates the filling color for intersected zone
324 * \param theDoc model document
325 * \param theZoneNames list of intersected zones
326 * \return result color
328 static QColor GenerateFillingColor( const Handle(HYDROData_Document)& theDoc,
329 const QStringList& theZoneNames );
332 * \brief Find names of existing objects of the given kind.
333 * \param theDoc model document
334 * \param theObjectKind kind of object
335 * \return list of names
337 static QStringList FindExistingObjectsNames( const Handle(HYDROData_Document)& theDoc,
338 const ObjectKind theObjectKind );
341 * \brief Converts coordinate value to string.
342 * \param theNumber coordinate as a number
343 * \return coordinate as a string
345 static QString GetCoordinateString( const double theNumber );