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