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