0025853: Edges disappear or reappear when displaying new edges
[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
22#include <AIS_Drawer.hxx>
23#include <AIS_GraphicTool.hxx>
24#include <BRepBuilderAPI_MakeEdge.hxx>
25#include <BRep_Tool.hxx>
26#include <Geom_Circle.hxx>
27#include <Geom_Line.hxx>
28#include <Geom_CartesianPoint.hxx>
29
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{
84 if (!myDrawer->HasWireAspect()){
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)) ) {
104 const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv;
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)) ) {
117 const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv;
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{
174 if (!myDrawer->HasPointAspect()){
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
185 if (!myDrawer->HasWireAspect()){
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
216 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
217 hasOwnColor=Standard_True;
218 myOwnColor=aCol;
219 myDrawer->TextAspect()->SetColor(aCol);
220
221 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
222 if (!myDrawer->HasLineAspect()) {
223 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
224 }
a6eb515f 225 if (!myDrawer->HasDimensionAspect()) {
226 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
7fd59977 227 }
a6eb515f 228
7fd59977 229 myDrawer->LineAspect()->SetColor(aCol);
a6eb515f 230 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
7fd59977 231 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
232 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
233
a6eb515f 234 DIMENSION->SetLineAspect(LINE);
235 DIMENSION->SetTextAspect(TEXT);
7fd59977 236}
237
238//=======================================================================
239//function : UnsetColor
240//purpose :
241//=======================================================================
242void AIS_Relation::UnsetColor()
243{
244 if (!hasOwnColor) return;
245 hasOwnColor = Standard_False;
246 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
7fd59977 247 Quantity_Color CC;
248 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
249 LA->SetColor(CC);
a6eb515f 250 myDrawer->DimensionAspect()->SetLineAspect(LA);
7fd59977 251 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
252}
253
254//=======================================================================
255//function : AcceptDisplayMode
256//purpose :
257//=======================================================================
258
259 Standard_Boolean AIS_Relation::
260AcceptDisplayMode(const Standard_Integer aMode) const
261{return aMode == 0;}
262
263
264//=======================================================================
265//function : SetFirstShape
266//purpose :
267//=======================================================================
268
269void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
270{
271 myFShape = aFShape;
272}
273
274
275//=======================================================================
276//function : SetSecondShape
277//purpose :
278//=======================================================================
279
280void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
281{
282 mySShape = aSShape;
283}
284
285//=======================================================================
286//function : KindOfDimension
287//purpose :
288//=======================================================================
289AIS_KindOfDimension AIS_Relation::KindOfDimension() const
290{return AIS_KOD_NONE;}
291
292//=======================================================================
293//function : IsMovable
294//purpose :
295//=======================================================================
296Standard_Boolean AIS_Relation::IsMovable() const
297{return Standard_False;}
298
299