0025418: Debug output to be limited to OCC development environment
[occt.git] / src / DsgPrs / DsgPrs_RadiusPresentation.cxx
CommitLineData
b311480e 1// Created on: 1995-03-01
2// Created by: Arnaud BOUZY
3// Copyright (c) 1995-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 20-feb-98 by <SZY>
18// Sergei Zaritchny
19
20#include <DsgPrs_RadiusPresentation.ixx>
21#include <gp_Lin.hxx>
22#include <gp_Dir.hxx>
23#include <gp_Circ.hxx>
24#include <ElCLib.hxx>
25#include <Graphic3d_Group.hxx>
b8ddfc2f 26#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 27#include <Prs3d_Arrow.hxx>
28#include <Prs3d_ArrowAspect.hxx>
29#include <Prs3d_LineAspect.hxx>
a6eb515f 30#include <Prs3d_DimensionAspect.hxx>
7fd59977 31#include <Prs3d_Text.hxx>
32
33#include <Graphic3d_Vertex.hxx>
34#include <Graphic3d_AspectMarker3d.hxx>
35#include <Graphic3d_AspectLine3d.hxx>
36#include <Aspect_TypeOfLine.hxx>
37#include <Aspect_TypeOfMarker.hxx>
38#include <Aspect_AspectMarker.hxx>
39#include <Quantity_Color.hxx>
40#include <DsgPrs.hxx>
41#include <Precision.hxx>
42#include <gce_MakeLin.hxx>
43#include <gce_MakeDir.hxx>
44
45
46static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
b8ddfc2f 47 const Standard_Real lpar,
48 const Standard_Real para)
7fd59977 49{
b8ddfc2f 50 if (fpar >= 0.)
7fd59977 51 return ((para >= fpar) && (para <= lpar));
b8ddfc2f 52 if (para >= (fpar+2.*M_PI)) return Standard_True;
7fd59977 53 if (para <= lpar) return Standard_True;
54 return Standard_False;
55}
56
57//=======================================================================
58//function : Add
59//purpose :
60//=======================================================================
61
62void DsgPrs_RadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
63 const Handle(Prs3d_Drawer)& aDrawer,
64 const TCollection_ExtendedString& aText,
65 const gp_Pnt& AttachmentPoint,
66 const gp_Circ& aCircle,
67 const Standard_Real firstparam,
68 const Standard_Real lastparam,
69 const Standard_Boolean drawFromCenter,
70 const Standard_Boolean reverseArrow)
71{
72 Standard_Real fpara = firstparam;
73 Standard_Real lpara = lastparam;
b8ddfc2f 74 while (lpara > 2.*M_PI) {
75 fpara -= 2.*M_PI;
76 lpara -= 2.*M_PI;
7fd59977 77 }
a6eb515f 78 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 79 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 80
7fd59977 81 Standard_Real parat = ElCLib::Parameter(aCircle,AttachmentPoint);
82 gp_Pnt attpoint = AttachmentPoint;
83 Standard_Boolean otherside = Standard_False;
84 if ( !DsgPrs_InDomain(fpara,lpara,parat)) {
c6541a0c 85 Standard_Real otherpar = parat + M_PI;
b8ddfc2f 86 if (otherpar > 2.*M_PI) otherpar -= 2.*M_PI;
7fd59977 87 if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
88 parat = otherpar;
89 otherside = Standard_True;
90 }
91 else {
b8ddfc2f 92 const Standard_Real ecartpar = Min(Abs(fpara-parat),Abs(lpara-parat));
93 const Standard_Real ecartoth = Min(Abs(fpara-otherpar),Abs(lpara-otherpar));
7fd59977 94 if (ecartpar <= ecartoth) {
b8ddfc2f 95 parat = (parat < fpara)? fpara : lpara;
7fd59977 96 }
97 else {
b8ddfc2f 98 otherside = Standard_True;
99 parat = (otherpar < fpara)? fpara : lpara;
7fd59977 100 }
101 gp_Pnt ptdir = ElCLib::Value(parat,aCircle);
b8ddfc2f 102 gp_Lin lsup(aCircle.Location(),gp_Dir(ptdir.XYZ()-aCircle.Location().XYZ()));
103 const Standard_Real parpos = ElCLib::Parameter(lsup,AttachmentPoint);
7fd59977 104 attpoint = ElCLib::Value(parpos,lsup);
105 }
106 }
107 gp_Pnt ptoncirc = ElCLib::Value(parat,aCircle);
108 gp_Lin L (aCircle.Location(),gp_Dir(attpoint.XYZ()-aCircle.Location().XYZ()));
109 gp_Pnt firstpoint = attpoint;
110 gp_Pnt drawtopoint = ptoncirc;
111 if (drawFromCenter && !otherside) {
b8ddfc2f 112 const Standard_Real uatt = ElCLib::Parameter(L,attpoint);
113 const Standard_Real uptc = ElCLib::Parameter(L,ptoncirc);
114 if (Abs(uatt) > Abs(uptc))
7fd59977 115 drawtopoint = aCircle.Location();
b8ddfc2f 116 else
7fd59977 117 firstpoint = aCircle.Location();
7fd59977 118 }
119
b8ddfc2f 120 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
121 aPrims->AddVertex(firstpoint);
122 aPrims->AddVertex(drawtopoint);
123 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 124
125 gp_Dir arrdir = L.Direction();
b8ddfc2f 126 if (reverseArrow)
7fd59977 127 arrdir.Reverse();
b8ddfc2f 128
7fd59977 129 // fleche
a6eb515f 130 Prs3d_Arrow::Draw(aPresentation,ptoncirc,arrdir,LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
7fd59977 131
132 // texte
133 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,attpoint);
7fd59977 134}
135
136//=======================================================================
137//function : DsgPrs_RadiusPresentation::Add
138//purpose : SZY 20-february-98
139// : adds radius representation according drawFromCenter value
140//=======================================================================
141
142void DsgPrs_RadiusPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
143 const Handle(Prs3d_Drawer)& aDrawer,
144 const TCollection_ExtendedString& aText,
145 const gp_Pnt& AttachmentPoint,
146 const gp_Pnt& Center,
147 const gp_Pnt& EndOfArrow,
148 const DsgPrs_ArrowSide ArrowPrs,
149 const Standard_Boolean drawFromCenter,
150 const Standard_Boolean reverseArrow)
151{
a6eb515f 152 Handle( Prs3d_DimensionAspect ) LA = aDrawer->DimensionAspect();
7fd59977 153 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
154
b8ddfc2f 155 gp_Pnt LineOrigin, LineEnd;
156 DsgPrs::ComputeRadiusLine(Center, EndOfArrow, AttachmentPoint, drawFromCenter, LineOrigin, LineEnd);
7fd59977 157
b8ddfc2f 158 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
159 aPrims->AddVertex(LineOrigin);
160 aPrims->AddVertex(LineEnd);
161 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 162
7fd59977 163 // text
164 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, AttachmentPoint );
165
166 gp_Dir ArrowDir = gce_MakeDir( LineOrigin , LineEnd );
167 if (reverseArrow)
168 ArrowDir.Reverse();
b8ddfc2f 169 DsgPrs::ComputeSymbol( aPresentation, LA, Center, EndOfArrow, ArrowDir.Reversed(), ArrowDir, ArrowPrs, drawFromCenter );
7fd59977 170}