38c58add41ec06d49227107a6d577848e5cfff9e
[occt.git] / src / XCAFDoc / XCAFDoc_DimTolTool.hxx
1 // Created on: 2004-01-09
2 // Created by: Sergey KUUL
3 // Copyright (c) 2004-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 _XCAFDoc_DimTolTool_HeaderFile
17 #define _XCAFDoc_DimTolTool_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <TDF_Attribute.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <TDF_LabelSequence.hxx>
25 #include <Standard_Integer.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <NCollection_IndexedDataMap.hxx>
29 #include <NCollection_DataMap.hxx>
30
31 class XCAFDoc_ShapeTool;
32 class TDF_Label;
33 class Standard_GUID;
34 class TCollection_HAsciiString;
35 class TDF_Attribute;
36 class TDF_RelocationTable;
37
38
39 class XCAFDoc_DimTolTool;
40 DEFINE_STANDARD_HANDLE(XCAFDoc_DimTolTool, TDF_Attribute)
41
42 //! Attribute containing GD&T section of XCAF document.
43 //! Provide tools for GD&T section management.
44 class XCAFDoc_DimTolTool : public TDF_Attribute
45 {
46
47 public:
48
49   
50   Standard_EXPORT XCAFDoc_DimTolTool();
51   
52   //! Creates (if not exist) DimTolTool attribute.
53   Standard_EXPORT static Handle(XCAFDoc_DimTolTool) Set (const TDF_Label& L);
54   
55   //! Returns the standard GD&T tool GUID.
56   Standard_EXPORT static const Standard_GUID& GetID();
57   
58   //! Returns the label under which GD&T table is stored.
59   Standard_EXPORT TDF_Label BaseLabel() const;
60   
61   //! Returns internal XCAFDoc_ShapeTool tool
62   Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
63
64   //! Returns True if the label belongs to a GD&T table and
65   //! is a Dimension definition.
66   Standard_EXPORT Standard_Boolean IsDimension (const TDF_Label& theLab) const;
67   
68   //! Returns a sequence of Dimension labels currently stored
69   //! in the GD&T table.
70   Standard_EXPORT void GetDimensionLabels (TDF_LabelSequence& theLabels) const;
71   
72   //! Sets a dimension to sequences target labels.
73   Standard_EXPORT void SetDimension (const TDF_LabelSequence& theFirstLS, 
74                                      const TDF_LabelSequence& theSecondLS, 
75                                      const TDF_Label& theDimL) const;
76
77   //! Sets a dimension to target labels.
78   Standard_EXPORT void SetDimension(const TDF_Label& theFirstL,
79                                      const TDF_Label& theSecondL, 
80                                      const TDF_Label& theDimL) const;
81   
82   //! Sets a dimension to the target label.
83   Standard_EXPORT void SetDimension (const TDF_Label& theL, 
84                                      const TDF_Label& theDimL) const;
85   
86   //! Returns all Dimension labels defined for theShapeL.
87   Standard_EXPORT Standard_Boolean GetRefDimensionLabels (const TDF_Label& theShapeL, 
88                                                           TDF_LabelSequence& theDimensions) const;
89   
90   //! Adds a dimension definition to the GD&T table and returns its label.
91   Standard_EXPORT TDF_Label AddDimension() ;
92   
93   //! Returns True if the label belongs to the GD&T table and is a dimension tolerance.
94   Standard_EXPORT Standard_Boolean IsGeomTolerance (const TDF_Label& theLab) const;
95   
96   //! Returns a sequence of Tolerance labels currently stored in the GD&T table.
97   Standard_EXPORT void GetGeomToleranceLabels (TDF_LabelSequence& theLabels) const;
98   
99   //! Sets a geometry tolerance from theGeomTolL to theL label.
100   //! Checks if theGeomTolL is a geometry tolerance definition first.
101   Standard_EXPORT void SetGeomTolerance (const TDF_Label& theL, 
102                                          const TDF_Label& theGeomTolL) const;
103
104   //! Sets a geometry tolerance from theGeomTolL to sequence of labels theL.
105   //! Checks if theGeomTolL is a geometry tolerance definition first.
106   Standard_EXPORT void SetGeomTolerance(const TDF_LabelSequence& theL,
107                                          const TDF_Label& theGeomTolL) const;
108   
109   //! Returns all GeomTolerance labels defined for theShapeL.
110   Standard_EXPORT Standard_Boolean GetRefGeomToleranceLabels (const TDF_Label& theShapeL, 
111                                                               TDF_LabelSequence& theDimTols) const;
112   
113   //! Adds a GeomTolerance definition to the GD&T table and returns its label.
114   Standard_EXPORT TDF_Label AddGeomTolerance();
115   
116   //! Returns True if theLab belongs to the GD&T table and is a dmension tolerance.
117   Standard_EXPORT Standard_Boolean IsDimTol(const TDF_Label& theLab) const;
118   
119   //! Returns a sequence of D&GTs currently stored in the GD&T table.
120   Standard_EXPORT void GetDimTolLabels (TDF_LabelSequence& Labels) const;
121   
122   //! Finds a dimension tolerance definition in the GD&T table 
123   //! sutisfying the specified kind, values, name and description
124   //! and returns its label if found.
125   //! Returns False if dimension tolerance is not found in DGTtable.
126   Standard_EXPORT Standard_Boolean FindDimTol (const Standard_Integer theKind, 
127                                                const Handle(TColStd_HArray1OfReal)& theVal, 
128                                                const Handle(TCollection_HAsciiString)& theName, 
129                                                const Handle(TCollection_HAsciiString)& theDescription, 
130                                                TDF_Label& lab) const;
131   
132   //! Finds a dimension tolerance in the GD&T table 
133   //! sutisfying the specified kind, values, name and description
134   //! and returns its label if found (or Null label else).
135   Standard_EXPORT TDF_Label FindDimTol (const Standard_Integer theKind, 
136                                         const Handle(TColStd_HArray1OfReal)& theVal, 
137                                         const Handle(TCollection_HAsciiString)& theName, 
138                                         const Handle(TCollection_HAsciiString)& theDescription) const;
139   
140   //! Adds a a dimension tolerance definition with the specified
141   //! kind, value, name and description to the GD&T table and returns its label.
142   Standard_EXPORT TDF_Label AddDimTol (const Standard_Integer theKind, 
143                                        const Handle(TColStd_HArray1OfReal)& theVal, 
144                                        const Handle(TCollection_HAsciiString)& theName, 
145                                        const Handle(TCollection_HAsciiString)& theDescription) const;
146   
147   //! Sets existing dimension tolerance to theL label.
148   Standard_EXPORT void SetDimTol (const TDF_Label& theL, 
149                                   const TDF_Label& theDimTolL) const;
150   
151   //! Creates a dimension tolerance and sets it to theL label.
152   Standard_EXPORT TDF_Label SetDimTol (const TDF_Label& theL, 
153                                        const Standard_Integer theKind, 
154                                        const Handle(TColStd_HArray1OfReal)& theVal, 
155                                        const Handle(TCollection_HAsciiString)& theName, 
156                                        const Handle(TCollection_HAsciiString)& theDescription) const;
157   
158   //! Gets all shape labels reffered by theL label of the GD&T table.
159   //! Returns False if there are no shape labels added to the sequences.
160   Standard_EXPORT Standard_Boolean GetRefShapeLabel (const TDF_Label& theL, 
161                                                      TDF_LabelSequence& theShapeLFirst, 
162                                                      TDF_LabelSequence& theShapeLSecond) const;
163   
164   //! Returns dimension tolerance assigned to theDimTolL label.
165   //! Returns False if no such dimension tolerance is assigned.
166   Standard_EXPORT Standard_Boolean GetDimTol (const TDF_Label& theDimTolL, 
167                                               Standard_Integer& theKind, 
168                                               Handle(TColStd_HArray1OfReal)& theVal, 
169                                               Handle(TCollection_HAsciiString)& theName, 
170                                               Handle(TCollection_HAsciiString)& theDescription) const;
171   
172   //! Returns True if label belongs to the GD&T table and
173   //! is a Datum definition.
174   Standard_EXPORT Standard_Boolean IsDatum (const TDF_Label& lab) const;
175   
176   //! Returns a sequence of Datums currently stored
177   //! in the GD&T table.
178   Standard_EXPORT void GetDatumLabels (TDF_LabelSequence& Labels) const;
179   
180   //! Finds a datum sutisfying the specified name, description and
181   //! identification and returns its label if found.
182   Standard_EXPORT Standard_Boolean FindDatum (const Handle(TCollection_HAsciiString)& theName, 
183                                               const Handle(TCollection_HAsciiString)& theDescription, 
184                                               const Handle(TCollection_HAsciiString)& theIdentification, 
185                                               TDF_Label& lab) const;
186   
187   //! Adds a datum definition to the GD&T table and returns its label.
188   Standard_EXPORT TDF_Label AddDatum (const Handle(TCollection_HAsciiString)& theName, 
189                                       const Handle(TCollection_HAsciiString)& theDescription, 
190                                       const Handle(TCollection_HAsciiString)& theIdentification) const;
191
192   //! Adds a datum definition to the GD&T table and returns its label.
193   Standard_EXPORT TDF_Label AddDatum() ;
194   
195   //! Sets a datum to the sequence of shape labels.
196   Standard_EXPORT void SetDatum (const TDF_LabelSequence& theShapeLabels, 
197                                  const TDF_Label& theDatumL) const;
198   
199   //! Sets a datum to theL label and binds it with theTolerL label.
200   //! A datum with the specified name, description and identification
201   //! is created if it isn't found in the GD&T table.
202   Standard_EXPORT void SetDatum (const TDF_Label& theL, 
203                                  const TDF_Label& theTolerL, 
204                                  const Handle(TCollection_HAsciiString)& theName, 
205                                  const Handle(TCollection_HAsciiString)& theDescription, 
206                                  const Handle(TCollection_HAsciiString)& theIdentification) const;
207
208   //! Sets a datum from theDatumL label to theToletL label.
209   Standard_EXPORT void SetDatumToGeomTol (const TDF_Label& theDatumL, 
210                                           const TDF_Label& theTolerL)  const;
211   
212   //! Returns datum assigned to theDatumL label.
213   //! Returns False if no such datum is assigned.
214   Standard_EXPORT Standard_Boolean GetDatum (const TDF_Label& theDatumL, 
215                                              Handle(TCollection_HAsciiString)& theName, 
216                                              Handle(TCollection_HAsciiString)& theDescription, 
217                                              Handle(TCollection_HAsciiString)& theIdentification) const;
218   
219   //! Returns all Datum labels defined for theDimTolL label.
220   Standard_EXPORT Standard_Boolean GetDatumOfTolerLabels (const TDF_Label& theDimTolL, 
221                                                           TDF_LabelSequence& theDatums) const;
222
223   //! Returns all Datum labels with XCAFDimTolObjects_DatumObject defined for label theDimTolL.
224   Standard_EXPORT Standard_Boolean GetDatumWithObjectOfTolerLabels (const TDF_Label& theDimTolL, 
225                                                                     TDF_LabelSequence& theDatums) const;
226
227   //! Returns all GeomToleranses labels defined for theDatumL label.
228   Standard_EXPORT Standard_Boolean GetTolerOfDatumLabels (const TDF_Label& theDatumL, 
229                                                           TDF_LabelSequence& theTols)  const;
230
231   //! Returns Datum label defined for theShapeL label.
232   Standard_EXPORT Standard_Boolean GetRefDatumLabel (const TDF_Label& theShapeL, 
233                                                      TDF_LabelSequence& theDatum)  const;
234
235   //! Returns true if the given GDT is marked as locked.
236   Standard_EXPORT Standard_Boolean IsLocked(const TDF_Label& theViewL) const;
237
238   //! Mark the given GDT as locked.
239   Standard_EXPORT void Lock(const TDF_Label& theViewL) const;
240
241   //! fill the map GDT label -> shape presentation 
242   Standard_EXPORT void GetGDTPresentations(NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToShape) const;
243
244   //! Set shape presentation for GDT labels according to given map (theGDTLabelToPrs)
245   //! theGDTLabelToPrsName map is an additional argument, can be used to set presentation names.
246   //! If label is not in the theGDTLabelToPrsName map, the presentation name will be empty
247   Standard_EXPORT void SetGDTPresentations(NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToPrs);
248
249   //! Unlock the given GDT.
250   Standard_EXPORT void Unlock(const TDF_Label& theViewL) const;
251     
252   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
253   
254   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
255   
256   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
257   
258   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
259
260
261
262
263   DEFINE_STANDARD_RTTIEXT(XCAFDoc_DimTolTool,TDF_Attribute)
264
265 protected:
266
267
268
269
270 private:
271
272
273   Handle(XCAFDoc_ShapeTool) myShapeTool;
274
275
276 };
277
278
279
280
281
282
283
284 #endif // _XCAFDoc_DimTolTool_HeaderFile