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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_AISTrihedron.h"
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>
28 #include <Quantity_Length.hxx>
30 HYDROGUI_AISTrihedron::HYDROGUI_AISTrihedron( const Handle(Geom_Axis2Placement)& thePlacement )
31 : AIS_Trihedron(thePlacement)
36 Handle(AIS_Trihedron) HYDROGUI_AISTrihedron::createTrihedron( double theSize )
38 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() );
39 Handle(HYDROGUI_AISTrihedron) aTrihedron = new HYDROGUI_AISTrihedron( anAxis );
40 aTrihedron->SetInfiniteState( Standard_True );
42 Quantity_Color aCol( 193/255., 205/255., 193/255., Quantity_TOC_RGB );
43 aTrihedron->SetArrowColor( aCol.Name() );
44 aTrihedron->SetSize( theSize );
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 ) );
54 aTrihedron->SetAxis2Placement();
58 void HYDROGUI_AISTrihedron::SetAxis2Placement()
63 void HYDROGUI_AISTrihedron::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
64 const Handle(Prs3d_Presentation)& thePresentation,
65 const Standard_Integer theMode)
67 thePresentation->Clear();
68 thePresentation->SetInfiniteState( Standard_True );
70 ComputeAxis(thePresentation, myUParams);
71 ComputeAxis(thePresentation, myZParams);
74 void HYDROGUI_AISTrihedron::ComputeAxis( const Handle(Prs3d_Presentation)& thePresentation,
75 const AxisParameters& theParams )
77 DsgPrs_XYZAxisPresentation::Add( thePresentation, theParams.myLineAspect,
78 myDrawer->ArrowAspect(), myDrawer->TextAspect(),
79 theParams.myDir, theParams.myVal, theParams.myText,
80 theParams.myPfirst, theParams.myPlast );
83 void HYDROGUI_AISTrihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
84 const Handle(Geom_Transformation)& aTransformation,
85 const Handle(Prs3d_Presentation)& aPresentation)
89 void HYDROGUI_AISTrihedron::ComputeSelection( const Handle(SelectMgr_Selection)& aSelection,
90 const Standard_Integer aMode )
94 void HYDROGUI_AISTrihedron::ComputeFields()
96 gp_Ax2 anAx2 = Component()->Ax2();
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);
103 gp_Dir oX = anAx2.XDirection();
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);
115 gp_Dir oY = anAx2.YDirection();
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);