1 // Created on: 2000-08-11
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.
16 #include <XCAFPrs_AISObject.hxx>
18 #include <AIS_DisplayMode.hxx>
19 #include <BRepBndLib.hxx>
21 #include <Graphic3d_AspectFillArea3d.hxx>
22 #include <Graphic3d_AspectLine3d.hxx>
23 #include <Handle_AIS_Drawer.hxx>
24 #include <Prs3d_DimensionAspect.hxx>
25 #include <Prs3d_IsoAspect.hxx>
26 #include <Prs3d_LineAspect.hxx>
27 #include <Prs3d_ShadingAspect.hxx>
28 #include <Prs3d_Text.hxx>
29 #include <TDataStd_Name.hxx>
30 #include <TDF_LabelSequence.hxx>
31 #include <TPrsStd_AISPresentation.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <XCAFDoc_ShapeTool.hxx>
34 #include <XCAFPrs.hxx>
35 #include <XCAFPrs_DataMapOfShapeStyle.hxx>
36 #include <XCAFPrs_DataMapIteratorOfDataMapOfShapeStyle.hxx>
37 #include <XCAFPrs_Style.hxx>
39 IMPLEMENT_STANDARD_HANDLE (XCAFPrs_AISObject, AIS_ColoredShape)
40 IMPLEMENT_STANDARD_RTTIEXT(XCAFPrs_AISObject, AIS_ColoredShape)
42 //=======================================================================
43 //function : XCAFPrs_AISObject
45 //=======================================================================
47 XCAFPrs_AISObject::XCAFPrs_AISObject (const TDF_Label& theLabel)
48 : AIS_ColoredShape(TopoDS_Shape())
53 //=======================================================================
54 //function : DisplayText
56 //=======================================================================
58 static void DisplayText (const TDF_Label& aLabel,
59 const Handle(Prs3d_Presentation)& aPrs,
60 const Handle(Prs3d_TextAspect)& anAspect,
61 const TopLoc_Location& aLocation)
64 Handle (TDataStd_Name) aName;
65 if (aLabel.FindAttribute (TDataStd_Name::GetID(), aName)) {
67 if (XCAFDoc_ShapeTool::GetShape (aLabel, aShape)) {
68 // find the position to display as middle of the bounding box
69 aShape.Move (aLocation);
71 BRepBndLib::Add (aShape, aBox);
72 if ( ! aBox.IsVoid() )
74 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
75 aBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
76 gp_Pnt aPnt (0.5 * (aXmin + aXmax), 0.5 * (aYmin + aYmax), 0.5 * (aZmin + aZmax));
77 Prs3d_Text::Draw( aPrs, anAspect, aName->Get(), aPnt);
82 TDF_LabelSequence seq;
84 // attibutes of subshapes
85 if (XCAFDoc_ShapeTool::GetSubShapes (aLabel, seq)) {
86 Standard_Integer i = 1;
87 for (i = 1; i <= seq.Length(); i++) {
88 TDF_Label aL = seq.Value (i);
89 DisplayText (aL, aPrs, anAspect, aLocation); //suppose that subshapes do not contain locations
93 // attibutes of components
95 if (XCAFDoc_ShapeTool::GetComponents (aLabel, seq)) {
96 Standard_Integer i = 1;
97 for (i = 1; i <= seq.Length(); i++) {
98 TDF_Label aL = seq.Value (i);
99 DisplayText (aL, aPrs, anAspect, aLocation);
102 // attributes of referrences
103 TopLoc_Location aLoc = XCAFDoc_ShapeTool::GetLocation (aL);
104 if (XCAFDoc_ShapeTool::GetReferredShape (aL, aRefLabel)) {
105 DisplayText (aRefLabel, aPrs, anAspect, aLoc);
111 //=======================================================================
114 //=======================================================================
115 void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
116 const Handle(Prs3d_Presentation)& thePrs,
117 const Standard_Integer theMode)
121 // abv: 06 Mar 00: to have good colors
122 Handle(TPrsStd_AISPresentation) aPrs = Handle(TPrsStd_AISPresentation)::DownCast (GetOwner());
123 if (aPrs.IsNull() || !aPrs->HasOwnMaterial()) SetMaterial (Graphic3d_NOM_PLASTIC);
126 if (!XCAFDoc_ShapeTool::GetShape (myLabel, aShape) || aShape.IsNull()) return;
128 // Shape vide -> Assemblage vide.
129 if (aShape.ShapeType() == TopAbs_COMPOUND)
131 TopoDS_Iterator anExplor (aShape);
132 if (!anExplor.More())
139 ClearCustomAspects();
141 // Collecting information on colored subshapes
142 TopLoc_Location aLoc;
143 XCAFPrs_DataMapOfShapeStyle aSettings;
144 XCAFPrs::CollectStyleSettings ( myLabel, aLoc, aSettings );
146 // Getting default colors
147 XCAFPrs_Style aDefStyle;
148 DefaultStyle (aDefStyle);
149 Quantity_Color aColorCurv = aDefStyle.GetColorCurv();
150 Quantity_Color aColorSurf = aDefStyle.GetColorSurf();
152 SetColors (myDrawer, aColorCurv, aColorSurf);
154 // Set colors etc. for current shape according to style
155 for (XCAFPrs_DataMapIteratorOfDataMapOfShapeStyle anIter( aSettings ); anIter.More(); anIter.Next())
157 Handle(AIS_ColoredDrawer) aDrawer = CustomAspects (anIter.Key());
158 const XCAFPrs_Style& aStyle = anIter.Value();
159 aDrawer->SetHidden (!aStyle.IsVisible());
161 aColorCurv = aStyle.IsSetColorCurv() ? aStyle.GetColorCurv() : aDefStyle.GetColorCurv();
162 aColorSurf = aStyle.IsSetColorSurf() ? aStyle.GetColorSurf() : aDefStyle.GetColorSurf();
164 SetColors (aDrawer, aColorCurv, aColorSurf);
167 AIS_ColoredShape::Compute (thePresentationManager, thePrs, theMode);
169 if (XCAFPrs::GetViewNameMode())
171 // Displaying Name attributes
172 thePrs->SetDisplayPriority (10);
173 DisplayText (myLabel, thePrs, Attributes()->DimensionAspect()->TextAspect(), TopLoc_Location());//no location
177 //=======================================================================
178 //function : SetColors
180 //=======================================================================
181 void XCAFPrs_AISObject::SetColors (const Handle(AIS_Drawer)& theDrawer,
182 const Quantity_Color& theColorCurv,
183 const Quantity_Color& theColorSurf)
185 if (!theDrawer->HasShadingAspect())
187 theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
188 *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
190 if (!theDrawer->HasLineAspect())
192 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
193 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
195 if (!theDrawer->HasWireAspect())
197 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
198 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
200 if (!theDrawer->HasUIsoAspect())
202 theDrawer->SetUIsoAspect (new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5, 1));
203 *theDrawer->UIsoAspect()->Aspect() = *theDrawer->Link()->UIsoAspect()->Aspect();
204 theDrawer->UIsoAspect()->SetNumber (theDrawer->Link()->UIsoAspect()->Number());
206 if (!theDrawer->HasVIsoAspect())
208 theDrawer->SetVIsoAspect (new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5, 1));
209 *theDrawer->VIsoAspect()->Aspect() = *theDrawer->Link()->VIsoAspect()->Aspect();
210 theDrawer->VIsoAspect()->SetNumber (theDrawer->Link()->VIsoAspect()->Number());
212 if (!theDrawer->HasFreeBoundaryAspect())
214 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
215 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
217 if (!theDrawer->HasUnFreeBoundaryAspect())
219 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
220 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
223 theDrawer->UnFreeBoundaryAspect()->SetColor (theColorCurv);
224 theDrawer->FreeBoundaryAspect()->SetColor (theColorCurv);
225 theDrawer->WireAspect()->SetColor (theColorCurv);
227 Graphic3d_MaterialAspect aMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
228 aMaterial.SetColor (theColorSurf);
229 theDrawer->ShadingAspect()->Aspect()->SetInteriorColor (theColorSurf);
230 theDrawer->ShadingAspect()->Aspect()->SetFrontMaterial (aMaterial);
231 theDrawer->UIsoAspect()->SetColor (theColorSurf);
232 theDrawer->VIsoAspect()->SetColor (theColorSurf);
235 //=======================================================================
236 //function : DefaultStyle
237 //purpose : DefaultStyle() can be redefined by subclasses in order to set custom default style
238 //=======================================================================
239 void XCAFPrs_AISObject::DefaultStyle (XCAFPrs_Style& theStyle) const
241 theStyle.SetColorSurf (Quantity_NOC_WHITE);
242 theStyle.SetColorCurv (Quantity_NOC_WHITE);