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