0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / AIS / AIS_MultipleConnectedInteractive.cxx
1 // Created on: 1997-04-22
2 // Created by: Guest Design
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <AIS_MultipleConnectedInteractive.hxx>
18
19 #include <AIS_ConnectedInteractive.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <Prs3d_Projector.hxx>
23 #include <PrsMgr_ModedPresentation.hxx>
24 #include <Select3D_SensitiveEntity.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <Standard_NotImplemented.hxx>
27 #include <TopLoc_Location.hxx>
28
29 IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject)
30
31 //=======================================================================
32 //function : AIS_MultipleConnectedInteractive
33 //purpose  :
34 //=======================================================================
35
36 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
37 : AIS_InteractiveObject (PrsMgr_TOP_AllView)
38 {
39   myHasOwnPresentations = Standard_False;
40 }
41
42 //=======================================================================
43 //function : Type
44 //purpose  : 
45 //=======================================================================
46 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
47 {
48   return AIS_KOI_Object;
49 }
50
51 //=======================================================================
52 //function : Signature
53 //purpose  : 
54 //=======================================================================
55 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
56 {
57   return 1;
58 }
59
60 //=======================================================================
61 //function : connect
62 //purpose  :
63 //=======================================================================
64 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
65                                                                          const Handle(Geom_Transformation)& theTrsf,
66                                                                          const Handle(Graphic3d_TransformPers)& theTrsfPers)
67 {
68   if (myAssemblyOwner.IsNull())
69     myAssemblyOwner = new SelectMgr_EntityOwner (this);
70
71   Handle(AIS_InteractiveObject) anObjectToAdd;
72
73   Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
74   if (!aMultiConnected.IsNull())
75   { 
76     Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
77     aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
78     aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom());
79
80     // Perform deep copy of instance tree
81     for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
82     {
83       Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
84       if (anInteractive.IsNull())
85       {
86         continue;
87       }
88
89       aNewMultiConnected->Connect (anInteractive);     
90     }
91
92     anObjectToAdd = aNewMultiConnected;
93   }
94   else
95   {
96     Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
97     aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom());
98
99     anObjectToAdd = aNewConnected;
100   }
101
102   anObjectToAdd->SetLocalTransformation (theTrsf);
103   if (!theTrsfPers.IsNull())
104   {
105     anObjectToAdd->SetTransformPersistence (theTrsfPers);
106   }
107   AddChild (anObjectToAdd);
108   return anObjectToAdd;
109 }
110
111 //=======================================================================
112 //function : HasConnection
113 //purpose  : 
114 //=======================================================================
115 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const 
116 {
117   return (Children().Size() != 0);
118 }
119
120 //=======================================================================
121 //function : Disconnect
122 //purpose  : 
123 //=======================================================================
124
125 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
126 {
127   RemoveChild (anotherIObj);
128 }
129
130 //=======================================================================
131 //function : DisconnectAll
132 //purpose  : 
133 //=======================================================================
134
135 void AIS_MultipleConnectedInteractive::DisconnectAll()
136 {
137   Standard_Integer aNbItemsToRemove = Children().Size();
138   for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
139   {
140     RemoveChild (Children().First());
141   }
142 }
143
144 //=======================================================================
145 //function : Compute
146 //purpose  :
147 //=======================================================================
148 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
149                                                 const Handle(Prs3d_Presentation)&           /*thePrs*/,
150                                                 const Standard_Integer                      /*theMode*/)
151 {
152   Handle(AIS_InteractiveContext) aCtx = GetContext();
153   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
154   {
155     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
156     if (!aChild.IsNull())
157     {
158       aChild->SetContext (aCtx);
159     }
160   }
161 }
162
163 //=======================================================================
164 //function : Compute
165 //purpose  : 
166 //=======================================================================
167
168 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
169                                                const Handle(Prs3d_Presentation)& aPresentation)
170 {
171   PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
172 }
173
174 //=======================================================================
175 //function : Compute
176 //purpose  : 
177 //=======================================================================
178
179 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
180                                                const Handle(Geom_Transformation)& aTransformation,
181                                                const Handle(Prs3d_Presentation)& aPresentation)
182 {
183   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
184 }
185
186 //=======================================================================
187 //function : AcceptShapeDecomposition
188 //purpose  : 
189 //=======================================================================
190 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const 
191 {
192   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
193   {
194     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
195     if (aChild.IsNull())
196     {
197       continue;
198     }
199
200     if (aChild->AcceptShapeDecomposition())
201     {
202       return Standard_True;
203     }
204   }
205   return Standard_False;
206 }
207
208 //=======================================================================
209 //function : ComputeSelection
210 //purpose  : 
211 //=======================================================================
212 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
213                                                          const Standard_Integer             theMode)
214 {
215   if (theMode == 0)
216   {
217     return;
218   }
219
220   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
221   {
222     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
223     if (aChild.IsNull())
224     {
225       continue;
226     }
227
228     if (!aChild->HasSelection (theMode))
229     {
230       aChild->RecomputePrimitives (theMode);
231     }
232
233     Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
234     aChild->ComputeSelection (aSelection, theMode);
235   }
236 }
237
238 //=======================================================================
239 //function : SetContext
240 //purpose  :
241 //=======================================================================
242 void AIS_MultipleConnectedInteractive::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
243 {
244   AIS_InteractiveObject::SetContext (theCtx);
245   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
246   {
247     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
248     if (!aChild.IsNull())
249     {
250       aChild->SetContext (theCtx);
251     }
252   }
253 }