Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:17

0001 // Created on: 2017-04-21
0002 // Created by: Alexander Bobkov
0003 // Copyright (c) 2017 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 _BRepTools_History_HeaderFile
0017 #define _BRepTools_History_HeaderFile
0018 
0019 #include <NCollection_Handle.hxx>
0020 #include <TopExp.hxx>
0021 #include <TopTools_DataMapOfShapeListOfShape.hxx>
0022 #include <TopTools_MapOfShape.hxx>
0023 
0024 class BRepTools_History;
0025 DEFINE_STANDARD_HANDLE(BRepTools_History, Standard_Transient)
0026 
0027 //! The history keeps the following relations between the input shapes
0028 //! (S1, ..., Sm) and output shapes (T1, ..., Tn):
0029 //! 1) an output shape Tj is generated from an input shape Si: Tj <= G(Si);
0030 //! 2) a output shape Tj is modified from an input shape Si: Tj <= M(Si);
0031 //! 3) an input shape (Si) is removed: R(Si) == 1.
0032 //!
0033 //! The relations are kept only for shapes of types vertex, edge, face, and
0034 //! solid.
0035 //!
0036 //! The last relation means that:
0037 //! 1) shape Si is not an output shape and
0038 //! 2) no any shape is modified (produced) from shape Si:
0039 //! R(Si) == 1 ==> Si != Tj, M(Si) == 0.
0040 //!
0041 //! It means that the input shape cannot be removed and modified
0042 //! simultaneously. However, the shapes may be generated from the
0043 //! removed shape. For instance, in Fillet operation the edges
0044 //! generate faces and then are removed.
0045 //!
0046 //! No any shape could be generated and modified from the same shape
0047 //! simultaneously: sets G(Si) and M(Si) are not intersected
0048 //! (G(Si) ^ M(Si) == 0).
0049 //!
0050 //! Each output shape should be:
0051 //! 1) an input shape or
0052 //! 2) generated or modified from an input shape (even generated from the
0053 //!   implicit null shape if necessary):
0054 //!   Tj == Si V (exists Si that Tj <= G(Si) U M(Si)).
0055 //!
0056 //! Recommendations to choose between relations 'generated' and 'modified':
0057 //! 1) a shape is generated from input shapes if it dimension is greater or
0058 //!   smaller than the dimensions of the input shapes;
0059 //! 2) a shape is generated from input shapes if these shapes are also output
0060 //!   shapes;
0061 //! 3) a shape is generated from input shapes of the same dimension if it is
0062 //!   produced by joining shapes generated from these shapes;
0063 //! 4) a shape is modified from an input shape if it replaces the input shape by
0064 //!   changes of the location, the tolerance, the bounds of the parametric
0065 //!   space (the faces for a solid), the parametrization and/or by applying of
0066 //!   an approximation;
0067 //! 5) a shape is modified from input shapes of the same dimension if it is
0068 //!   produced by joining shapes modified from these shapes.
0069 //!
0070 //! Two sequential histories:
0071 //! - one history (H12) of shapes S1, ..., Sm to shapes T1, ..., Tn and
0072 //! - another history (H23) of shapes T1, ..., Tn to shapes Q1, ..., Ql
0073 //! could be merged to the single history (H13) of shapes S1, ..., Sm to shapes
0074 //! Q1, ..., Ql.
0075 //!
0076 //! During the merge:
0077 //! 1) if shape Tj is generated from shape Si then each shape generated or
0078 //!   modified from shape Tj is considered as a shape generated from shape Si
0079 //!   among shapes Q1, ..., Ql:
0080 //!   Tj <= G12(Si), Qk <= G23(Tj) U M23(Tj) ==> Qk <= G13(Si).
0081 //! 2) if shape Tj is modified from shape Si, shape Qk is generated from shape
0082 //!   Tj then shape Qk is considered as a shape generated from shape Si among
0083 //!   shapes Q1, ..., Ql:
0084 //!   Tj <= M12(Si), Qk <= G23(Tj) ==> Qk <= G13(Si);
0085 //! 3) if shape Tj is modified from shape Si, shape Qk is modified from shape
0086 //!   Tj then shape Qk is considered as a shape modified from shape Si among
0087 //!   shapes Q1, ..., Ql:
0088 //!   Tj <= M12(Si), Qk <= M23(Tj) ==> Qk <= M13(Si);
0089 class BRepTools_History: public Standard_Transient
0090 {
0091 public: //! @name Constructors for History creation
0092 
0093   //! Empty constructor
0094   BRepTools_History() {}
0095 
0096   //! Template constructor for History creation from the algorithm having
0097   //! standard history methods such as IsDeleted(), Modified() and Generated().
0098   //! @param theArguments [in] Arguments of the algorithm;
0099   //! @param theAlgo [in] The algorithm.
0100   template <class TheAlgo>
0101   BRepTools_History(const TopTools_ListOfShape& theArguments,
0102                     TheAlgo& theAlgo)
0103   {
0104     // Map all argument shapes to save them in history
0105     TopTools_IndexedMapOfShape anArgsMap;
0106     TopTools_ListIteratorOfListOfShape aIt(theArguments);
0107     for (; aIt.More(); aIt.Next())
0108     {
0109       if (!aIt.Value().IsNull())
0110         TopExp::MapShapes(aIt.Value(), anArgsMap);
0111     }
0112 
0113     // Copy the history for all supported shapes from the algorithm
0114     Standard_Integer i, aNb = anArgsMap.Extent();
0115     for (i = 1; i <= aNb; ++i)
0116     {
0117       const TopoDS_Shape& aS = anArgsMap(i);
0118       if (!IsSupportedType(aS))
0119         continue;
0120 
0121       if (theAlgo.IsDeleted(aS))
0122         Remove(aS);
0123 
0124       // Check Modified
0125       const TopTools_ListOfShape& aModified = theAlgo.Modified(aS);
0126       for (aIt.Initialize(aModified); aIt.More(); aIt.Next())
0127         AddModified(aS, aIt.Value());
0128 
0129       // Check Generated
0130       const TopTools_ListOfShape& aGenerated = theAlgo.Generated(aS);
0131       for (aIt.Initialize(aGenerated); aIt.More(); aIt.Next())
0132         AddGenerated(aS, aIt.Value());
0133     }
0134   }
0135 
0136 public:
0137 
0138   //! The types of the historical relations.
0139   enum TRelationType
0140   {
0141     TRelationType_Removed,
0142     TRelationType_Generated,
0143     TRelationType_Modified
0144   };
0145 
0146 public:
0147 
0148   //! Returns 'true' if the type of the shape is supported by the history.
0149   static Standard_Boolean IsSupportedType(const TopoDS_Shape& theShape)
0150   {
0151     const TopAbs_ShapeEnum aType = theShape.ShapeType();
0152     return aType == TopAbs_VERTEX || aType == TopAbs_EDGE ||
0153       aType == TopAbs_FACE || aType == TopAbs_SOLID;
0154   }
0155 
0156 public: //! Methods to set the history.
0157 
0158   //! Set the second shape as generated one from the first shape.
0159   Standard_EXPORT void AddGenerated(
0160     const TopoDS_Shape& theInitial, const TopoDS_Shape& theGenerated);
0161 
0162   //! Set the second shape as modified one from the first shape.
0163   Standard_EXPORT void AddModified(
0164     const TopoDS_Shape& theInitial, const TopoDS_Shape& theModified);
0165 
0166   //! Set the shape as removed one.
0167   Standard_EXPORT void Remove(const TopoDS_Shape& theRemoved);
0168 
0169   //! Set the second shape as the only generated one from the first one.
0170   Standard_EXPORT void ReplaceGenerated(
0171     const TopoDS_Shape& theInitial, const TopoDS_Shape& theGenerated);
0172 
0173   //! Set the second shape as the only modified one from the first one.
0174   Standard_EXPORT void ReplaceModified(
0175     const TopoDS_Shape& theInitial, const TopoDS_Shape& theModified);
0176 
0177   //! Clears the history.
0178   void Clear()
0179   {
0180     myShapeToModified.Clear();
0181     myShapeToGenerated.Clear();
0182     myRemoved.Clear();
0183   }
0184 
0185 public: //! Methods to read the history.
0186 
0187   //! Returns all shapes generated from the shape.
0188   Standard_EXPORT
0189   const TopTools_ListOfShape& Generated(const TopoDS_Shape& theInitial) const;
0190 
0191   //! Returns all shapes modified from the shape.
0192   Standard_EXPORT
0193   const TopTools_ListOfShape& Modified(const TopoDS_Shape& theInitial) const;
0194 
0195   //! Returns 'true' if the shape is removed.
0196   Standard_EXPORT
0197   Standard_Boolean IsRemoved(const TopoDS_Shape& theInitial) const;
0198 
0199   //! Returns 'true' if there any shapes with Generated elements present
0200   Standard_Boolean HasGenerated() const { return !myShapeToGenerated.IsEmpty(); }
0201 
0202   //! Returns 'true' if there any Modified shapes present
0203   Standard_Boolean HasModified() const { return !myShapeToModified.IsEmpty(); }
0204 
0205   //! Returns 'true' if there any removed shapes present
0206   Standard_Boolean HasRemoved() const { return !myRemoved.IsEmpty(); }
0207 
0208 public: //! A method to merge a next history to this history.
0209 
0210   //! Merges the next history to this history.
0211   Standard_EXPORT void Merge(const Handle(BRepTools_History)& theHistory23);
0212 
0213   //! Merges the next history to this history.
0214   Standard_EXPORT void Merge(const BRepTools_History& theHistory23);
0215 
0216   //! Template method for merging history of the algorithm having standard
0217   //! history methods such as IsDeleted(), Modified() and Generated()
0218   //! into current history object.
0219   //! @param theArguments [in] Arguments of the algorithm;
0220   //! @param theAlgo [in] The algorithm.
0221   template<class TheAlgo>
0222   void Merge(const TopTools_ListOfShape& theArguments,
0223              TheAlgo& theAlgo)
0224   {
0225     // Create new history object from the given algorithm and merge it into this.
0226     Merge(BRepTools_History(theArguments, theAlgo));
0227   }
0228 
0229 public: //! A method to dump a history
0230 
0231   //! Prints the brief description of the history into a stream
0232   void Dump(Standard_OStream& theS)
0233   {
0234     theS << "History contains:\n";
0235     theS << " - " << myRemoved.Extent() << " Deleted shapes;\n";
0236     theS << " - " << myShapeToModified.Extent() << " Modified shapes;\n";
0237     theS << " - " << myShapeToGenerated.Extent() << " Generated shapes.\n";
0238   }
0239 
0240 public:
0241 
0242   //! Define the OCCT RTTI for the type.
0243   DEFINE_STANDARD_RTTIEXT(BRepTools_History, Standard_Transient)
0244 
0245 private:
0246   //! Prepares the shapes generated from the first shape to set the second one
0247   //! as generated one from the first one by the addition or the replacement.
0248   //! Returns 'true' on success.
0249   Standard_Boolean prepareGenerated(
0250     const TopoDS_Shape& theInitial, const TopoDS_Shape& theGenerated);
0251 
0252   //! Prepares the shapes modified from the first shape to set the second one
0253   //! as modified one from the first one by the addition or the replacement.
0254   //! Returns 'true' on success.
0255   Standard_Boolean prepareModified(
0256     const TopoDS_Shape& theInitial, const TopoDS_Shape& theModified);
0257 
0258 private: //! Data to keep the history.
0259 
0260   //! Maps each input shape to all shapes modified from it.
0261   //! If an input shape is not bound to the map then
0262   //! there is no shapes modified from the shape.
0263   //! No any shape should be mapped to an empty list.
0264   TopTools_DataMapOfShapeListOfShape myShapeToModified;
0265 
0266   //! Maps each input shape to all shapes generated from it.
0267   //! If an input shape is not bound to the map then
0268   //! there is no shapes generated from the shape.
0269   //! No any shape should be mapped to an empty list.
0270   TopTools_DataMapOfShapeListOfShape myShapeToGenerated;
0271 
0272   TopTools_MapOfShape myRemoved; //!< The removed shapes.
0273 
0274 private: //! Auxiliary members to read the history.
0275 
0276   //! An auxiliary empty list.
0277   static const TopTools_ListOfShape myEmptyList;
0278 
0279   //! A method to export the auxiliary list.
0280   Standard_EXPORT static const TopTools_ListOfShape& emptyList();
0281 
0282 private:
0283 
0284   //! Auxiliary messages.
0285   static const char* myMsgUnsupportedType;
0286   static const char* myMsgGeneratedAndRemoved;
0287   static const char* myMsgModifiedAndRemoved;
0288   static const char* myMsgGeneratedAndModified;
0289 };
0290 
0291 #endif // _BRepTools_History_HeaderFile