1 // Created on: 1995-02-20
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_NotImplemented.hxx>
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>
27 #include <TopLoc_Location.hxx>
30 static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
31 const Handle (SelectMgr_Selection)& theSel)
33 Standard_Integer ifound=0;
34 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
35 {if(theSel == seq.Value(i)) ifound=i;}
41 //==================================================
44 //==================================================
46 SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
48 myAutoHilight = Standard_True;
52 //==================================================
55 //==================================================
57 Standard_Boolean SelectMgr_SelectableObject
58 ::HasSelection(const Standard_Integer aMode) const
60 Standard_Boolean Found=Standard_False;
61 for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
62 { if(((myselections.Value(I))->Mode())==aMode)
65 return Standard_False;
68 //==================================================
69 // Function: UpdateSelection
71 //==================================================
72 void SelectMgr_SelectableObject::UpdateSelection()
74 for (Standard_Integer I=1;I<=myselections.Length();I++)
76 UpdateSelection(myselections.ChangeValue(I)->Mode());
80 Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const
83 //==================================================
84 // Function: UpdateSelection
86 //==================================================
87 void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
89 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
90 if (myselections.Value(i)->Mode() == aMode) {
91 myselections(i)->Clear();
92 ComputeSelection(myselections(i),aMode);
93 myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
97 Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
98 ComputeSelection(S,aMode);
99 S->UpdateStatus(SelectMgr_TOU_Partial);
101 myselections.Append(S);
105 //==================================================
106 // Function: ClearSelections
108 //==================================================
109 void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
111 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
112 myselections.Value(i)->Clear();
114 myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
119 //==================================================
120 // Function: Selection
122 //==================================================
124 const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
125 ::Selection(const Standard_Integer aMode) const
127 static Handle(SelectMgr_Selection) bidsel;
128 Standard_Boolean Found = Standard_False;
129 Standard_Integer Rank=0;
130 for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
132 if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
134 return myselections.Value(Rank);
138 //==================================================
139 // Function: AddSelection
141 //==================================================
143 void SelectMgr_SelectableObject
144 ::AddSelection(const Handle(SelectMgr_Selection)& aSel,
145 const Standard_Integer aMode)
148 ComputeSelection(aSel,aMode);
149 aSel->UpdateStatus(SelectMgr_TOU_Partial);
151 if(HasSelection(aMode))
153 const Handle(SelectMgr_Selection)& temp= Selection(aMode);
154 Standard_Integer I = Search(myselections,temp);
155 if(I!=0) myselections.Remove(I);
157 myselections.Append(aSel);
163 //=======================================================================
164 //function : ReSetTransformation
166 //=======================================================================
167 void SelectMgr_SelectableObject::ResetTransformation()
169 TopLoc_Location aLoc;
171 TopLoc_Location aSelfLocation (Transformation());
174 Handle(Select3D_SensitiveEntity) SE;
175 for(Init();More();Next()){
176 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
177 for(Sel->Init();Sel->More();Sel->Next()){
178 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
180 if(SE->HasLocation()) {
181 if( SE->Location()==aSelfLocation){
183 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
184 (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
186 const TopLoc_Location& iniloc =SE->Location();
187 SE->SetLocation(iniloc*aSelfLocation.Inverted());
188 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
189 (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
193 Sel->UpdateStatus(SelectMgr_TOU_None);
196 PrsMgr_PresentableObject::ResetTransformation();
200 //=======================================================================
201 //function : UpdateTransformation
203 //=======================================================================
204 void SelectMgr_SelectableObject::UpdateTransformation()
207 Handle(Select3D_SensitiveEntity) SE;
208 for(Init();More();Next()){
209 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
210 Sel->UpdateStatus(SelectMgr_TOU_Partial);
212 PrsMgr_PresentableObject::UpdateTransformation();
217 //=======================================================================
218 //function : UpdateTransformation
220 //=======================================================================
221 void SelectMgr_SelectableObject::UpdateTransformations(const Handle(SelectMgr_Selection)& Sel)
223 TopLoc_Location aSelfLocation (Transformation());
224 Handle(Select3D_SensitiveEntity) SE;
225 if(aSelfLocation.IsIdentity()) return;
226 for(Sel->Init();Sel->More();Sel->Next()){
227 SE = Handle(Select3D_SensitiveEntity)::DownCast(Sel->Sensitive());
229 SE->UpdateLocation(aSelfLocation);
230 const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId();
231 Handle(SelectMgr_EntityOwner) aMgrEO =
232 Handle(SelectMgr_EntityOwner)::DownCast (aEOwner);
233 if (!aMgrEO.IsNull())
234 aMgrEO->SetLocation (aSelfLocation);
239 //=======================================================================
240 //function : HilightSelected
242 //=======================================================================
243 void SelectMgr_SelectableObject::HilightSelected
244 ( const Handle(PrsMgr_PresentationManager3d)&,
245 const SelectMgr_SequenceOfOwner&)
247 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
250 //=======================================================================
251 //function : ClearSelected
253 //=======================================================================
254 void SelectMgr_SelectableObject::ClearSelected ()
256 if( !mySelectionPrs.IsNull() )
257 mySelectionPrs->Clear();
260 //=======================================================================
261 //function : HilightOwnerWithColor
263 //=======================================================================
264 void SelectMgr_SelectableObject::HilightOwnerWithColor
265 ( const Handle(PrsMgr_PresentationManager3d)&,
266 const Quantity_NameOfColor,
267 const Handle(SelectMgr_EntityOwner)&)
269 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
272 //=======================================================================
273 //function : MaxFaceNodes
275 //=======================================================================
276 Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
278 return myAutoHilight;
281 //=======================================================================
282 //function : MaxFaceNodes
284 //=======================================================================
285 void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
287 myAutoHilight = newAutoHilight;
290 //=======================================================================
291 //function : GetHilightPresentation
293 //=======================================================================
294 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
296 if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
298 myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
299 myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(),
300 GetTransformPersistencePoint() );
307 //=======================================================================
308 //function : GetSelectPresentation
310 //=======================================================================
311 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
313 if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
314 mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
315 mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(),
316 GetTransformPersistencePoint() );
318 return mySelectionPrs;
321 //=======================================================================
322 //function : SetZLayer
324 //=======================================================================
325 void SelectMgr_SelectableObject::SetZLayer
326 (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
327 const Standard_Integer theLayerId)
329 if (thePrsMgr.IsNull())
332 // update own presentations
333 PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId);
335 // update selection presentations
336 if (!mySelectionPrs.IsNull())
337 mySelectionPrs->SetZLayer (theLayerId);
339 if (!myHilightPrs.IsNull())
340 myHilightPrs->SetZLayer (theLayerId);
342 // update all entity owner presentations
343 for (Init (); More () ;Next ())
345 const Handle(SelectMgr_Selection)& aSel = CurrentSelection();
346 for (aSel->Init (); aSel->More (); aSel->Next ())
348 Handle(Select3D_SensitiveEntity) aEntity =
349 Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive());
350 if (!aEntity.IsNull())
352 Handle(SelectMgr_EntityOwner) aOwner =
353 Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId());
354 if (!aOwner.IsNull())
355 aOwner->SetZLayer (thePrsMgr, theLayerId);