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 //! <until> gives the level of type until which requests are taken
116 //! into account. For subshapes of the type <until> no rebuild
117 //! and futher exploring are done.
119 //! NOTE: each subshape can be replaced by shape of the same type
120 //! or by shape containing only shapes of that type (for
121 //! example, TopoDS_Edge can be replaced by TopoDS_Edge,
122 //! TopoDS_Wire or TopoDS_Compound containing TopoDS_Edges).
123 //! If incompatible shape type is encountered, it is ignored
124 //! and flag FAIL1 is set in Status.
125 Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& shape, const TopAbs_ShapeEnum until = TopAbs_SHAPE);
127 //! Returns (modifiable) the flag which defines whether Location of shape take into account
128 //! during replacing shapes.
129 virtual Standard_Boolean& ModeConsiderLocation()
131 return myConsiderLocation;
134 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise.
135 //@param theV - original vertex.
136 //@param theTol - new tolerance of vertex, optional.
137 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV,
138 const Standard_Real theTol = -1.0);
140 //! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise.
141 //@param theV - original vertex.
142 //@param theNewPos - new position for vertex copy.
143 //@param theTol - new tolerance of vertex.
144 Standard_EXPORT TopoDS_Vertex CopyVertex(const TopoDS_Vertex& theV,
145 const gp_Pnt& theNewPos,
146 const Standard_Real aTol);
148 //! Checks if shape has been recorded by reshaper as a value
149 //@param theShape is the given shape
150 Standard_EXPORT Standard_Boolean IsNewShape(const TopoDS_Shape& theShape) const;
152 //! Returns the history of the substituted shapes.
153 Standard_EXPORT Handle(BRepTools_History) History() const;
155 DEFINE_STANDARD_RTTIEXT(BRepTools_ReShape,Standard_Transient)
158 //! The kinds of the replacements.
159 enum TReplacementKind
161 TReplacementKind_Remove = 1,
162 TReplacementKind_Modify = 2,
163 TReplacementKind_Merge_Main = 4,
164 TReplacementKind_Merge_Ordinary = 8
167 //! Replaces the first shape by the second one
168 //! after the following reorientation.
170 //! If the first shape has the reversed orientation
171 //! then the both shapes are reversed.
172 //! If the first shape has the internal or external orientation then: <br>
173 //! - the second shape is oriented forward (reversed) if it's orientation
174 //! is equal (not equal) to the orientation of the first shape; <br>
175 //! - the first shape is oriented forward.
176 Standard_EXPORT virtual void replace (
177 const TopoDS_Shape& shape,
178 const TopoDS_Shape& newshape,
179 const TReplacementKind theKind);
182 //! Returns 'true' if the kind of a replacement is an ordinary merging.
183 static Standard_Boolean isOrdinaryMerged(const TReplacementKind theKind)
185 return (theKind == TReplacementKind_Merge_Ordinary);
188 //! A replacement of an initial shape.
192 //! The default constructor.
193 TReplacement() : myKind(TReplacementKind_Remove)
197 //! The initializing constructor.
199 const TopoDS_Shape& theResult, const TReplacementKind theKind) :
200 myResult(theResult), myKind(theKind)
204 //! Returns the result of the replacement.
205 TopoDS_Shape Result() const
207 return (myKind != TReplacementKind_Merge_Ordinary) ?
208 myResult : TopoDS_Shape();
211 //! Returns the result of the relation.
212 const TopoDS_Shape& RelationResult() const
217 //! Returns the kind of the relation
218 //! between an initial shape and the result of the replacement.
219 BRepTools_History::TRelationType RelationKind() const
221 return (myKind == TReplacementKind_Remove) ?
222 BRepTools_History::TRelationType_Removed :
223 BRepTools_History::TRelationType_Modified;
227 TopoDS_Shape myResult; //!< The result of the replacement.
228 TReplacementKind myKind; //!< The kind of the replacement.
231 typedef NCollection_DataMap<TopoDS_Shape, TReplacement,
232 TopTools_ShapeMapHasher> TShapeToReplacement;
235 //! Maps each shape to its replacement.
236 //! If a shape is not bound to the map then the shape is replaced by itself.
237 TShapeToReplacement myShapeToReplacement;
240 TopTools_MapOfShape myNewShapes;
241 Standard_Integer myStatus;
247 Standard_Boolean myConsiderLocation;
258 #endif // _BRepTools_ReShape_HeaderFile