0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / AIS / AIS_Trihedron.cxx
1 // Created on: 1995-10-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <AIS_Trihedron.hxx>
18
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_TrihedronOwner.hxx>
21 #include <AIS_TrihedronSelectionMode.hxx>
22 #include <Geom_Axis2Placement.hxx>
23 #include <gp_Pnt.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfPoints.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27
28 #include <Prs3d_Arrow.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_DatumAspect.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_PointAspect.hxx>
34 #include <Prs3d_Presentation.hxx>
35 #include <Prs3d_ShadingAspect.hxx>
36 #include <Prs3d_Text.hxx>
37 #include <Prs3d_TextAspect.hxx>
38 #include <Prs3d_ToolSphere.hxx>
39
40 #include <Select3D_SensitivePoint.hxx>
41 #include <Select3D_SensitivePrimitiveArray.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <Select3D_SensitiveTriangle.hxx>
44 #include <SelectMgr_EntityOwner.hxx>
45 #include <Standard_Type.hxx>
46
47 IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
48
49 //=======================================================================
50 //function : AIS_Trihedron
51 //purpose  :
52 //=======================================================================
53 AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
54 : myComponent (theComponent),
55   myTrihDispMode (Prs3d_DM_WireFrame),
56   myHasOwnSize (Standard_False),
57   myHasOwnTextColor (Standard_False),
58   myHasOwnArrowColor (Standard_False)
59 {
60   myAutoHilight = Standard_False;
61
62   // selection priorities
63   memset (mySelectionPriority, 0, sizeof(mySelectionPriority));
64   mySelectionPriority[Prs3d_DatumParts_None] =    5; // complete trihedron: priority 5 (same as faces)
65   mySelectionPriority[Prs3d_DatumParts_Origin] =  8; // origin: priority 8
66   for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
67   {
68     mySelectionPriority[aPartIter] = 7; // axes: priority: 7
69   }
70   for (int aPartIter = Prs3d_DatumParts_XOYAxis; aPartIter <= Prs3d_DatumParts_XOZAxis; ++aPartIter)
71   {
72     mySelectionPriority[aPartIter] = 5; // planes: priority: 5
73   }
74   myHiddenLineAspect = new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_EMPTY, 1.0f);
75
76   // trihedron labels
77   myLabels[Prs3d_DatumParts_XAxis] = "X";
78   myLabels[Prs3d_DatumParts_YAxis] = "Y";
79   myLabels[Prs3d_DatumParts_ZAxis] = "Z";
80 }
81
82 //=======================================================================
83 //function : SetComponent
84 //purpose  :
85 //=======================================================================
86 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
87 {
88   myComponent = theComponent;
89   SetToUpdate();
90 }
91
92 //=======================================================================
93 //function : setOwnDatumAspect
94 //purpose  :
95 //=======================================================================
96 void AIS_Trihedron::setOwnDatumAspect()
97 {
98   if (myDrawer->HasOwnDatumAspect())
99   {
100     return;
101   }
102
103   Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
104   myDrawer->SetDatumAspect (aNewAspect);
105   if (!myDrawer->Link().IsNull())
106   {
107     aNewAspect->CopyAspectsFrom (myDrawer->Link()->DatumAspect());
108   }
109 }
110
111 //=======================================================================
112 //function : SetSize
113 //purpose  :
114 //=======================================================================
115 void AIS_Trihedron::SetSize(const Standard_Real theValue)
116 {
117   myHasOwnSize = Standard_True;
118
119   setOwnDatumAspect();
120   myDrawer->DatumAspect()->SetAxisLength (theValue, theValue, theValue);
121
122   SetToUpdate();
123   UpdateSelection();
124 }
125
126 //=======================================================================
127 //function : UnsetSize
128 //purpose  :
129 //=======================================================================
130 void AIS_Trihedron::UnsetSize()
131 {
132   if (!myHasOwnSize)
133   {
134     return;
135   }
136
137   myHasOwnSize = Standard_False;
138   if (hasOwnColor)
139   {
140     const Handle(Prs3d_DatumAspect) DA = myDrawer->HasLink()
141                                        ? myDrawer->Link()->DatumAspect()
142                                        : new Prs3d_DatumAspect();
143     myDrawer->DatumAspect()->SetAxisLength (DA->AxisLength (Prs3d_DatumParts_XAxis),
144                                             DA->AxisLength (Prs3d_DatumParts_YAxis),
145                                             DA->AxisLength (Prs3d_DatumParts_ZAxis));
146   }
147   else
148   {
149     SetToUpdate();
150   }
151   UpdateSelection();
152 }
153
154 //=======================================================================
155 //function : Size
156 //purpose  :
157 //=======================================================================
158 Standard_Real AIS_Trihedron::Size() const 
159 {
160   return myDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
161 }
162
163 //=======================================================================
164 //function : Compute
165 //purpose  :
166 //=======================================================================
167 void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
168                              const Handle(Prs3d_Presentation)& thePrs,
169                              const Standard_Integer theMode)
170 {
171   if (theMode != 0)
172   {
173     return;
174   }
175
176   thePrs->SetInfiniteState (Standard_True);
177
178   gp_Ax2 anAxis (myComponent->Ax2());
179   updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
180                     anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
181   computePresentation (thePrsMgr, thePrs);
182 }
183
184 //=======================================================================
185 //function : ComputeSelection
186 //purpose  :
187 //=======================================================================
188 void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
189                                       const Standard_Integer theMode)
190 {
191   Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
192   switch (theMode)
193   {
194     case AIS_TrihedronSelectionMode_EntireObject:
195     {
196       Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this, mySelectionPriority[Prs3d_DatumParts_None]);
197       const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
198       for (int aPartIter = isShadingMode ? Prs3d_DatumParts_Origin : Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis;
199            ++aPartIter)
200       {
201         const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
202         if (!anAspect->DrawDatumPart (aPart))
203         {
204           continue;
205         }
206         theSelection->Add (createSensitiveEntity (aPart, anOwner));
207       }
208       break;
209     }
210     case AIS_TrihedronSelectionMode_Origin:
211     {
212       const Prs3d_DatumParts aPart = Prs3d_DatumParts_Origin;
213       if (anAspect->DrawDatumPart (aPart))
214       {
215         Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
216         Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives(aPart);
217         theSelection->Add (createSensitiveEntity (aPart, anOwner));
218       }
219       break;
220     }
221     case AIS_TrihedronSelectionMode_Axes:
222     {
223       for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
224       {
225         const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
226         if (!anAspect->DrawDatumPart (aPart))
227         {
228           continue;
229         }
230         Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
231         theSelection->Add (createSensitiveEntity (aPart, anOwner));
232       }
233       break;
234     }
235     case AIS_TrihedronSelectionMode_MainPlanes:
236     {
237       // create owner for each trihedron plane
238       {
239         for (int aPartIter = Prs3d_DatumParts_XOYAxis; aPartIter <= Prs3d_DatumParts_XOZAxis; ++aPartIter)
240         {
241           const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
242           if (!anAspect->DrawDatumPart (aPart))
243           {
244             continue;
245           }
246           Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
247           theSelection->Add (createSensitiveEntity (aPart, anOwner));
248         }
249       }
250       break;
251     }
252   }
253 }
254
255 //=======================================================================
256 //function : HilightOwnerWithColor
257 //purpose  :
258 //=======================================================================
259 void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
260                                            const Handle(Prs3d_Drawer)& theStyle,
261                                            const Handle(SelectMgr_EntityOwner)& theOwner)
262 {
263   Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
264   if (anOwner.IsNull())
265   {
266     // default 0 selection mode
267     Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
268     thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
269     return;
270   }
271
272   Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
273   if (aPresentation.IsNull())
274   {
275     return;
276   }
277
278   aPresentation->Clear();
279   const Prs3d_DatumParts aPart = anOwner->DatumPart();
280   Handle(Graphic3d_Group) aGroup = aPresentation->CurrentGroup();
281   if (aPart >= Prs3d_DatumParts_XOYAxis && aPart <= Prs3d_DatumParts_XOZAxis)
282   {
283     // planes selection is equal in both shading and wireframe mode
284     aGroup->SetGroupPrimitivesAspect (theStyle->LineAspect()->Aspect());
285   }
286   else
287   {
288     if (myTrihDispMode == Prs3d_DM_Shaded)
289     {
290       aGroup->SetGroupPrimitivesAspect (theStyle->ShadingAspect()->Aspect());
291     }
292     else
293     {
294       if (aPart == Prs3d_DatumParts_Origin)
295       {
296         aGroup->SetGroupPrimitivesAspect (theStyle->PointAspect()->Aspect());
297       }
298       else
299       {
300         aGroup->SetGroupPrimitivesAspect(theStyle->LineAspect()->Aspect());
301       }
302     }
303   }
304   aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
305
306   const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer();
307   if (aPresentation->GetZLayer() != aLayer)
308   {
309     aPresentation->SetZLayer (aLayer);
310   }
311
312   aPresentation->Highlight (theStyle);
313   thePM->AddToImmediateList (aPresentation);
314 }
315
316 //========================================================================
317 //function : HilightSelected
318 //purpose  :
319 //========================================================================
320 void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager)& thePM,
321                                      const SelectMgr_SequenceOfOwner& theOwners)
322 {
323   if (theOwners.IsEmpty() || !HasInteractiveContext())
324   {
325     return;
326   }
327
328   const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
329
330   Handle(Prs3d_Drawer) anAspect = !myHilightDrawer.IsNull() ? myHilightDrawer : GetContext()->SelectionStyle();
331   for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
332   {
333     const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
334     Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
335     if (aTrihedronOwner.IsNull())
336     {
337       thePM->Color (this, anAspect, 0);
338       continue;
339     }
340       
341     const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
342     if (myPartToGroup[aPart].IsNull()
343      || mySelectedParts.Contains (aPart))
344     {
345       continue;
346     }
347
348     const Handle(Graphic3d_Group)& aGroup = myPartToGroup[aPart];
349     if (aPart >= Prs3d_DatumParts_XOYAxis
350      && aPart <= Prs3d_DatumParts_XOZAxis)
351     {
352       aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
353     }
354     else
355     {
356       if (isShadingMode)
357       {
358         aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect()->Aspect());
359       }
360       else
361       {
362         if (aPart == Prs3d_DatumParts_Origin)
363         {
364           aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
365         }
366         else
367         {
368           aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
369         }
370       }
371     }
372     mySelectedParts.Append (aPart);
373   }
374 }
375
376 //=======================================================================
377 //function : ClearSelected
378 //purpose  :
379 //=======================================================================
380 void AIS_Trihedron::ClearSelected()
381 {
382   Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
383   const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
384   for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (mySelectedParts); anIterator.More();
385        anIterator.Next())
386   {
387     const Prs3d_DatumParts aPart = anIterator.Value();
388     const Handle(Graphic3d_Group)& aGroup = myPartToGroup[aPart];
389     if (aPart >= Prs3d_DatumParts_XOYAxis
390      && aPart <= Prs3d_DatumParts_XOZAxis)
391     {
392       aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
393     }
394     else if (isShadingMode)
395     {
396       aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
397     }
398     else
399     {
400       if (aPart == Prs3d_DatumParts_Origin)
401       {
402         aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
403       }
404       else
405       {
406         aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
407       }
408     }
409   }
410   mySelectedParts.Clear();
411 }
412
413 //=======================================================================
414 //function : computePresentation
415 //purpose  :
416 //=======================================================================
417 void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager)& /*thePrsMgr*/,
418                                          const Handle(Prs3d_Presentation)& thePrs)
419 {
420   for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_NB; ++aPartIter)
421   {
422     myPartToGroup[aPartIter].Nullify();
423   }
424
425   Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
426   const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
427   // display origin
428   {
429     // Origin is visualized only in shading mode
430     Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
431     const Prs3d_DatumParts aPart = Prs3d_DatumParts_Origin;
432     if (anAspect->DrawDatumPart(aPart))
433     {
434       myPartToGroup[aPart] = aGroup;
435       if (isShadingMode)
436       {
437         aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
438       }
439       else
440       {
441         aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
442       }
443       aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
444     }
445   }
446
447   // display axes
448   {
449     for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
450     {
451       Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
452       if (!anAspect->DrawDatumPart (aPart))
453       {
454         continue;
455       }
456
457       Handle(Graphic3d_Group) anAxisGroup = thePrs->NewGroup();
458       myPartToGroup[aPart] = anAxisGroup;
459       if (isShadingMode)
460       {
461         anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
462       }
463       else
464       {
465         anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
466       }
467       anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
468
469       // draw arrow
470       const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
471       if (!anAspect->DrawDatumPart (anArrowPart))
472       {
473         continue;
474       }
475
476       Handle(Graphic3d_Group) anArrowGroup = thePrs->NewGroup();
477       if (isShadingMode)
478       {
479         anArrowGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (anArrowPart)->Aspect());
480       }
481       else
482       {
483         anArrowGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (anArrowPart)->Aspect());
484       }
485       anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
486     }
487   }
488
489   // display labels
490   if (anAspect->ToDrawLabels())
491   {
492     Handle(Geom_Axis2Placement) aComponent = myComponent;
493     const gp_Pnt anOrigin = aComponent->Location();
494     for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
495     {
496       const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
497       if (!anAspect->DrawDatumPart (aPart))
498       {
499         continue;
500       }
501
502       const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
503       const TCollection_ExtendedString& aLabel = myLabels[aPart];
504       gp_Dir aDir;
505       switch (aPart)
506       {
507         case Prs3d_DatumParts_XAxis: aDir = aComponent->XDirection(); break;
508         case Prs3d_DatumParts_YAxis: aDir = aComponent->YDirection(); break;
509         case Prs3d_DatumParts_ZAxis: aDir = aComponent->Direction();  break;
510         default: break;
511       }
512       Handle(Graphic3d_Group) aLabelGroup = thePrs->NewGroup();
513       const gp_Pnt aPoint = anOrigin.XYZ() + aDir.XYZ() * anAxisLength;
514       Prs3d_Text::Draw (aLabelGroup, anAspect->TextAspect (aPart), aLabel, aPoint);
515     }
516   }
517
518   // planes invisible group for planes selection
519   for (Standard_Integer anAxisIter = Prs3d_DatumParts_XOYAxis; anAxisIter <= Prs3d_DatumParts_XOZAxis; ++anAxisIter)
520   {
521     Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
522     if (!anAspect->DrawDatumPart(aPart))
523     {
524       continue;
525     }
526
527     Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
528     myPartToGroup[aPart] = aGroup;
529
530     aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
531     aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
532   }
533 }
534
535 //=======================================================================
536 //function : SetColor
537 //purpose  :
538 //=======================================================================
539 void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
540                                        const Quantity_Color&  theColor)
541 {
542   setOwnDatumAspect();
543
544   myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
545   if (thePart != Prs3d_DatumParts_Origin)
546   {
547     myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
548   }
549 }
550
551 //=======================================================================
552 //function : SetTextColor
553 //purpose  :
554 //=======================================================================
555 void AIS_Trihedron::SetTextColor (const Prs3d_DatumParts thePart,
556                                   const Quantity_Color& theColor)
557 {
558   setOwnDatumAspect();
559   myDrawer->DatumAspect()->TextAspect (thePart)->SetColor (theColor);
560 }
561
562 //=======================================================================
563 //function : SetTextColor
564 //purpose  :
565 //=======================================================================
566 void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
567 {
568   setOwnDatumAspect();
569   myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_XAxis)->SetColor (theColor);
570   myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_YAxis)->SetColor (theColor);
571   myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_ZAxis)->SetColor (theColor);
572 }
573
574 //=======================================================================
575 //function : Color
576 //purpose  :
577 //=======================================================================
578 Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
579 {
580   if (myTrihDispMode == Prs3d_DM_Shaded)
581   {
582     return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
583   }
584   else
585   {
586     return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
587   }
588 }
589
590 //=======================================================================
591 //function : SetOriginColor
592 //purpose  :
593 //=======================================================================
594 void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
595 {
596   if (myTrihDispMode == Prs3d_DM_Shaded)
597   {
598     SetDatumPartColor (Prs3d_DatumParts_Origin, theColor);
599   }
600 }
601
602 //=======================================================================
603 //function : SetXAxisColor
604 //purpose  :
605 //=======================================================================
606 void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
607 {
608   SetDatumPartColor (Prs3d_DatumParts_XAxis, theColor);
609 }
610
611 //=======================================================================
612 //function : SetYAxisColor
613 //purpose  :
614 //=======================================================================
615 void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
616 {
617   SetDatumPartColor (Prs3d_DatumParts_YAxis, theColor);
618 }
619
620 //=======================================================================
621 //function : SetAxisColor
622 //purpose  :
623 //=======================================================================
624 void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
625 {
626   SetDatumPartColor (Prs3d_DatumParts_ZAxis, theColor);
627 }
628
629 //=======================================================================
630 //function : SetColor
631 //purpose  :
632 //=======================================================================
633 void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
634 {
635   hasOwnColor = Standard_True;
636   myDrawer->SetColor (theColor);
637
638   SetDatumPartColor (Prs3d_DatumParts_Origin, theColor);
639   SetDatumPartColor (Prs3d_DatumParts_XAxis,  theColor);
640   SetDatumPartColor (Prs3d_DatumParts_YAxis,  theColor);
641   SetDatumPartColor (Prs3d_DatumParts_ZAxis,  theColor);
642 }
643
644 //=======================================================================
645 //function : SetArrowColor
646 //purpose  :
647 //=======================================================================
648 void AIS_Trihedron::SetArrowColor (const Prs3d_DatumParts thePart,
649                                    const Quantity_Color& theColor)
650 {
651   setOwnDatumAspect();
652   myHasOwnArrowColor = Standard_True;
653   const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (thePart);
654   myDrawer->DatumAspect()->ShadingAspect(anArrowPart)->SetColor (theColor);
655   myDrawer->DatumAspect()->LineAspect   (anArrowPart)->SetColor (theColor);
656 }
657
658 //=======================================================================
659 //function : SetArrowColor
660 //purpose  :
661 //=======================================================================
662 void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
663 {
664   setOwnDatumAspect();
665
666   myHasOwnArrowColor = Standard_True;
667   myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
668   for (Standard_Integer anAxisIter = Prs3d_DatumParts_XArrow; anAxisIter <= Prs3d_DatumParts_ZArrow; ++anAxisIter)
669   {
670     myDrawer->DatumAspect()->ShadingAspect((Prs3d_DatumParts )anAxisIter)->SetColor (theColor);
671     myDrawer->DatumAspect()->LineAspect   ((Prs3d_DatumParts )anAxisIter)->SetColor (theColor);
672   }
673 }
674
675 //=======================================================================
676 //function : TextColor
677 //purpose  :
678 //=======================================================================
679 Quantity_Color AIS_Trihedron::TextColor() const
680 {
681   return myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_XAxis)->Aspect()->Color();
682 }
683
684 //=======================================================================
685 //function : ArrowColor
686 //purpose  :
687 //=======================================================================
688 Quantity_Color AIS_Trihedron::ArrowColor() const
689 {
690   return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
691 }
692
693 //=======================================================================
694 //function : UnsetColor
695 //purpose  : 
696 //=======================================================================
697 void AIS_Trihedron::UnsetColor()
698 {
699   hasOwnColor = Standard_False;
700   Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
701   SetColor (aDefaultColor);
702   if (HasTextColor())
703   {
704     SetTextColor (aDefaultColor);
705     myHasOwnTextColor = Standard_False;
706   }
707   if (HasArrowColor())
708   {
709     SetArrowColor (aDefaultColor);
710     myHasOwnArrowColor = Standard_False;
711   }
712 }
713
714 //=======================================================================
715 //function : ToDrawArrows
716 //purpose  :
717 //=======================================================================
718 Standard_Boolean AIS_Trihedron::ToDrawArrows() const
719 {
720   return myDrawer->DatumAspect()->ToDrawArrows();
721 }
722
723 //=======================================================================
724 //function : SetDrawArrows
725 //purpose  :
726 //=======================================================================
727 void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
728 {
729   setOwnDatumAspect();
730   myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
731 }
732
733 //=======================================================================
734 //function : createSensitiveEntity
735 //purpose  :
736 //=======================================================================
737 Handle(Select3D_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
738                                                    const Handle(SelectMgr_EntityOwner)& theOwner) const
739 {
740   Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
741   Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
742   if (aPrimitives.IsNull())
743   {
744     return Handle(Select3D_SensitiveEntity)();
745   }
746
747   if (thePart >= Prs3d_DatumParts_XOYAxis
748    && thePart <= Prs3d_DatumParts_XOZAxis)
749   { // plane
750     const gp_Pnt anXYZ1 = aPrimitives->Vertice (1);
751     const gp_Pnt anXYZ2 = aPrimitives->Vertice (2);
752     const gp_Pnt anXYZ3 = aPrimitives->Vertice (3);
753     return new Select3D_SensitiveTriangle (theOwner, anXYZ1, anXYZ2, anXYZ3);
754   }
755
756   if (myTrihDispMode == Prs3d_DM_Shaded)
757   {
758     Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
759     aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
760     return aSelArray;
761   }
762
763   if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
764   {
765     const gp_Pnt anXYZ1 = aPoints->Vertice (1);
766     return new Select3D_SensitivePoint (theOwner, anXYZ1);
767   }
768   else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
769   {
770     const gp_Pnt anXYZ1 = aSegments->Vertice (1);
771     const gp_Pnt anXYZ2 = aSegments->Vertice (2);
772     return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
773   }
774   return Handle(Select3D_SensitiveEntity)();
775 }
776
777 // =======================================================================
778 // function : updatePrimitives
779 // purpose  :
780 // =======================================================================
781 void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
782                                      Prs3d_DatumMode theMode,
783                                      const gp_Pnt& theOrigin,
784                                      const gp_Dir& theXDirection,
785                                      const gp_Dir& theYDirection,
786                                      const gp_Dir& theZDirection)
787 {
788   for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_NB; ++aPartIter)
789   {
790     myPrimitives[aPartIter].Nullify();
791   }
792
793   NCollection_DataMap<Prs3d_DatumParts, gp_Dir> anAxisDirs;
794   anAxisDirs.Bind(Prs3d_DatumParts_XAxis, theXDirection);
795   anAxisDirs.Bind(Prs3d_DatumParts_YAxis, theYDirection);
796   anAxisDirs.Bind(Prs3d_DatumParts_ZAxis, theZDirection);
797
798   NCollection_DataMap<Prs3d_DatumParts, gp_Pnt> anAxisPoints;
799   gp_XYZ anXYZOrigin = theOrigin.XYZ();
800   for (int anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
801   {
802     Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
803     anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
804                                                    theAspect->AxisLength(aPart)));
805   }
806
807   if (theMode == Prs3d_DM_WireFrame)
808   {
809     // origin
810     if (theAspect->DrawDatumPart(Prs3d_DatumParts_Origin))
811     {
812       Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
813       aPrims->AddVertex(theOrigin);
814       myPrimitives[Prs3d_DatumParts_Origin] = aPrims;
815     }
816     // axes
817     for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
818     {
819       const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
820       if (theAspect->DrawDatumPart(aPart))
821       {
822         Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
823         aPrims->AddVertex(theOrigin);
824         aPrims->AddVertex(anAxisPoints.Find(aPart));
825         myPrimitives[aPart] = aPrims;
826       }
827
828       const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
829       if (theAspect->DrawDatumPart(anArrowPart))
830       {
831         myPrimitives[anArrowPart] = Prs3d_Arrow::DrawSegments (anAxisPoints.Find(aPart), anAxisDirs.Find(aPart),
832                                                                theAspect->ArrowAspect()->Angle(),
833                                                                theAspect->AxisLength(aPart) * theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeLengthPercent),
834                                                                (Standard_Integer) theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes));
835       }
836     }
837   }
838   else
839   {
840     // shading mode
841     // origin
842     if (theAspect->DrawDatumPart(Prs3d_DatumParts_Origin))
843     {
844       const Standard_Real aSphereRadius = theAspect->AxisLength(Prs3d_DatumParts_XAxis) *
845                                           theAspect->Attribute(Prs3d_DatumAttribute_ShadingOriginRadiusPercent);
846       const Standard_Integer aNbOfFacettes =
847                            (Standard_Integer)theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes);
848       gp_Trsf aSphereTransform;
849       aSphereTransform.SetTranslationPart(gp_Vec(gp::Origin(), theOrigin));
850       myPrimitives[Prs3d_DatumParts_Origin] = Prs3d_ToolSphere::Create (aSphereRadius, aNbOfFacettes, aNbOfFacettes, aSphereTransform);
851     }
852     // axes
853     {
854       const Standard_Integer aNbOfFacettes = 
855                                (Standard_Integer)theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes);
856       const Standard_Real aTubeRadiusPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingTubeRadiusPercent);
857       const Standard_Real aConeLengthPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeLengthPercent);
858       const Standard_Real aConeRadiusPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeRadiusPercent);
859       for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
860       {
861         const Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
862         const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
863         const bool aDrawArrow = theAspect->DrawDatumPart(anArrowPart);
864         const Standard_Real anAxisLength = theAspect->AxisLength(aPart);
865         const gp_Ax1 anAxis(theOrigin, anAxisDirs.Find(aPart));
866
867         if (theAspect->DrawDatumPart(aPart))
868         {
869           // draw cylinder
870           myPrimitives[aPart] = Prs3d_Arrow::DrawShaded (anAxis, anAxisLength * aTubeRadiusPercent,
871                                                          aDrawArrow ? (anAxisLength - anAxisLength * aConeLengthPercent) : anAxisLength,
872                                                          0.0, 0.0, aNbOfFacettes);
873         }
874
875         // draw arrow
876         if (aDrawArrow)
877         {
878           myPrimitives[anArrowPart] = Prs3d_Arrow::DrawShaded (anAxis, 0.0, anAxisLength,
879                                                                anAxisLength * aConeRadiusPercent,
880                                                                anAxisLength * aConeLengthPercent, aNbOfFacettes);
881         }
882       }
883     }
884   }
885   // planes
886   for (Standard_Integer aPlaneIter = Prs3d_DatumParts_XOYAxis; aPlaneIter <= Prs3d_DatumParts_XOZAxis; ++aPlaneIter)
887   {
888     const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
889     if (!theAspect->DrawDatumPart(aPart))
890     {
891       continue;
892     }
893
894     Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
895     aPrims->AddVertex(theOrigin);
896
897     Prs3d_DatumParts aPart1 = Prs3d_DatumParts_XAxis, aPart2 = Prs3d_DatumParts_XAxis;
898     switch(aPart)
899     {
900       case Prs3d_DatumParts_XOYAxis:
901       {
902         aPart1 = Prs3d_DatumParts_XAxis;
903         aPart2 = Prs3d_DatumParts_YAxis;
904         break;
905       }
906       case Prs3d_DatumParts_YOZAxis:
907       {
908         aPart1 = Prs3d_DatumParts_YAxis;
909         aPart2 = Prs3d_DatumParts_ZAxis;
910         break;
911       }
912       case Prs3d_DatumParts_XOZAxis:
913       {
914         aPart1 = Prs3d_DatumParts_XAxis;
915         aPart2 = Prs3d_DatumParts_ZAxis;
916         break;
917       }
918       default: break;
919     }
920     aPrims->AddVertex(anAxisPoints.Find(aPart1));
921     aPrims->AddVertex(anAxisPoints.Find(aPart2));
922
923     aPrims->AddVertex(theOrigin);
924     myPrimitives[aPart] = aPrims;
925   }
926 }
927
928 //=======================================================================
929 //function : DumpJson
930 //purpose  : 
931 //=======================================================================
932 void AIS_Trihedron::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
933 {
934   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
935
936   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
937
938   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnSize)
939   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnTextColor)
940   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnArrowColor)
941   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTrihDispMode)
942 }