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