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
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.
20 #include <Standard_NotImplemented.hxx>
22 #include <AIS_MultipleConnectedShape.ixx>
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
29 #include <StdPrs_WFDeflectionShape.hxx>
30 #include <StdPrs_HLRPolyShape.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Aspect_TypeOfDeflection.hxx>
33 #include <Bnd_Box.hxx>
34 #include <BRepTools.hxx>
35 #include <BRepBndLib.hxx>
36 #include <OSD_Timer.hxx>
37 #include <StdSelect_BRepSelectionTool.hxx>
38 #include <StdSelect.hxx>
39 #include <Precision.hxx>
41 //=======================================================================
42 //function : AIS_ConnectedShape
44 //=======================================================================
46 AIS_MultipleConnectedShape::AIS_MultipleConnectedShape (const TopoDS_Shape& aShape):
47 AIS_MultipleConnectedInteractive(PrsMgr_TOP_ProjectorDependant),
52 //=======================================================================
55 //=======================================================================
56 AIS_KindOfInteractive AIS_MultipleConnectedShape::Type() const
57 {return AIS_KOI_Shape;}
60 //=======================================================================
61 //function : Signature
63 //=======================================================================
64 Standard_Integer AIS_MultipleConnectedShape::Signature() const
68 //=======================================================================
69 //function : AcceptShapeDecomposition
71 //=======================================================================
73 Standard_Boolean AIS_MultipleConnectedShape::AcceptShapeDecomposition() const
74 {return Standard_True;}
79 //=======================================================================
80 //function : Compute Hidden Lines
82 //=======================================================================
84 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
85 const Handle(Prs3d_Presentation)& aPresentation)
87 Compute(aProjector,aPresentation,myShape);
91 //=======================================================================
94 //=======================================================================
96 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
97 const Handle(Geom_Transformation)& aTrsf,
98 const Handle(Prs3d_Presentation)& aPresentation)
100 aPresentation->Clear();
102 const TopLoc_Location& loc = myShape.Location();
103 TopoDS_Shape shbis = myShape.Located(TopLoc_Location(aTrsf->Trsf())*loc);
104 Compute(aProjector,aPresentation,shbis);
110 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
111 const Handle(Prs3d_Presentation)& aPresentation,
112 const TopoDS_Shape& SH)
114 //Standard_Boolean recompute = Standard_False;
115 //Standard_Boolean myFirstCompute = Standard_True;
116 switch (SH.ShapeType()){
121 aPresentation->SetDisplayPriority(4);
122 StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
128 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
129 if (defdrawer->DrawHiddenLine())
130 {myDrawer->EnableDrawHiddenLine();}
131 else {myDrawer->DisableDrawHiddenLine();}
133 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
134 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
136 // traitement HLRAngle et HLRDeviationCoefficient()
137 Standard_Real prevangl = myDrawer->HLRAngle();
138 Standard_Real newangl = defdrawer->HLRAngle();
139 if (Abs(newangl- prevangl) > Precision::Angular()) {
141 cout << "AIS_MultipleConnectedShape : compute"<<endl;
142 cout << "newangl : " << newangl << " # de " << "prevangl : " << prevangl << endl;
144 BRepTools::Clean(SH);
146 myDrawer->SetHLRAngle(newangl);
147 myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
149 StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
152 defdrawer->SetTypeOfDeflection (prevdef);
158 //=======================================================================
161 //=======================================================================
163 void AIS_MultipleConnectedShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager3d,
164 const Handle(Prs3d_Presentation)& aPresentation,
167 AIS_MultipleConnectedInteractive::Compute( aPresentationManager3d , aPresentation , anint ) ;
170 //=======================================================================
171 //function : ComputeSelection
173 //=======================================================================
175 void AIS_MultipleConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
176 const Standard_Integer aMode)
178 //cout<<"AIS_MultipleConnectedShape::ComputeSelection"<<endl;
180 Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
181 Standard_Real aDeflection = myDrawer->MaximalChordialDeviation();
182 if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
184 // On calcule la fleche en fonction des min max globaux de la piece:
185 Bnd_Box aBndBox; //= BoundingBox(); ?
186 BRepBndLib::Add (myShape, aBndBox);
187 if (!aBndBox.IsVoid())
189 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
190 aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
191 aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient();
197 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_VERTEX, aDeflection, aDeviationAngle);
200 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_EDGE, aDeflection, aDeviationAngle);
203 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_WIRE, aDeflection, aDeviationAngle);
206 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE, aDeflection, aDeviationAngle);
209 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHELL, aDeflection, aDeviationAngle);
212 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SOLID, aDeflection, aDeviationAngle);
215 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPOUND, aDeflection, aDeviationAngle);
218 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPSOLID, aDeflection, aDeviationAngle);
221 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE, aDeflection, aDeviationAngle);
224 // insert the drawer in the BrepOwners for hilight...
225 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);