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