Salome HOME
23080: [CEA 1497] Do not merge a middle node in quadratic with the extreme nodes...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Utils.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_Utils.h
25 // Author : Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_UTILS_H
28 #define SMESHGUI_UTILS_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32
33 // CORBA includes
34 #include <omniORB4/CORBA.h>
35
36 // SALOME KERNEL includes
37 #include <SALOMEDSClient_definitions.hxx>
38 #include <SALOME_GenericObj_wrap.hxx>
39
40 // SALOME GUI includes
41 #include <SALOME_InteractiveObject.hxx>
42 #include <LightApp_DataOwner.h>
43
44 //OCC includes
45 #include <gp_XYZ.hxx>
46
47 #include <SALOMEconfig.h>
48 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
49
50 class SUIT_ViewWindow;
51 class SUIT_Desktop;
52 class SUIT_Study;
53 class SUIT_ResourceMgr;
54
55 class CAM_Module;
56
57 class SALOMEDSClient_Study;
58 class SALOMEDSClient_SObject;
59
60 class SalomeApp_Study;
61 class SalomeApp_Module;
62 class LightApp_SelectionMgr;
63
64 class SMDS_MeshFace;
65
66 namespace SMESH
67 {
68 SMESHGUI_EXPORT
69   SUIT_Desktop*
70   GetDesktop( const CAM_Module* );
71
72 SMESHGUI_EXPORT
73   LightApp_SelectionMgr*
74   GetSelectionMgr( const SalomeApp_Module* );
75
76 SMESHGUI_EXPORT
77   SalomeApp_Study*
78   GetAppStudy( const CAM_Module* );
79
80 SMESHGUI_EXPORT
81   SUIT_ResourceMgr*
82   GetResourceMgr( const SalomeApp_Module* );
83   
84 SMESHGUI_EXPORT
85   _PTR(Study)
86   GetCStudy( const SalomeApp_Study* );
87
88 SMESHGUI_EXPORT
89   CORBA::Object_var DataOwnerToObject( const LightApp_DataOwnerPtr& );
90
91   template<class TInterface> typename TInterface::_var_type
92     DataOwnerToInterface( const LightApp_DataOwnerPtr& theDataOwner )
93     {
94       CORBA::Object_var anObj = DataOwnerToObject(theDataOwner);
95       if(!CORBA::is_nil(anObj))
96         return TInterface::_narrow(anObj);
97       return TInterface::_nil();
98     }
99
100 SMESHGUI_EXPORT
101   SUIT_Study* GetActiveStudy();
102
103 SMESHGUI_EXPORT
104   SUIT_ViewWindow* GetActiveWindow();
105
106 SMESHGUI_EXPORT
107   _PTR(Study) GetActiveStudyDocument();
108
109 SMESHGUI_EXPORT
110   _PTR(SObject) FindSObject( CORBA::Object_ptr );
111
112 SMESHGUI_EXPORT
113   void SetName( _PTR(SObject), const QString& );
114
115 SMESHGUI_EXPORT
116   void SetValue( _PTR(SObject), const QString& );
117   void setFileType( _PTR(SObject), const QString& );
118   void setFileName( _PTR(SObject), const QString& );
119
120 SMESHGUI_EXPORT
121   CORBA::Object_var SObjectToObject( _PTR(SObject),
122                                      _PTR(Study) );
123
124 SMESHGUI_EXPORT
125   CORBA::Object_var SObjectToObject( _PTR(SObject) );
126
127   template<class TInterface> typename TInterface::_var_type
128     SObjectToInterface( _PTR(SObject) theSObject )
129     {
130       CORBA::Object_var anObj = SObjectToObject(theSObject);
131       if(!CORBA::is_nil(anObj))
132         return TInterface::_narrow(anObj);
133       return TInterface::_nil();
134     }
135
136 SMESHGUI_EXPORT
137   _PTR(SObject) ObjectToSObject( CORBA::Object_ptr );
138
139 SMESHGUI_EXPORT
140   CORBA::Object_var IObjectToObject( const Handle(SALOME_InteractiveObject)& );
141
142   template<class TInterface> typename TInterface::_var_type
143     IObjectToInterface( const Handle(SALOME_InteractiveObject)& theIO )
144     {
145       CORBA::Object_var anObj = IObjectToObject(theIO);
146       if(!CORBA::is_nil(anObj))
147         return TInterface::_narrow(anObj);
148       return TInterface::_nil();
149     }
150
151 SMESHGUI_EXPORT
152   CORBA::Object_var IORToObject( const QString& );
153
154   template<class TInterface> typename TInterface::_var_type
155     IORToInterface( const QString& theIOR )
156     {
157       CORBA::Object_var anObj = IORToObject( theIOR );
158       if ( !CORBA::is_nil( anObj ) )
159         return TInterface::_narrow( anObj );
160       return TInterface::_nil();
161     }
162
163 SMESHGUI_EXPORT
164   int GetNameOfSelectedIObjects( LightApp_SelectionMgr*, QString& );
165
166 SMESHGUI_EXPORT
167   _PTR(SObject) GetMeshOrSubmesh( _PTR(SObject) );
168
169 SMESHGUI_EXPORT
170   void ModifiedMesh( _PTR(SObject), bool, bool = false );
171
172 SMESHGUI_EXPORT
173   void ShowHelpFile( const QString& );
174
175   /*!
176    * \brief Return the normal to a face
177     * \param theFace - input face
178     * \retval gp_XYZ - normal to a face 
179    */
180 SMESHGUI_EXPORT
181   gp_XYZ getNormale( const SMDS_MeshFace* theFace );
182
183
184   // type to use instead of SMESH_IDSource_var for automatic UnRegister()
185   typedef SALOME::GenericObj_wrap<SMESH_IDSource> IDSource_wrap;
186
187   /*!
188    * \brief Class usefull to convert a string returned from a CORBA call
189    *        to other string types w/o memory leak.
190    *
191    *        Usage (of instantiations): QString s = toQStr( objVar->GetName() );
192    *                              std::string ss = toStdStr( objVar->GetName() );
193    */
194   template < class _STRING >
195   class toStrT : public _STRING {
196     CORBA::String_var myStr;
197   public:
198     toStrT( char* s ): myStr(s), _STRING( s )
199     {}
200     operator const char*() const
201     { return myStr.in(); }
202   };
203   // Instantiations:
204   struct toQStr : public toStrT< QString > {
205     toQStr( char* s ): toStrT< QString >(s) {}
206   };
207   struct toStdStr : public toStrT< std::string > {
208     toStdStr( char* s ): toStrT< std::string >(s) {}
209   };
210
211   QString fromUtf8( const char* txt );
212   QString fromUtf8( const std::string& txt );
213   struct toUtf8: public std::string
214   {
215     toUtf8( const QString& txt );
216     operator const char*() const { return c_str(); }
217   };
218 }
219
220 #endif // SMESHGUI_UTILS_H