0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / TNaming / TNaming_Tool.hxx
1 // Created on: 1996-12-24
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _TNaming_Tool_HeaderFile
18 #define _TNaming_Tool_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <TDF_LabelMap.hxx>
25 #include <TNaming_MapOfNamedShape.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <TDF_LabelList.hxx>
29 #include <TopTools_IndexedMapOfShape.hxx>
30 class TNaming_Localizer;
31 class TNaming_NamedShape;
32 class TNaming_OldShapeIterator;
33 class TopoDS_Shape;
34 class TDF_Label;
35 class TNaming_UsedShapes;
36
37
38 //! A tool to get information on the topology of a
39 //! named shape attribute.
40 //! This information is typically a TopoDS_Shape object.
41 //! Using this tool, relations between named shapes
42 //! are also accessible.
43 class TNaming_Tool 
44 {
45 public:
46
47   DEFINE_STANDARD_ALLOC
48
49   
50   //! Returns the last Modification of <NS>.
51   //! Returns the shape CurrentShape contained in
52   //! the named shape attribute NS.
53   //! CurrentShape is the current state of the entities
54   //! if they have been modified in other attributes of the same data structure.
55   //! Each call to this function creates a new compound.
56   Standard_EXPORT static TopoDS_Shape CurrentShape (const Handle(TNaming_NamedShape)& NS);
57   
58   //! Returns the shape CurrentShape contained in
59   //! the named shape attribute NS, and present in
60   //! the updated attribute map Updated.
61   //! CurrentShape is the current state of the entities
62   //! if they have been modified in other attributes of the same data structure.
63   //! Each call to this function creates a new compound.
64   //! Warning
65   //! Only the contents of Updated are searched.R
66   Standard_EXPORT static TopoDS_Shape CurrentShape (const Handle(TNaming_NamedShape)& NS, const TDF_LabelMap& Updated);
67   
68   //! Returns the NamedShape of the last Modification of <NS>.
69   //! This shape is identified by a label.
70   Standard_EXPORT static Handle(TNaming_NamedShape) CurrentNamedShape (const Handle(TNaming_NamedShape)& NS, const TDF_LabelMap& Updated);
71   
72   //! Returns NamedShape the last Modification of <NS>.
73   Standard_EXPORT static Handle(TNaming_NamedShape) CurrentNamedShape (const Handle(TNaming_NamedShape)& NS);
74   
75   //! Returns the named shape attribute defined by
76   //! the shape aShape and the label anAccess.
77   //! This attribute is returned as a new shape.
78   //! You call this function, if you need to create a
79   //! topological attribute for existing data.
80   //! Example
81   //! class MyPkg_MyClass
82   //! {
83   //! public: Standard_Boolean
84   //! SameEdge(const
85   //! Handle(OCafTest_Line)& , const
86   //! Handle(CafTest_Line)& );
87   //! };
88   //!
89   //! Standard_Boolean
90   //! MyPkg_MyClass::SameEdge
91   //! (const Handle(OCafTest_Line)& L1
92   //! const Handle(OCafTest_Line)& L2)
93   //! { Handle(TNaming_NamedShape)
94   //! NS1 = L1->NamedShape();
95   //! Handle(TNaming_NamedShape)
96   //! NS2 = L2->NamedShape();
97   //!
98   //! return
99   //! BRepTools::Compare(NS1->Get(),NS2->Get());
100   //! }
101   //! In the example above, the function SameEdge is
102   //! created to compare the edges having two lines
103   //! for geometric supports. If these edges are found
104   //! by BRepTools::Compare to be within the same
105   //! tolerance, they are considered to be the same.
106   //! Warning
107   //! To avoid sharing of names, a SELECTED
108   //! attribute will not be returned. Sharing of names
109   //! makes it harder to manage the data structure.
110   //! When the user of the name is removed, for
111   //! example, it is difficult to know whether the name
112   //! should be destroyed.
113   Standard_EXPORT static Handle(TNaming_NamedShape) NamedShape (const TopoDS_Shape& aShape, const TDF_Label& anAcces);
114   
115   //! Returns the entities stored in the named shape attribute NS.
116   //! If there is only one old-new pair, the new shape
117   //! is returned. Otherwise, a Compound is returned.
118   //! This compound is made out of all the new shapes found.
119   //! Each call to this function creates a new compound.
120   Standard_EXPORT static TopoDS_Shape GetShape (const Handle(TNaming_NamedShape)& NS);
121   
122   //! Returns the shape contained as OldShape in <NS>
123   Standard_EXPORT static TopoDS_Shape OriginalShape (const Handle(TNaming_NamedShape)& NS);
124   
125   //! Returns the shape generated from S or by a
126   //! modification of S and contained in the named
127   //! shape Generation.
128   Standard_EXPORT static TopoDS_Shape GeneratedShape (const TopoDS_Shape& S, const Handle(TNaming_NamedShape)& Generation);
129   
130   Standard_EXPORT static void Collect (const Handle(TNaming_NamedShape)& NS, TNaming_MapOfNamedShape& Labels, const Standard_Boolean OnlyModif = Standard_True);
131   
132   //! Returns True if <aShape> appears under a label.(DP)
133   Standard_EXPORT static Standard_Boolean HasLabel (const TDF_Label& access, const TopoDS_Shape& aShape);
134   
135   //! Returns  the label  of   the first apparition  of
136   //! <aShape>.  Transdef  is a value of the transaction
137   //! of the first apparition of <aShape>.
138   Standard_EXPORT static TDF_Label Label (const TDF_Label& access, const TopoDS_Shape& aShape, Standard_Integer& TransDef);
139   
140
141   //! Returns the shape created from the shape
142   //! aShape contained in the attribute anAcces.
143   Standard_EXPORT static TopoDS_Shape InitialShape (const TopoDS_Shape& aShape, const TDF_Label& anAcces, TDF_LabelList& Labels);
144   
145   //! Returns the last transaction where the creation of S
146   //! is valid.
147   Standard_EXPORT static Standard_Integer ValidUntil (const TDF_Label& access, const TopoDS_Shape& S);
148   
149   //! Returns the current shape (a Wire or a Shell) built (in the data framework)
150   //! from the the shapes of the argument named shape.
151   //! It is used for IDENTITY name type computation.
152   Standard_EXPORT static void FindShape (const TDF_LabelMap& Valid, const TDF_LabelMap& Forbiden, const Handle(TNaming_NamedShape)& Arg, TopoDS_Shape& S);
153
154
155 friend class TNaming_Localizer;
156 friend class TNaming_NamedShape;
157 friend class TNaming_OldShapeIterator;
158
159
160 protected:
161
162
163
164
165
166 private:
167
168   
169   //! Returns True if <aShape> appears under a label.
170   Standard_EXPORT static Standard_Boolean HasLabel (const Handle(TNaming_UsedShapes)& Shapes, const TopoDS_Shape& aShape);
171   
172   //! Returns the last transaction where the creation of S
173   //! is valid.
174   Standard_EXPORT static Standard_Integer ValidUntil (const TopoDS_Shape& S, const Handle(TNaming_UsedShapes)& US);
175   
176   //! Returns  the label  of   the first apparition  of
177   //! <aShape>.  Transdef  is a value of the transaction
178   //! of the first apparition of <aShape>.
179   Standard_EXPORT static TDF_Label Label (const Handle(TNaming_UsedShapes)& Shapes, const TopoDS_Shape& aShape, Standard_Integer& TransDef);
180   
181   Standard_EXPORT static void FirstOlds (const Handle(TNaming_UsedShapes)& Shapes, const TopoDS_Shape& S, TNaming_OldShapeIterator& it, TopTools_IndexedMapOfShape& MS, TDF_LabelList& Labels);
182
183
184
185
186 };
187
188
189
190
191
192
193
194 #endif // _TNaming_Tool_HeaderFile