1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <TColStd_HSequenceOfExtendedString.hxx>
19 #include <TDF_AttributeSequence.hxx>
20 #include <TDF_Label.hxx>
21 #include <TDF_LabelSequence.hxx>
22 #include <TopLoc_IndexedMapOfLocation.hxx>
23 #include <TopLoc_Location.hxx>
25 #include <TopoDS_Compound.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopTools_SequenceOfShape.hxx>
28 #include <XCAFDoc_ColorTool.hxx>
29 #include <XCAFDoc_DocumentTool.hxx>
30 #include <XCAFDoc_GraphNode.hxx>
31 #include <XCAFDoc_LayerTool.hxx>
32 #include <XCAFDoc_ShapeTool.hxx>
33 #include <XCAFPrs.hxx>
34 #include <XCAFPrs_Style.hxx>
36 static Standard_Boolean viewnameMode = Standard_False;
38 static Standard_Boolean getShapesOfSHUO (TopLoc_IndexedMapOfLocation& theaPrevLocMap,
39 const Handle(XCAFDoc_ShapeTool)& theSTool,
40 const TDF_Label& theSHUOlab,
41 TopTools_SequenceOfShape& theSHUOShapeSeq)
43 Handle(XCAFDoc_GraphNode) SHUO;
44 TDF_LabelSequence aLabSeq;
45 theSTool->GetSHUONextUsage( theSHUOlab, aLabSeq );
46 if (aLabSeq.Length() >= 1)
47 for (Standard_Integer i = 1; i <= aLabSeq.Length(); i++) {
48 TDF_Label aSubCompL = aLabSeq.Value( i );
49 TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( aSubCompL.Father() );
50 // create new map of laocation (to not merge locations from different shapes)
51 TopLoc_IndexedMapOfLocation aNewPrevLocMap;
52 for (Standard_Integer m = 1; m <= theaPrevLocMap.Extent(); m++)
53 aNewPrevLocMap.Add( theaPrevLocMap.FindKey( m ) );
54 aNewPrevLocMap.Add( compLoc );
55 // got for the new sublocations and corresponding shape
56 getShapesOfSHUO( aNewPrevLocMap, theSTool, aSubCompL, theSHUOShapeSeq );
59 TopoDS_Shape aSHUO_NUSh = theSTool->GetShape ( theSHUOlab.Father() );
60 if ( aSHUO_NUSh.IsNull() ) return Standard_False;
61 // cause got shape with location already.
62 TopLoc_Location nullLoc;
63 aSHUO_NUSh.Location ( nullLoc );
64 // multiply the locations
65 Standard_Integer intMapLenght = theaPrevLocMap.Extent();
66 if ( intMapLenght < 1 )
67 return Standard_False; // should not be, but to avoid exception...?
68 TopLoc_Location SupcompLoc;
69 SupcompLoc = theaPrevLocMap.FindKey( intMapLenght );
70 if (intMapLenght > 1) {
71 Standard_Integer l = intMapLenght - 1;
73 SupcompLoc = theaPrevLocMap.FindKey( l ).Multiplied( SupcompLoc );
77 aSHUO_NUSh.Location( SupcompLoc );
78 theSHUOShapeSeq.Append( aSHUO_NUSh );
80 return (theSHUOShapeSeq.Length() > 0);
83 //=======================================================================
84 //function : CollectStyleSettings
86 //=======================================================================
88 void XCAFPrs::CollectStyleSettings (const TDF_Label& theLabel,
89 const TopLoc_Location& theLoc,
90 XCAFPrs_DataMapOfShapeStyle& theSettings)
92 // for references, first collect colors of referred shape
95 if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aLabelRef))
97 TopLoc_Location aLocSub = theLoc.Multiplied (XCAFDoc_ShapeTool::GetLocation (theLabel));
98 CollectStyleSettings (aLabelRef, aLocSub, theSettings);
102 // for assemblies, first collect colors defined in components
104 TDF_LabelSequence aComponentLabSeq;
105 if (XCAFDoc_ShapeTool::GetComponents (theLabel, aComponentLabSeq)
106 && !aComponentLabSeq.IsEmpty())
108 for (TDF_LabelSequence::Iterator aComponentIter (aComponentLabSeq); aComponentIter.More(); aComponentIter.Next())
110 const TDF_Label& aComponentLab = aComponentIter.Value();
111 CollectStyleSettings (aComponentLab, theLoc, theSettings);
116 // collect settings on subshapes
117 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(theLabel);
118 TDF_LabelSequence aLabSeq;
119 XCAFDoc_ShapeTool::GetSubShapes (theLabel, aLabSeq);
120 // and add the shape itself
121 aLabSeq.Append (theLabel);
122 for (TDF_LabelSequence::Iterator aLabIter (aLabSeq); aLabIter.More(); aLabIter.Next())
124 const TDF_Label& aLabel = aLabIter.Value();
125 XCAFPrs_Style aStyle;
127 Standard_Boolean isVisible = aColorTool->IsVisible (aLabel);
130 Handle(XCAFDoc_LayerTool) aLayerTool = XCAFDoc_DocumentTool::LayerTool (aLabel);
131 Handle(TColStd_HSequenceOfExtendedString) aLayerNames = new TColStd_HSequenceOfExtendedString();
132 aLayerTool->GetLayers (aLabel, aLayerNames);
133 Standard_Integer aNbHidden = 0;
134 for (TColStd_HSequenceOfExtendedString::Iterator aLayerIter (*aLayerNames); aLayerIter.More(); aLayerIter.Next())
136 const TCollection_ExtendedString& aLayerName = aLayerIter.Value();
137 if (!aLayerTool->IsVisible (aLayerTool->FindLayer (aLayerName)))
142 isVisible = aNbHidden == 0
143 || aNbHidden != aLayerNames->Length();
148 aStyle.SetVisibility (Standard_False);
152 Quantity_Color aColor;
153 if (aColorTool->GetColor (aLabel, XCAFDoc_ColorGen, aColor))
155 aStyle.SetColorCurv (aColor);
156 aStyle.SetColorSurf (aColor);
158 if (aColorTool->GetColor (aLabel, XCAFDoc_ColorSurf, aColor))
160 aStyle.SetColorSurf (aColor);
162 if (aColorTool->GetColor (aLabel, XCAFDoc_ColorCurv, aColor))
164 aStyle.SetColorCurv (aColor);
168 // PTV try to set color from SHUO structure
169 Handle(XCAFDoc_ShapeTool) aShapeTool = aColorTool->ShapeTool();
170 if (aShapeTool->IsComponent (aLabel))
172 TDF_AttributeSequence aShuoAttribSeq;
173 aShapeTool->GetAllComponentSHUO (aLabel, aShuoAttribSeq);
174 for (TDF_AttributeSequence::Iterator aShuoAttribIter (aShuoAttribSeq); aShuoAttribIter.More(); aShuoAttribIter.Next())
176 Handle(XCAFDoc_GraphNode) aShuoNode = Handle(XCAFDoc_GraphNode)::DownCast (aShuoAttribIter.Value());
177 if (aShuoNode.IsNull())
182 const TDF_Label aShuolab = aShuoNode->Label();
184 TDF_LabelSequence aShuoLabSeq;
185 aShapeTool->GetSHUONextUsage (aShuolab, aShuoLabSeq);
186 if (aShuoLabSeq.IsEmpty())
192 Quantity_Color aColor;
193 XCAFPrs_Style aShuoStyle;
194 if (!aColorTool->IsVisible (aShuolab))
196 aShuoStyle.SetVisibility (Standard_False);
200 if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorGen, aColor))
202 aShuoStyle.SetColorCurv (aColor);
203 aShuoStyle.SetColorSurf (aColor);
205 if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorSurf, aColor))
207 aShuoStyle.SetColorSurf (aColor);
209 if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorCurv, aColor))
211 aShuoStyle.SetColorCurv (aColor);
214 if (!aShuoStyle.IsSetColorCurv()
215 && !aShuoStyle.IsSetColorSurf()
216 && aShuoStyle.IsVisible())
221 // set style for all component from Next Usage Occurrence.
223 cout << "Set the style for SHUO next_usage-occurrance" << endl;
226 // may be work, but static it returns excess shapes. It is more faster to use OLD version.
227 // PTV 14.02.2003 NEW version using API of ShapeTool
228 TopTools_SequenceOfShape aShuoShapeSeq;
229 aShapeTool->GetAllStyledComponents (aShuoNode, aShuoShapeSeq);
230 for (TopTools_SequenceOfShape::Iterator aShuoShapeIter (aShuoShapeSeq); aShuoShapeIter.More(); aShuoShapeIter.Next())
232 const TopoDS_Shape& aShuoShape = aShuoShapeIter.Value();
233 if (!aShuoShape.IsNull())
234 theSettings.Bind (aShuoShape, aShuoStyle);
236 // OLD version that was written before ShapeTool API, and it FASTER for presentation
237 // get TOP location of SHUO component
238 TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation (aLabel);
239 TopLoc_IndexedMapOfLocation aPrevLocMap;
240 // get previous set location
241 if (!theLoc.IsIdentity())
243 aPrevLocMap.Add (theLoc);
245 aPrevLocMap.Add (compLoc);
247 // get shapes of SHUO Next_Usage components
248 TopTools_SequenceOfShape aShuoShapeSeq;
249 getShapesOfSHUO (aPrevLocMap, aShapeTool, aShuolab, aShuoShapeSeq);
250 for (TopTools_SequenceOfShape::Iterator aShuoShapeIter (aShuoShapeSeq); aShuoShapeIter.More(); aShuoShapeIter.Next())
252 const TopoDS_Shape& aShuoShape = aShuoShapeIter.Value();
253 theSettings.Bind (aShuoShape, aShuoStyle);
259 if (!aStyle.IsSetColorCurv()
260 && !aStyle.IsSetColorSurf()
261 && aStyle.IsVisible())
266 TopoDS_Shape aSubshape = XCAFDoc_ShapeTool::GetShape (aLabel);
267 if (aSubshape.ShapeType() == TopAbs_COMPOUND)
269 const TopoDS_Iterator aShapeIter (aSubshape);
270 if (!aShapeIter.More())
275 aSubshape.Move (theLoc);
276 theSettings.Bind (aSubshape, aStyle);
280 //=======================================================================
281 //function : SetViewNameMode
283 //=======================================================================
285 void XCAFPrs::SetViewNameMode(const Standard_Boolean aNameMode )
287 viewnameMode = aNameMode;
290 //=======================================================================
291 //function : GetViewNameMode
293 //=======================================================================
295 Standard_Boolean XCAFPrs::GetViewNameMode()