File indexing completed on 2026-06-03 08:36:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef _SelectMgr_ViewerSelector_HeaderFile
0018 #define _SelectMgr_ViewerSelector_HeaderFile
0019
0020 #include <OSD_Chronometer.hxx>
0021 #include <SelectMgr_BVHThreadPool.hxx>
0022 #include <SelectMgr_IndexedDataMapOfOwnerCriterion.hxx>
0023 #include <SelectMgr_SelectingVolumeManager.hxx>
0024 #include <SelectMgr_Selection.hxx>
0025 #include <SelectMgr_SelectableObject.hxx>
0026 #include <SelectMgr_SelectableObjectSet.hxx>
0027 #include <SelectMgr_StateOfSelection.hxx>
0028 #include <SelectMgr_ToleranceMap.hxx>
0029 #include <SelectMgr_TypeOfDepthTolerance.hxx>
0030 #include <SelectMgr_ViewerSelector.hxx>
0031 #include <Standard_OStream.hxx>
0032 #include <Standard_Transient.hxx>
0033 #include <StdSelect_TypeOfSelectionImage.hxx>
0034 #include <TColStd_HArray1OfInteger.hxx>
0035
0036 class SelectMgr_SensitiveEntitySet;
0037 class SelectMgr_EntityOwner;
0038 class Select3D_SensitiveEntity;
0039 class V3d_View;
0040
0041
0042 #ifdef Status
0043 #undef Status
0044 #endif
0045 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject),
0046 Handle(SelectMgr_SensitiveEntitySet)>
0047 SelectMgr_MapOfObjectSensitives;
0048 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject),
0049 Handle(SelectMgr_SensitiveEntitySet)>::Iterator
0050 SelectMgr_MapOfObjectSensitivesIterator;
0051
0052 typedef NCollection_DataMap<Standard_Integer, SelectMgr_SelectingVolumeManager>
0053 SelectMgr_FrustumCache;
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 class SelectMgr_ViewerSelector : public Standard_Transient
0086 {
0087 DEFINE_STANDARD_RTTIEXT(SelectMgr_ViewerSelector, Standard_Transient)
0088 friend class SelectMgr_SelectionManager;
0089
0090 public:
0091
0092 Standard_EXPORT SelectMgr_ViewerSelector();
0093
0094
0095 Standard_Integer CustomPixelTolerance() const { return myTolerances.CustomTolerance(); }
0096
0097
0098 Standard_EXPORT void SetPixelTolerance(const Standard_Integer theTolerance);
0099
0100
0101 Standard_Real Sensitivity() const { return myTolerances.Tolerance(); }
0102
0103
0104 Standard_Integer PixelTolerance() const { return myTolerances.Tolerance(); }
0105
0106
0107 Standard_EXPORT virtual void SortResult() const;
0108
0109
0110
0111 Handle(SelectMgr_EntityOwner) OnePicked() const
0112 {
0113 return mystored.IsEmpty() ? Handle(SelectMgr_EntityOwner)() : Picked(1);
0114 }
0115
0116
0117
0118
0119
0120 bool ToPickClosest() const { return myToPreferClosest; }
0121
0122
0123 void SetPickClosest(bool theToPreferClosest) { myToPreferClosest = theToPreferClosest; }
0124
0125
0126
0127 SelectMgr_TypeOfDepthTolerance DepthToleranceType() const { return myDepthTolType; }
0128
0129
0130
0131 Standard_Real DepthTolerance() const { return myDepthTolerance; }
0132
0133
0134
0135
0136
0137
0138
0139
0140 void SetDepthTolerance(SelectMgr_TypeOfDepthTolerance theType, Standard_Real theTolerance)
0141 {
0142 myDepthTolType = theType;
0143 myDepthTolerance = theTolerance;
0144 }
0145
0146
0147 Standard_Integer NbPicked() const { return mystored.Extent(); }
0148
0149
0150 Standard_EXPORT void ClearPicked();
0151
0152
0153 void Clear() { ClearPicked(); }
0154
0155
0156
0157 Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked(const Standard_Integer theRank) const;
0158
0159
0160
0161 Standard_EXPORT const SelectMgr_SortCriterion& PickedData(const Standard_Integer theRank) const;
0162
0163
0164
0165 const Handle(Select3D_SensitiveEntity)& PickedEntity(const Standard_Integer theRank) const
0166 {
0167 return PickedData(theRank).Entity;
0168 }
0169
0170
0171
0172
0173 gp_Pnt PickedPoint(const Standard_Integer theRank) const { return PickedData(theRank).Point; }
0174
0175
0176 Standard_EXPORT Standard_Boolean
0177 RemovePicked(const Handle(SelectMgr_SelectableObject)& theObject);
0178
0179 Standard_EXPORT Standard_Boolean
0180 Contains(const Handle(SelectMgr_SelectableObject)& theObject) const;
0181
0182
0183 const Handle(Select3D_BVHBuilder3d) EntitySetBuilder() { return myEntitySetBuilder; }
0184
0185
0186
0187
0188 Standard_EXPORT void SetEntitySetBuilder(const Handle(Select3D_BVHBuilder3d)& theBuilder);
0189
0190
0191
0192
0193
0194
0195 Standard_EXPORT Standard_Boolean
0196 Modes(const Handle(SelectMgr_SelectableObject)& theSelectableObject,
0197 TColStd_ListOfInteger& theModeList,
0198 const SelectMgr_StateOfSelection theWantedState = SelectMgr_SOS_Any) const;
0199
0200
0201
0202
0203 Standard_EXPORT Standard_Boolean
0204 IsActive(const Handle(SelectMgr_SelectableObject)& theSelectableObject,
0205 const Standard_Integer theMode) const;
0206
0207
0208
0209
0210 Standard_EXPORT Standard_Boolean
0211 IsInside(const Handle(SelectMgr_SelectableObject)& theSelectableObject,
0212 const Standard_Integer theMode) const;
0213
0214
0215 Standard_EXPORT SelectMgr_StateOfSelection
0216 Status(const Handle(SelectMgr_Selection)& theSelection) const;
0217
0218 Standard_EXPORT TCollection_AsciiString
0219 Status(const Handle(SelectMgr_SelectableObject)& theSelectableObject) const;
0220
0221
0222 Standard_EXPORT void ActiveOwners(
0223 NCollection_List<Handle(SelectMgr_EntityOwner)>& theOwners) const;
0224
0225
0226 Standard_EXPORT void AddSelectableObject(const Handle(SelectMgr_SelectableObject)& theObject);
0227
0228
0229 Standard_EXPORT void AddSelectionToObject(const Handle(SelectMgr_SelectableObject)& theObject,
0230 const Handle(SelectMgr_Selection)& theSelection);
0231
0232
0233
0234 Standard_EXPORT void MoveSelectableObject(const Handle(SelectMgr_SelectableObject)& theObject);
0235
0236
0237 Standard_EXPORT void RemoveSelectableObject(const Handle(SelectMgr_SelectableObject)& theObject);
0238
0239
0240 Standard_EXPORT void RemoveSelectionOfObject(const Handle(SelectMgr_SelectableObject)& theObject,
0241 const Handle(SelectMgr_Selection)& theSelection);
0242
0243
0244
0245 Standard_EXPORT void RebuildObjectsTree(const Standard_Boolean theIsForce = Standard_False);
0246
0247
0248
0249
0250 Standard_EXPORT void RebuildSensitivesTree(const Handle(SelectMgr_SelectableObject)& theObject,
0251 const Standard_Boolean theIsForce = Standard_False);
0252
0253
0254 SelectMgr_SelectingVolumeManager& GetManager() { return mySelectingVolumeMgr; }
0255
0256
0257 const SelectMgr_SelectableObjectSet& SelectableObjects() const { return mySelectableObjects; }
0258
0259
0260 Standard_EXPORT void ResetSelectionActivationStatus();
0261
0262
0263
0264
0265 Standard_EXPORT void AllowOverlapDetection(const Standard_Boolean theIsToAllow);
0266
0267 public:
0268
0269
0270 Standard_EXPORT void Pick(const Standard_Integer theXPix,
0271 const Standard_Integer theYPix,
0272 const Handle(V3d_View)& theView);
0273
0274
0275
0276
0277 Standard_EXPORT void Pick(const Standard_Integer theXPMin,
0278 const Standard_Integer theYPMin,
0279 const Standard_Integer theXPMax,
0280 const Standard_Integer theYPMax,
0281 const Handle(V3d_View)& theView);
0282
0283
0284 Standard_EXPORT void Pick(const TColgp_Array1OfPnt2d& thePolyline,
0285 const Handle(V3d_View)& theView);
0286
0287
0288
0289
0290 Standard_EXPORT void Pick(const gp_Ax1& theAxis, const Handle(V3d_View)& theView);
0291
0292
0293
0294
0295
0296
0297
0298
0299 Standard_EXPORT Standard_Boolean ToPixMap(Image_PixMap& theImage,
0300 const Handle(V3d_View)& theView,
0301 const StdSelect_TypeOfSelectionImage theType,
0302 const Standard_Integer thePickedIndex = 1);
0303
0304 public:
0305
0306 Standard_EXPORT void DisplaySensitive(const Handle(V3d_View)& theView);
0307
0308 Standard_EXPORT void ClearSensitive(const Handle(V3d_View)& theView);
0309
0310 Standard_EXPORT void DisplaySensitive(const Handle(SelectMgr_Selection)& theSel,
0311 const gp_Trsf& theTrsf,
0312 const Handle(V3d_View)& theView,
0313 const Standard_Boolean theToClearOthers = Standard_True);
0314
0315
0316 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0317
0318 public:
0319
0320 Standard_EXPORT void SetToPrebuildBVH(Standard_Boolean theToPrebuild,
0321 Standard_Integer theThreadsNum = -1);
0322
0323
0324 Standard_EXPORT void QueueBVHBuild(const Handle(Select3D_SensitiveEntity)& theEntity);
0325
0326
0327 Standard_EXPORT void WaitForBVHBuild();
0328
0329
0330 Standard_Boolean ToPrebuildBVH() const { return myToPrebuildBVH; }
0331
0332 protected:
0333
0334
0335 Standard_EXPORT void TraverseSensitives(const Standard_Integer theViewId = -1);
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 Standard_EXPORT void traverseObject(const Handle(SelectMgr_SelectableObject)& theObject,
0347 const SelectMgr_SelectingVolumeManager& theMgr,
0348 const Handle(Graphic3d_Camera)& theCamera,
0349 const Graphic3d_Mat4d& theProjectionMat,
0350 const Graphic3d_Mat4d& theWorldViewMat,
0351 const Graphic3d_Vec2i& theWinSize);
0352
0353
0354
0355 Standard_EXPORT void checkOverlap(const Handle(Select3D_SensitiveEntity)& theEntity,
0356 const gp_GTrsf& theInversedTrsf,
0357 SelectMgr_SelectingVolumeManager& theMgr);
0358
0359
0360 Standard_EXPORT void updateZLayers(const Handle(V3d_View)& theView);
0361
0362 private:
0363
0364 Standard_Boolean isToScaleFrustum(const Handle(Select3D_SensitiveEntity)& theEntity);
0365
0366
0367
0368 Standard_Integer sensitivity(const Handle(Select3D_SensitiveEntity)& theEntity) const;
0369
0370 void Activate(const Handle(SelectMgr_Selection)& theSelection);
0371
0372 void Deactivate(const Handle(SelectMgr_Selection)& theSelection);
0373
0374
0375 void Remove(const Handle(SelectMgr_Selection)& aSelection);
0376
0377
0378
0379 void computeFrustum(const Handle(Select3D_SensitiveEntity)& theEnt,
0380 const SelectMgr_SelectingVolumeManager& theMgrGlobal,
0381 const SelectMgr_SelectingVolumeManager& theMgrObject,
0382 const gp_GTrsf& theInvTrsf,
0383 SelectMgr_FrustumCache& theCachedMgrs,
0384 SelectMgr_SelectingVolumeManager& theResMgr);
0385
0386 private:
0387
0388 void updatePoint3d(SelectMgr_SortCriterion& theCriterion,
0389 const SelectBasics_PickResult& thePickResult,
0390 const Handle(Select3D_SensitiveEntity)& theEntity,
0391 const gp_GTrsf& theInversedTrsf,
0392 const SelectMgr_SelectingVolumeManager& theMgr) const;
0393
0394 protected:
0395 Standard_Real myDepthTolerance;
0396 SelectMgr_TypeOfDepthTolerance myDepthTolType;
0397 Standard_Boolean myToPreferClosest;
0398 SelectMgr_IndexedDataMapOfOwnerCriterion mystored;
0399 SelectMgr_SelectingVolumeManager mySelectingVolumeMgr;
0400 mutable SelectMgr_SelectableObjectSet mySelectableObjects;
0401 SelectMgr_ToleranceMap myTolerances;
0402 NCollection_DataMap<Graphic3d_ZLayerId, Standard_Integer> myZLayerOrderMap;
0403 Handle(Select3D_BVHBuilder3d) myEntitySetBuilder;
0404 gp_Pnt myCameraEye;
0405 gp_Dir myCameraDir;
0406 Standard_Real myCameraScale;
0407
0408 Standard_Boolean myToPrebuildBVH;
0409 Handle(SelectMgr_BVHThreadPool) myBVHThreadPool;
0410
0411 mutable TColStd_Array1OfInteger myIndexes;
0412 mutable Standard_Boolean myIsSorted;
0413 Standard_Boolean myIsLeftChildQueuedFirst;
0414 SelectMgr_MapOfObjectSensitives myMapOfObjectSensitives;
0415
0416 Graphic3d_SequenceOfStructure myStructs;
0417 };
0418
0419 DEFINE_STANDARD_HANDLE(SelectMgr_ViewerSelector, Standard_Transient)
0420
0421 #endif