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