Salome HOME
lot 10 - warnings for DTM - untested
[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 #include <Quantity_Length.hxx>
29
30 HYDROGUI_AISTrihedron::HYDROGUI_AISTrihedron( const Handle(Geom_Axis2Placement)& thePlacement )
31  : AIS_Trihedron(thePlacement)
32 {
33   ComputeFields();
34 }
35
36 Handle(AIS_Trihedron) HYDROGUI_AISTrihedron::createTrihedron( double theSize )
37 {
38   Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() );
39   Handle(HYDROGUI_AISTrihedron) aTrihedron = new HYDROGUI_AISTrihedron( anAxis );
40   aTrihedron->SetInfiniteState( Standard_True );
41
42   Quantity_Color aCol( 193/255., 205/255., 193/255., Quantity_TOC_RGB );
43   aTrihedron->SetArrowColor( aCol.Name() );
44   aTrihedron->SetSize( theSize );
45
46   Handle(Prs3d_Drawer) aDrawer = aTrihedron->Attributes();
47   if ( aDrawer->HasOwnDatumAspect() ) {
48     Handle(Prs3d_DatumAspect) aDaspect = aDrawer->DatumAspect();
49     aDaspect->FirstAxisAspect()->SetColor( Quantity_Color( 1.0, 0.0, 0.0, Quantity_TOC_RGB ) );
50     aDaspect->SecondAxisAspect()->SetColor( Quantity_Color( 0.0, 1.0, 0.0, Quantity_TOC_RGB ) );
51     aDaspect->ThirdAxisAspect()->SetColor( Quantity_Color( 0.0, 0.0, 1.0, Quantity_TOC_RGB ) );
52   }
53   
54   aTrihedron->SetAxis2Placement();
55   return aTrihedron;
56 }
57
58 void HYDROGUI_AISTrihedron::SetAxis2Placement()
59 {
60   ComputeFields();
61 }
62
63 void HYDROGUI_AISTrihedron::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
64                                      const Handle(Prs3d_Presentation)& thePresentation, 
65                                      const Standard_Integer theMode)
66 {
67   thePresentation->Clear();
68   thePresentation->SetInfiniteState( Standard_True );
69
70   ComputeAxis(thePresentation, myUParams);
71   ComputeAxis(thePresentation, myZParams);
72 }
73
74 void HYDROGUI_AISTrihedron::ComputeAxis( const Handle(Prs3d_Presentation)& thePresentation,
75                                          const AxisParameters& theParams )
76 {
77   DsgPrs_XYZAxisPresentation::Add( thePresentation, theParams.myLineAspect,
78                                    myDrawer->ArrowAspect(), myDrawer->TextAspect(),
79                                    theParams.myDir, theParams.myVal, theParams.myText,
80                                    theParams.myPfirst, theParams.myPlast );
81 }
82
83 void HYDROGUI_AISTrihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
84                                     const Handle(Geom_Transformation)& aTransformation,
85                                     const Handle(Prs3d_Presentation)& aPresentation)
86 {
87 }
88
89 void HYDROGUI_AISTrihedron::ComputeSelection( const Handle(SelectMgr_Selection)& aSelection,
90                                               const Standard_Integer aMode )
91 {
92 }
93
94 void HYDROGUI_AISTrihedron::ComputeFields()
95 {
96   gp_Ax2 anAx2 = Component()->Ax2();
97
98   Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
99   gp_Pnt Orig = anAx2.Location();
100   Quantity_Length xo,yo,zo,x,y,z;
101   Orig.Coord(xo,yo,zo);
102
103   gp_Dir oX = anAx2.XDirection();
104   oX.Coord(x,y,z);
105   myUParams.myPfirst.SetCoord(xo,yo,zo);
106   myUParams.myVal = DA->FirstAxisLength();
107   myUParams.myDir = oX;
108   myUParams.myText = "U";
109   myUParams.myLineAspect = DA->FirstAxisAspect();
110   x = xo + x*myUParams.myVal;
111   y = yo + y*myUParams.myVal;
112   z = zo + z*myUParams.myVal;
113   myUParams.myPlast.SetCoord(x,y,z);
114
115   gp_Dir oY = anAx2.YDirection();
116   oY.Coord(x,y,z);
117   myZParams.myPfirst.SetCoord(xo,yo,zo);
118   myZParams.myVal = DA->SecondAxisLength();
119   myZParams.myDir = oY;
120   myZParams.myText = "Z";
121   myZParams.myLineAspect = DA->SecondAxisAspect();
122   x = xo + x*myZParams.myVal;
123   y = yo + y*myZParams.myVal;
124   z = zo + z*myZParams.myVal;
125   myZParams.myPlast.SetCoord(x,y,z);
126 }