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 <XCAFDimTolObjects_DimensionObject.hxx>
30 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
31 #include <XCAFDoc.hxx>
32 #include <XCAFDoc_Dimension.hxx>
33 #include <XCAFDoc_GeomTolerance.hxx>
34 #include <XCAFDoc_Datum.hxx>
35 #include <XCAFDoc_DimTol.hxx>
36 #include <XCAFDoc_DimTolTool.hxx>
37 #include <XCAFDoc_DocumentTool.hxx>
38 #include <XCAFDoc_GraphNode.hxx>
39 #include <XCAFDoc_ShapeTool.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DimTolTool,TDF_Attribute)
44 //=======================================================================
45 //function : XCAFDoc_DimTolTool
47 //=======================================================================
48 XCAFDoc_DimTolTool::XCAFDoc_DimTolTool()
53 //=======================================================================
56 //=======================================================================
58 Handle(XCAFDoc_DimTolTool) XCAFDoc_DimTolTool::Set(const TDF_Label& L)
60 Handle(XCAFDoc_DimTolTool) A;
61 if (!L.FindAttribute (XCAFDoc_DimTolTool::GetID(), A)) {
62 A = new XCAFDoc_DimTolTool ();
64 A->myShapeTool = XCAFDoc_DocumentTool::ShapeTool(L);
70 //=======================================================================
73 //=======================================================================
75 const Standard_GUID& XCAFDoc_DimTolTool::GetID()
77 static Standard_GUID DGTTblID ("72afb19b-44de-11d8-8776-001083004c77");
82 //=======================================================================
83 //function : BaseLabel
85 //=======================================================================
87 TDF_Label XCAFDoc_DimTolTool::BaseLabel() const
93 //=======================================================================
94 //function : ShapeTool
96 //=======================================================================
98 const Handle(XCAFDoc_ShapeTool)& XCAFDoc_DimTolTool::ShapeTool()
100 if(myShapeTool.IsNull())
101 myShapeTool = XCAFDoc_DocumentTool::ShapeTool(Label());
106 //=======================================================================
107 //function : IsDimTol
109 //=======================================================================
111 Standard_Boolean XCAFDoc_DimTolTool::IsDimTol(const TDF_Label& theDimTolL) const
113 Handle(XCAFDoc_DimTol) aDimTolAttr;
114 if(theDimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),aDimTolAttr)) {
115 return Standard_True;
117 return Standard_False;
120 //=======================================================================
121 //function : IsDimension
123 //=======================================================================
125 Standard_Boolean XCAFDoc_DimTolTool::IsDimension(const TDF_Label& theDimTolL) const
127 Handle(XCAFDoc_Dimension) aDimTolAttr;
128 if(theDimTolL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimTolAttr)) {
129 return Standard_True;
131 return Standard_False;
134 //=======================================================================
135 //function : IsGeomTolerance
137 //=======================================================================
139 Standard_Boolean XCAFDoc_DimTolTool::IsGeomTolerance(const TDF_Label& theDimTolL) const
141 Handle(XCAFDoc_GeomTolerance) aDimTolAttr;
142 if(theDimTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimTolAttr)) {
143 return Standard_True;
145 return Standard_False;
148 //=======================================================================
149 //function : GetDimTolLabels
151 //=======================================================================
153 void XCAFDoc_DimTolTool::GetDimTolLabels(TDF_LabelSequence& theLabels) const
156 TDF_ChildIterator aChildIterator( Label() );
157 for (; aChildIterator.More(); aChildIterator.Next()) {
158 TDF_Label aL = aChildIterator.Value();
159 if ( IsDimTol(aL)) theLabels.Append(aL);
163 //=======================================================================
164 //function : GetDimensionLabels
166 //=======================================================================
168 void XCAFDoc_DimTolTool::GetDimensionLabels(TDF_LabelSequence& theLabels) const
171 TDF_ChildIterator aChildIterator( Label() );
172 for (; aChildIterator.More(); aChildIterator.Next()) {
173 TDF_Label aL = aChildIterator.Value();
174 if ( IsDimension(aL)) theLabels.Append(aL);
178 //=======================================================================
179 //function : GetGeomToleranceLabels
181 //=======================================================================
183 void XCAFDoc_DimTolTool::GetGeomToleranceLabels(TDF_LabelSequence& theLabels) const
186 TDF_ChildIterator aChildIterator( Label() );
187 for (; aChildIterator.More(); aChildIterator.Next()) {
188 TDF_Label aL = aChildIterator.Value();
189 if ( IsGeomTolerance(aL)) theLabels.Append(aL);
193 //=======================================================================
194 //function : FindDimTol
196 //=======================================================================
198 Standard_Boolean XCAFDoc_DimTolTool::FindDimTol(const Standard_Integer kind,
199 const Handle(TColStd_HArray1OfReal)& aVal,
200 const Handle(TCollection_HAsciiString)& aName,
201 const Handle(TCollection_HAsciiString)& aDescription,
202 TDF_Label& lab) const
204 TDF_ChildIDIterator it(Label(),XCAFDoc_DimTol::GetID());
205 for(; it.More(); it.Next()) {
206 TDF_Label DimTolL = it.Value()->Label();
207 Handle(XCAFDoc_DimTol) DimTolAttr;
208 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
209 Standard_Integer kind1 = DimTolAttr->GetKind();
210 Handle(TColStd_HArray1OfReal) aVal1 = DimTolAttr->GetVal();
211 Handle(TCollection_HAsciiString) aName1 = DimTolAttr->GetName();
212 Handle(TCollection_HAsciiString) aDescription1 = DimTolAttr->GetDescription();
213 Standard_Boolean IsEqual = Standard_True;
214 if(!(kind1==kind)) continue;
215 if(!(aName==aName1)) continue;
216 if(!(aDescription==aDescription1)) continue;
217 if(kind<20) { //dimension
218 for(Standard_Integer i=1; i<=aVal->Length(); i++) {
219 if(Abs(aVal->Value(i)-aVal1->Value(i))>Precision::Confusion())
220 IsEqual = Standard_False;
223 else if(kind<50) { //tolerance
224 if(Abs(aVal->Value(1)-aVal1->Value(1))>Precision::Confusion())
225 IsEqual = Standard_False;
229 return Standard_True;
232 return Standard_False;
236 //=======================================================================
237 //function : FindDimTol
239 //=======================================================================
241 TDF_Label XCAFDoc_DimTolTool::FindDimTol(const Standard_Integer kind,
242 const Handle(TColStd_HArray1OfReal)& aVal,
243 const Handle(TCollection_HAsciiString)& aName,
244 const Handle(TCollection_HAsciiString)& aDescription) const
247 FindDimTol(kind,aVal,aName,aDescription,L);
252 //=======================================================================
253 //function : AddDimTol
255 //=======================================================================
257 TDF_Label XCAFDoc_DimTolTool::AddDimTol(const Standard_Integer kind,
258 const Handle(TColStd_HArray1OfReal)& aVal,
259 const Handle(TCollection_HAsciiString)& aName,
260 const Handle(TCollection_HAsciiString)& aDescription) const
264 DimTolL = aTag.NewChild ( Label() );
265 XCAFDoc_DimTol::Set(DimTolL,kind,aVal,aName,aDescription);
266 TCollection_AsciiString str = "DGT:";
267 if(kind<20) str.AssignCat("Dimension");
268 else str.AssignCat("Tolerance");
269 TDataStd_Name::Set(DimTolL,str);
273 //=======================================================================
274 //function : AddDimension
276 //=======================================================================
278 TDF_Label XCAFDoc_DimTolTool::AddDimension()
282 aDimTolL = aTag.NewChild ( Label() );
283 Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aDimTolL);
284 TCollection_AsciiString aStr = "DGT:Dimension";
285 TDataStd_Name::Set(aDimTolL,aStr);
289 //=======================================================================
290 //function : AddGeomTolerance
292 //=======================================================================
294 TDF_Label XCAFDoc_DimTolTool::AddGeomTolerance()
298 aDimTolL = aTag.NewChild ( Label() );
299 Handle(XCAFDoc_GeomTolerance) aTol = XCAFDoc_GeomTolerance::Set(aDimTolL);
300 TCollection_AsciiString aStr = "DGT:Tolerance";
301 TDataStd_Name::Set(aDimTolL,aStr);
305 //=======================================================================
306 //function : SetDimension
308 //=======================================================================
310 void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theL,
311 const TDF_Label& theDimTolL) const
314 SetDimension(theL, nullLab, theDimTolL);
317 //=======================================================================
318 //function : SetDimension
320 //=======================================================================
322 void XCAFDoc_DimTolTool::SetDimension(const TDF_Label& theFirstL,
323 const TDF_Label& theSecondL,
324 const TDF_Label& theDimTolL) const
326 TDF_LabelSequence aFirstLS, aSecondLS;
327 if(!theFirstL.IsNull())
328 aFirstLS.Append(theFirstL);
329 if(!theSecondL.IsNull())
330 aSecondLS.Append(theSecondL);
331 SetDimension(aFirstLS, aSecondLS, theDimTolL);
334 //=======================================================================
335 //function : SetDimension
337 //=======================================================================
339 void XCAFDoc_DimTolTool::SetDimension(const TDF_LabelSequence& theFirstL,
340 const TDF_LabelSequence& theSecondL,
341 const TDF_Label& theDimTolL) const
343 if(!IsDimension(theDimTolL) || theFirstL.Length() == 0)
348 Handle(XCAFDoc_GraphNode) aChGNode;
349 Handle(XCAFDoc_GraphNode) aFGNode;
350 Handle(XCAFDoc_GraphNode) aSecondFGNode;
352 if ( theDimTolL.FindAttribute (XCAFDoc::DimensionRefFirstGUID(), aChGNode) ) {
353 while (aChGNode->NbFathers() > 0) {
354 aFGNode = aChGNode->GetFather(1);
355 aFGNode->UnSetChild(aChGNode);
356 if(aFGNode->NbChildren() == 0)
357 aFGNode->ForgetAttribute( XCAFDoc::DimensionRefFirstGUID() );
359 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefFirstGUID() );
361 if ( theDimTolL.FindAttribute (XCAFDoc::DimensionRefSecondGUID(), aChGNode) ) {
362 while (aChGNode->NbFathers() > 0) {
363 aFGNode = aChGNode->GetFather(1);
364 aFGNode->UnSetChild(aChGNode);
365 if(aFGNode->NbChildren() == 0)
366 aFGNode->ForgetAttribute( XCAFDoc::DimensionRefSecondGUID() );
368 theDimTolL.ForgetAttribute ( XCAFDoc::DimensionRefSecondGUID() );
371 if (!theDimTolL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aChGNode)) {
372 aChGNode = new XCAFDoc_GraphNode;
373 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
374 aChGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
376 for(Standard_Integer i = theFirstL.Lower(); i <= theFirstL.Upper(); i++)
378 if (!theFirstL.Value(i).FindAttribute(XCAFDoc::DimensionRefFirstGUID(), aFGNode) ) {
379 aFGNode = new XCAFDoc_GraphNode;
380 aFGNode = XCAFDoc_GraphNode::Set(theFirstL.Value(i));
382 aFGNode->SetGraphID(XCAFDoc::DimensionRefFirstGUID());
383 aFGNode->SetChild(aChGNode);
384 aChGNode->SetFather(aFGNode);
387 if (!theDimTolL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(), aChGNode) && theSecondL.Length() > 0) {
388 aChGNode = new XCAFDoc_GraphNode;
389 aChGNode = XCAFDoc_GraphNode::Set(theDimTolL);
390 aChGNode->SetGraphID(XCAFDoc::DimensionRefSecondGUID());
392 for(Standard_Integer i = theSecondL.Lower(); i <= theSecondL.Upper(); i++)
394 if(!theSecondL.Value(i).FindAttribute(XCAFDoc::DimensionRefSecondGUID(), aSecondFGNode) ) {
395 aSecondFGNode = new XCAFDoc_GraphNode;
396 aSecondFGNode = XCAFDoc_GraphNode::Set(theSecondL.Value(i));
398 aSecondFGNode->SetGraphID(XCAFDoc::DimensionRefSecondGUID());
399 aSecondFGNode->SetChild(aChGNode);
400 aChGNode->SetFather(aSecondFGNode);
404 //=======================================================================
405 //function : SetGeomTolerance
407 //=======================================================================
409 void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_Label& theL,
410 const TDF_Label& theGeomTolL) const
412 TDF_LabelSequence aSeq;
414 SetGeomTolerance(aSeq, theGeomTolL);
417 //=======================================================================
418 //function : SetGeomTolerance
420 //=======================================================================
422 void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_LabelSequence& theL,
423 const TDF_Label& theGeomTolL) const
426 // Handle(TDataStd_TreeNode) refNode, mainNode;
427 // refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::GeomToleranceRefGUID() );
428 // mainNode = TDataStd_TreeNode::Set ( theL, XCAFDoc::GeomToleranceRefGUID() );
429 // refNode->Remove(); // abv: fix against bug in TreeNode::Append()
430 // mainNode->Append(refNode);
432 if (!IsGeomTolerance(theGeomTolL) || theL.Length() == 0)
437 Handle(XCAFDoc_GraphNode) aChGNode;
438 Handle(XCAFDoc_GraphNode) aFGNode;
440 if (theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
441 while (aChGNode->NbFathers() > 0) {
442 aFGNode = aChGNode->GetFather(1);
443 aFGNode->UnSetChild(aChGNode);
444 if(aFGNode->NbChildren() == 0)
445 aFGNode->ForgetAttribute( XCAFDoc::GeomToleranceRefGUID() );
447 theGeomTolL.ForgetAttribute(XCAFDoc::GeomToleranceRefGUID());
450 if (!theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
451 aChGNode = new XCAFDoc_GraphNode;
452 aChGNode = XCAFDoc_GraphNode::Set(theGeomTolL);
453 aChGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
455 for(Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
457 if (!theL.Value(i).FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aFGNode) ) {
458 aFGNode = new XCAFDoc_GraphNode;
459 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
461 aFGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
462 aFGNode->SetChild(aChGNode);
463 aChGNode->SetFather(aFGNode);
467 //=======================================================================
468 //function : SetDimTol
470 //=======================================================================
472 void XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& theL,
473 const TDF_Label& theDimTolL) const
476 Handle(TDataStd_TreeNode) refNode, mainNode;
477 refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::DimTolRefGUID() );
478 mainNode = TDataStd_TreeNode::Set (theL, XCAFDoc::DimTolRefGUID() );
479 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
480 mainNode->Append(refNode);
484 //=======================================================================
485 //function : SetDimTol
487 //=======================================================================
489 TDF_Label XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& L,
490 const Standard_Integer kind,
491 const Handle(TColStd_HArray1OfReal)& aVal,
492 const Handle(TCollection_HAsciiString)& aName,
493 const Handle(TCollection_HAsciiString)& aDescription) const
495 TDF_Label DimTolL = AddDimTol(kind,aVal,aName,aDescription);
496 SetDimTol(L,DimTolL);
501 //=======================================================================
502 //function : GetRefShapeLabel
504 //=======================================================================
506 Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL,
507 TDF_LabelSequence& theShapeLFirst,
508 TDF_LabelSequence& theShapeLSecond) const
510 theShapeLFirst.Clear();
511 theShapeLSecond.Clear();
512 Handle(TDataStd_TreeNode) aNode;
513 if( !theL.FindAttribute(XCAFDoc::DimTolRefGUID(),aNode) || !aNode->HasFather() ) {
514 if( !theL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) || !aNode->HasFather() ) {
515 Handle(XCAFDoc_GraphNode) aGNode;
516 if( theL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
517 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
519 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
521 return Standard_True;
523 else if (theL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode) && aGNode->NbFathers() > 0) {
524 for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
526 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
528 return Standard_True;
530 else if( theL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
531 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
533 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
535 if( theL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
536 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
538 theShapeLSecond.Append(aGNode->GetFather(i)->Label());
541 return Standard_True;
545 return Standard_False;
550 theShapeLFirst.Append(aNode->Father()->Label());
551 return Standard_True;
554 //=======================================================================
555 //function : GetRefDimensionLabels
557 //=======================================================================
559 Standard_Boolean XCAFDoc_DimTolTool::GetRefDimensionLabels(const TDF_Label& theShapeL,
560 TDF_LabelSequence& theDimTols) const
562 Handle(XCAFDoc_GraphNode) aGNode;
563 Standard_Boolean aResult = Standard_False;
564 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
565 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
567 theDimTols.Append(aGNode->GetChild(i)->Label());
569 aResult = Standard_True;
571 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
572 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
574 theDimTols.Append(aGNode->GetChild(i)->Label());
576 aResult = Standard_True;
581 //=======================================================================
582 //function : GetRefGeomToleranceLabels
584 //=======================================================================
586 Standard_Boolean XCAFDoc_DimTolTool::GetRefGeomToleranceLabels(const TDF_Label& theShapeL,
587 TDF_LabelSequence& theDimTols) const
589 Handle(XCAFDoc_GraphNode) aGNode;
590 if( !theShapeL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) ||
591 aGNode->NbChildren() == 0 ) {
592 return Standard_False;
594 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
596 theDimTols.Append(aGNode->GetChild(i)->Label());
598 return Standard_True;
601 //=======================================================================
602 //function : GetRefDatumLabel
604 //=======================================================================
606 Standard_Boolean XCAFDoc_DimTolTool::GetRefDatumLabel(const TDF_Label& theShapeL,
607 TDF_LabelSequence& theDatum) const
609 Handle(XCAFDoc_GraphNode) aGNode;
610 if (!theShapeL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode)) {
611 return Standard_False;
613 for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) {
614 theDatum.Append(aGNode->GetChild(i)->Label());
616 return Standard_True;
619 //=======================================================================
620 //function : GetDimTol
622 //=======================================================================
624 Standard_Boolean XCAFDoc_DimTolTool::GetDimTol(const TDF_Label& DimTolL,
625 Standard_Integer& kind,
626 Handle(TColStd_HArray1OfReal)& aVal,
627 Handle(TCollection_HAsciiString)& aName,
628 Handle(TCollection_HAsciiString)& aDescription) const
630 Handle(XCAFDoc_DimTol) DimTolAttr;
631 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) {
632 return Standard_False;
634 kind = DimTolAttr->GetKind();
635 aVal = DimTolAttr->GetVal();
636 aName = DimTolAttr->GetName();
637 aDescription = DimTolAttr->GetDescription();
639 return Standard_True;
643 //=======================================================================
646 //=======================================================================
648 Standard_Boolean XCAFDoc_DimTolTool::IsDatum(const TDF_Label& theDimTolL) const
650 Handle(XCAFDoc_Datum) aDatumAttr;
651 if(theDimTolL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr)) {
652 return Standard_True;
654 return Standard_False;
658 //=======================================================================
659 //function : GetDatumLabels
661 //=======================================================================
663 void XCAFDoc_DimTolTool::GetDatumLabels(TDF_LabelSequence& theLabels) const
666 TDF_ChildIterator aChildIterator( Label() );
667 for (; aChildIterator.More(); aChildIterator.Next()) {
668 TDF_Label L = aChildIterator.Value();
669 if ( IsDatum(L)) theLabels.Append(L);
673 //=======================================================================
674 //function : FindDatum
676 //=======================================================================
678 Standard_Boolean XCAFDoc_DimTolTool::FindDatum(const Handle(TCollection_HAsciiString)& aName,
679 const Handle(TCollection_HAsciiString)& aDescription,
680 const Handle(TCollection_HAsciiString)& anIdentification,
681 TDF_Label& lab) const
683 TDF_ChildIDIterator it(Label(),XCAFDoc_Datum::GetID());
684 for(; it.More(); it.Next()) {
685 Handle(TCollection_HAsciiString) aName1, aDescription1, anIdentification1;
686 TDF_Label aLabel = it.Value()->Label();
687 if ( !GetDatum( aLabel, aName1, aDescription1, anIdentification1 ) )
689 if(!(aName==aName1)) continue;
690 if(!(aDescription==aDescription1)) continue;
691 if(!(anIdentification==anIdentification1)) continue;
693 return Standard_True;
695 return Standard_False;
699 //=======================================================================
700 //function : AddDatum
702 //=======================================================================
704 TDF_Label XCAFDoc_DimTolTool::AddDatum(const Handle(TCollection_HAsciiString)& aName,
705 const Handle(TCollection_HAsciiString)& aDescription,
706 const Handle(TCollection_HAsciiString)& anIdentification) const
710 DatumL = aTag.NewChild ( Label() );
711 XCAFDoc_Datum::Set(DatumL,aName,aDescription,anIdentification);
712 TDataStd_Name::Set(DatumL,"DGT:Datum");
716 //=======================================================================
717 //function : AddDatum
719 //=======================================================================
721 TDF_Label XCAFDoc_DimTolTool::AddDatum()
725 aDatumL = aTag.NewChild ( Label() );
726 Handle(XCAFDoc_Datum) aDat = XCAFDoc_Datum::Set(aDatumL);
727 TDataStd_Name::Set(aDatumL,"DGT:Datum");
731 //=======================================================================
732 //function : SetDatum
734 //=======================================================================
736 void XCAFDoc_DimTolTool::SetDatum(const TDF_LabelSequence& theL,
737 const TDF_Label& theDatumL) const
739 if (!IsDatum(theDatumL))
744 Handle(XCAFDoc_GraphNode) aChGNode;
745 Handle(XCAFDoc_GraphNode) aFGNode;
747 if (theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
748 while (aChGNode->NbFathers() > 0) {
749 aFGNode = aChGNode->GetFather(1);
750 aFGNode->UnSetChild(aChGNode);
751 if (aFGNode->NbChildren() == 0)
752 aFGNode->ForgetAttribute(XCAFDoc::DatumRefGUID());
754 theDatumL.ForgetAttribute(XCAFDoc::DatumRefGUID());
757 if (!theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
758 aChGNode = new XCAFDoc_GraphNode;
759 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
760 aChGNode->SetGraphID(XCAFDoc::DatumRefGUID());
762 for (Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
764 if (!theL.Value(i).FindAttribute(XCAFDoc::DatumRefGUID(), aFGNode)) {
765 aFGNode = new XCAFDoc_GraphNode;
766 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
768 aFGNode->SetGraphID(XCAFDoc::DatumRefGUID());
769 aFGNode->SetChild(aChGNode);
770 aChGNode->SetFather(aFGNode);
774 //=======================================================================
775 //function : SetDatum
777 //=======================================================================
779 void XCAFDoc_DimTolTool::SetDatum(const TDF_Label& L,
780 const TDF_Label& TolerL,
781 const Handle(TCollection_HAsciiString)& aName,
782 const Handle(TCollection_HAsciiString)& aDescription,
783 const Handle(TCollection_HAsciiString)& anIdentification) const
786 if(!FindDatum(aName,aDescription,anIdentification,DatumL))
787 DatumL = AddDatum(aName,aDescription,anIdentification);
788 TDF_LabelSequence aLabels;
790 SetDatum(aLabels,DatumL);
792 Handle(XCAFDoc_GraphNode) FGNode;
793 Handle(XCAFDoc_GraphNode) ChGNode;
794 if (! TolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), FGNode) ) {
795 FGNode = new XCAFDoc_GraphNode;
796 FGNode = XCAFDoc_GraphNode::Set(TolerL);
798 if (! DatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), ChGNode) ) {
799 ChGNode = new XCAFDoc_GraphNode;
800 ChGNode = XCAFDoc_GraphNode::Set(DatumL);
802 FGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
803 ChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
804 FGNode->SetChild(ChGNode);
805 ChGNode->SetFather(FGNode);
808 //=======================================================================
809 //function : SetDatumToGeomTol
811 //=======================================================================
813 void XCAFDoc_DimTolTool::SetDatumToGeomTol(const TDF_Label& theDatumL,
814 const TDF_Label& theTolerL) const
817 Handle(XCAFDoc_GraphNode) aFGNode;
818 Handle(XCAFDoc_GraphNode) aChGNode;
819 if (! theTolerL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aFGNode) ) {
820 aFGNode = new XCAFDoc_GraphNode;
821 aFGNode = XCAFDoc_GraphNode::Set(theTolerL);
823 if (! theDatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aChGNode) ) {
824 aChGNode = new XCAFDoc_GraphNode;
825 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
827 aFGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
828 aChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
829 aFGNode->SetChild(aChGNode);
830 aChGNode->SetFather(aFGNode);
833 //=======================================================================
834 //function : GetDatum
836 //=======================================================================
838 Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL,
839 Handle(TCollection_HAsciiString)& theName,
840 Handle(TCollection_HAsciiString)& theDescription,
841 Handle(TCollection_HAsciiString)& theIdentification) const
843 Handle(XCAFDoc_Datum) aDatumAttr;
844 if( theDatumL.IsNull() ||
845 !theDatumL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr) )
846 return Standard_False;
848 theName = aDatumAttr->GetName();
849 theDescription = aDatumAttr->GetDescription();
850 theIdentification = aDatumAttr->GetIdentification();
851 return Standard_True;
854 //=======================================================================
855 //function : GetDatumTolerLabels
857 //=======================================================================
859 Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL,
860 TDF_LabelSequence& theDatums) const
862 Handle(XCAFDoc_GraphNode) aNode;
863 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
864 return Standard_False;
866 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
867 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
868 theDatums.Append(aDatumNode->Label());
870 return Standard_True;
873 //=======================================================================
874 //function : GetDatumWthObjectsTolerLabels
876 //=======================================================================
878 Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL,
879 TDF_LabelSequence& theDatums) const
881 Handle(XCAFDoc_GraphNode) aNode;
882 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
883 return Standard_False;
885 TColStd_MapOfAsciiString aDatumNameMap;
886 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
887 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
888 TDF_Label aDatumL = aDatumNode->Label();
889 Handle(XCAFDoc_Datum) aDatumAttr;
890 if (!aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr))
892 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
893 if (aDatumObj.IsNull())
895 Handle(TCollection_HAsciiString) aName = aDatumObj->GetName();
896 if (!aDatumNameMap.Add(aName->String())) {
897 // the datum has already been appended to sequence, due to one of its datum targets
900 theDatums.Append(aDatumNode->Label());
902 return Standard_True;
905 //=======================================================================
906 //function : GetTolerDatumLabels
908 //=======================================================================
910 Standard_Boolean XCAFDoc_DimTolTool::GetTolerOfDatumLabels(const TDF_Label& theDatumL,
911 TDF_LabelSequence& theTols) const
913 Handle(XCAFDoc_GraphNode) aNode;
914 if( !theDatumL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
915 return Standard_False;
916 for(Standard_Integer i=1; i<=aNode->NbFathers(); i++) {
917 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetFather(i);
918 theTols.Append(aDatumNode->Label());
920 return Standard_True;
923 //=======================================================================
924 //function : IsLocked
926 //=======================================================================
928 Standard_Boolean XCAFDoc_DimTolTool::IsLocked(const TDF_Label& theViewL) const
930 Handle(TDataStd_UAttribute) anAttr;
931 return theViewL.FindAttribute(XCAFDoc::LockGUID(), anAttr);
934 //=======================================================================
937 //=======================================================================
939 void XCAFDoc_DimTolTool::Lock(const TDF_Label& theViewL) const
941 TDataStd_UAttribute::Set(theViewL, XCAFDoc::LockGUID());
944 //=======================================================================
947 //=======================================================================
949 void XCAFDoc_DimTolTool::Unlock(const TDF_Label& theViewL) const
951 theViewL.ForgetAttribute(XCAFDoc::LockGUID());
954 //=======================================================================
957 //=======================================================================
959 const Standard_GUID& XCAFDoc_DimTolTool::ID() const
965 //=======================================================================
968 //=======================================================================
970 void XCAFDoc_DimTolTool::Restore(const Handle(TDF_Attribute)& /*with*/)
975 //=======================================================================
976 //function : NewEmpty
978 //=======================================================================
980 Handle(TDF_Attribute) XCAFDoc_DimTolTool::NewEmpty() const
982 return new XCAFDoc_DimTolTool;
986 //=======================================================================
989 //=======================================================================
991 void XCAFDoc_DimTolTool::Paste(const Handle(TDF_Attribute)& /*into*/,
992 const Handle(TDF_RelocationTable)& /*RT*/) const
996 //=======================================================================
997 //function : GetGDTPresentations
999 //=======================================================================
1000 void XCAFDoc_DimTolTool::GetGDTPresentations(NCollection_IndexedDataMap<TDF_Label,
1001 TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToShape) const
1003 TDF_LabelSequence aGDTs;
1004 GetDimensionLabels(aGDTs);
1005 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
1006 Handle(XCAFDoc_Dimension) aDimAttr;
1007 const TDF_Label& aCL = aGDTs.Value(i);
1008 if (!aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr))
1010 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
1011 if (anObject.IsNull())
1013 TopoDS_Shape aShape = anObject->GetPresentation();
1014 if (!aShape.IsNull())
1015 theGDTLabelToShape.Add(aCL, aShape);
1019 GetGeomToleranceLabels(aGDTs);
1020 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
1021 Handle(XCAFDoc_GeomTolerance) aGTAttr;
1022 const TDF_Label& aCL = aGDTs.Value(i);
1023 if (!aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aGTAttr))
1025 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
1026 if (anObject.IsNull())
1028 TopoDS_Shape aShape = anObject->GetPresentation();
1029 if (!aShape.IsNull())
1030 theGDTLabelToShape.Add(aCL, aShape);
1034 GetDatumLabels(aGDTs);
1035 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
1036 Handle(XCAFDoc_Datum) aGTAttr;
1037 const TDF_Label& aCL = aGDTs.Value(i);
1038 if (!aCL.FindAttribute(XCAFDoc_Datum::GetID(),aGTAttr))
1040 Handle(XCAFDimTolObjects_DatumObject) anObject = aGTAttr->GetObject();
1041 if (anObject.IsNull())
1043 TopoDS_Shape aShape = anObject->GetPresentation();
1044 if (!aShape.IsNull())
1045 theGDTLabelToShape.Add(aCL, aShape);
1049 //=======================================================================
1050 //function : SetGDTPresentations
1052 //=======================================================================
1053 void XCAFDoc_DimTolTool::SetGDTPresentations(NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToPrs)
1055 for (Standard_Integer i = 1; i <= theGDTLabelToPrs.Extent(); i++)
1057 const TDF_Label& aCL = theGDTLabelToPrs.FindKey(i);
1058 Handle(XCAFDoc_Dimension) aDimAttrDim;
1059 if (aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttrDim))
1061 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttrDim->GetObject();
1062 if (anObject.IsNull())
1064 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1065 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1066 aDimAttrDim->SetObject(anObject);
1069 Handle(XCAFDoc_GeomTolerance) aDimAttrG;
1070 if (aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimAttrG))
1072 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aDimAttrG->GetObject();
1073 if (anObject.IsNull())
1075 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1076 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1077 aDimAttrG->SetObject(anObject);
1080 Handle(XCAFDoc_Datum) aDimAttrD;
1081 if (aCL.FindAttribute(XCAFDoc_Datum::GetID(),aDimAttrD))
1083 Handle(XCAFDimTolObjects_DatumObject) anObject = aDimAttrD->GetObject();
1084 if (anObject.IsNull())
1086 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1087 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1088 aDimAttrD->SetObject(anObject);