|
|
|||
File indexing completed on 2026-09-13 09:15:59
0001 // Created on: 1998-06-03 0002 // Created by: data exchange team 0003 // Copyright (c) 1998-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _BRepTools_ReShape_HeaderFile 0018 #define _BRepTools_ReShape_HeaderFile 0019 0020 #include <BRepTools_History.hxx> 0021 0022 #include <TopoDS_Shape.hxx> 0023 #include <TopoDS_TShape.hxx> 0024 #include <TopTools_ShapeMapHasher.hxx> 0025 #include <NCollection_DataMap.hxx> 0026 #include <NCollection_Map.hxx> 0027 #include <Standard_Integer.hxx> 0028 #include <Standard_Transient.hxx> 0029 #include <TopAbs_ShapeEnum.hxx> 0030 0031 class TopoDS_Vertex; 0032 0033 // resolve name collisions with X11 headers 0034 #ifdef Status 0035 #undef Status 0036 #endif 0037 0038 //! Rebuilds a Shape by making pre-defined substitutions on some 0039 //! of its components 0040 //! 0041 //! In a first phase, it records requests to replace or remove 0042 //! some individual shapes 0043 //! For each shape, the last given request is recorded 0044 //! Requests may be applied "Oriented" (i.e. only to an item with 0045 //! the SAME orientation) or not (the orientation of replacing 0046 //! shape is respectful of that of the original one) 0047 //! 0048 //! Then, these requests may be applied to any shape which may 0049 //! contain one or more of these individual shapes 0050 //! 0051 //! Supports the 'BRepTools_History' history by method 'History'. 0052 class BRepTools_ReShape : public Standard_Transient 0053 { 0054 public: 0055 //! Returns an empty Reshape 0056 Standard_EXPORT BRepTools_ReShape(); 0057 0058 //! Clears all substitutions requests 0059 Standard_EXPORT virtual void Clear(); 0060 0061 //! Sets a request to Remove a Shape whatever the orientation 0062 Standard_EXPORT virtual void Remove(const TopoDS_Shape& shape); 0063 0064 //! Sets a request to Replace a Shape by a new one. 0065 virtual void Replace(const TopoDS_Shape& shape, const TopoDS_Shape& newshape) 0066 { 0067 replace(shape, newshape, TReplacementKind_Modify); 0068 } 0069 0070 //! Merges the parts to the single product. 0071 //! The first part is replaced by the product. 0072 //! The other parts are removed. 0073 //! The history of the merged shapes is presented by equal ways. 0074 template <typename TCollection> 0075 void Merge(const TCollection& theParts, const TopoDS_Shape& theProduct) 0076 { 0077 typename TCollection::Iterator aPIt(theParts); 0078 0079 if (aPIt.More()) 0080 { 0081 replace(aPIt.Value(), theProduct, TReplacementKind_Merge_Main); 0082 0083 aPIt.Next(); 0084 } 0085 0086 const TReplacementKind aKind = TReplacementKind_Merge_Ordinary; 0087 for (; aPIt.More(); aPIt.Next()) 0088 { 0089 replace(aPIt.Value(), theProduct, aKind); 0090 } 0091 } 0092 0093 //! Tells if a shape is recorded for Replace/Remove 0094 Standard_EXPORT virtual bool IsRecorded(const TopoDS_Shape& shape) const; 0095 0096 //! Returns the new value for an individual shape 0097 //! If not recorded, returns the original shape itself 0098 //! If to be Removed, returns a Null Shape 0099 //! Else, returns the replacing item 0100 Standard_EXPORT virtual TopoDS_Shape Value(const TopoDS_Shape& shape) const; 0101 0102 //! Follows the replacement chain for @p theShape to its leaf without descending into sub-shapes. 0103 //! Iterates Value() until a fixpoint is reached. Unlike Apply(), this does not rebuild 0104 //! the shape from its children, so it is safe to call on edges/wires whose sub-shapes 0105 //! have their own pending replacements (avoids cascading sub-shape re-expansion). 0106 //! @return the final replacement, or the original shape if not recorded, 0107 //! or a Null shape if the chain terminates in a Remove. 0108 Standard_EXPORT TopoDS_Shape ValueLeaf(const TopoDS_Shape& theShape) const; 0109 0110 //! Returns a complete substitution status for a shape 0111 //! 0 : not recorded, <newsh> = original <shape> 0112 //! < 0: to be removed, <newsh> is NULL 0113 //! > 0: to be replaced, <newsh> is a new item 0114 //! If <last> is False, returns status and new shape recorded in 0115 //! the map directly for the shape, if True and status > 0 then 0116 //! recursively searches for the last status and new shape. 0117 Standard_EXPORT virtual int Status(const TopoDS_Shape& shape, 0118 TopoDS_Shape& newsh, 0119 const bool last = false); 0120 0121 //! Applies the substitutions requests to a shape. 0122 //! 0123 //! theUntil gives the level of type until which requests are taken into account. 0124 //! For subshapes of the type <until> no rebuild and further exploring are done. 0125 //! 0126 //! NOTE: each subshape can be replaced by shape of the same type 0127 //! or by shape containing only shapes of that type 0128 //! (for example, TopoDS_Edge can be replaced by TopoDS_Edge, 0129 //! TopoDS_Wire or TopoDS_Compound containing TopoDS_Edges). 0130 //! If incompatible shape type is encountered, it is ignored and flag FAIL1 is set in Status. 0131 Standard_EXPORT virtual TopoDS_Shape Apply(const TopoDS_Shape& theShape, 0132 const TopAbs_ShapeEnum theUntil = TopAbs_SHAPE); 0133 0134 //! Returns (modifiable) the flag which defines whether Location of shape take into account 0135 //! during replacing shapes. 0136 virtual bool& ModeConsiderLocation() { return myConsiderLocation; } 0137 0138 //! Returns modified copy of vertex if original one is not recorded or returns modified original 0139 //! vertex otherwise. 0140 //@param theV - original vertex. 0141 //@param theTol - new tolerance of vertex, optional. 0142 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV, const double theTol = -1.0); 0143 0144 //! Returns modified copy of vertex if original one is not recorded or returns modified original 0145 //! vertex otherwise. 0146 //@param theV - original vertex. 0147 //@param theNewPos - new position for vertex copy. 0148 //@param theTol - new tolerance of vertex. 0149 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV, 0150 const gp_Pnt& theNewPos, 0151 const double aTol); 0152 0153 //! Checks if shape has been recorded by reshaper as a value 0154 //@param theShape is the given shape 0155 Standard_EXPORT bool IsNewShape(const TopoDS_Shape& theShape) const; 0156 0157 //! Returns the history of the substituted shapes. 0158 Standard_EXPORT occ::handle<BRepTools_History> History() const; 0159 0160 DEFINE_STANDARD_RTTIEXT(BRepTools_ReShape, Standard_Transient) 0161 0162 protected: 0163 //! The kinds of the replacements. 0164 enum TReplacementKind 0165 { 0166 TReplacementKind_Remove = 1, 0167 TReplacementKind_Modify = 2, 0168 TReplacementKind_Merge_Main = 4, 0169 TReplacementKind_Merge_Ordinary = 8 0170 }; 0171 0172 //! Replaces the first shape by the second one 0173 //! after the following reorientation. 0174 //! 0175 //! If the first shape has the reversed orientation 0176 //! then the both shapes are reversed. 0177 //! If the first shape has the internal or external orientation then: 0178 //! - the second shape is oriented forward (reversed) if it's orientation 0179 //! is equal (not equal) to the orientation of the first shape; 0180 //! - the first shape is oriented forward. 0181 Standard_EXPORT virtual void replace(const TopoDS_Shape& shape, 0182 const TopoDS_Shape& newshape, 0183 const TReplacementKind theKind); 0184 0185 //! Recursive worker for Apply with a DFS in-flight set keyed by TShape handle. 0186 //! Prevents unbounded descent when a replacement is a compound that transitively 0187 //! contains the original shape as a sub-shape (cyclic containment, distinct from 0188 //! cycles in the replacement map itself). 0189 Standard_EXPORT TopoDS_Shape applyImpl(const TopoDS_Shape& theShape, 0190 const TopAbs_ShapeEnum theUntil, 0191 NCollection_Map<occ::handle<TopoDS_TShape>>& theInFlight); 0192 0193 private: 0194 //! Returns 'true' if the kind of a replacement is an ordinary merging. 0195 static bool isOrdinaryMerged(const TReplacementKind theKind) 0196 { 0197 return (theKind == TReplacementKind_Merge_Ordinary); 0198 } 0199 0200 //! A replacement of an initial shape. 0201 struct TReplacement 0202 { 0203 public: 0204 //! The default constructor. 0205 TReplacement() 0206 : myKind(TReplacementKind_Remove) 0207 { 0208 } 0209 0210 //! The initializing constructor. 0211 TReplacement(const TopoDS_Shape& theResult, const TReplacementKind theKind) 0212 : myResult(theResult), 0213 myKind(theKind) 0214 { 0215 } 0216 0217 //! Returns the result of the replacement. 0218 TopoDS_Shape Result() const 0219 { 0220 return (myKind != TReplacementKind_Merge_Ordinary) ? myResult : TopoDS_Shape(); 0221 } 0222 0223 //! Returns the result of the relation. 0224 const TopoDS_Shape& RelationResult() const { return myResult; } 0225 0226 //! Returns the kind of the relation 0227 //! between an initial shape and the result of the replacement. 0228 BRepTools_History::TRelationType RelationKind() const 0229 { 0230 return (myKind == TReplacementKind_Remove) ? BRepTools_History::TRelationType_Removed 0231 : BRepTools_History::TRelationType_Modified; 0232 } 0233 0234 private: 0235 TopoDS_Shape myResult; //!< The result of the replacement. 0236 TReplacementKind myKind; //!< The kind of the replacement. 0237 }; 0238 0239 typedef NCollection_DataMap<TopoDS_Shape, TReplacement, TopTools_ShapeMapHasher> 0240 TShapeToReplacement; 0241 0242 private: 0243 //! Maps each shape to its replacement. 0244 //! If a shape is not bound to the map then the shape is replaced by itself. 0245 TShapeToReplacement myShapeToReplacement; 0246 0247 protected: 0248 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> myNewShapes; 0249 int myStatus; 0250 0251 private: 0252 bool myConsiderLocation; 0253 }; 0254 0255 #endif // _BRepTools_ReShape_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|