1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <XCAFDoc_DimTolTool.hxx>
15 #include <Precision.hxx>
16 #include <Standard_GUID.hxx>
17 #include <Standard_Type.hxx>
18 #include <TCollection_HAsciiString.hxx>
19 #include <TColStd_MapOfAsciiString.hxx>
20 #include <TDataStd_Name.hxx>
21 #include <TDataStd_TreeNode.hxx>
22 #include <TDataStd_UAttribute.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_AttributeIterator.hxx>
25 #include <TDF_ChildIDIterator.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_RelocationTable.hxx>
28 #include <XCAFDimTolObjects_DatumObject.hxx>
29 #include <XCAFDoc.hxx>
30 #include <XCAFDoc_Dimension.hxx>
31 #include <XCAFDoc_GeomTolerance.hxx>
32 #include <XCAFDoc_Datum.hxx>
33 #include <XCAFDoc_DimTol.hxx>
34 #include <XCAFDoc_DimTolTool.hxx>
35 #include <XCAFDoc_DocumentTool.hxx>
36 #include <XCAFDoc_GraphNode.hxx>
37 #include <XCAFDoc_ShapeTool.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DimTolTool,TDF_Attribute)
42 //=======================================================================
43 //function : XCAFDoc_DimTolTool
45 //=======================================================================
46 XCAFDoc_DimTolTool::XCAFDoc_DimTolTool()
51 //=======================================================================
54 //=======================================================================
56 Handle(XCAFDoc_DimTolTool) XCAFDoc_DimTolTool::Set(const TDF_Label& L)
58 Handle(XCAFDoc_DimTolTool) A;
59 if (!L.FindAttribute (XCAFDoc_DimTolTool::GetID(), A)) {
60 A = new XCAFDoc_DimTolTool ();
62 A->myShapeTool = XCAFDoc_DocumentTool::ShapeTool(L);
68 //=======================================================================
71 //=======================================================================
73 const Standard_GUID& XCAFDoc_DimTolTool::GetID()
75 static Standard_GUID DGTTblID ("72afb19b-44de-11d8-8776-001083004c77");
80 //=======================================================================
81 //function : BaseLabel
83 //=======================================================================
85 TDF_Label XCAFDoc_DimTolTool::BaseLabel() const
91 //=======================================================================
92 //function : ShapeTool
94 //=======================================================================
96 const Handle(XCAFDoc_ShapeTool)& XCAFDoc_DimTolTool::ShapeTool()
98 if(myShapeTool.IsNull())
99 myShapeTool = XCAFDoc_DocumentTool::ShapeTool(Label());
104 //=======================================================================
105 //function : IsDimTol
107 //=======================================================================
109 Standard_Boolean XCAFDoc_DimTolTool::IsDimTol(const TDF_Label& theDimTolL) const
111 Handle(XCAFDoc_DimTol) aDimTolAttr;
112 if(theDimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),aDimTolAttr)) {
113 return Standard_True;
115 return Standard_False;
118 //=======================================================================
119 //function : IsDimension
121 //=======================================================================
123 Standard_Boolean XCAFDoc_DimTolTool::IsDimension(const TDF_Label& theDimTolL) const
125 Handle(XCAFDoc_Dimension) aDimTolAttr;
126 if(theDimTolL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimTolAttr)) {
127 return Standard_True;
129 return Standard_False;
132 //=======================================================================
133 //function : IsGeomTolerance
135 //=======================================================================
137 Standard_Boolean XCAFDoc_DimTolTool::IsGeomTolerance(const TDF_Label& theDimTolL) const
139 Handle(XCAFDoc_GeomTolerance) aDimTolAttr;
140 if(theDimTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimTolAttr)) {
141 return Standard_True;
143 return Standard_False;
146 //=======================================================================
147 //function : GetDimTolLabels
149 //=======================================================================
151 void XCAFDoc_DimTolTool::GetDimTolLabels(TDF_LabelSequence& theLabels) const
154 TDF_ChildIterator aChildIterator( Label() );
155 for (; aChildIterator.More(); aChildIterator.Next()) {
156 TDF_Label aL = aChildIterator.Value();
157 if ( IsDimTol(aL)) theLabels.Append(aL);
161 //=======================================================================
162 //function : GetDimensionLabels
164 //=======================================================================
166 void XCAFDoc_DimTolTool::GetDimensionLabels(TDF_LabelSequence& theLabels) const
169 TDF_ChildIterator aChildIterator( Label() );
170 for (; aChildIterator.More(); aChildIterator.Next()) {
171 TDF_Label aL = aChildIterator.Value();
172 if ( IsDimension(aL)) theLabels.Append(aL);
176 //=======================================================================
177 //function : GetGeomToleranceLabels
179 //=======================================================================
181 void XCAFDoc_DimTolTool::GetGeomToleranceLabels(TDF_LabelSequence& theLabels) const
184 TDF_ChildIterator aChildIterator( Label() );
185 for (; aChildIterator.More(); aChildIterator.Next()) {
186 TDF_Label aL = aChildIterator.Value();
187 if ( IsGeomTolerance(aL)) theLabels.Append(aL);
191 //=======================================================================
192 //function : FindDimTol
194 //=======================================================================
196 Standard_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
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;
221 else if(kind<50) { //tolerance
222 if(Abs(aVal->Value(1)-aVal1->Value(1))>Precision::Confusion())
223 IsEqual = Standard_False;
227 return Standard_True;
230 return Standard_False;
234 //=======================================================================
235 //function : FindDimTol
237 //=======================================================================
239 TDF_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
245 FindDimTol(kind,aVal,aName,aDescription,L);
250 //=======================================================================
251 //function : AddDimTol
253 //=======================================================================
255 TDF_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
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);
271 //=======================================================================
272 //function : AddDimension
274 //=======================================================================
276 TDF_Label XCAFDoc_DimTolTool::AddDimension()
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);
287 //=======================================================================
288 //function : AddGeomTolerance
290 //=======================================================================
292 TDF_Label XCAFDoc_DimTolTool::AddGeomTolerance()
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);
303 //=======================================================================
304 //function : SetDimension
306 //=======================================================================
308 void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theL,
309 const TDF_Label& theDimTolL) const
312 SetDimension(theL, nullLab, theDimTolL);
315 //=======================================================================
316 //function : SetDimension
318 //=======================================================================
320 void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theFirstL,
321 const TDF_Label& theSecondL,
322 const TDF_Label& theDimTolL) const
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);
332 //=======================================================================
333 //function : SetDimension
335 //=======================================================================
337 void XCAFDoc_DimTolTool::SetDimension(const TDF_LabelSequence& theFirstL,
338 const TDF_LabelSequence& theSecondL,
339 const TDF_Label& theDimTolL) const
341 if(!IsDimension(theDimTolL) || theFirstL.Length() == 0)
346 Handle(XCAFDoc_GraphNode) aChGNode;
347 Handle(XCAFDoc_GraphNode) aFGNode;
348 Handle(XCAFDoc_GraphNode) aSecondFGNode;
350 if ( theDimTolL.FindAttribute (XCAFDoc::DimensionRefFirstGUID(), aChGNode) ) {
351 while (aChGNode->NbFathers() > 0) {
352 aFGNode = aChGNode->GetFather(1);
353 aFGNode->UnSetChild(aChGNode);
354 if(aFGNode->NbChildren() == 0)
355 aFGNode->ForgetAttribute( XCAFDoc::DimensionRefFirstGUID() );
357 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefFirstGUID() );
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() );
366 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefSecondGUID() );
369 if (!theDimTolL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aChGNode)) {
370 aChGNode = new XCAFDoc_GraphNode;
371 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
372 aChGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
374 for(Standard_Integer i = theFirstL.Lower(); i <= theFirstL.Upper(); i++)
376 if (!theFirstL.Value(i).FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aFGNode) ) {
377 aFGNode = new XCAFDoc_GraphNode;
378 aFGNode = XCAFDoc_GraphNode::Set(theFirstL.Value(i));
380 aFGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
381 aFGNode->SetChild(aChGNode);
382 aChGNode->SetFather(aFGNode);
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());
390 for(Standard_Integer i = theSecondL.Lower(); i <= theSecondL.Upper(); i++)
392 if(!theSecondL.Value(i).FindAttribute(XCAFDoc::DimensionRefSecondGUID(), aSecondFGNode) ) {
393 aSecondFGNode = new XCAFDoc_GraphNode;
394 aSecondFGNode = XCAFDoc_GraphNode::Set(theSecondL.Value(i));
396 aSecondFGNode->SetGraphID(XCAFDoc::DimensionRefSecondGUID());
397 aSecondFGNode->SetChild(aChGNode);
398 aChGNode->SetFather(aSecondFGNode);
402 //=======================================================================
403 //function : SetGeomTolerance
405 //=======================================================================
407 void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_Label& theL,
408 const TDF_Label& theDimTolL) const
410 TDF_LabelSequence aSeq;
412 SetGeomTolerance(aSeq, theDimTolL);
415 //=======================================================================
416 //function : SetGeomTolerance
418 //=======================================================================
420 void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_LabelSequence& theL,
421 const TDF_Label& theDimTolL) const
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);
430 if(!IsGeomTolerance(theDimTolL) || theL.Length() == 0)
435 Handle(XCAFDoc_GraphNode) aChGNode;
436 Handle(XCAFDoc_GraphNode) aFGNode;
438 //Handle(XCAFDoc_GraphNode) ChGNode, FGNode;
439 if ( theDimTolL.FindAttribute (XCAFDoc::GeomToleranceRefGUID(), aChGNode) ) {
440 while (aChGNode->NbFathers() > 0) {
441 aFGNode = aChGNode->GetFather(1);
442 aFGNode->UnSetChild(aChGNode);
443 if(aFGNode->NbChildren() == 0)
444 aFGNode->ForgetAttribute( XCAFDoc::GeomToleranceRefGUID() );
446 theDimTolL.ForgetAttribute ( XCAFDoc::GeomToleranceRefGUID() );
449 if (!theDimTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
450 aChGNode = new XCAFDoc_GraphNode;
451 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
452 aChGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
454 for(Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
456 if (!theL.Value(i).FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aFGNode) ) {
457 aFGNode = new XCAFDoc_GraphNode;
458 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
460 aFGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
461 aFGNode->SetChild(aChGNode);
462 aChGNode->SetFather(aFGNode);
466 //=======================================================================
467 //function : SetDimTol
469 //=======================================================================
471 void XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& theL,
472 const TDF_Label& theDimTolL) const
475 Handle(TDataStd_TreeNode) refNode, mainNode;
476 refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::DimTolRefGUID() );
477 mainNode = TDataStd_TreeNode::Set (theL, XCAFDoc::DimTolRefGUID() );
478 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
479 mainNode->Append(refNode);
483 //=======================================================================
484 //function : SetDimTol
486 //=======================================================================
488 TDF_Label XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& L,
489 const Standard_Integer kind,
490 const Handle(TColStd_HArray1OfReal)& aVal,
491 const Handle(TCollection_HAsciiString)& aName,
492 const Handle(TCollection_HAsciiString)& aDescription) const
494 TDF_Label DimTolL = AddDimTol(kind,aVal,aName,aDescription);
495 SetDimTol(L,DimTolL);
500 //=======================================================================
501 //function : GetRefShapeLabel
503 //=======================================================================
505 Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL,
506 TDF_LabelSequence& theShapeLFirst,
507 TDF_LabelSequence& theShapeLSecond) const
509 theShapeLFirst.Clear();
510 theShapeLSecond.Clear();
511 Handle(TDataStd_TreeNode) aNode;
512 if( !theL.FindAttribute(XCAFDoc::DimTolRefGUID(),aNode) || !aNode->HasFather() ) {
513 if( !theL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) || !aNode->HasFather() ) {
514 Handle(XCAFDoc_GraphNode) aGNode;
515 if( theL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
516 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
518 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
520 return Standard_True;
522 else if (theL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode) && aGNode->NbFathers() > 0) {
523 for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
525 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
527 return Standard_True;
529 else if( theL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
530 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
532 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
534 if( theL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
535 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
537 theShapeLSecond.Append(aGNode->GetFather(i)->Label());
540 return Standard_True;
544 return Standard_False;
549 theShapeLFirst.Append(aNode->Father()->Label());
550 return Standard_True;
553 //=======================================================================
554 //function : GetRefDimensionLabels
556 //=======================================================================
558 Standard_Boolean XCAFDoc_DimTolTool::GetRefDimensionLabels(const TDF_Label& theShapeL,
559 TDF_LabelSequence& theDimTols) const
561 Handle(XCAFDoc_GraphNode) aGNode;
562 Standard_Boolean aResult = Standard_False;
563 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
564 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
566 theDimTols.Append(aGNode->GetChild(i)->Label());
568 aResult = Standard_True;
570 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
571 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
573 theDimTols.Append(aGNode->GetChild(i)->Label());
575 aResult = Standard_True;
580 //=======================================================================
581 //function : GetRefGeomToleranceLabels
583 //=======================================================================
585 Standard_Boolean XCAFDoc_DimTolTool::GetRefGeomToleranceLabels(const TDF_Label& theShapeL,
586 TDF_LabelSequence& theDimTols) const
588 Handle(XCAFDoc_GraphNode) aGNode;
589 if( !theShapeL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) ||
590 aGNode->NbChildren() == 0 ) {
591 return Standard_False;
593 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
595 theDimTols.Append(aGNode->GetChild(i)->Label());
597 return Standard_True;
600 //=======================================================================
601 //function : GetRefDatumLabel
603 //=======================================================================
605 Standard_Boolean XCAFDoc_DimTolTool::GetRefDatumLabel(const TDF_Label& theShapeL,
606 TDF_LabelSequence& theDatum) const
608 Handle(XCAFDoc_GraphNode) aGNode;
609 if (!theShapeL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode)) {
610 return Standard_False;
612 for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) {
613 theDatum.Append(aGNode->GetChild(i)->Label());
615 return Standard_True;
618 //=======================================================================
619 //function : GetDimTol
621 //=======================================================================
623 Standard_Boolean XCAFDoc_DimTolTool::GetDimTol(const TDF_Label& DimTolL,
624 Standard_Integer& kind,
625 Handle(TColStd_HArray1OfReal)& aVal,
626 Handle(TCollection_HAsciiString)& aName,
627 Handle(TCollection_HAsciiString)& aDescription) const
629 Handle(XCAFDoc_DimTol) DimTolAttr;
630 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) {
631 return Standard_False;
633 kind = DimTolAttr->GetKind();
634 aVal = DimTolAttr->GetVal();
635 aName = DimTolAttr->GetName();
636 aDescription = DimTolAttr->GetDescription();
638 return Standard_True;
642 //=======================================================================
645 //=======================================================================
647 Standard_Boolean XCAFDoc_DimTolTool::IsDatum(const TDF_Label& theDimTolL) const
649 Handle(XCAFDoc_Datum) aDatumAttr;
650 if(theDimTolL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr)) {
651 return Standard_True;
653 return Standard_False;
657 //=======================================================================
658 //function : GetDatumLabels
660 //=======================================================================
662 void XCAFDoc_DimTolTool::GetDatumLabels(TDF_LabelSequence& theLabels) const
665 TDF_ChildIterator aChildIterator( Label() );
666 for (; aChildIterator.More(); aChildIterator.Next()) {
667 TDF_Label L = aChildIterator.Value();
668 if ( IsDatum(L)) theLabels.Append(L);
672 //=======================================================================
673 //function : FindDatum
675 //=======================================================================
677 Standard_Boolean XCAFDoc_DimTolTool::FindDatum(const Handle(TCollection_HAsciiString)& aName,
678 const Handle(TCollection_HAsciiString)& aDescription,
679 const Handle(TCollection_HAsciiString)& anIdentification,
680 TDF_Label& lab) const
682 TDF_ChildIDIterator it(Label(),XCAFDoc_Datum::GetID());
683 for(; it.More(); it.Next()) {
684 Handle(TCollection_HAsciiString) aName1, aDescription1, anIdentification1;
685 TDF_Label aLabel = it.Value()->Label();
686 if ( !GetDatum( aLabel, aName1, aDescription1, anIdentification1 ) )
688 if(!(aName==aName1)) continue;
689 if(!(aDescription==aDescription1)) continue;
690 if(!(anIdentification==anIdentification1)) continue;
692 return Standard_True;
694 return Standard_False;
698 //=======================================================================
699 //function : AddDatum
701 //=======================================================================
703 TDF_Label XCAFDoc_DimTolTool::AddDatum(const Handle(TCollection_HAsciiString)& aName,
704 const Handle(TCollection_HAsciiString)& aDescription,
705 const Handle(TCollection_HAsciiString)& anIdentification) const
709 DatumL = aTag.NewChild ( Label() );
710 XCAFDoc_Datum::Set(DatumL,aName,aDescription,anIdentification);
711 TDataStd_Name::Set(DatumL,"DGT:Datum");
715 //=======================================================================
716 //function : AddDatum
718 //=======================================================================
720 TDF_Label XCAFDoc_DimTolTool::AddDatum()
724 aDatumL = aTag.NewChild ( Label() );
725 Handle(XCAFDoc_Datum) aDat = XCAFDoc_Datum::Set(aDatumL);
726 TDataStd_Name::Set(aDatumL,"DGT:Datum");
730 //=======================================================================
731 //function : SetDatum
733 //=======================================================================
735 void XCAFDoc_DimTolTool::SetDatum(const TDF_LabelSequence& theL,
736 const TDF_Label& theDatumL) const
738 if (!IsDatum(theDatumL))
743 Handle(XCAFDoc_GraphNode) aChGNode;
744 Handle(XCAFDoc_GraphNode) aFGNode;
746 if (theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
747 while (aChGNode->NbFathers() > 0) {
748 aFGNode = aChGNode->GetFather(1);
749 aFGNode->UnSetChild(aChGNode);
750 if (aFGNode->NbChildren() == 0)
751 aFGNode->ForgetAttribute(XCAFDoc::DatumRefGUID());
753 theDatumL.ForgetAttribute(XCAFDoc::DatumRefGUID());
756 if (!theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
757 aChGNode = new XCAFDoc_GraphNode;
758 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
759 aChGNode->SetGraphID(XCAFDoc::DatumRefGUID());
761 for (Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
763 if (!theL.Value(i).FindAttribute(XCAFDoc::DatumRefGUID(), aFGNode)) {
764 aFGNode = new XCAFDoc_GraphNode;
765 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
767 aFGNode->SetGraphID(XCAFDoc::DatumRefGUID());
768 aFGNode->SetChild(aChGNode);
769 aChGNode->SetFather(aFGNode);
773 //=======================================================================
774 //function : SetDatum
776 //=======================================================================
778 void XCAFDoc_DimTolTool::SetDatum(const TDF_Label& L,
779 const TDF_Label& TolerL,
780 const Handle(TCollection_HAsciiString)& aName,
781 const Handle(TCollection_HAsciiString)& aDescription,
782 const Handle(TCollection_HAsciiString)& anIdentification) const
785 if(!FindDatum(aName,aDescription,anIdentification,DatumL))
786 DatumL = AddDatum(aName,aDescription,anIdentification);
787 TDF_LabelSequence aLabels;
789 SetDatum(aLabels,DatumL);
791 Handle(XCAFDoc_GraphNode) FGNode;
792 Handle(XCAFDoc_GraphNode) ChGNode;
793 if (! TolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), FGNode) ) {
794 FGNode = new XCAFDoc_GraphNode;
795 FGNode = XCAFDoc_GraphNode::Set(TolerL);
797 if (! DatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), ChGNode) ) {
798 ChGNode = new XCAFDoc_GraphNode;
799 ChGNode = XCAFDoc_GraphNode::Set(DatumL);
801 FGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
802 ChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
803 FGNode->SetChild(ChGNode);
804 ChGNode->SetFather(FGNode);
807 //=======================================================================
808 //function : SetDatumToGeomTol
810 //=======================================================================
812 void XCAFDoc_DimTolTool::SetDatumToGeomTol(const TDF_Label& theDatumL,
813 const TDF_Label& theTolerL) const
816 Handle(XCAFDoc_GraphNode) aFGNode;
817 Handle(XCAFDoc_GraphNode) aChGNode;
818 if (! theTolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aFGNode) ) {
819 aFGNode = new XCAFDoc_GraphNode;
820 aFGNode = XCAFDoc_GraphNode::Set(theTolerL);
822 if (! theDatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aChGNode) ) {
823 aChGNode = new XCAFDoc_GraphNode;
824 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
826 aFGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
827 aChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
828 aFGNode->SetChild(aChGNode);
829 aChGNode->SetFather(aFGNode);
832 //=======================================================================
833 //function : GetDatum
835 //=======================================================================
837 Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL,
838 Handle(TCollection_HAsciiString)& theName,
839 Handle(TCollection_HAsciiString)& theDescription,
840 Handle(TCollection_HAsciiString)& theIdentification) const
842 Handle(XCAFDoc_Datum) aDatumAttr;
843 if( theDatumL.IsNull() ||
844 !theDatumL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr) )
845 return Standard_False;
847 theName = aDatumAttr->GetName();
848 theDescription = aDatumAttr->GetDescription();
849 theIdentification = aDatumAttr->GetIdentification();
850 return Standard_True;
853 //=======================================================================
854 //function : GetDatumTolerLabels
856 //=======================================================================
858 Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL,
859 TDF_LabelSequence& theDatums) const
861 Handle(XCAFDoc_GraphNode) aNode;
862 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
863 return Standard_False;
865 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
866 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
867 theDatums.Append(aDatumNode->Label());
869 return Standard_True;
872 //=======================================================================
873 //function : GetDatumWthObjectsTolerLabels
875 //=======================================================================
877 Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL,
878 TDF_LabelSequence& theDatums) const
880 Handle(XCAFDoc_GraphNode) aNode;
881 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
882 return Standard_False;
884 TColStd_MapOfAsciiString aDatumNameMap;
885 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
886 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
887 TDF_Label aDatumL = aDatumNode->Label();
888 Handle(XCAFDoc_Datum) aDatumAttr;
889 if (!aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
891 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
892 if (aDatumObj.IsNull())
894 Handle(TCollection_HAsciiString) aName = aDatumObj->GetName();
895 if (!aDatumNameMap.Add(aName->String())) {
896 // the datum has already been appended to sequence, due to one of its datum targets
899 theDatums.Append(aDatumNode->Label());
901 return Standard_True;
904 //=======================================================================
905 //function : GetTolerDatumLabels
907 //=======================================================================
909 Standard_Boolean XCAFDoc_DimTolTool::GetTolerOfDatumLabels(const TDF_Label& theDatumL,
910 TDF_LabelSequence& theTols) const
912 Handle(XCAFDoc_GraphNode) aNode;
913 if( !theDatumL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
914 return Standard_False;
915 for(Standard_Integer i=1; i<=aNode->NbFathers(); i++) {
916 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetFather(i);
917 theTols.Append(aDatumNode->Label());
919 return Standard_True;
922 //=======================================================================
923 //function : IsLocked
925 //=======================================================================
927 Standard_Boolean XCAFDoc_DimTolTool::IsLocked(const TDF_Label& theViewL) const
929 Handle(TDataStd_UAttribute) anAttr;
930 return theViewL.FindAttribute(XCAFDoc::LockGUID(), anAttr);
933 //=======================================================================
936 //=======================================================================
938 void XCAFDoc_DimTolTool::Lock(const TDF_Label& theViewL) const
940 TDataStd_UAttribute::Set(theViewL, XCAFDoc::LockGUID());
943 //=======================================================================
946 //=======================================================================
948 void XCAFDoc_DimTolTool::Unlock(const TDF_Label& theViewL) const
950 theViewL.ForgetAttribute(XCAFDoc::LockGUID());
953 //=======================================================================
956 //=======================================================================
958 const Standard_GUID& XCAFDoc_DimTolTool::ID() const
964 //=======================================================================
967 //=======================================================================
969 void XCAFDoc_DimTolTool::Restore(const Handle(TDF_Attribute)& /*with*/)
974 //=======================================================================
975 //function : NewEmpty
977 //=======================================================================
979 Handle(TDF_Attribute) XCAFDoc_DimTolTool::NewEmpty() const
981 return new XCAFDoc_DimTolTool;
985 //=======================================================================
988 //=======================================================================
990 void XCAFDoc_DimTolTool::Paste(const Handle(TDF_Attribute)& /*into*/,
991 const Handle(TDF_RelocationTable)& /*RT*/) const