File indexing completed on 2026-07-12 08:21:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _SelectMgr_SelectableObjectSet_HeaderFile
0017 #define _SelectMgr_SelectableObjectSet_HeaderFile
0018
0019 #include <NCollection_Handle.hxx>
0020 #include <Select3D_BVHBuilder3d.hxx>
0021 #include <SelectMgr_SelectableObject.hxx>
0022
0023
0024
0025
0026
0027
0028
0029 class SelectMgr_SelectableObjectSet
0030 {
0031 public:
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 enum BVHSubset
0057 {
0058 BVHSubset_3d,
0059 BVHSubset_3dPersistent,
0060 BVHSubset_2dPersistent,
0061 BVHSubset_ortho3dPersistent,
0062 BVHSubset_ortho2dPersistent,
0063 BVHSubsetNb
0064 };
0065
0066 public:
0067
0068 class Iterator
0069 {
0070
0071 typedef NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)>::Iterator ObjectMapIterator;
0072
0073 public:
0074
0075 Iterator()
0076 : mySet(NULL),
0077 mySubsetIdx(BVHSubsetNb)
0078 {
0079 }
0080
0081
0082 Iterator(const SelectMgr_SelectableObjectSet& theSet) { Init(theSet); }
0083
0084
0085 void Init(const SelectMgr_SelectableObjectSet& theSet)
0086 {
0087 mySet = &theSet;
0088 mySubsetIdx = 0;
0089 mySubsetIt = ObjectMapIterator(theSet.myObjects[mySubsetIdx]);
0090 More();
0091 }
0092
0093
0094 Standard_Boolean More()
0095 {
0096 if (mySubsetIt.More())
0097 {
0098 return Standard_True;
0099 }
0100 else if ((mySubsetIdx == BVHSubsetNb - 1) || mySet == NULL)
0101 {
0102 return Standard_False;
0103 }
0104 mySubsetIt = ObjectMapIterator(mySet->myObjects[++mySubsetIdx]);
0105 return More();
0106 }
0107
0108
0109 void Next() { mySubsetIt.Next(); }
0110
0111
0112 const Handle(SelectMgr_SelectableObject)& Value() const { return mySubsetIt.Value(); }
0113
0114 private:
0115 const SelectMgr_SelectableObjectSet* mySet;
0116 Standard_Integer mySubsetIdx;
0117 ObjectMapIterator mySubsetIt;
0118 };
0119
0120 public:
0121
0122 Standard_EXPORT SelectMgr_SelectableObjectSet();
0123
0124
0125 virtual ~SelectMgr_SelectableObjectSet() {}
0126
0127
0128
0129
0130
0131
0132 Standard_EXPORT Standard_Boolean Append(const Handle(SelectMgr_SelectableObject)& theObject);
0133
0134
0135
0136
0137
0138
0139 Standard_EXPORT Standard_Boolean Remove(const Handle(SelectMgr_SelectableObject)& theObject);
0140
0141
0142
0143
0144 Standard_EXPORT void ChangeSubset(const Handle(SelectMgr_SelectableObject)& theObject);
0145
0146
0147
0148 Standard_EXPORT void UpdateBVH(const Handle(Graphic3d_Camera)& theCam,
0149 const Graphic3d_Vec2i& theWinSize);
0150
0151
0152 Standard_EXPORT void MarkDirty();
0153
0154
0155 Standard_Boolean Contains(const Handle(SelectMgr_SelectableObject)& theObject) const
0156 {
0157 return myObjects[BVHSubset_3d].Contains(theObject)
0158 || myObjects[BVHSubset_3dPersistent].Contains(theObject)
0159 || myObjects[BVHSubset_2dPersistent].Contains(theObject)
0160 || myObjects[BVHSubset_ortho3dPersistent].Contains(theObject)
0161 || myObjects[BVHSubset_ortho2dPersistent].Contains(theObject);
0162 }
0163
0164
0165 Standard_Boolean IsEmpty() const
0166 {
0167 return myObjects[BVHSubset_3d].IsEmpty() && myObjects[BVHSubset_3dPersistent].IsEmpty()
0168 && myObjects[BVHSubset_2dPersistent].IsEmpty()
0169 && myObjects[BVHSubset_ortho3dPersistent].IsEmpty()
0170 && myObjects[BVHSubset_ortho2dPersistent].IsEmpty();
0171 }
0172
0173
0174 Standard_Boolean IsEmpty(const BVHSubset theSubset) const
0175 {
0176 return myObjects[theSubset].IsEmpty();
0177 }
0178
0179
0180
0181 const Handle(SelectMgr_SelectableObject)& GetObjectById(const BVHSubset theSubset,
0182 const Standard_Integer theIndex) const
0183 {
0184 return myObjects[theSubset].FindKey(theIndex + 1);
0185 }
0186
0187
0188 const opencascade::handle<BVH_Tree<Standard_Real, 3>>& BVH(const BVHSubset theSubset) const
0189 {
0190 return myBVH[theSubset];
0191 }
0192
0193
0194 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0195
0196 private:
0197
0198 Standard_Integer appropriateSubset(const Handle(SelectMgr_SelectableObject)& theObject)
0199 {
0200 if (theObject->TransformPersistence().IsNull())
0201 {
0202 const PrsMgr_Presentations& aPresentations = theObject->Presentations();
0203 for (PrsMgr_Presentations::Iterator aPrsIter(aPresentations); aPrsIter.More();
0204 aPrsIter.Next())
0205 {
0206 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
0207 if (aPrs3d->CStructure()->HasGroupTransformPersistence())
0208 {
0209 return SelectMgr_SelectableObjectSet::BVHSubset_3dPersistent;
0210 }
0211 }
0212 return SelectMgr_SelectableObjectSet::BVHSubset_3d;
0213 }
0214 else if ((theObject->TransformPersistence()->Mode() & Graphic3d_TMF_2d) != 0)
0215 {
0216 if (theObject->TransformPersistence()->IsOrthoPers())
0217 {
0218 return SelectMgr_SelectableObjectSet::BVHSubset_ortho2dPersistent;
0219 }
0220 return SelectMgr_SelectableObjectSet::BVHSubset_2dPersistent;
0221 }
0222 else if (theObject->TransformPersistence()->IsOrthoPers())
0223 {
0224 return SelectMgr_SelectableObjectSet::BVHSubset_ortho3dPersistent;
0225 }
0226 else
0227 {
0228 return SelectMgr_SelectableObjectSet::BVHSubset_3dPersistent;
0229 }
0230 }
0231
0232
0233 Standard_Integer currentSubset(const Handle(SelectMgr_SelectableObject)& theObject)
0234 {
0235 for (Standard_Integer aSubsetIdx = 0; aSubsetIdx < BVHSubsetNb; ++aSubsetIdx)
0236 {
0237 if (myObjects[aSubsetIdx].Contains(theObject))
0238 {
0239 return aSubsetIdx;
0240 }
0241 }
0242 return -1;
0243 }
0244
0245 private:
0246
0247 NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)> myObjects[BVHSubsetNb];
0248 opencascade::handle<BVH_Tree<Standard_Real, 3> > myBVH[BVHSubsetNb];
0249 Handle(Select3D_BVHBuilder3d) myBuilder[BVHSubsetNb];
0250 Standard_Boolean myIsDirty[BVHSubsetNb];
0251 Graphic3d_WorldViewProjState myLastViewState;
0252 Graphic3d_Vec2i myLastWinSize;
0253
0254 friend class Iterator;
0255 };
0256
0257 #endif