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.
19 #include <AIS_Chamf3dDimension.hxx>
20 #include <Bnd_Box.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepTools_WireExplorer.hxx>
24 #include <DsgPrs_Chamf2dPresentation.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_Transformation.hxx>
32 #include <Precision.hxx>
33 #include <ProjLib.hxx>
34 #include <Prs3d_ArrowAspect.hxx>
35 #include <Prs3d_DimensionAspect.hxx>
36 #include <Prs3d_Drawer.hxx>
37 #include <Prs3d_Presentation.hxx>
38 #include <Prs3d_Projector.hxx>
39 #include <Select3D_SensitiveBox.hxx>
40 #include <Select3D_SensitiveSegment.hxx>
41 #include <SelectMgr_EntityOwner.hxx>
42 #include <SelectMgr_Selection.hxx>
43 #include <Standard_NotImplemented.hxx>
44 #include <Standard_Type.hxx>
45 #include <TCollection_AsciiString.hxx>
46 #include <TCollection_ExtendedString.hxx>
47 #include <TopAbs_Orientation.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Shape.hxx>
52 IMPLEMENT_STANDARD_RTTIEXT(AIS_Chamf3dDimension,AIS_Relation)
54 //=======================================================================
55 //function : Constructor
57 //=======================================================================
58 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
59 const Standard_Real aVal,
60 const TCollection_ExtendedString& aText)
66 mySymbolPrs = DsgPrs_AS_LASTAR;
67 myAutomaticPosition = Standard_True;
69 myArrowSize = myVal / 100.;
71 //=======================================================================
72 //function : Constructor
74 //=======================================================================
75 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
76 const Standard_Real aVal,
77 const TCollection_ExtendedString& aText,
78 const gp_Pnt& aPosition,
79 const DsgPrs_ArrowSide aSymbolPrs ,
80 const Standard_Real anArrowSize)
86 myPosition = aPosition;
87 mySymbolPrs = aSymbolPrs;
88 SetArrowSize( anArrowSize );
89 myAutomaticPosition = Standard_False;
93 //=======================================================================
96 //=======================================================================
98 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
99 const Handle(Prs3d_Presentation)& aPresentation,
100 const Standard_Integer)
102 aPresentation->Clear();
104 //----------------------------
105 // Calcul du centre de la face
106 //----------------------------
107 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
108 Standard_Real uFirst, uLast, vFirst, vLast;
109 uFirst = surfAlgo.FirstUParameter();
110 uLast = surfAlgo.LastUParameter();
111 vFirst = surfAlgo.FirstVParameter();
112 vLast = surfAlgo.LastVParameter();
113 Standard_Real uMoy = (uFirst + uLast)/2;
114 Standard_Real vMoy = (vFirst + vLast)/2;
117 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
121 // myDir = surfAlgo.Plane().Axis().Direction();
126 //--------------------------------------------
127 //Calcul du point de positionnement du texte
128 //--------------------------------------------
130 if (myAutomaticPosition) {
131 gp_Vec transVec(myDir);
133 curpos = myPntAttach.Translated(transVec);
136 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
142 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
143 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
144 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
146 if ( curpos.Distance(myPntAttach) < 5. ) {
147 gp_Vec transVec(myDir);
149 curpos = myPntAttach.Translated(transVec);
154 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
155 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
157 //-------------------------------------------------
158 //Calcul de la boite englobante du component pour
159 //determiner la taille de la fleche
160 //-------------------------------------------------
161 if( !myArrowSizeIsDefined ) {
162 Standard_Real arrsize = myArrowSize;
163 if ( (myVal/4) < arrsize)
167 else if (arrsize < 8.)
169 myArrowSize = arrsize;
171 arr->SetLength(myArrowSize);
173 //Calcul de la presentation
174 DsgPrs_Chamf2dPresentation::Add(aPresentation,
183 //=======================================================================
185 //purpose : to avoid warning
186 //=======================================================================
188 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
189 const Handle(Prs3d_Presentation)& aPresentation)
191 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
192 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
195 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
197 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
198 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
201 //=======================================================================
202 //function : ComputeSelection
204 //=======================================================================
206 void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
207 const Standard_Integer)
209 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
210 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
211 aSelection->Add(seg);
214 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
215 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
219 myPosition.X() + size,
220 myPosition.Y() + size,
221 myPosition.Z() + size);
222 aSelection->Add(box);