1 // Created on: 1996-12-05
2 // Created by: Odile Olivier
3 // Copyright (c) 1996-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.
22 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
23 // if any in all dimensions.
25 #include <Standard_NotImplemented.hxx>
27 #include <AIS_Chamf3dDimension.ixx>
29 #include <DsgPrs_Chamf2dPresentation.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_LengthAspect.hxx>
33 #include <Prs3d_Drawer.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <Select3D_SensitiveSegment.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
42 #include <TopAbs_Orientation.hxx>
44 #include <Bnd_Box.hxx>
45 #include <BRepBndLib.hxx>
51 #include <Geom_Line.hxx>
55 #include <Precision.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TCollection_ExtendedString.hxx>
60 #include <BRepTools_WireExplorer.hxx>
63 #include <AIS_Drawer.hxx>
65 #include <BRepAdaptor_Surface.hxx>
66 #include <ProjLib.hxx>
67 #include <Select3D_SensitiveBox.hxx>
69 //=======================================================================
70 //function : Constructor
72 //=======================================================================
73 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
74 const Standard_Real aVal,
75 const TCollection_ExtendedString& aText)
81 mySymbolPrs = DsgPrs_AS_LASTAR;
82 myAutomaticPosition = Standard_True;
84 myArrowSize = myVal / 100.;
86 //=======================================================================
87 //function : Constructor
89 //=======================================================================
90 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
91 const Standard_Real aVal,
92 const TCollection_ExtendedString& aText,
93 const gp_Pnt& aPosition,
94 const DsgPrs_ArrowSide aSymbolPrs ,
95 const Standard_Real anArrowSize)
101 myPosition = aPosition;
102 mySymbolPrs = aSymbolPrs;
104 SetArrowSize( anArrowSize );
106 myArrowSize = anArrowSize;
108 myAutomaticPosition = Standard_False;
112 //=======================================================================
115 //=======================================================================
117 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
118 const Handle(Prs3d_Presentation)& aPresentation,
119 const Standard_Integer)
121 aPresentation->Clear();
123 //----------------------------
124 // Calcul du centre de la face
125 //----------------------------
126 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
127 Standard_Real uFirst, uLast, vFirst, vLast;
128 uFirst = surfAlgo.FirstUParameter();
129 uLast = surfAlgo.LastUParameter();
130 vFirst = surfAlgo.FirstVParameter();
131 vLast = surfAlgo.LastVParameter();
132 Standard_Real uMoy = (uFirst + uLast)/2;
133 Standard_Real vMoy = (vFirst + vLast)/2;
136 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
140 // myDir = surfAlgo.Plane().Axis().Direction();
145 //--------------------------------------------
146 //Calcul du point de positionnement du texte
147 //--------------------------------------------
149 if (myAutomaticPosition) {
150 gp_Vec transVec(myDir);
152 curpos = myPntAttach.Translated(transVec);
155 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
161 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
162 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
163 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
165 if ( curpos.Distance(myPntAttach) < 5. ) {
166 gp_Vec transVec(myDir);
168 curpos = myPntAttach.Translated(transVec);
173 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
174 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
176 //-------------------------------------------------
177 //Calcul de la boite englobante du component pour
178 //determiner la taille de la fleche
179 //-------------------------------------------------
181 if( !myArrowSizeIsDefined ) {
183 Standard_Real arrsize = myArrowSize;
184 if ( (myVal/4) < arrsize)
188 else if (arrsize < 8.)
191 myArrowSize = arrsize;
193 arr->SetLength(myArrowSize);
195 arr->SetLength(arrsize);
198 //Calcul de la presentation
199 DsgPrs_Chamf2dPresentation::Add(aPresentation,
208 //=======================================================================
210 //purpose : to avoid warning
211 //=======================================================================
213 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
214 const Handle(Prs3d_Presentation)& aPresentation)
216 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
217 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
220 //=======================================================================
222 //purpose : to avoid warning
223 //=======================================================================
225 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d,
226 const Handle(Graphic2d_GraphicObject)& aGraphicObject,
227 const Standard_Integer anInteger)
229 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
230 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
233 void AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
235 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
236 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
239 //=======================================================================
240 //function : ComputeSelection
242 //=======================================================================
244 void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
245 const Standard_Integer)
247 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
248 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
249 aSelection->Add(seg);
252 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
253 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
257 myPosition.X() + size,
258 myPosition.Y() + size,
259 myPosition.Z() + size);
260 aSelection->Add(box);