1 // Created on: 1996-12-05
2 // Created by: Flore Lantheaume/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_Chamf2dDimension.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_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
74 const Handle(Geom_Plane)& aPlane,
75 const Standard_Real aVal,
76 const TCollection_ExtendedString& aText)
83 mySymbolPrs = DsgPrs_AS_LASTAR;
84 myAutomaticPosition = Standard_True;
86 myArrowSize = myVal / 100.;
88 //=======================================================================
89 //function : Constructor
91 //=======================================================================
92 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
93 const Handle(Geom_Plane)& aPlane,
94 const Standard_Real aVal,
95 const TCollection_ExtendedString& aText,
96 const gp_Pnt& aPosition,
97 const DsgPrs_ArrowSide aSymbolPrs ,
98 const Standard_Real anArrowSize)
105 myPosition = aPosition;
106 mySymbolPrs = aSymbolPrs;
108 SetArrowSize( anArrowSize );
110 myArrowSize = anArrowSize;
112 myAutomaticPosition = Standard_False;
116 //=======================================================================
119 //=======================================================================
121 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
122 const Handle(Prs3d_Presentation)& aPresentation,
123 const Standard_Integer)
125 aPresentation->Clear();
127 Handle(Geom_Line) glin;
129 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
130 if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) )
134 gp_Dir dir1 (glin->Position().Direction());
135 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
136 myDir = norm1.Crossed(dir1);
139 //-------------------------------------------------
140 // calcul d'une direction orthogonale a l'edge du
141 // chanfrein et dirigee vers l'ext. du contour
142 //-------------------------------------------------
145 // recup. d'une edge adjacente a l'edge du chanfrein
146 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
148 gp_Pnt pfirstnext,plastnext;
149 Handle(Geom_Line) glinnext;
150 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
153 gp_Vec v1(pfirst,plast);
155 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
156 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
158 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
159 gp_Vec crossvec = v1.Crossed(v2);
161 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
162 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
163 myDir.Reverse();*/ // myDir => donne a la creation
165 //--------------------------------------------
166 //Calcul du point de positionnement du texte
167 //--------------------------------------------
169 if (myAutomaticPosition) {
170 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
171 gp_Vec transVec(myDir);
173 curpos = myPntAttach.Translated(transVec);
176 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
182 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
183 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
184 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
185 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
186 //static Standard_Real minlength = 0.005;
187 //taille minimale de la dimension
189 if ( curpos.Distance(myPntAttach) < 5. ) {
190 gp_Vec transVec(myDir);
192 curpos = myPntAttach.Translated(transVec);
197 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
198 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
200 //-------------------------------------------------
201 //Calcul de la boite englobante du component pour
202 //determiner la taille de la fleche
203 //-------------------------------------------------
206 if( !myArrowSizeIsDefined ) {
208 Standard_Real arrsize = myArrowSize;
209 if ( (myVal/4) < arrsize)
213 else if (arrsize < 8.)
216 myArrowSize = arrsize;
218 arr->SetLength(myArrowSize);
220 arr->SetLength(arrsize);
223 //Calcul de la presentation
224 DsgPrs_Chamf2dPresentation::Add(aPresentation,
233 //=======================================================================
235 //purpose : to avoid warning
236 //=======================================================================
238 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
239 const Handle(Prs3d_Presentation)& aPresentation)
241 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
242 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
245 void AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
247 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
248 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
251 //=======================================================================
252 //function : ComputeSelection
254 //=======================================================================
256 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
257 const Standard_Integer)
259 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
260 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
261 aSelection->Add(seg);
264 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
265 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
269 myPosition.X() + size,
270 myPosition.Y() + size,
271 myPosition.Z() + size);
272 aSelection->Add(box);