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