1 // Created on: 1993-02-02 2 // Created by: Christian CAILLET 3 // Copyright (c) 1993-1999 Matra Datavision 4 // Copyright (c) 1999-2014 OPEN CASCADE SAS 5 // 6 // This file is part of Open CASCADE Technology software library. 7 // 8 // This library is free software; you can redistribute it and/or modify it under 9 // the terms of the GNU Lesser General Public License version 2.1 as published 10 // by the Free Software Foundation, with special exception defined in the file 11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 12 // distribution for complete text of the license and disclaimer of any warranty. 13 // 14 // Alternatively, this file may be used under the terms of Open CASCADE 15 // commercial license or contractual agreement. 16 17 #ifndef _Interface_CopyTool_HeaderFile 18 #define _Interface_CopyTool_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_DefineAlloc.hxx> 22 #include <Standard_Handle.hxx> 23 24 #include <Interface_BitMap.hxx> 25 #include <Interface_GeneralLib.hxx> 26 #include <Standard_Integer.hxx> 27 #include <TColStd_SequenceOfInteger.hxx> 28 #include <Standard_Boolean.hxx> 29 class Interface_InterfaceModel; 30 class Interface_CopyControl; 31 class Interface_CopyMap; 32 class Standard_Transient; 33 class Interface_GeneralModule; 34 class Interface_Protocol; 35 class Interface_EntityIterator; 36 37 38 //! Performs Deep Copies of sets of Entities 39 //! Allows to perform Copy of Interface Entities from a Model to 40 //! another one. Works by calling general services GetFromAnother 41 //! and GetImplied. 42 //! Uses a CopyMap to bind a unique Result to each Copied Entity 43 //! 44 //! It is possible to command Copies of Entities (and those they 45 //! reference) by call to the General Service Library, or to 46 //! enforce results for transfer of some Entities (calling Bind) 47 //! 48 //! A Same CopyTool can be used for several successive Copies from 49 //! the same Model : either by restarting from scratch (e.g. to 50 //! copy different parts of a starting Model to several Targets), 51 //! or incremental : in that case, it is possible to know what is 52 //! the content of the last increment (defined by last call to 53 //! ClearLastFlags and queried by call to LastCopiedAfter) 54 //! 55 //! Works in two times : first, create the list of copied Entities 56 //! second, pushes them to a target Model (manages also Model's 57 //! Header) or returns the Result as an Iterator, as desired 58 //! 59 //! The core action (Copy) works by using ShallowCopy (method 60 //! attached to each class) and Copy from GeneralLib (itself using 61 //! dedicated tools). It can be redefined for specific actions. 62 class Interface_CopyTool 63 { 64 public: 65 66 DEFINE_STANDARD_ALLOC 67 68 69 //! Creates a CopyTool adapted to work from a Model. Works 70 //! with a General Service Library, given as an argument 71 Standard_EXPORT Interface_CopyTool(const Handle(Interface_InterfaceModel)& amodel, const Interface_GeneralLib& lib); 72 73 //! Same as above, but Library is defined through a Protocol 74 Standard_EXPORT Interface_CopyTool(const Handle(Interface_InterfaceModel)& amodel, const Handle(Interface_Protocol)& protocol); 75 76 //! Same as above, but works with the Active Protocol 77 Standard_EXPORT Interface_CopyTool(const Handle(Interface_InterfaceModel)& amodel); 78 79 //! Returns the Model on which the CopyTool works 80 Standard_EXPORT Handle(Interface_InterfaceModel) Model() const; 81 82 //! Changes the Map of Result for another one. This allows to work 83 //! with a more sophisticated Mapping Control than the Standard 84 //! one which is CopyMap (e.g. TransferProcess from Transfer) 85 Standard_EXPORT void SetControl (const Handle(Interface_CopyControl)& othermap); 86 87 //! Returns the object used for Control 88 Standard_EXPORT Handle(Interface_CopyControl) Control() const; 89 90 //! Clears Transfer List. Gets Ready to begin another Transfer 91 Standard_EXPORT virtual void Clear(); 92 93 //! Creates the CounterPart of an Entity (by ShallowCopy), Binds 94 //! it, then Copies the content of the former Entity to the other 95 //! one (same Type), by call to the General Service Library 96 //! It may command the Copy of Referenced Entities 97 //! Then, its returns True. 98 //! 99 //! If <mapped> is True, the Map is used to store the Result 100 //! Else, the Result is simply produced : it can be used to Copy 101 //! internal sub-parts of Entities, which are not intended to be 102 //! shared (Strings, Arrays, etc...) 103 //! If <errstat> is True, this means that the Entity is recorded 104 //! in the Model as Erroneous : in this case, the General Service 105 //! for Deep Copy is not called (this could be dangerous) : hence 106 //! the Counter-Part is produced but empty, it can be referenced. 107 //! 108 //! This method does nothing and returns False if the Protocol 109 //! does not recognize <ent>. 110 //! It basically makes a Deep Copy without changing the Types. 111 //! It can be redefined for special uses. 112 Standard_EXPORT virtual Standard_Boolean Copy (const Handle(Standard_Transient)& entfrom, Handle(Standard_Transient)& entto, const Standard_Boolean mapped, const Standard_Boolean errstat); 113 114 //! Transfers one Entity, if not yet bound to a result 115 //! Remark : For an Entity which is reported in the Starting Model, 116 //! the ReportEntity will also be copied with its Content if it 117 //! has one (at least ShallowCopy; Complete Copy if the Protocol 118 //! recognizes the Content : see method Copy) 119 Standard_EXPORT Handle(Standard_Transient) Transferred (const Handle(Standard_Transient)& ent); 120 121 //! Defines a Result for the Transfer of a Starting object. 122 //! Used by method Transferred (which performs a normal Copy), 123 //! but can also be called to enforce a result : in the latter 124 //! case, the enforced result must be compatible with the other 125 //! Transfers which are performed 126 Standard_EXPORT void Bind (const Handle(Standard_Transient)& ent, const Handle(Standard_Transient)& res); 127 128 //! Search for the result of a Starting Object (i.e. an Entity) 129 //! Returns True if a Result is Bound (and fills "result") 130 //! Returns False if no result is Bound 131 Standard_EXPORT Standard_Boolean Search (const Handle(Standard_Transient)& ent, Handle(Standard_Transient)& res) const; 132 133 //! Clears LastFlags only. This allows to know what Entities are 134 //! copied after its call (see method LastCopiedAfter). It can be 135 //! used when copies are done by increments, which must be 136 //! distinghished. ClearLastFlags is also called by Clear. 137 Standard_EXPORT void ClearLastFlags(); 138 139 //! Returns an copied Entity and its Result which were operated 140 //! after last call to ClearLastFlags. It returns the first 141 //! "Last Copied Entity" which Number follows <numfrom>, Zero if 142 //! none. It is used in a loop as follow : 143 //! Integer num = 0; 144 //! while ( (num = CopyTool.LastCopiedAfter(num,ent,res)) ) { 145 //! .. Process Starting <ent> and its Result <res> 146 //! } 147 Standard_EXPORT Standard_Integer LastCopiedAfter (const Standard_Integer numfrom, Handle(Standard_Transient)& ent, Handle(Standard_Transient)& res) const; 148 149 //! Transfers one Entity and records result into the Transfer List 150 //! Calls method Transferred 151 Standard_EXPORT void TransferEntity (const Handle(Standard_Transient)& ent); 152 153 //! Renews the Implied References. These References do not involve 154 //! Copying of referenced Entities. For such a Reference, if the 155 //! Entity which defines it AND the referenced Entity are both 156 //! copied, then this Reference is renewed. Else it is deleted in 157 //! the copied Entities. 158 //! Remark : this concerns only some specific references, such as 159 //! "back pointers". 160 Standard_EXPORT void RenewImpliedRefs(); 161 162 //! Fills a Model with the result of the transfer (TransferList) 163 //! Commands copy of Header too, and calls RenewImpliedRefs 164 Standard_EXPORT void FillModel (const Handle(Interface_InterfaceModel)& bmodel); 165 166 //! Returns the complete list of copied Entities 167 //! If <withreports> is given True, the entities which were 168 //! reported in the Starting Model are replaced in the list 169 //! by the copied ReportEntities 170 Standard_EXPORT Interface_EntityIterator CompleteResult (const Standard_Boolean withreports = Standard_False) const; 171 172 //! Returns the list of Root copied Entities (those which were 173 //! asked for copy by the user of CopyTool, not by copying 174 //! another Entity) 175 Standard_EXPORT Interface_EntityIterator RootResult (const Standard_Boolean withreports = Standard_False) const; 176 Standard_EXPORT virtual ~Interface_CopyTool(); 177 178 179 180 181 protected: 182 183 184 //! Creates a new void instance (just created) of the same class 185 //! as <entfrom>. Uses the general service GeneralModule:NewVoid 186 //! Returns True if OK (Recognize has succeeded), False else 187 //! (in such a case, the standard method ShallowCopy is called 188 //! to produce <ento> from <entfrom> : hence it is not void) 189 //! 190 //! No mapping is managed by this method 191 Standard_EXPORT virtual Standard_Boolean NewVoid (const Handle(Standard_Transient)& entfrom, Handle(Standard_Transient)& entto); 192 193 194 Interface_GeneralLib thelib; 195 196 197 private: 198 199 200 //! Renews the Implied References of one already Copied Entity 201 Standard_EXPORT virtual void Implied (const Handle(Standard_Transient)& entfrom, const Handle(Standard_Transient)& entto); 202 203 204 Handle(Interface_InterfaceModel) themod; 205 Handle(Interface_CopyControl) themap; 206 Handle(Interface_CopyMap) therep; 207 Interface_BitMap thelst; 208 Standard_Integer thelev; 209 TColStd_SequenceOfInteger therts; 210 Standard_Boolean theimp; 211 Handle(Standard_Transient) theent; 212 Handle(Interface_GeneralModule) themdu; 213 Standard_Integer theCN; 214 215 216 }; 217 218 219 220 221 222 223 224 #endif // _Interface_CopyTool_HeaderFile 225