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