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