Salome HOME
Merge multi-study removal branch.
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.hh
1 // Copyright (C) 2007-2016  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 #include "GEOMUtils.hxx"
55
56 #include <TopTools_IndexedMapOfShape.hxx>
57 #include <TopTools_SequenceOfShape.hxx>
58
59 #include <map>
60 #include <set>
61 #include <list>
62 #include <string>
63
64 //#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
65
66 //=====================================================================
67 // Generic operations creator (for plugins mechanism)
68 //=====================================================================
69 class GEOM_I_EXPORT GEOM_GenericOperationsCreator
70 {
71 public:
72   // Create operations
73   virtual GEOM_IOperations_i* Create (PortableServer::POA_ptr thePOA,
74                                       GEOM::GEOM_Gen_ptr      theEngine,
75                                       ::GEOMImpl_Gen*         theGenImpl) = 0;
76   // return the name of IDL module
77   //virtual std::string GetModuleName() = 0;
78 };
79
80 //=====================================================================
81 // GEOM_Gen_i : class definition
82 //=====================================================================
83 class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual public Engines_Component_i
84 {
85  public:
86
87   //-----------------------------------------------------------------------//
88   // Constructor / Destructor                                              //
89   //-----------------------------------------------------------------------//
90
91   // constructor to be called for servant creation.
92   GEOM_Gen_i();
93   GEOM_Gen_i(CORBA::ORB_ptr orb,
94              PortableServer::POA_ptr poa,
95              PortableServer::ObjectId * contId,
96              const char *instanceName,
97              const char *interfaceName);
98
99   // destructor, doing nothing (for now)
100   virtual ~GEOM_Gen_i();
101
102   // generic method to be put in a super class
103   void register_name(char * name);
104
105   // Get ORB object
106   CORBA::ORB_ptr GetORB() { return CORBA::ORB::_duplicate(_orb); }
107
108   // Get Naming Service object
109   SALOME_NamingService* GetNS() { return name_service; }
110
111   // Get Study
112   SALOMEDS::Study_var getStudyServant();
113
114   //-----------------------------------------------------------------------//
115   // Inherited methods from SALOMEDS::Driver                               //
116   //-----------------------------------------------------------------------//
117
118   SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent,
119                           const char* theURL,
120                           bool isMultiFile);
121
122   SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent,
123                                const char* theURL,
124                                bool isMultiFile);
125
126   CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent,
127                       const SALOMEDS::TMPFile& theStream,
128                       const char* theURL,
129                       bool isMultiFile);
130
131   CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent,
132                            const SALOMEDS::TMPFile& theStream,
133                            const char* theURL,
134                            bool isMultiFile);
135
136   void Close(SALOMEDS::SComponent_ptr theComponent);
137   char* ComponentDataType();
138
139
140   char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
141                                const char* IORString,
142                                CORBA::Boolean isMultiFile,
143                                CORBA::Boolean isASCII);
144   char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
145                                const char* aLocalPersistentID,
146                                CORBA::Boolean isMultiFile,
147                                CORBA::Boolean isASCII);
148
149   bool CanPublishInStudy(CORBA::Object_ptr theIOR);
150   SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::SObject_ptr theSObject,
151                                        CORBA::Object_ptr theObject,
152                                        const char* theName) throw (SALOME::SALOME_Exception) ;
153
154   GEOM::ListOfGO* PublishNamedShapesInStudy(CORBA::Object_ptr theObject);
155
156   CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject);
157   SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID);
158   CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID);
159   SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream,
160                                   CORBA::Long theObjectID,
161                                   SALOMEDS::SObject_ptr theObject);
162
163   /*! \brief Adds theObject in the study with a name = theName, if
164    *         theFather is not null the object is placed under theFather
165    */
166   SALOMEDS::SObject_ptr AddInStudy (GEOM::GEOM_BaseObject_ptr theObject,
167                                     const char*               theName,
168                                     GEOM::GEOM_BaseObject_ptr theFather);
169
170   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
171    *         To be used from python scripts out of geompy.addToStudy (non-default usage)
172    */
173   GEOM::ListOfGO* RestoreSubShapesO (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 (GEOM::GEOM_Object_ptr   theObject,
183                                           const GEOM::ListOfGO&   theArgs,
184                                           GEOM::find_shape_method theFindMethod,
185                                           CORBA::Boolean          theInheritFirstArg,
186                                           CORBA::Boolean          theAddPrefix);
187
188   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
189    *         To be used from GUI and from geompy.addToStudy
190    */
191   GEOM::ListOfGO* RestoreSubShapesSO (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   //Collects dependencies of the given objects from other ones
198   SALOMEDS::TMPFile* GetDependencyTree(const GEOM::string_array& theObjectEntries);
199
200   //-----------------------------------------------------------------------//
201   // Transaction methods                                                   //
202   //-----------------------------------------------------------------------//
203
204   //Undos one transaction in the document
205   virtual void Undo();
206
207   //Redos one transaction in the document
208   virtual void Redo();
209
210   //-----------------------------------------------------------------------//
211   // Operations methods                                                    //
212   //-----------------------------------------------------------------------//
213
214   //Returns a pointer to BasicOperations interface
215   virtual GEOM::GEOM_IBasicOperations_ptr GetIBasicOperations()
216     throw (SALOME::SALOME_Exception);
217
218   //Returns a pointer to TransformOperations interface
219   virtual GEOM::GEOM_ITransformOperations_ptr GetITransformOperations()
220     throw (SALOME::SALOME_Exception);
221
222   //Returns a pointer to 3DPrimOperations interface
223   virtual GEOM::GEOM_I3DPrimOperations_ptr GetI3DPrimOperations()
224     throw (SALOME::SALOME_Exception);
225
226   //Returns a pointer to ShapesOperations interface
227   virtual GEOM::GEOM_IShapesOperations_ptr GetIShapesOperations()
228     throw (SALOME::SALOME_Exception);
229
230   //Returns a pointer to BlocksOperations interface
231   virtual GEOM::GEOM_IBlocksOperations_ptr GetIBlocksOperations()
232     throw (SALOME::SALOME_Exception);
233
234   //Returns a pointer to BooleanOperations interface
235   virtual GEOM::GEOM_IBooleanOperations_ptr GetIBooleanOperations()
236     throw (SALOME::SALOME_Exception);
237
238   //Returns a pointer to CurvesOperations interface
239   virtual GEOM::GEOM_ICurvesOperations_ptr GetICurvesOperations()
240     throw (SALOME::SALOME_Exception);
241
242   //Returns a pointer to LocalOperations interface
243   virtual GEOM::GEOM_ILocalOperations_ptr GetILocalOperations()
244     throw (SALOME::SALOME_Exception);
245
246   //Returns a pointer to HealingOperations interface
247   virtual GEOM::GEOM_IHealingOperations_ptr GetIHealingOperations()
248     throw (SALOME::SALOME_Exception);
249
250   //Returns a pointer to InsertOperations interface
251   virtual GEOM::GEOM_IInsertOperations_ptr GetIInsertOperations()
252     throw (SALOME::SALOME_Exception);
253
254   //Returns a pointer to MeasureOperations interface
255   virtual GEOM::GEOM_IMeasureOperations_ptr GetIMeasureOperations()
256     throw (SALOME::SALOME_Exception);
257
258   //Returns a pointer to GroupOperations interface
259   virtual GEOM::GEOM_IGroupOperations_ptr GetIGroupOperations()
260     throw (SALOME::SALOME_Exception);
261
262   //Returns a pointer to FiedlOperations interface
263   virtual GEOM::GEOM_IFieldOperations_ptr GetIFieldOperations()
264     throw (SALOME::SALOME_Exception);
265
266   //Returns a pointer to corresponding plugin operations interface
267   virtual GEOM::GEOM_IOperations_ptr GetPluginOperations (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::Boolean isPublished,
281                                        CORBA::Boolean isMultiFile,
282                                        CORBA::Boolean& isValidScript);
283
284   char* GetDumpName (const char* theStudyEntry);
285
286   GEOM::string_array* GetAllDumpNames();
287
288   // Object information
289   virtual bool hasObjectInfo();
290   virtual char* getObjectInfo(const char* entry);
291
292   // Version information
293   virtual char* getVersion();
294
295   // Create a new folder object
296   SALOMEDS::SObject_ptr CreateFolder(const char* theName,
297                                      SALOMEDS::SObject_ptr theFather);
298
299   // Move GEOM object to the specified folder
300   void MoveToFolder(GEOM::GEOM_Object_ptr theObject,
301                     SALOMEDS::SObject_ptr theFolder);
302
303   // Move list of GEOM objects to the specified folder
304   void MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
305                          SALOMEDS::SObject_ptr theFolder);
306
307   // Move objects to the specified position
308   void Move( const GEOM::object_list& what,
309              SALOMEDS::SObject_ptr where,
310              CORBA::Long row );
311
312   /*! \brief Fills 3 lists that is used to clean study of redundant objects.
313    *         To be used from GUI.
314    */
315   void GetEntriesToReduceStudy(GEOM::string_array& theSelectedEntries,
316                                GEOM::string_array& theParentEntries,
317                                GEOM::string_array& theSubEntries,
318                                GEOM::string_array& theOtherEntries);
319
320   //-----------------------------------------------------------------------//
321   // Internal methods                                                      //
322   //-----------------------------------------------------------------------//
323
324   virtual GEOM::GEOM_BaseObject_ptr GetObject(const char* theEntry);
325
326  private:
327   GEOM::ListOfGO* RestoreSubShapes (GEOM::GEOM_Object_ptr   theObject,
328                                     SALOMEDS::SObject_ptr   theSObject,
329                                     const GEOM::ListOfGO&   theArgs,
330                                     GEOM::find_shape_method theFindMethod,
331                                     CORBA::Boolean          theInheritFirstArg,
332                                     CORBA::Boolean          theAddPrefix);
333
334   GEOM::ListOfGO* RestoreSubShapesOneLevel (SALOMEDS::SObject_ptr   theOldSO,
335                                             SALOMEDS::SObject_ptr   theNewSO,
336                                             GEOM::GEOM_Object_ptr   theNewO,
337                                             GEOM::ListOfGO&         theOutArgs,
338                                             GEOM::find_shape_method theFindMethod,
339                                             CORBA::Boolean          theAddPrefix);
340
341   GEOM::ListOfGO* RestoreGivenSubShapes (GEOM::GEOM_Object_ptr   theObject,
342                                          SALOMEDS::SObject_ptr   theSObject,
343                                          const GEOM::ListOfGO&   theArgs,
344                                          GEOM::find_shape_method theFindMethod,
345                                          CORBA::Boolean          theInheritFirstArg,
346                                          CORBA::Boolean          theAddPrefix);
347
348   GEOM::ListOfGO* RestoreGivenSubShapesOneLevel (SALOMEDS::SObject_ptr   theOldSO,
349                                                  SALOMEDS::SObject_ptr   theNewSO,
350                                                  GEOM::GEOM_Object_ptr   theNewO,
351                                                  std::set<std::string>   theArgs,
352                                                  GEOM::find_shape_method theFindMethod,
353                                                  CORBA::Boolean          theAddPrefix);
354
355   // auxilary for PublishNamedShapesInStudy
356   void CreateAndPublishGroup(GEOM::GEOM_Object_var theMainShape,
357                              const TopTools_IndexedMapOfShape& anIndices,
358                              const TopTools_SequenceOfShape& SeqS,
359                              const TColStd_SequenceOfAsciiString& SeqN,
360                              const Standard_CString& GrName,
361                              GEOM::ListOfGO_var aResList);
362
363   void getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
364                             GEOMUtils::LevelsList &upLevelList,
365                             std::map< std::string, std::set<std::string> > &passedEntries,
366                             int level = 0 );
367
368   void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
369                               GEOMUtils::LevelsList &downLevelList,
370                               std::map< std::string, std::set<std::string> > &passedEntries,
371                               int level = 0 );
372
373   void includeParentDependencies(GEOM::GEOM_BaseObject_ptr gbo,
374                                  std::set<std::string>& aSelected,
375                                  std::set<std::string>& aParents,
376                                  std::set<std::string>& aChildren,
377                                  std::set<std::string>& anOthers);
378
379   void includeSubObjects(const std::string& aSelectedEntry,
380                          std::set<std::string>& aSelected,
381                          std::set<std::string>& aParents,
382                          std::set<std::string>& aChildren,
383                          std::set<std::string>& anOthers);
384
385   void LoadPlugin(const std::string& theLibName);
386
387  private:
388
389    ::GEOMImpl_Gen* _impl;
390    SALOME_NamingService * name_service;
391    char * _name;
392
393    // plugin operations managing
394    std::map<std::string, GEOM_GenericOperationsCreator*> myOpCreatorMap;
395 };
396
397 #endif