1 // Created on: 1996-12-13
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // + X/YAxis() returns AIS_Line instead of AIS_Axis
18 // + (-1) selection mode token into account
21 #include <DsgPrs_XYZAxisPresentation.hxx>
22 #include <AIS_Line.hxx>
23 #include <Geom_Line.hxx>
25 #include <AIS_PlaneTrihedron.ixx>
27 #include <DsgPrs_DatumPrs.hxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <Select3D_SensitiveSegment.hxx>
30 #include <Select3D_SensitivePoint.hxx>
31 #include <Geom_Axis1Placement.hxx>
32 #include <Geom_Axis2Placement.hxx>
33 #include <Geom_CartesianPoint.hxx>
38 #include <Prs3d_Drawer.hxx>
39 #include <Prs3d_LineAspect.hxx>
40 #include <Prs3d_DatumAspect.hxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_Structure.hxx>
43 #include <Graphic3d_MaterialAspect.hxx>
44 #include <Graphic3d_AspectFillArea3d.hxx>
45 #include <Aspect_TypeOfLine.hxx>
46 #include <AIS_Drawer.hxx>
47 #include <UnitsAPI.hxx>
48 #include <TColgp_Array1OfPnt.hxx>
50 #include <Select3D_SensitiveFace.hxx>
52 void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
54 //=======================================================================
55 //function : AIS_PlaneTrihedron
57 //=======================================================================
58 AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
61 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
62 //POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
63 Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
64 DA->SetAxisLength(aLength,aLength,aLength);
65 Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1;
66 DA->FirstAxisAspect()->SetColor(col);
67 DA->SecondAxisAspect()->SetColor(col);
68 DA->SetDrawFirstAndSecondAxis(Standard_True);
69 DA->SetDrawThirdAxis(Standard_False);
70 myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
71 myShapes[0] = Position();
72 myShapes[1] = XAxis();
73 myShapes[2] = YAxis();
75 myXLabel = TCollection_AsciiString( "X" );
76 myYLabel = TCollection_AsciiString( "Y" );
79 //=======================================================================
80 //function : Component
82 //=======================================================================
84 Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
90 //=======================================================================
91 //function : SetComponent
93 //=======================================================================
95 void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
100 //=======================================================================
103 //=======================================================================
104 Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const
106 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
107 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
108 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
112 //=======================================================================
115 //=======================================================================
116 Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const
118 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
119 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
120 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
124 //=======================================================================
125 //function : Position
127 //=======================================================================
128 Handle(AIS_Point) AIS_PlaneTrihedron::Position() const
130 gp_Pnt aPnt = myPlane->Pln().Location();
131 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
132 Handle(AIS_Point) aPt = new AIS_Point (aPoint);
136 void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
137 myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
141 Standard_Real AIS_PlaneTrihedron::GetLength() const {
142 return myDrawer->DatumAspect()->FirstAxisLength();
145 //=======================================================================
148 //=======================================================================
149 void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
150 const Handle(Prs3d_Presentation)& aPresentation,
151 const Standard_Integer)
153 aPresentation->Clear();
154 aPresentation->SetDisplayPriority(5);
155 // drawing axis in X direction
157 Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
158 gp_Dir xDir = myPlane->Position().Ax2().XDirection();
160 gp_Pnt orig = myPlane->Position().Ax2().Location();
161 Quantity_Length xo,yo,zo,x,y,z;
162 orig.Coord( xo, yo, zo );
163 xDir.Coord( x, y, z );
164 first.SetCoord( xo, yo, zo );
165 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
167 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
169 // drawing axis in Y direction
170 value = myDrawer->DatumAspect()->SecondAxisLength();
171 gp_Dir yDir = myPlane->Position().Ax2().YDirection();
173 yDir.Coord( x, y, z );
174 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
175 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
177 aPresentation->SetInfiniteState (Standard_True);
180 void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
182 // Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
183 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
186 //=======================================================================
187 //function : ComputeSelection
189 //=======================================================================
191 void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
192 const Standard_Integer aMode)
194 Standard_Integer Prior;
195 Handle(SelectMgr_EntityOwner) eown;
196 TColgp_Array1OfPnt PP(1,4),PO(1,4);
197 // ExtremityPoints(PP);
198 ExtremityPoints(PP,myPlane,myDrawer);
203 // gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
204 // gp_Pnt p1 = theax.Location();
206 eown = new SelectMgr_EntityOwner(this,Prior);
207 for (Standard_Integer i=1; i<=2;i++)
208 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
215 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
216 aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
221 { //axes ... priorite 7
223 for (Standard_Integer i=1; i<=2;i++){
224 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
225 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
239 void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
241 SetColor(Quantity_Color(aCol));
244 void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
246 hasOwnColor=Standard_True;
248 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
249 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
253 void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&,
254 const Handle(Prs3d_Presentation)&)
259 //=======================================================================
260 //function : ExtremityPoints
261 //purpose : to avoid warning
262 //=======================================================================
263 //void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
264 void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
266 // gp_Ax2 theax(myPlane->Ax2());
267 gp_Ax2 theax(myPlane->Position().Ax2());
268 PP(1) = theax.Location();
270 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
271 gp_Vec vec = theax.XDirection();
273 PP(2) = PP(1).Translated(vec);
275 len = myDrawer->DatumAspect()->SecondAxisLength();
276 vec = theax.YDirection();
278 PP(3) = PP(1).Translated(vec);
282 //=======================================================================
283 //function : AcceptDisplayMode
285 //=======================================================================
286 Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const