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
9 // under the terms of the GNU Lesser General Public 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 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
18 // if any in all dimensions.
20 #include <Standard_NotImplemented.hxx>
22 #include <AIS_Chamf3dDimension.ixx>
24 #include <DsgPrs_Chamf2dPresentation.hxx>
26 #include <Prs3d_ArrowAspect.hxx>
27 #include <Prs3d_DimensionAspect.hxx>
28 #include <Prs3d_Drawer.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <Select3D_SensitiveSegment.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
37 #include <TopAbs_Orientation.hxx>
39 #include <Bnd_Box.hxx>
40 #include <BRepBndLib.hxx>
46 #include <Geom_Line.hxx>
50 #include <Precision.hxx>
52 #include <TCollection_AsciiString.hxx>
53 #include <TCollection_ExtendedString.hxx>
55 #include <BRepTools_WireExplorer.hxx>
58 #include <AIS_Drawer.hxx>
60 #include <BRepAdaptor_Surface.hxx>
61 #include <ProjLib.hxx>
62 #include <Select3D_SensitiveBox.hxx>
64 //=======================================================================
65 //function : Constructor
67 //=======================================================================
68 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
69 const Standard_Real aVal,
70 const TCollection_ExtendedString& aText)
76 mySymbolPrs = DsgPrs_AS_LASTAR;
77 myAutomaticPosition = Standard_True;
79 myArrowSize = myVal / 100.;
81 //=======================================================================
82 //function : Constructor
84 //=======================================================================
85 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
86 const Standard_Real aVal,
87 const TCollection_ExtendedString& aText,
88 const gp_Pnt& aPosition,
89 const DsgPrs_ArrowSide aSymbolPrs ,
90 const Standard_Real anArrowSize)
96 myPosition = aPosition;
97 mySymbolPrs = aSymbolPrs;
99 SetArrowSize( anArrowSize );
101 myArrowSize = anArrowSize;
103 myAutomaticPosition = Standard_False;
107 //=======================================================================
110 //=======================================================================
112 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
113 const Handle(Prs3d_Presentation)& aPresentation,
114 const Standard_Integer)
116 aPresentation->Clear();
118 //----------------------------
119 // Calcul du centre de la face
120 //----------------------------
121 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
122 Standard_Real uFirst, uLast, vFirst, vLast;
123 uFirst = surfAlgo.FirstUParameter();
124 uLast = surfAlgo.LastUParameter();
125 vFirst = surfAlgo.FirstVParameter();
126 vLast = surfAlgo.LastVParameter();
127 Standard_Real uMoy = (uFirst + uLast)/2;
128 Standard_Real vMoy = (vFirst + vLast)/2;
131 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
135 // myDir = surfAlgo.Plane().Axis().Direction();
140 //--------------------------------------------
141 //Calcul du point de positionnement du texte
142 //--------------------------------------------
144 if (myAutomaticPosition) {
145 gp_Vec transVec(myDir);
147 curpos = myPntAttach.Translated(transVec);
150 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
156 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
157 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
158 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
160 if ( curpos.Distance(myPntAttach) < 5. ) {
161 gp_Vec transVec(myDir);
163 curpos = myPntAttach.Translated(transVec);
168 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
169 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
171 //-------------------------------------------------
172 //Calcul de la boite englobante du component pour
173 //determiner la taille de la fleche
174 //-------------------------------------------------
176 if( !myArrowSizeIsDefined ) {
178 Standard_Real arrsize = myArrowSize;
179 if ( (myVal/4) < arrsize)
183 else if (arrsize < 8.)
186 myArrowSize = arrsize;
188 arr->SetLength(myArrowSize);
190 arr->SetLength(arrsize);
193 //Calcul de la presentation
194 DsgPrs_Chamf2dPresentation::Add(aPresentation,
203 //=======================================================================
205 //purpose : to avoid warning
206 //=======================================================================
208 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
209 const Handle(Prs3d_Presentation)& aPresentation)
211 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
212 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
215 void AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
217 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
218 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
221 //=======================================================================
222 //function : ComputeSelection
224 //=======================================================================
226 void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
227 const Standard_Integer)
229 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
230 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
231 aSelection->Add(seg);
234 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
235 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
239 myPosition.X() + size,
240 myPosition.Y() + size,
241 myPosition.Z() + size);
242 aSelection->Add(box);