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