Salome HOME
Improvements for HYDRO module: 1. General mechanism for activation of GUI Geometry...
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.hh
1 // Copyright (C) 2007-2013  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.
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 #ifndef __GEOM_GEN_I_H__
23 #define __GEOM_GEN_I_H__
24
25 #include "GEOM_GEOM_I.hxx"
26
27 #include "GEOMImpl_Gen.hxx"
28
29 // IDL headers
30 #include <SALOMEconfig.h>
31 #include CORBA_SERVER_HEADER(GEOM_Gen)
32
33 #include CORBA_CLIENT_HEADER(SALOMEDS)
34 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
35
36
37 #include "SALOME_Component_i.hxx"
38 #include "SALOME_NamingService.hxx"
39
40 #include "GEOM_IBasicOperations_i.hh"
41 #include "GEOM_ITransformOperations_i.hh"
42 #include "GEOM_I3DPrimOperations_i.hh"
43 #include "GEOM_IShapesOperations_i.hh"
44 #include "GEOM_IBlocksOperations_i.hh"
45 #include "GEOM_IBooleanOperations_i.hh"
46 #include "GEOM_ICurvesOperations_i.hh"
47 #include "GEOM_ILocalOperations_i.hh"
48 #include "GEOM_IHealingOperations_i.hh"
49 #include "GEOM_IInsertOperations_i.hh"
50 #include "GEOM_IMeasureOperations_i.hh"
51 #include "GEOM_IGroupOperations_i.hh"
52
53 #include <TopTools_IndexedMapOfShape.hxx>
54
55 #include <map>
56 #include <set>
57 #include <string>
58
59 //#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
60
61
62 //=====================================================================
63 // Generic operations creator (for plugins mechanism)
64 //=====================================================================
65 class GEOM_I_EXPORT GEOM_GenericOperationsCreator
66 {
67 public:
68   // Create operations
69   virtual GEOM_IOperations_i* Create (PortableServer::POA_ptr thePOA,
70                                       int                     theStudyId,
71                                       GEOM::GEOM_Gen_ptr      theEngine,
72                                       ::GEOMImpl_Gen*         theGenImpl) = 0;
73   // return the name of IDL module
74   //virtual std::string GetModuleName() = 0;
75 };
76
77 //=====================================================================
78 // GEOM_Gen_i : class definition
79 //=====================================================================
80 class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual public Engines_Component_i
81 {
82  public:
83
84   //-----------------------------------------------------------------------//
85   // Constructor / Destructor                                              //
86   //-----------------------------------------------------------------------//
87
88   // constructor to be called for servant creation.
89   GEOM_Gen_i();
90   GEOM_Gen_i(CORBA::ORB_ptr orb,
91              PortableServer::POA_ptr poa,
92              PortableServer::ObjectId * contId,
93              const char *instanceName,
94              const char *interfaceName);
95
96   // destructor, doing nothing (for now)
97   virtual ~GEOM_Gen_i();
98
99   // generic method to be put in a super class
100   void register_name(char * name);
101
102   // Get ORB object
103   CORBA::ORB_ptr GetORB() { return CORBA::ORB::_duplicate(_orb); }
104
105   // Get Naming Service object
106   SALOME_NamingService* GetNS() { return name_service; }
107
108   //-----------------------------------------------------------------------//
109   // Inherited methods from SALOMEDS::Driver                               //
110   //-----------------------------------------------------------------------//
111
112   SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent,
113                           const char* theURL,
114                           bool isMultiFile);
115
116   SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent,
117                                const char* theURL,
118                                bool isMultiFile);
119
120   CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent,
121                       const SALOMEDS::TMPFile& theStream,
122                       const char* theURL,
123                       bool isMultiFile);
124
125   CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent,
126                            const SALOMEDS::TMPFile& theStream,
127                            const char* theURL,
128                            bool isMultiFile);
129
130   void Close(SALOMEDS::SComponent_ptr theComponent);
131   char* ComponentDataType();
132
133
134   char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
135                                const char* IORString,
136                                CORBA::Boolean isMultiFile,
137                                CORBA::Boolean isASCII);
138   char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
139                                const char* aLocalPersistentID,
140                                CORBA::Boolean isMultiFile,
141                                CORBA::Boolean isASCII);
142
143   bool CanPublishInStudy(CORBA::Object_ptr theIOR);
144   SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy,
145                                        SALOMEDS::SObject_ptr theSObject,
146                                        CORBA::Object_ptr theObject,
147                                        const char* theName) throw (SALOME::SALOME_Exception) ;
148
149   GEOM::ListOfGO* PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
150                                             CORBA::Object_ptr theObject);
151
152   CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject);
153   SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID);
154   CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID);
155   SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream,
156                                   CORBA::Long theObjectID,
157                                   SALOMEDS::SObject_ptr theObject);
158
159   /*! \brief Adds theObject in the study with a name = theName, if
160    *         theFather is not null the object is placed under theFather
161    */
162   SALOMEDS::SObject_ptr AddInStudy (SALOMEDS::Study_ptr theStudy,
163                                     GEOM::GEOM_Object_ptr theObject,
164                                     const char* theName,
165                                     GEOM::GEOM_Object_ptr theFather);
166
167   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
168    *         To be used from python scripts out of geompy.addToStudy (non-default usage)
169    */
170   GEOM::ListOfGO* RestoreSubShapesO (SALOMEDS::Study_ptr     theStudy,
171                                      GEOM::GEOM_Object_ptr   theObject,
172                                      const GEOM::ListOfGO&   theArgs,
173                                      GEOM::find_shape_method theFindMethod,
174                                      CORBA::Boolean          theInheritFirstArg,
175                                      CORBA::Boolean          theAddPrefix);
176
177   /*! \brief Publish sub-shapes, standing for given in \a theArgs arguments and sub-shapes.
178    *         To be used from python scripts, generated by Dump Python.
179    */
180   GEOM::ListOfGO* RestoreGivenSubShapesO (SALOMEDS::Study_ptr     theStudy,
181                                           GEOM::GEOM_Object_ptr   theObject,
182                                           const GEOM::ListOfGO&   theArgs,
183                                           GEOM::find_shape_method theFindMethod,
184                                           CORBA::Boolean          theInheritFirstArg,
185                                           CORBA::Boolean          theAddPrefix);
186
187   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
188    *         To be used from GUI and from geompy.addToStudy
189    */
190   GEOM::ListOfGO* RestoreSubShapesSO (SALOMEDS::Study_ptr     theStudy,
191                                       SALOMEDS::SObject_ptr   theSObject,
192                                       const GEOM::ListOfGO&   theArgs,
193                                       GEOM::find_shape_method theFindMethod,
194                                       CORBA::Boolean          theInheritFirstArg,
195                                       CORBA::Boolean          theAddPrefix);
196
197   //-----------------------------------------------------------------------//
198   // Transaction methods                                                   //
199   //-----------------------------------------------------------------------//
200
201   //Undos one transaction in the document associated with theStudyID
202   virtual void Undo(CORBA::Long theStudyID);
203
204   //Redos one transaction in the document associated with theStudyID
205   virtual void Redo(CORBA::Long theStudyID);
206
207   //-----------------------------------------------------------------------//
208   // Operations methods                                                    //
209   //-----------------------------------------------------------------------//
210
211   //Returns a pointer to BasicOperations interface
212   virtual GEOM::GEOM_IBasicOperations_ptr GetIBasicOperations (CORBA::Long theStudyID)
213     throw (SALOME::SALOME_Exception);
214
215   //Returns a pointer to TransformOperations interface
216   virtual GEOM::GEOM_ITransformOperations_ptr GetITransformOperations (CORBA::Long theStudyID)
217     throw (SALOME::SALOME_Exception);
218
219   //Returns a pointer to 3DPrimOperations interface
220   virtual GEOM::GEOM_I3DPrimOperations_ptr GetI3DPrimOperations (CORBA::Long theStudyID)
221     throw (SALOME::SALOME_Exception);
222
223   //Returns a pointer to ShapesOperations interface
224   virtual GEOM::GEOM_IShapesOperations_ptr GetIShapesOperations (CORBA::Long theStudyID)
225     throw (SALOME::SALOME_Exception);
226
227   //Returns a pointer to BlocksOperations interface
228   virtual GEOM::GEOM_IBlocksOperations_ptr GetIBlocksOperations (CORBA::Long theStudyID)
229     throw (SALOME::SALOME_Exception);
230
231   //Returns a pointer to BooleanOperations interface
232   virtual GEOM::GEOM_IBooleanOperations_ptr GetIBooleanOperations (CORBA::Long theStudyID)
233     throw (SALOME::SALOME_Exception);
234
235   //Returns a pointer to CurvesOperations interface
236   virtual GEOM::GEOM_ICurvesOperations_ptr GetICurvesOperations (CORBA::Long theStudyID)
237     throw (SALOME::SALOME_Exception);
238
239   //Returns a pointer to LocalOperations interface
240   virtual GEOM::GEOM_ILocalOperations_ptr GetILocalOperations (CORBA::Long theStudyID)
241     throw (SALOME::SALOME_Exception);
242
243   //Returns a pointer to HealingOperations interface
244   virtual GEOM::GEOM_IHealingOperations_ptr GetIHealingOperations (CORBA::Long theStudyID)
245     throw (SALOME::SALOME_Exception);
246
247   //Returns a pointer to InsertOperations interface
248   virtual GEOM::GEOM_IInsertOperations_ptr GetIInsertOperations (CORBA::Long theStudyID)
249     throw (SALOME::SALOME_Exception);
250
251   //Returns a pointer to MeasureOperations interface
252   virtual GEOM::GEOM_IMeasureOperations_ptr GetIMeasureOperations (CORBA::Long theStudyID)
253     throw (SALOME::SALOME_Exception);
254
255   //Returns a pointer to GroupOperations interface
256   virtual GEOM::GEOM_IGroupOperations_ptr GetIGroupOperations (CORBA::Long theStudyID)
257     throw (SALOME::SALOME_Exception);
258
259   //Returns a pointer to corresponding plugin operations interface
260   virtual GEOM::GEOM_IOperations_ptr GetPluginOperations (CORBA::Long theStudyID,
261                                                           const char* theLibName)
262     throw (SALOME::SALOME_Exception);
263
264   //Adds a new sub-shape
265   virtual GEOM::GEOM_Object_ptr AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
266                                              const GEOM::ListOfLong& theIndices);
267
268   virtual void RemoveObject(GEOM::GEOM_Object_ptr theObject);
269
270   virtual  char* GetStringFromIOR(GEOM::GEOM_Object_ptr theObject);
271
272   virtual GEOM::GEOM_Object_ptr GetIORFromString(const char* stringIOR);
273
274   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
275                                        CORBA::Boolean isPublished,
276                                        CORBA::Boolean isMultiFile,
277                                        CORBA::Boolean& isValidScript);
278
279   char* GetDumpName (const char* theStudyEntry);
280
281   GEOM::string_array* GetAllDumpNames();
282
283   // Object information
284   virtual bool hasObjectInfo();
285   virtual char* getObjectInfo(CORBA::Long studyId, const char* entry);
286
287   // Version information
288   virtual char* getVersion();
289
290   // Create a new folder object
291   SALOMEDS::SObject_ptr CreateFolder(const char* theName, 
292                                      SALOMEDS::SObject_ptr theFather);
293
294   // Move GEOM object to the specified folder
295   void MoveToFolder(GEOM::GEOM_Object_ptr theObject, 
296                     SALOMEDS::SObject_ptr theFolder);
297
298   // Move list of GEOM objects to the specified folder
299   void MoveListToFolder (const GEOM::ListOfGO& theListOfGO, 
300                          SALOMEDS::SObject_ptr theFolder);
301
302   // Move objects to the specified position
303   void Move( const GEOM::object_list& what,
304              SALOMEDS::SObject_ptr where,
305              CORBA::Long row );
306
307   //-----------------------------------------------------------------------//
308   // Internal methods                                                      //
309   //-----------------------------------------------------------------------//
310
311   virtual GEOM::GEOM_Object_ptr GetObject(CORBA::Long theStudyID, const char* theEntry);
312
313  private:
314   GEOM::ListOfGO* RestoreSubShapes (SALOMEDS::Study_ptr     theStudy,
315                                     GEOM::GEOM_Object_ptr   theObject,
316                                     SALOMEDS::SObject_ptr   theSObject,
317                                     const GEOM::ListOfGO&   theArgs,
318                                     GEOM::find_shape_method theFindMethod,
319                                     CORBA::Boolean          theInheritFirstArg,
320                                     CORBA::Boolean          theAddPrefix);
321
322   GEOM::ListOfGO* RestoreSubShapesOneLevel (SALOMEDS::Study_ptr     theStudy,
323                                             SALOMEDS::SObject_ptr   theOldSO,
324                                             SALOMEDS::SObject_ptr   theNewSO,
325                                             GEOM::GEOM_Object_ptr   theNewO,
326                                             GEOM::ListOfGO&         theOutArgs,
327                                             GEOM::find_shape_method theFindMethod,
328                                             CORBA::Boolean          theAddPrefix);
329
330   GEOM::ListOfGO* RestoreGivenSubShapes (SALOMEDS::Study_ptr     theStudy,
331                                          GEOM::GEOM_Object_ptr   theObject,
332                                          SALOMEDS::SObject_ptr   theSObject,
333                                          const GEOM::ListOfGO&   theArgs,
334                                          GEOM::find_shape_method theFindMethod,
335                                          CORBA::Boolean          theInheritFirstArg,
336                                          CORBA::Boolean          theAddPrefix);
337
338   GEOM::ListOfGO* RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr     theStudy,
339                                                  SALOMEDS::SObject_ptr   theOldSO,
340                                                  SALOMEDS::SObject_ptr   theNewSO,
341                                                  GEOM::GEOM_Object_ptr   theNewO,
342                                                  std::set<std::string>   theArgs,
343                                                  GEOM::find_shape_method theFindMethod,
344                                                  CORBA::Boolean          theAddPrefix);
345
346   // auxilary for PublishNamedShapesInStudy
347   void CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
348                              GEOM::GEOM_Object_var theMainShape,
349                              const TopTools_IndexedMapOfShape& anIndices,
350                              const TopTools_SequenceOfShape& SeqS,
351                              const TColStd_SequenceOfAsciiString& SeqN,
352                              const Standard_CString& GrName,
353                              GEOM::ListOfGO_var aResList);
354
355  private:
356
357    ::GEOMImpl_Gen* _impl;
358    SALOME_NamingService * name_service;
359    char * _name;
360
361    // plugin operations managing
362    std::map<std::string, GEOM_GenericOperationsCreator*> myOpCreatorMap;
363 };
364
365 #endif