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 #define GER61351 //GG_171199 Enable to set an object RGB color
23 // instead a restricted object NameOfColor.
25 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
26 // if any in all dimensions.
29 #include <Graphic3d_Array1OfVertex.hxx>
30 #include <Graphic3d_Group.hxx>
32 #include <AIS_Relation.ixx>
34 #include <AIS_Drawer.hxx>
35 #include <AIS_GraphicTool.hxx>
36 #include <BRepBuilderAPI_MakeEdge.hxx>
37 #include <BRep_Tool.hxx>
38 #include <Geom_Circle.hxx>
39 #include <Geom_Line.hxx>
40 #include <Geom_CartesianPoint.hxx>
42 #include <Prs3d_LineAspect.hxx>
43 #include <Prs3d_AngleAspect.hxx>
44 #include <Prs3d_PointAspect.hxx>
45 #include <Prs3d_LengthAspect.hxx>
46 #include <Prs3d_TextAspect.hxx>
48 #include <StdPrs_WFDeflectionShape.hxx>
49 #include <StdPrs_Point.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <gp_Circ.hxx>
60 #include <Precision.hxx>
61 #include <BRepBuilderAPI_MakeVertex.hxx>
63 //=======================================================================
64 //function : AIS_Relation
66 //=======================================================================
67 AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
68 :AIS_InteractiveObject(aTypeOfPresentation3d),
72 myArrowSize( myVal / 10. ),
74 myAutomaticPosition(Standard_True),
76 myFirstOffset(0.),mySecondOffset(0.),
77 myIsSetBndBox( Standard_False )
79 ,myArrowSizeIsDefined( Standard_False)
86 //=======================================================================
87 //function : ComputeProjEdgePresentation
89 //=======================================================================
91 void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
92 const TopoDS_Edge& anEdge,
93 const Handle(Geom_Curve)& ProjCurv,
96 const Quantity_NameOfColor aColor,
97 const Standard_Real width,
98 const Aspect_TypeOfLine aProjTOL,
99 const Aspect_TypeOfLine aCallTOL) const
101 if (!myDrawer->HasWireAspect()){
102 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
104 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
105 li->SetColor(aColor);
106 li->SetTypeOfLine(aProjTOL);
110 Standard_Real pf, pl;
112 Handle(Geom_Curve) curve;
113 Standard_Boolean isInfinite;
114 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
115 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
119 // Calcul de la presentation de l'edge
120 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
121 const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv;
123 pf = ElCLib::Parameter(gl->Lin(),FirstP);
124 pl = ElCLib::Parameter(gl->Lin(),LastP);
125 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
129 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
133 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
134 const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv;
135 pf = ElCLib::Parameter(gc->Circ(),FirstP);
136 pl = ElCLib::Parameter(gc->Circ(),LastP);
137 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
140 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
142 //Calcul de la presentation des lignes de raccord
143 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
146 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
147 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
148 if (FirstP.Distance( ppf ) > gp::Resolution())
150 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
151 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
155 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
156 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
158 if (LastP.Distance( ppl ) > gp::Resolution())
160 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
161 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
165 BRepBuilderAPI_MakeVertex MakVert2( LastP );
166 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
169 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
170 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
171 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
172 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
178 //=======================================================================
179 //function : ComputeProjVertexPresentation
181 //=======================================================================
183 void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
184 const TopoDS_Vertex& aVertex,
185 const gp_Pnt& ProjPoint,
186 const Quantity_NameOfColor aColor,
187 const Standard_Real width,
188 const Aspect_TypeOfMarker aProjTOM,
189 const Aspect_TypeOfLine aCallTOL) const
191 if (!myDrawer->HasPointAspect()){
192 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
194 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
195 pa->SetColor(aColor);
196 pa->SetTypeOfMarker(aProjTOM);
200 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
202 if (!myDrawer->HasWireAspect()){
203 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
205 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
206 li->SetColor(aColor);
207 li->SetTypeOfLine(aCallTOL);
211 // Si les points ne sont pas confondus...
212 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
213 // calcul des lignes de rappel
214 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
215 StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer);
219 //=======================================================================
220 //function : SetColor
222 //=======================================================================
224 void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
227 SetColor(Quantity_Color(aCol));
230 void AIS_Relation::SetColor(const Quantity_Color &aCol)
233 if(hasOwnColor && myOwnColor==aCol) return;
235 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
236 hasOwnColor=Standard_True;
238 myDrawer->TextAspect()->SetColor(aCol);
240 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
241 if (!myDrawer->HasLineAspect()) {
242 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
244 if (!myDrawer->HasLengthAspect()) {
245 myDrawer->SetLengthAspect(new Prs3d_LengthAspect);
247 if (!myDrawer->HasAngleAspect()) {
248 myDrawer->SetAngleAspect(new Prs3d_AngleAspect);
250 myDrawer->LineAspect()->SetColor(aCol);
251 const Handle(Prs3d_LengthAspect)& LENGTH = myDrawer->LengthAspect();
252 const Handle(Prs3d_AngleAspect)& ANGLE = myDrawer->AngleAspect();
253 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
254 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
256 LENGTH->SetLineAspect(LINE);
257 LENGTH->SetTextAspect(TEXT);
258 ANGLE->SetLineAspect(LINE);
259 ANGLE->SetTextAspect(TEXT);
262 //=======================================================================
263 //function : UnsetColor
265 //=======================================================================
266 void AIS_Relation::UnsetColor()
268 if (!hasOwnColor) return;
269 hasOwnColor = Standard_False;
270 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
273 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
276 LA->SetColor(AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line));
278 myDrawer->AngleAspect()->SetLineAspect(LA);
279 myDrawer->LengthAspect()->SetLineAspect(LA);
280 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
283 //=======================================================================
284 //function : AcceptDisplayMode
286 //=======================================================================
288 Standard_Boolean AIS_Relation::
289 AcceptDisplayMode(const Standard_Integer aMode) const
293 //=======================================================================
294 //function : SetFirstShape
296 //=======================================================================
298 void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
304 //=======================================================================
305 //function : SetSecondShape
307 //=======================================================================
309 void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
314 //=======================================================================
315 //function : KindOfDimension
317 //=======================================================================
318 AIS_KindOfDimension AIS_Relation::KindOfDimension() const
319 {return AIS_KOD_NONE;}
321 //=======================================================================
322 //function : IsMovable
324 //=======================================================================
325 Standard_Boolean AIS_Relation::IsMovable() const
326 {return Standard_False;}