Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 09:19:01

0001 // Created by: DAUTRY Philippe
0002 // Copyright (c) 1997-1999 Matra Datavision
0003 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _TDF_RelocationTable_HeaderFile
0017 #define _TDF_RelocationTable_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 
0021 #include <TDF_Label.hxx>
0022 #include <NCollection_DataMap.hxx>
0023 #include <TDF_Attribute.hxx>
0024 #include <Standard_Transient.hxx>
0025 #include <NCollection_IndexedDataMap.hxx>
0026 #include <NCollection_Map.hxx>
0027 #include <Standard_Handle.hxx>
0028 #include <Standard_OStream.hxx>
0029 class TDF_Label;
0030 class TDF_Attribute;
0031 
0032 //! This is a relocation dictionary between source
0033 //! and target labels, attributes or any
0034 //! transient(useful for copy or paste actions).
0035 //! Note that one target value may be the
0036 //! relocation value of more than one source object.
0037 //!
0038 //! Common behaviour: it returns true and the found
0039 //! relocation value as target object; false
0040 //! otherwise.
0041 //!
0042 //! Look at SelfRelocate method for more explanation
0043 //! about self relocation behavior of this class.
0044 class TDF_RelocationTable : public Standard_Transient
0045 {
0046 
0047 public:
0048   //! Creates an relocation table. <selfRelocate> says
0049   //! if a value without explicit relocation is its own
0050   //! relocation.
0051   Standard_EXPORT TDF_RelocationTable(const bool selfRelocate = false);
0052 
0053   //! Sets <mySelfRelocate> to <selfRelocate>.
0054   //!
0055   //! This flag affects the HasRelocation method
0056   //! behavior like this:
0057   //!
0058   //! <mySelfRelocate> == False:
0059   //!
0060   //! If no relocation object is found in the map, a
0061   //! null object is returned
0062   //!
0063   //! <mySelfRelocate> == True:
0064   //!
0065   //! If no relocation object is found in the map, the
0066   //! method assumes the source object is relocation
0067   //! value; so the source object is returned as target
0068   //! object.
0069   Standard_EXPORT void SelfRelocate(const bool selfRelocate);
0070 
0071   //! Returns <mySelfRelocate>.
0072   Standard_EXPORT bool SelfRelocate() const;
0073 
0074   Standard_EXPORT void AfterRelocate(const bool afterRelocate);
0075 
0076   //! Returns <myAfterRelocate>.
0077   Standard_EXPORT bool AfterRelocate() const;
0078 
0079   //! Sets the relocation value of <aSourceLabel> to
0080   //! <aTargetLabel>.
0081   Standard_EXPORT void SetRelocation(const TDF_Label& aSourceLabel, const TDF_Label& aTargetLabel);
0082 
0083   //! Finds the relocation value of <aSourceLabel>
0084   //! and returns it into <aTargetLabel>.
0085   //!
0086   //! (See above SelfRelocate method for more
0087   //! explanation about the method behavior)
0088   Standard_EXPORT bool HasRelocation(const TDF_Label& aSourceLabel, TDF_Label& aTargetLabel) const;
0089 
0090   //! Sets the relocation value of <aSourceAttribute> to
0091   //! <aTargetAttribute>.
0092   Standard_EXPORT void SetRelocation(const occ::handle<TDF_Attribute>& aSourceAttribute,
0093                                      const occ::handle<TDF_Attribute>& aTargetAttribute);
0094 
0095   //! Finds the relocation value of <aSourceAttribute>
0096   //! and returns it into <aTargetAttribute>.
0097   //!
0098   //! (See above SelfRelocate method for more
0099   //! explanation about the method behavior)
0100   Standard_EXPORT bool HasRelocation(const occ::handle<TDF_Attribute>& aSourceAttribute,
0101                                      occ::handle<TDF_Attribute>&       aTargetAttribute) const;
0102 
0103   //! Safe variant for arbitrary type of argument
0104   template <class T>
0105   bool HasRelocation(const occ::handle<TDF_Attribute>& theSource, occ::handle<T>& theTarget) const
0106   {
0107     occ::handle<TDF_Attribute> anAttr = theTarget;
0108     return HasRelocation(theSource, anAttr) && !(theTarget = occ::down_cast<T>(anAttr)).IsNull();
0109   }
0110 
0111   //! Sets the relocation value of <aSourceTransient> to
0112   //! <aTargetTransient>.
0113   Standard_EXPORT void SetTransientRelocation(
0114     const occ::handle<Standard_Transient>& aSourceTransient,
0115     const occ::handle<Standard_Transient>& aTargetTransient);
0116 
0117   //! Finds the relocation value of <aSourceTransient>
0118   //! and returns it into <aTargetTransient>.
0119   //!
0120   //! (See above SelfRelocate method for more
0121   //! explanation about the method behavior)
0122   Standard_EXPORT bool HasTransientRelocation(
0123     const occ::handle<Standard_Transient>& aSourceTransient,
0124     occ::handle<Standard_Transient>&       aTargetTransient) const;
0125 
0126   //! Clears the relocation dictionary, but lets the
0127   //! self relocation flag to its current value.
0128   Standard_EXPORT void Clear();
0129 
0130   //! Fills <aLabelMap> with target relocation
0131   //! labels. <aLabelMap> is not cleared before use.
0132   Standard_EXPORT void TargetLabelMap(NCollection_Map<TDF_Label>& aLabelMap) const;
0133 
0134   //! Fills <anAttributeMap> with target relocation
0135   //! attributes. <anAttributeMap> is not cleared before
0136   //! use.
0137   Standard_EXPORT void TargetAttributeMap(
0138     NCollection_Map<occ::handle<TDF_Attribute>>& anAttributeMap) const;
0139 
0140   //! Returns <myLabelTable> to be used or updated.
0141   Standard_EXPORT NCollection_DataMap<TDF_Label, TDF_Label>& LabelTable();
0142 
0143   //! Returns <myAttributeTable> to be used or updated.
0144   Standard_EXPORT NCollection_DataMap<occ::handle<TDF_Attribute>, occ::handle<TDF_Attribute>>&
0145                   AttributeTable();
0146 
0147   //! Returns <myTransientTable> to be used or updated.
0148   Standard_EXPORT NCollection_IndexedDataMap<occ::handle<Standard_Transient>,
0149                                              occ::handle<Standard_Transient>>&
0150                   TransientTable();
0151 
0152   //! Dumps the relocation table.
0153   Standard_EXPORT Standard_OStream& Dump(const bool        dumpLabels,
0154                                          const bool        dumpAttributes,
0155                                          const bool        dumpTransients,
0156                                          Standard_OStream& anOS) const;
0157 
0158   DEFINE_STANDARD_RTTIEXT(TDF_RelocationTable, Standard_Transient)
0159 
0160 private:
0161   bool                                                                        mySelfRelocate;
0162   bool                                                                        myAfterRelocate;
0163   NCollection_DataMap<TDF_Label, TDF_Label>                                   myLabelTable;
0164   NCollection_DataMap<occ::handle<TDF_Attribute>, occ::handle<TDF_Attribute>> myAttributeTable;
0165   NCollection_IndexedDataMap<occ::handle<Standard_Transient>, occ::handle<Standard_Transient>>
0166     myTransientTable;
0167 };
0168 
0169 #endif // _TDF_RelocationTable_HeaderFile