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