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 #include <Standard_NotImplemented.hxx>
19 #include <AIS_Chamf2dDimension.ixx>
21 #include <DsgPrs_Chamf2dPresentation.hxx>
23 #include <Prs3d_ArrowAspect.hxx>
24 #include <Prs3d_DimensionAspect.hxx>
25 #include <Prs3d_Drawer.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
34 #include <TopAbs_Orientation.hxx>
36 #include <Bnd_Box.hxx>
37 #include <BRepBndLib.hxx>
43 #include <Geom_Line.hxx>
47 #include <Precision.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <TCollection_ExtendedString.hxx>
52 #include <BRepTools_WireExplorer.hxx>
55 #include <AIS_Drawer.hxx>
57 #include <BRepAdaptor_Surface.hxx>
58 #include <ProjLib.hxx>
59 #include <Select3D_SensitiveBox.hxx>
61 //=======================================================================
62 //function : Constructor
64 //=======================================================================
65 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
66 const Handle(Geom_Plane)& aPlane,
67 const Standard_Real aVal,
68 const TCollection_ExtendedString& aText)
75 mySymbolPrs = DsgPrs_AS_LASTAR;
76 myAutomaticPosition = Standard_True;
78 myArrowSize = myVal / 100.;
80 //=======================================================================
81 //function : Constructor
83 //=======================================================================
84 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
85 const Handle(Geom_Plane)& aPlane,
86 const Standard_Real aVal,
87 const TCollection_ExtendedString& aText,
88 const gp_Pnt& aPosition,
89 const DsgPrs_ArrowSide aSymbolPrs ,
90 const Standard_Real anArrowSize)
97 myPosition = aPosition;
98 mySymbolPrs = aSymbolPrs;
99 SetArrowSize( anArrowSize );
100 myAutomaticPosition = Standard_False;
104 //=======================================================================
107 //=======================================================================
109 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
110 const Handle(Prs3d_Presentation)& aPresentation,
111 const Standard_Integer)
113 aPresentation->Clear();
115 Handle(Geom_Line) glin;
117 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
118 if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) )
122 gp_Dir dir1 (glin->Position().Direction());
123 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
124 myDir = norm1.Crossed(dir1);
127 //-------------------------------------------------
128 // calcul d'une direction orthogonale a l'edge du
129 // chanfrein et dirigee vers l'ext. du contour
130 //-------------------------------------------------
133 // recup. d'une edge adjacente a l'edge du chanfrein
134 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
136 gp_Pnt pfirstnext,plastnext;
137 Handle(Geom_Line) glinnext;
138 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
141 gp_Vec v1(pfirst,plast);
143 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
144 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
146 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
147 gp_Vec crossvec = v1.Crossed(v2);
149 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
150 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
151 myDir.Reverse();*/ // myDir => donne a la creation
153 //--------------------------------------------
154 //Calcul du point de positionnement du texte
155 //--------------------------------------------
157 if (myAutomaticPosition) {
158 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
159 gp_Vec transVec(myDir);
161 curpos = myPntAttach.Translated(transVec);
164 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
170 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
171 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
172 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
173 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
174 //static Standard_Real minlength = 0.005;
175 //taille minimale de la dimension
177 if ( curpos.Distance(myPntAttach) < 5. ) {
178 gp_Vec transVec(myDir);
180 curpos = myPntAttach.Translated(transVec);
185 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
186 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
188 //-------------------------------------------------
189 //Calcul de la boite englobante du component pour
190 //determiner la taille de la fleche
191 //-------------------------------------------------
193 if( !myArrowSizeIsDefined ) {
194 Standard_Real arrsize = myArrowSize;
195 if ( (myVal/4) < arrsize)
199 else if (arrsize < 8.)
201 myArrowSize = arrsize;
203 arr->SetLength(myArrowSize);
205 //Calcul de la presentation
206 DsgPrs_Chamf2dPresentation::Add(aPresentation,
215 //=======================================================================
217 //purpose : to avoid warning
218 //=======================================================================
220 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
221 const Handle(Prs3d_Presentation)& aPresentation)
223 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
224 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
227 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
229 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
230 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
233 //=======================================================================
234 //function : ComputeSelection
236 //=======================================================================
238 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
239 const Standard_Integer)
241 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
242 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
243 aSelection->Add(seg);
246 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
247 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
251 myPosition.X() + size,
252 myPosition.Y() + size,
253 myPosition.Z() + size);
254 aSelection->Add(box);