summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_PlaneTrihedron.cxx
blob: 73258252da043422ca41d48d849f38b125b39703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// File:	AIS_PlaneTrihedron.cxx
// Created:	Fri Dec 13 15:33:04 1996
// Author:	Jean-Pierre COMBE
//		<jpr>

#define GER61351		//GG_171199     Enable to set an object RGB color
//						  instead a restricted object NameOfColor.

#define OCC218                  //SAV using DsgPrs_XYZAxisPresentation to draw axes.
                                // + X/YAxis() returns AIS_Line instead of AIS_Axis
                                // + (-1) selection mode token into account 
                                // (SAMTECH specific)

#ifdef OCC218
#include <DsgPrs_XYZAxisPresentation.hxx>
#include <AIS_Line.hxx>
#include <Geom_Line.hxx>
#endif

#include <AIS_PlaneTrihedron.ixx>

#include <DsgPrs_DatumPrs.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitivePoint.hxx>
#include <Geom_Axis1Placement.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_CartesianPoint.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_DatumAspect.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_Structure.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Aspect_TypeOfLine.hxx>
#include <AIS_Drawer.hxx>
#include <UnitsAPI.hxx>
#include <TColgp_Array1OfPnt.hxx>

#include <Select3D_SensitiveFace.hxx>

#define OCC10

void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer);

//=======================================================================
//function : AIS_PlaneTrihedron
//purpose  : 
//=======================================================================
AIS_PlaneTrihedron::AIS_PlaneTrihedron(const Handle(Geom_Plane)& aPlane)
:myPlane(aPlane)
{
  Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
//POP  Standard_Real aLength = UnitsAPI::CurrentFromLS (100. ,"LENGTH");
  Standard_Real aLength = UnitsAPI::AnyToLS (100. ,"mm");
  DA->SetAxisLength(aLength,aLength,aLength);
  Quantity_NameOfColor col = Quantity_NOC_ROYALBLUE1;
  DA->FirstAxisAspect()->SetColor(col);
  DA->SecondAxisAspect()->SetColor(col);
  DA->SetDrawFirstAndSecondAxis(Standard_True);
  DA->SetDrawThirdAxis(Standard_False);
  myDrawer->SetDatumAspect(DA); // odl - specific is created because it is modified
  myShapes[0] = Position();
  myShapes[1] = XAxis();
  myShapes[2] = YAxis();

#ifdef OCC218
  myXLabel = TCollection_AsciiString( "X" );
  myYLabel = TCollection_AsciiString( "Y" );
#endif
}

//=======================================================================
//function : Component
//purpose  : 
//=======================================================================

 Handle(Geom_Plane) AIS_PlaneTrihedron::Component()
{
  return myPlane;
}


//=======================================================================
//function : SetComponent
//purpose  : 
//=======================================================================

 void AIS_PlaneTrihedron::SetComponent(const Handle(Geom_Plane)& aPlane)
{
  myPlane = aPlane;
}

//=======================================================================
//function : XAxis
//purpose  : 
//=======================================================================
#ifdef OCC218
Handle(AIS_Line) AIS_PlaneTrihedron::XAxis() const 
{
  Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().XAxis());
  Handle(AIS_Line) aLine = new AIS_Line (aGLine);
  aLine->SetColor(Quantity_NOC_ROYALBLUE1);
  return aLine;
}
#else
Handle(AIS_Axis) AIS_PlaneTrihedron::XAxis() const 
{
  Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().XAxis());
  Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
  anAxis->SetTypeOfAxis(AIS_TOAX_XAxis);
  return anAxis;
}
#endif

//=======================================================================
//function : YAxis
//purpose  : 
//=======================================================================
#ifdef OCC218
Handle(AIS_Line) AIS_PlaneTrihedron::YAxis() const 
{
  Handle(Geom_Line) aGLine = new Geom_Line(myPlane->Pln().YAxis());
  Handle(AIS_Line) aLine = new AIS_Line (aGLine);
  aLine->SetColor(Quantity_NOC_ROYALBLUE1);
  return aLine;
}
#else
Handle(AIS_Axis) AIS_PlaneTrihedron::YAxis() const 
{
  Handle(Geom_Axis1Placement) anAx1 = new Geom_Axis1Placement(myPlane->Pln().YAxis());
  Handle(AIS_Axis) anAxis = new AIS_Axis (anAx1);
  anAxis->SetTypeOfAxis(AIS_TOAX_YAxis);
  return anAxis;
}
#endif

//=======================================================================
//function : Position
//purpose  : 
//=======================================================================
Handle(AIS_Point) AIS_PlaneTrihedron::Position() const 
{
  gp_Pnt aPnt = myPlane->Pln().Location();
  Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
  Handle(AIS_Point) aPt = new AIS_Point (aPoint);
  return aPt;
}

#ifdef OCC10
void AIS_PlaneTrihedron::SetLength(const Standard_Real theLength) {
  myDrawer->DatumAspect()->SetAxisLength(theLength, theLength, theLength);
  SetToUpdate();
}

Standard_Real AIS_PlaneTrihedron::GetLength() const {
  return myDrawer->DatumAspect()->FirstAxisLength();
}
#endif

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager3d)&,
				    const Handle(Prs3d_Presentation)& aPresentation, 
				    const Standard_Integer)
{
  aPresentation->Clear();
  aPresentation->SetDisplayPriority(5);
#ifndef OCC218
  DsgPrs_DatumPrs::Add(aPresentation,myPlane->Position().Ax2(),myDrawer);
#else
  // drawing axis in X direction
  gp_Pnt first, last;
  Standard_Real value = myDrawer->DatumAspect()->FirstAxisLength();
  gp_Dir xDir = myPlane->Position().Ax2().XDirection();

  gp_Pnt orig = myPlane->Position().Ax2().Location();
  Quantity_Length xo,yo,zo,x,y,z;
  orig.Coord( xo, yo, zo );
  xDir.Coord( x, y, z );
  first.SetCoord( xo, yo, zo );
  last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
  
  DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), xDir, value, myXLabel.ToCString(), first, last );
  
  // drawing axis in Y direction
  value = myDrawer->DatumAspect()->SecondAxisLength();
  gp_Dir yDir = myPlane->Position().Ax2().YDirection();

  yDir.Coord( x, y, z );
  last.SetCoord( xo + x * value, yo + y * value, zo + z * value );
  DsgPrs_XYZAxisPresentation::Add( aPresentation, myDrawer->DatumAspect()->FirstAxisAspect(), myDrawer->ArrowAspect(), myDrawer->TextAspect(), yDir, value, myYLabel.ToCString(), first, last );

#endif
  aPresentation->SetInfiniteState (Standard_True);
}

void AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
{
// Standard_NotImplemented::Raise("AIS_PlaneTrihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
}

//=======================================================================
//function : ComputeSelection
//purpose  : 
//=======================================================================

void AIS_PlaneTrihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
					     const Standard_Integer aMode)
{
  Standard_Integer Prior;
  Handle(SelectMgr_EntityOwner) eown;
  TColgp_Array1OfPnt PP(1,4),PO(1,4);
//  ExtremityPoints(PP);
  ExtremityPoints(PP,myPlane,myDrawer);
  switch (aMode) {
  case 0:
    {   // triedre complet
      Prior = 5;
//      gp_Ax2 theax = gp_Ax2(myPlane->Position().Ax2());
//      gp_Pnt p1 = theax.Location();
      
      eown = new SelectMgr_EntityOwner(this,Prior);
      for (Standard_Integer i=1; i<=2;i++)
	aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
      
      break;
    }
  case 1:
    {  //origine
      Prior = 8;
      eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
      aSelection->Add(new Select3D_SensitivePoint(eown,myPlane->Location()));

      break;
    }
  case 2:
    { //axes ... priorite 7
      Prior = 7;
      for (Standard_Integer i=1; i<=2;i++){
	eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
	aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));

      }
      break;
    }
#ifdef OCC218
  case -1:
    {
      Prior = 5;
      aSelection->Clear();
      break;
    }
#endif
  }
}

void AIS_PlaneTrihedron::SetColor(const Quantity_NameOfColor aCol)
#ifdef GER61351
{
  SetColor(Quantity_Color(aCol));
}

void AIS_PlaneTrihedron::SetColor(const Quantity_Color &aCol)
#endif
{
  hasOwnColor=Standard_True;
  myOwnColor = aCol;
  myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
  myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
}

//=======================================================================
//function : Compute
//purpose  : to avoid warning
//=======================================================================
void AIS_PlaneTrihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&, 
			       const Handle(Graphic2d_GraphicObject)&,
			       const Standard_Integer)
{
}

void AIS_PlaneTrihedron::Compute(const Handle(Prs3d_Projector)&, 
			       const Handle(Prs3d_Presentation)&)
{
}


//=======================================================================
//function : ExtremityPoints
//purpose  : to avoid warning
//=======================================================================
//void  AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const 
void  ExtremityPoints(TColgp_Array1OfPnt& PP,const Handle(Geom_Plane)& myPlane,const Handle(Prs3d_Drawer)& myDrawer )
{
//  gp_Ax2 theax(myPlane->Ax2());
  gp_Ax2 theax(myPlane->Position().Ax2());
  PP(1) = theax.Location();

  Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
  gp_Vec vec = theax.XDirection();
  vec *= len;
  PP(2) = PP(1).Translated(vec);
  
  len = myDrawer->DatumAspect()->SecondAxisLength();
  vec = theax.YDirection();
  vec *= len;
  PP(3) = PP(1).Translated(vec);

}

//=======================================================================
//function : AcceptDisplayMode
//purpose  : 
//=======================================================================
Standard_Boolean  AIS_PlaneTrihedron::AcceptDisplayMode(const Standard_Integer aMode) const
{return aMode == 0;}