1 // File: AIS_Relation.cxx
2 // Created: Tue Dec 5 15:09:04 1996
3 // Author: Odile Olivier
6 #define GER61351 //GG_171199 Enable to set an object RGB color
7 // instead a restricted object NameOfColor.
9 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
10 // if any in all dimensions.
13 #include <Graphic3d_Array1OfVertex.hxx>
14 #include <Graphic3d_Group.hxx>
16 #include <AIS_Relation.ixx>
18 #include <AIS_Drawer.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <BRepBuilderAPI_MakeEdge.hxx>
21 #include <BRep_Tool.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Line.hxx>
24 #include <Geom_CartesianPoint.hxx>
26 #include <Prs3d_LineAspect.hxx>
27 #include <Prs3d_AngleAspect.hxx>
28 #include <Prs3d_PointAspect.hxx>
29 #include <Prs3d_LengthAspect.hxx>
30 #include <Prs3d_TextAspect.hxx>
32 #include <StdPrs_WFDeflectionShape.hxx>
33 #include <StdPrs_Point.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <gp_Circ.hxx>
44 #include <Precision.hxx>
45 #include <BRepBuilderAPI_MakeVertex.hxx>
47 //=======================================================================
48 //function : AIS_Relation
50 //=======================================================================
51 AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
52 :AIS_InteractiveObject(aTypeOfPresentation3d),
56 myArrowSize( myVal / 10. ),
58 myAutomaticPosition(Standard_True),
60 myFirstOffset(0.),mySecondOffset(0.),
61 myIsSetBndBox( Standard_False )
63 ,myArrowSizeIsDefined( Standard_False)
70 //=======================================================================
71 //function : ComputeProjEdgePresentation
73 //=======================================================================
75 void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
76 const TopoDS_Edge& anEdge,
77 const Handle(Geom_Curve)& ProjCurv,
80 const Quantity_NameOfColor aColor,
81 const Standard_Real width,
82 const Aspect_TypeOfLine aProjTOL,
83 const Aspect_TypeOfLine aCallTOL) const
85 if (!myDrawer->HasWireAspect()){
86 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
88 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
90 li->SetTypeOfLine(aProjTOL);
96 Handle(Geom_Curve) curve;
97 Standard_Boolean isInfinite;
98 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
99 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
103 // Calcul de la presentation de l'edge
104 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
105 const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv;
107 pf = ElCLib::Parameter(gl->Lin(),FirstP);
108 pl = ElCLib::Parameter(gl->Lin(),LastP);
109 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
113 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
117 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
118 const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv;
119 pf = ElCLib::Parameter(gc->Circ(),FirstP);
120 pl = ElCLib::Parameter(gc->Circ(),LastP);
121 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
124 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
126 //Calcul de la presentation des lignes de raccord
127 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
130 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
131 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
132 if (FirstP.Distance( ppf ) > gp::Resolution())
134 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
135 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
139 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
140 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
142 if (LastP.Distance( ppl ) > gp::Resolution())
144 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
145 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
149 BRepBuilderAPI_MakeVertex MakVert2( LastP );
150 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
153 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
154 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
155 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
156 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
162 //=======================================================================
163 //function : ComputeProjVertexPresentation
165 //=======================================================================
167 void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
168 const TopoDS_Vertex& aVertex,
169 const gp_Pnt& ProjPoint,
170 const Quantity_NameOfColor aColor,
171 const Standard_Real width,
172 const Aspect_TypeOfMarker aProjTOM,
173 const Aspect_TypeOfLine aCallTOL) const
175 if (!myDrawer->HasPointAspect()){
176 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
178 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
179 pa->SetColor(aColor);
180 pa->SetTypeOfMarker(aProjTOM);
184 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
186 if (!myDrawer->HasWireAspect()){
187 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
189 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
190 li->SetColor(aColor);
191 li->SetTypeOfLine(aCallTOL);
195 // Si les points ne sont pas confondus...
196 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
197 // calcul des lignes de rappel
198 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
199 StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer);
203 //=======================================================================
204 //function : SetColor
206 //=======================================================================
208 void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
211 SetColor(Quantity_Color(aCol));
214 void AIS_Relation::SetColor(const Quantity_Color &aCol)
217 if(hasOwnColor && myOwnColor==aCol) return;
219 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
220 hasOwnColor=Standard_True;
222 myDrawer->TextAspect()->SetColor(aCol);
224 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
225 if (!myDrawer->HasLineAspect()) {
226 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
228 if (!myDrawer->HasLengthAspect()) {
229 myDrawer->SetLengthAspect(new Prs3d_LengthAspect);
231 if (!myDrawer->HasAngleAspect()) {
232 myDrawer->SetAngleAspect(new Prs3d_AngleAspect);
234 myDrawer->LineAspect()->SetColor(aCol);
235 const Handle(Prs3d_LengthAspect)& LENGTH = myDrawer->LengthAspect();
236 const Handle(Prs3d_AngleAspect)& ANGLE = myDrawer->AngleAspect();
237 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
238 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
240 LENGTH->SetLineAspect(LINE);
241 LENGTH->SetTextAspect(TEXT);
242 ANGLE->SetLineAspect(LINE);
243 ANGLE->SetTextAspect(TEXT);
246 //=======================================================================
247 //function : UnsetColor
249 //=======================================================================
250 void AIS_Relation::UnsetColor()
252 if (!hasOwnColor) return;
253 hasOwnColor = Standard_False;
254 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
257 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
260 LA->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line));
262 myDrawer->AngleAspect()->SetLineAspect(LA);
263 myDrawer->LengthAspect()->SetLineAspect(LA);
264 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
267 //=======================================================================
268 //function : AcceptDisplayMode
270 //=======================================================================
272 Standard_Boolean AIS_Relation::
273 AcceptDisplayMode(const Standard_Integer aMode) const
277 //=======================================================================
278 //function : SetFirstShape
280 //=======================================================================
282 void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
288 //=======================================================================
289 //function : SetSecondShape
291 //=======================================================================
293 void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
298 //=======================================================================
299 //function : KindOfDimension
301 //=======================================================================
302 AIS_KindOfDimension AIS_Relation::KindOfDimension() const
303 {return AIS_KOD_NONE;}
305 //=======================================================================
306 //function : IsMovable
308 //=======================================================================
309 Standard_Boolean AIS_Relation::IsMovable() const
310 {return Standard_False;}