1 // Created on: 1997-04-22
2 // Created by: Guest Design
3 // Copyright (c) 1997-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 <AIS_MultipleConnectedShape.ixx>
30 #include <AIS_InteractiveContext.hxx>
31 #include <AIS_Drawer.hxx>
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <StdPrs_WFDeflectionShape.hxx>
34 #include <StdPrs_HLRPolyShape.hxx>
35 #include <Prs3d_Drawer.hxx>
36 #include <Aspect_TypeOfDeflection.hxx>
37 #include <Bnd_Box.hxx>
38 #include <BRepTools.hxx>
39 #include <BRepBndLib.hxx>
40 #include <OSD_Timer.hxx>
41 #include <StdSelect_BRepSelectionTool.hxx>
42 #include <StdSelect.hxx>
43 #include <Precision.hxx>
45 //=======================================================================
46 //function : AIS_ConnectedShape
48 //=======================================================================
50 AIS_MultipleConnectedShape::AIS_MultipleConnectedShape (const TopoDS_Shape& aShape):
51 AIS_MultipleConnectedInteractive(PrsMgr_TOP_ProjectorDependant),
56 //=======================================================================
59 //=======================================================================
60 AIS_KindOfInteractive AIS_MultipleConnectedShape::Type() const
61 {return AIS_KOI_Shape;}
64 //=======================================================================
65 //function : Signature
67 //=======================================================================
68 Standard_Integer AIS_MultipleConnectedShape::Signature() const
72 //=======================================================================
73 //function : AcceptShapeDecomposition
75 //=======================================================================
77 Standard_Boolean AIS_MultipleConnectedShape::AcceptShapeDecomposition() const
78 {return Standard_True;}
83 //=======================================================================
84 //function : Compute Hidden Lines
86 //=======================================================================
88 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
89 const Handle(Prs3d_Presentation)& aPresentation)
91 Compute(aProjector,aPresentation,myShape);
95 //=======================================================================
98 //=======================================================================
100 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
101 const Handle(Geom_Transformation)& aTrsf,
102 const Handle(Prs3d_Presentation)& aPresentation)
104 aPresentation->Clear();
106 const TopLoc_Location& loc = myShape.Location();
107 TopoDS_Shape shbis = myShape.Located(TopLoc_Location(aTrsf->Trsf())*loc);
108 Compute(aProjector,aPresentation,shbis);
114 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector,
115 const Handle(Prs3d_Presentation)& aPresentation,
116 const TopoDS_Shape& SH)
118 //Standard_Boolean recompute = Standard_False;
119 //Standard_Boolean myFirstCompute = Standard_True;
120 switch (SH.ShapeType()){
125 aPresentation->SetDisplayPriority(4);
126 StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
132 Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
133 if (defdrawer->DrawHiddenLine())
134 {myDrawer->EnableDrawHiddenLine();}
135 else {myDrawer->DisableDrawHiddenLine();}
137 Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
138 defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
140 // traitement HLRAngle et HLRDeviationCoefficient()
141 Standard_Real prevangl = myDrawer->HLRAngle();
142 Standard_Real newangl = defdrawer->HLRAngle();
143 if (Abs(newangl- prevangl) > Precision::Angular()) {
145 cout << "AIS_MultipleConnectedShape : compute"<<endl;
146 cout << "newangl : " << newangl << " # de " << "prevangl : " << prevangl << endl;
148 BRepTools::Clean(SH);
150 myDrawer->SetHLRAngle(newangl);
151 myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
153 StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
156 defdrawer->SetTypeOfDeflection (prevdef);
162 //=======================================================================
165 //=======================================================================
167 void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& aPresentationManager3d,
168 const Handle_Prs3d_Presentation& aPresentation,
171 AIS_MultipleConnectedInteractive::Compute( aPresentationManager3d , aPresentation , anint ) ;
174 //=======================================================================
177 //=======================================================================
179 void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
180 const Handle_Graphic2d_GraphicObject& aGraphicObject,
183 // Standard_NotImplemented::Raise("AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
184 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
187 //=======================================================================
188 //function : ComputeSelection
190 //=======================================================================
192 void AIS_MultipleConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
193 const Standard_Integer aMode)
195 //cout<<"AIS_MultipleConnectedShape::ComputeSelection"<<endl;
197 Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
198 Standard_Real aDeflection = myDrawer->MaximalChordialDeviation();
199 if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
201 // On calcule la fleche en fonction des min max globaux de la piece:
202 Bnd_Box aBndBox; //= BoundingBox(); ?
203 BRepBndLib::Add (myShape, aBndBox);
204 if (!aBndBox.IsVoid())
206 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
207 aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
208 aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient();
214 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_VERTEX, aDeflection, aDeviationAngle);
217 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_EDGE, aDeflection, aDeviationAngle);
220 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_WIRE, aDeflection, aDeviationAngle);
223 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE, aDeflection, aDeviationAngle);
226 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHELL, aDeflection, aDeviationAngle);
229 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SOLID, aDeflection, aDeviationAngle);
232 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPOUND, aDeflection, aDeviationAngle);
235 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPSOLID, aDeflection, aDeviationAngle);
238 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE, aDeflection, aDeviationAngle);
241 // insert the drawer in the BrepOwners for hilight...
242 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);