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