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