File indexing completed on 2026-10-24 09:13:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _AIS_ViewCube_HeaderFile
0017 #define _AIS_ViewCube_HeaderFile
0018
0019 #include <AIS_InteractiveObject.hxx>
0020 #include <Graphic3d_Camera.hxx>
0021 #include <NCollection_Vec2.hxx>
0022 #include <Standard_TypeDef.hxx>
0023 #include <Prs3d_DatumParts.hxx>
0024 #include <Prs3d_ShadingAspect.hxx>
0025 #include <Prs3d_TextAspect.hxx>
0026 #include <SelectMgr_EntityOwner.hxx>
0027 #include <V3d_TypeOfOrientation.hxx>
0028 #include <Select3D_SensitivePrimitiveArray.hxx>
0029
0030 class AIS_AnimationCamera;
0031 class AIS_ViewCubeOwner;
0032 class Graphic3d_ArrayOfTriangles;
0033 class V3d_View;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 class AIS_ViewCube : public AIS_InteractiveObject
0062 {
0063 DEFINE_STANDARD_RTTIEXT(AIS_ViewCube, AIS_InteractiveObject)
0064 public:
0065
0066 Standard_EXPORT static bool IsBoxSide(V3d_TypeOfOrientation theOrient);
0067
0068
0069 Standard_EXPORT static bool IsBoxEdge(V3d_TypeOfOrientation theOrient);
0070
0071
0072 Standard_EXPORT static bool IsBoxCorner(V3d_TypeOfOrientation theOrient);
0073
0074 public:
0075
0076 Standard_EXPORT AIS_ViewCube();
0077
0078
0079 const occ::handle<AIS_AnimationCamera>& ViewAnimation() const { return myViewAnimation; }
0080
0081
0082 void SetViewAnimation(const occ::handle<AIS_AnimationCamera>& theAnimation)
0083 {
0084 myViewAnimation = theAnimation;
0085 }
0086
0087
0088
0089 bool ToAutoStartAnimation() const { return myToAutoStartAnim; }
0090
0091
0092
0093
0094 void SetAutoStartAnimation(bool theToEnable) { myToAutoStartAnim = theToEnable; }
0095
0096
0097 bool IsFixedAnimationLoop() const { return myIsFixedAnimation; }
0098
0099
0100 void SetFixedAnimationLoop(bool theToEnable) { myIsFixedAnimation = theToEnable; }
0101
0102
0103
0104 Standard_EXPORT void ResetStyles();
0105
0106 protected:
0107
0108 Standard_EXPORT void setDefaultAttributes();
0109
0110
0111 Standard_EXPORT void setDefaultHighlightAttributes();
0112
0113 public:
0114
0115 double Size() const { return mySize; }
0116
0117
0118
0119 Standard_EXPORT void SetSize(double theValue, bool theToAdaptAnother = true);
0120
0121
0122 double BoxFacetExtension() const { return myBoxFacetExtension; }
0123
0124
0125 void SetBoxFacetExtension(double theValue)
0126 {
0127 if (std::abs(myBoxFacetExtension - theValue) > Precision::Confusion())
0128 {
0129 myBoxFacetExtension = theValue;
0130 SetToUpdate();
0131 }
0132 }
0133
0134
0135 double AxesPadding() const { return myAxesPadding; }
0136
0137
0138 void SetAxesPadding(double theValue)
0139 {
0140 if (std::abs(myAxesPadding - theValue) > Precision::Confusion())
0141 {
0142 myAxesPadding = theValue;
0143 SetToUpdate();
0144 }
0145 }
0146
0147
0148 double BoxEdgeGap() const { return myBoxEdgeGap; }
0149
0150
0151 void SetBoxEdgeGap(double theValue)
0152 {
0153 if (std::abs(myBoxEdgeGap - theValue) > Precision::Confusion())
0154 {
0155 myBoxEdgeGap = theValue;
0156 SetToUpdate();
0157 }
0158 }
0159
0160
0161 double BoxEdgeMinSize() const { return myBoxEdgeMinSize; }
0162
0163
0164 void SetBoxEdgeMinSize(double theValue)
0165 {
0166 if (std::abs(myBoxEdgeMinSize - theValue) > Precision::Confusion())
0167 {
0168 myBoxEdgeMinSize = theValue;
0169 SetToUpdate();
0170 }
0171 }
0172
0173
0174 double BoxCornerMinSize() const { return myCornerMinSize; }
0175
0176
0177 void SetBoxCornerMinSize(double theValue)
0178 {
0179 if (std::abs(myCornerMinSize - theValue) > Precision::Confusion())
0180 {
0181 myCornerMinSize = theValue;
0182 SetToUpdate();
0183 }
0184 }
0185
0186
0187
0188 double RoundRadius() const { return myRoundRadius; }
0189
0190
0191
0192 Standard_EXPORT void SetRoundRadius(const double theValue);
0193
0194
0195 double AxesRadius() const { return myAxesRadius; }
0196
0197
0198 void SetAxesRadius(const double theRadius)
0199 {
0200 if (std::abs(myAxesRadius - theRadius) > Precision::Confusion())
0201 {
0202 myAxesRadius = theRadius;
0203 SetToUpdate();
0204 }
0205 }
0206
0207
0208 double AxesConeRadius() const { return myAxesConeRadius; }
0209
0210
0211 void SetAxesConeRadius(double theRadius)
0212 {
0213 if (std::abs(myAxesConeRadius - theRadius) > Precision::Confusion())
0214 {
0215 myAxesConeRadius = theRadius;
0216 SetToUpdate();
0217 }
0218 }
0219
0220
0221 double AxesSphereRadius() const { return myAxesSphereRadius; }
0222
0223
0224 void SetAxesSphereRadius(double theRadius)
0225 {
0226 if (std::abs(myAxesSphereRadius - theRadius) > Precision::Confusion())
0227 {
0228 myAxesSphereRadius = theRadius;
0229 SetToUpdate();
0230 }
0231 }
0232
0233
0234 bool ToDrawAxes() const { return myToDisplayAxes; }
0235
0236
0237 void SetDrawAxes(bool theValue)
0238 {
0239 if (myToDisplayAxes != theValue)
0240 {
0241 myToDisplayAxes = theValue;
0242 SetToUpdate();
0243 }
0244 }
0245
0246
0247 bool ToDrawEdges() const { return myToDisplayEdges; }
0248
0249
0250 void SetDrawEdges(bool theValue)
0251 {
0252 if (myToDisplayEdges != theValue)
0253 {
0254 myToDisplayEdges = theValue;
0255 SetToUpdate();
0256 }
0257 }
0258
0259
0260 bool ToDrawVertices() const { return myToDisplayVertices; }
0261
0262
0263 void SetDrawVertices(bool theValue)
0264 {
0265 if (myToDisplayVertices != theValue)
0266 {
0267 myToDisplayVertices = theValue;
0268 SetToUpdate();
0269 }
0270 }
0271
0272
0273 bool IsYup() const { return myIsYup; }
0274
0275
0276 Standard_EXPORT void SetYup(bool theIsYup, bool theToUpdateLabels = true);
0277
0278 public:
0279
0280 const occ::handle<Prs3d_ShadingAspect>& BoxSideStyle() const { return myDrawer->ShadingAspect(); }
0281
0282
0283 const occ::handle<Prs3d_ShadingAspect>& BoxEdgeStyle() const { return myBoxEdgeAspect; }
0284
0285
0286 const occ::handle<Prs3d_ShadingAspect>& BoxCornerStyle() const { return myBoxCornerAspect; }
0287
0288
0289 const Quantity_Color& BoxColor() const { return myDrawer->ShadingAspect()->Color(); }
0290
0291
0292
0293 void SetBoxColor(const Quantity_Color& theColor)
0294 {
0295 if (!myDrawer->ShadingAspect()->Color().IsEqual(theColor)
0296 || !myBoxEdgeAspect->Color().IsEqual(theColor)
0297 || !myBoxCornerAspect->Color().IsEqual(theColor))
0298 {
0299 myDrawer->ShadingAspect()->SetColor(theColor);
0300 myBoxEdgeAspect->SetColor(theColor);
0301 myBoxCornerAspect->SetColor(theColor);
0302 SynchronizeAspects();
0303 }
0304 }
0305
0306
0307 double BoxTransparency() const { return myDrawer->ShadingAspect()->Transparency(); }
0308
0309
0310
0311 void SetBoxTransparency(double theValue)
0312 {
0313 if (std::abs(myDrawer->ShadingAspect()->Transparency() - theValue) > Precision::Confusion()
0314 || std::abs(myBoxEdgeAspect->Transparency() - theValue) > Precision::Confusion()
0315 || std::abs(myBoxCornerAspect->Transparency() - theValue) > Precision::Confusion())
0316 {
0317 myDrawer->ShadingAspect()->SetTransparency(theValue);
0318 myBoxEdgeAspect->SetTransparency(theValue);
0319 myBoxCornerAspect->SetTransparency(theValue);
0320 SynchronizeAspects();
0321 }
0322 }
0323
0324
0325 const Quantity_Color& InnerColor() const
0326 {
0327 return myDrawer->ShadingAspect()->Color(Aspect_TOFM_BACK_SIDE);
0328 }
0329
0330
0331
0332 void SetInnerColor(const Quantity_Color& theColor)
0333 {
0334 myDrawer->ShadingAspect()->SetColor(theColor, Aspect_TOFM_BACK_SIDE);
0335 SynchronizeAspects();
0336 }
0337
0338
0339
0340 TCollection_AsciiString BoxSideLabel(V3d_TypeOfOrientation theSide) const
0341 {
0342 const TCollection_AsciiString* aLabel = myBoxSideLabels.Seek(theSide);
0343 return aLabel != nullptr ? *aLabel : TCollection_AsciiString();
0344 }
0345
0346
0347 void SetBoxSideLabel(const V3d_TypeOfOrientation theSide, const TCollection_AsciiString& theLabel)
0348 {
0349 if (!IsBoxSide(theSide))
0350 {
0351 throw Standard_ProgramError("AIS_ViewCube::SetBoxSideLabel(), invalid enumeration value");
0352 }
0353 myBoxSideLabels.Bind(theSide, theLabel);
0354 SetToUpdate();
0355 }
0356
0357
0358 const Quantity_Color& TextColor() const { return myDrawer->TextAspect()->Aspect()->Color(); }
0359
0360
0361
0362 void SetTextColor(const Quantity_Color& theColor)
0363 {
0364 myDrawer->TextAspect()->SetColor(theColor);
0365 SynchronizeAspects();
0366 }
0367
0368
0369
0370 const TCollection_AsciiString& Font() const { return myDrawer->TextAspect()->Aspect()->Font(); }
0371
0372
0373
0374 void SetFont(const TCollection_AsciiString& theFont)
0375 {
0376 myDrawer->TextAspect()->Aspect()->SetFont(theFont);
0377 SynchronizeAspects();
0378 }
0379
0380
0381 double FontHeight() const { return myDrawer->TextAspect()->Height(); }
0382
0383
0384
0385 void SetFontHeight(double theValue)
0386 {
0387 if (std::abs(myDrawer->TextAspect()->Height() - theValue) > Precision::Confusion())
0388 {
0389 myDrawer->TextAspect()->SetHeight(theValue);
0390 SetToUpdate();
0391 }
0392 }
0393
0394
0395
0396 TCollection_AsciiString AxisLabel(Prs3d_DatumParts theAxis) const
0397 {
0398 const TCollection_AsciiString* aLabel = myAxesLabels.Seek(theAxis);
0399 return aLabel != nullptr ? *aLabel : TCollection_AsciiString();
0400 }
0401
0402
0403 void SetAxesLabels(const TCollection_AsciiString& theX,
0404 const TCollection_AsciiString& theY,
0405 const TCollection_AsciiString& theZ)
0406 {
0407 myAxesLabels.Bind(Prs3d_DatumParts_XAxis, theX);
0408 myAxesLabels.Bind(Prs3d_DatumParts_YAxis, theY);
0409 myAxesLabels.Bind(Prs3d_DatumParts_ZAxis, theZ);
0410 SetToUpdate();
0411 }
0412
0413 public:
0414
0415
0416 void SetColor(const Quantity_Color& theColor) override { SetBoxColor(theColor); }
0417
0418
0419 void UnsetColor() override
0420 {
0421 myDrawer->ShadingAspect()->SetColor(Quantity_NOC_WHITE);
0422 myBoxEdgeAspect->SetColor(Quantity_NOC_GRAY30);
0423 myBoxCornerAspect->SetColor(Quantity_NOC_GRAY30);
0424 SynchronizeAspects();
0425 }
0426
0427
0428
0429 void SetTransparency(const double theValue) override { SetBoxTransparency(theValue); }
0430
0431
0432 void UnsetTransparency() override { SetBoxTransparency(0.0f); }
0433
0434
0435 void SetMaterial(const Graphic3d_MaterialAspect& theMat) override
0436 {
0437 myDrawer->ShadingAspect()->SetMaterial(theMat);
0438 myBoxEdgeAspect->SetMaterial(theMat);
0439 myBoxCornerAspect->SetMaterial(theMat);
0440 SynchronizeAspects();
0441 }
0442
0443
0444 void UnsetMaterial() override
0445 {
0446 Graphic3d_MaterialAspect aMat(Graphic3d_NameOfMaterial_UserDefined);
0447 aMat.SetColor(Quantity_NOC_WHITE);
0448 aMat.SetAmbientColor(Quantity_NOC_GRAY60);
0449 myDrawer->ShadingAspect()->SetMaterial(aMat);
0450 myBoxEdgeAspect->SetMaterial(aMat);
0451 myBoxEdgeAspect->SetColor(Quantity_NOC_GRAY30);
0452 myBoxCornerAspect->SetMaterial(aMat);
0453 myBoxCornerAspect->SetColor(Quantity_NOC_GRAY30);
0454 SynchronizeAspects();
0455 }
0456
0457 public:
0458
0459 Standard_EXPORT double Duration() const;
0460
0461
0462
0463 Standard_EXPORT void SetDuration(double theValue);
0464
0465
0466
0467
0468 bool ToResetCameraUp() const { return myToResetCameraUp; }
0469
0470
0471
0472 void SetResetCamera(bool theToReset) { myToResetCameraUp = theToReset; }
0473
0474
0475
0476 bool ToFitSelected() const { return myToFitSelected; }
0477
0478
0479 void SetFitSelected(bool theToFitSelected) { myToFitSelected = theToFitSelected; }
0480
0481
0482 Standard_EXPORT bool HasAnimation() const;
0483
0484
0485
0486 Standard_EXPORT virtual void StartAnimation(const occ::handle<AIS_ViewCubeOwner>& theOwner);
0487
0488
0489
0490
0491 Standard_EXPORT virtual bool UpdateAnimation(const bool theToUpdate);
0492
0493
0494 Standard_EXPORT virtual void HandleClick(const occ::handle<AIS_ViewCubeOwner>& theOwner);
0495
0496 protected:
0497
0498
0499 Standard_EXPORT bool updateAnimation();
0500
0501
0502
0503
0504 Standard_EXPORT virtual void viewFitAll(const occ::handle<V3d_View>& theView,
0505 const occ::handle<Graphic3d_Camera>& theCamera);
0506
0507 protected:
0508
0509 virtual void onAfterAnimation() {}
0510
0511
0512 virtual void onAnimationFinished() {}
0513
0514 public:
0515
0516 bool AcceptDisplayMode(const int theMode) const override { return theMode == 0; }
0517
0518
0519 occ::handle<SelectMgr_EntityOwner> GlobalSelOwner() const override
0520 {
0521 return occ::handle<SelectMgr_EntityOwner>();
0522 }
0523
0524
0525
0526
0527
0528
0529 Standard_EXPORT void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0530 const occ::handle<Prs3d_Presentation>& thePrs,
0531 const int theMode = 0) override;
0532
0533
0534
0535
0536
0537 Standard_EXPORT void ComputeSelection(const occ::handle<SelectMgr_Selection>& theSelection,
0538 const int theMode) override;
0539
0540
0541
0542 bool IsAutoHilight() const override { return false; }
0543
0544
0545
0546 void ClearSelected() override {}
0547
0548
0549
0550
0551
0552 Standard_EXPORT void HilightOwnerWithColor(
0553 const occ::handle<PrsMgr_PresentationManager>& thePM,
0554 const occ::handle<Prs3d_Drawer>& theStyle,
0555 const occ::handle<SelectMgr_EntityOwner>& theOwner) override;
0556
0557
0558 Standard_EXPORT void HilightSelected(
0559 const occ::handle<PrsMgr_PresentationManager>& thePM,
0560 const NCollection_Sequence<occ::handle<SelectMgr_EntityOwner>>& theSeq) override;
0561
0562
0563
0564 void UnsetAttributes() override
0565 {
0566 setDefaultAttributes();
0567 SetToUpdate();
0568 }
0569
0570
0571 void UnsetHilightAttributes() override
0572 {
0573 myHilightDrawer.Nullify();
0574 setDefaultHighlightAttributes();
0575 SetToUpdate();
0576 }
0577
0578 protected:
0579
0580
0581
0582
0583
0584
0585
0586 Standard_EXPORT virtual void createBoxPartTriangles(
0587 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris,
0588 int& theNbNodes,
0589 int& theNbTris,
0590 V3d_TypeOfOrientation theDir) const;
0591
0592
0593
0594
0595
0596
0597
0598
0599 Standard_EXPORT virtual void createBoxSideTriangles(
0600 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris,
0601 int& theNbNodes,
0602 int& theNbTris,
0603 V3d_TypeOfOrientation theDir) const;
0604
0605
0606
0607
0608
0609
0610
0611
0612 Standard_EXPORT virtual void createBoxEdgeTriangles(
0613 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris,
0614 int& theNbNodes,
0615 int& theNbTris,
0616 V3d_TypeOfOrientation theDir) const;
0617
0618
0619
0620
0621
0622
0623
0624
0625 Standard_EXPORT virtual void createBoxCornerTriangles(
0626 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris,
0627 int& theNbNodes,
0628 int& theNbTris,
0629 V3d_TypeOfOrientation theDir) const;
0630
0631 protected:
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641 Standard_EXPORT static void createRoundRectangleTriangles(
0642 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris,
0643 int& theNbNodes,
0644 int& theNbTris,
0645 const gp_XY& theSize,
0646 double theRadius,
0647 const gp_Trsf& theTrsf);
0648
0649 protected:
0650 NCollection_DataMap<V3d_TypeOfOrientation, TCollection_AsciiString>
0651 myBoxSideLabels;
0652 NCollection_DataMap<Prs3d_DatumParts, TCollection_AsciiString>
0653 myAxesLabels;
0654 occ::handle<Prs3d_ShadingAspect> myBoxEdgeAspect;
0655 occ::handle<Prs3d_ShadingAspect> myBoxCornerAspect;
0656
0657 double mySize;
0658 double myBoxEdgeMinSize;
0659 double myBoxEdgeGap;
0660 double myBoxFacetExtension;
0661 double myAxesPadding;
0662
0663 double myAxesRadius;
0664 double myAxesConeRadius;
0665 double myAxesSphereRadius;
0666 double myCornerMinSize;
0667 double myRoundRadius;
0668 bool myToDisplayAxes;
0669 bool myToDisplayEdges;
0670 bool myToDisplayVertices;
0671 bool myIsYup;
0672
0673
0674 protected:
0675 occ::handle<AIS_AnimationCamera> myViewAnimation;
0676 occ::handle<Graphic3d_Camera> myStartState;
0677 occ::handle<Graphic3d_Camera> myEndState;
0678 bool myToAutoStartAnim;
0679 bool myIsFixedAnimation;
0680 bool myToFitSelected;
0681
0682 bool myToResetCameraUp;
0683
0684 };
0685
0686
0687
0688 class AIS_ViewCubeOwner : public SelectMgr_EntityOwner
0689 {
0690 DEFINE_STANDARD_RTTIEXT(AIS_ViewCubeOwner, SelectMgr_EntityOwner)
0691 public:
0692
0693 AIS_ViewCubeOwner(const occ::handle<AIS_ViewCube>& theObject,
0694 V3d_TypeOfOrientation theOrient,
0695 int thePriority = 5)
0696 : SelectMgr_EntityOwner((const occ::handle<SelectMgr_SelectableObject>&)theObject,
0697 thePriority),
0698 myMainOrient(theOrient)
0699 {
0700 myFromDecomposition = true;
0701 }
0702
0703
0704
0705 bool IsForcedHilight() const override { return true; }
0706
0707
0708 V3d_TypeOfOrientation MainOrientation() const { return myMainOrient; }
0709
0710
0711 bool HandleMouseClick(const NCollection_Vec2<int>& thePoint,
0712 Aspect_VKeyMouse theButton,
0713 Aspect_VKeyFlags theModifiers,
0714 bool theIsDoubleClick) override
0715 {
0716 (void)thePoint;
0717 (void)theButton;
0718 (void)theModifiers;
0719 (void)theIsDoubleClick;
0720 AIS_ViewCube* aCubePrs = dynamic_cast<AIS_ViewCube*>(mySelectable);
0721 aCubePrs->HandleClick(this);
0722 return true;
0723 }
0724
0725 protected:
0726 V3d_TypeOfOrientation myMainOrient;
0727 };
0728
0729
0730 class AIS_ViewCubeSensitive : public Select3D_SensitivePrimitiveArray
0731 {
0732 DEFINE_STANDARD_RTTIEXT(AIS_ViewCubeSensitive, Select3D_SensitivePrimitiveArray)
0733 public:
0734
0735 Standard_EXPORT AIS_ViewCubeSensitive(const occ::handle<SelectMgr_EntityOwner>& theOwner,
0736 const occ::handle<Graphic3d_ArrayOfTriangles>& theTris);
0737
0738
0739 Standard_EXPORT bool Matches(SelectBasics_SelectingVolumeManager& theMgr,
0740 SelectBasics_PickResult& thePickResult) override;
0741
0742 protected:
0743
0744 Standard_EXPORT bool isValidRay(const SelectBasics_SelectingVolumeManager& theMgr) const;
0745 };
0746
0747 #endif