0027670: Visualization - avoid duplication of structures defining primitive array...
[occt.git] / src / DsgPrs / DsgPrs_EllipseRadiusPresentation.cxx
CommitLineData
b311480e 1// Created on: 1998-01-26
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-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
b6472664 17#include <DsgPrs_EllipseRadiusPresentation.hxx>
7fd59977 18
42cf5bc1 19#include <DsgPrs.hxx>
42cf5bc1 20#include <ElCLib.hxx>
21#include <Geom_Ellipse.hxx>
22#include <Geom_Line.hxx>
23#include <Geom_OffsetCurve.hxx>
24#include <Geom_TrimmedCurve.hxx>
25#include <GeomAPI_ExtremaCurveCurve.hxx>
7fd59977 26#include <gp_Dir.hxx>
27#include <gp_Elips.hxx>
42cf5bc1 28#include <gp_Lin.hxx>
29#include <gp_Pnt.hxx>
b8ddfc2f 30#include <Graphic3d_ArrayOfPolylines.hxx>
42cf5bc1 31#include <Graphic3d_ArrayOfSegments.hxx>
32#include <Graphic3d_AspectLine3d.hxx>
33#include <Graphic3d_AspectMarker3d.hxx>
34#include <Graphic3d_Group.hxx>
42cf5bc1 35#include <Precision.hxx>
7fd59977 36#include <Prs3d_Arrow.hxx>
37#include <Prs3d_ArrowAspect.hxx>
42cf5bc1 38#include <Prs3d_DimensionAspect.hxx>
7fd59977 39#include <Prs3d_LineAspect.hxx>
42cf5bc1 40#include <Prs3d_Presentation.hxx>
7fd59977 41#include <Prs3d_Text.hxx>
42#include <TCollection_AsciiString.hxx>
43#include <TCollection_ExtendedString.hxx>
44
7fd59977 45//=======================================================================
46//function : Add
47//purpose :
48//=======================================================================
7fd59977 49void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
50 const Handle(Prs3d_Drawer)& aDrawer,
51 const Standard_Real theval,
52 const TCollection_ExtendedString & aText,
7fd59977 53 const gp_Pnt & aPosition,
54 const gp_Pnt & anEndOfArrow,
55 const gp_Pnt & aCenter,
56 const Standard_Boolean IsMaxRadius,
57 const DsgPrs_ArrowSide ArrowPrs)
58{
a6eb515f 59 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 60 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
61
b8ddfc2f 62 const Standard_Real dist = aCenter.Distance( aPosition );
63 const Standard_Boolean inside = ( dist <= theval );
64 gp_Pnt EndPoint(inside? anEndOfArrow : aPosition);
65
66 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
67 aPrims->AddVertex(aCenter);
68 aPrims->AddVertex(EndPoint);
69 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
70
71 // value
72 TCollection_ExtendedString Text(IsMaxRadius? "a = " : "b = ");
73 Text += aText;
7fd59977 74 Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, aPosition );
75
b8ddfc2f 76 // arrows
7fd59977 77 gp_Dir arrdir( gp_Vec( aCenter, anEndOfArrow));
78 if (!inside) arrdir.Reverse();
79
b8ddfc2f 80 DsgPrs::ComputeSymbol(aPresentation, LA, anEndOfArrow, anEndOfArrow, arrdir, arrdir, ArrowPrs );
7fd59977 81}
82
83//=======================================================================
84//function : Add
85//purpose :
86//=======================================================================
87
88void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
89 const Handle(Prs3d_Drawer)& aDrawer,
90 const Standard_Real theval,
91 const TCollection_ExtendedString & aText,
92 const gp_Elips & anEllipse,
93 const gp_Pnt & aPosition,
94 const gp_Pnt & anEndOfArrow,
95 const gp_Pnt & aCenter,
96 const Standard_Real uFirst,
97 const Standard_Boolean IsInDomain,
98 const Standard_Boolean IsMaxRadius,
99 const DsgPrs_ArrowSide ArrowPrs)
100{
a6eb515f 101 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 102 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 103
7fd59977 104 if(!IsInDomain)
b8ddfc2f 105 {
106 const Standard_Real uLast = ElCLib::Parameter ( anEllipse, anEndOfArrow );
107 const Standard_Real Alpha = DsgPrs::DistanceFromApex(anEllipse, anEndOfArrow, uFirst);//length of ellipse arc
108 gp_Vec Vapex(aCenter, ElCLib::Value( uLast, anEllipse )) ;
109 gp_Vec Vpnt(aCenter, ElCLib::Value( uFirst, anEllipse )) ;
110 gp_Dir dir(Vpnt ^ Vapex);
111 Standard_Real parFirst = anEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())? uLast : uFirst;
112 const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
113 const Standard_Real delta = Alpha / ( NodeNumber - 1 );
114
115 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
116 for (Standard_Integer i = 0 ; i < NodeNumber; i++, parFirst += delta)
117 aPrims->AddVertex(ElCLib::Value( parFirst, anEllipse ));
118 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
119 }
7fd59977 120 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, aDrawer, theval, aText,
b8ddfc2f 121 aPosition, anEndOfArrow, aCenter, IsMaxRadius, ArrowPrs);
7fd59977 122}
123
124
7fd59977 125//=======================================================================
126//function : Add
127//purpose : // for offset curve
128//=======================================================================
129
130void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
131 const Handle(Prs3d_Drawer)& aDrawer,
132 const Standard_Real theval,
133 const TCollection_ExtendedString & aText,
134 const Handle(Geom_OffsetCurve) & aCurve,
135 const gp_Pnt & aPosition,
136 const gp_Pnt & anEndOfArrow,
137 const gp_Pnt & aCenter,
138 const Standard_Real uFirst,
139 const Standard_Boolean IsInDomain,
140 const Standard_Boolean IsMaxRadius,
141 const DsgPrs_ArrowSide ArrowPrs)
142{
a6eb515f 143 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 144 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 145
7fd59977 146 if(!IsInDomain)
b8ddfc2f 147 {
148 if(!aCurve->IsCN(1)) return ;
149 gp_Elips aBEllipse = Handle(Geom_Ellipse)::DownCast(aCurve->BasisCurve ())->Elips();
150 const Standard_Real Offset = aCurve->Offset();
151 aBEllipse.SetMajorRadius(aBEllipse.MajorRadius() + Offset);
152 aBEllipse.SetMinorRadius(aBEllipse.MinorRadius() + Offset);
153 const Standard_Real uLast = ElCLib::Parameter ( aBEllipse, anEndOfArrow );
154 const Standard_Real Alpha = DsgPrs::DistanceFromApex(aBEllipse, anEndOfArrow, uFirst);//length of ellipse arc
155 gp_Pnt p1;
156 aCurve->D0(uFirst, p1);
157 gp_Vec Vapex(aCenter, anEndOfArrow) ;
158 gp_Vec Vpnt (aCenter, p1) ;
159 gp_Dir dir(Vpnt ^ Vapex);
160 Standard_Real parFirst = aCurve->Direction().IsOpposite( dir, Precision::Angular())? uLast : uFirst;
161 const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
162 const Standard_Real delta = Alpha / ( NodeNumber - 1 );
163
164 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
165 for (Standard_Integer i = 0 ; i < NodeNumber; i++, parFirst += delta)
7fd59977 166 {
b8ddfc2f 167 aCurve->D0( parFirst, p1 );
168 aPrims->AddVertex(p1);
7fd59977 169 }
b8ddfc2f 170 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
171 }
7fd59977 172 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, aDrawer, theval, aText,
b8ddfc2f 173 aPosition, anEndOfArrow, aCenter, IsMaxRadius, ArrowPrs);
7fd59977 174}