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