File indexing completed on 2026-09-23 09:16:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _AIS_Manipulator_HeaderFile
0017 #define _AIS_Manipulator_HeaderFile
0018
0019 #include <AIS_InteractiveObject.hxx>
0020 #include <AIS_ManipulatorMode.hxx>
0021 #include <gp_Ax1.hxx>
0022 #include <gp_Dir.hxx>
0023 #include <gp_Pnt.hxx>
0024 #include <Graphic3d_ArrayOfTriangles.hxx>
0025 #include <Graphic3d_Group.hxx>
0026 #include <NCollection_HSequence.hxx>
0027 #include <Poly_Triangulation.hxx>
0028 #include <V3d_View.hxx>
0029 #include <Standard_DefineHandle.hxx>
0030
0031
0032
0033
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
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 class AIS_Manipulator : public AIS_InteractiveObject
0090 {
0091 public:
0092
0093 Standard_EXPORT AIS_Manipulator();
0094
0095
0096
0097 Standard_EXPORT AIS_Manipulator(const gp_Ax2& thePosition);
0098
0099
0100
0101
0102
0103
0104 Standard_EXPORT void SetPart(const int theAxisIndex,
0105 const AIS_ManipulatorMode theMode,
0106 const bool theIsEnabled);
0107
0108
0109
0110
0111
0112
0113 Standard_EXPORT void SetPart(const AIS_ManipulatorMode theMode, const bool theIsEnabled);
0114
0115
0116
0117
0118 struct OptionsForAttach
0119 {
0120
0121 OptionsForAttach()
0122 : AdjustPosition(true),
0123 AdjustSize(false),
0124 EnableModes(true)
0125 {
0126 }
0127
0128 OptionsForAttach& SetAdjustPosition(const bool theApply)
0129 {
0130 AdjustPosition = theApply;
0131 return *this;
0132 }
0133
0134 OptionsForAttach& SetAdjustSize(const bool theApply)
0135 {
0136 AdjustSize = theApply;
0137 return *this;
0138 }
0139
0140 OptionsForAttach& SetEnableModes(const bool theApply)
0141 {
0142 EnableModes = theApply;
0143 return *this;
0144 }
0145
0146 bool AdjustPosition;
0147 bool AdjustSize;
0148 bool EnableModes;
0149 };
0150
0151
0152
0153
0154 Standard_EXPORT void Attach(const occ::handle<AIS_InteractiveObject>& theObject,
0155 const OptionsForAttach& theOptions = OptionsForAttach());
0156
0157
0158
0159
0160
0161 Standard_EXPORT void Attach(
0162 const occ::handle<NCollection_HSequence<occ::handle<AIS_InteractiveObject>>>& theObject,
0163 const OptionsForAttach& theOptions = OptionsForAttach());
0164
0165
0166
0167
0168 Standard_EXPORT void EnableMode(const AIS_ManipulatorMode theMode);
0169
0170
0171
0172
0173 void SetModeActivationOnDetection(const bool theToEnable)
0174 {
0175 myIsActivationOnDetection = theToEnable;
0176 }
0177
0178
0179 bool IsModeActivationOnDetection() const { return myIsActivationOnDetection; }
0180
0181 public:
0182
0183
0184
0185
0186
0187
0188
0189
0190 Standard_EXPORT bool ProcessDragging(const occ::handle<AIS_InteractiveContext>& theCtx,
0191 const occ::handle<V3d_View>& theView,
0192 const occ::handle<SelectMgr_EntityOwner>& theOwner,
0193 const NCollection_Vec2<int>& theDragFrom,
0194 const NCollection_Vec2<int>& theDragTo,
0195 const AIS_DragAction theAction) override;
0196
0197
0198
0199
0200
0201
0202 Standard_EXPORT void StartTransform(const int theX,
0203 const int theY,
0204 const occ::handle<V3d_View>& theView);
0205
0206
0207
0208
0209
0210
0211
0212
0213 Standard_EXPORT void Transform(const gp_Trsf& aTrsf);
0214
0215
0216 Standard_EXPORT void RecomputeTransformation(
0217 const occ::handle<Graphic3d_Camera>& theCamera) override;
0218
0219
0220
0221 Standard_EXPORT void RecomputeSelection(const AIS_ManipulatorMode theMode);
0222
0223
0224
0225
0226
0227 Standard_EXPORT void StopTransform(const bool theToApply = true);
0228
0229
0230
0231
0232 Standard_EXPORT gp_Trsf Transform(const int theX,
0233 const int theY,
0234 const occ::handle<V3d_View>& theView);
0235
0236
0237
0238
0239
0240 Standard_EXPORT bool ObjectTransformation(const int theX,
0241 const int theY,
0242 const occ::handle<V3d_View>& theView,
0243 gp_Trsf& theTrsf);
0244
0245
0246
0247
0248 Standard_EXPORT void DeactivateCurrentMode();
0249
0250
0251 Standard_EXPORT void Detach();
0252
0253
0254 Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<AIS_InteractiveObject>>> Objects()
0255 const;
0256
0257
0258 Standard_EXPORT occ::handle<AIS_InteractiveObject> Object() const;
0259
0260
0261
0262 Standard_EXPORT occ::handle<AIS_InteractiveObject> Object(const int theIndex) const;
0263
0264
0265 bool IsAttached() const { return HasOwner(); }
0266
0267
0268
0269 bool HasActiveMode() const { return IsAttached() && myCurrentMode != AIS_MM_None; }
0270
0271 bool HasActiveTransformation() { return myHasStartedTransformation; }
0272
0273 gp_Trsf StartTransformation() const
0274 {
0275 return !myStartTrsfs.IsEmpty() ? myStartTrsfs.First() : gp_Trsf();
0276 }
0277
0278 gp_Trsf StartTransformation(int theIndex) const
0279 {
0280 Standard_ProgramError_Raise_if(
0281 theIndex < 1 || theIndex > Objects()->Upper(),
0282 "AIS_Manipulator::StartTransformation(): theIndex is out of bounds");
0283 return !myStartTrsfs.IsEmpty() ? myStartTrsfs(theIndex) : gp_Trsf();
0284 }
0285
0286 public:
0287
0288
0289
0290
0291
0292
0293 Standard_EXPORT void SetZoomPersistence(const bool theToEnable);
0294
0295
0296 bool ZoomPersistence() const { return myIsZoomPersistentMode; }
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307 Standard_EXPORT void SetTransformPersistence(
0308 const occ::handle<Graphic3d_TransformPers>& theTrsfPers) override;
0309
0310 public:
0311 enum ManipulatorSkin
0312 {
0313 ManipulatorSkin_Shaded,
0314 ManipulatorSkin_Flat
0315 };
0316
0317
0318 ManipulatorSkin SkinMode() const { return mySkinMode; }
0319
0320
0321 Standard_EXPORT void SetSkinMode(const ManipulatorSkin theSkinMode);
0322
0323 AIS_ManipulatorMode ActiveMode() const { return myCurrentMode; }
0324
0325 int ActiveAxisIndex() const { return myCurrentIndex; }
0326
0327
0328 const gp_Ax2& Position() const { return myPosition; }
0329
0330
0331 Standard_EXPORT void SetPosition(const gp_Ax2& thePosition);
0332
0333 float Size() const { return myAxes[0].Size(); }
0334
0335
0336 Standard_EXPORT void SetSize(const float theSideLength);
0337
0338
0339 Standard_EXPORT void SetGap(const float theValue);
0340
0341 public:
0342
0343
0344
0345 struct BehaviorOnTransform
0346 {
0347
0348 BehaviorOnTransform()
0349 : FollowTranslation(true),
0350 FollowRotation(true),
0351 FollowDragging(true)
0352 {
0353 }
0354
0355 BehaviorOnTransform& SetFollowTranslation(const bool theApply)
0356 {
0357 FollowTranslation = theApply;
0358 return *this;
0359 }
0360
0361 BehaviorOnTransform& SetFollowRotation(const bool theApply)
0362 {
0363 FollowRotation = theApply;
0364 return *this;
0365 }
0366
0367 BehaviorOnTransform& SetFollowDragging(const bool theApply)
0368 {
0369 FollowDragging = theApply;
0370 return *this;
0371 }
0372
0373 bool FollowTranslation;
0374 bool FollowRotation;
0375 bool FollowDragging;
0376 };
0377
0378
0379
0380 void SetTransformBehavior(const BehaviorOnTransform& theSettings)
0381 {
0382 myBehaviorOnTransform = theSettings;
0383 }
0384
0385
0386 BehaviorOnTransform& ChangeTransformBehavior() { return myBehaviorOnTransform; }
0387
0388
0389 const BehaviorOnTransform& TransformBehavior() const { return myBehaviorOnTransform; }
0390
0391 public:
0392
0393
0394
0395 Standard_EXPORT void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0396 const occ::handle<Prs3d_Presentation>& thePrs,
0397 const int theMode = 0) override;
0398
0399
0400
0401 Standard_EXPORT void ComputeSelection(const occ::handle<SelectMgr_Selection>& theSelection,
0402 const int theMode) override;
0403
0404
0405
0406 bool IsAutoHilight() const override { return false; }
0407
0408
0409
0410 Standard_EXPORT void ClearSelected() override;
0411
0412
0413 Standard_EXPORT void HilightSelected(
0414 const occ::handle<PrsMgr_PresentationManager>& thePM,
0415 const NCollection_Sequence<occ::handle<SelectMgr_EntityOwner>>& theSeq) override;
0416
0417
0418
0419 Standard_EXPORT void HilightOwnerWithColor(
0420 const occ::handle<PrsMgr_PresentationManager>& thePM,
0421 const occ::handle<Prs3d_Drawer>& theStyle,
0422 const occ::handle<SelectMgr_EntityOwner>& theOwner) override;
0423
0424 protected:
0425 Standard_EXPORT void init();
0426
0427 Standard_EXPORT void updateTransformation();
0428
0429 Standard_EXPORT occ::handle<Prs3d_Presentation> getHighlightPresentation(
0430 const occ::handle<SelectMgr_EntityOwner>& theOwner) const;
0431
0432 Standard_EXPORT occ::handle<Graphic3d_Group> getGroup(const int theIndex,
0433 const AIS_ManipulatorMode theMode) const;
0434
0435 Standard_EXPORT void attachToPoint(const gp_Pnt& thePoint);
0436
0437 Standard_EXPORT void attachToBox(const Bnd_Box& theBox);
0438
0439 Standard_EXPORT void adjustSize(const Bnd_Box& theBox);
0440
0441 Standard_EXPORT void setTransformPersistence(
0442 const occ::handle<Graphic3d_TransformPers>& theTrsfPers);
0443
0444
0445
0446
0447
0448
0449
0450 Standard_EXPORT void setLocalTransformation(const occ::handle<TopLoc_Datum3D>& theTrsf) override;
0451 using AIS_InteractiveObject::SetLocalTransformation;
0452
0453 protected:
0454 class Quadric
0455 {
0456 public:
0457 virtual ~Quadric()
0458 {
0459 myTriangulation.Nullify();
0460 myArray.Nullify();
0461 }
0462
0463 const occ::handle<Poly_Triangulation>& Triangulation() const { return myTriangulation; }
0464
0465 const occ::handle<Graphic3d_ArrayOfTriangles>& Array() const { return myArray; }
0466
0467 protected:
0468 occ::handle<Poly_Triangulation> myTriangulation;
0469 occ::handle<Graphic3d_ArrayOfTriangles> myArray;
0470 };
0471
0472 class Disk : public Quadric
0473 {
0474 public:
0475 Disk()
0476 : Quadric(),
0477 myInnerRad(0.0f),
0478 myOuterRad(1.0f)
0479 {
0480 }
0481
0482 ~Disk() override = default;
0483
0484 void Init(const float theInnerRadius,
0485 const float theOuterRadius,
0486 const gp_Ax1& thePosition,
0487 const double theAngle,
0488 const int theSlicesNb = 20,
0489 const int theStacksNb = 20);
0490
0491 protected:
0492 gp_Ax1 myPosition;
0493 float myInnerRad;
0494 float myOuterRad;
0495 };
0496
0497 class Sphere : public Quadric
0498 {
0499 public:
0500 Sphere()
0501 : Quadric(),
0502 myRadius(1.0f)
0503 {
0504 }
0505
0506 void Init(const float theRadius,
0507 const gp_Pnt& thePosition,
0508 const ManipulatorSkin theSkinMode,
0509 const int theSlicesNb = 20,
0510 const int theStacksNb = 20);
0511
0512 protected:
0513 gp_Pnt myPosition;
0514 float myRadius;
0515 };
0516
0517 class Cube
0518 {
0519 public:
0520 Cube() = default;
0521
0522 ~Cube() = default;
0523
0524 void Init(const gp_Ax1& thePosition, const float myBoxSize, const ManipulatorSkin theSkinMode);
0525
0526 const occ::handle<Poly_Triangulation>& Triangulation() const { return myTriangulation; }
0527
0528 const occ::handle<Graphic3d_ArrayOfTriangles>& Array() const { return myArray; }
0529
0530 private:
0531 void addTriangle(const int theIndex,
0532 const gp_Pnt& theP1,
0533 const gp_Pnt& theP2,
0534 const gp_Pnt& theP3,
0535 const gp_Dir& theNormal);
0536
0537 protected:
0538 occ::handle<Poly_Triangulation> myTriangulation;
0539 occ::handle<Graphic3d_ArrayOfTriangles> myArray;
0540 };
0541
0542 class Sector : public Quadric
0543 {
0544 public:
0545 Sector()
0546 : Quadric(),
0547 myRadius(0.0f)
0548 {
0549 }
0550
0551 ~Sector() override = default;
0552
0553 void Init(const float theRadius,
0554 const gp_Ax1& thePosition,
0555 const gp_Dir& theXDirection,
0556 const ManipulatorSkin theSkinMode,
0557 const int theSlicesNb = 5,
0558 const int theStacksNb = 5);
0559
0560 protected:
0561 gp_Ax1 myPosition;
0562 float myRadius;
0563 };
0564
0565
0566
0567
0568
0569
0570 class Axis
0571 {
0572 public:
0573 Axis(const gp_Ax1& theAxis = gp_Ax1(),
0574 const Quantity_Color& theColor = Quantity_Color(),
0575 const float theLength = 10.0f);
0576
0577 void Compute(const occ::handle<PrsMgr_PresentationManager>& thePrsMgr,
0578 const occ::handle<Prs3d_Presentation>& thePrs,
0579 const occ::handle<Prs3d_ShadingAspect>& theAspect,
0580 const ManipulatorSkin theSkinMode);
0581
0582 const gp_Ax1& ReferenceAxis() const { return myReferenceAxis; }
0583
0584 void SetPosition(const gp_Ax1& thePosition) { myPosition = thePosition; }
0585
0586 const gp_Ax1& Position() const { return myPosition; }
0587
0588 void SetTransformPersistence(const occ::handle<Graphic3d_TransformPers>& theTrsfPers)
0589 {
0590 if (!myHighlightTranslator.IsNull())
0591 {
0592 myHighlightTranslator->SetTransformPersistence(theTrsfPers);
0593 }
0594
0595 if (!myHighlightScaler.IsNull())
0596 {
0597 myHighlightScaler->SetTransformPersistence(theTrsfPers);
0598 }
0599
0600 if (!myHighlightRotator.IsNull())
0601 {
0602 myHighlightRotator->SetTransformPersistence(theTrsfPers);
0603 }
0604
0605 if (!myHighlightDragger.IsNull())
0606 {
0607 myHighlightDragger->SetTransformPersistence(theTrsfPers);
0608 }
0609 }
0610
0611 void Transform(const occ::handle<TopLoc_Datum3D>& theTransformation)
0612 {
0613 if (!myHighlightTranslator.IsNull())
0614 {
0615 myHighlightTranslator->SetTransformation(theTransformation);
0616 }
0617
0618 if (!myHighlightScaler.IsNull())
0619 {
0620 myHighlightScaler->SetTransformation(theTransformation);
0621 }
0622
0623 if (!myHighlightRotator.IsNull())
0624 {
0625 myHighlightRotator->SetTransformation(theTransformation);
0626 }
0627
0628 if (!myHighlightDragger.IsNull())
0629 {
0630 myHighlightDragger->SetTransformation(theTransformation);
0631 }
0632 }
0633
0634 bool HasTranslation() const { return myHasTranslation; }
0635
0636 bool HasRotation() const { return myHasRotation; }
0637
0638 bool HasScaling() const { return myHasScaling; }
0639
0640 bool HasDragging() const { return myHasDragging; }
0641
0642 void SetTranslation(const bool theIsEnabled) { myHasTranslation = theIsEnabled; }
0643
0644 void SetRotation(const bool theIsEnabled) { myHasRotation = theIsEnabled; }
0645
0646 void SetScaling(const bool theIsEnabled) { myHasScaling = theIsEnabled; }
0647
0648 void SetDragging(const bool theIsEnabled) { myHasDragging = theIsEnabled; }
0649
0650 Quantity_Color Color() const { return myColor; }
0651
0652 float AxisLength() const { return myLength; }
0653
0654 float BoxSize() const { return myBoxSize; }
0655
0656 float AxisRadius() const { return myAxisRadius; }
0657
0658 float Indent() const { return myIndent; }
0659
0660 void SetAxisRadius(const float theValue) { myAxisRadius = theValue; }
0661
0662 const occ::handle<Prs3d_Presentation>& TranslatorHighlightPrs() const
0663 {
0664 return myHighlightTranslator;
0665 }
0666
0667 const occ::handle<Prs3d_Presentation>& RotatorHighlightPrs() const
0668 {
0669 return myHighlightRotator;
0670 }
0671
0672 const occ::handle<Prs3d_Presentation>& ScalerHighlightPrs() const { return myHighlightScaler; }
0673
0674 const occ::handle<Prs3d_Presentation>& DraggerHighlightPrs() const
0675 {
0676 return myHighlightDragger;
0677 }
0678
0679 const occ::handle<Graphic3d_Group>& TranslatorGroup() const { return myTranslatorGroup; }
0680
0681 const occ::handle<Graphic3d_Group>& RotatorGroup() const { return myRotatorGroup; }
0682
0683 const occ::handle<Graphic3d_Group>& ScalerGroup() const { return myScalerGroup; }
0684
0685 const occ::handle<Graphic3d_Group>& DraggerGroup() const { return myDraggerGroup; }
0686
0687 const occ::handle<Graphic3d_ArrayOfTriangles>& TriangleArray() const { return myTriangleArray; }
0688
0689 void SetIndent(const float theValue) { myIndent = theValue; }
0690
0691 float Size() const { return myInnerRadius + myDiskThickness + myIndent * 2; }
0692
0693 float InnerRadius() const { return myInnerRadius + myIndent * 2.0f; }
0694
0695 gp_Pnt ScalerCenter(const gp_Pnt& theLocation) const
0696 {
0697 return theLocation.XYZ()
0698 + myPosition.Direction().XYZ() * (myLength + myIndent + myBoxSize * 0.5f);
0699 }
0700
0701 void SetSize(const float theValue)
0702 {
0703 if (myIndent > theValue * 0.1f)
0704 {
0705 myLength = theValue * 0.7f;
0706 myBoxSize = theValue * 0.15f;
0707 myDiskThickness = theValue * 0.05f;
0708 myIndent = theValue * 0.05f;
0709 }
0710 else
0711 {
0712 float aLength = theValue - 2 * myIndent;
0713 myLength = aLength * 0.8f;
0714 myBoxSize = aLength * 0.15f;
0715 myDiskThickness = aLength * 0.05f;
0716 }
0717 myInnerRadius = myIndent * 2 + myBoxSize + myLength;
0718 myAxisRadius = myBoxSize / 4.0f;
0719 }
0720
0721 int FacettesNumber() const { return myFacettesNumber; }
0722
0723 public:
0724 const gp_Pnt& TranslatorTipPosition() const { return myArrowTipPos; }
0725
0726 const Sector& DraggerSector() const { return mySector; }
0727
0728 const Disk& RotatorDisk() const { return myCircle; }
0729
0730 float RotatorDiskRadius() const { return myCircleRadius; }
0731
0732 const Cube& ScalerCube() const { return myCube; }
0733
0734 const gp_Pnt& ScalerCubePosition() const { return myCubePos; }
0735
0736 protected:
0737 gp_Ax1 myReferenceAxis;
0738 gp_Ax1 myPosition;
0739 Quantity_Color myColor;
0740
0741 bool myHasTranslation;
0742 float myLength;
0743 float myAxisRadius;
0744
0745 bool myHasScaling;
0746 float myBoxSize;
0747
0748 bool myHasRotation;
0749 float myInnerRadius;
0750 float myDiskThickness;
0751 float myIndent;
0752
0753 bool myHasDragging;
0754
0755 protected:
0756 int myFacettesNumber;
0757
0758 gp_Pnt myArrowTipPos;
0759 Sector mySector;
0760 Disk myCircle;
0761 float myCircleRadius;
0762 Cube myCube;
0763 gp_Pnt myCubePos;
0764
0765 occ::handle<Graphic3d_Group> myTranslatorGroup;
0766 occ::handle<Graphic3d_Group> myScalerGroup;
0767 occ::handle<Graphic3d_Group> myRotatorGroup;
0768 occ::handle<Graphic3d_Group> myDraggerGroup;
0769
0770 occ::handle<Prs3d_Presentation> myHighlightTranslator;
0771 occ::handle<Prs3d_Presentation> myHighlightScaler;
0772 occ::handle<Prs3d_Presentation> myHighlightRotator;
0773 occ::handle<Prs3d_Presentation> myHighlightDragger;
0774
0775 occ::handle<Graphic3d_ArrayOfTriangles> myTriangleArray;
0776 };
0777
0778 protected:
0779 Axis myAxes[3];
0780 Sphere myCenter;
0781
0782 gp_Ax2 myPosition;
0783
0784 Disk myCircle;
0785 occ::handle<Graphic3d_Group> myCircleGroup;
0786
0787 Disk mySector;
0788 occ::handle<Graphic3d_Group> mySectorGroup;
0789
0790 int myCurrentIndex;
0791 AIS_ManipulatorMode myCurrentMode;
0792 ManipulatorSkin mySkinMode;
0793
0794 bool myIsActivationOnDetection;
0795 bool myIsZoomPersistentMode;
0796 BehaviorOnTransform myBehaviorOnTransform;
0797
0798 protected:
0799
0800 NCollection_Sequence<gp_Trsf> myStartTrsfs;
0801 bool myHasStartedTransformation;
0802
0803 gp_Ax2 myStartPosition;
0804 gp_Pnt myStartPick;
0805 double myPrevState;
0806
0807
0808 occ::handle<Prs3d_ShadingAspect> myHighlightAspect;
0809
0810
0811 occ::handle<Prs3d_ShadingAspect> myDraggerHighlight;
0812
0813 public:
0814 DEFINE_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject)
0815 };
0816 #endif