0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / XCAFDoc / XCAFDoc_ColorTool.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
bc73b006 14#include <XCAFDoc_ColorTool.hxx>
7fd59977 15
42cf5bc1 16#include <Quantity_Color.hxx>
bc73b006 17#include <Standard_Dump.hxx>
42cf5bc1 18#include <Standard_GUID.hxx>
19#include <Standard_Type.hxx>
7fd59977 20#include <TDataStd_Name.hxx>
42cf5bc1 21#include <TDataStd_TreeNode.hxx>
22#include <TDataStd_UAttribute.hxx>
23#include <TDF_Attribute.hxx>
24#include <TDF_ChildIDIterator.hxx>
25#include <TDF_Label.hxx>
26#include <TDF_RelocationTable.hxx>
7fd59977 27#include <TNaming_NamedShape.hxx>
42cf5bc1 28#include <TopoDS_Shape.hxx>
29#include <XCAFDoc.hxx>
7fd59977 30#include <XCAFDoc_Color.hxx>
42cf5bc1 31#include <XCAFDoc_DocumentTool.hxx>
7fd59977 32#include <XCAFDoc_GraphNode.hxx>
42cf5bc1 33#include <XCAFDoc_ShapeTool.hxx>
7fd59977 34
92efcf78 35IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_ColorTool,TDF_Attribute)
36
a4815d55 37static Standard_Boolean XCAFDoc_ColorTool_AutoNaming = Standard_True;
38
39//=======================================================================
40//function : SetAutoNaming
41//purpose :
42//=======================================================================
43void XCAFDoc_ColorTool::SetAutoNaming (Standard_Boolean theIsAutoNaming)
44{
45 XCAFDoc_ColorTool_AutoNaming = theIsAutoNaming;
46}
47
48//=======================================================================
49//function : AutoNaming
50//purpose :
51//=======================================================================
52Standard_Boolean XCAFDoc_ColorTool::AutoNaming()
53{
54 return XCAFDoc_ColorTool_AutoNaming;
55}
7fd59977 56
57//=======================================================================
58//function : BaseLabel
59//purpose :
60//=======================================================================
61
62TDF_Label XCAFDoc_ColorTool::BaseLabel() const
63{
64 return Label();
65}
66//=======================================================================
67//function : ShapeTool
68//purpose :
69//=======================================================================
70
71const Handle(XCAFDoc_ShapeTool)& XCAFDoc_ColorTool::ShapeTool()
72{
73 if (myShapeTool.IsNull())
74 myShapeTool = XCAFDoc_DocumentTool::ShapeTool(Label());
75 return myShapeTool;
76}
77
78
79//=======================================================================
80//function : IsColor
81//purpose :
82//=======================================================================
83
84Standard_Boolean XCAFDoc_ColorTool::IsColor (const TDF_Label& lab) const
85{
86 Quantity_Color C;
87 return GetColor ( lab, C );
88}
89
90//=======================================================================
91//function : GetColor
92//purpose :
93//=======================================================================
94
95Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& lab,
96 Quantity_Color& col) const
97{
973d410e 98 Quantity_ColorRGBA aCol;
99 Standard_Boolean isDone = GetColor(lab, aCol);
100 if (isDone)
101 col = aCol.GetRGB();
102 return isDone;
103}
104
105//=======================================================================
106//function : GetColor
107//purpose :
108//=======================================================================
109
110Standard_Boolean XCAFDoc_ColorTool::GetColor(const TDF_Label& lab,
111 Quantity_ColorRGBA& col) const
112{
113 if (lab.Father() != Label()) return Standard_False;
114
7fd59977 115 Handle(XCAFDoc_Color) ColorAttribute;
973d410e 116 if (!lab.FindAttribute(XCAFDoc_Color::GetID(), ColorAttribute))
7fd59977 117 return Standard_False;
973d410e 118
119 col = ColorAttribute->GetColorRGBA();
120
7fd59977 121 return Standard_True;
122}
123
124//=======================================================================
125//function : FindColor
126//purpose :
127//=======================================================================
128
129Standard_Boolean XCAFDoc_ColorTool::FindColor (const Quantity_Color& col, TDF_Label& lab) const
130{
973d410e 131 Quantity_ColorRGBA aCol;
132 aCol.SetRGB(col);
133 return FindColor(aCol, lab);
134}
135
136//=======================================================================
137//function : FindColor
138//purpose :
139//=======================================================================
140
141Standard_Boolean XCAFDoc_ColorTool::FindColor(const Quantity_ColorRGBA& col, TDF_Label& lab) const
142{
143 TDF_ChildIDIterator it(Label(), XCAFDoc_Color::GetID());
7fd59977 144 for (; it.More(); it.Next()) {
145 TDF_Label aLabel = it.Value()->Label();
973d410e 146 Quantity_ColorRGBA C;
147 if (!GetColor(aLabel, C)) continue;
148 if (C.IsEqual(col)) {
7fd59977 149 lab = aLabel;
150 return Standard_True;
151 }
152 }
153 return Standard_False;
154}
155
156//=======================================================================
157//function : FindColor
158//purpose :
159//=======================================================================
160
973d410e 161TDF_Label XCAFDoc_ColorTool::FindColor (const Quantity_ColorRGBA& col) const
7fd59977 162{
163 TDF_Label L;
164 FindColor ( col, L );
165 return L;
166}
167
973d410e 168//=======================================================================
169//function : FindColor
170//purpose :
171//=======================================================================
172
173TDF_Label XCAFDoc_ColorTool::FindColor(const Quantity_Color& col) const
174{
175 TDF_Label L;
176 FindColor(col, L);
177 return L;
178}
179
7fd59977 180//=======================================================================
181//function : AddColor
182//purpose :
183//=======================================================================
184
185TDF_Label XCAFDoc_ColorTool::AddColor (const Quantity_Color& col) const
973d410e 186{
187 Quantity_ColorRGBA aCol;
188 aCol.SetRGB(col);
189 return AddColor(aCol);
190}
191
192//=======================================================================
193//function : AddColor
194//purpose :
195//=======================================================================
196
a4815d55 197TDF_Label XCAFDoc_ColorTool::AddColor (const Quantity_ColorRGBA& theColor) const
7fd59977 198{
a4815d55 199 TDF_Label aLab;
200 if (FindColor (theColor, aLab))
201 {
202 return aLab;
203 }
7fd59977 204
205 // create a new color entry
7fd59977 206 TDF_TagSource aTag;
a4815d55 207 aLab = aTag.NewChild (Label());
208 XCAFDoc_Color::Set (aLab, theColor);
209
210 if (XCAFDoc_ColorTool_AutoNaming)
211 {
212 // set name according to color value
213 const NCollection_Vec4<float>& anRgbaF = theColor;
214 const NCollection_Vec4<unsigned int> anRgba (anRgbaF * 255.0f);
215 char aColorHex[32];
216 Sprintf (aColorHex, "%02X%02X%02X%02X", anRgba.r(), anRgba.g(), anRgba.b(), anRgba.a());
217 const TCollection_AsciiString aName = TCollection_AsciiString (Quantity_Color::StringName (theColor.GetRGB().Name()))
218 + " (#" + aColorHex + ")";
219 TDataStd_Name::Set (aLab, aName);
220 }
973d410e 221
a4815d55 222 return aLab;
7fd59977 223}
224
225//=======================================================================
226//function : RemoveColor
227//purpose :
228//=======================================================================
229
230void XCAFDoc_ColorTool::RemoveColor (const TDF_Label& lab) const
231{
232 lab.ForgetAllAttributes (Standard_True);
233}
234
235//=======================================================================
236//function : GetColors
237//purpose :
238//=======================================================================
239
240void XCAFDoc_ColorTool::GetColors (TDF_LabelSequence& Labels) const
241{
242 Labels.Clear();
243
244 TDF_ChildIDIterator ChildIDIterator(Label(),XCAFDoc_Color::GetID());
245 for (; ChildIDIterator.More(); ChildIDIterator.Next()) {
246 TDF_Label L = ChildIDIterator.Value()->Label();
247 if ( IsColor ( L ) ) Labels.Append ( L );
248 }
249}
250
251//=======================================================================
252//function : SetColor
253//purpose :
254//=======================================================================
255
256void XCAFDoc_ColorTool::SetColor (const TDF_Label& L,
257 const TDF_Label& colorL,
258 const XCAFDoc_ColorType type) const
259{
260 // set reference
261 Handle(TDataStd_TreeNode) refNode, mainNode;
262 mainNode = TDataStd_TreeNode::Set ( colorL, XCAFDoc::ColorRefGUID(type) );
263 refNode = TDataStd_TreeNode::Set ( L, XCAFDoc::ColorRefGUID(type) );
264 refNode->Remove(); // abv: fix against bug in TreeNode::Append()
265 mainNode->Prepend(refNode);
266}
267
268//=======================================================================
269//function : SetColor
270//purpose :
271//=======================================================================
272
273void XCAFDoc_ColorTool::SetColor (const TDF_Label& L,
274 const Quantity_Color& Color,
275 const XCAFDoc_ColorType type) const
276{
277 TDF_Label colorL = AddColor ( Color );
278 SetColor ( L, colorL, type );
279}
280
973d410e 281//=======================================================================
282//function : SetColor
283//purpose :
284//=======================================================================
285
286void XCAFDoc_ColorTool::SetColor(const TDF_Label& L,
287 const Quantity_ColorRGBA& Color,
288 const XCAFDoc_ColorType type) const
289{
290 TDF_Label colorL = AddColor(Color);
291 SetColor(L, colorL, type);
292}
293
7fd59977 294//=======================================================================
295//function : UnSetColor
296//purpose :
297//=======================================================================
298
299void XCAFDoc_ColorTool::UnSetColor (const TDF_Label& L, const XCAFDoc_ColorType type) const
300{
301 L.ForgetAttribute ( XCAFDoc::ColorRefGUID(type) );
302}
303
304//=======================================================================
305//function : IsSet
306//purpose :
307//=======================================================================
308
309Standard_Boolean XCAFDoc_ColorTool::IsSet (const TDF_Label& L, const XCAFDoc_ColorType type) const
310{
311 Handle(TDataStd_TreeNode) Node;
312 return L.FindAttribute ( XCAFDoc::ColorRefGUID(type), Node) && Node->HasFather();
313}
314
315//=======================================================================
316//function : GetColor
317//purpose :
318//=======================================================================
319
320Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& L,
321 const XCAFDoc_ColorType type,
322 TDF_Label& colorL)
323{
324 Handle(TDataStd_TreeNode) Node;
325 if ( ! L.FindAttribute ( XCAFDoc::ColorRefGUID(type), Node) ||
326 ! Node->HasFather() ) return Standard_False;
327 colorL = Node->Father()->Label();
328 return Standard_True;
329}
330
331//=======================================================================
332//function : GetColor
333//purpose :
334//=======================================================================
335
336Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& L,
337 const XCAFDoc_ColorType type,
338 Quantity_Color& color)
339{
340 TDF_Label colorL;
341 if ( ! GetColor ( L, type, colorL ) ) return Standard_False;
342 return GetColor ( colorL, color );
343}
344
973d410e 345//=======================================================================
346//function : GetColor
347//purpose :
348//=======================================================================
349
350Standard_Boolean XCAFDoc_ColorTool::GetColor(const TDF_Label& L,
351 const XCAFDoc_ColorType type,
352 Quantity_ColorRGBA& color)
353{
354 TDF_Label colorL;
355 if (!GetColor(L, type, colorL)) return Standard_False;
356 return GetColor(colorL, color);
357}
358
7fd59977 359//=======================================================================
360//function : SetColor
361//purpose :
362//=======================================================================
363
364Standard_Boolean XCAFDoc_ColorTool::SetColor (const TopoDS_Shape& S,
365 const TDF_Label& colorL,
366 const XCAFDoc_ColorType type)
367{
368 TDF_Label L;
369 if ( ! ShapeTool()->Search ( S, L ) ) return Standard_False;
370 SetColor ( L, colorL, type );
371 return Standard_True;
372}
373
374//=======================================================================
375//function : SetColor
376//purpose :
377//=======================================================================
378
379Standard_Boolean XCAFDoc_ColorTool::SetColor (const TopoDS_Shape& S,
380 const Quantity_Color& Color,
381 const XCAFDoc_ColorType type)
382{
383 TDF_Label colorL = AddColor ( Color );
384 return SetColor ( S, colorL, type );
385}
386
973d410e 387//=======================================================================
388//function : SetColor
389//purpose :
390//=======================================================================
391
392Standard_Boolean XCAFDoc_ColorTool::SetColor(const TopoDS_Shape& S,
393 const Quantity_ColorRGBA& Color,
394 const XCAFDoc_ColorType type)
395{
396 TDF_Label colorL = AddColor(Color);
397 return SetColor(S, colorL, type);
398}
399
7fd59977 400//=======================================================================
401//function : UnSetColor
402//purpose :
403//=======================================================================
404
405Standard_Boolean XCAFDoc_ColorTool::UnSetColor (const TopoDS_Shape& S,
406 const XCAFDoc_ColorType type)
407{
408 TDF_Label L;
409 if ( ! ShapeTool()->Search ( S, L ) ) return Standard_False;
410 UnSetColor ( L, type );
411 return Standard_True;
412}
413
414//=======================================================================
415//function : IsSet
416//purpose :
417//=======================================================================
418
419Standard_Boolean XCAFDoc_ColorTool::IsSet (const TopoDS_Shape& S,
420 const XCAFDoc_ColorType type)
421{
422 TDF_Label L;
423 if ( ! ShapeTool()->Search ( S, L ) ) return Standard_False;
424 return IsSet ( L, type );
425}
426
427//=======================================================================
428//function : GetColor
429//purpose :
430//=======================================================================
431
432Standard_Boolean XCAFDoc_ColorTool::GetColor (const TopoDS_Shape& S,
433 const XCAFDoc_ColorType type,
434 TDF_Label& colorL)
435{
436 TDF_Label L;
437 if ( ! ShapeTool()->Search ( S, L ) ) return Standard_False;
438 return GetColor ( L, type, colorL );
439}
440
441//=======================================================================
442//function : GetColor
443//purpose :
444//=======================================================================
445
446Standard_Boolean XCAFDoc_ColorTool::GetColor (const TopoDS_Shape& S,
447 const XCAFDoc_ColorType type,
448 Quantity_Color& color)
449{
450 TDF_Label colorL;
451 if ( ! GetColor ( S, type, colorL ) ) return Standard_False;
452 return GetColor ( colorL, color );
453}
454
973d410e 455//=======================================================================
456//function : GetColor
457//purpose :
458//=======================================================================
459
460Standard_Boolean XCAFDoc_ColorTool::GetColor(const TopoDS_Shape& S,
461 const XCAFDoc_ColorType type,
462 Quantity_ColorRGBA& color)
463{
464 TDF_Label colorL;
465 if (!GetColor(S, type, colorL)) return Standard_False;
466 return GetColor(colorL, color);
467}
468
7fd59977 469//=======================================================================
470//function : GetID
471//purpose :
472//=======================================================================
473
474const Standard_GUID& XCAFDoc_ColorTool::GetID()
475{
476 static Standard_GUID ColorTblID ("efd212ed-6dfd-11d4-b9c8-0060b0ee281b");
477 return ColorTblID;
478}
479
480//=======================================================================
481//function : Set
482//purpose :
483//=======================================================================
484
485Handle(XCAFDoc_ColorTool) XCAFDoc_ColorTool::Set(const TDF_Label& L)
486{
487 Handle(XCAFDoc_ColorTool) A;
488 if (!L.FindAttribute (XCAFDoc_ColorTool::GetID(), A)) {
489 A = new XCAFDoc_ColorTool ();
490 L.AddAttribute(A);
491 A->myShapeTool = XCAFDoc_DocumentTool::ShapeTool(L);
492 }
493 return A;
494}
495
496//=======================================================================
497//function : ID
498//purpose :
499//=======================================================================
500
501const Standard_GUID& XCAFDoc_ColorTool::ID() const
502{
503 return GetID();
504}
505
506//=======================================================================
507//function : Restore
508//purpose :
509//=======================================================================
510
511void XCAFDoc_ColorTool::Restore(const Handle(TDF_Attribute)& /*with*/)
512{
513}
514
515//=======================================================================
516//function : NewEmpty
517//purpose :
518//=======================================================================
519
520Handle(TDF_Attribute) XCAFDoc_ColorTool::NewEmpty() const
521{
522 return new XCAFDoc_ColorTool;
523}
524
525//=======================================================================
526//function : Paste
527//purpose :
528//=======================================================================
529
530void XCAFDoc_ColorTool::Paste (const Handle(TDF_Attribute)& /*into*/,
531 const Handle(TDF_RelocationTable)& /*RT*/) const
532{
533}
534
535/**/
536
537//=======================================================================
538//function : XCAFDoc_ColorTool
539//purpose :
540//=======================================================================
541
542XCAFDoc_ColorTool::XCAFDoc_ColorTool()
543{
544}
545
546// PTV 23.01.2003 add visibility flag for objects (CAX-IF TRJ11)
547//=======================================================================
548//function : IsVisible
549//purpose :
550//=======================================================================
551
552Standard_Boolean XCAFDoc_ColorTool::IsVisible (const TDF_Label& L) const
553{
554 Handle(TDataStd_UAttribute) aUAttr;
555 return (!L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr));
556}
557
558//=======================================================================
559//function : SetVisibility
560//purpose :
561//=======================================================================
562
563void XCAFDoc_ColorTool::SetVisibility (const TDF_Label& L,
564 const Standard_Boolean isvisible)
565{
566 Handle(TDataStd_UAttribute) aUAttr;
567 if (! isvisible ) {
568 Handle(XCAFDoc_GraphNode) aSHUO;
569 if (ShapeTool()->IsShape(L) || ShapeTool()->GetSHUO( L, aSHUO ) )
570 if (!L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr))
ad67e367 571 TDataStd_UAttribute::Set( L, XCAFDoc::InvisibleGUID() );
7fd59977 572 }
573 else L.ForgetAttribute( XCAFDoc::InvisibleGUID() );
574}
575
08b183fe 576//=======================================================================
577//function : IsColorByLayer
578//purpose :
579//=======================================================================
580
581Standard_Boolean XCAFDoc_ColorTool::IsColorByLayer (const TDF_Label& L) const
582{
583 Handle(TDataStd_UAttribute) aUAttr;
584 return L.FindAttribute(XCAFDoc::ColorByLayerGUID(), aUAttr);
585}
586
587//=======================================================================
588//function : SetColorByLayer
589//purpose :
590//=======================================================================
591
592void XCAFDoc_ColorTool::SetColorByLayer (const TDF_Label& L,
593 const Standard_Boolean isColorByLayer)
594{
595 Handle(TDataStd_UAttribute) aUAttr;
596 if ( isColorByLayer ) {
597 Handle(XCAFDoc_GraphNode) aSHUO;
598 if (ShapeTool()->IsShape(L) || ShapeTool()->GetSHUO( L, aSHUO ) )
599 if (!L.FindAttribute(XCAFDoc::ColorByLayerGUID(), aUAttr))
ad67e367 600 TDataStd_UAttribute::Set( L, XCAFDoc::ColorByLayerGUID() );
08b183fe 601 }
602 else L.ForgetAttribute( XCAFDoc::ColorByLayerGUID() );
603}
604
7fd59977 605//=======================================================================
606//function : SetInstanceColor
607//purpose :
608//=======================================================================
609
610Standard_Boolean XCAFDoc_ColorTool::SetInstanceColor (const TopoDS_Shape& theShape,
611 const XCAFDoc_ColorType type,
612 const Quantity_Color& color,
613 const Standard_Boolean IsCreateSHUO)
973d410e 614{
615 Quantity_ColorRGBA aCol;
616 aCol.SetRGB(color);
617 return SetInstanceColor(theShape, type, aCol, IsCreateSHUO);
618}
619
620//=======================================================================
621//function : SetInstanceColor
622//purpose :
623//=======================================================================
624
625Standard_Boolean XCAFDoc_ColorTool::SetInstanceColor(const TopoDS_Shape& theShape,
626 const XCAFDoc_ColorType type,
627 const Quantity_ColorRGBA& color,
628 const Standard_Boolean IsCreateSHUO)
7fd59977 629{
630 // find shuo label structure
631 TDF_LabelSequence aLabels;
973d410e 632 if (!ShapeTool()->FindComponent(theShape, aLabels))
7fd59977 633 return Standard_False;
634 Handle(XCAFDoc_GraphNode) aSHUO;
635 // set the SHUO structure for this component if it is not exist
973d410e 636 if (!ShapeTool()->FindSHUO(aLabels, aSHUO)) {
7fd59977 637 if (aLabels.Length() == 1) {
638 // set color directly for component as NAUO
639 SetColor(aLabels.Value(1), color, type);
640 return Standard_True;
641 }
973d410e 642 else if (!IsCreateSHUO || !ShapeTool()->SetSHUO(aLabels, aSHUO)) {
7fd59977 643 return Standard_False;
eafb234b 644 }
645 }
7fd59977 646 TDF_Label aSHUOLabel = aSHUO->Label();
973d410e 647 SetColor(aSHUOLabel, color, type);
7fd59977 648 return Standard_True;
649}
650
973d410e 651
7fd59977 652//=======================================================================
653//function : GetInstanceColor
654//purpose :
655//=======================================================================
656
657Standard_Boolean XCAFDoc_ColorTool::GetInstanceColor (const TopoDS_Shape& theShape,
658 const XCAFDoc_ColorType type,
659 Quantity_Color& color)
973d410e 660{
661 Quantity_ColorRGBA aCol;
662 Standard_Boolean isDone = GetInstanceColor(theShape, type, aCol);
663 if (isDone)
664 color = aCol.GetRGB();
665 return isDone;
666}
667
668//=======================================================================
669//function : GetInstanceColor
670//purpose :
671//=======================================================================
672
673Standard_Boolean XCAFDoc_ColorTool::GetInstanceColor(const TopoDS_Shape& theShape,
674 const XCAFDoc_ColorType type,
675 Quantity_ColorRGBA& color)
7fd59977 676{
677 // find shuo label structure
678 TDF_LabelSequence aLabels;
973d410e 679 if (!ShapeTool()->FindComponent(theShape, aLabels))
7fd59977 680 return Standard_False;
681 Handle(XCAFDoc_GraphNode) aSHUO;
682 // get shuo from document by label structure
683 TDF_Label aCompLab = aLabels.Value(aLabels.Length());
684 while (aLabels.Length() > 1) {
973d410e 685 if (!ShapeTool()->FindSHUO(aLabels, aSHUO)) {
7fd59977 686 // try to find other shuo
687 aLabels.Remove(aLabels.Length());
688 continue;
973d410e 689 }
690 else {
7fd59977 691 TDF_Label aSHUOLabel = aSHUO->Label();
973d410e 692 if (GetColor(aSHUOLabel, type, color))
7fd59977 693 return Standard_True;
973d410e 694 else
7fd59977 695 // try to find other shuo
696 aLabels.Remove(aLabels.Length());
697 }
698 }
699 // attempt to get color exactly of component
973d410e 700 if (GetColor(aCompLab, type, color))
7fd59977 701 return Standard_True;
973d410e 702
7fd59977 703 // attempt to get color of solid
704 TopLoc_Location aLoc;
705 TopoDS_Shape S0 = theShape;
973d410e 706 S0.Location(aLoc);
707 TDF_Label aRefLab = ShapeTool()->FindShape(S0);
7fd59977 708 if (!aRefLab.IsNull())
973d410e 709 return GetColor(aRefLab, type, color);
7fd59977 710 // no color assigned
711 return Standard_False;
712}
713
714//=======================================================================
715//function : IsInstanceVisible
716//purpose :
717//=======================================================================
718
719Standard_Boolean XCAFDoc_ColorTool::IsInstanceVisible (const TopoDS_Shape& theShape)
720{
721 // check visibility status of top-level solid, cause it is have highest priority
722 TopLoc_Location NullLoc;
723 TopoDS_Shape S0 = theShape;
724 S0.Location( NullLoc );
725 TDF_Label aRefL = ShapeTool()->FindShape( S0 );
726 if (!aRefL.IsNull() && !IsVisible(aRefL))
727 return Standard_False;
728 // find shuo label structure
729 TDF_LabelSequence aLabels;
730 if ( !ShapeTool()->FindComponent( theShape, aLabels ) )
731 return Standard_True;
732 TDF_Label aCompLab = aLabels.Value(aLabels.Length());
733 // visibility status of component withouts SHUO.
734 if (!IsVisible( aCompLab ))
735 return Standard_False;
736 // check by SHUO structure
737 TDF_LabelSequence aCurLabels;
738 aCurLabels.Append(aCompLab);
739 Standard_Integer i = aLabels.Length() - 1;
740 // while (aCurLabels.Length() < aLabels.Length()) {
741 while (i >= 1) {
742 aCurLabels.Prepend( aLabels.Value(i--) );
743 // get shuo from document by label structure
744 Handle(XCAFDoc_GraphNode) aSHUO;
745 if ( !ShapeTool()->FindSHUO( aCurLabels, aSHUO ) )
746 continue;
747 if ( !IsVisible(aSHUO->Label()) )
748 return Standard_False;
749 }
750 return Standard_True; //visible, cause cannot find invisibility status
751}
752
753
754//=======================================================================
755//function : ReverseTreeNodes
756//purpose : auxilary
757//=======================================================================
758static void ReverseTreeNodes(Handle(TDataStd_TreeNode)& mainNode)
759{
760 if(mainNode->HasFirst()) {
761 Handle(TDataStd_TreeNode) tmpNode;
762 Handle(TDataStd_TreeNode) pNode = mainNode->First();
763 Handle(TDataStd_TreeNode) nNode = pNode->Next();
764 while(!nNode.IsNull()) {
765 tmpNode = pNode->Previous();
766 pNode->SetPrevious(nNode);
767 pNode->SetNext(tmpNode);
768 pNode = nNode;
769 nNode = pNode->Next();
770 }
771 tmpNode = pNode->Previous();
772 pNode->SetPrevious(nNode);
773 pNode->SetNext(tmpNode);
774 mainNode->SetFirst(pNode);
775 }
776}
777
778
779//=======================================================================
780//function : ReverseChainsOfTreeNodes
781//purpose :
782//=======================================================================
783
784Standard_Boolean XCAFDoc_ColorTool::ReverseChainsOfTreeNodes()
785{
786 TDF_ChildIDIterator it(Label(),XCAFDoc_Color::GetID());
787 for (; it.More(); it.Next()) {
788 TDF_Label aLabel = it.Value()->Label();
789 Handle(TDataStd_TreeNode) mainNode;
790 if(aLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf),mainNode)) {
791 ReverseTreeNodes(mainNode);
792 }
793 if(aLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv),mainNode)) {
794 ReverseTreeNodes(mainNode);
795 }
796 if(aLabel.FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen),mainNode)) {
797 ReverseTreeNodes(mainNode);
798 }
799 }
800 return Standard_True;
801}
bc73b006 802
803//=======================================================================
804//function : DumpJson
805//purpose :
806//=======================================================================
807void XCAFDoc_ColorTool::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
808{
809 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
810
811 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
812
813 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myShapeTool.get())
814}