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