0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / DsgPrs / DsgPrs_DiameterPresentation.cxx
CommitLineData
b311480e 1// Created on: 1996-08-21
2// Created by: Jacques MINOT
3// Copyright (c) 1996-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_DiameterPresentation.hxx>
7fd59977 18
42cf5bc1 19#include <DsgPrs.hxx>
42cf5bc1 20#include <ElCLib.hxx>
21#include <gp_Circ.hxx>
7fd59977 22#include <gp_Dir.hxx>
23#include <gp_Pnt.hxx>
24#include <gp_Vec.hxx>
42cf5bc1 25#include <Graphic3d_Group.hxx>
42cf5bc1 26#include <Prs3d_Arrow.hxx>
42cf5bc1 27#include <Prs3d_DimensionAspect.hxx>
28#include <Prs3d_LineAspect.hxx>
29#include <Prs3d_Presentation.hxx>
30#include <Prs3d_Text.hxx>
42cf5bc1 31#include <TCollection_ExtendedString.hxx>
7fd59977 32
33//==========================================================================
34// function : DsgPrs_DiameterPresentation::Add
81bba717 35// purpose : it is possible to choose the symbol of extremities of the face (arrow, point ...)
7fd59977 36//==========================================================================
37void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
38 const Handle(Prs3d_Drawer)& aDrawer,
39 const TCollection_ExtendedString& aText,
40 const gp_Pnt& AttachmentPoint,
41 const gp_Circ& aCircle,
42 const DsgPrs_ArrowSide ArrowPrs,
43 const Standard_Boolean IsDiamSymbol )
44{
a6eb515f 45 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
d6c48921 46 aPresentation->CurrentGroup()->SetPrimitivesAspect(LA->LineAspect()->Aspect());
7fd59977 47
48 Standard_Real parat = ElCLib::Parameter(aCircle, AttachmentPoint);
49 gp_Pnt ptoncirc = ElCLib::Value (parat, aCircle);
50
81bba717 51 // sideline
7fd59977 52 gp_Pnt center = aCircle.Location();
53 gp_Vec vecrap (ptoncirc,center);
54
55 Standard_Real dist = center.Distance(AttachmentPoint);
56 Standard_Real aRadius = aCircle.Radius();
b8ddfc2f 57 Standard_Boolean inside = (dist < aRadius);
7fd59977 58
59 gp_Pnt pt1 = AttachmentPoint;
b8ddfc2f 60 if (inside) {
7fd59977 61 pt1 = ptoncirc;
62 dist = aRadius;
7fd59977 63 }
64 vecrap.Normalize();
65 vecrap *= (dist+aRadius);
b8ddfc2f 66 gp_Pnt OppositePoint = pt1.Translated(vecrap);
7fd59977 67
b8ddfc2f 68 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
69 aPrims->AddVertex(pt1);
70 aPrims->AddVertex(OppositePoint);
d6c48921 71 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
7fd59977 72
73 // value
74 TCollection_ExtendedString Text = aText;
75 if(IsDiamSymbol)
76 Text = TCollection_ExtendedString("\330 ") + aText; // VRO (2007-05-17) inserted a blank.
d6c48921 77 Prs3d_Text::Draw (aPresentation->CurrentGroup(), LA->TextAspect(), Text, AttachmentPoint);
7fd59977 78
79 // arrows
7fd59977 80 gp_Dir arrdir (vecrap);
81 if (inside) arrdir.Reverse();
82
7fd59977 83 gp_Vec vecrap2 = vecrap;
84 gp_Pnt ptoncirc2 = ptoncirc;
85 gp_Dir arrdir2 = arrdir;
86 vecrap2.Normalize();
87 vecrap2 *= (aCircle.Radius() * 2.);
88 ptoncirc2.Translate (vecrap2);
89 arrdir2.Reverse();
90
91 DsgPrs::ComputeSymbol(aPresentation,LA,ptoncirc,ptoncirc2,arrdir,arrdir2,ArrowPrs);
92}
93
94
95static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
96 const Standard_Real lpar,
97 const Standard_Real para)
98{
99 if (fpar >= 0.) {
100 if(lpar > fpar)
101 return ((para >= fpar) && (para <= lpar));
102 else { // fpar > lpar
b8ddfc2f 103 Standard_Real delta = 2.*M_PI-fpar;
7fd59977 104 Standard_Real lp, par, fp;
105 lp = lpar + delta;
106 par = para + delta;
c6541a0c
D
107 while(lp > 2*M_PI) lp-=2*M_PI;
108 while(par > 2*M_PI) par-=2*M_PI;
7fd59977 109 fp = 0.;
110 return ((par >= fp) && (par <= lp));
111 }
7fd59977 112 }
c6541a0c 113 if (para >= (fpar+2*M_PI)) return Standard_True;
7fd59977 114 if (para <= lpar) return Standard_True;
115 return Standard_False;
116}
117
118
119//=======================================================================
120//function : DsgPrs_DiameterPresentation::Add
121//purpose : SZY 12-february-98
122//=======================================================================
123
124void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
125 const Handle(Prs3d_Drawer)& aDrawer,
126 const TCollection_ExtendedString& aText,
127 const gp_Pnt& AttachmentPoint,
128 const gp_Circ& aCircle,
129 const Standard_Real uFirst,
130 const Standard_Real uLast,
131 const DsgPrs_ArrowSide ArrowPrs,//ArrowSide
132 const Standard_Boolean IsDiamSymbol )
133{
134 Standard_Real fpara = uFirst;
135 Standard_Real lpara = uLast;
b8ddfc2f 136 while (lpara > 2.*M_PI) {
137 fpara -= 2.*M_PI;
138 lpara -= 2.*M_PI;
7fd59977 139 }
140
a6eb515f 141 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
d6c48921 142 aPresentation->CurrentGroup()->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 143 Standard_Real parEndOfArrow = ElCLib::Parameter(aCircle,AttachmentPoint);
7fd59977 144 gp_Pnt EndOfArrow;
81bba717 145 gp_Pnt DrawPosition = AttachmentPoint;// point of attachment
7fd59977 146
147 gp_Pnt Center = aCircle.Location();
148 gp_Pnt FirstPoint = ElCLib::Value(uFirst, aCircle);
149 gp_Pnt SecondPoint = ElCLib::Value(uLast, aCircle);
150
151 if ( !DsgPrs_InDomain(fpara,lpara,parEndOfArrow)) {
c6541a0c
D
152 Standard_Real otherpar = parEndOfArrow + M_PI;// not in domain
153 if (otherpar > 2*M_PI) otherpar -= 2*M_PI;
7fd59977 154 if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
155 parEndOfArrow = otherpar; // parameter on circle
156 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
7fd59977 157 }
158 else {
159 gp_Dir dir1(gp_Vec(Center, FirstPoint));
160 gp_Dir dir2(gp_Vec(Center, SecondPoint));
161 gp_Lin L1( Center, dir1 );
162 gp_Lin L2( Center, dir2 );
163 if(L1.Distance(AttachmentPoint) < L2.Distance(AttachmentPoint))
b8ddfc2f 164 {
165 EndOfArrow = FirstPoint; //***
166 DrawPosition = ElCLib::Value(ElCLib::Parameter( L1, AttachmentPoint ), L1);
167 }
7fd59977 168 else
b8ddfc2f 169 {
170 EndOfArrow = SecondPoint; //***
171 DrawPosition = ElCLib::Value(ElCLib::Parameter( L2, AttachmentPoint ), L2);
172 }
7fd59977 173 }
7fd59977 174 }
175 else {
176 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
177 DrawPosition = AttachmentPoint;
178 }
7fd59977 179
b8ddfc2f 180 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
181 aPrims->AddVertex(DrawPosition);
182 aPrims->AddVertex(EndOfArrow);
d6c48921 183 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
7fd59977 184
185 // text
186 TCollection_ExtendedString Text = aText;
187 if(IsDiamSymbol)
188 Text = TCollection_ExtendedString("\330 ") + Text;// => \330 | \370?
d6c48921 189 Prs3d_Text::Draw (aPresentation->CurrentGroup(), LA->TextAspect(), Text, DrawPosition);
7fd59977 190
b8ddfc2f 191 // Add presentation of arrow
7fd59977 192 gp_Dir DirOfArrow(gp_Vec(DrawPosition, EndOfArrow).XYZ());
b8ddfc2f 193 DsgPrs::ComputeSymbol(aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs);
7fd59977 194}