1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 /***********************************************************************
18 Classe V3d_Viewer_3.cxx :
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 27-12-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
28 ************************************************************************/
30 #define IMP240300 //GG
31 // -> Remove the grid plane axis when it is requested.
32 // -> Redraw the privilegied grid plane after any change
34 /*----------------------------------------------------------------------*/
39 #include <V3d_Viewer.jxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectText3d.hxx>
45 #include <Graphic3d_Structure.hxx>
46 #include <Graphic3d_Group.hxx>
48 #include <Graphic3d_ArrayOfSegments.hxx>
50 /*----------------------------------------------------------------------*/
57 static TCollection_AsciiString XLetter("X");
58 static TCollection_AsciiString YLetter("Y");
59 static TCollection_AsciiString ZLetter("Z");
61 static TCollection_AsciiString _XLetter() {
62 static TCollection_AsciiString XLetter("X");
65 #define XLetter _XLetter()
67 static TCollection_AsciiString _YLetter() {
68 static TCollection_AsciiString YLetter("Y");
71 #define YLetter _YLetter()
73 static TCollection_AsciiString _ZLetter() {
74 static TCollection_AsciiString ZLetter("Z");
77 #define ZLetter _ZLetter()
81 /*----------------------------------------------------------------------*/
83 void V3d_Viewer::SetPrivilegedPlane(const gp_Ax3& aPlane)
85 myPrivilegedPlane = aPlane;
86 Grid()->SetDrawMode(Grid()->DrawMode());
87 for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
88 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
90 DisplayPrivilegedPlane(Standard_True,myDisplayPlaneLength);
95 /*----------------------------------------------------------------------*/
97 gp_Ax3 V3d_Viewer::PrivilegedPlane() const
99 return myPrivilegedPlane;
102 /*----------------------------------------------------------------------*/
103 void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quantity_Length aSize)
105 Standard_Boolean Change = (myDisplayPlane != OnOff);
106 myDisplayPlane = OnOff;
107 myDisplayPlaneLength = aSize;
111 if(myPlaneStructure.IsNull()) {
112 myPlaneStructure = new Graphic3d_Structure(MyViewer);
113 myPlaneStructure->SetInfiniteState(Standard_True);
114 myPlaneStructure->Display();
117 myPlaneStructure->Clear();
119 Handle(Graphic3d_Group) Group = myPlaneStructure->NewGroup();
121 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ;
122 LineAttrib->SetColor(Quantity_Color(Quantity_NOC_GRAY60));
123 Group->SetPrimitivesAspect(LineAttrib) ;
125 Handle(Graphic3d_AspectText3d) TextAttrib = new Graphic3d_AspectText3d();
126 TextAttrib->SetColor(Quantity_Color(Quantity_NOC_ROYALBLUE1));
127 Group->SetPrimitivesAspect(TextAttrib);
129 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
131 const gp_Pnt &p0 = myPrivilegedPlane.Location();
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.);
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.);
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.);
148 Group->AddPrimitiveArray(aPrims);
150 myPlaneStructure->Display();
154 if( !myPlaneStructure.IsNull() ) myPlaneStructure->Erase();
159 /*----------------------------------------------------------------------*/