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
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.
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.
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.
21 #include <DsgPrs_OffsetPresentation.ixx>
28 #include <gce_MakeLin.hxx>
30 #include <Graphic3d_Group.hxx>
31 #include <Graphic3d_ArrayOfSegments.hxx>
33 #include <Prs3d_Arrow.hxx>
34 #include <Prs3d_ArrowAspect.hxx>
35 #include <Prs3d_LineAspect.hxx>
36 #include <Prs3d_LengthAspect.hxx>
38 #include <TCollection_AsciiString.hxx>
40 #include <Graphic3d_AspectLine3d.hxx>
41 #include <Graphic3d_AspectMarker3d.hxx>
42 #include <Graphic3d_Vertex.hxx>
44 #include <Aspect_TypeOfLine.hxx>
45 #include <Aspect_TypeOfMarker.hxx>
46 #include <Aspect_AspectMarker.hxx>
48 #include <Quantity_Color.hxx>
50 #include <Prs3d_Text.hxx>
51 #include <Precision.hxx>
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,
61 const gp_Pnt& OffsetPoint)
63 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
64 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
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);
71 Standard_Boolean DimNulle = Standard_False;
72 if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) {
73 L3 = gce_MakeLin(Proj1,Proj2);
76 //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl;
77 DimNulle = Standard_True;
78 L3 = gp_Lin(Proj1,aDirection);
79 gp_Vec v4 (Proj1,OffsetPoint);
81 L4 = gp_Lin(Proj1,d4); // normale
83 Standard_Real parmin,parmax,parcur;
84 parmin = ElCLib::Parameter(L3,Proj1);
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);
93 Standard_Boolean outside = Standard_False;
94 if (parcur < parmin) {
96 outside = Standard_True;
98 if (parcur > parmax) {
100 outside = Standard_True;
103 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
104 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
106 // trait de cote : 1er groupe
107 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
108 aPrims->AddVertex(PointMin);
109 aPrims->AddVertex(PointMax);
111 Prs3d_Root::NewGroup(aPresentation);
112 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
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());
121 if (dist < (LA->Arrow1Aspect()->Length()+LA->Arrow2Aspect()->Length()))
122 outside = Standard_True;
123 gp_Dir arrdir = L3.Direction().Reversed();
127 // fleche 1 : 2eme groupe
128 Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
130 Prs3d_Root::NewGroup(aPresentation);
131 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
133 // ball 1 : 3eme groupe
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);
146 Prs3d_Root::NewGroup(aPresentation);
148 // texte : 4eme groupe
149 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
152 Prs3d_Root::NewGroup(aPresentation);
153 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
155 // trait de rappel 1 : 5eme groupe
156 aPrims->AddVertex(AttachmentPoint1);
157 aPrims->AddVertex(Proj1);
159 // trait de rappel 2 : 6eme groupe
160 aPrims->AddVertex(AttachmentPoint2);
161 aPrims->AddVertex(Proj2);
163 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
166 void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation,
167 const Handle(Prs3d_Drawer)& aDrawer,
168 const TCollection_ExtendedString& aText,
169 const gp_Pnt& AttachmentPoint1,
170 const gp_Pnt& AttachmentPoint2,
171 const gp_Dir& aDirection,
172 const gp_Dir& aDirection2,
173 const gp_Pnt& OffsetPoint)
175 gp_Lin L1 (AttachmentPoint1,aDirection);
176 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
178 gp_Lin L2 (AttachmentPoint2,aDirection);
179 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
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);
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);
192 // trait d'axe : 1er groupe
193 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
194 aPrims->AddVertex(AttachmentPoint1);
195 aPrims->AddVertex(Proj1);
196 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
198 Prs3d_Root::NewGroup(aPresentation);
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);
205 // trait d'axe: 2eme groupe
206 aPrims = new Graphic3d_ArrayOfSegments(2);
207 aPrims->AddVertex(AttachmentPoint2);
208 aPrims->AddVertex(Proj2);
209 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
211 // anneau : 3eme et 4eme groupes
212 Graphic3d_Vertex V3d(Proj2.X() ,Proj2.Y(), Proj2.Z());
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);
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);