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