0023649: Visualization, AIS_LocalContext - make highlighting of already selected...
[occt.git] / src / MeshVS / MeshVS_MeshOwner.cxx
... / ...
CommitLineData
1// Created on: 2007-01-25
2// Created by: Sergey KOCHETKOV
3// Copyright (c) 2007-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <MeshVS_MeshOwner.ixx>
17
18#include <SelectBasics_EntityOwner.hxx>
19#include <SelectMgr_SelectableObject.hxx>
20#include <PrsMgr_PresentationManager3d.hxx>
21#include <MeshVS_Mesh.hxx>
22#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
23
24
25#ifndef MeshVS_PRSBUILDERHXX
26#include <MeshVS_PrsBuilder.hxx>
27#endif
28
29
30//================================================================
31// Function : Constructor MeshVS_MeshOwner
32// Purpose :
33//================================================================
34MeshVS_MeshOwner::MeshVS_MeshOwner (const SelectMgr_SOPtr& theSelObj,
35 const Handle(MeshVS_DataSource)& theDS,
36 const Standard_Integer thePriority)
37: SelectMgr_EntityOwner ( theSelObj, thePriority )
38{
39 myLastID = -1;
40 if( !theDS.IsNull() )
41 myDataSource = theDS;
42 SelectBasics_EntityOwner::Set ( thePriority );
43}
44
45//================================================================
46// Function : GetDataSource
47// Purpose :
48//================================================================
49const Handle(MeshVS_DataSource)& MeshVS_MeshOwner::GetDataSource () const
50{
51 return myDataSource;
52}
53
54//================================================================
55// Function : GetSelectedNodes
56// Purpose :
57//================================================================
58const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedNodes () const
59{
60 return mySelectedNodes;
61}
62
63//================================================================
64// Function : GetSelectedElements
65// Purpose :
66//================================================================
67const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedElements () const
68{
69 return mySelectedElems;
70}
71
72//================================================================
73// Function : AddSelectedEntities
74// Purpose :
75//================================================================
76void MeshVS_MeshOwner::AddSelectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
77 const Handle(TColStd_HPackedMapOfInteger)& Elems)
78{
79 if( mySelectedNodes.IsNull() )
80 mySelectedNodes = Nodes;
81 else if( !Nodes.IsNull() )
82 mySelectedNodes->ChangeMap().Unite( Nodes->Map() );
83 if( mySelectedElems.IsNull() )
84 mySelectedElems = Elems;
85 else if( !Elems.IsNull() )
86 mySelectedElems->ChangeMap().Unite( Elems->Map() );
87}
88
89//================================================================
90// Function : ClearSelectedEntities
91// Purpose :
92//================================================================
93void MeshVS_MeshOwner::ClearSelectedEntities ()
94{
95 mySelectedNodes.Nullify();
96 mySelectedElems.Nullify();
97}
98
99//================================================================
100// Function : GetDetectedNodes
101// Purpose :
102//================================================================
103const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedNodes () const
104{
105 return myDetectedNodes;
106}
107
108//================================================================
109// Function : GetDetectedElements
110// Purpose :
111//================================================================
112const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedElements () const
113{
114 return myDetectedElems;
115}
116
117//================================================================
118// Function : SetDetectedEntities
119// Purpose :
120//================================================================
121void MeshVS_MeshOwner::SetDetectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
122 const Handle(TColStd_HPackedMapOfInteger)& Elems)
123{
124 myDetectedNodes = Nodes;
125 myDetectedElems = Elems;
126 if (IsSelected()) SetSelected (Standard_False);
127}
128
129//================================================================
130// Function : HilightWithColor
131// Purpose :
132//================================================================
133void MeshVS_MeshOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
134 const Quantity_NameOfColor theColor,
135 const Standard_Integer /*theMode*/)
136{
137 Handle( SelectMgr_SelectableObject ) aSelObj;
138 if ( HasSelectable() )
139 aSelObj = Selectable();
140
141 if ( thePM->IsImmediateModeOn() && aSelObj->IsKind( STANDARD_TYPE( MeshVS_Mesh ) ) )
142 {
143 // Update last detected entity ID
144 Handle(TColStd_HPackedMapOfInteger) aNodes = GetDetectedNodes();
145 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
146 if( !aNodes.IsNull() && aNodes->Map().Extent() == 1 )
147 {
148 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
149 if( myLastID != anIt.Key() )
150 {
151 myLastID = anIt.Key();
152 }
153 }
154 else if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
155 {
156 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
157 if( myLastID != anIt.Key() )
158 {
159 myLastID = anIt.Key();
160 }
161 }
162
163 // hilight detected entities
164 Handle( MeshVS_Mesh ) aMesh = Handle( MeshVS_Mesh )::DownCast ( aSelObj );
165 aMesh->HilightOwnerWithColor ( thePM, theColor, this );
166 }
167}
168
169void MeshVS_MeshOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& thePM,
170 const Standard_Integer theMode)
171{
172 SelectMgr_EntityOwner::Unhilight( thePM, theMode );
173
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 ) ) )
178 return;
179 // Reset last detected ID
180 myLastID = -1;
181}
182
183Standard_Boolean MeshVS_MeshOwner::IsForcedHilight () const
184{
185 Standard_Boolean aHilight = Standard_True;
186 Standard_Integer aKey = -1;
187 if( myLastID > 0 )
188 {
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 )
193 {
194 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
195 aKey = anIt.Key();
196 if( myLastID == aKey )
197 {
198 aHilight = Standard_False;
199 }
200 }
201 Handle(TColStd_HPackedMapOfInteger) aElems = GetDetectedElements();
202 if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
203 {
204 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
205 aKey = anIt.Key();
206 if( myLastID == aKey )
207 {
208 aHilight = Standard_False;
209 }
210 }
211 }
212 return aHilight;
213}