|
||||
File indexing completed on 2025-01-18 10:03:17
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 <TopTools_DataMapOfShapeShape.hxx> 0023 #include <TopTools_MapOfShape.hxx> 0024 #include <Standard_Integer.hxx> 0025 #include <Standard_Transient.hxx> 0026 #include <TopAbs_ShapeEnum.hxx> 0027 0028 class TopoDS_Vertex; 0029 0030 // resolve name collisions with X11 headers 0031 #ifdef Status 0032 #undef Status 0033 #endif 0034 0035 class BRepTools_ReShape; 0036 DEFINE_STANDARD_HANDLE(BRepTools_ReShape, Standard_Transient) 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> void Merge( 0075 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 Standard_Boolean 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 //! Returns a complete substitution status for a shape 0103 //! 0 : not recorded, <newsh> = original <shape> 0104 //! < 0: to be removed, <newsh> is NULL 0105 //! > 0: to be replaced, <newsh> is a new item 0106 //! If <last> is False, returns status and new shape recorded in 0107 //! the map directly for the shape, if True and status > 0 then 0108 //! recursively searches for the last status and new shape. 0109 Standard_EXPORT virtual Standard_Integer Status (const TopoDS_Shape& shape, TopoDS_Shape& newsh, const Standard_Boolean last = Standard_False); 0110 0111 //! Applies the substitutions requests to a shape. 0112 //! 0113 //! theUntil gives the level of type until which requests are taken into account. 0114 //! For subshapes of the type <until> no rebuild and further exploring are done. 0115 //! 0116 //! NOTE: each subshape can be replaced by shape of the same type 0117 //! or by shape containing only shapes of that type 0118 //! (for example, TopoDS_Edge can be replaced by TopoDS_Edge, 0119 //! TopoDS_Wire or TopoDS_Compound containing TopoDS_Edges). 0120 //! If incompatible shape type is encountered, it is ignored and flag FAIL1 is set in Status. 0121 Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& theShape, 0122 const TopAbs_ShapeEnum theUntil = TopAbs_SHAPE); 0123 0124 //! Returns (modifiable) the flag which defines whether Location of shape take into account 0125 //! during replacing shapes. 0126 virtual Standard_Boolean& ModeConsiderLocation() 0127 { 0128 return myConsiderLocation; 0129 } 0130 0131 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise. 0132 //@param theV - original vertex. 0133 //@param theTol - new tolerance of vertex, optional. 0134 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV, 0135 const Standard_Real theTol = -1.0); 0136 0137 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise. 0138 //@param theV - original vertex. 0139 //@param theNewPos - new position for vertex copy. 0140 //@param theTol - new tolerance of vertex. 0141 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV, 0142 const gp_Pnt& theNewPos, 0143 const Standard_Real aTol); 0144 0145 //! Checks if shape has been recorded by reshaper as a value 0146 //@param theShape is the given shape 0147 Standard_EXPORT Standard_Boolean IsNewShape(const TopoDS_Shape& theShape) const; 0148 0149 //! Returns the history of the substituted shapes. 0150 Standard_EXPORT Handle(BRepTools_History) History() const; 0151 0152 DEFINE_STANDARD_RTTIEXT(BRepTools_ReShape,Standard_Transient) 0153 0154 protected: 0155 //! The kinds of the replacements. 0156 enum TReplacementKind 0157 { 0158 TReplacementKind_Remove = 1, 0159 TReplacementKind_Modify = 2, 0160 TReplacementKind_Merge_Main = 4, 0161 TReplacementKind_Merge_Ordinary = 8 0162 }; 0163 0164 //! Replaces the first shape by the second one 0165 //! after the following reorientation. 0166 //! 0167 //! If the first shape has the reversed orientation 0168 //! then the both shapes are reversed. 0169 //! If the first shape has the internal or external orientation then: <br> 0170 //! - the second shape is oriented forward (reversed) if it's orientation 0171 //! is equal (not equal) to the orientation of the first shape; <br> 0172 //! - the first shape is oriented forward. 0173 Standard_EXPORT virtual void replace ( 0174 const TopoDS_Shape& shape, 0175 const TopoDS_Shape& newshape, 0176 const TReplacementKind theKind); 0177 0178 private: 0179 //! Returns 'true' if the kind of a replacement is an ordinary merging. 0180 static Standard_Boolean isOrdinaryMerged(const TReplacementKind theKind) 0181 { 0182 return (theKind == TReplacementKind_Merge_Ordinary); 0183 } 0184 0185 //! A replacement of an initial shape. 0186 struct TReplacement 0187 { 0188 public: 0189 //! The default constructor. 0190 TReplacement() : myKind(TReplacementKind_Remove) 0191 { 0192 } 0193 0194 //! The initializing constructor. 0195 TReplacement( 0196 const TopoDS_Shape& theResult, const TReplacementKind theKind) : 0197 myResult(theResult), myKind(theKind) 0198 { 0199 } 0200 0201 //! Returns the result of the replacement. 0202 TopoDS_Shape Result() const 0203 { 0204 return (myKind != TReplacementKind_Merge_Ordinary) ? 0205 myResult : TopoDS_Shape(); 0206 } 0207 0208 //! Returns the result of the relation. 0209 const TopoDS_Shape& RelationResult() const 0210 { 0211 return myResult; 0212 } 0213 0214 //! Returns the kind of the relation 0215 //! between an initial shape and the result of the replacement. 0216 BRepTools_History::TRelationType RelationKind() const 0217 { 0218 return (myKind == TReplacementKind_Remove) ? 0219 BRepTools_History::TRelationType_Removed : 0220 BRepTools_History::TRelationType_Modified; 0221 } 0222 0223 private: 0224 TopoDS_Shape myResult; //!< The result of the replacement. 0225 TReplacementKind myKind; //!< The kind of the replacement. 0226 }; 0227 0228 typedef NCollection_DataMap<TopoDS_Shape, TReplacement, 0229 TopTools_ShapeMapHasher> TShapeToReplacement; 0230 0231 private: 0232 //! Maps each shape to its replacement. 0233 //! If a shape is not bound to the map then the shape is replaced by itself. 0234 TShapeToReplacement myShapeToReplacement; 0235 0236 protected: 0237 TopTools_MapOfShape myNewShapes; 0238 Standard_Integer myStatus; 0239 0240 0241 private: 0242 0243 0244 Standard_Boolean myConsiderLocation; 0245 0246 0247 }; 0248 0249 0250 0251 0252 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 |