1 // Created on: 1996-12-05
2 // Created by: Flore Lantheaume/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_Chamf2dDimension.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_Plane.hxx>
28 #include <Geom_Transformation.hxx>
33 #include <Precision.hxx>
34 #include <ProjLib.hxx>
35 #include <Prs3d_ArrowAspect.hxx>
36 #include <Prs3d_DimensionAspect.hxx>
37 #include <Prs3d_Drawer.hxx>
38 #include <Prs3d_Presentation.hxx>
39 #include <Prs3d_Projector.hxx>
40 #include <Select3D_SensitiveBox.hxx>
41 #include <Select3D_SensitiveSegment.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Selection.hxx>
44 #include <Standard_NotImplemented.hxx>
45 #include <Standard_Type.hxx>
46 #include <TCollection_AsciiString.hxx>
47 #include <TCollection_ExtendedString.hxx>
48 #include <TopAbs_Orientation.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Shape.hxx>
53 IMPLEMENT_STANDARD_RTTIEXT(AIS_Chamf2dDimension,AIS_Relation)
55 //=======================================================================
56 //function : Constructor
58 //=======================================================================
59 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
60 const Handle(Geom_Plane)& aPlane,
61 const Standard_Real aVal,
62 const TCollection_ExtendedString& aText)
69 mySymbolPrs = DsgPrs_AS_LASTAR;
70 myAutomaticPosition = Standard_True;
72 myArrowSize = myVal / 100.;
74 //=======================================================================
75 //function : Constructor
77 //=======================================================================
78 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
79 const Handle(Geom_Plane)& aPlane,
80 const Standard_Real aVal,
81 const TCollection_ExtendedString& aText,
82 const gp_Pnt& aPosition,
83 const DsgPrs_ArrowSide aSymbolPrs ,
84 const Standard_Real anArrowSize)
91 myPosition = aPosition;
92 mySymbolPrs = aSymbolPrs;
93 SetArrowSize( anArrowSize );
94 myAutomaticPosition = Standard_False;
98 //=======================================================================
101 //=======================================================================
103 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
104 const Handle(Prs3d_Presentation)& aPresentation,
105 const Standard_Integer)
107 Handle(Geom_Curve) gcurv;
109 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
110 if (!AIS::ComputeGeometry (thechamfedge, gcurv, pfirst, plast))
113 Handle(Geom_Line) glin = Handle(Geom_Line)::DownCast (gcurv);
114 gp_Dir dir1 (glin->Position().Direction());
115 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
116 myDir = norm1.Crossed(dir1);
119 //-------------------------------------------------
120 // calcul d'une direction orthogonale a l'edge du
121 // chanfrein et dirigee vers l'ext. du contour
122 //-------------------------------------------------
125 // recup. d'une edge adjacente a l'edge du chanfrein
126 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
128 gp_Pnt pfirstnext,plastnext;
129 Handle(Geom_Line) glinnext;
130 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
133 gp_Vec v1(pfirst,plast);
135 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
136 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
138 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
139 gp_Vec crossvec = v1.Crossed(v2);
141 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
142 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
143 myDir.Reverse();*/ // myDir => donne a la creation
145 //--------------------------------------------
146 //Calcul du point de positionnement du texte
147 //--------------------------------------------
149 if (myAutomaticPosition) {
150 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
151 gp_Vec transVec(myDir);
153 curpos = myPntAttach.Translated(transVec);
156 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
162 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
163 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
164 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
165 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
166 //static Standard_Real minlength = 0.005;
167 //taille minimale de la dimension
169 if ( curpos.Distance(myPntAttach) < 5. ) {
170 gp_Vec transVec(myDir);
172 curpos = myPntAttach.Translated(transVec);
177 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
178 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
180 //-------------------------------------------------
181 //Calcul de la boite englobante du component pour
182 //determiner la taille de la fleche
183 //-------------------------------------------------
185 if( !myArrowSizeIsDefined ) {
186 Standard_Real arrsize = myArrowSize;
187 if ( (myVal/4) < arrsize)
191 else if (arrsize < 8.)
193 myArrowSize = arrsize;
195 arr->SetLength(myArrowSize);
197 //Calcul de la presentation
198 DsgPrs_Chamf2dPresentation::Add(aPresentation,
207 //=======================================================================
209 //purpose : to avoid warning
210 //=======================================================================
212 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
213 const Handle(Prs3d_Presentation)& aPresentation)
215 // throw Standard_NotImplemented("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
216 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
219 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
221 // throw Standard_NotImplemented("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
222 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
225 //=======================================================================
226 //function : ComputeSelection
228 //=======================================================================
230 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
231 const Standard_Integer)
233 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
234 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
235 aSelection->Add(seg);
238 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
239 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
243 myPosition.X() + size,
244 myPosition.Y() + size,
245 myPosition.Z() + size);
246 aSelection->Add(box);