1 // Copyright: Matra-Datavision 1995
2 // File: SelectMgr_SelectableObject.cxx
3 // Created: Mon Feb 20 17:40:49 1995
9 #include <Standard_NotImplemented.hxx>
11 #include <SelectMgr_SelectableObject.ixx>
12 #include <Standard_NoSuchObject.hxx>
13 #include <SelectMgr_Selection.hxx>
14 #include <Select3D_SensitiveEntity.hxx>
15 #include <SelectBasics_EntityOwner.hxx>
16 #include <SelectMgr_EntityOwner.hxx>
17 #include <PrsMgr_PresentationManager3d.hxx>
21 static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
22 const Handle (SelectMgr_Selection)& theSel)
24 Standard_Integer ifound=0;
25 for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++)
26 {if(theSel == seq.Value(i)) ifound=i;}
32 //==================================================
35 //==================================================
37 SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d)
39 myAutoHilight = Standard_True;
43 //==================================================
46 //==================================================
48 Standard_Boolean SelectMgr_SelectableObject
49 ::HasSelection(const Standard_Integer aMode) const
51 Standard_Boolean Found=Standard_False;
52 for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
53 { if(((myselections.Value(I))->Mode())==aMode)
56 return Standard_False;
59 //==================================================
60 // Function: UpdateSelection
62 //==================================================
63 void SelectMgr_SelectableObject::UpdateSelection()
65 for (Standard_Integer I=1;I<=myselections.Length();I++)
67 UpdateSelection(myselections.ChangeValue(I)->Mode());
71 Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const
74 //==================================================
75 // Function: UpdateSelection
77 //==================================================
78 void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode)
80 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
81 if (myselections.Value(i)->Mode() == aMode) {
82 myselections(i)->Clear();
83 ComputeSelection(myselections(i),aMode);
84 myselections(i)->UpdateStatus(SelectMgr_TOU_Partial);
88 Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode);
89 ComputeSelection(S,aMode);
90 S->UpdateStatus(SelectMgr_TOU_Partial);
92 myselections.Append(S);
96 //==================================================
97 // Function: ClearSelections
99 //==================================================
100 void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update)
102 for (Standard_Integer i =1; i<= myselections.Length(); i++ ) {
103 myselections.Value(i)->Clear();
105 myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full);
110 //==================================================
111 // Function: Selection
113 //==================================================
115 const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject
116 ::Selection(const Standard_Integer aMode) const
118 static Handle(SelectMgr_Selection) bidsel;
119 Standard_Boolean Found = Standard_False;
120 Standard_Integer Rank=0;
121 for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++)
123 if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True;
125 return myselections.Value(Rank);
129 //==================================================
130 // Function: AddSelection
132 //==================================================
134 void SelectMgr_SelectableObject
135 ::AddSelection(const Handle(SelectMgr_Selection)& aSel,
136 const Standard_Integer aMode)
139 ComputeSelection(aSel,aMode);
140 aSel->UpdateStatus(SelectMgr_TOU_Partial);
142 if(HasSelection(aMode))
144 const Handle(SelectMgr_Selection)& temp= Selection(aMode);
145 Standard_Integer I = Search(myselections,temp);
146 if(I!=0) myselections.Remove(I);
148 myselections.Append(aSel);
154 //=======================================================================
155 //function : ReSetLocation
157 //=======================================================================
158 void SelectMgr_SelectableObject::ResetLocation()
160 TopLoc_Location aLoc;
164 Handle(Select3D_SensitiveEntity) SE;
165 for(Init();More();Next()){
166 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
167 for(Sel->Init();Sel->More();Sel->Next()){
168 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
170 if(SE->HasLocation())
171 if( SE->Location()==myLocation){
173 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
174 (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();}
176 const TopLoc_Location& iniloc =SE->Location();
177 SE->SetLocation(iniloc*myLocation.Inverted());
178 const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId();
179 (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());}
183 Sel->UpdateStatus(SelectMgr_TOU_None);
186 PrsMgr_PresentableObject::ResetLocation();
190 //=======================================================================
191 //function : UpdateLocation
193 //=======================================================================
194 void SelectMgr_SelectableObject::UpdateLocation()
197 Handle(Select3D_SensitiveEntity) SE;
198 for(Init();More();Next()){
199 const Handle(SelectMgr_Selection) & Sel = CurrentSelection();
200 Sel->UpdateStatus(SelectMgr_TOU_Partial);
202 PrsMgr_PresentableObject::UpdateLocation();
207 //=======================================================================
208 //function : UpdateLocation
210 //=======================================================================
211 void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
213 Handle(Select3D_SensitiveEntity) SE;
214 if(myLocation.IsIdentity()) return;
215 for(Sel->Init();Sel->More();Sel->Next()){
216 SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive()));
218 SE->UpdateLocation(myLocation);
223 //=======================================================================
224 //function : HilightSelected
226 //=======================================================================
227 void SelectMgr_SelectableObject::HilightSelected
228 ( const Handle(PrsMgr_PresentationManager3d)&,
229 const SelectMgr_SequenceOfOwner&)
231 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected");
234 //=======================================================================
235 //function : ClearSelected
237 //=======================================================================
238 void SelectMgr_SelectableObject::ClearSelected ()
240 //Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
241 if( !mySelectionPrs.IsNull() )
242 mySelectionPrs->Clear();
245 //=======================================================================
246 //function : HilightOwnerWithColor
248 //=======================================================================
249 void SelectMgr_SelectableObject::HilightOwnerWithColor
250 ( const Handle(PrsMgr_PresentationManager3d)&,
251 const Quantity_NameOfColor,
252 const Handle(SelectMgr_EntityOwner)&)
254 Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor");
257 //=======================================================================
258 //function : MaxFaceNodes
260 //=======================================================================
261 Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const
263 return myAutoHilight;
266 //=======================================================================
267 //function : MaxFaceNodes
269 //=======================================================================
270 void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight )
272 myAutoHilight = newAutoHilight;
275 //=======================================================================
276 //function : GetHilightPresentation
278 //=======================================================================
279 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
281 if( myHilightPrs.IsNull() && !TheMgr.IsNull() )
283 myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
284 myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(),
285 GetTransformPersistencePoint() );
292 //=======================================================================
293 //function : GetSelectPresentation
295 //=======================================================================
296 Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr )
298 if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) {
299 mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() );
300 mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(),
301 GetTransformPersistencePoint() );
303 return mySelectionPrs;