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 <SelectMgr_SelectableObject.hxx>
22 #include <Standard_Type.hxx>
23 #include <TColStd_HPackedMapOfInteger.hxx>
24 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_MeshOwner,SelectMgr_EntityOwner)
28 #ifndef MeshVS_PRSBUILDERHXX
32 //================================================================
33 // Function : Constructor MeshVS_MeshOwner
35 //================================================================
36 MeshVS_MeshOwner::MeshVS_MeshOwner (const SelectMgr_SelectableObject* theSelObj,
37 const Handle(MeshVS_DataSource)& theDS,
38 const Standard_Integer thePriority)
39 : SelectMgr_EntityOwner ( theSelObj, thePriority )
46 //================================================================
47 // Function : GetDataSource
49 //================================================================
50 const Handle(MeshVS_DataSource)& MeshVS_MeshOwner::GetDataSource () const
55 //================================================================
56 // Function : GetSelectedNodes
58 //================================================================
59 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedNodes () const
61 return mySelectedNodes;
64 //================================================================
65 // Function : GetSelectedElements
67 //================================================================
68 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedElements () const
70 return mySelectedElems;
73 //================================================================
74 // Function : AddSelectedEntities
76 //================================================================
77 void MeshVS_MeshOwner::AddSelectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
78 const Handle(TColStd_HPackedMapOfInteger)& Elems)
80 if( mySelectedNodes.IsNull() )
81 mySelectedNodes = Nodes;
82 else if( !Nodes.IsNull() )
83 mySelectedNodes->ChangeMap().Unite( Nodes->Map() );
84 if( mySelectedElems.IsNull() )
85 mySelectedElems = Elems;
86 else if( !Elems.IsNull() )
87 mySelectedElems->ChangeMap().Unite( Elems->Map() );
90 //================================================================
91 // Function : ClearSelectedEntities
93 //================================================================
94 void MeshVS_MeshOwner::ClearSelectedEntities ()
96 mySelectedNodes.Nullify();
97 mySelectedElems.Nullify();
100 //================================================================
101 // Function : GetDetectedNodes
103 //================================================================
104 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedNodes () const
106 return myDetectedNodes;
109 //================================================================
110 // Function : GetDetectedElements
112 //================================================================
113 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedElements () const
115 return myDetectedElems;
118 //================================================================
119 // Function : SetDetectedEntities
121 //================================================================
122 void MeshVS_MeshOwner::SetDetectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
123 const Handle(TColStd_HPackedMapOfInteger)& Elems)
125 myDetectedNodes = Nodes;
126 myDetectedElems = Elems;
127 if (IsSelected()) SetSelected (Standard_False);
130 //================================================================
131 // Function : HilightWithColor
133 //================================================================
134 void MeshVS_MeshOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
135 const Handle(Prs3d_Drawer)& theStyle,
136 const Standard_Integer /*theMode*/)
138 Handle( SelectMgr_SelectableObject ) aSelObj;
139 if ( HasSelectable() )
140 aSelObj = Selectable();
142 if ( thePM->IsImmediateModeOn() && aSelObj->IsKind( STANDARD_TYPE( MeshVS_Mesh ) ) )
144 // Update last detected entity ID
145 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
146 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
147 if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 )
149 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
150 if( myLastID != anIt.Key() )
152 myLastID = anIt.Key();
155 else if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
157 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
158 if( myLastID != anIt.Key() )
160 myLastID = anIt.Key();
164 // hilight detected entities
165 Handle( MeshVS_Mesh ) aMesh = Handle( MeshVS_Mesh )::DownCast ( aSelObj );
166 aMesh->HilightOwnerWithColor ( thePM, theStyle, this );
170 void MeshVS_MeshOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePM, const Standard_Integer )
172 SelectMgr_EntityOwner::Unhilight (thePM);
174 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
175 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
176 if( ( !aNodes.IsNull() && !aNodes->Map().Contains( myLastID ) ) ||
177 ( !aElems.IsNull() && !aElems->Map().Contains( myLastID ) ) )
179 // Reset last detected ID
183 Standard_Boolean MeshVS_MeshOwner::IsForcedHilight () const
185 Standard_Boolean aHilight = Standard_True;
186 Standard_Integer aKey = -1;
189 // Check the detected entity and
190 // allow to hilight it if it differs from the last detected entity <myLastID>
191 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
192 if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 )
194 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
196 if( myLastID == aKey )
198 aHilight = Standard_False;
201 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
202 if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
204 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
206 if( myLastID == aKey )
208 aHilight = Standard_False;