0024162: Eliminate CLang compiler warning
[occt.git] / src / DsgPrs / DsgPrs_OffsetPresentation.cxx
1 // Created on: 1996-09-18
2 // Created by: Jacques MINOT
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 #include <DsgPrs_OffsetPresentation.ixx>
22
23 #include <gp_Lin.hxx>
24 #include <gp_Dir.hxx>
25
26 #include <ElCLib.hxx>
27
28 #include <gce_MakeLin.hxx>
29
30 #include <Graphic3d_Group.hxx>
31 #include <Graphic3d_ArrayOfSegments.hxx>
32 #include <Graphic3d_ArrayOfPoints.hxx>
33
34 #include <Prs3d_Arrow.hxx>
35 #include <Prs3d_ArrowAspect.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Prs3d_LengthAspect.hxx>
38
39 #include <TCollection_AsciiString.hxx>
40
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_Vertex.hxx>
44
45 #include <Aspect_TypeOfLine.hxx>
46 #include <Aspect_TypeOfMarker.hxx>
47 #include <Aspect_AspectMarker.hxx>
48
49 #include <Quantity_Color.hxx>
50
51 #include <Prs3d_Text.hxx>
52 #include <Precision.hxx>
53
54
55 void DsgPrs_OffsetPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
56                                      const Handle(Prs3d_Drawer)& aDrawer,
57                                      const TCollection_ExtendedString& aText,
58                                      const gp_Pnt& AttachmentPoint1,
59                                      const gp_Pnt& AttachmentPoint2,
60                                      const gp_Dir& aDirection,
61                                      const gp_Dir& aDirection2,
62                                      const gp_Pnt& OffsetPoint)
63 {
64   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
65   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
66
67   gp_Lin L1 (AttachmentPoint1,aDirection);
68   gp_Lin L2 (AttachmentPoint2,aDirection2);
69   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
70   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
71   gp_Lin L3,L4;
72   Standard_Boolean DimNulle = Standard_False;
73   if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) {
74     L3 = gce_MakeLin(Proj1,Proj2);
75   }
76   else {
77     //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl;
78     DimNulle = Standard_True;
79     L3 = gp_Lin(Proj1,aDirection); 
80     gp_Vec v4 (Proj1,OffsetPoint);
81     gp_Dir d4 (v4);
82     L4 = gp_Lin(Proj1,d4); // normale
83   }
84   Standard_Real parmin,parmax,parcur;
85   parmin = ElCLib::Parameter(L3,Proj1);
86   parmax = parmin;
87   parcur = ElCLib::Parameter(L3,Proj2);
88   Standard_Real dist = Abs(parmin-parcur);
89   if (parcur < parmin) parmin = parcur;
90   if (parcur > parmax) parmax = parcur;
91   parcur = ElCLib::Parameter(L3,OffsetPoint);
92   gp_Pnt offp = ElCLib::Value(parcur,L3);
93
94   Standard_Boolean outside = Standard_False;
95   if (parcur < parmin) {
96     parmin = parcur;
97     outside = Standard_True;
98   }
99   if (parcur > parmax) {
100     parmax = parcur;
101     outside = Standard_True;
102   }
103
104   gp_Pnt PointMin = ElCLib::Value(parmin,L3);
105   gp_Pnt PointMax = ElCLib::Value(parmax,L3);
106
107   // trait de cote : 1er groupe
108   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
109   aPrims->AddVertex(PointMin);
110   aPrims->AddVertex(PointMax);
111
112   Prs3d_Root::NewGroup(aPresentation);
113   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
114
115   if (DimNulle)
116   {
117     Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction(),LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
118     Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction().Reversed(),LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
119   }
120   else
121   {
122     if (dist < (LA->Arrow1Aspect()->Length()+LA->Arrow2Aspect()->Length()))
123       outside = Standard_True;
124     gp_Dir arrdir = L3.Direction().Reversed();
125     if (outside)
126       arrdir.Reverse();
127
128     // fleche 1 : 2eme groupe
129     Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
130
131     Prs3d_Root::NewGroup(aPresentation);
132     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
133     
134     // ball 1 : 3eme groupe
135     Quantity_Color aColor;
136     Aspect_TypeOfLine aType;
137     Standard_Real aWidth;
138     LA->LineAspect()->Aspect()->Values (aColor, aType, aWidth);
139     Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
140     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp);
141     Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
142     anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
143     Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
144
145     Prs3d_Root::NewGroup(aPresentation);
146
147     // texte : 4eme groupe
148     Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
149   }
150
151   Prs3d_Root::NewGroup(aPresentation);
152   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
153
154   // trait de rappel 1 : 5eme groupe
155   aPrims->AddVertex(AttachmentPoint1);
156   aPrims->AddVertex(Proj1);
157
158   // trait de rappel 2 : 6eme groupe
159   aPrims->AddVertex(AttachmentPoint2);
160   aPrims->AddVertex(Proj2);
161
162   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
163 }
164
165 void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation,
166                                          const Handle(Prs3d_Drawer)& aDrawer,
167                                          const TCollection_ExtendedString& /*aText*/,
168                                          const gp_Pnt& AttachmentPoint1,
169                                          const gp_Pnt& AttachmentPoint2,
170                                          const gp_Dir& aDirection,
171                                          const gp_Dir& /*aDirection2*/,
172                                          const gp_Pnt& OffsetPoint)
173 {
174   gp_Lin L1 (AttachmentPoint1,aDirection);
175   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
176
177   gp_Lin L2 (AttachmentPoint2,aDirection);
178   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
179
180   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
181   Quantity_Color acolor;
182   Aspect_TypeOfLine atype;
183   Standard_Real awidth;
184   LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
185
186   Handle(Graphic3d_AspectLine3d) AxeAsp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
187   AxeAsp->SetType( Aspect_TOL_DOTDASH);
188   Prs3d_Root::NewGroup(aPresentation);
189   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(AxeAsp);
190
191   // trait d'axe : 1er groupe
192   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
193   aPrims->AddVertex(AttachmentPoint1);
194   aPrims->AddVertex(Proj1);
195   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
196
197   Prs3d_Root::NewGroup(aPresentation);
198
199   Handle(Graphic3d_AspectLine3d) Axe2Asp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
200   Axe2Asp->SetType  ( Aspect_TOL_DOTDASH);
201   Axe2Asp->SetWidth ( 4.);
202   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Axe2Asp);
203
204   // trait d'axe: 2eme groupe
205   aPrims = new Graphic3d_ArrayOfSegments(2);
206   aPrims->AddVertex(AttachmentPoint2);
207   aPrims->AddVertex(Proj2);
208   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
209
210   // anneau : 3eme et 4eme groupes
211   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
212   anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
213
214   Prs3d_Root::NewGroup(aPresentation);
215   Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
216   MarkerAsp->SetType(Aspect_TOM_O);
217   MarkerAsp->SetScale(4.);
218   //MarkerAsp->SetColor(Quantity_Color(Quantity_NOC_RED));
219   MarkerAsp->SetColor(acolor);
220   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
221   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
222
223   Prs3d_Root::NewGroup(aPresentation);
224   Handle(Graphic3d_AspectMarker3d) Marker2Asp = new Graphic3d_AspectMarker3d();
225   Marker2Asp->SetType(Aspect_TOM_O);
226   Marker2Asp->SetScale(2.);
227   //Marker2Asp->SetColor(Quantity_Color(Quantity_NOC_GREEN));
228   Marker2Asp->SetColor(acolor);
229   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Marker2Asp);
230   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
231 }