8a814a5841e66d612145caaa2cf9de82b6fed4ad
[occt.git] / src / ShapeProcess / ShapeProcess_ShapeContext.hxx
1 // Created on: 2000-08-22
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _ShapeProcess_ShapeContext_HeaderFile
17 #define _ShapeProcess_ShapeContext_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <TopoDS_Shape.hxx>
23 #include <TopTools_DataMapOfShapeShape.hxx>
24 #include <TopAbs_ShapeEnum.hxx>
25 #include <ShapeProcess_Context.hxx>
26 #include <Standard_CString.hxx>
27 #include <Message_Gravity.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <GeomAbs_Shape.hxx>
30 class ShapeExtend_MsgRegistrator;
31 class TopoDS_Shape;
32 class ShapeBuild_ReShape;
33 class BRepTools_Modifier;
34 class Message_Msg;
35
36
37 class ShapeProcess_ShapeContext;
38 DEFINE_STANDARD_HANDLE(ShapeProcess_ShapeContext, ShapeProcess_Context)
39
40 //! Extends Context to handle shapes
41 //! Contains map of shape-shape, and messages
42 //! attached to shapes
43 class ShapeProcess_ShapeContext : public ShapeProcess_Context
44 {
45
46 public:
47
48   
49   Standard_EXPORT ShapeProcess_ShapeContext(const Standard_CString file, const Standard_CString seq = "");
50   
51   //! Initializes a tool by resource file and shape
52   //! to be processed
53   Standard_EXPORT ShapeProcess_ShapeContext(const TopoDS_Shape& S, const Standard_CString file, const Standard_CString seq = "");
54   
55   //! Initializes tool by a new shape and clears all results
56   Standard_EXPORT void Init (const TopoDS_Shape& S);
57   
58   //! Returns shape being processed
59   Standard_EXPORT const TopoDS_Shape& Shape() const;
60   
61   //! Returns current result
62   Standard_EXPORT const TopoDS_Shape& Result() const;
63   
64   //! Returns map of replacements shape -> shape
65   //! This map is not recursive
66   Standard_EXPORT const TopTools_DataMapOfShapeShape& Map() const;
67   
68   Standard_EXPORT const Handle(ShapeExtend_MsgRegistrator)& Messages() const;
69   
70   //! Returns messages recorded during shape processing
71   //! It can be nullified before processing in order to
72   //! avoid recording messages
73   Standard_EXPORT Handle(ShapeExtend_MsgRegistrator)& Messages();
74   
75   Standard_EXPORT void SetDetalisation (const TopAbs_ShapeEnum level);
76   
77   //! Set and get value for detalisation level
78   //! Only shapes of types from TopoDS_COMPOUND and until
79   //! specified detalisation level will be recorded in maps
80   //! To cancel mapping, use TopAbs_SHAPE
81   //! To force full mapping, use TopAbs_VERTEX
82   //! The default level is TopAbs_FACE
83   Standard_EXPORT TopAbs_ShapeEnum GetDetalisation() const;
84   
85   //! Sets a new result shape
86   //! NOTE: this method should be used very carefully
87   //! to keep consistency of modifications
88   //! It is recommended to use RecordModification() methods
89   //! with explicit definition of mapping from current
90   //! result to a new one
91   Standard_EXPORT void SetResult (const TopoDS_Shape& S);
92   
93   Standard_EXPORT void RecordModification (const TopTools_DataMapOfShapeShape& repl, const Handle(ShapeExtend_MsgRegistrator)& msg = 0);
94   
95   Standard_EXPORT void RecordModification (const Handle(ShapeBuild_ReShape)& repl, const Handle(ShapeExtend_MsgRegistrator)& msg);
96   
97   Standard_EXPORT void RecordModification (const Handle(ShapeBuild_ReShape)& repl);
98   
99   //! Records modifications and resets result accordingly
100   //! NOTE: modification of resulting shape should be explicitly
101   //! defined in the maps along with modifications of subshapes
102   //!
103   //! In the last function, sh is the shape on which Modifier
104   //! was run. It can be different from the whole shape,
105   //! but in that case result as a whole should be reset later
106   //! either by call to SetResult(), or by another call to
107   //! RecordModification() which contains mapping of current
108   //! result to a new one explicitly
109   Standard_EXPORT void RecordModification (const TopoDS_Shape& sh, const BRepTools_Modifier& repl, const Handle(ShapeExtend_MsgRegistrator)& msg = 0);
110   
111   //! Record a message for shape S
112   //! Shape S should be one of subshapes of original shape
113   //! (or whole one), but not one of intermediate shapes
114   //! Records only if Message() is not Null
115   Standard_EXPORT void AddMessage (const TopoDS_Shape& S, const Message_Msg& msg, const Message_Gravity gravity = Message_Warning);
116   
117   //! Get value of parameter as being of the type GeomAbs_Shape
118   //! Returns False if parameter is not defined or has a wrong type
119   Standard_EXPORT Standard_Boolean GetContinuity (const Standard_CString param, GeomAbs_Shape& val) const;
120   
121   //! Get value of parameter as being of the type GeomAbs_Shape
122   //! If parameter is not defined or does not have expected
123   //! type, returns default value as specified
124   Standard_EXPORT GeomAbs_Shape ContinuityVal (const Standard_CString param, const GeomAbs_Shape def) const;
125   
126   //! Prints statistics on Shape Processing onto the current Messenger.
127   Standard_EXPORT void PrintStatistics() const;
128
129   //! Set NonManifold flag
130   Standard_EXPORT void SetNonManifold(Standard_Boolean theNonManifold)
131   {
132       myNonManifold = theNonManifold;
133   }
134
135   //! Get NonManifold flag
136   Standard_EXPORT Standard_Boolean IsNonManifold()
137   {
138       return myNonManifold;
139   }
140
141
142   DEFINE_STANDARD_RTTIEXT(ShapeProcess_ShapeContext,ShapeProcess_Context)
143
144 protected:
145
146
147
148
149 private:
150
151
152   TopoDS_Shape myShape;
153   TopoDS_Shape myResult;
154   TopTools_DataMapOfShapeShape myMap;
155   Handle(ShapeExtend_MsgRegistrator) myMsg;
156   TopAbs_ShapeEnum myUntil;
157   Standard_Boolean myNonManifold;
158
159 };
160
161
162
163
164
165
166
167 #endif // _ShapeProcess_ShapeContext_HeaderFile