1 // Created on: 1995-02-20
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <Standard_NotImplemented.hxx>
26 #include <SelectMgr_SelectableObject.ixx>
27 #include <Standard_NoSuchObject.hxx>
28 #include <SelectMgr_Selection.hxx>
29 #include <Select3D_SensitiveEntity.hxx>
30 #include <SelectBasics_EntityOwner.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32 #include <PrsMgr_PresentationManager3d.hxx>
36 static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
37 const Handle (SelectMgr_Selection)& theSel)
39 Standard_Integer ifound=0;
40 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
41 {if(theSel == seq.Value(i)) ifound=i;}
47 //==================================================
50 //==================================================
52 SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
54 myAutoHilight = Standard_True;
58 //==================================================
61 //==================================================
63 Standard_Boolean SelectMgr_SelectableObject
64 ::HasSelection(const Standard_Integer aMode) const
66 Standard_Boolean Found=Standard_False;
67 for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
68 { if(((myselections.Value(I))->Mode())==aMode)
71 return Standard_False;
74 //==================================================
75 // Function: UpdateSelection
77 //==================================================
78 void SelectMgr_SelectableObject::UpdateSelection()
80 for (Standard_Integer I=1;I<=myselections.Length();I++)
82 UpdateSelection(myselections.ChangeValue(I)->Mode());
86 Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const
89 //==================================================
90 // Function: UpdateSelection
92 //==================================================
93 void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
95 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
96 if (myselections.Value(i)->Mode() == aMode) {
97 myselections(i)->Clear();
98 ComputeSelection(myselections(i),aMode);
99 myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
103 Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
104 ComputeSelection(S,aMode);
105 S->UpdateStatus(SelectMgr_TOU_Partial);
107 myselections.Append(S);
111 //==================================================
112 // Function: ClearSelections
114 //==================================================
115 void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
117 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
118 myselections.Value(i)->Clear();
120 myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
125 //==================================================
126 // Function: Selection
128 //==================================================
130 const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
131 ::Selection(const Standard_Integer aMode) const
133 static Handle(SelectMgr_Selection) bidsel;
134 Standard_Boolean Found = Standard_False;
135 Standard_Integer Rank=0;
136 for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
138 if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
140 return myselections.Value(Rank);
144 //==================================================
145 // Function: AddSelection
147 //==================================================
149 void SelectMgr_SelectableObject
150 ::AddSelection(const Handle(SelectMgr_Selection)& aSel,
151 const Standard_Integer aMode)
154 ComputeSelection(aSel,aMode);
155 aSel->UpdateStatus(SelectMgr_TOU_Partial);
157 if(HasSelection(aMode))
159 const Handle(SelectMgr_Selection)& temp= Selection(aMode);
160 Standard_Integer I = Search(myselections,temp);
161 if(I!=0) myselections.Remove(I);
163 myselections.Append(aSel);
169 //=======================================================================
170 //function : ReSetLocation
172 //=======================================================================
173 void SelectMgr_SelectableObject::ResetLocation()
175 TopLoc_Location aLoc;
179 Handle(Select3D_SensitiveEntity) SE;
180 for(Init();More();Next()){
181 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
182 for(Sel->Init();Sel->More();Sel->Next()){
183 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
185 if(SE->HasLocation()) {
186 if( SE->Location()==myLocation){
188 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
189 (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
191 const TopLoc_Location& iniloc =SE->Location();
192 SE->SetLocation(iniloc*myLocation.Inverted());
193 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
194 (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
198 Sel->UpdateStatus(SelectMgr_TOU_None);
201 PrsMgr_PresentableObject::ResetLocation();
205 //=======================================================================
206 //function : UpdateLocation
208 //=======================================================================
209 void SelectMgr_SelectableObject::UpdateLocation()
212 Handle(Select3D_SensitiveEntity) SE;
213 for(Init();More();Next()){
214 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
215 Sel->UpdateStatus(SelectMgr_TOU_Partial);
217 PrsMgr_PresentableObject::UpdateLocation();
222 //=======================================================================
223 //function : UpdateLocation
225 //=======================================================================
226 void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
228 Handle(Select3D_SensitiveEntity) SE;
229 if(myLocation.IsIdentity()) return;
230 for(Sel->Init();Sel->More();Sel->Next()){
231 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
233 SE->UpdateLocation(myLocation);
234 const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId();
235 Handle(SelectMgr_EntityOwner) aMgrEO =
236 Handle(SelectMgr_EntityOwner)::DownCast (aEOwner);
237 if (!aMgrEO.IsNull())
238 aMgrEO->SetLocation (myLocation);
243 //=======================================================================
244 //function : HilightSelected
246 //=======================================================================
247 void SelectMgr_SelectableObject::HilightSelected
248 ( const Handle(PrsMgr_PresentationManager3d)&,
249 const SelectMgr_SequenceOfOwner&)
251 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
254 //=======================================================================
255 //function : ClearSelected
257 //=======================================================================
258 void SelectMgr_SelectableObject::ClearSelected ()
260 if( !mySelectionPrs.IsNull() )
261 mySelectionPrs->Clear();
264 //=======================================================================
265 //function : HilightOwnerWithColor
267 //=======================================================================
268 void SelectMgr_SelectableObject::HilightOwnerWithColor
269 ( const Handle(PrsMgr_PresentationManager3d)&,
270 const Quantity_NameOfColor,
271 const Handle(SelectMgr_EntityOwner)&)
273 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
276 //=======================================================================
277 //function : MaxFaceNodes
279 //=======================================================================
280 Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
282 return myAutoHilight;
285 //=======================================================================
286 //function : MaxFaceNodes
288 //=======================================================================
289 void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
291 myAutoHilight = newAutoHilight;
294 //=======================================================================
295 //function : GetHilightPresentation
297 //=======================================================================
298 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
300 if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
302 myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
303 myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(),
304 GetTransformPersistencePoint() );
311 //=======================================================================
312 //function : GetSelectPresentation
314 //=======================================================================
315 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
317 if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
318 mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
319 mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(),
320 GetTransformPersistencePoint() );
322 return mySelectionPrs;
325 //=======================================================================
326 //function : SetZLayer
328 //=======================================================================
329 void SelectMgr_SelectableObject::SetZLayer
330 (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
331 const Standard_Integer theLayerId)
333 if (thePrsMgr.IsNull())
336 // update own presentations
337 PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId);
339 // update selection presentations
340 if (!mySelectionPrs.IsNull())
341 mySelectionPrs->SetZLayer (theLayerId);
343 if (!myHilightPrs.IsNull())
344 myHilightPrs->SetZLayer (theLayerId);
346 // update all entity owner presentations
347 for (Init (); More () ;Next ())
349 const Handle(SelectMgr_Selection)& aSel = CurrentSelection();
350 for (aSel->Init (); aSel->More (); aSel->Next ())
352 Handle(Select3D_SensitiveEntity) aEntity =
353 Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive());
354 if (!aEntity.IsNull())
356 Handle(SelectMgr_EntityOwner) aOwner =
357 Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId());
358 if (!aOwner.IsNull())
359 aOwner->SetZLayer (thePrsMgr, theLayerId);