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