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.
17 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
18 // if any in all dimensions.
20 #include <Standard_NotImplemented.hxx>
22 #include <AIS_Chamf2dDimension.ixx>
24 #include <DsgPrs_Chamf2dPresentation.hxx>
26 #include <Prs3d_ArrowAspect.hxx>
27 #include <Prs3d_DimensionAspect.hxx>
28 #include <Prs3d_Drawer.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <Select3D_SensitiveSegment.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
37 #include <TopAbs_Orientation.hxx>
39 #include <Bnd_Box.hxx>
40 #include <BRepBndLib.hxx>
46 #include <Geom_Line.hxx>
50 #include <Precision.hxx>
52 #include <TCollection_AsciiString.hxx>
53 #include <TCollection_ExtendedString.hxx>
55 #include <BRepTools_WireExplorer.hxx>
58 #include <AIS_Drawer.hxx>
60 #include <BRepAdaptor_Surface.hxx>
61 #include <ProjLib.hxx>
62 #include <Select3D_SensitiveBox.hxx>
64 //=======================================================================
65 //function : Constructor
67 //=======================================================================
68 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
69 const Handle(Geom_Plane)& aPlane,
70 const Standard_Real aVal,
71 const TCollection_ExtendedString& aText)
78 mySymbolPrs = DsgPrs_AS_LASTAR;
79 myAutomaticPosition = Standard_True;
81 myArrowSize = myVal / 100.;
83 //=======================================================================
84 //function : Constructor
86 //=======================================================================
87 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
88 const Handle(Geom_Plane)& aPlane,
89 const Standard_Real aVal,
90 const TCollection_ExtendedString& aText,
91 const gp_Pnt& aPosition,
92 const DsgPrs_ArrowSide aSymbolPrs ,
93 const Standard_Real anArrowSize)
100 myPosition = aPosition;
101 mySymbolPrs = aSymbolPrs;
103 SetArrowSize( anArrowSize );
105 myArrowSize = anArrowSize;
107 myAutomaticPosition = Standard_False;
111 //=======================================================================
114 //=======================================================================
116 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
117 const Handle(Prs3d_Presentation)& aPresentation,
118 const Standard_Integer)
120 aPresentation->Clear();
122 Handle(Geom_Line) glin;
124 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
125 if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) )
129 gp_Dir dir1 (glin->Position().Direction());
130 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
131 myDir = norm1.Crossed(dir1);
134 //-------------------------------------------------
135 // calcul d'une direction orthogonale a l'edge du
136 // chanfrein et dirigee vers l'ext. du contour
137 //-------------------------------------------------
140 // recup. d'une edge adjacente a l'edge du chanfrein
141 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
143 gp_Pnt pfirstnext,plastnext;
144 Handle(Geom_Line) glinnext;
145 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
148 gp_Vec v1(pfirst,plast);
150 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
151 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
153 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
154 gp_Vec crossvec = v1.Crossed(v2);
156 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
157 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
158 myDir.Reverse();*/ // myDir => donne a la creation
160 //--------------------------------------------
161 //Calcul du point de positionnement du texte
162 //--------------------------------------------
164 if (myAutomaticPosition) {
165 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
166 gp_Vec transVec(myDir);
168 curpos = myPntAttach.Translated(transVec);
171 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
177 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
178 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
179 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
180 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
181 //static Standard_Real minlength = 0.005;
182 //taille minimale de la dimension
184 if ( curpos.Distance(myPntAttach) < 5. ) {
185 gp_Vec transVec(myDir);
187 curpos = myPntAttach.Translated(transVec);
192 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
193 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
195 //-------------------------------------------------
196 //Calcul de la boite englobante du component pour
197 //determiner la taille de la fleche
198 //-------------------------------------------------
201 if( !myArrowSizeIsDefined ) {
203 Standard_Real arrsize = myArrowSize;
204 if ( (myVal/4) < arrsize)
208 else if (arrsize < 8.)
211 myArrowSize = arrsize;
213 arr->SetLength(myArrowSize);
215 arr->SetLength(arrsize);
218 //Calcul de la presentation
219 DsgPrs_Chamf2dPresentation::Add(aPresentation,
228 //=======================================================================
230 //purpose : to avoid warning
231 //=======================================================================
233 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
234 const Handle(Prs3d_Presentation)& aPresentation)
236 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
237 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
240 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
242 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
243 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
246 //=======================================================================
247 //function : ComputeSelection
249 //=======================================================================
251 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
252 const Standard_Integer)
254 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
255 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
256 aSelection->Add(seg);
259 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
260 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
264 myPosition.X() + size,
265 myPosition.Y() + size,
266 myPosition.Z() + size);
267 aSelection->Add(box);