773a1e82ec7e704daf413cba961bec98192c130a
[occt.git] / src / DsgPrs / DsgPrs_FixPresentation.cxx
1 // Created on: 1996-04-01
2 // Created by: Flore Lantheaume
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
22
23 #include <DsgPrs_FixPresentation.ixx>
24
25 #include <Graphic3d_Array1OfVertex.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_AspectMarker3d.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_Vertex.hxx>
30
31 #include <Prs3d_LengthAspect.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_Root.hxx>
34
35 #include <Aspect_TypeOfLine.hxx>
36 #include <Aspect_TypeOfMarker.hxx>
37 #include <Aspect_AspectMarker.hxx>
38
39 #include <gp_Vec.hxx>
40 #include <gp_Dir.hxx>
41 #include <gp_Pnt.hxx>
42 #include <gp_Ax1.hxx>
43
44 #include <Quantity_Color.hxx>
45
46
47
48
49 //=======================================================================
50 //function : Add
51 //purpose  : 
52 //=======================================================================
53
54 void DsgPrs_FixPresentation::Add(
55                        const Handle(Prs3d_Presentation)& aPresentation,
56                        const Handle(Prs3d_Drawer)& aDrawer,
57                        const gp_Pnt& aPntAttach,
58                        const gp_Pnt& aPntEnd,
59                        const gp_Dir& aNormPln,
60                        const Standard_Real symbsize)
61 {
62   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
63   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
64
65   //Trace du segment de raccordement
66   Graphic3d_Array1OfVertex V(1,2);
67   V(1).SetCoord(aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
68   V(2).SetCoord(aPntEnd.X(), aPntEnd.Y(), aPntEnd.Z() );
69   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
70
71   // trace du symbole 'Fix'
72   Prs3d_Root::NewGroup(aPresentation);
73   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
74
75   
76   gp_Vec dirac(aPntAttach, aPntEnd);
77                                    // vecteur directeur du seg. de raccord
78   dirac.Normalize();
79   gp_Vec norac = dirac.Crossed(gp_Vec(aNormPln));
80   gp_Ax1 ax(aPntEnd, aNormPln);
81   norac.Rotate(ax, M_PI/8);
82                                   // vecteur normal au seg. de raccord
83   norac*=(symbsize/2);
84   gp_Pnt P1 = aPntEnd.Translated(norac);
85   gp_Pnt P2 = aPntEnd.Translated(-norac);
86
87   V(1).SetCoord(P1.X(),P1.Y(),P1.Z());
88   V(2).SetCoord(P2.X(),P2.Y(),P2.Z());
89   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
90
91   // trace des 'dents'
92   norac*=0.8;
93   P1 = aPntEnd.Translated(norac);
94   P2 = aPntEnd.Translated(-norac);
95   dirac*=(symbsize/2);
96   gp_Pnt PF(P1.XYZ());
97   gp_Pnt PL = PF.Translated(dirac);
98   PL.Translate(norac);
99   V(1).SetCoord( PF.X(), PF.Y(), PF.Z() );
100   V(2).SetCoord( PL.X(), PL.Y(), PL.Z() );
101   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
102
103   PF.SetXYZ(P2.XYZ());
104   PL = PF.Translated(dirac);
105   PL.Translate(norac);
106   V(1).SetCoord( PF.X(), PF.Y(), PF.Z() );
107   V(2).SetCoord( PL.X(), PL.Y(), PL.Z() );
108   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
109
110   PF.SetXYZ((P1.XYZ() + P2.XYZ())/2);
111   PL = PF.Translated(dirac);
112   PL.Translate(norac);
113   V(1).SetCoord( PF.X(), PF.Y(), PF.Z() );
114   V(2).SetCoord( PL.X(), PL.Y(), PL.Z() );
115   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
116
117   // On ajoute un rond au point d'attache
118   Prs3d_Root::NewGroup(aPresentation);
119   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
120   Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
121   MarkerAsp->SetType(Aspect_TOM_BALL);
122   MarkerAsp->SetScale(0.8);
123   Quantity_Color acolor;
124   Aspect_TypeOfLine atype;
125   Standard_Real awidth;
126   LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
127   MarkerAsp->SetColor(acolor);
128   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
129   Graphic3d_Vertex V3d(aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
130   Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
131
132 }