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.
17 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
19 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
20 // if any in all dimensions.
23 #include <Graphic3d_Group.hxx>
25 #include <AIS_Relation.ixx>
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>
35 #include <Prs3d_LineAspect.hxx>
36 #include <Prs3d_DimensionAspect.hxx>
37 #include <Prs3d_PointAspect.hxx>
38 #include <Prs3d_TextAspect.hxx>
40 #include <StdPrs_WFDeflectionShape.hxx>
41 #include <StdPrs_Point.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <gp_Circ.hxx>
52 #include <Precision.hxx>
53 #include <BRepBuilderAPI_MakeVertex.hxx>
55 //=======================================================================
56 //function : AIS_Relation
58 //=======================================================================
59 AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
60 :AIS_InteractiveObject(aTypeOfPresentation3d),
64 myArrowSize( myVal / 10. ),
66 myAutomaticPosition(Standard_True),
68 myFirstOffset(0.),mySecondOffset(0.),
69 myIsSetBndBox( Standard_False )
71 ,myArrowSizeIsDefined( Standard_False)
78 //=======================================================================
79 //function : ComputeProjEdgePresentation
81 //=======================================================================
83 void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
84 const TopoDS_Edge& anEdge,
85 const Handle(Geom_Curve)& ProjCurv,
88 const Quantity_NameOfColor aColor,
89 const Standard_Real width,
90 const Aspect_TypeOfLine aProjTOL,
91 const Aspect_TypeOfLine aCallTOL) const
93 if (!myDrawer->HasWireAspect()){
94 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
96 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
98 li->SetTypeOfLine(aProjTOL);
102 Standard_Real pf, pl;
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));
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;
115 pf = ElCLib::Parameter(gl->Lin(),FirstP);
116 pl = ElCLib::Parameter(gl->Lin(),LastP);
117 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
121 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
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);
132 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
134 //Calcul de la presentation des lignes de raccord
135 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
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())
142 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
143 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
147 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
148 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
150 if (LastP.Distance( ppl ) > gp::Resolution())
152 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
153 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
157 BRepBuilderAPI_MakeVertex MakVert2( LastP );
158 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
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);
170 //=======================================================================
171 //function : ComputeProjVertexPresentation
173 //=======================================================================
175 void 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
183 if (!myDrawer->HasPointAspect()){
184 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
186 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
187 pa->SetColor(aColor);
188 pa->SetTypeOfMarker(aProjTOM);
192 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
194 if (!myDrawer->HasWireAspect()){
195 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
197 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
198 li->SetColor(aColor);
199 li->SetTypeOfLine(aCallTOL);
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);
211 //=======================================================================
212 //function : SetColor
214 //=======================================================================
216 void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
218 SetColor(Quantity_Color(aCol));
221 void AIS_Relation::SetColor(const Quantity_Color &aCol)
223 if(hasOwnColor && myOwnColor==aCol) return;
225 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
226 hasOwnColor=Standard_True;
228 myDrawer->TextAspect()->SetColor(aCol);
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));
234 if (!myDrawer->HasDimensionAspect()) {
235 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
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();
243 DIMENSION->SetLineAspect(LINE);
244 DIMENSION->SetTextAspect(TEXT);
247 //=======================================================================
248 //function : UnsetColor
250 //=======================================================================
251 void AIS_Relation::UnsetColor()
253 if (!hasOwnColor) return;
254 hasOwnColor = Standard_False;
255 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
257 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
259 myDrawer->DimensionAspect()->SetLineAspect(LA);
260 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
263 //=======================================================================
264 //function : AcceptDisplayMode
266 //=======================================================================
268 Standard_Boolean AIS_Relation::
269 AcceptDisplayMode(const Standard_Integer aMode) const
273 //=======================================================================
274 //function : SetFirstShape
276 //=======================================================================
278 void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
284 //=======================================================================
285 //function : SetSecondShape
287 //=======================================================================
289 void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
294 //=======================================================================
295 //function : KindOfDimension
297 //=======================================================================
298 AIS_KindOfDimension AIS_Relation::KindOfDimension() const
299 {return AIS_KOD_NONE;}
301 //=======================================================================
302 //function : IsMovable
304 //=======================================================================
305 Standard_Boolean AIS_Relation::IsMovable() const
306 {return Standard_False;}