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