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.
16 #include <MeshVS_MeshOwner.ixx>
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>
25 #ifndef MeshVS_PRSBUILDERHXX
26 #include <MeshVS_PrsBuilder.hxx>
30 //================================================================
31 // Function : Constructor MeshVS_MeshOwner
33 //================================================================
34 MeshVS_MeshOwner::MeshVS_MeshOwner (const SelectMgr_SOPtr& theSelObj,
35 const Handle(MeshVS_DataSource)& theDS,
36 const Standard_Integer thePriority)
37 : SelectMgr_EntityOwner ( theSelObj, thePriority )
42 SelectBasics_EntityOwner::Set ( thePriority );
45 //================================================================
46 // Function : GetDataSource
48 //================================================================
49 const Handle(MeshVS_DataSource)& MeshVS_MeshOwner::GetDataSource () const
54 //================================================================
55 // Function : GetSelectedNodes
57 //================================================================
58 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedNodes () const
60 return mySelectedNodes;
63 //================================================================
64 // Function : GetSelectedElements
66 //================================================================
67 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetSelectedElements () const
69 return mySelectedElems;
72 //================================================================
73 // Function : AddSelectedEntities
75 //================================================================
76 void MeshVS_MeshOwner::AddSelectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
77 const Handle(TColStd_HPackedMapOfInteger)& Elems)
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() );
89 //================================================================
90 // Function : ClearSelectedEntities
92 //================================================================
93 void MeshVS_MeshOwner::ClearSelectedEntities ()
95 mySelectedNodes.Nullify();
96 mySelectedElems.Nullify();
99 //================================================================
100 // Function : GetDetectedNodes
102 //================================================================
103 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedNodes () const
105 return myDetectedNodes;
108 //================================================================
109 // Function : GetDetectedElements
111 //================================================================
112 const Handle(TColStd_HPackedMapOfInteger)& MeshVS_MeshOwner::GetDetectedElements () const
114 return myDetectedElems;
117 //================================================================
118 // Function : SetDetectedEntities
120 //================================================================
121 void MeshVS_MeshOwner::SetDetectedEntities (const Handle(TColStd_HPackedMapOfInteger)& Nodes,
122 const Handle(TColStd_HPackedMapOfInteger)& Elems)
124 myDetectedNodes = Nodes;
125 myDetectedElems = Elems;
126 if( State() ) State( 0 );
129 //================================================================
130 // Function : HilightWithColor
132 //================================================================
133 void MeshVS_MeshOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
134 const Quantity_NameOfColor theColor,
135 const Standard_Integer /*theMode*/)
137 Handle( SelectMgr_SelectableObject ) aSelObj;
138 if ( HasSelectable() )
139 aSelObj = Selectable();
141 if ( thePM->IsImmediateModeOn() && aSelObj->IsKind( STANDARD_TYPE( MeshVS_Mesh ) ) )
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 )
148 TColStd_MapIteratorOfPackedMapOfInteger anIt( aNodes->Map() );
149 if( myLastID != anIt.Key() )
151 myLastID = anIt.Key();
154 else if( !aElems.IsNull() && aElems->Map().Extent() == 1 )
156 TColStd_MapIteratorOfPackedMapOfInteger anIt( aElems->Map() );
157 if( myLastID != anIt.Key() )
159 myLastID = anIt.Key();
163 // hilight detected entities
164 Handle( MeshVS_Mesh ) aMesh = Handle( MeshVS_Mesh )::DownCast ( aSelObj );
165 aMesh->HilightOwnerWithColor ( thePM, theColor, this );
169 void MeshVS_MeshOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& thePM,
170 const Standard_Integer theMode)
172 SelectMgr_EntityOwner::Unhilight( thePM, theMode );
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;