0024530: TKMesh - remove unused package IntPoly
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DsgPrs_FixPresentation.ixx>
18
19 #include <Graphic3d_ArrayOfSegments.hxx>
20 #include <Graphic3d_Group.hxx>
21 #include <Graphic3d_AspectMarker3d.hxx>
22 #include <Graphic3d_AspectLine3d.hxx>
23 #include <Graphic3d_ArrayOfPoints.hxx>
24 #include <Graphic3d_Vertex.hxx>
25
26 #include <Prs3d_DimensionAspect.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_Root.hxx>
29
30 #include <Aspect_TypeOfLine.hxx>
31 #include <Aspect_TypeOfMarker.hxx>
32 #include <Aspect_AspectMarker.hxx>
33
34 #include <gp_Vec.hxx>
35 #include <gp_Dir.hxx>
36 #include <gp_Pnt.hxx>
37 #include <gp_Ax1.hxx>
38
39 #include <Quantity_Color.hxx>
40
41
42 //=======================================================================
43 //function : Add
44 //purpose  : 
45 //=======================================================================
46
47 void DsgPrs_FixPresentation::Add(
48                        const Handle(Prs3d_Presentation)& aPresentation,
49                        const Handle(Prs3d_Drawer)& aDrawer,
50                        const gp_Pnt& aPntAttach,
51                        const gp_Pnt& aPntEnd,
52                        const gp_Dir& aNormPln,
53                        const Standard_Real symbsize)
54 {
55   Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
56   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
57
58   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(10);
59
60   //Trace du segment de raccordement
61   aPrims->AddVertex(aPntAttach);
62   aPrims->AddVertex(aPntEnd);
63
64   // trace du symbole 'Fix'
65   gp_Vec dirac(aPntAttach, aPntEnd); // vecteur directeur du seg. de raccord
66   dirac.Normalize();
67   gp_Vec norac = dirac.Crossed(gp_Vec(aNormPln));
68   gp_Ax1 ax(aPntEnd, aNormPln);
69   norac.Rotate(ax, M_PI/8); // vecteur normal au seg. de raccord
70   norac*=(symbsize/2);
71   gp_Pnt P1 = aPntEnd.Translated(norac);
72   gp_Pnt P2 = aPntEnd.Translated(-norac);
73
74   aPrims->AddVertex(P1);
75   aPrims->AddVertex(P2);
76
77   // trace des 'dents'
78   norac*=0.8;
79   P1 = aPntEnd.Translated(norac);
80   P2 = aPntEnd.Translated(-norac);
81   dirac*=(symbsize/2);
82   gp_Pnt PF = P1;
83   gp_Pnt PL = PF.Translated(dirac);
84   PL.Translate(norac);
85
86   aPrims->AddVertex(PF);
87   aPrims->AddVertex(PL);
88
89   PF = P2;
90   PL = PF.Translated(dirac);
91   PL.Translate(norac);
92
93   aPrims->AddVertex(PF);
94   aPrims->AddVertex(PL);
95
96   PF.SetXYZ(0.5*(P1.XYZ() + P2.XYZ()));
97   PL = PF.Translated(dirac);
98   PL.Translate(norac);
99
100   aPrims->AddVertex(PF);
101   aPrims->AddVertex(PL);
102
103   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
104
105   // On ajoute un rond au point d'attache
106   Prs3d_Root::NewGroup(aPresentation);
107   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
108   Quantity_Color aColor;
109   Aspect_TypeOfLine aType;
110   Standard_Real aWidth;
111   LA->LineAspect()->Aspect()->Values (aColor, aType, aWidth);
112   Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
113   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp);
114   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
115   anArrayOfPoints->AddVertex (aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
116   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
117 }