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 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
19 #define OCC218 //SAV using DsgPrs_XYZAxisPresentation to draw axes.
20 // + X/YAxis() returns AIS_Line instead of AIS_Axis
21 // + (-1) selection mode token into account
25 #include <DsgPrs_XYZAxisPresentation.hxx>
26 #include <AIS_Line.hxx>
27 #include <Geom_Line.hxx>
30 #include <AIS_PlaneTrihedron.ixx>
32 #include <DsgPrs_DatumPrs.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <Select3D_SensitiveSegment.hxx>
35 #include <Select3D_SensitivePoint.hxx>
36 #include <Geom_Axis1Placement.hxx>
37 #include <Geom_Axis2Placement.hxx>
38 #include <Geom_CartesianPoint.hxx>
43 #include <Prs3d_Drawer.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <Prs3d_DatumAspect.hxx>
46 #include <Graphic3d_AspectLine3d.hxx>
47 #include <Graphic3d_Structure.hxx>
48 #include <Graphic3d_MaterialAspect.hxx>
49 #include <Graphic3d_AspectFillArea3d.hxx>
50 #include <Aspect_TypeOfLine.hxx>
51 #include <AIS_Drawer.hxx>
52 #include <UnitsAPI.hxx>
53 #include <TColgp_Array1OfPnt.hxx>
55 #include <Select3D_SensitiveFace.hxx>
59 void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);
61 //=======================================================================
62 //function : AIS_PlaneTrihedron
64 //=======================================================================
65 AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
68 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
69 //POP Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
70 Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
71 DA->SetAxisLength(aLength,aLength,aLength);
72 Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1;
73 DA->FirstAxisAspect()->SetColor(col);
74 DA->SecondAxisAspect()->SetColor(col);
75 DA->SetDrawFirstAndSecondAxis(Standard_True);
76 DA->SetDrawThirdAxis(Standard_False);
77 myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
78 myShapes[0] = Position();
79 myShapes[1] = XAxis();
80 myShapes[2] = YAxis();
83 myXLabel = TCollection_AsciiString( "X" );
84 myYLabel = TCollection_AsciiString( "Y" );
88 //=======================================================================
89 //function : Component
91 //=======================================================================
93 Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
99 //=======================================================================
100 //function : SetComponent
102 //=======================================================================
104 void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
109 //=======================================================================
112 //=======================================================================
114 Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const
116 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
117 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
118 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
122 Handle(AIS_Axis) AIS_PlaneTrihedron::XAxis() const
124 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().XAxis());
125 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
126 anAxis->SetTypeOfAxis(AIS_TOAX_XAxis);
131 //=======================================================================
134 //=======================================================================
136 Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const
138 Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
139 Handle(AIS_Line) aLine = new AIS_Line (aGLine);
140 aLine->SetColor(Quantity_NOC_ROYALBLUE1);
144 Handle(AIS_Axis) AIS_PlaneTrihedron::YAxis() const
146 Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().YAxis());
147 Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
148 anAxis->SetTypeOfAxis(AIS_TOAX_YAxis);
153 //=======================================================================
154 //function : Position
156 //=======================================================================
157 Handle(AIS_Point) AIS_PlaneTrihedron::Position() const
159 gp_Pnt aPnt = myPlane->Pln().Location();
160 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
161 Handle(AIS_Point) aPt = new AIS_Point (aPoint);
166 void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
167 myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
171 Standard_Real AIS_PlaneTrihedron::GetLength() const {
172 return myDrawer->DatumAspect()->FirstAxisLength();
176 //=======================================================================
179 //=======================================================================
180 void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
181 const Handle(Prs3d_Presentation)& aPresentation,
182 const Standard_Integer)
184 aPresentation->Clear();
185 aPresentation->SetDisplayPriority(5);
187 DsgPrs_DatumPrs::Add(aPresentation,myPlane->Position().Ax2(),myDrawer);
189 // drawing axis in X direction
191 Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
192 gp_Dir xDir = myPlane->Position().Ax2().XDirection();
194 gp_Pnt orig = myPlane->Position().Ax2().Location();
195 Quantity_Length xo,yo,zo,x,y,z;
196 orig.Coord( xo, yo, zo );
197 xDir.Coord( x, y, z );
198 first.SetCoord( xo, yo, zo );
199 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
201 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
203 // drawing axis in Y direction
204 value = myDrawer->DatumAspect()->SecondAxisLength();
205 gp_Dir yDir = myPlane->Position().Ax2().YDirection();
207 yDir.Coord( x, y, z );
208 last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
209 DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );
212 aPresentation->SetInfiniteState (Standard_True);
215 void AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
217 // Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
218 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
221 //=======================================================================
222 //function : ComputeSelection
224 //=======================================================================
226 void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
227 const Standard_Integer aMode)
229 Standard_Integer Prior;
230 Handle(SelectMgr_EntityOwner) eown;
231 TColgp_Array1OfPnt PP(1,4),PO(1,4);
232 // ExtremityPoints(PP);
233 ExtremityPoints(PP,myPlane,myDrawer);
238 // gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
239 // gp_Pnt p1 = theax.Location();
241 eown = new SelectMgr_EntityOwner(this,Prior);
242 for (Standard_Integer i=1; i<=2;i++)
243 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
250 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
251 aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));
256 { //axes ... priorite 7
258 for (Standard_Integer i=1; i<=2;i++){
259 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
260 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
276 void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
278 SetColor(Quantity_Color(aCol));
281 void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
283 hasOwnColor=Standard_True;
285 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
286 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
290 void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&,
291 const Handle(Prs3d_Presentation)&)
296 //=======================================================================
297 //function : ExtremityPoints
298 //purpose : to avoid warning
299 //=======================================================================
300 //void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
301 void ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
303 // gp_Ax2 theax(myPlane->Ax2());
304 gp_Ax2 theax(myPlane->Position().Ax2());
305 PP(1) = theax.Location();
307 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
308 gp_Vec vec = theax.XDirection();
310 PP(2) = PP(1).Translated(vec);
312 len = myDrawer->DatumAspect()->SecondAxisLength();
313 vec = theax.YDirection();
315 PP(3) = PP(1).Translated(vec);
319 //=======================================================================
320 //function : AcceptDisplayMode
322 //=======================================================================
323 Standard_Boolean AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const