0026754: Visualization - provide API to display AIS_Trihedron presentation without...
[occt.git] / src / DsgPrs / DsgPrs_FilletRadiusPresentation.cxx
CommitLineData
b311480e 1// Created on: 1997-12-08
2// Created by: Serguei ZARITCHNY
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
b311480e 17
42cf5bc1 18#include <Aspect_AspectMarker.hxx>
19#include <Aspect_TypeOfLine.hxx>
20#include <Aspect_TypeOfMarker.hxx>
21#include <DsgPrs.hxx>
22#include <DsgPrs_FilletRadiusPresentation.hxx>
7fd59977 23#include <ElCLib.hxx>
42cf5bc1 24#include <Geom_Circle.hxx>
25#include <Geom_Line.hxx>
26#include <Geom_TrimmedCurve.hxx>
27#include <GeomAPI_ExtremaCurveCurve.hxx>
28#include <gp_Dir.hxx>
29#include <gp_Lin.hxx>
30#include <gp_Pnt.hxx>
b8ddfc2f 31#include <Graphic3d_ArrayOfPolylines.hxx>
42cf5bc1 32#include <Graphic3d_ArrayOfSegments.hxx>
33#include <Graphic3d_AspectLine3d.hxx>
34#include <Graphic3d_AspectMarker3d.hxx>
35#include <Graphic3d_Group.hxx>
36#include <Graphic3d_Vertex.hxx>
37#include <Precision.hxx>
7fd59977 38#include <Prs3d_Arrow.hxx>
39#include <Prs3d_ArrowAspect.hxx>
42cf5bc1 40#include <Prs3d_DimensionAspect.hxx>
7fd59977 41#include <Prs3d_LineAspect.hxx>
42cf5bc1 42#include <Prs3d_Presentation.hxx>
7fd59977 43#include <Prs3d_Text.hxx>
42cf5bc1 44#include <Quantity_Color.hxx>
7fd59977 45#include <TCollection_AsciiString.hxx>
46#include <TCollection_ExtendedString.hxx>
47
42cf5bc1 48#include <stdio.h>
7fd59977 49//=======================================================================
50//function : Add
51//purpose :
52//=======================================================================
7fd59977 53void DsgPrs_FilletRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
54 const Handle(Prs3d_Drawer)& aDrawer,
55 const Standard_Real theval,
56 const TCollection_ExtendedString & aText,
57 const gp_Pnt & aPosition,
58 const gp_Dir & aNormalDir,
59 const gp_Pnt & aBasePnt,
60 const gp_Pnt & aFirstPoint,
61 const gp_Pnt & aSecondPoint,
62 const gp_Pnt & aCenter,
63 const DsgPrs_ArrowSide ArrowPrs,
64 const Standard_Boolean drawRevers,
65 gp_Pnt & DrawPosition,
66 gp_Pnt & EndOfArrow,
67 Handle(Geom_TrimmedCurve)& TrimCurve,
68 Standard_Boolean & HasCircle )
69{
70 char valcar[80];
71 sprintf(valcar,"%5.2f",theval);
b8ddfc2f 72
7fd59977 73 Standard_Real FirstParCirc, LastParCirc;
74 Standard_Boolean SpecCase;
75 gp_Dir DirOfArrow;
76 gp_Circ FilletCirc;
77 // gp_Pnt NewPosition, EndOfArrow;
a6eb515f 78 Handle( Prs3d_DimensionAspect ) LA = aDrawer->DimensionAspect();
7fd59977 79 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
b8ddfc2f 80
a6eb515f 81 Standard_Real ArrowLength = LA->ArrowAspect()->Length();
7fd59977 82 DsgPrs::ComputeFilletRadiusPresentation( ArrowLength,
83 theval,
84 aPosition,
85 aNormalDir,
86 aFirstPoint,
87 aSecondPoint,
88 aCenter,
89 aBasePnt,
90 drawRevers,
91 SpecCase,
92 FilletCirc,
93 FirstParCirc,
94 LastParCirc,
95 EndOfArrow,
96 DirOfArrow,
97 DrawPosition //NewPosition
98 );
99 // Creating the fillet's arc
100 if( !SpecCase )
b8ddfc2f 101 {
102 const Standard_Real Alpha = Abs(LastParCirc - FirstParCirc);
103 const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
104 const Standard_Real delta = Alpha / ( NodeNumber - 1 );
105
106 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
107 for (Standard_Integer i = 0 ; i < NodeNumber; i++, FirstParCirc += delta)
108 aPrims->AddVertex(ElCLib::Value( FirstParCirc, FilletCirc ));
109 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
110
111 HasCircle = Standard_True;
112 Handle(Geom_Circle) Circle = new Geom_Circle( FilletCirc );
113 TrimCurve = new Geom_TrimmedCurve( Circle, FirstParCirc, LastParCirc );
114 }
7fd59977 115 else // null or PI anle or Radius = 0
b8ddfc2f 116 {
117 HasCircle = Standard_False;
118 }
7fd59977 119
120 // Line from position to intersection point on fillet's circle (EndOfArrow)
b8ddfc2f 121 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
122 aPrims->AddVertex(DrawPosition);
123 aPrims->AddVertex(EndOfArrow);
124 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
125
7fd59977 126 // Drawing the text
127 Prs3d_Text::Draw(aPresentation, LA->TextAspect(), aText, DrawPosition);
128
129 // Add presentation of arrows
130 DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs );
7fd59977 131}