0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / SelectMgr / SelectMgr_SelectableObject.cxx
CommitLineData
b311480e 1// Created on: 1995-02-20
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <Standard_NotImplemented.hxx>
18
19#include <SelectMgr_SelectableObject.ixx>
20#include <Standard_NoSuchObject.hxx>
21#include <SelectMgr_Selection.hxx>
22#include <Select3D_SensitiveEntity.hxx>
23#include <SelectBasics_EntityOwner.hxx>
24#include <SelectMgr_EntityOwner.hxx>
25#include <PrsMgr_PresentationManager3d.hxx>
26
27#include <gp_Pnt.hxx>
28
29static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
30 const Handle (SelectMgr_Selection)& theSel)
31{
32 Standard_Integer ifound=0;
33 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
34 {if(theSel == seq.Value(i)) ifound=i;}
35 return ifound;
36}
37
38
39
40//==================================================
41// Function:
42// Purpose :
43//==================================================
44
45SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
46{
47 myAutoHilight = Standard_True;
48}
49
50
51//==================================================
52// Function:
53// Purpose :
54//==================================================
55
56Standard_Boolean SelectMgr_SelectableObject
57::HasSelection(const Standard_Integer aMode) const
58{
59 Standard_Boolean Found=Standard_False;
60 for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
61 { if(((myselections.Value(I))->Mode())==aMode)
62 return Standard_True;
63 }
64 return Standard_False;
65}
66
67//==================================================
68// Function: UpdateSelection
69// Purpose :
70//==================================================
71void SelectMgr_SelectableObject::UpdateSelection()
72{
73 for (Standard_Integer I=1;I<=myselections.Length();I++)
74 {
75 UpdateSelection(myselections.ChangeValue(I)->Mode());
76 }
77}
78
79Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const
80{return 0;}
81
82//==================================================
83// Function: UpdateSelection
84// Purpose :
85//==================================================
86void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
87{
88 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
89 if (myselections.Value(i)->Mode() == aMode) {
90 myselections(i)->Clear();
91 ComputeSelection(myselections(i),aMode);
92 myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
93 return;
94 }
95 }
96 Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
97 ComputeSelection(S,aMode);
98 S->UpdateStatus(SelectMgr_TOU_Partial);
99
100 myselections.Append(S);
101
102}
103
104//==================================================
105// Function: ClearSelections
106// Purpose :
107//==================================================
108void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
109{
110 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
111 myselections.Value(i)->Clear();
112 if(update)
113 myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
114 }
115}
116
117
118//==================================================
119// Function: Selection
120// Purpose :
121//==================================================
122
123const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
124::Selection(const Standard_Integer aMode) const
125{
126 static Handle(SelectMgr_Selection) bidsel;
127 Standard_Boolean Found = Standard_False;
128 Standard_Integer Rank=0;
129 for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
130 {
131 if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
132 Rank=i;}}
133 return myselections.Value(Rank);
134}
135
136
137//==================================================
138// Function: AddSelection
139// Purpose :
140//==================================================
141
142void SelectMgr_SelectableObject
143::AddSelection(const Handle(SelectMgr_Selection)& aSel,
144 const Standard_Integer aMode)
145{
146 if(aSel->IsEmpty()){
147 ComputeSelection(aSel,aMode);
148 aSel->UpdateStatus(SelectMgr_TOU_Partial);
149 }
150 if(HasSelection(aMode))
151 {
152 const Handle(SelectMgr_Selection)& temp= Selection(aMode);
153 Standard_Integer I = Search(myselections,temp);
154 if(I!=0) myselections.Remove(I);
155 }
156 myselections.Append(aSel);
157
158}
159
160
161
162//=======================================================================
163//function : ReSetLocation
164//purpose :
165//=======================================================================
166void SelectMgr_SelectableObject::ResetLocation()
167{
168 TopLoc_Location aLoc;
169
170
171 // les selections
172 Handle(Select3D_SensitiveEntity) SE;
173 for(Init();More();Next()){
174 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
175 for(Sel->Init();Sel->More();Sel->Next()){
176 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
177 if(!SE.IsNull()){
eafb234b 178 if(SE->HasLocation()) {
7fd59977 179 if( SE->Location()==myLocation){
180 SE->ResetLocation();
181 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
182 (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
183 else{
184 const TopLoc_Location& iniloc =SE->Location();
185 SE->SetLocation(iniloc*myLocation.Inverted());
186 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
187 (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
eafb234b 188 }
7fd59977 189 }
190 }
191 Sel->UpdateStatus(SelectMgr_TOU_None);
192 }
193
194 PrsMgr_PresentableObject::ResetLocation();
195}
196
197
198//=======================================================================
199//function : UpdateLocation
200//purpose :
201//=======================================================================
202void SelectMgr_SelectableObject::UpdateLocation()
203{
204
205 Handle(Select3D_SensitiveEntity) SE;
206 for(Init();More();Next()){
207 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
208 Sel->UpdateStatus(SelectMgr_TOU_Partial);
209 }
210 PrsMgr_PresentableObject::UpdateLocation();
211
212}
213
214
215//=======================================================================
216//function : UpdateLocation
217//purpose :
218//=======================================================================
219void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
220{
221 Handle(Select3D_SensitiveEntity) SE;
222 if(myLocation.IsIdentity()) return;
223 for(Sel->Init();Sel->More();Sel->Next()){
224 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
225 if(!SE.IsNull()){
226 SE->UpdateLocation(myLocation);
29d43f9c
A
227 const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId();
228 Handle(SelectMgr_EntityOwner) aMgrEO =
229 Handle(SelectMgr_EntityOwner)::DownCast (aEOwner);
230 if (!aMgrEO.IsNull())
231 aMgrEO->SetLocation (myLocation);
7fd59977 232 }
233 }
234}
235
236//=======================================================================
237//function : HilightSelected
238//purpose :
239//=======================================================================
240void SelectMgr_SelectableObject::HilightSelected
241 ( const Handle(PrsMgr_PresentationManager3d)&,
242 const SelectMgr_SequenceOfOwner&)
243{
244 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
245}
246
247//=======================================================================
248//function : ClearSelected
249//purpose :
250//=======================================================================
251void SelectMgr_SelectableObject::ClearSelected ()
252{
7fd59977 253 if( !mySelectionPrs.IsNull() )
2b442de5 254 mySelectionPrs->Clear();
7fd59977 255}
256
257//=======================================================================
258//function : HilightOwnerWithColor
259//purpose :
260//=======================================================================
261void SelectMgr_SelectableObject::HilightOwnerWithColor
262 ( const Handle(PrsMgr_PresentationManager3d)&,
263 const Quantity_NameOfColor,
264 const Handle(SelectMgr_EntityOwner)&)
265{
266 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
267}
268
269//=======================================================================
270//function : MaxFaceNodes
271//purpose :
272//=======================================================================
273Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
274{
275 return myAutoHilight;
276}
277
278//=======================================================================
279//function : MaxFaceNodes
280//purpose :
281//=======================================================================
282void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
283{
284 myAutoHilight = newAutoHilight;
285}
286
287//=======================================================================
288//function : GetHilightPresentation
289//purpose :
290//=======================================================================
291Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
292{
293 if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
294 {
295 myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
296 myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(),
297 GetTransformPersistencePoint() );
298 }
299
300 return myHilightPrs;
301}
302
303
304//=======================================================================
305//function : GetSelectPresentation
306//purpose :
307//=======================================================================
308Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
309{
310 if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
311 mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
312 mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(),
313 GetTransformPersistencePoint() );
314 }
315 return mySelectionPrs;
316}
317
59f45b7c 318//=======================================================================
319//function : SetZLayer
320//purpose :
321//=======================================================================
322void SelectMgr_SelectableObject::SetZLayer
323 (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
324 const Standard_Integer theLayerId)
325{
326 if (thePrsMgr.IsNull())
327 return;
328
329 // update own presentations
330 PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId);
331
332 // update selection presentations
333 if (!mySelectionPrs.IsNull())
334 mySelectionPrs->SetZLayer (theLayerId);
335
336 if (!myHilightPrs.IsNull())
337 myHilightPrs->SetZLayer (theLayerId);
338
339 // update all entity owner presentations
340 for (Init (); More () ;Next ())
341 {
342 const Handle(SelectMgr_Selection)& aSel = CurrentSelection();
343 for (aSel->Init (); aSel->More (); aSel->Next ())
344 {
345 Handle(Select3D_SensitiveEntity) aEntity =
346 Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive());
347 if (!aEntity.IsNull())
348 {
349 Handle(SelectMgr_EntityOwner) aOwner =
350 Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId());
351 if (!aOwner.IsNull())
352 aOwner->SetZLayer (thePrsMgr, theLayerId);
353 }
354 }
355 }
356}