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 #include <PrsDim_Relation.hxx>
20 #include <AIS_GraphicTool.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepBuilderAPI_MakeEdge.hxx>
23 #include <BRepBuilderAPI_MakeVertex.hxx>
25 #include <Geom_CartesianPoint.hxx>
26 #include <Geom_Circle.hxx>
27 #include <Geom_Curve.hxx>
28 #include <Geom_Line.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Graphic3d_ArrayOfSegments.hxx>
32 #include <gp_Circ.hxx>
35 #include <Graphic3d_Group.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_DimensionAspect.hxx>
38 #include <Prs3d_Drawer.hxx>
39 #include <Prs3d_LineAspect.hxx>
40 #include <Prs3d_PointAspect.hxx>
41 #include <Prs3d_Presentation.hxx>
42 #include <Prs3d_TextAspect.hxx>
43 #include <Quantity_Color.hxx>
44 #include <StdPrs_Point.hxx>
45 #include <StdPrs_WFShape.hxx>
46 #include <TCollection_ExtendedString.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Shape.hxx>
51 #include <TopoDS_Vertex.hxx>
53 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_Relation, AIS_InteractiveObject)
55 //=======================================================================
56 //function : PrsDim_Relation
58 //=======================================================================
59 PrsDim_Relation::PrsDim_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
60 :AIS_InteractiveObject(aTypeOfPresentation3d),
63 myArrowSize( myVal / 10. ),
64 myAutomaticPosition(Standard_True),
66 myFirstOffset(0.),mySecondOffset(0.),
67 myIsSetBndBox( Standard_False ),
68 myArrowSizeIsDefined( Standard_False)
72 //=======================================================================
73 //function : ComputeProjEdgePresentation
75 //=======================================================================
77 void PrsDim_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
78 const TopoDS_Edge& anEdge,
79 const Handle(Geom_Curve)& ProjCurv,
82 const Quantity_NameOfColor aColor,
83 const Standard_Real width,
84 const Aspect_TypeOfLine aProjTOL,
85 const Aspect_TypeOfLine aCallTOL) const
87 if (!myDrawer->HasOwnWireAspect()){
88 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
90 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
92 li->SetTypeOfLine(aProjTOL);
98 Handle(Geom_Curve) curve;
99 Standard_Boolean isInfinite;
100 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
101 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
105 // Calcul de la presentation de l'edge
106 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
107 Handle(Geom_Line) gl (Handle(Geom_Line)::DownCast (ProjCurv));
109 pf = ElCLib::Parameter(gl->Lin(),FirstP);
110 pl = ElCLib::Parameter(gl->Lin(),LastP);
111 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
115 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
119 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
120 Handle(Geom_Circle) gc (Handle(Geom_Circle)::DownCast (ProjCurv));
121 pf = ElCLib::Parameter(gc->Circ(),FirstP);
122 pl = ElCLib::Parameter(gc->Circ(),LastP);
123 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
126 StdPrs_WFShape::Add (aPrs, E, myDrawer);
128 //Calcul de la presentation des lignes de raccord
129 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
132 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
133 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
134 if (FirstP.Distance (ppf) > gp::Resolution())
136 BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf);
137 StdPrs_WFShape::Add (aPrs, MakEd1.Edge(), myDrawer);
141 BRepBuilderAPI_MakeVertex MakVert1 (FirstP);
142 StdPrs_WFShape::Add (aPrs, MakVert1.Vertex(), myDrawer);
144 if (LastP.Distance (ppl) > gp::Resolution())
146 BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl);
147 StdPrs_WFShape::Add (aPrs, MakEd2.Edge(), myDrawer);
151 BRepBuilderAPI_MakeVertex MakVert2 (LastP);
152 StdPrs_WFShape::Add (aPrs, MakVert2.Vertex(), myDrawer);
155 BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf);
156 StdPrs_WFShape::Add (aPrs, MakEd1.Edge(), myDrawer);
157 BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl);
158 StdPrs_WFShape::Add (aPrs, MakEd2.Edge(), myDrawer);
164 //=======================================================================
165 //function : ComputeProjVertexPresentation
167 //=======================================================================
169 void PrsDim_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
170 const TopoDS_Vertex& aVertex,
171 const gp_Pnt& ProjPoint,
172 const Quantity_NameOfColor aColor,
173 const Standard_Real width,
174 const Aspect_TypeOfMarker aProjTOM,
175 const Aspect_TypeOfLine aCallTOL) const
177 if (!myDrawer->HasOwnPointAspect()){
178 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
180 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
181 pa->SetColor(aColor);
182 pa->SetTypeOfMarker(aProjTOM);
186 Handle(Graphic3d_Group) aGroup = aPrs->NewGroup();
187 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
188 anArrayOfPoints->AddVertex (ProjPoint);
189 aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect());
190 aGroup->AddPrimitiveArray (anArrayOfPoints);
193 if (!myDrawer->HasOwnWireAspect()){
194 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
196 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
197 li->SetColor(aColor);
198 li->SetTypeOfLine(aCallTOL);
202 // Si les points ne sont pas confondus...
203 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion()))
205 Handle(Graphic3d_Group) aGroup = aPrs->NewGroup();
206 Handle(Graphic3d_ArrayOfSegments) anArrayOfLines = new Graphic3d_ArrayOfSegments (2);
207 anArrayOfLines->AddVertex (ProjPoint);
208 anArrayOfLines->AddVertex (BRep_Tool::Pnt(aVertex));
209 aGroup->SetGroupPrimitivesAspect (myDrawer->WireAspect()->Aspect());
210 aGroup->AddPrimitiveArray (anArrayOfLines);
214 //=======================================================================
215 //function : SetColor
217 //=======================================================================
218 void PrsDim_Relation::SetColor(const Quantity_Color &aCol)
220 if(hasOwnColor && myDrawer->Color() == aCol) return;
222 if (!myDrawer->HasOwnTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
223 hasOwnColor=Standard_True;
224 myDrawer->SetColor (aCol);
225 myDrawer->TextAspect()->SetColor(aCol);
227 Standard_Real WW = HasWidth()? Width(): myDrawer->HasLink() ?
228 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
229 if (!myDrawer->HasOwnLineAspect()) {
230 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
232 if (!myDrawer->HasOwnDimensionAspect()) {
233 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
236 myDrawer->LineAspect()->SetColor(aCol);
237 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
238 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
239 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
241 DIMENSION->SetLineAspect(LINE);
242 DIMENSION->SetTextAspect(TEXT);
245 //=======================================================================
246 //function : UnsetColor
248 //=======================================================================
249 void PrsDim_Relation::UnsetColor()
251 if (!hasOwnColor) return;
252 hasOwnColor = Standard_False;
253 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
254 Quantity_Color CC = Quantity_NOC_YELLOW;
255 if (myDrawer->HasLink())
257 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
258 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
261 myDrawer->DimensionAspect()->SetLineAspect(LA);