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 &L,
89 const TopLoc_Location &loc,
90 XCAFPrs_DataMapOfShapeStyle &settings)
92 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( L );
94 // for references, first collect colors of referred shape
96 if ( XCAFDoc_ShapeTool::GetReferredShape ( L, Lref ) ) {
97 TopLoc_Location locSub = loc.Multiplied ( XCAFDoc_ShapeTool::GetLocation ( L ) );
98 CollectStyleSettings ( Lref, locSub, settings );
101 // for assemblies, first collect colors defined in components
102 TDF_LabelSequence seq;
103 if ( XCAFDoc_ShapeTool::GetComponents ( L, seq ) && seq.Length() >0 ) {
104 for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) {
105 CollectStyleSettings ( seq.Value(i), loc, settings );
109 // collect settings on subshapes and the shape itself
111 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
113 for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) {
114 TDF_Label lab = seq.Value(i);
116 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( lab );
117 Handle(TColStd_HSequenceOfExtendedString) LayNames = new TColStd_HSequenceOfExtendedString;
119 LTool->GetLayers(lab, LayNames);
120 Standard_Integer InVisCount = 0;
121 for ( Standard_Integer iL = 1; iL <= LayNames->Length(); iL++) {
122 if ( !LTool->IsVisible( LTool->FindLayer(LayNames->Value(iL)) ) ) InVisCount++;
124 if ( (InVisCount >0 && InVisCount == LayNames->Length()) ||
125 !CTool->IsVisible(lab) ) {
126 style.SetVisibility(Standard_False);
130 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
131 style.SetColorCurv ( C );
132 style.SetColorSurf ( C );
134 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
135 style.SetColorSurf ( C );
136 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
137 style.SetColorCurv ( C );
139 // PTV try to set color from SHUO structure
140 Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
141 Handle(XCAFDoc_GraphNode) SHUO;
142 TDF_AttributeSequence theSHUOAttrs;
143 if (STool->IsComponent( lab ) ) {
144 STool->GetAllComponentSHUO( lab, theSHUOAttrs );
145 for (Standard_Integer shuoIndx = 1; shuoIndx <= theSHUOAttrs.Length(); shuoIndx++) {
146 SHUO = Handle(XCAFDoc_GraphNode)::DownCast(theSHUOAttrs.Value(shuoIndx));
149 TDF_Label aSHUOlab = SHUO->Label();
151 TDF_LabelSequence aLabSeq;
152 STool->GetSHUONextUsage( aSHUOlab, aLabSeq );
153 if (aLabSeq.Length() < 1 )
157 XCAFPrs_Style SHUOstyle;
158 if (!CTool->IsVisible( aSHUOlab ) )
159 SHUOstyle.SetVisibility(Standard_False);
161 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
162 SHUOstyle.SetColorCurv ( C );
163 SHUOstyle.SetColorSurf ( C );
165 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
166 SHUOstyle.SetColorSurf ( C );
167 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
168 SHUOstyle.SetColorCurv ( C );
170 if ( !SHUOstyle.IsSetColorCurv() &&
171 !SHUOstyle.IsSetColorSurf() &&
172 SHUOstyle.IsVisible() )
175 // set style for all component from Next Usage Occurrence.
177 cout << "Set the style for SHUO next_usage-occurrance" << endl;
180 // may be work, but static it returns excess shapes. It is more faster to use OLD version.
181 // PTV 14.02.2003 NEW version using API of ShapeTool
182 TopTools_SequenceOfShape aSHUOShapeSeq;
183 STool->GetAllStyledComponents( SHUO, aSHUOShapeSeq );
184 for (Standard_Integer si= 1; si <= aSHUOShapeSeq.Length(); si++) {
185 TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value(si);
186 if (!aSHUOSh.IsNull())
187 settings.Bind ( aSHUOSh, SHUOstyle );
190 // OLD version that was written before ShapeTool API, and ti FASTER for presentation
191 // get TOP location of SHUO component
192 TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( lab );
193 TopLoc_IndexedMapOfLocation aPrevLocMap;
194 // get previous setted location
195 if ( !loc.IsIdentity() )
196 aPrevLocMap.Add( loc );
198 aPrevLocMap.Add( compLoc );
199 TopTools_SequenceOfShape aSHUOShapeSeq;
200 // get shapes of SHUO Next_Usage components
201 getShapesOfSHUO( aPrevLocMap, STool, aSHUOlab, aSHUOShapeSeq );
202 for (Standard_Integer n = 1; n <= aSHUOShapeSeq.Length(); n++ ) {
203 TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value( n );
204 settings.Bind ( aSHUOSh, SHUOstyle );
209 if ( !style.IsSetColorCurv() &&
210 !style.IsSetColorSurf() &&
213 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
215 settings.Bind ( sub, style );
219 //=======================================================================
220 //function : SetViewNameMode
222 //=======================================================================
224 void XCAFPrs::SetViewNameMode(const Standard_Boolean aNameMode )
226 viewnameMode = aNameMode;
229 //=======================================================================
230 //function : GetViewNameMode
232 //=======================================================================
234 Standard_Boolean XCAFPrs::GetViewNameMode()