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
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Graphic3d_Group.hxx>
20 #include <AIS_Relation.ixx>
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>
29 #include <Prs3d_Drawer.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_DimensionAspect.hxx>
32 #include <Prs3d_PointAspect.hxx>
33 #include <Prs3d_TextAspect.hxx>
35 #include <StdPrs_WFDeflectionShape.hxx>
36 #include <StdPrs_Point.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <gp_Circ.hxx>
47 #include <Precision.hxx>
48 #include <BRepBuilderAPI_MakeVertex.hxx>
50 //=======================================================================
51 //function : AIS_Relation
53 //=======================================================================
54 AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
55 :AIS_InteractiveObject(aTypeOfPresentation3d),
58 myArrowSize( myVal / 10. ),
59 myAutomaticPosition(Standard_True),
61 myFirstOffset(0.),mySecondOffset(0.),
62 myIsSetBndBox( Standard_False ),
63 myArrowSizeIsDefined( Standard_False)
69 //=======================================================================
70 //function : ComputeProjEdgePresentation
72 //=======================================================================
74 void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
75 const TopoDS_Edge& anEdge,
76 const Handle(Geom_Curve)& ProjCurv,
79 const Quantity_NameOfColor aColor,
80 const Standard_Real width,
81 const Aspect_TypeOfLine aProjTOL,
82 const Aspect_TypeOfLine aCallTOL) const
84 if (!myDrawer->HasOwnWireAspect()){
85 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
87 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
89 li->SetTypeOfLine(aProjTOL);
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));
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;
106 pf = ElCLib::Parameter(gl->Lin(),FirstP);
107 pl = ElCLib::Parameter(gl->Lin(),LastP);
108 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
112 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
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);
123 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
125 //Calcul de la presentation des lignes de raccord
126 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
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())
133 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
134 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
138 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
139 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
141 if (LastP.Distance( ppl ) > gp::Resolution())
143 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
144 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
148 BRepBuilderAPI_MakeVertex MakVert2( LastP );
149 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
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);
161 //=======================================================================
162 //function : ComputeProjVertexPresentation
164 //=======================================================================
166 void 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
174 if (!myDrawer->HasOwnPointAspect()){
175 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
177 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
178 pa->SetColor(aColor);
179 pa->SetTypeOfMarker(aProjTOM);
183 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
185 if (!myDrawer->HasOwnWireAspect()){
186 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
188 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
189 li->SetColor(aColor);
190 li->SetTypeOfLine(aCallTOL);
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);
202 //=======================================================================
203 //function : SetColor
205 //=======================================================================
207 void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
209 SetColor(Quantity_Color(aCol));
212 void AIS_Relation::SetColor(const Quantity_Color &aCol)
214 if(hasOwnColor && myOwnColor==aCol) return;
216 if (!myDrawer->HasOwnTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
217 hasOwnColor=Standard_True;
219 myDrawer->TextAspect()->SetColor(aCol);
221 Standard_Real WW = HasWidth()? Width(): myDrawer->HasLink() ?
222 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
223 if (!myDrawer->HasOwnLineAspect()) {
224 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
226 if (!myDrawer->HasOwnDimensionAspect()) {
227 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
230 myDrawer->LineAspect()->SetColor(aCol);
231 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
232 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
233 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
235 DIMENSION->SetLineAspect(LINE);
236 DIMENSION->SetTextAspect(TEXT);
239 //=======================================================================
240 //function : UnsetColor
242 //=======================================================================
243 void AIS_Relation::UnsetColor()
245 if (!hasOwnColor) return;
246 hasOwnColor = Standard_False;
247 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
248 Quantity_Color CC = Quantity_NOC_YELLOW;
249 if (myDrawer->HasLink())
251 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
252 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
255 myDrawer->DimensionAspect()->SetLineAspect(LA);
258 //=======================================================================
259 //function : AcceptDisplayMode
261 //=======================================================================
263 Standard_Boolean AIS_Relation::
264 AcceptDisplayMode(const Standard_Integer aMode) const
268 //=======================================================================
269 //function : SetFirstShape
271 //=======================================================================
273 void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
279 //=======================================================================
280 //function : SetSecondShape
282 //=======================================================================
284 void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
289 //=======================================================================
290 //function : KindOfDimension
292 //=======================================================================
293 AIS_KindOfDimension AIS_Relation::KindOfDimension() const
294 {return AIS_KOD_NONE;}
296 //=======================================================================
297 //function : IsMovable
299 //=======================================================================
300 Standard_Boolean AIS_Relation::IsMovable() const
301 {return Standard_False;}