Salome HOME
Copyright update 2021
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.hh
1 // Copyright (C) 2007-2021  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   virtual ~GEOM_GenericOperationsCreator() {}
79 };
80
81 //=====================================================================
82 // GEOM_Gen_i : class definition
83 //=====================================================================
84 class GEOM_I_EXPORT GEOM_Gen_i : public POA_GEOM::GEOM_Gen, public Engines_Component_i
85 {
86  public:
87
88   //-----------------------------------------------------------------------//
89   // Constructor / Destructor                                              //
90   //-----------------------------------------------------------------------//
91
92   // constructor to be called for servant creation.
93   GEOM_Gen_i();
94   GEOM_Gen_i(CORBA::ORB_ptr orb,
95              PortableServer::POA_ptr poa,
96              PortableServer::ObjectId * contId,
97              const char *instanceName,
98              const char *interfaceName,
99              bool withRegistry = true);
100
101   // destructor, doing nothing (for now)
102   virtual ~GEOM_Gen_i();
103
104   // Get ORB object
105   CORBA::ORB_ptr GetORB() { return CORBA::ORB::_duplicate(_orb); }
106
107   // Get Study
108   virtual SALOMEDS::Study_var getStudyServant() = 0;
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::SObject_ptr theSObject,
147                                        CORBA::Object_ptr theObject,
148                                        const char* theName) ;
149
150   GEOM::ListOfGO* PublishNamedShapesInStudy(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 (GEOM::GEOM_BaseObject_ptr theObject,
163                                     const char*               theName,
164                                     GEOM::GEOM_BaseObject_ptr theFather);
165
166   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
167    *         To be used from python scripts out of geompy.addToStudy (non-default usage)
168    */
169   GEOM::ListOfGO* RestoreSubShapesO (GEOM::GEOM_Object_ptr   theObject,
170                                      const GEOM::ListOfGO&   theArgs,
171                                      GEOM::find_shape_method theFindMethod,
172                                      CORBA::Boolean          theInheritFirstArg,
173                                      CORBA::Boolean          theAddPrefix);
174
175   /*! \brief Publish sub-shapes, standing for given in \a theArgs arguments and sub-shapes.
176    *         To be used from python scripts, generated by Dump Python.
177    */
178   GEOM::ListOfGO* RestoreGivenSubShapesO (GEOM::GEOM_Object_ptr   theObject,
179                                           const GEOM::ListOfGO&   theArgs,
180                                           GEOM::find_shape_method theFindMethod,
181                                           CORBA::Boolean          theInheritFirstArg,
182                                           CORBA::Boolean          theAddPrefix);
183
184   /*! \brief Publish sub-shapes, standing for arguments and sub-shapes of arguments.
185    *         To be used from GUI and from geompy.addToStudy
186    */
187   GEOM::ListOfGO* RestoreSubShapesSO (SALOMEDS::SObject_ptr   theSObject,
188                                       const GEOM::ListOfGO&   theArgs,
189                                       GEOM::find_shape_method theFindMethod,
190                                       CORBA::Boolean          theInheritFirstArg,
191                                       CORBA::Boolean          theAddPrefix);
192
193   //Collects dependencies of the given objects from other ones
194   SALOMEDS::TMPFile* GetDependencyTree(const GEOM::string_array& theObjectEntries);
195
196   //-----------------------------------------------------------------------//
197   // Transaction methods                                                   //
198   //-----------------------------------------------------------------------//
199
200   //Undos one transaction in the document
201   virtual void Undo();
202
203   //Redos one transaction in the document
204   virtual void Redo();
205
206   //-----------------------------------------------------------------------//
207   // Operations methods                                                    //
208   //-----------------------------------------------------------------------//
209
210   //Returns a pointer to BasicOperations interface
211   virtual GEOM::GEOM_IBasicOperations_ptr GetIBasicOperations();
212
213   //Returns a pointer to TransformOperations interface
214   virtual GEOM::GEOM_ITransformOperations_ptr GetITransformOperations();
215
216   //Returns a pointer to 3DPrimOperations interface
217   virtual GEOM::GEOM_I3DPrimOperations_ptr GetI3DPrimOperations();
218
219   //Returns a pointer to ShapesOperations interface
220   virtual GEOM::GEOM_IShapesOperations_ptr GetIShapesOperations();
221
222   //Returns a pointer to BlocksOperations interface
223   virtual GEOM::GEOM_IBlocksOperations_ptr GetIBlocksOperations();
224
225   //Returns a pointer to BooleanOperations interface
226   virtual GEOM::GEOM_IBooleanOperations_ptr GetIBooleanOperations()
227     ;
228
229   //Returns a pointer to CurvesOperations interface
230   virtual GEOM::GEOM_ICurvesOperations_ptr GetICurvesOperations()
231     ;
232
233   //Returns a pointer to LocalOperations interface
234   virtual GEOM::GEOM_ILocalOperations_ptr GetILocalOperations()
235     ;
236
237   //Returns a pointer to HealingOperations interface
238   virtual GEOM::GEOM_IHealingOperations_ptr GetIHealingOperations()
239     ;
240
241   //Returns a pointer to InsertOperations interface
242   virtual GEOM::GEOM_IInsertOperations_ptr GetIInsertOperations()
243     ;
244
245   //Returns a pointer to MeasureOperations interface
246   virtual GEOM::GEOM_IMeasureOperations_ptr GetIMeasureOperations()
247     ;
248
249   //Returns a pointer to GroupOperations interface
250   virtual GEOM::GEOM_IGroupOperations_ptr GetIGroupOperations()
251     ;
252
253   //Returns a pointer to FiedlOperations interface
254   virtual GEOM::GEOM_IFieldOperations_ptr GetIFieldOperations()
255     ;
256
257   //Returns a pointer to corresponding plugin operations interface
258   virtual GEOM::GEOM_IOperations_ptr GetPluginOperations (const char* theLibName)
259     ;
260
261   //Adds a new sub-shape
262   virtual GEOM::GEOM_Object_ptr AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
263                                              const GEOM::ListOfLong& theIndices);
264
265   virtual void RemoveObject(GEOM::GEOM_BaseObject_ptr theObject);
266
267   virtual  char* GetStringFromIOR(GEOM::GEOM_Object_ptr theObject);
268
269   virtual GEOM::GEOM_Object_ptr GetIORFromString(const char* stringIOR);
270
271   virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished,
272                                        CORBA::Boolean isMultiFile,
273                                        CORBA::Boolean& isValidScript);
274
275   char* GetDumpName (const char* theStudyEntry);
276
277   GEOM::string_array* GetAllDumpNames();
278
279   // Object information
280   virtual bool hasObjectInfo();
281   virtual char* getObjectInfo(const char* entry);
282
283   // Version information
284   virtual char* getVersion();
285
286   // Create a new folder object
287   SALOMEDS::SObject_ptr CreateFolder(const char* theName,
288                                      SALOMEDS::SObject_ptr theFather);
289
290   // Move GEOM object to the specified folder
291   void MoveToFolder(GEOM::GEOM_Object_ptr theObject,
292                     SALOMEDS::SObject_ptr theFolder);
293
294   // Move list of GEOM objects to the specified folder
295   void MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
296                          SALOMEDS::SObject_ptr theFolder);
297
298   // Move objects to the specified position
299   void Move( const GEOM::object_list& what,
300              SALOMEDS::SObject_ptr where,
301              CORBA::Long row );
302
303   /*! \brief Fills 3 lists that is used to clean study of redundant objects.
304    *         To be used from GUI.
305    */
306   void GetEntriesToReduceStudy(GEOM::string_array& theSelectedEntries,
307                                GEOM::string_array& theParentEntries,
308                                GEOM::string_array& theSubEntries,
309                                GEOM::string_array& theOtherEntries);
310
311   //-----------------------------------------------------------------------//
312   // Internal methods                                                      //
313   //-----------------------------------------------------------------------//
314
315   virtual GEOM::GEOM_BaseObject_ptr GetObject(const char* theEntry);
316
317  private:
318   SALOMEDS::SComponent_var findOrCreateComponent();
319
320   GEOM::ListOfGO* RestoreSubShapes (GEOM::GEOM_Object_ptr   theObject,
321                                     SALOMEDS::SObject_ptr   theSObject,
322                                     const GEOM::ListOfGO&   theArgs,
323                                     GEOM::find_shape_method theFindMethod,
324                                     CORBA::Boolean          theInheritFirstArg,
325                                     CORBA::Boolean          theAddPrefix);
326
327   GEOM::ListOfGO* RestoreSubShapesOneLevel (SALOMEDS::SObject_ptr   theOldSO,
328                                             SALOMEDS::SObject_ptr   theNewSO,
329                                             GEOM::GEOM_Object_ptr   theNewO,
330                                             GEOM::ListOfGO&         theOutArgs,
331                                             GEOM::find_shape_method theFindMethod,
332                                             CORBA::Boolean          theAddPrefix);
333
334   GEOM::ListOfGO* RestoreGivenSubShapes (GEOM::GEOM_Object_ptr   theObject,
335                                          SALOMEDS::SObject_ptr   theSObject,
336                                          const GEOM::ListOfGO&   theArgs,
337                                          GEOM::find_shape_method theFindMethod,
338                                          CORBA::Boolean          theInheritFirstArg,
339                                          CORBA::Boolean          theAddPrefix);
340
341   GEOM::ListOfGO* RestoreGivenSubShapesOneLevel (SALOMEDS::SObject_ptr   theOldSO,
342                                                  SALOMEDS::SObject_ptr   theNewSO,
343                                                  GEOM::GEOM_Object_ptr   theNewO,
344                                                  std::set<std::string>   theArgs,
345                                                  GEOM::find_shape_method theFindMethod,
346                                                  CORBA::Boolean          theAddPrefix);
347
348   // auxilary for PublishNamedShapesInStudy
349   void CreateAndPublishGroup(GEOM::GEOM_Object_var theMainShape,
350                              const TopTools_IndexedMapOfShape& anIndices,
351                              const TopTools_SequenceOfShape& SeqS,
352                              const TColStd_SequenceOfAsciiString& SeqN,
353                              const Standard_CString& GrName,
354                              GEOM::ListOfGO_var aResList);
355
356   void getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
357                             GEOMUtils::LevelsList &upLevelList,
358                             std::map< std::string, std::set<std::string> > &passedEntries,
359                             int level = 0 );
360
361   void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
362                               GEOMUtils::LevelsList &downLevelList,
363                               std::map< std::string, std::set<std::string> > &passedEntries,
364                               int level = 0 );
365
366   void includeParentDependencies(GEOM::GEOM_BaseObject_ptr gbo,
367                                  std::set<std::string>& aSelected,
368                                  std::set<std::string>& aParents,
369                                  std::set<std::string>& aChildren,
370                                  std::set<std::string>& anOthers);
371
372   void includeSubObjects(const std::string& aSelectedEntry,
373                          std::set<std::string>& aSelected,
374                          std::set<std::string>& aParents,
375                          std::set<std::string>& aChildren,
376                          std::set<std::string>& anOthers);
377
378   void LoadPlugin(const std::string& theLibName);
379
380
381   virtual void BreakLink(const char*) {}
382
383  private:
384
385    ::GEOMImpl_Gen* _impl;
386    char * _name;
387
388    // plugin operations managing
389    std::map<std::string, GEOM_GenericOperationsCreator*> myOpCreatorMap;
390 };
391
392 #endif