0024047: Exception in TPrsStd_AISPresentation during destruction of TDocStd_Document
[occt.git] / src / AIS / AIS_Chamf3dDimension.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Odile Olivier
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
23// if any in all dimensions.
24
25#include <Standard_NotImplemented.hxx>
26
27#include <AIS_Chamf3dDimension.ixx>
28
29#include <DsgPrs_Chamf2dPresentation.hxx>
30
31#include <Prs3d_ArrowAspect.hxx>
32#include <Prs3d_LengthAspect.hxx>
33#include <Prs3d_Drawer.hxx>
34
35#include <SelectMgr_EntityOwner.hxx>
36#include <Select3D_SensitiveSegment.hxx>
37
38#include <TopoDS.hxx>
39#include <TopoDS_Shape.hxx>
40#include <TopoDS_Edge.hxx>
41
42#include <TopAbs_Orientation.hxx>
43
44#include <Bnd_Box.hxx>
45#include <BRepBndLib.hxx>
46
47#include <gp_Dir.hxx>
48#include <gp_Pln.hxx>
49#include <gp_Vec.hxx>
50
51#include <Geom_Line.hxx>
52
53#include <ElCLib.hxx>
54
55#include <Precision.hxx>
56
57#include <TCollection_AsciiString.hxx>
58#include <TCollection_ExtendedString.hxx>
59
60#include <BRepTools_WireExplorer.hxx>
61
62#include <AIS.hxx>
63#include <AIS_Drawer.hxx>
64
65#include <BRepAdaptor_Surface.hxx>
66#include <ProjLib.hxx>
67#include <Select3D_SensitiveBox.hxx>
68
69//=======================================================================
70//function : Constructor
71//purpose :
72//=======================================================================
73AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
74 const Standard_Real aVal,
75 const TCollection_ExtendedString& aText)
76:AIS_Relation()
77{
78 myFShape = aFShape;
79 myVal = aVal;
80 myText = aText;
81 mySymbolPrs = DsgPrs_AS_LASTAR;
82 myAutomaticPosition = Standard_True;
83
84 myArrowSize = myVal / 100.;
85}
86//=======================================================================
87//function : Constructor
88//purpose :
89//=======================================================================
90AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
91 const Standard_Real aVal,
92 const TCollection_ExtendedString& aText,
93 const gp_Pnt& aPosition,
94 const DsgPrs_ArrowSide aSymbolPrs ,
95 const Standard_Real anArrowSize)
96:AIS_Relation()
97{
98 myFShape = aFShape;
99 myVal = aVal;
100 myText = aText;
101 myPosition = aPosition;
102 mySymbolPrs = aSymbolPrs;
103#ifdef BUC60915
104 SetArrowSize( anArrowSize );
105#else
106 myArrowSize = anArrowSize;
107#endif
108 myAutomaticPosition = Standard_False;
109}
110
111
112//=======================================================================
113//function : Compute
114//purpose :
115//=======================================================================
116
117void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
118 const Handle(Prs3d_Presentation)& aPresentation,
119 const Standard_Integer)
120{
121 aPresentation->Clear();
122
123 //----------------------------
124 // Calcul du centre de la face
125 //----------------------------
126 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
127 Standard_Real uFirst, uLast, vFirst, vLast;
128 uFirst = surfAlgo.FirstUParameter();
129 uLast = surfAlgo.LastUParameter();
130 vFirst = surfAlgo.FirstVParameter();
131 vLast = surfAlgo.LastVParameter();
132 Standard_Real uMoy = (uFirst + uLast)/2;
133 Standard_Real vMoy = (vFirst + vLast)/2;
134 gp_Pnt apos ;
135 gp_Vec d1u, d1v;
136 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
137 myPntAttach = apos;
138
139 myDir = d1u ^ d1v;
140// myDir = surfAlgo.Plane().Axis().Direction();
141
142
143
144
145 //--------------------------------------------
146 //Calcul du point de positionnement du texte
147 //--------------------------------------------
148 gp_Pnt curpos;
149 if (myAutomaticPosition) {
150 gp_Vec transVec(myDir);
151 transVec*=myVal;
152 curpos = myPntAttach.Translated(transVec);
153
154 if (myIsSetBndBox)
155 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
156
157 myPosition = curpos;
158 }
159 else {
160
161 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
162 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
163 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
164
165 if ( curpos.Distance(myPntAttach) < 5. ) {
166 gp_Vec transVec(myDir);
167 transVec*=5.;
168 curpos = myPntAttach.Translated(transVec);
169 }
170 myPosition = curpos;
171 }
172
173 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
174 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
175
176 //-------------------------------------------------
177 //Calcul de la boite englobante du component pour
178 //determiner la taille de la fleche
179 //-------------------------------------------------
180#ifdef BUC60915
181 if( !myArrowSizeIsDefined ) {
182#endif
183 Standard_Real arrsize = myArrowSize;
184 if ( (myVal/4) < arrsize)
185 arrsize = myVal/4;
186 if (arrsize > 30.)
187 arrsize = 30.;
188 else if (arrsize < 8.)
189 arrsize = 8.;
190#ifdef BUC60915
191 myArrowSize = arrsize;
192 }
193 arr->SetLength(myArrowSize);
194#else
195 arr->SetLength(arrsize);
196#endif
197
198 //Calcul de la presentation
199 DsgPrs_Chamf2dPresentation::Add(aPresentation,
200 myDrawer,
201 myPntAttach,
202 curpos,
203 myText,
204 mySymbolPrs);
205
206}
207
208//=======================================================================
209//function : Compute
210//purpose : to avoid warning
211//=======================================================================
212
213void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
214 const Handle(Prs3d_Presentation)& aPresentation)
215{
216// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
217 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
218}
219
7fd59977 220void AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
221{
222// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
223 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
224}
225
226//=======================================================================
227//function : ComputeSelection
228//purpose :
229//=======================================================================
230
231void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
232 const Standard_Integer)
233{
234 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
235 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
236 aSelection->Add(seg);
237
238 // Text
239 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
240 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
241 myPosition.X(),
242 myPosition.Y(),
243 myPosition.Z(),
244 myPosition.X() + size,
245 myPosition.Y() + size,
246 myPosition.Z() + size);
247 aSelection->Add(box);
248}
249