0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / XCAFDoc / XCAFDoc_DimTolTool.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
5df609e7 14#include <XCAFDoc_DimTolTool.hxx>
bc73b006 15
42cf5bc1 16#include <Standard_Type.hxx>
6595eee7 17#include <TColStd_MapOfAsciiString.hxx>
42cf5bc1 18#include <TDataStd_Name.hxx>
19#include <TDataStd_TreeNode.hxx>
0c63f2f8 20#include <TDataStd_UAttribute.hxx>
42cf5bc1 21#include <TDF_Attribute.hxx>
22#include <TDF_ChildIDIterator.hxx>
23#include <TDF_Label.hxx>
24#include <TDF_RelocationTable.hxx>
39b707a6 25#include <TDF_Tool.hxx>
6595eee7 26#include <XCAFDimTolObjects_DatumObject.hxx>
61ace3dc 27#include <XCAFDimTolObjects_DimensionObject.hxx>
28#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
7fd59977 29#include <XCAFDoc.hxx>
9ebaae37 30#include <XCAFDoc_Dimension.hxx>
31#include <XCAFDoc_GeomTolerance.hxx>
7fd59977 32#include <XCAFDoc_Datum.hxx>
42cf5bc1 33#include <XCAFDoc_DimTol.hxx>
34#include <XCAFDoc_DimTolTool.hxx>
7fd59977 35#include <XCAFDoc_DocumentTool.hxx>
36#include <XCAFDoc_GraphNode.hxx>
42cf5bc1 37#include <XCAFDoc_ShapeTool.hxx>
7fd59977 38
5df609e7 39
c99ad5d7 40IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_DimTolTool,TDataStd_GenericEmpty,"xcaf","DimTolTool")
92efcf78 41
7fd59977 42//=======================================================================
43//function : XCAFDoc_DimTolTool
44//purpose :
45//=======================================================================
7fd59977 46XCAFDoc_DimTolTool::XCAFDoc_DimTolTool()
47{
48}
49
50
51//=======================================================================
52//function : Set
53//purpose :
54//=======================================================================
55
56Handle(XCAFDoc_DimTolTool) XCAFDoc_DimTolTool::Set(const TDF_Label& L)
57{
58 Handle(XCAFDoc_DimTolTool) A;
59 if (!L.FindAttribute (XCAFDoc_DimTolTool::GetID(), A)) {
60 A = new XCAFDoc_DimTolTool ();
61 L.AddAttribute(A);
62 A->myShapeTool = XCAFDoc_DocumentTool::ShapeTool(L);
63 }
64 return A;
65}
66
67
68//=======================================================================
69//function : GetID
70//purpose :
71//=======================================================================
72
73const Standard_GUID& XCAFDoc_DimTolTool::GetID()
74{
75 static Standard_GUID DGTTblID ("72afb19b-44de-11d8-8776-001083004c77");
76 return DGTTblID;
77}
78
79
80//=======================================================================
81//function : BaseLabel
82//purpose :
83//=======================================================================
84
85TDF_Label XCAFDoc_DimTolTool::BaseLabel() const
86{
87 return Label();
88}
89
90
91//=======================================================================
92//function : ShapeTool
93//purpose :
94//=======================================================================
95
96const Handle(XCAFDoc_ShapeTool)& XCAFDoc_DimTolTool::ShapeTool()
97{
98 if(myShapeTool.IsNull())
99 myShapeTool = XCAFDoc_DocumentTool::ShapeTool(Label());
100 return myShapeTool;
101}
102
103
104//=======================================================================
105//function : IsDimTol
106//purpose :
107//=======================================================================
108
9ebaae37 109Standard_Boolean XCAFDoc_DimTolTool::IsDimTol(const TDF_Label& theDimTolL) const
7fd59977 110{
9ebaae37 111 Handle(XCAFDoc_DimTol) aDimTolAttr;
112 if(theDimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),aDimTolAttr)) {
7fd59977 113 return Standard_True;
114 }
115 return Standard_False;
116}
117
9ebaae37 118//=======================================================================
119//function : IsDimension
120//purpose :
121//=======================================================================
122
123Standard_Boolean XCAFDoc_DimTolTool::IsDimension(const TDF_Label& theDimTolL) const
124{
125 Handle(XCAFDoc_Dimension) aDimTolAttr;
126 if(theDimTolL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimTolAttr)) {
127 return Standard_True;
128 }
129 return Standard_False;
130}
131
132//=======================================================================
133//function : IsGeomTolerance
134//purpose :
135//=======================================================================
136
137Standard_Boolean XCAFDoc_DimTolTool::IsGeomTolerance(const TDF_Label& theDimTolL) const
138{
139 Handle(XCAFDoc_GeomTolerance) aDimTolAttr;
140 if(theDimTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimTolAttr)) {
141 return Standard_True;
142 }
143 return Standard_False;
144}
7fd59977 145
146//=======================================================================
147//function : GetDimTolLabels
148//purpose :
149//=======================================================================
150
9ebaae37 151void XCAFDoc_DimTolTool::GetDimTolLabels(TDF_LabelSequence& theLabels) const
7fd59977 152{
9ebaae37 153 theLabels.Clear();
154 TDF_ChildIterator aChildIterator( Label() );
155 for (; aChildIterator.More(); aChildIterator.Next()) {
156 TDF_Label aL = aChildIterator.Value();
157 if ( IsDimTol(aL)) theLabels.Append(aL);
7fd59977 158 }
159}
160
9ebaae37 161//=======================================================================
162//function : GetDimensionLabels
163//purpose :
164//=======================================================================
165
166void XCAFDoc_DimTolTool::GetDimensionLabels(TDF_LabelSequence& theLabels) const
167{
168 theLabels.Clear();
169 TDF_ChildIterator aChildIterator( Label() );
170 for (; aChildIterator.More(); aChildIterator.Next()) {
171 TDF_Label aL = aChildIterator.Value();
172 if ( IsDimension(aL)) theLabels.Append(aL);
173 }
174}
175
176//=======================================================================
177//function : GetGeomToleranceLabels
178//purpose :
179//=======================================================================
180
181void XCAFDoc_DimTolTool::GetGeomToleranceLabels(TDF_LabelSequence& theLabels) const
182{
183 theLabels.Clear();
184 TDF_ChildIterator aChildIterator( Label() );
185 for (; aChildIterator.More(); aChildIterator.Next()) {
186 TDF_Label aL = aChildIterator.Value();
187 if ( IsGeomTolerance(aL)) theLabels.Append(aL);
188 }
189}
7fd59977 190
191//=======================================================================
192//function : FindDimTol
193//purpose :
194//=======================================================================
195
196Standard_Boolean XCAFDoc_DimTolTool::FindDimTol(const Standard_Integer kind,
197 const Handle(TColStd_HArray1OfReal)& aVal,
198 const Handle(TCollection_HAsciiString)& aName,
199 const Handle(TCollection_HAsciiString)& aDescription,
200 TDF_Label& lab) const
201{
202 TDF_ChildIDIterator it(Label(),XCAFDoc_DimTol::GetID());
203 for(; it.More(); it.Next()) {
204 TDF_Label DimTolL = it.Value()->Label();
205 Handle(XCAFDoc_DimTol) DimTolAttr;
206 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
207 Standard_Integer kind1 = DimTolAttr->GetKind();
208 Handle(TColStd_HArray1OfReal) aVal1 = DimTolAttr->GetVal();
209 Handle(TCollection_HAsciiString) aName1 = DimTolAttr->GetName();
210 Handle(TCollection_HAsciiString) aDescription1 = DimTolAttr->GetDescription();
211 Standard_Boolean IsEqual = Standard_True;
212 if(!(kind1==kind)) continue;
213 if(!(aName==aName1)) continue;
214 if(!(aDescription==aDescription1)) continue;
215 if(kind<20) { //dimension
216 for(Standard_Integer i=1; i<=aVal->Length(); i++) {
217 if(Abs(aVal->Value(i)-aVal1->Value(i))>Precision::Confusion())
218 IsEqual = Standard_False;
219 }
220 }
221 else if(kind<50) { //tolerance
222 if(Abs(aVal->Value(1)-aVal1->Value(1))>Precision::Confusion())
223 IsEqual = Standard_False;
224 }
225 if(IsEqual) {
226 lab = DimTolL;
227 return Standard_True;
228 }
229 }
230 return Standard_False;
231}
232
233
234//=======================================================================
235//function : FindDimTol
236//purpose :
237//=======================================================================
238
239TDF_Label XCAFDoc_DimTolTool::FindDimTol(const Standard_Integer kind,
240 const Handle(TColStd_HArray1OfReal)& aVal,
241 const Handle(TCollection_HAsciiString)& aName,
242 const Handle(TCollection_HAsciiString)& aDescription) const
243{
244 TDF_Label L;
245 FindDimTol(kind,aVal,aName,aDescription,L);
246 return L;
247}
248
249
250//=======================================================================
251//function : AddDimTol
252//purpose :
253//=======================================================================
254
255TDF_Label XCAFDoc_DimTolTool::AddDimTol(const Standard_Integer kind,
256 const Handle(TColStd_HArray1OfReal)& aVal,
257 const Handle(TCollection_HAsciiString)& aName,
258 const Handle(TCollection_HAsciiString)& aDescription) const
259{
260 TDF_Label DimTolL;
261 TDF_TagSource aTag;
262 DimTolL = aTag.NewChild ( Label() );
263 XCAFDoc_DimTol::Set(DimTolL,kind,aVal,aName,aDescription);
264 TCollection_AsciiString str = "DGT:";
265 if(kind<20) str.AssignCat("Dimension");
266 else str.AssignCat("Tolerance");
267 TDataStd_Name::Set(DimTolL,str);
268 return DimTolL;
269}
270
9ebaae37 271//=======================================================================
272//function : AddDimension
273//purpose :
274//=======================================================================
275
276TDF_Label XCAFDoc_DimTolTool::AddDimension()
277{
278 TDF_Label aDimTolL;
279 TDF_TagSource aTag;
280 aDimTolL = aTag.NewChild ( Label() );
281 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aDimTolL);
282 TCollection_AsciiString aStr = "DGT:Dimension";
283 TDataStd_Name::Set(aDimTolL,aStr);
284 return aDimTolL;
285}
286
287//=======================================================================
288//function : AddGeomTolerance
289//purpose :
290//=======================================================================
291
292TDF_Label XCAFDoc_DimTolTool::AddGeomTolerance()
293{
294 TDF_Label aDimTolL;
295 TDF_TagSource aTag;
296 aDimTolL = aTag.NewChild ( Label() );
297 Handle(XCAFDoc_GeomTolerance) aTol = XCAFDoc_GeomTolerance::Set(aDimTolL);
298 TCollection_AsciiString aStr = "DGT:Tolerance";
299 TDataStd_Name::Set(aDimTolL,aStr);
300 return aDimTolL;
301}
302
303//=======================================================================
304//function : SetDimension
305//purpose :
306//=======================================================================
307
308void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theL,
309 const TDF_Label& theDimTolL) const
310{
311 TDF_Label nullLab;
312 SetDimension(theL, nullLab, theDimTolL);
313}
314
315//=======================================================================
316//function : SetDimension
317//purpose :
318//=======================================================================
319
320void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theFirstL,
321 const TDF_Label& theSecondL,
322 const TDF_Label& theDimTolL) const
323{
1c9d3225 324 TDF_LabelSequence aFirstLS, aSecondLS;
325 if(!theFirstL.IsNull())
326 aFirstLS.Append(theFirstL);
327 if(!theSecondL.IsNull())
328 aSecondLS.Append(theSecondL);
329 SetDimension(aFirstLS, aSecondLS, theDimTolL);
330}
331
332//=======================================================================
333//function : SetDimension
334//purpose :
335//=======================================================================
336
337void XCAFDoc_DimTolTool::SetDimension(const TDF_LabelSequence& theFirstL,
338 const TDF_LabelSequence& theSecondL,
339 const TDF_Label& theDimTolL) const
340{
341 if(!IsDimension(theDimTolL) || theFirstL.Length() == 0)
342 {
343 return;
344 }
345
9ebaae37 346 Handle(XCAFDoc_GraphNode) aChGNode;
347 Handle(XCAFDoc_GraphNode) aFGNode;
348 Handle(XCAFDoc_GraphNode) aSecondFGNode;
349
1c9d3225 350 if ( theDimTolL.FindAttribute (XCAFDoc::DimensionRefFirstGUID(), aChGNode) ) {
9ebaae37 351 while (aChGNode->NbFathers() > 0) {
352 aFGNode = aChGNode->GetFather(1);
353 aFGNode->UnSetChild(aChGNode);
1c9d3225 354 if(aFGNode->NbChildren() == 0)
355 aFGNode->ForgetAttribute( XCAFDoc::DimensionRefFirstGUID() );
9ebaae37 356 }
1c9d3225 357 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefFirstGUID() );
9ebaae37 358 }
1c9d3225 359 if ( theDimTolL.FindAttribute (XCAFDoc::DimensionRefSecondGUID(), aChGNode) ) {
360 while (aChGNode->NbFathers() > 0) {
361 aFGNode = aChGNode->GetFather(1);
362 aFGNode->UnSetChild(aChGNode);
363 if(aFGNode->NbChildren() == 0)
364 aFGNode->ForgetAttribute( XCAFDoc::DimensionRefSecondGUID() );
365 }
366 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefSecondGUID() );
9ebaae37 367 }
368
1c9d3225 369 if (!theDimTolL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aChGNode)) {
9ebaae37 370 aChGNode = new XCAFDoc_GraphNode;
371 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
1c9d3225 372 aChGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
9ebaae37 373 }
1c9d3225 374 for(Standard_Integer i = theFirstL.Lower(); i <= theFirstL.Upper(); i++)
375 {
376 if (!theFirstL.Value(i).FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aFGNode) ) {
377 aFGNode = new XCAFDoc_GraphNode;
378 aFGNode = XCAFDoc_GraphNode::Set(theFirstL.Value(i));
379 }
380 aFGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
381 aFGNode->SetChild(aChGNode);
382 aChGNode->SetFather(aFGNode);
9ebaae37 383 }
9ebaae37 384
1c9d3225 385 if (!theDimTolL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(), aChGNode) && theSecondL.Length() > 0) {
386 aChGNode = new XCAFDoc_GraphNode;
387 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
388 aChGNode->SetGraphID(XCAFDoc::DimensionRefSecondGUID());
389 }
390 for(Standard_Integer i = theSecondL.Lower(); i <= theSecondL.Upper(); i++)
391 {
392 if(!theSecondL.Value(i).FindAttribute(XCAFDoc::DimensionRefSecondGUID(), aSecondFGNode) ) {
9ebaae37 393 aSecondFGNode = new XCAFDoc_GraphNode;
1c9d3225 394 aSecondFGNode = XCAFDoc_GraphNode::Set(theSecondL.Value(i));
9ebaae37 395 }
1c9d3225 396 aSecondFGNode->SetGraphID(XCAFDoc::DimensionRefSecondGUID());
9ebaae37 397 aSecondFGNode->SetChild(aChGNode);
398 aChGNode->SetFather(aSecondFGNode);
399 }
400}
401
402//=======================================================================
403//function : SetGeomTolerance
404//purpose :
405//=======================================================================
406
407void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_Label& theL,
a8a3b37c 408 const TDF_Label& theGeomTolL) const
9ebaae37 409{
1c9d3225 410 TDF_LabelSequence aSeq;
411 aSeq.Append(theL);
a8a3b37c 412 SetGeomTolerance(aSeq, theGeomTolL);
1c9d3225 413}
414
415//=======================================================================
416//function : SetGeomTolerance
417//purpose :
418//=======================================================================
419
420void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_LabelSequence& theL,
a8a3b37c 421 const TDF_Label& theGeomTolL) const
1c9d3225 422{
423 // // set reference
424 // Handle(TDataStd_TreeNode) refNode, mainNode;
425 // refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::GeomToleranceRefGUID() );
426 // mainNode = TDataStd_TreeNode::Set ( theL, XCAFDoc::GeomToleranceRefGUID() );
427 // refNode->Remove(); // abv: fix against bug in TreeNode::Append()
428 // mainNode->Append(refNode);
429
a8a3b37c 430 if (!IsGeomTolerance(theGeomTolL) || theL.Length() == 0)
1c9d3225 431 {
432 return;
433 }
434
435 Handle(XCAFDoc_GraphNode) aChGNode;
436 Handle(XCAFDoc_GraphNode) aFGNode;
437
a8a3b37c 438 if (theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
1c9d3225 439 while (aChGNode->NbFathers() > 0) {
440 aFGNode = aChGNode->GetFather(1);
441 aFGNode->UnSetChild(aChGNode);
442 if(aFGNode->NbChildren() == 0)
443 aFGNode->ForgetAttribute( XCAFDoc::GeomToleranceRefGUID() );
444 }
a8a3b37c 445 theGeomTolL.ForgetAttribute(XCAFDoc::GeomToleranceRefGUID());
1c9d3225 446 }
447
a8a3b37c 448 if (!theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
1c9d3225 449 aChGNode = new XCAFDoc_GraphNode;
a8a3b37c 450 aChGNode = XCAFDoc_GraphNode::Set(theGeomTolL);
1c9d3225 451 aChGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
452 }
453 for(Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
454 {
455 if (!theL.Value(i).FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aFGNode) ) {
456 aFGNode = new XCAFDoc_GraphNode;
457 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
458 }
459 aFGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
460 aFGNode->SetChild(aChGNode);
461 aChGNode->SetFather(aFGNode);
462 }
9ebaae37 463}
7fd59977 464
465//=======================================================================
466//function : SetDimTol
467//purpose :
468//=======================================================================
469
9ebaae37 470void XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& theL,
471 const TDF_Label& theDimTolL) const
7fd59977 472{
473 // set reference
474 Handle(TDataStd_TreeNode) refNode, mainNode;
9ebaae37 475 refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::DimTolRefGUID() );
476 mainNode = TDataStd_TreeNode::Set (theL, XCAFDoc::DimTolRefGUID() );
7fd59977 477 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
478 mainNode->Append(refNode);
479}
480
481
482//=======================================================================
483//function : SetDimTol
484//purpose :
485//=======================================================================
486
487TDF_Label XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& L,
488 const Standard_Integer kind,
489 const Handle(TColStd_HArray1OfReal)& aVal,
490 const Handle(TCollection_HAsciiString)& aName,
491 const Handle(TCollection_HAsciiString)& aDescription) const
492{
493 TDF_Label DimTolL = AddDimTol(kind,aVal,aName,aDescription);
494 SetDimTol(L,DimTolL);
495 return DimTolL;
496}
497
498
499//=======================================================================
500//function : GetRefShapeLabel
501//purpose :
502//=======================================================================
503
9ebaae37 504Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL,
1c9d3225 505 TDF_LabelSequence& theShapeLFirst,
47263fa6 506 TDF_LabelSequence& theShapeLSecond)
7fd59977 507{
1c9d3225 508 theShapeLFirst.Clear();
509 theShapeLSecond.Clear();
9ebaae37 510 Handle(TDataStd_TreeNode) aNode;
511 if( !theL.FindAttribute(XCAFDoc::DimTolRefGUID(),aNode) || !aNode->HasFather() ) {
512 if( !theL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) || !aNode->HasFather() ) {
1c9d3225 513 Handle(XCAFDoc_GraphNode) aGNode;
514 if( theL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
515 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
516 {
517 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
518 }
519 return Standard_True;
520 }
400af1bc 521 else if (theL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode) && aGNode->NbFathers() > 0) {
522 for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
523 {
524 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
525 }
526 return Standard_True;
527 }
1c9d3225 528 else if( theL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
529 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
530 {
531 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
532 }
533 if( theL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
9ebaae37 534 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
535 {
1c9d3225 536 theShapeLSecond.Append(aGNode->GetFather(i)->Label());
9ebaae37 537 }
9ebaae37 538 }
1c9d3225 539 return Standard_True;
540 }
541 else
542 {
9ebaae37 543 return Standard_False;
544 }
7fd59977 545 }
546 }
1c9d3225 547
548 theShapeLFirst.Append(aNode->Father()->Label());
7fd59977 549 return Standard_True;
550}
551
9ebaae37 552//=======================================================================
553//function : GetRefDimensionLabels
554//purpose :
555//=======================================================================
556
557Standard_Boolean XCAFDoc_DimTolTool::GetRefDimensionLabels(const TDF_Label& theShapeL,
558 TDF_LabelSequence& theDimTols) const
559{
560 Handle(XCAFDoc_GraphNode) aGNode;
1c9d3225 561 Standard_Boolean aResult = Standard_False;
562 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
9ebaae37 563 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
564 {
565 theDimTols.Append(aGNode->GetChild(i)->Label());
566 }
1c9d3225 567 aResult = Standard_True;
9ebaae37 568 }
1c9d3225 569 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
570 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
571 {
572 theDimTols.Append(aGNode->GetChild(i)->Label());
573 }
574 aResult = Standard_True;
575 }
576 return aResult;
9ebaae37 577}
7fd59977 578
579//=======================================================================
9ebaae37 580//function : GetRefGeomToleranceLabels
7fd59977 581//purpose :
582//=======================================================================
583
9ebaae37 584Standard_Boolean XCAFDoc_DimTolTool::GetRefGeomToleranceLabels(const TDF_Label& theShapeL,
585 TDF_LabelSequence& theDimTols) const
7fd59977 586{
1c9d3225 587 Handle(XCAFDoc_GraphNode) aGNode;
588 if( !theShapeL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) ||
589 aGNode->NbChildren() == 0 ) {
7fd59977 590 return Standard_False;
591 }
1c9d3225 592 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
593 {
594 theDimTols.Append(aGNode->GetChild(i)->Label());
7fd59977 595 }
596 return Standard_True;
597}
598
9ebaae37 599//=======================================================================
600//function : GetRefDatumLabel
601//purpose :
602//=======================================================================
603
604Standard_Boolean XCAFDoc_DimTolTool::GetRefDatumLabel(const TDF_Label& theShapeL,
1c9d3225 605 TDF_LabelSequence& theDatum) const
9ebaae37 606{
400af1bc 607 Handle(XCAFDoc_GraphNode) aGNode;
608 if (!theShapeL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode)) {
9ebaae37 609 return Standard_False;
610 }
400af1bc 611 for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) {
612 theDatum.Append(aGNode->GetChild(i)->Label());
1c9d3225 613 }
9ebaae37 614 return Standard_True;
615}
7fd59977 616
617//=======================================================================
618//function : GetDimTol
619//purpose :
620//=======================================================================
621
622Standard_Boolean XCAFDoc_DimTolTool::GetDimTol(const TDF_Label& DimTolL,
623 Standard_Integer& kind,
624 Handle(TColStd_HArray1OfReal)& aVal,
625 Handle(TCollection_HAsciiString)& aName,
626 Handle(TCollection_HAsciiString)& aDescription) const
627{
628 Handle(XCAFDoc_DimTol) DimTolAttr;
629 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) {
630 return Standard_False;
631 }
632 kind = DimTolAttr->GetKind();
633 aVal = DimTolAttr->GetVal();
634 aName = DimTolAttr->GetName();
635 aDescription = DimTolAttr->GetDescription();
636
637 return Standard_True;
638}
639
640
641//=======================================================================
642//function : IsDatum
643//purpose :
644//=======================================================================
645
9ebaae37 646Standard_Boolean XCAFDoc_DimTolTool::IsDatum(const TDF_Label& theDimTolL) const
7fd59977 647{
9ebaae37 648 Handle(XCAFDoc_Datum) aDatumAttr;
649 if(theDimTolL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr)) {
7fd59977 650 return Standard_True;
651 }
652 return Standard_False;
653}
654
655
656//=======================================================================
657//function : GetDatumLabels
658//purpose :
659//=======================================================================
660
9ebaae37 661void XCAFDoc_DimTolTool::GetDatumLabels(TDF_LabelSequence& theLabels) const
7fd59977 662{
9ebaae37 663 theLabels.Clear();
664 TDF_ChildIterator aChildIterator( Label() );
665 for (; aChildIterator.More(); aChildIterator.Next()) {
666 TDF_Label L = aChildIterator.Value();
667 if ( IsDatum(L)) theLabels.Append(L);
7fd59977 668 }
669}
670
7fd59977 671//=======================================================================
672//function : FindDatum
673//purpose :
674//=======================================================================
675
676Standard_Boolean XCAFDoc_DimTolTool::FindDatum(const Handle(TCollection_HAsciiString)& aName,
677 const Handle(TCollection_HAsciiString)& aDescription,
678 const Handle(TCollection_HAsciiString)& anIdentification,
679 TDF_Label& lab) const
680{
681 TDF_ChildIDIterator it(Label(),XCAFDoc_Datum::GetID());
682 for(; it.More(); it.Next()) {
683 Handle(TCollection_HAsciiString) aName1, aDescription1, anIdentification1;
684 TDF_Label aLabel = it.Value()->Label();
685 if ( !GetDatum( aLabel, aName1, aDescription1, anIdentification1 ) )
686 continue;
687 if(!(aName==aName1)) continue;
688 if(!(aDescription==aDescription1)) continue;
689 if(!(anIdentification==anIdentification1)) continue;
690 lab = aLabel;
691 return Standard_True;
692 }
693 return Standard_False;
694}
695
696
697//=======================================================================
698//function : AddDatum
699//purpose :
700//=======================================================================
701
702TDF_Label XCAFDoc_DimTolTool::AddDatum(const Handle(TCollection_HAsciiString)& aName,
703 const Handle(TCollection_HAsciiString)& aDescription,
704 const Handle(TCollection_HAsciiString)& anIdentification) const
705{
706 TDF_Label DatumL;
707 TDF_TagSource aTag;
708 DatumL = aTag.NewChild ( Label() );
709 XCAFDoc_Datum::Set(DatumL,aName,aDescription,anIdentification);
710 TDataStd_Name::Set(DatumL,"DGT:Datum");
711 return DatumL;
712}
713
9ebaae37 714//=======================================================================
715//function : AddDatum
716//purpose :
717//=======================================================================
718
719TDF_Label XCAFDoc_DimTolTool::AddDatum()
720{
721 TDF_Label aDatumL;
722 TDF_TagSource aTag;
723 aDatumL = aTag.NewChild ( Label() );
724 Handle(XCAFDoc_Datum) aDat = XCAFDoc_Datum::Set(aDatumL);
725 TDataStd_Name::Set(aDatumL,"DGT:Datum");
726 return aDatumL;
727}
7fd59977 728
729//=======================================================================
730//function : SetDatum
731//purpose :
732//=======================================================================
733
400af1bc 734void XCAFDoc_DimTolTool::SetDatum(const TDF_LabelSequence& theL,
9ebaae37 735 const TDF_Label& theDatumL) const
7fd59977 736{
400af1bc 737 if (!IsDatum(theDatumL))
738 {
739 return;
740 }
741
742 Handle(XCAFDoc_GraphNode) aChGNode;
743 Handle(XCAFDoc_GraphNode) aFGNode;
744
745 if (theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
746 while (aChGNode->NbFathers() > 0) {
747 aFGNode = aChGNode->GetFather(1);
748 aFGNode->UnSetChild(aChGNode);
749 if (aFGNode->NbChildren() == 0)
750 aFGNode->ForgetAttribute(XCAFDoc::DatumRefGUID());
751 }
752 theDatumL.ForgetAttribute(XCAFDoc::DatumRefGUID());
753 }
754
755 if (!theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
756 aChGNode = new XCAFDoc_GraphNode;
757 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
758 aChGNode->SetGraphID(XCAFDoc::DatumRefGUID());
759 }
760 for (Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
761 {
762 if (!theL.Value(i).FindAttribute(XCAFDoc::DatumRefGUID(), aFGNode)) {
763 aFGNode = new XCAFDoc_GraphNode;
764 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
765 }
766 aFGNode->SetGraphID(XCAFDoc::DatumRefGUID());
767 aFGNode->SetChild(aChGNode);
768 aChGNode->SetFather(aFGNode);
769 }
7fd59977 770}
771
7fd59977 772//=======================================================================
773//function : SetDatum
774//purpose :
775//=======================================================================
776
777void XCAFDoc_DimTolTool::SetDatum(const TDF_Label& L,
778 const TDF_Label& TolerL,
779 const Handle(TCollection_HAsciiString)& aName,
780 const Handle(TCollection_HAsciiString)& aDescription,
781 const Handle(TCollection_HAsciiString)& anIdentification) const
782{
783 TDF_Label DatumL;
784 if(!FindDatum(aName,aDescription,anIdentification,DatumL))
785 DatumL = AddDatum(aName,aDescription,anIdentification);
400af1bc 786 TDF_LabelSequence aLabels;
787 aLabels.Append(L);
788 SetDatum(aLabels,DatumL);
7fd59977 789 // set reference
790 Handle(XCAFDoc_GraphNode) FGNode;
791 Handle(XCAFDoc_GraphNode) ChGNode;
792 if (! TolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), FGNode) ) {
793 FGNode = new XCAFDoc_GraphNode;
794 FGNode = XCAFDoc_GraphNode::Set(TolerL);
795 }
796 if (! DatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), ChGNode) ) {
797 ChGNode = new XCAFDoc_GraphNode;
798 ChGNode = XCAFDoc_GraphNode::Set(DatumL);
799 }
800 FGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
801 ChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
802 FGNode->SetChild(ChGNode);
803 ChGNode->SetFather(FGNode);
804}
805
9ebaae37 806//=======================================================================
807//function : SetDatumToGeomTol
808//purpose :
809//=======================================================================
810
811void XCAFDoc_DimTolTool::SetDatumToGeomTol(const TDF_Label& theDatumL,
812 const TDF_Label& theTolerL) const
813{
814 // set reference
815 Handle(XCAFDoc_GraphNode) aFGNode;
816 Handle(XCAFDoc_GraphNode) aChGNode;
817 if (! theTolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aFGNode) ) {
818 aFGNode = new XCAFDoc_GraphNode;
819 aFGNode = XCAFDoc_GraphNode::Set(theTolerL);
820 }
821 if (! theDatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aChGNode) ) {
822 aChGNode = new XCAFDoc_GraphNode;
823 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
824 }
825 aFGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
826 aChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
827 aFGNode->SetChild(aChGNode);
828 aChGNode->SetFather(aFGNode);
829}
830
7fd59977 831//=======================================================================
832//function : GetDatum
833//purpose :
834//=======================================================================
835
836Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL,
837 Handle(TCollection_HAsciiString)& theName,
838 Handle(TCollection_HAsciiString)& theDescription,
839 Handle(TCollection_HAsciiString)& theIdentification) const
840{
841 Handle(XCAFDoc_Datum) aDatumAttr;
842 if( theDatumL.IsNull() ||
843 !theDatumL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr) )
844 return Standard_False;
845
846 theName = aDatumAttr->GetName();
847 theDescription = aDatumAttr->GetDescription();
848 theIdentification = aDatumAttr->GetIdentification();
849 return Standard_True;
850}
851
852//=======================================================================
853//function : GetDatumTolerLabels
854//purpose :
855//=======================================================================
856
9ebaae37 857Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL,
47263fa6 858 TDF_LabelSequence& theDatums)
9ebaae37 859{
860 Handle(XCAFDoc_GraphNode) aNode;
861 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
862 return Standard_False;
6595eee7 863
9ebaae37 864 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
865 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
866 theDatums.Append(aDatumNode->Label());
867 }
868 return Standard_True;
869}
870
6595eee7 871//=======================================================================
872//function : GetDatumWthObjectsTolerLabels
873//purpose :
874//=======================================================================
875
876Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL,
47263fa6 877 TDF_LabelSequence& theDatums)
6595eee7 878{
879 Handle(XCAFDoc_GraphNode) aNode;
880 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
881 return Standard_False;
882
883 TColStd_MapOfAsciiString aDatumNameMap;
884 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
885 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
886 TDF_Label aDatumL = aDatumNode->Label();
887 Handle(XCAFDoc_Datum) aDatumAttr;
888 if (!aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
889 continue;
890 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
891 if (aDatumObj.IsNull())
892 continue;
893 Handle(TCollection_HAsciiString) aName = aDatumObj->GetName();
894 if (!aDatumNameMap.Add(aName->String())) {
895 // the datum has already been appended to sequence, due to one of its datum targets
896 continue;
897 }
898 theDatums.Append(aDatumNode->Label());
899 }
900 return Standard_True;
901}
902
9ebaae37 903//=======================================================================
904//function : GetTolerDatumLabels
905//purpose :
906//=======================================================================
907
908Standard_Boolean XCAFDoc_DimTolTool::GetTolerOfDatumLabels(const TDF_Label& theDatumL,
909 TDF_LabelSequence& theTols) const
7fd59977 910{
9ebaae37 911 Handle(XCAFDoc_GraphNode) aNode;
912 if( !theDatumL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
7fd59977 913 return Standard_False;
9ebaae37 914 for(Standard_Integer i=1; i<=aNode->NbFathers(); i++) {
915 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetFather(i);
916 theTols.Append(aDatumNode->Label());
7fd59977 917 }
918 return Standard_True;
919}
920
0c63f2f8 921//=======================================================================
922//function : IsLocked
923//purpose :
924//=======================================================================
925
926Standard_Boolean XCAFDoc_DimTolTool::IsLocked(const TDF_Label& theViewL) const
927{
928 Handle(TDataStd_UAttribute) anAttr;
929 return theViewL.FindAttribute(XCAFDoc::LockGUID(), anAttr);
930}
931
932//=======================================================================
933//function : Lock
934//purpose :
935//=======================================================================
7fd59977 936
0c63f2f8 937void XCAFDoc_DimTolTool::Lock(const TDF_Label& theViewL) const
938{
939 TDataStd_UAttribute::Set(theViewL, XCAFDoc::LockGUID());
940}
941
942//=======================================================================
943//function : Unlock
944//purpose :
945//=======================================================================
946
947void XCAFDoc_DimTolTool::Unlock(const TDF_Label& theViewL) const
948{
949 theViewL.ForgetAttribute(XCAFDoc::LockGUID());
950}
5df609e7 951
7fd59977 952//=======================================================================
953//function : ID
954//purpose :
955//=======================================================================
956
957const Standard_GUID& XCAFDoc_DimTolTool::ID() const
958{
959 return GetID();
960}
961
962
61ace3dc 963//=======================================================================
964//function : GetGDTPresentations
965//purpose :
966//=======================================================================
967void XCAFDoc_DimTolTool::GetGDTPresentations(NCollection_IndexedDataMap<TDF_Label,
1103eb60 968 TopoDS_Shape>& theGDTLabelToShape) const
61ace3dc 969{
970 TDF_LabelSequence aGDTs;
971 GetDimensionLabels(aGDTs);
972 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
973 Handle(XCAFDoc_Dimension) aDimAttr;
974 const TDF_Label& aCL = aGDTs.Value(i);
975 if (!aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
976 continue;
977 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
978 if (anObject.IsNull())
979 continue;
980 TopoDS_Shape aShape = anObject->GetPresentation();
981 if (!aShape.IsNull())
982 theGDTLabelToShape.Add(aCL, aShape);
983 }
984
985 aGDTs.Clear();
986 GetGeomToleranceLabels(aGDTs);
987 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
988 Handle(XCAFDoc_GeomTolerance) aGTAttr;
989 const TDF_Label& aCL = aGDTs.Value(i);
990 if (!aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aGTAttr))
991 continue;
992 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
993 if (anObject.IsNull())
994 continue;
995 TopoDS_Shape aShape = anObject->GetPresentation();
996 if (!aShape.IsNull())
997 theGDTLabelToShape.Add(aCL, aShape);
998 }
999
1000 aGDTs.Clear();
1001 GetDatumLabels(aGDTs);
1002 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
1003 Handle(XCAFDoc_Datum) aGTAttr;
1004 const TDF_Label& aCL = aGDTs.Value(i);
1005 if (!aCL.FindAttribute(XCAFDoc_Datum::GetID(),aGTAttr))
1006 continue;
1007 Handle(XCAFDimTolObjects_DatumObject) anObject = aGTAttr->GetObject();
1008 if (anObject.IsNull())
1009 continue;
1010 TopoDS_Shape aShape = anObject->GetPresentation();
1011 if (!aShape.IsNull())
1012 theGDTLabelToShape.Add(aCL, aShape);
1013 }
1014}
1015
1016//=======================================================================
1017//function : SetGDTPresentations
1018//purpose :
1019//=======================================================================
1103eb60 1020void XCAFDoc_DimTolTool::SetGDTPresentations(NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape>& theGDTLabelToPrs)
61ace3dc 1021{
1022 for (Standard_Integer i = 1; i <= theGDTLabelToPrs.Extent(); i++)
1023 {
1024 const TDF_Label& aCL = theGDTLabelToPrs.FindKey(i);
1025 Handle(XCAFDoc_Dimension) aDimAttrDim;
1026 if (aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttrDim))
1027 {
1028 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttrDim->GetObject();
1029 if (anObject.IsNull())
1030 continue;
1031 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1032 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1033 aDimAttrDim->SetObject(anObject);
1034 continue;
1035 }
1036 Handle(XCAFDoc_GeomTolerance) aDimAttrG;
1037 if (aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimAttrG))
1038 {
1039 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aDimAttrG->GetObject();
1040 if (anObject.IsNull())
1041 continue;
1042 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1043 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1044 aDimAttrG->SetObject(anObject);
1045 continue;
1046 }
1047 Handle(XCAFDoc_Datum) aDimAttrD;
1048 if (aCL.FindAttribute(XCAFDoc_Datum::GetID(),aDimAttrD))
1049 {
1050 Handle(XCAFDimTolObjects_DatumObject) anObject = aDimAttrD->GetObject();
1051 if (anObject.IsNull())
1052 continue;
1053 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1054 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1055 aDimAttrD->SetObject(anObject);
1056 continue;
1057 }
1058 }
bc73b006 1059}
1060
1061//=======================================================================
1062//function : DumpJson
1063//purpose :
1064//=======================================================================
1065void XCAFDoc_DimTolTool::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
1066{
1067 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
1068
1069 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
1070
39b707a6 1071 TDF_LabelSequence aLabels;
1072 GetDimensionLabels (aLabels);
1073 for (TDF_LabelSequence::Iterator aDimLabelIt (aLabels); aDimLabelIt.More(); aDimLabelIt.Next())
1074 {
1075 TCollection_AsciiString aDimensionLabel;
1076 TDF_Tool::Entry (aDimLabelIt.Value(), aDimensionLabel);
1077 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDimensionLabel)
1078 }
1079
1080 aLabels.Clear();
1081 GetGeomToleranceLabels (aLabels);
1082 for (TDF_LabelSequence::Iterator aGeomToleranceLabelIt (aLabels); aGeomToleranceLabelIt.More(); aGeomToleranceLabelIt.Next())
1083 {
1084 TCollection_AsciiString aGeomToleranceLabel;
1085 TDF_Tool::Entry (aGeomToleranceLabelIt.Value(), aGeomToleranceLabel);
1086 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aGeomToleranceLabel)
1087 }
1088
1089 aLabels.Clear();
1090 GetDimTolLabels (aLabels);
1091 for (TDF_LabelSequence::Iterator aDimTolLabelIt (aLabels); aDimTolLabelIt.More(); aDimTolLabelIt.Next())
1092 {
1093 TCollection_AsciiString aDimTolLabelLabel;
1094 TDF_Tool::Entry (aDimTolLabelIt.Value(), aDimTolLabelLabel);
1095 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDimTolLabelLabel)
1096 }
1097
1098 aLabels.Clear();
1099 GetDatumLabels (aLabels);
1100 for (TDF_LabelSequence::Iterator aDatumLabelIt (aLabels); aDatumLabelIt.More(); aDatumLabelIt.Next())
1101 {
1102 TCollection_AsciiString aDatumLabel;
1103 TDF_Tool::Entry (aDatumLabelIt.Value(), aDatumLabel);
1104 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDatumLabel)
1105 }
bc73b006 1106}