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>
16 #include <Standard_Type.hxx>
17 #include <TColStd_MapOfAsciiString.hxx>
18 #include <TDataStd_Name.hxx>
19 #include <TDataStd_TreeNode.hxx>
20 #include <TDataStd_UAttribute.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_ChildIDIterator.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_RelocationTable.hxx>
25 #include <TDF_Tool.hxx>
26 #include <XCAFDimTolObjects_DatumObject.hxx>
27 #include <XCAFDimTolObjects_DimensionObject.hxx>
28 #include <XCAFDimTolObjects_GeomToleranceObject.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_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_DimTolTool,TDataStd_GenericEmpty,"xcaf","DimTolTool")
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& theGeomTolL) const
410 TDF_LabelSequence aSeq;
412 SetGeomTolerance(aSeq, theGeomTolL);
415 //=======================================================================
416 //function : SetGeomTolerance
418 //=======================================================================
420 void XCAFDoc_DimTolTool::SetGeomTolerance(const TDF_LabelSequence& theL,
421 const TDF_Label& theGeomTolL) 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(theGeomTolL) || theL.Length() == 0)
435 Handle(XCAFDoc_GraphNode) aChGNode;
436 Handle(XCAFDoc_GraphNode) aFGNode;
438 if (theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
439 while (aChGNode->NbFathers() > 0) {
440 aFGNode = aChGNode->GetFather(1);
441 aFGNode->UnSetChild(aChGNode);
442 if(aFGNode->NbChildren() == 0)
443 aFGNode->ForgetAttribute( XCAFDoc::GeomToleranceRefGUID() );
445 theGeomTolL.ForgetAttribute(XCAFDoc::GeomToleranceRefGUID());
448 if (!theGeomTolL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aChGNode)) {
449 aChGNode = new XCAFDoc_GraphNode;
450 aChGNode = XCAFDoc_GraphNode::Set(theGeomTolL);
451 aChGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
453 for(Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
455 if (!theL.Value(i).FindAttribute(XCAFDoc::GeomToleranceRefGUID(), aFGNode) ) {
456 aFGNode = new XCAFDoc_GraphNode;
457 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
459 aFGNode->SetGraphID(XCAFDoc::GeomToleranceRefGUID());
460 aFGNode->SetChild(aChGNode);
461 aChGNode->SetFather(aFGNode);
465 //=======================================================================
466 //function : SetDimTol
468 //=======================================================================
470 void XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& theL,
471 const TDF_Label& theDimTolL) const
474 Handle(TDataStd_TreeNode) refNode, mainNode;
475 refNode = TDataStd_TreeNode::Set ( theDimTolL, XCAFDoc::DimTolRefGUID() );
476 mainNode = TDataStd_TreeNode::Set (theL, XCAFDoc::DimTolRefGUID() );
477 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
478 mainNode->Append(refNode);
482 //=======================================================================
483 //function : SetDimTol
485 //=======================================================================
487 TDF_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
493 TDF_Label DimTolL = AddDimTol(kind,aVal,aName,aDescription);
494 SetDimTol(L,DimTolL);
499 //=======================================================================
500 //function : GetRefShapeLabel
502 //=======================================================================
504 Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL,
505 TDF_LabelSequence& theShapeLFirst,
506 TDF_LabelSequence& theShapeLSecond) const
508 theShapeLFirst.Clear();
509 theShapeLSecond.Clear();
510 Handle(TDataStd_TreeNode) aNode;
511 if( !theL.FindAttribute(XCAFDoc::DimTolRefGUID(),aNode) || !aNode->HasFather() ) {
512 if( !theL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) || !aNode->HasFather() ) {
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++)
517 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
519 return Standard_True;
521 else if (theL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode) && aGNode->NbFathers() > 0) {
522 for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
524 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
526 return Standard_True;
528 else if( theL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
529 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
531 theShapeLFirst.Append(aGNode->GetFather(i)->Label());
533 if( theL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbFathers() > 0 ) {
534 for(Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
536 theShapeLSecond.Append(aGNode->GetFather(i)->Label());
539 return Standard_True;
543 return Standard_False;
548 theShapeLFirst.Append(aNode->Father()->Label());
549 return Standard_True;
552 //=======================================================================
553 //function : GetRefDimensionLabels
555 //=======================================================================
557 Standard_Boolean XCAFDoc_DimTolTool::GetRefDimensionLabels(const TDF_Label& theShapeL,
558 TDF_LabelSequence& theDimTols) const
560 Handle(XCAFDoc_GraphNode) aGNode;
561 Standard_Boolean aResult = Standard_False;
562 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefFirstGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
563 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
565 theDimTols.Append(aGNode->GetChild(i)->Label());
567 aResult = Standard_True;
569 if( theShapeL.FindAttribute(XCAFDoc::DimensionRefSecondGUID(),aGNode) && aGNode->NbChildren() > 0 ) {
570 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
572 theDimTols.Append(aGNode->GetChild(i)->Label());
574 aResult = Standard_True;
579 //=======================================================================
580 //function : GetRefGeomToleranceLabels
582 //=======================================================================
584 Standard_Boolean XCAFDoc_DimTolTool::GetRefGeomToleranceLabels(const TDF_Label& theShapeL,
585 TDF_LabelSequence& theDimTols) const
587 Handle(XCAFDoc_GraphNode) aGNode;
588 if( !theShapeL.FindAttribute(XCAFDoc::GeomToleranceRefGUID(),aGNode) ||
589 aGNode->NbChildren() == 0 ) {
590 return Standard_False;
592 for(Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
594 theDimTols.Append(aGNode->GetChild(i)->Label());
596 return Standard_True;
599 //=======================================================================
600 //function : GetRefDatumLabel
602 //=======================================================================
604 Standard_Boolean XCAFDoc_DimTolTool::GetRefDatumLabel(const TDF_Label& theShapeL,
605 TDF_LabelSequence& theDatum) const
607 Handle(XCAFDoc_GraphNode) aGNode;
608 if (!theShapeL.FindAttribute(XCAFDoc::DatumRefGUID(), aGNode)) {
609 return Standard_False;
611 for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) {
612 theDatum.Append(aGNode->GetChild(i)->Label());
614 return Standard_True;
617 //=======================================================================
618 //function : GetDimTol
620 //=======================================================================
622 Standard_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
628 Handle(XCAFDoc_DimTol) DimTolAttr;
629 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) {
630 return Standard_False;
632 kind = DimTolAttr->GetKind();
633 aVal = DimTolAttr->GetVal();
634 aName = DimTolAttr->GetName();
635 aDescription = DimTolAttr->GetDescription();
637 return Standard_True;
641 //=======================================================================
644 //=======================================================================
646 Standard_Boolean XCAFDoc_DimTolTool::IsDatum(const TDF_Label& theDimTolL) const
648 Handle(XCAFDoc_Datum) aDatumAttr;
649 if(theDimTolL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr)) {
650 return Standard_True;
652 return Standard_False;
656 //=======================================================================
657 //function : GetDatumLabels
659 //=======================================================================
661 void XCAFDoc_DimTolTool::GetDatumLabels(TDF_LabelSequence& theLabels) const
664 TDF_ChildIterator aChildIterator( Label() );
665 for (; aChildIterator.More(); aChildIterator.Next()) {
666 TDF_Label L = aChildIterator.Value();
667 if ( IsDatum(L)) theLabels.Append(L);
671 //=======================================================================
672 //function : FindDatum
674 //=======================================================================
676 Standard_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
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 ) )
687 if(!(aName==aName1)) continue;
688 if(!(aDescription==aDescription1)) continue;
689 if(!(anIdentification==anIdentification1)) continue;
691 return Standard_True;
693 return Standard_False;
697 //=======================================================================
698 //function : AddDatum
700 //=======================================================================
702 TDF_Label XCAFDoc_DimTolTool::AddDatum(const Handle(TCollection_HAsciiString)& aName,
703 const Handle(TCollection_HAsciiString)& aDescription,
704 const Handle(TCollection_HAsciiString)& anIdentification) const
708 DatumL = aTag.NewChild ( Label() );
709 XCAFDoc_Datum::Set(DatumL,aName,aDescription,anIdentification);
710 TDataStd_Name::Set(DatumL,"DGT:Datum");
714 //=======================================================================
715 //function : AddDatum
717 //=======================================================================
719 TDF_Label XCAFDoc_DimTolTool::AddDatum()
723 aDatumL = aTag.NewChild ( Label() );
724 Handle(XCAFDoc_Datum) aDat = XCAFDoc_Datum::Set(aDatumL);
725 TDataStd_Name::Set(aDatumL,"DGT:Datum");
729 //=======================================================================
730 //function : SetDatum
732 //=======================================================================
734 void XCAFDoc_DimTolTool::SetDatum(const TDF_LabelSequence& theL,
735 const TDF_Label& theDatumL) const
737 if (!IsDatum(theDatumL))
742 Handle(XCAFDoc_GraphNode) aChGNode;
743 Handle(XCAFDoc_GraphNode) aFGNode;
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());
752 theDatumL.ForgetAttribute(XCAFDoc::DatumRefGUID());
755 if (!theDatumL.FindAttribute(XCAFDoc::DatumRefGUID(), aChGNode)) {
756 aChGNode = new XCAFDoc_GraphNode;
757 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
758 aChGNode->SetGraphID(XCAFDoc::DatumRefGUID());
760 for (Standard_Integer i = theL.Lower(); i <= theL.Upper(); i++)
762 if (!theL.Value(i).FindAttribute(XCAFDoc::DatumRefGUID(), aFGNode)) {
763 aFGNode = new XCAFDoc_GraphNode;
764 aFGNode = XCAFDoc_GraphNode::Set(theL.Value(i));
766 aFGNode->SetGraphID(XCAFDoc::DatumRefGUID());
767 aFGNode->SetChild(aChGNode);
768 aChGNode->SetFather(aFGNode);
772 //=======================================================================
773 //function : SetDatum
775 //=======================================================================
777 void 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
784 if(!FindDatum(aName,aDescription,anIdentification,DatumL))
785 DatumL = AddDatum(aName,aDescription,anIdentification);
786 TDF_LabelSequence aLabels;
788 SetDatum(aLabels,DatumL);
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);
796 if (! DatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), ChGNode) ) {
797 ChGNode = new XCAFDoc_GraphNode;
798 ChGNode = XCAFDoc_GraphNode::Set(DatumL);
800 FGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
801 ChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
802 FGNode->SetChild(ChGNode);
803 ChGNode->SetFather(FGNode);
806 //=======================================================================
807 //function : SetDatumToGeomTol
809 //=======================================================================
811 void XCAFDoc_DimTolTool::SetDatumToGeomTol(const TDF_Label& theDatumL,
812 const TDF_Label& theTolerL) const
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);
821 if (! theDatumL.FindAttribute( XCAFDoc::DatumTolRefGUID(), aChGNode) ) {
822 aChGNode = new XCAFDoc_GraphNode;
823 aChGNode = XCAFDoc_GraphNode::Set(theDatumL);
825 aFGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
826 aChGNode->SetGraphID( XCAFDoc::DatumTolRefGUID() );
827 aFGNode->SetChild(aChGNode);
828 aChGNode->SetFather(aFGNode);
831 //=======================================================================
832 //function : GetDatum
834 //=======================================================================
836 Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL,
837 Handle(TCollection_HAsciiString)& theName,
838 Handle(TCollection_HAsciiString)& theDescription,
839 Handle(TCollection_HAsciiString)& theIdentification) const
841 Handle(XCAFDoc_Datum) aDatumAttr;
842 if( theDatumL.IsNull() ||
843 !theDatumL.FindAttribute(XCAFDoc_Datum::GetID(),aDatumAttr) )
844 return Standard_False;
846 theName = aDatumAttr->GetName();
847 theDescription = aDatumAttr->GetDescription();
848 theIdentification = aDatumAttr->GetIdentification();
849 return Standard_True;
852 //=======================================================================
853 //function : GetDatumTolerLabels
855 //=======================================================================
857 Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL,
858 TDF_LabelSequence& theDatums) const
860 Handle(XCAFDoc_GraphNode) aNode;
861 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
862 return Standard_False;
864 for(Standard_Integer i=1; i<=aNode->NbChildren(); i++) {
865 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetChild(i);
866 theDatums.Append(aDatumNode->Label());
868 return Standard_True;
871 //=======================================================================
872 //function : GetDatumWthObjectsTolerLabels
874 //=======================================================================
876 Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL,
877 TDF_LabelSequence& theDatums) const
879 Handle(XCAFDoc_GraphNode) aNode;
880 if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
881 return Standard_False;
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))
890 Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject();
891 if (aDatumObj.IsNull())
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
898 theDatums.Append(aDatumNode->Label());
900 return Standard_True;
903 //=======================================================================
904 //function : GetTolerDatumLabels
906 //=======================================================================
908 Standard_Boolean XCAFDoc_DimTolTool::GetTolerOfDatumLabels(const TDF_Label& theDatumL,
909 TDF_LabelSequence& theTols) const
911 Handle(XCAFDoc_GraphNode) aNode;
912 if( !theDatumL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) )
913 return Standard_False;
914 for(Standard_Integer i=1; i<=aNode->NbFathers(); i++) {
915 Handle(XCAFDoc_GraphNode) aDatumNode = aNode->GetFather(i);
916 theTols.Append(aDatumNode->Label());
918 return Standard_True;
921 //=======================================================================
922 //function : IsLocked
924 //=======================================================================
926 Standard_Boolean XCAFDoc_DimTolTool::IsLocked(const TDF_Label& theViewL) const
928 Handle(TDataStd_UAttribute) anAttr;
929 return theViewL.FindAttribute(XCAFDoc::LockGUID(), anAttr);
932 //=======================================================================
935 //=======================================================================
937 void XCAFDoc_DimTolTool::Lock(const TDF_Label& theViewL) const
939 TDataStd_UAttribute::Set(theViewL, XCAFDoc::LockGUID());
942 //=======================================================================
945 //=======================================================================
947 void XCAFDoc_DimTolTool::Unlock(const TDF_Label& theViewL) const
949 theViewL.ForgetAttribute(XCAFDoc::LockGUID());
952 //=======================================================================
955 //=======================================================================
957 const Standard_GUID& XCAFDoc_DimTolTool::ID() const
963 //=======================================================================
964 //function : GetGDTPresentations
966 //=======================================================================
967 void XCAFDoc_DimTolTool::GetGDTPresentations(NCollection_IndexedDataMap<TDF_Label,
968 TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToShape) const
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))
977 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject();
978 if (anObject.IsNull())
980 TopoDS_Shape aShape = anObject->GetPresentation();
981 if (!aShape.IsNull())
982 theGDTLabelToShape.Add(aCL, aShape);
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))
992 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject();
993 if (anObject.IsNull())
995 TopoDS_Shape aShape = anObject->GetPresentation();
996 if (!aShape.IsNull())
997 theGDTLabelToShape.Add(aCL, aShape);
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))
1007 Handle(XCAFDimTolObjects_DatumObject) anObject = aGTAttr->GetObject();
1008 if (anObject.IsNull())
1010 TopoDS_Shape aShape = anObject->GetPresentation();
1011 if (!aShape.IsNull())
1012 theGDTLabelToShape.Add(aCL, aShape);
1016 //=======================================================================
1017 //function : SetGDTPresentations
1019 //=======================================================================
1020 void XCAFDoc_DimTolTool::SetGDTPresentations(NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape, TDF_LabelMapHasher>& theGDTLabelToPrs)
1022 for (Standard_Integer i = 1; i <= theGDTLabelToPrs.Extent(); i++)
1024 const TDF_Label& aCL = theGDTLabelToPrs.FindKey(i);
1025 Handle(XCAFDoc_Dimension) aDimAttrDim;
1026 if (aCL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttrDim))
1028 Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttrDim->GetObject();
1029 if (anObject.IsNull())
1031 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1032 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1033 aDimAttrDim->SetObject(anObject);
1036 Handle(XCAFDoc_GeomTolerance) aDimAttrG;
1037 if (aCL.FindAttribute(XCAFDoc_GeomTolerance::GetID(),aDimAttrG))
1039 Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aDimAttrG->GetObject();
1040 if (anObject.IsNull())
1042 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1043 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1044 aDimAttrG->SetObject(anObject);
1047 Handle(XCAFDoc_Datum) aDimAttrD;
1048 if (aCL.FindAttribute(XCAFDoc_Datum::GetID(),aDimAttrD))
1050 Handle(XCAFDimTolObjects_DatumObject) anObject = aDimAttrD->GetObject();
1051 if (anObject.IsNull())
1053 const TopoDS_Shape& aPrs = theGDTLabelToPrs.FindFromIndex(i);
1054 anObject->SetPresentation(aPrs, anObject->GetPresentationName());
1055 aDimAttrD->SetObject(anObject);
1061 //=======================================================================
1062 //function : DumpJson
1064 //=======================================================================
1065 void XCAFDoc_DimTolTool::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
1067 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
1069 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
1071 TDF_LabelSequence aLabels;
1072 GetDimensionLabels (aLabels);
1073 for (TDF_LabelSequence::Iterator aDimLabelIt (aLabels); aDimLabelIt.More(); aDimLabelIt.Next())
1075 TCollection_AsciiString aDimensionLabel;
1076 TDF_Tool::Entry (aDimLabelIt.Value(), aDimensionLabel);
1077 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDimensionLabel)
1081 GetGeomToleranceLabels (aLabels);
1082 for (TDF_LabelSequence::Iterator aGeomToleranceLabelIt (aLabels); aGeomToleranceLabelIt.More(); aGeomToleranceLabelIt.Next())
1084 TCollection_AsciiString aGeomToleranceLabel;
1085 TDF_Tool::Entry (aGeomToleranceLabelIt.Value(), aGeomToleranceLabel);
1086 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aGeomToleranceLabel)
1090 GetDimTolLabels (aLabels);
1091 for (TDF_LabelSequence::Iterator aDimTolLabelIt (aLabels); aDimTolLabelIt.More(); aDimTolLabelIt.Next())
1093 TCollection_AsciiString aDimTolLabelLabel;
1094 TDF_Tool::Entry (aDimTolLabelIt.Value(), aDimTolLabelLabel);
1095 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDimTolLabelLabel)
1099 GetDatumLabels (aLabels);
1100 for (TDF_LabelSequence::Iterator aDatumLabelIt (aLabels); aDatumLabelIt.More(); aDatumLabelIt.Next())
1102 TCollection_AsciiString aDatumLabel;
1103 TDF_Tool::Entry (aDatumLabelIt.Value(), aDatumLabel);
1104 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aDatumLabel)