1 // File: AIS_ConnectedShape.cxx
2 // Created: Wed Apr 10 16:40:43 1996
3 // Author: Guest Design
7 #include <Standard_NotImplemented.hxx>
9 #include <AIS_ConnectedShape.ixx>
11 #include <AIS_InteractiveContext.hxx>
12 #include <AIS_Drawer.hxx>
13 #include <TopAbs_ShapeEnum.hxx>
14 #include <StdPrs_WFDeflectionShape.hxx>
15 #include <StdPrs_HLRPolyShape.hxx>
16 #include <Prs3d_Drawer.hxx>
17 #include <Aspect_TypeOfDeflection.hxx>
18 #include <BRepTools.hxx>
19 #include <OSD_Timer.hxx>
20 #include <StdSelect_BRepSelectionTool.hxx>
21 #include <StdSelect_BRepOwner.hxx>
22 #include <StdSelect.hxx>
23 #include <TopTools_IndexedMapOfShape.hxx>
25 #include <Select3D_SensitiveEntity.hxx>
26 #include <SelectMgr_EntityOwner.hxx>
27 #include <SelectBasics_EntityOwner.hxx>
28 #include <AIS_MultipleConnectedShape.hxx>
29 #include <Precision.hxx>
31 //=======================================================================
32 //function : AIS_ConnectedShape
34 //=======================================================================
36 AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_Shape)& TheAISShape,
37 const PrsMgr_TypeOfPresentation3d TheType):
38 AIS_ConnectedInteractive(TheType)
40 myReference = TheAISShape;
43 AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_ConnectedShape)& TheConnectedShape,
44 const PrsMgr_TypeOfPresentation3d TheType):
45 AIS_ConnectedInteractive(TheType)
47 myReference = TheConnectedShape;
51 //=======================================================================
54 //=======================================================================
56 AIS_KindOfInteractive AIS_ConnectedShape::Type() const
57 {return AIS_KOI_Shape;}
59 //=======================================================================
60 //function : Signature
62 //=======================================================================
63 Standard_Integer AIS_ConnectedShape::Signature() const
66 //=======================================================================
67 //function : AcceptShapeDecomposition
69 //=======================================================================
70 Standard_Boolean AIS_ConnectedShape::AcceptShapeDecomposition() const
71 {return Standard_True;}
73 //=======================================================================
74 //function : Compute Hidden Lines
76 //=======================================================================
78 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
79 const Handle(Prs3d_Presentation)& aPresentation)
81 UpdateShape(Standard_True);
82 Compute(aProjector,aPresentation,myOwnSh);
86 //=======================================================================
89 //=======================================================================
90 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
91 const Handle(Geom_Transformation)& TheTrsf,
92 const Handle(Prs3d_Presentation)& aPresentation)
94 UpdateShape(Standard_False);
95 const TopLoc_Location& loc = myOwnSh.Location();
96 TopoDS_Shape shbis = myOwnSh.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
97 Compute(aProjector,aPresentation,shbis);
101 //=======================================================================
104 //=======================================================================
106 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
107 const Handle(Prs3d_Presentation)& aPresentation,
108 const TopoDS_Shape& SH)
110 // Standard_Boolean recompute = Standard_False;
111 // Standard_Boolean myFirstCompute = Standard_True;
112 switch (SH.ShapeType()){
117 aPresentation->SetDisplayPriority(4);
118 StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
123 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
124 if (defdrawer->DrawHiddenLine())
125 {myDrawer->EnableDrawHiddenLine();}
126 else {myDrawer->DisableDrawHiddenLine();}
128 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
129 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
131 // traitement HLRAngle et HLRDeviationCoefficient()
132 Standard_Real prevangl = myDrawer->HLRAngle();
133 Standard_Real newangl = defdrawer->HLRAngle();
134 if (Abs(newangl- prevangl) > Precision::Angular()) {
136 cout << "AIS_MultipleConnectedShape : compute"<<endl;
137 cout << "newangl : " << newangl << " # de " << "prevangl : " << prevangl << endl;
139 BRepTools::Clean(SH);
141 myDrawer->SetHLRAngle(newangl);
142 myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
143 StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
144 defdrawer->SetTypeOfDeflection (prevdef);
149 //=======================================================================
152 //=======================================================================
154 void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
155 const Handle_Graphic2d_GraphicObject& aGraphicObject,
158 // Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
159 AIS_ConnectedInteractive::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
162 //=======================================================================
165 //=======================================================================
167 void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& /*aPresentationManager3d*/,
168 const Handle_Prs3d_Presentation& /*aPresentation*/,
169 const int /*anInteger*/)
171 Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d&, const Handle_Prs3d_Presentation&, const int)");
172 // AIS_ConnectedInteractive::Compute( aPresentationManager3d ,aPresentation,anInteger) ; not accessible
175 //=======================================================================
176 //function : ComputeSelection
177 //purpose : Attention fragile...
178 //=======================================================================
180 void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
181 const Standard_Integer aMode)
185 // On regarde s'il n'y a pas des choses a faire sur la reference,
186 // du type mise a jour...
188 if(!myReference->HasSelection(aMode))
189 myReference->UpdateSelection(aMode);
190 const Handle(SelectMgr_Selection)& RefSel = myReference->Selection(aMode);
191 if(RefSel->IsEmpty())
192 myReference->UpdateSelection(aMode);
193 if(RefSel->UpdateStatus()==SelectMgr_TOU_Full)
194 myReference->UpdateSelection(aMode);
196 //suivant le type de decomposition, on deduit les primitives connectees.
197 // il faut suivre l'ordre de creation de StdSelect_BRepSelectionTool...
199 TopAbs_ShapeEnum TheType = AIS_Shape::SelectionType(aMode);
200 Handle(StdSelect_BRepOwner) OWNR;
201 Handle(Select3D_SensitiveEntity) SE,NiouSE;
202 TopLoc_Location BidLoc;
211 TopTools_IndexedMapOfShape subshaps;
212 TopExp::MapShapes(myOwnSh,TheType,subshaps);
215 for(Standard_Integer I=1;
216 I<=subshaps.Extent()&& RefSel->More();
219 SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
221 OWNR = new StdSelect_BRepOwner(subshaps(I),this,SE->OwnerId()->Priority());
224 if(myLocation.IsIdentity())
225 NiouSE = SE->GetConnected(BidLoc);
227 NiouSE = SE->GetConnected(myLocation);
229 aSelection->Add(NiouSE);
238 // Dans ce cas on n'a qu'un seul proprietaire pour l'ensemble des
239 // primitives sensibles...
240 OWNR = new StdSelect_BRepOwner(myOwnSh,this);
241 Standard_Boolean FirstIncr(Standard_True);
242 for(RefSel->Init();RefSel->More();RefSel->Next()){
243 SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
245 Standard_Integer Prior = SE->OwnerId()->Priority();
246 Handle(SelectBasics_EntityOwner)::DownCast(OWNR)->Set(Prior);
247 FirstIncr = Standard_False;}
249 if(myLocation.IsIdentity())
250 NiouSE = SE->GetConnected(BidLoc);
252 NiouSE = SE->GetConnected(myLocation);
254 aSelection->Add(NiouSE);
259 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
264 //=======================================================================
267 //=======================================================================
269 const TopoDS_Shape& AIS_ConnectedShape::Shape()
274 AIS_ConnectedShape::AIS_ConnectedShape(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
275 AIS_ConnectedInteractive(aTypeOfPresentation3d)
280 //=======================================================================
281 //function : UpdateShape
282 //purpose : if<WithLocation=False> computes only the deducted shape
283 // from reference; does not put "myLocation"
284 //=======================================================================
285 void AIS_ConnectedShape::UpdateShape(const Standard_Boolean WithTheLocation)
287 if(myReference.IsNull()) return;
289 // attention grosse ligne...
290 if(myReference->Type()!=AIS_KOI_Shape) return;
292 Standard_Integer Sig = myReference->Signature();
297 S = (*((Handle(AIS_Shape)*) &myReference))->Shape();
300 S = (*((Handle(AIS_ConnectedShape)*) &myReference))->Shape();
303 S=(*((Handle(AIS_MultipleConnectedShape)*) &myReference))->Shape();
308 if(S.IsNull()) return;
309 if(myLocation.IsIdentity() || !WithTheLocation)
312 myOwnSh = S.Moved(myLocation);
316 //=======================================================================
319 //=======================================================================
320 void AIS_ConnectedShape::
321 Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
323 if(anotherIObj->Type()== AIS_KOI_Shape){
324 Standard_Integer Sig = anotherIObj->Signature();
326 AIS_ConnectedInteractive::Connect(anotherIObj);
330 //=======================================================================
333 //=======================================================================
334 void AIS_ConnectedShape::
335 Connect(const Handle(AIS_InteractiveObject)& anotherIObj,
336 const TopLoc_Location& aLocation)
338 if(anotherIObj->Type()== AIS_KOI_Shape){
339 Standard_Integer Sig = anotherIObj->Signature();
341 AIS_ConnectedInteractive::Connect(anotherIObj,aLocation);