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