Salome HOME
refs #432: refactoring of the shape class
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_AISTrihedron.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_AISTrihedron.h"
24
25 #include <Geom_Axis2Placement.hxx>
26 #include <Prs3d_DatumAspect.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_Presentation.hxx>
29 #include <AIS_Drawer.hxx>
30 #include <DsgPrs_XYZAxisPresentation.hxx>
31 #include <gp_Ax2.hxx>
32
33 HYDROGUI_AISTrihedron::HYDROGUI_AISTrihedron( const Handle(Geom_Axis2Placement)& thePlacement )
34  : AIS_Trihedron(thePlacement)
35 {
36   ComputeFields();
37 }
38
39 Handle(AIS_Trihedron) HYDROGUI_AISTrihedron::createTrihedron( double theSize )
40 {
41   Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() );
42   Handle(HYDROGUI_AISTrihedron) aTrihedron = new HYDROGUI_AISTrihedron( anAxis );
43   aTrihedron->SetInfiniteState( Standard_True );
44
45   Quantity_Color aCol( 193/255., 205/255., 193/255., Quantity_TOC_RGB );
46   aTrihedron->SetArrowColor( aCol.Name() );
47   aTrihedron->SetSize( theSize );
48
49   Handle(AIS_Drawer) aDrawer = aTrihedron->Attributes();
50   if ( aDrawer->HasDatumAspect() ) {
51     Handle(Prs3d_DatumAspect) aDaspect = aDrawer->DatumAspect();
52     aDaspect->FirstAxisAspect()->SetColor( Quantity_Color( 1.0, 0.0, 0.0, Quantity_TOC_RGB ) );
53     aDaspect->SecondAxisAspect()->SetColor( Quantity_Color( 0.0, 1.0, 0.0, Quantity_TOC_RGB ) );
54     aDaspect->ThirdAxisAspect()->SetColor( Quantity_Color( 0.0, 0.0, 1.0, Quantity_TOC_RGB ) );
55   }
56   aTrihedron->SetAxis2Placement();
57   return aTrihedron;
58 }
59
60 void HYDROGUI_AISTrihedron::SetAxis2Placement()
61 {
62   ComputeFields();
63 }
64
65 void HYDROGUI_AISTrihedron::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
66                                      const Handle(Prs3d_Presentation)& thePresentation, 
67                                      const Standard_Integer theMode)
68 {
69   thePresentation->Clear();
70   thePresentation->SetInfiniteState( Standard_True );
71
72   ComputeAxis(thePresentation, myUParams);
73   ComputeAxis(thePresentation, myZParams);
74 }
75
76 void HYDROGUI_AISTrihedron::ComputeAxis( const Handle(Prs3d_Presentation)& thePresentation,
77                                          const AxisParameters& theParams )
78 {
79   DsgPrs_XYZAxisPresentation::Add( thePresentation, theParams.myLineAspect,
80                                    myDrawer->ArrowAspect(), myDrawer->TextAspect(),
81                                    theParams.myDir, theParams.myVal, theParams.myText,
82                                    theParams.myPfirst, theParams.myPlast );
83 }
84
85 void HYDROGUI_AISTrihedron::Compute(const Handle_Prs3d_Projector& aProjector,
86                                     const Handle_Geom_Transformation& aTransformation,
87                                     const Handle_Prs3d_Presentation& aPresentation)
88 {
89 }
90
91 void HYDROGUI_AISTrihedron::ComputeSelection( const Handle(SelectMgr_Selection)& aSelection,
92                                               const Standard_Integer aMode )
93 {
94 }
95
96 void HYDROGUI_AISTrihedron::ComputeFields()
97 {
98   gp_Ax2 anAx2 = Component()->Ax2();
99
100   Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
101   gp_Pnt Orig = anAx2.Location();
102   Quantity_Length xo,yo,zo,x,y,z;
103   Orig.Coord(xo,yo,zo);
104
105   gp_Dir oX = anAx2.XDirection();
106   oX.Coord(x,y,z);
107   myUParams.myPfirst.SetCoord(xo,yo,zo);
108   myUParams.myVal = DA->FirstAxisLength();
109   myUParams.myDir = oX;
110   myUParams.myText = "U";
111   myUParams.myLineAspect = DA->FirstAxisAspect();
112   x = xo + x*myUParams.myVal;
113   y = yo + y*myUParams.myVal;
114   z = zo + z*myUParams.myVal;
115   myUParams.myPlast.SetCoord(x,y,z);
116
117   gp_Dir oY = anAx2.YDirection();
118   oY.Coord(x,y,z);
119   myZParams.myPfirst.SetCoord(xo,yo,zo);
120   myZParams.myVal = DA->SecondAxisLength();
121   myZParams.myDir = oY;
122   myZParams.myText = "Z";
123   myZParams.myLineAspect = DA->SecondAxisAspect();
124   x = xo + x*myZParams.myVal;
125   y = yo + y*myZParams.myVal;
126   z = zo + z*myZParams.myVal;
127   myZParams.myPlast.SetCoord(x,y,z);
128 }