1 // Created on: 2007-01-25
2 // Created by: Sergey KOCHETKOV
3 // Copyright (c) 2007-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 <MeshVS_DataSource.hxx>
18 #include <MeshVS_Mesh.hxx>
19 #include <MeshVS_MeshOwner.hxx>
20 #include <PrsMgr_PresentationManager.hxx>
21 #include <PrsMgr_PresentationManager3d.hxx>
22 #include <SelectBasics_EntityOwner.hxx>
23 #include <SelectMgr_SelectableObject.hxx>
24 #include <Standard_Type.hxx>
25 #include <TColStd_HPackedMapOfInteger.hxx>
26 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_MeshOwner,SelectMgr_EntityOwner)
30 #ifndef MeshVS_PRSBUILDERHXX
31 #include <MeshVS_PrsBuilder.hxx>
35 //================================================================
36 // Function : Constructor MeshVS_MeshOwner
38 //================================================================
39 MeshVS_MeshOwner::MeshVS_MeshOwner (const SelectMgr_SOPtr& theSelObj,
40 const Handle(MeshVS_DataSource)& theDS,
41 const Standard_Integer thePriority)
42 : SelectMgr_EntityOwner ( theSelObj, thePriority )
47 SelectBasics_EntityOwner::Set ( thePriority );
50 //================================================================
51 // Function : GetDataSource
53 //================================================================
54 const Handle(MeshVS_DataSource)& MeshVS_MeshOwner::GetDataSource () const
59 //================================================================
60 // Function : GetSelectedNodes
62 //================================================================
63 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedNodes () const
65 return mySelectedNodes;
68 //================================================================
69 // Function : GetSelectedElements
71 //================================================================
72 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedElements () const
74 return mySelectedElems;
77 //================================================================
78 // Function : AddSelectedEntities
80 //================================================================
81 void MeshVS_MeshOwner::AddSelectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
82 const Handle(TColStd_HPackedMapOfInteger)& Elems)
84 if( mySelectedNodes.IsNull() )
85 mySelectedNodes = Nodes;
86 else if( !Nodes.IsNull() )
87 mySelectedNodes->ChangeMap().Unite( Nodes->Map() );
88 if( mySelectedElems.IsNull() )
89 mySelectedElems = Elems;
90 else if( !Elems.IsNull() )
91 mySelectedElems->ChangeMap().Unite( Elems->Map() );
94 //================================================================
95 // Function : ClearSelectedEntities
97 //================================================================
98 void MeshVS_MeshOwner::ClearSelectedEntities ()
100 mySelectedNodes.Nullify();
101 mySelectedElems.Nullify();
104 //================================================================
105 // Function : GetDetectedNodes
107 //================================================================
108 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedNodes () const
110 return myDetectedNodes;
113 //================================================================
114 // Function : GetDetectedElements
116 //================================================================
117 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedElements () const
119 return myDetectedElems;
122 //================================================================
123 // Function : SetDetectedEntities
125 //================================================================
126 void MeshVS_MeshOwner::SetDetectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
127 const Handle(TColStd_HPackedMapOfInteger)& Elems)
129 myDetectedNodes = Nodes;
130 myDetectedElems = Elems;
131 if (IsSelected()) SetSelected (Standard_False);
134 //================================================================
135 // Function : HilightWithColor
137 //================================================================
138 void MeshVS_MeshOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
139 const Handle(Graphic3d_HighlightStyle)& theStyle,
140 const Standard_Integer /*theMode*/)
142 Handle( SelectMgr_SelectableObject ) aSelObj;
143 if ( HasSelectable() )
144 aSelObj = Selectable();
146 if ( thePM->IsImmediateModeOn() && aSelObj->IsKind( STANDARD_TYPE( MeshVS_Mesh ) ) )
148 // Update last detected entity ID
149 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
150 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
151 if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 )
153 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
154 if( myLastID != anIt.Key() )
156 myLastID = anIt.Key();
159 else if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
161 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
162 if( myLastID != anIt.Key() )
164 myLastID = anIt.Key();
168 // hilight detected entities
169 Handle( MeshVS_Mesh ) aMesh = Handle( MeshVS_Mesh )::DownCast ( aSelObj );
170 aMesh->HilightOwnerWithColor ( thePM, theStyle, this );
174 void MeshVS_MeshOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& thePM,
175 const Standard_Integer theMode)
177 SelectMgr_EntityOwner::Unhilight( thePM, theMode );
179 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
180 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
181 if( ( !aNodes.IsNull() && !aNodes->Map().Contains( myLastID ) ) ||
182 ( !aElems.IsNull() && !aElems->Map().Contains( myLastID ) ) )
184 // Reset last detected ID
188 Standard_Boolean MeshVS_MeshOwner::IsForcedHilight () const
190 Standard_Boolean aHilight = Standard_True;
191 Standard_Integer aKey = -1;
194 // Check the detected entity and
195 // allow to hilight it if it differs from the last detected entity <myLastID>
196 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
197 if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 )
199 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
201 if( myLastID == aKey )
203 aHilight = Standard_False;
206 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
207 if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
209 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
211 if( myLastID == aKey )
213 aHilight = Standard_False;