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