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 <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_Chamf2dDimension,AIS_Relation)
54 //=======================================================================
55 //function : Constructor
57 //=======================================================================
58 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
59 const Handle(Geom_Plane)& aPlane,
60 const Standard_Real aVal,
61 const TCollection_ExtendedString& aText)
68 mySymbolPrs = DsgPrs_AS_LASTAR;
69 myAutomaticPosition = Standard_True;
71 myArrowSize = myVal / 100.;
73 //=======================================================================
74 //function : Constructor
76 //=======================================================================
77 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
78 const Handle(Geom_Plane)& aPlane,
79 const Standard_Real aVal,
80 const TCollection_ExtendedString& aText,
81 const gp_Pnt& aPosition,
82 const DsgPrs_ArrowSide aSymbolPrs ,
83 const Standard_Real anArrowSize)
90 myPosition = aPosition;
91 mySymbolPrs = aSymbolPrs;
92 SetArrowSize( anArrowSize );
93 myAutomaticPosition = Standard_False;
97 //=======================================================================
100 //=======================================================================
102 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
103 const Handle(Prs3d_Presentation)& aPresentation,
104 const Standard_Integer)
106 Handle(Geom_Curve) gcurv;
108 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
109 if (!AIS::ComputeGeometry (thechamfedge, gcurv, pfirst, plast))
112 Handle(Geom_Line) glin = Handle(Geom_Line)::DownCast (gcurv);
113 gp_Dir dir1 (glin->Position().Direction());
114 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
115 myDir = norm1.Crossed(dir1);
118 //-------------------------------------------------
119 // calcul d'une direction orthogonale a l'edge du
120 // chanfrein et dirigee vers l'ext. du contour
121 //-------------------------------------------------
124 // recup. d'une edge adjacente a l'edge du chanfrein
125 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
127 gp_Pnt pfirstnext,plastnext;
128 Handle(Geom_Line) glinnext;
129 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
132 gp_Vec v1(pfirst,plast);
134 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
135 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
137 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
138 gp_Vec crossvec = v1.Crossed(v2);
140 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
141 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
142 myDir.Reverse();*/ // myDir => donne a la creation
144 //--------------------------------------------
145 //Calcul du point de positionnement du texte
146 //--------------------------------------------
148 if (myAutomaticPosition) {
149 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
150 gp_Vec transVec(myDir);
152 curpos = myPntAttach.Translated(transVec);
155 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
161 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
162 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
163 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
164 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
165 //static Standard_Real minlength = 0.005;
166 //taille minimale de la dimension
168 if ( curpos.Distance(myPntAttach) < 5. ) {
169 gp_Vec transVec(myDir);
171 curpos = myPntAttach.Translated(transVec);
176 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
177 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
179 //-------------------------------------------------
180 //Calcul de la boite englobante du component pour
181 //determiner la taille de la fleche
182 //-------------------------------------------------
184 if( !myArrowSizeIsDefined ) {
185 Standard_Real arrsize = myArrowSize;
186 if ( (myVal/4) < arrsize)
190 else if (arrsize < 8.)
192 myArrowSize = arrsize;
194 arr->SetLength(myArrowSize);
196 //Calcul de la presentation
197 DsgPrs_Chamf2dPresentation::Add(aPresentation,
206 //=======================================================================
207 //function : ComputeSelection
209 //=======================================================================
211 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
212 const Standard_Integer)
214 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
215 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
216 aSelection->Add(seg);
219 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
220 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
224 myPosition.X() + size,
225 myPosition.Y() + size,
226 myPosition.Z() + size);
227 aSelection->Add(box);