0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[occt.git] / src / V3d / V3d_Viewer_3.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_Viewer_3.cxx :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 27-12-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
24
25 REMARQUES :
26 -----------
27
28************************************************************************/
29
30#define IMP240300 //GG
31// -> Remove the grid plane axis when it is requested.
32// -> Redraw the privilegied grid plane after any change
33
34/*----------------------------------------------------------------------*/
35/*
36 * Includes
37 */
38
39#include <V3d_Viewer.jxx>
40
41#include <Graphic3d_AspectLine3d.hxx>
42#include <Graphic3d_AspectText3d.hxx>
43#include <gp_Dir.hxx>
44#include <gp_Pnt.hxx>
45#include <Graphic3d_Structure.hxx>
46#include <Graphic3d_Group.hxx>
47
b8ddfc2f 48#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 49
50/*----------------------------------------------------------------------*/
51/*
52 * Static variable
53 */
54
55#define LOPTIM
56#ifndef LOPTIM
57static TCollection_AsciiString XLetter("X");
58static TCollection_AsciiString YLetter("Y");
59static TCollection_AsciiString ZLetter("Z");
60#else
61static TCollection_AsciiString _XLetter() {
62 static TCollection_AsciiString XLetter("X");
63return XLetter;
64}
65#define XLetter _XLetter()
66
67static TCollection_AsciiString _YLetter() {
68 static TCollection_AsciiString YLetter("Y");
69return YLetter;
70}
71#define YLetter _YLetter()
72
73static TCollection_AsciiString _ZLetter() {
74 static TCollection_AsciiString ZLetter("Z");
75return ZLetter;
76}
77#define ZLetter _ZLetter()
78
79#endif // LOPTIM
80
81/*----------------------------------------------------------------------*/
82
b8ddfc2f 83void V3d_Viewer::SetPrivilegedPlane(const gp_Ax3& aPlane)
84{
7fd59977 85 myPrivilegedPlane = aPlane;
7fd59977 86 Grid()->SetDrawMode(Grid()->DrawMode());
b8ddfc2f 87 for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
7fd59977 88 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
b8ddfc2f 89 if(myDisplayPlane)
90 DisplayPrivilegedPlane(Standard_True,myDisplayPlaneLength);
91 else
7fd59977 92 Update();
7fd59977 93}
94
95/*----------------------------------------------------------------------*/
b8ddfc2f 96
97gp_Ax3 V3d_Viewer::PrivilegedPlane() const
98{
7fd59977 99 return myPrivilegedPlane;
7fd59977 100}
101
102/*----------------------------------------------------------------------*/
b8ddfc2f 103void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quantity_Length aSize)
104{
105 Standard_Boolean Change = (myDisplayPlane != OnOff);
7fd59977 106 myDisplayPlane = OnOff;
107 myDisplayPlaneLength = aSize;
108
b8ddfc2f 109 if(myDisplayPlane)
110 {
7fd59977 111 if(myPlaneStructure.IsNull()) {
112 myPlaneStructure = new Graphic3d_Structure(MyViewer);
113 myPlaneStructure->SetInfiniteState(Standard_True);
114 myPlaneStructure->Display();
115 }
116 else
117 myPlaneStructure->Clear();
b8ddfc2f 118
b64d84be 119 Handle(Graphic3d_Group) Group = myPlaneStructure->NewGroup();
7fd59977 120
121 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ;
122 LineAttrib->SetColor(Quantity_Color(Quantity_NOC_GRAY60));
123 Group->SetPrimitivesAspect(LineAttrib) ;
124
125 Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d();
126 TextAttrib->SetColor(Quantity_Color(Quantity_NOC_ROYALBLUE1));
127 Group->SetPrimitivesAspect(TextAttrib);
b8ddfc2f 128
129 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
130
131 const gp_Pnt &p0 = myPrivilegedPlane.Location();
132
133 const gp_Pnt pX(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.XDirection().XYZ());
134 aPrims->AddVertex(p0);
135 aPrims->AddVertex(pX);
136 Group->Text(XLetter.ToCString(),Graphic3d_Vertex(pX.X(),pX.Y(),pX.Z()),1./81.);
137
138 const gp_Pnt pY(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.YDirection().XYZ());
139 aPrims->AddVertex(p0);
140 aPrims->AddVertex(pY);
141 Group->Text(YLetter.ToCString(),Graphic3d_Vertex(pY.X(),pY.Y(),pY.Z()),1./81.);
7fd59977 142
b8ddfc2f 143 const gp_Pnt pZ(p0.XYZ() + myDisplayPlaneLength*myPrivilegedPlane.Direction().XYZ());
144 aPrims->AddVertex(p0);
145 aPrims->AddVertex(pZ);
146 Group->Text(ZLetter.ToCString(),Graphic3d_Vertex(pZ.X(),pZ.Y(),pZ.Z()),1./81.);
147
148 Group->AddPrimitiveArray(aPrims);
149
150 myPlaneStructure->Display();
151 }
152 else
153 {
7fd59977 154 if( !myPlaneStructure.IsNull() ) myPlaneStructure->Erase();
7fd59977 155 }
156 if(Change) Update();
157}
158
159/*----------------------------------------------------------------------*/