0024428: Implementation of LGPL license
[occt.git] / src / DsgPrs / DsgPrs_OffsetPresentation.cxx
CommitLineData
b311480e 1// Created on: 1996-09-18
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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
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#include <DsgPrs_OffsetPresentation.ixx>
18
19#include <gp_Lin.hxx>
20#include <gp_Dir.hxx>
21
22#include <ElCLib.hxx>
23
24#include <gce_MakeLin.hxx>
25
26#include <Graphic3d_Group.hxx>
b8ddfc2f 27#include <Graphic3d_ArrayOfSegments.hxx>
a577aaab 28#include <Graphic3d_ArrayOfPoints.hxx>
7fd59977 29
30#include <Prs3d_Arrow.hxx>
31#include <Prs3d_ArrowAspect.hxx>
32#include <Prs3d_LineAspect.hxx>
a6eb515f 33#include <Prs3d_DimensionAspect.hxx>
7fd59977 34
35#include <TCollection_AsciiString.hxx>
36
37#include <Graphic3d_AspectLine3d.hxx>
38#include <Graphic3d_AspectMarker3d.hxx>
39#include <Graphic3d_Vertex.hxx>
40
41#include <Aspect_TypeOfLine.hxx>
42#include <Aspect_TypeOfMarker.hxx>
43#include <Aspect_AspectMarker.hxx>
44
45#include <Quantity_Color.hxx>
46
47#include <Prs3d_Text.hxx>
48#include <Precision.hxx>
49
50
51void DsgPrs_OffsetPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
52 const Handle(Prs3d_Drawer)& aDrawer,
53 const TCollection_ExtendedString& aText,
54 const gp_Pnt& AttachmentPoint1,
55 const gp_Pnt& AttachmentPoint2,
56 const gp_Dir& aDirection,
57 const gp_Dir& aDirection2,
b8ddfc2f 58 const gp_Pnt& OffsetPoint)
59{
a6eb515f 60 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 61 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 62
7fd59977 63 gp_Lin L1 (AttachmentPoint1,aDirection);
64 gp_Lin L2 (AttachmentPoint2,aDirection2);
65 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
66 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
67 gp_Lin L3,L4;
68 Standard_Boolean DimNulle = Standard_False;
69 if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) {
70 L3 = gce_MakeLin(Proj1,Proj2);
71 }
72 else {
73 //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl;
74 DimNulle = Standard_True;
75 L3 = gp_Lin(Proj1,aDirection);
76 gp_Vec v4 (Proj1,OffsetPoint);
77 gp_Dir d4 (v4);
78 L4 = gp_Lin(Proj1,d4); // normale
79 }
80 Standard_Real parmin,parmax,parcur;
81 parmin = ElCLib::Parameter(L3,Proj1);
82 parmax = parmin;
83 parcur = ElCLib::Parameter(L3,Proj2);
84 Standard_Real dist = Abs(parmin-parcur);
85 if (parcur < parmin) parmin = parcur;
86 if (parcur > parmax) parmax = parcur;
87 parcur = ElCLib::Parameter(L3,OffsetPoint);
88 gp_Pnt offp = ElCLib::Value(parcur,L3);
89
90 Standard_Boolean outside = Standard_False;
91 if (parcur < parmin) {
92 parmin = parcur;
93 outside = Standard_True;
94 }
95 if (parcur > parmax) {
96 parmax = parcur;
97 outside = Standard_True;
98 }
99
100 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
101 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
102
7fd59977 103 // trait de cote : 1er groupe
b8ddfc2f 104 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
105 aPrims->AddVertex(PointMin);
106 aPrims->AddVertex(PointMax);
7fd59977 107
b8ddfc2f 108 Prs3d_Root::NewGroup(aPresentation);
109 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
7fd59977 110
b8ddfc2f 111 if (DimNulle)
112 {
a6eb515f 113 Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
114 Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction().Reversed(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
b8ddfc2f 115 }
116 else
117 {
a6eb515f 118 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
7fd59977 119 outside = Standard_True;
7fd59977 120 gp_Dir arrdir = L3.Direction().Reversed();
b8ddfc2f 121 if (outside)
7fd59977 122 arrdir.Reverse();
b8ddfc2f 123
7fd59977 124 // fleche 1 : 2eme groupe
a6eb515f 125 Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
b8ddfc2f 126
7fd59977 127 Prs3d_Root::NewGroup(aPresentation);
128 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
129
130 // ball 1 : 3eme groupe
a577aaab 131 Quantity_Color aColor;
132 Aspect_TypeOfLine aType;
133 Standard_Real aWidth;
134 LA->LineAspect()->Aspect()->Values (aColor, aType, aWidth);
135 Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
136 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp);
137 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
138 anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
139 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
140
7fd59977 141 Prs3d_Root::NewGroup(aPresentation);
a577aaab 142
7fd59977 143 // texte : 4eme groupe
144 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
145 }
146
7fd59977 147 Prs3d_Root::NewGroup(aPresentation);
148 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 149
7fd59977 150 // trait de rappel 1 : 5eme groupe
b8ddfc2f 151 aPrims->AddVertex(AttachmentPoint1);
152 aPrims->AddVertex(Proj1);
7fd59977 153
7fd59977 154 // trait de rappel 2 : 6eme groupe
b8ddfc2f 155 aPrims->AddVertex(AttachmentPoint2);
156 aPrims->AddVertex(Proj2);
157
158 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 159}
160
161void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation,
162 const Handle(Prs3d_Drawer)& aDrawer,
35e08fe8 163 const TCollection_ExtendedString& /*aText*/,
7fd59977 164 const gp_Pnt& AttachmentPoint1,
165 const gp_Pnt& AttachmentPoint2,
166 const gp_Dir& aDirection,
35e08fe8 167 const gp_Dir& /*aDirection2*/,
b8ddfc2f 168 const gp_Pnt& OffsetPoint)
169{
7fd59977 170 gp_Lin L1 (AttachmentPoint1,aDirection);
171 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
172
173 gp_Lin L2 (AttachmentPoint2,aDirection);
174 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
175
a6eb515f 176 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 177 Quantity_Color acolor;
178 Aspect_TypeOfLine atype;
179 Standard_Real awidth;
180 LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
181
182 Handle(Graphic3d_AspectLine3d) AxeAsp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
183 AxeAsp->SetType( Aspect_TOL_DOTDASH);
184 Prs3d_Root::NewGroup(aPresentation);
185 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(AxeAsp);
186
7fd59977 187 // trait d'axe : 1er groupe
b8ddfc2f 188 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
189 aPrims->AddVertex(AttachmentPoint1);
190 aPrims->AddVertex(Proj1);
191 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 192
193 Prs3d_Root::NewGroup(aPresentation);
b8ddfc2f 194
7fd59977 195 Handle(Graphic3d_AspectLine3d) Axe2Asp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
196 Axe2Asp->SetType ( Aspect_TOL_DOTDASH);
197 Axe2Asp->SetWidth ( 4.);
198 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Axe2Asp);
199
7fd59977 200 // trait d'axe: 2eme groupe
b8ddfc2f 201 aPrims = new Graphic3d_ArrayOfSegments(2);
202 aPrims->AddVertex(AttachmentPoint2);
203 aPrims->AddVertex(Proj2);
204 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 205
206 // anneau : 3eme et 4eme groupes
a577aaab 207 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
208 anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
7fd59977 209
210 Prs3d_Root::NewGroup(aPresentation);
211 Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
212 MarkerAsp->SetType(Aspect_TOM_O);
213 MarkerAsp->SetScale(4.);
214 //MarkerAsp->SetColor(Quantity_Color(Quantity_NOC_RED));
215 MarkerAsp->SetColor(acolor);
216 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
a577aaab 217 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
7fd59977 218
219 Prs3d_Root::NewGroup(aPresentation);
220 Handle(Graphic3d_AspectMarker3d) Marker2Asp = new Graphic3d_AspectMarker3d();
221 Marker2Asp->SetType(Aspect_TOM_O);
222 Marker2Asp->SetScale(2.);
223 //Marker2Asp->SetColor(Quantity_Color(Quantity_NOC_GREEN));
224 Marker2Asp->SetColor(acolor);
225 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Marker2Asp);
a577aaab 226 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
7fd59977 227}