1 // Created on: 1998-06-03
2 // Created by: data exchange team
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _BRepTools_ReShape_HeaderFile
18 #define _BRepTools_ReShape_HeaderFile
20 #include <BRepTools_History.hxx>
22 #include <TopTools_DataMapOfShapeShape.hxx>
23 #include <TopTools_MapOfShape.hxx>
24 #include <Standard_Integer.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_Transient.hxx>
27 #include <TopAbs_ShapeEnum.hxx>
32 // resolve name collisions with X11 headers
37 class BRepTools_ReShape;
38 DEFINE_STANDARD_HANDLE(BRepTools_ReShape, Standard_Transient)
40 //! Rebuilds a Shape by making pre-defined substitutions on some
43 //! In a first phase, it records requests to replace or remove
44 //! some individual shapes
45 //! For each shape, the last given request is recorded
46 //! Requests may be applied "Oriented" (i.e. only to an item with
47 //! the SAME orientation) or not (the orientation of replacing
48 //! shape is respectful of that of the original one)
50 //! Then, these requests may be applied to any shape which may
51 //! contain one or more of these individual shapes
53 //! Supports the 'BRepTools_History' history by method 'History'.
54 class BRepTools_ReShape : public Standard_Transient
57 //! Returns an empty Reshape
58 Standard_EXPORT BRepTools_ReShape();
60 //! Clears all substitutions requests
61 Standard_EXPORT virtual void Clear();
63 //! Sets a request to Remove a Shape whatever the orientation
64 Standard_EXPORT virtual void Remove (const TopoDS_Shape& shape);
66 //! Sets a request to Replace a Shape by a new one.
67 virtual void Replace (const TopoDS_Shape& shape, const TopoDS_Shape& newshape)
69 replace (shape, newshape, TReplacementKind_Modify);
72 //! Merges the parts to the single product.
73 //! The first part is replaced by the product.
74 //! The other parts are removed.
75 //! The history of the merged shapes is presented by equal ways.
76 template<typename TCollection> void Merge(
77 const TCollection& theParts, const TopoDS_Shape& theProduct)
79 typename TCollection::Iterator aPIt(theParts);
83 replace(aPIt.Value(), theProduct, TReplacementKind_Merge_Main);
88 const TReplacementKind aKind = TReplacementKind_Merge_Ordinary;
89 for (; aPIt.More(); aPIt.Next())
91 replace(aPIt.Value(), theProduct, aKind);
95 //! Tells if a shape is recorded for Replace/Remove
96 Standard_EXPORT virtual Standard_Boolean IsRecorded (const TopoDS_Shape& shape) const;
98 //! Returns the new value for an individual shape
99 //! If not recorded, returns the original shape itself
100 //! If to be Removed, returns a Null Shape
101 //! Else, returns the replacing item
102 Standard_EXPORT virtual TopoDS_Shape Value (const TopoDS_Shape& shape) const;
104 //! Returns a complete substitution status for a shape
105 //! 0 : not recorded, <newsh> = original <shape>
106 //! < 0: to be removed, <newsh> is NULL
107 //! > 0: to be replaced, <newsh> is a new item
108 //! If <last> is False, returns status and new shape recorded in
109 //! the map directly for the shape, if True and status > 0 then
110 //! recursively searches for the last status and new shape.
111 Standard_EXPORT virtual Standard_Integer Status (const TopoDS_Shape& shape, TopoDS_Shape& newsh, const Standard_Boolean last = Standard_False);
113 //! Applies the substitutions requests to a shape.
115 //! theUntil gives the level of type until which requests are taken into account.
116 //! For subshapes of the type <until> no rebuild and further exploring are done.
118 //! NOTE: each subshape can be replaced by shape of the same type
119 //! or by shape containing only shapes of that type
120 //! (for example, TopoDS_Edge can be replaced by TopoDS_Edge,
121 //! TopoDS_Wire or TopoDS_Compound containing TopoDS_Edges).
122 //! If incompatible shape type is encountered, it is ignored and flag FAIL1 is set in Status.
123 Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& theShape,
124 const TopAbs_ShapeEnum theUntil = TopAbs_SHAPE);
126 //! Returns (modifiable) the flag which defines whether Location of shape take into account
127 //! during replacing shapes.
128 virtual Standard_Boolean& ModeConsiderLocation()
130 return myConsiderLocation;
133 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise.
134 //@param theV - original vertex.
135 //@param theTol - new tolerance of vertex, optional.
136 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV,
137 const Standard_Real theTol = -1.0);
139 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise.
140 //@param theV - original vertex.
141 //@param theNewPos - new position for vertex copy.
142 //@param theTol - new tolerance of vertex.
143 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV,
144 const gp_Pnt& theNewPos,
145 const Standard_Real aTol);
147 //! Checks if shape has been recorded by reshaper as a value
148 //@param theShape is the given shape
149 Standard_EXPORT Standard_Boolean IsNewShape(const TopoDS_Shape& theShape) const;
151 //! Returns the history of the substituted shapes.
152 Standard_EXPORT Handle(BRepTools_History) History() const;
154 DEFINE_STANDARD_RTTIEXT(BRepTools_ReShape,Standard_Transient)
157 //! The kinds of the replacements.
158 enum TReplacementKind
160 TReplacementKind_Remove = 1,
161 TReplacementKind_Modify = 2,
162 TReplacementKind_Merge_Main = 4,
163 TReplacementKind_Merge_Ordinary = 8
166 //! Replaces the first shape by the second one
167 //! after the following reorientation.
169 //! If the first shape has the reversed orientation
170 //! then the both shapes are reversed.
171 //! If the first shape has the internal or external orientation then: <br>
172 //! - the second shape is oriented forward (reversed) if it's orientation
173 //! is equal (not equal) to the orientation of the first shape; <br>
174 //! - the first shape is oriented forward.
175 Standard_EXPORT virtual void replace (
176 const TopoDS_Shape& shape,
177 const TopoDS_Shape& newshape,
178 const TReplacementKind theKind);
181 //! Returns 'true' if the kind of a replacement is an ordinary merging.
182 static Standard_Boolean isOrdinaryMerged(const TReplacementKind theKind)
184 return (theKind == TReplacementKind_Merge_Ordinary);
187 //! A replacement of an initial shape.
191 //! The default constructor.
192 TReplacement() : myKind(TReplacementKind_Remove)
196 //! The initializing constructor.
198 const TopoDS_Shape& theResult, const TReplacementKind theKind) :
199 myResult(theResult), myKind(theKind)
203 //! Returns the result of the replacement.
204 TopoDS_Shape Result() const
206 return (myKind != TReplacementKind_Merge_Ordinary) ?
207 myResult : TopoDS_Shape();
210 //! Returns the result of the relation.
211 const TopoDS_Shape& RelationResult() const
216 //! Returns the kind of the relation
217 //! between an initial shape and the result of the replacement.
218 BRepTools_History::TRelationType RelationKind() const
220 return (myKind == TReplacementKind_Remove) ?
221 BRepTools_History::TRelationType_Removed :
222 BRepTools_History::TRelationType_Modified;
226 TopoDS_Shape myResult; //!< The result of the replacement.
227 TReplacementKind myKind; //!< The kind of the replacement.
230 typedef NCollection_DataMap<TopoDS_Shape, TReplacement,
231 TopTools_ShapeMapHasher> TShapeToReplacement;
234 //! Maps each shape to its replacement.
235 //! If a shape is not bound to the map then the shape is replaced by itself.
236 TShapeToReplacement myShapeToReplacement;
239 TopTools_MapOfShape myNewShapes;
240 Standard_Integer myStatus;
246 Standard_Boolean myConsiderLocation;
257 #endif // _BRepTools_ReShape_HeaderFile