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