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