1 // Created on: 1996-12-05
2 // Created by: Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
24 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
25 // if any in all dimensions.
28 #include <Graphic3d_Group.hxx>
30 #include <AIS_Relation.ixx>
32 #include <AIS_Drawer.hxx>
33 #include <AIS_GraphicTool.hxx>
34 #include <BRepBuilderAPI_MakeEdge.hxx>
35 #include <BRep_Tool.hxx>
36 #include <Geom_Circle.hxx>
37 #include <Geom_Line.hxx>
38 #include <Geom_CartesianPoint.hxx>
40 #include <Prs3d_LineAspect.hxx>
41 #include <Prs3d_DimensionAspect.hxx>
42 #include <Prs3d_PointAspect.hxx>
43 #include <Prs3d_TextAspect.hxx>
45 #include <StdPrs_WFDeflectionShape.hxx>
46 #include <StdPrs_Point.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <gp_Circ.hxx>
57 #include <Precision.hxx>
58 #include <BRepBuilderAPI_MakeVertex.hxx>
60 //=======================================================================
61 //function : AIS_Relation
63 //=======================================================================
64 AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
65 :AIS_InteractiveObject(aTypeOfPresentation3d),
69 myArrowSize( myVal / 10. ),
71 myAutomaticPosition(Standard_True),
73 myFirstOffset(0.),mySecondOffset(0.),
74 myIsSetBndBox( Standard_False )
76 ,myArrowSizeIsDefined( Standard_False)
83 //=======================================================================
84 //function : ComputeProjEdgePresentation
86 //=======================================================================
88 void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
89 const TopoDS_Edge& anEdge,
90 const Handle(Geom_Curve)& ProjCurv,
93 const Quantity_NameOfColor aColor,
94 const Standard_Real width,
95 const Aspect_TypeOfLine aProjTOL,
96 const Aspect_TypeOfLine aCallTOL) const
98 if (!myDrawer->HasWireAspect()){
99 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
101 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
102 li->SetColor(aColor);
103 li->SetTypeOfLine(aProjTOL);
107 Standard_Real pf, pl;
109 Handle(Geom_Curve) curve;
110 Standard_Boolean isInfinite;
111 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
112 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
116 // Calcul de la presentation de l'edge
117 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
118 const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv;
120 pf = ElCLib::Parameter(gl->Lin(),FirstP);
121 pl = ElCLib::Parameter(gl->Lin(),LastP);
122 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
126 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
130 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
131 const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv;
132 pf = ElCLib::Parameter(gc->Circ(),FirstP);
133 pl = ElCLib::Parameter(gc->Circ(),LastP);
134 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
137 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
139 //Calcul de la presentation des lignes de raccord
140 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
143 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
144 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
145 if (FirstP.Distance( ppf ) > gp::Resolution())
147 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
148 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
152 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
153 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
155 if (LastP.Distance( ppl ) > gp::Resolution())
157 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
158 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
162 BRepBuilderAPI_MakeVertex MakVert2( LastP );
163 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
166 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
167 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
168 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
169 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
175 //=======================================================================
176 //function : ComputeProjVertexPresentation
178 //=======================================================================
180 void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
181 const TopoDS_Vertex& aVertex,
182 const gp_Pnt& ProjPoint,
183 const Quantity_NameOfColor aColor,
184 const Standard_Real width,
185 const Aspect_TypeOfMarker aProjTOM,
186 const Aspect_TypeOfLine aCallTOL) const
188 if (!myDrawer->HasPointAspect()){
189 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
191 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
192 pa->SetColor(aColor);
193 pa->SetTypeOfMarker(aProjTOM);
197 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
199 if (!myDrawer->HasWireAspect()){
200 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
202 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
203 li->SetColor(aColor);
204 li->SetTypeOfLine(aCallTOL);
208 // Si les points ne sont pas confondus...
209 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
210 // calcul des lignes de rappel
211 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
212 StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer);
216 //=======================================================================
217 //function : SetColor
219 //=======================================================================
221 void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
223 SetColor(Quantity_Color(aCol));
226 void AIS_Relation::SetColor(const Quantity_Color &aCol)
228 if(hasOwnColor && myOwnColor==aCol) return;
230 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
231 hasOwnColor=Standard_True;
233 myDrawer->TextAspect()->SetColor(aCol);
235 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
236 if (!myDrawer->HasLineAspect()) {
237 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
239 if (!myDrawer->HasDimensionAspect()) {
240 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
243 myDrawer->LineAspect()->SetColor(aCol);
244 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
245 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
246 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
248 DIMENSION->SetLineAspect(LINE);
249 DIMENSION->SetTextAspect(TEXT);
252 //=======================================================================
253 //function : UnsetColor
255 //=======================================================================
256 void AIS_Relation::UnsetColor()
258 if (!hasOwnColor) return;
259 hasOwnColor = Standard_False;
260 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
262 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
264 myDrawer->DimensionAspect()->SetLineAspect(LA);
265 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
268 //=======================================================================
269 //function : AcceptDisplayMode
271 //=======================================================================
273 Standard_Boolean AIS_Relation::
274 AcceptDisplayMode(const Standard_Integer aMode) const
278 //=======================================================================
279 //function : SetFirstShape
281 //=======================================================================
283 void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
289 //=======================================================================
290 //function : SetSecondShape
292 //=======================================================================
294 void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
299 //=======================================================================
300 //function : KindOfDimension
302 //=======================================================================
303 AIS_KindOfDimension AIS_Relation::KindOfDimension() const
304 {return AIS_KOD_NONE;}
306 //=======================================================================
307 //function : IsMovable
309 //=======================================================================
310 Standard_Boolean AIS_Relation::IsMovable() const
311 {return Standard_False;}