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 | |
b8ddfc2f |
22 | //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor. |
7fd59977 |
23 | |
24 | #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size |
25 | // if any in all dimensions. |
26 | |
27 | #include <AIS.hxx> |
7fd59977 |
28 | #include <Graphic3d_Group.hxx> |
29 | |
30 | #include <AIS_Relation.ixx> |
31 | |
32 | #include <AIS_Drawer.hxx> |
33 | #include <AIS_GraphicTool.hxx> |
34 | #include <BRepBuilderAPI_MakeEdge.hxx> |
35 | #include <BRep_Tool.hxx> |
36 | #include <Geom_Circle.hxx> |
37 | #include <Geom_Line.hxx> |
38 | #include <Geom_CartesianPoint.hxx> |
39 | |
40 | #include <Prs3d_LineAspect.hxx> |
41 | #include <Prs3d_AngleAspect.hxx> |
42 | #include <Prs3d_PointAspect.hxx> |
43 | #include <Prs3d_LengthAspect.hxx> |
44 | #include <Prs3d_TextAspect.hxx> |
45 | |
46 | #include <StdPrs_WFDeflectionShape.hxx> |
47 | #include <StdPrs_Point.hxx> |
48 | |
49 | #include <TopoDS.hxx> |
50 | #include <TopoDS_Edge.hxx> |
51 | #include <gp_Circ.hxx> |
52 | #include <gp_Lin.hxx> |
53 | #include <gp_Pnt.hxx> |
54 | #include <ElCLib.hxx> |
55 | #include <TopExp.hxx> |
56 | |
57 | |
58 | #include <Precision.hxx> |
59 | #include <BRepBuilderAPI_MakeVertex.hxx> |
60 | |
61 | //======================================================================= |
62 | //function : AIS_Relation |
63 | //purpose : |
64 | //======================================================================= |
65 | AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
66 | :AIS_InteractiveObject(aTypeOfPresentation3d), |
67 | myVal(1.), |
68 | myPosition(0.,0.,0.), |
69 | #ifdef BUC60915 |
70 | myArrowSize( myVal / 10. ), |
71 | #endif |
72 | myAutomaticPosition(Standard_True), |
73 | myExtShape(0), |
74 | myFirstOffset(0.),mySecondOffset(0.), |
75 | myIsSetBndBox( Standard_False ) |
76 | #ifdef BUC60915 |
77 | ,myArrowSizeIsDefined( Standard_False) |
78 | #endif |
79 | { |
80 | } |
81 | |
82 | |
83 | |
84 | //======================================================================= |
85 | //function : ComputeProjEdgePresentation |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs, |
90 | const TopoDS_Edge& anEdge, |
91 | const Handle(Geom_Curve)& ProjCurv, |
92 | const gp_Pnt& FirstP, |
93 | const gp_Pnt& LastP, |
94 | const Quantity_NameOfColor aColor, |
95 | const Standard_Real width, |
96 | const Aspect_TypeOfLine aProjTOL, |
97 | const Aspect_TypeOfLine aCallTOL) const |
98 | { |
99 | if (!myDrawer->HasWireAspect()){ |
100 | myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));} |
101 | else { |
102 | const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect(); |
103 | li->SetColor(aColor); |
104 | li->SetTypeOfLine(aProjTOL); |
105 | li->SetWidth(width); |
106 | } |
107 | |
108 | Standard_Real pf, pl; |
109 | TopLoc_Location loc; |
110 | Handle(Geom_Curve) curve; |
111 | Standard_Boolean isInfinite; |
112 | curve = BRep_Tool::Curve(anEdge,loc,pf,pl); |
113 | isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl)); |
114 | |
115 | TopoDS_Edge E; |
116 | |
117 | // Calcul de la presentation de l'edge |
118 | if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) { |
119 | const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv; |
120 | if ( !isInfinite) { |
121 | pf = ElCLib::Parameter(gl->Lin(),FirstP); |
122 | pl = ElCLib::Parameter(gl->Lin(),LastP); |
123 | BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl); |
124 | E = MakEd.Edge(); |
125 | } |
126 | else { |
127 | BRepBuilderAPI_MakeEdge MakEd(gl->Lin()); |
128 | E = MakEd.Edge(); |
129 | } |
130 | } |
131 | else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { |
132 | const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv; |
133 | pf = ElCLib::Parameter(gc->Circ(),FirstP); |
134 | pl = ElCLib::Parameter(gc->Circ(),LastP); |
135 | BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl); |
136 | E = MakEd.Edge(); |
137 | } |
138 | StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer); |
139 | |
140 | //Calcul de la presentation des lignes de raccord |
141 | myDrawer->WireAspect()->SetTypeOfLine(aCallTOL); |
142 | if (!isInfinite) { |
143 | gp_Pnt ppf, ppl; |
144 | ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge))); |
145 | ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge))); |
146 | if (FirstP.Distance( ppf ) > gp::Resolution()) |
147 | { |
148 | BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf); |
149 | StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer); |
150 | } |
151 | else |
152 | { |
153 | BRepBuilderAPI_MakeVertex MakVert1( FirstP ); |
154 | StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer); |
155 | } |
156 | if (LastP.Distance( ppl ) > gp::Resolution()) |
157 | { |
158 | BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl); |
159 | StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer); |
160 | } |
161 | else |
162 | { |
163 | BRepBuilderAPI_MakeVertex MakVert2( LastP ); |
164 | StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer); |
165 | } |
166 | /* |
167 | BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf); |
168 | StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer); |
169 | BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl); |
170 | StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer); |
171 | */ |
172 | } |
173 | } |
174 | |
175 | |
176 | //======================================================================= |
177 | //function : ComputeProjVertexPresentation |
178 | //purpose : |
179 | //======================================================================= |
180 | |
181 | void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs, |
182 | const TopoDS_Vertex& aVertex, |
183 | const gp_Pnt& ProjPoint, |
184 | const Quantity_NameOfColor aColor, |
185 | const Standard_Real width, |
186 | const Aspect_TypeOfMarker aProjTOM, |
187 | const Aspect_TypeOfLine aCallTOL) const |
188 | { |
189 | if (!myDrawer->HasPointAspect()){ |
190 | myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));} |
191 | else { |
192 | const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect(); |
193 | pa->SetColor(aColor); |
194 | pa->SetTypeOfMarker(aProjTOM); |
195 | } |
196 | |
197 | // calcul du projete |
198 | StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer); |
199 | |
200 | if (!myDrawer->HasWireAspect()){ |
201 | myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));} |
202 | else { |
203 | const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect(); |
204 | li->SetColor(aColor); |
205 | li->SetTypeOfLine(aCallTOL); |
206 | li->SetWidth(width); |
207 | } |
208 | |
209 | // Si les points ne sont pas confondus... |
210 | if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) { |
211 | // calcul des lignes de rappel |
212 | BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex)); |
213 | StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer); |
214 | } |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : SetColor |
219 | //purpose : |
220 | //======================================================================= |
221 | |
222 | void AIS_Relation::SetColor(const Quantity_NameOfColor aCol) |
7fd59977 |
223 | { |
224 | SetColor(Quantity_Color(aCol)); |
225 | } |
226 | |
227 | void AIS_Relation::SetColor(const Quantity_Color &aCol) |
7fd59977 |
228 | { |
229 | if(hasOwnColor && myOwnColor==aCol) return; |
230 | |
231 | if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect()); |
232 | hasOwnColor=Standard_True; |
233 | myOwnColor=aCol; |
234 | myDrawer->TextAspect()->SetColor(aCol); |
235 | |
236 | Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
237 | if (!myDrawer->HasLineAspect()) { |
238 | myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
239 | } |
240 | if (!myDrawer->HasLengthAspect()) { |
241 | myDrawer->SetLengthAspect(new Prs3d_LengthAspect); |
242 | } |
243 | if (!myDrawer->HasAngleAspect()) { |
244 | myDrawer->SetAngleAspect(new Prs3d_AngleAspect); |
245 | } |
246 | myDrawer->LineAspect()->SetColor(aCol); |
247 | const Handle(Prs3d_LengthAspect)& LENGTH = myDrawer->LengthAspect(); |
248 | const Handle(Prs3d_AngleAspect)& ANGLE = myDrawer->AngleAspect(); |
249 | const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect(); |
250 | const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect(); |
251 | |
252 | LENGTH->SetLineAspect(LINE); |
253 | LENGTH->SetTextAspect(TEXT); |
254 | ANGLE->SetLineAspect(LINE); |
255 | ANGLE->SetTextAspect(TEXT); |
256 | } |
257 | |
258 | //======================================================================= |
259 | //function : UnsetColor |
260 | //purpose : |
261 | //======================================================================= |
262 | void AIS_Relation::UnsetColor() |
263 | { |
264 | if (!hasOwnColor) return; |
265 | hasOwnColor = Standard_False; |
266 | const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect(); |
7fd59977 |
267 | Quantity_Color CC; |
268 | AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
269 | LA->SetColor(CC); |
7fd59977 |
270 | myDrawer->AngleAspect()->SetLineAspect(LA); |
271 | myDrawer->LengthAspect()->SetLineAspect(LA); |
272 | myDrawer->SetTextAspect(myDrawer->Link()->TextAspect()); |
273 | } |
274 | |
275 | //======================================================================= |
276 | //function : AcceptDisplayMode |
277 | //purpose : |
278 | //======================================================================= |
279 | |
280 | Standard_Boolean AIS_Relation:: |
281 | AcceptDisplayMode(const Standard_Integer aMode) const |
282 | {return aMode == 0;} |
283 | |
284 | |
285 | //======================================================================= |
286 | //function : SetFirstShape |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape) |
291 | { |
292 | myFShape = aFShape; |
293 | } |
294 | |
295 | |
296 | //======================================================================= |
297 | //function : SetSecondShape |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape) |
302 | { |
303 | mySShape = aSShape; |
304 | } |
305 | |
306 | //======================================================================= |
307 | //function : KindOfDimension |
308 | //purpose : |
309 | //======================================================================= |
310 | AIS_KindOfDimension AIS_Relation::KindOfDimension() const |
311 | {return AIS_KOD_NONE;} |
312 | |
313 | //======================================================================= |
314 | //function : IsMovable |
315 | //purpose : |
316 | //======================================================================= |
317 | Standard_Boolean AIS_Relation::IsMovable() const |
318 | {return Standard_False;} |
319 | |
320 | |