1 // Created on: 1996-12-05
2 // Created by: Odile Olivier
3 // Copyright (c) 1996-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.
17 #include <Standard_NotImplemented.hxx>
19 #include <AIS_Chamf3dDimension.ixx>
21 #include <DsgPrs_Chamf2dPresentation.hxx>
23 #include <Prs3d_ArrowAspect.hxx>
24 #include <Prs3d_DimensionAspect.hxx>
25 #include <Prs3d_Drawer.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
34 #include <TopAbs_Orientation.hxx>
36 #include <Bnd_Box.hxx>
37 #include <BRepBndLib.hxx>
43 #include <Geom_Line.hxx>
47 #include <Precision.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <TCollection_ExtendedString.hxx>
52 #include <BRepTools_WireExplorer.hxx>
55 #include <AIS_Drawer.hxx>
57 #include <BRepAdaptor_Surface.hxx>
58 #include <ProjLib.hxx>
59 #include <Select3D_SensitiveBox.hxx>
61 //=======================================================================
62 //function : Constructor
64 //=======================================================================
65 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
66 const Standard_Real aVal,
67 const TCollection_ExtendedString& aText)
73 mySymbolPrs = DsgPrs_AS_LASTAR;
74 myAutomaticPosition = Standard_True;
76 myArrowSize = myVal / 100.;
78 //=======================================================================
79 //function : Constructor
81 //=======================================================================
82 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
83 const Standard_Real aVal,
84 const TCollection_ExtendedString& aText,
85 const gp_Pnt& aPosition,
86 const DsgPrs_ArrowSide aSymbolPrs ,
87 const Standard_Real anArrowSize)
93 myPosition = aPosition;
94 mySymbolPrs = aSymbolPrs;
95 SetArrowSize( anArrowSize );
96 myAutomaticPosition = Standard_False;
100 //=======================================================================
103 //=======================================================================
105 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
106 const Handle(Prs3d_Presentation)& aPresentation,
107 const Standard_Integer)
109 aPresentation->Clear();
111 //----------------------------
112 // Calcul du centre de la face
113 //----------------------------
114 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
115 Standard_Real uFirst, uLast, vFirst, vLast;
116 uFirst = surfAlgo.FirstUParameter();
117 uLast = surfAlgo.LastUParameter();
118 vFirst = surfAlgo.FirstVParameter();
119 vLast = surfAlgo.LastVParameter();
120 Standard_Real uMoy = (uFirst + uLast)/2;
121 Standard_Real vMoy = (vFirst + vLast)/2;
124 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
128 // myDir = surfAlgo.Plane().Axis().Direction();
133 //--------------------------------------------
134 //Calcul du point de positionnement du texte
135 //--------------------------------------------
137 if (myAutomaticPosition) {
138 gp_Vec transVec(myDir);
140 curpos = myPntAttach.Translated(transVec);
143 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
149 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
150 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
151 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
153 if ( curpos.Distance(myPntAttach) < 5. ) {
154 gp_Vec transVec(myDir);
156 curpos = myPntAttach.Translated(transVec);
161 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
162 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
164 //-------------------------------------------------
165 //Calcul de la boite englobante du component pour
166 //determiner la taille de la fleche
167 //-------------------------------------------------
168 if( !myArrowSizeIsDefined ) {
169 Standard_Real arrsize = myArrowSize;
170 if ( (myVal/4) < arrsize)
174 else if (arrsize < 8.)
176 myArrowSize = arrsize;
178 arr->SetLength(myArrowSize);
180 //Calcul de la presentation
181 DsgPrs_Chamf2dPresentation::Add(aPresentation,
190 //=======================================================================
192 //purpose : to avoid warning
193 //=======================================================================
195 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
196 const Handle(Prs3d_Presentation)& aPresentation)
198 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
199 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
202 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
204 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
205 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
208 //=======================================================================
209 //function : ComputeSelection
211 //=======================================================================
213 void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
214 const Standard_Integer)
216 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
217 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
218 aSelection->Add(seg);
221 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
222 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
226 myPosition.X() + size,
227 myPosition.Y() + size,
228 myPosition.Z() + size);
229 aSelection->Add(box);