0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[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 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.
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.hxx>
18
19 #include <gp_Ax1.hxx>
20 #include <gp_Dir.hxx>
21 #include <gp_Pnt.hxx>
22 #include <gp_Vec.hxx>
23 #include <Graphic3d_ArrayOfPoints.hxx>
24 #include <Graphic3d_ArrayOfSegments.hxx>
25 #include <Graphic3d_AspectLine3d.hxx>
26 #include <Graphic3d_AspectMarker3d.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Prs3d_DimensionAspect.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_Presentation.hxx>
31 #include <Prs3d_Root.hxx>
32
33 //=======================================================================
34 //function : Add
35 //purpose  : 
36 //=======================================================================
37 void DsgPrs_FixPresentation::Add(
38                        const Handle(Prs3d_Presentation)& aPresentation,
39                        const Handle(Prs3d_Drawer)& aDrawer,
40                        const gp_Pnt& aPntAttach,
41                        const gp_Pnt& aPntEnd,
42                        const gp_Dir& aNormPln,
43                        const Standard_Real symbsize)
44 {
45   Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
46   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
47
48   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(10);
49
50   //Trace du segment de raccordement
51   aPrims->AddVertex(aPntAttach);
52   aPrims->AddVertex(aPntEnd);
53
54   // trace du symbole 'Fix'
55   gp_Vec dirac(aPntAttach, aPntEnd); // vecteur directeur du seg. de raccord
56   dirac.Normalize();
57   gp_Vec norac = dirac.Crossed(gp_Vec(aNormPln));
58   gp_Ax1 ax(aPntEnd, aNormPln);
59   norac.Rotate(ax, M_PI/8); // vecteur normal au seg. de raccord
60   norac*=(symbsize/2);
61   gp_Pnt P1 = aPntEnd.Translated(norac);
62   gp_Pnt P2 = aPntEnd.Translated(-norac);
63
64   aPrims->AddVertex(P1);
65   aPrims->AddVertex(P2);
66
67   // trace des 'dents'
68   norac*=0.8;
69   P1 = aPntEnd.Translated(norac);
70   P2 = aPntEnd.Translated(-norac);
71   dirac*=(symbsize/2);
72   gp_Pnt PF = P1;
73   gp_Pnt PL = PF.Translated(dirac);
74   PL.Translate(norac);
75
76   aPrims->AddVertex(PF);
77   aPrims->AddVertex(PL);
78
79   PF = P2;
80   PL = PF.Translated(dirac);
81   PL.Translate(norac);
82
83   aPrims->AddVertex(PF);
84   aPrims->AddVertex(PL);
85
86   PF.SetXYZ(0.5*(P1.XYZ() + P2.XYZ()));
87   PL = PF.Translated(dirac);
88   PL.Translate(norac);
89
90   aPrims->AddVertex(PF);
91   aPrims->AddVertex(PL);
92
93   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
94
95   Prs3d_Root::NewGroup(aPresentation);
96   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
97   Quantity_Color aColor = LA->LineAspect()->Aspect()->Color();
98   Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
99   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp);
100   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
101   anArrayOfPoints->AddVertex (aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
102   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
103 }