1 // Created on: 1995-03-08
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <StdSelect_BRepOwner.hxx>
19 #include <Graphic3d_StructureManager.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <PrsMgr_PresentationManager.hxx>
22 #include <SelectMgr_EntityOwner.hxx>
23 #include <SelectMgr_SelectableObject.hxx>
24 #include <Standard_Type.hxx>
25 #include <StdSelect_Shape.hxx>
26 #include <TopLoc_Location.hxx>
27 #include <TopoDS_Shape.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner)
31 //==================================================
32 // Function: StdSelect_BRepOwner
34 //==================================================
35 StdSelect_BRepOwner::StdSelect_BRepOwner (const Standard_Integer thePriority)
36 : SelectMgr_EntityOwner (thePriority),
42 //==================================================
43 // Function: StdSelect_BRepOwner
45 //==================================================
46 StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
47 const Standard_Integer thePriority,
48 const Standard_Boolean theComesFromDecomposition)
49 : SelectMgr_EntityOwner (thePriority),
53 myFromDecomposition = theComesFromDecomposition;
56 //==================================================
57 // Function: StdSelect_BRepOwner
59 //==================================================
60 StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
61 const Handle (SelectMgr_SelectableObject)& theOrigin,
62 const Standard_Integer thePriority,
63 const Standard_Boolean theComesFromDecomposition)
64 : SelectMgr_EntityOwner (theOrigin, thePriority),
68 myFromDecomposition = theComesFromDecomposition;
71 //=======================================================================
72 //function : IsHilighted
74 //=======================================================================
75 Standard_Boolean StdSelect_BRepOwner::
76 IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
77 const Standard_Integer aMode) const
79 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
81 return PM->IsHighlighted(Selectable(),M);
82 return PM->IsHighlighted(myPrsSh,M);
85 //=======================================================================
86 //function : HilightWithColor
88 //=======================================================================
89 void StdSelect_BRepOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
90 const Handle(Prs3d_Drawer)& theStyle,
91 const Standard_Integer theMode)
98 const Standard_Integer aDispMode = (theMode < 0) ? myCurMode : theMode;
99 Handle(SelectMgr_SelectableObject) aSel = Selectable();
100 const Graphic3d_ZLayerId aHiLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : aSel->ZLayer();
101 if (!myFromDecomposition)
103 thePM->Color (aSel, theStyle, aDispMode, NULL, aHiLayer);
107 // do the update flag check
108 if (!myPrsSh.IsNull()
109 && myPrsSh->ToBeUpdated (true))
114 // generate new presentable shape
115 if (myPrsSh.IsNull())
119 TopLoc_Location lbid = Location() * myShape.Location();
120 TopoDS_Shape ShBis = myShape.Located(lbid);
121 myPrsSh = new StdSelect_Shape (ShBis, theStyle);
125 myPrsSh = new StdSelect_Shape (myShape, theStyle);
129 // initialize presentation attributes of child presentation
130 myPrsSh->SetZLayer (aSel->ZLayer());
131 myPrsSh->SetTransformPersistence (aSel->TransformPersistence());
132 myPrsSh->Attributes()->SetLink (theStyle);
133 myPrsSh->Attributes()->SetColor (theStyle->Color());
134 myPrsSh->Attributes()->SetTransparency (theStyle->Transparency());
135 myPrsSh->Attributes()->SetBasicFillAreaAspect (theStyle->BasicFillAreaAspect());
137 // highlight with color and set layer
138 thePM->Color (myPrsSh, theStyle, aDispMode, aSel, aHiLayer);
141 void StdSelect_BRepOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer )
143 if (myPrsSh.IsNull() || !myFromDecomposition)
145 thePrsMgr->Unhighlight (Selectable());
149 thePrsMgr->Unhighlight (myPrsSh);
153 void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
154 const Standard_Integer aMode)
156 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
157 if (!myPrsSh.IsNull())
158 PM->Clear(myPrsSh,M);
162 void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
164 SelectMgr_EntityOwner::SetLocation(aLoc);
165 // we must not nullify the myPrsSh here, because unhilight method
166 // will be working with wrong entity in this case, the best is to
167 // set the update flag and then recompute myPrsSh on hilighting
168 if (!myPrsSh.IsNull())
169 myPrsSh->SetToUpdate();
172 //=======================================================================
173 //function : UpdateHighlightTrsf
175 //=======================================================================
176 void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
177 const Handle(PrsMgr_PresentationManager3d)& theManager,
178 const Standard_Integer theDispMode)
180 if (myPrsSh.IsNull() && Selectable().IsNull())
183 theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh);
186 // =======================================================================
187 // function : DumpJson
189 // =======================================================================
190 void StdSelect_BRepOwner::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
192 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
194 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myShape)
195 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPrsSh.get())
197 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurMode)