File indexing completed on 2025-01-18 10:04:53
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 class SelectMgr_SelectableObjectSet
0029 {
0030 public:
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 enum BVHSubset
0046 {
0047 BVHSubset_3d,
0048 BVHSubset_3dPersistent,
0049 BVHSubset_2dPersistent,
0050 BVHSubsetNb
0051 };
0052
0053 public:
0054
0055
0056 class Iterator
0057 {
0058
0059 typedef NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)>::Iterator ObjectMapIterator;
0060
0061 public:
0062
0063
0064 Iterator() : mySet (NULL), mySubsetIdx (BVHSubsetNb) {}
0065
0066
0067 Iterator (const SelectMgr_SelectableObjectSet& theSet) { Init (theSet); }
0068
0069
0070 void Init (const SelectMgr_SelectableObjectSet& theSet)
0071 {
0072 mySet = &theSet;
0073 mySubsetIdx = 0;
0074 mySubsetIt = ObjectMapIterator (theSet.myObjects[mySubsetIdx]);
0075 More();
0076 }
0077
0078
0079 Standard_Boolean More()
0080 {
0081 if (mySubsetIt.More())
0082 {
0083 return Standard_True;
0084 }
0085 else if ((mySubsetIdx == BVHSubsetNb - 1) || mySet == NULL)
0086 {
0087 return Standard_False;
0088 }
0089 mySubsetIt = ObjectMapIterator (mySet->myObjects[++mySubsetIdx]);
0090 return More();
0091 }
0092
0093
0094 void Next() { mySubsetIt.Next(); }
0095
0096
0097 const Handle(SelectMgr_SelectableObject)& Value() const { return mySubsetIt.Value(); }
0098
0099 private:
0100 const SelectMgr_SelectableObjectSet* mySet;
0101 Standard_Integer mySubsetIdx;
0102 ObjectMapIterator mySubsetIt;
0103 };
0104
0105 public:
0106
0107
0108 Standard_EXPORT SelectMgr_SelectableObjectSet();
0109
0110
0111 virtual ~SelectMgr_SelectableObjectSet() { }
0112
0113
0114
0115
0116
0117 Standard_EXPORT Standard_Boolean Append (const Handle(SelectMgr_SelectableObject)& theObject);
0118
0119
0120
0121
0122
0123 Standard_EXPORT Standard_Boolean Remove (const Handle(SelectMgr_SelectableObject)& theObject);
0124
0125
0126
0127
0128 Standard_EXPORT void ChangeSubset (const Handle(SelectMgr_SelectableObject)& theObject);
0129
0130
0131
0132 Standard_EXPORT void UpdateBVH (const Handle(Graphic3d_Camera)& theCam,
0133 const Graphic3d_Vec2i& theWinSize);
0134
0135
0136 Standard_EXPORT void MarkDirty();
0137
0138
0139 Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const
0140 {
0141 return myObjects[BVHSubset_3d].Contains (theObject)
0142 || myObjects[BVHSubset_3dPersistent].Contains (theObject)
0143 || myObjects[BVHSubset_2dPersistent].Contains (theObject);
0144 }
0145
0146
0147 Standard_Boolean IsEmpty() const
0148 {
0149 return myObjects[BVHSubset_3d].IsEmpty()
0150 && myObjects[BVHSubset_3dPersistent].IsEmpty()
0151 && myObjects[BVHSubset_2dPersistent].IsEmpty();
0152 }
0153
0154
0155 Standard_Boolean IsEmpty (const BVHSubset theSubset) const
0156 {
0157 return myObjects[theSubset].IsEmpty();
0158 }
0159
0160
0161
0162 const Handle(SelectMgr_SelectableObject)& GetObjectById (const BVHSubset theSubset,
0163 const Standard_Integer theIndex) const
0164 {
0165 return myObjects[theSubset].FindKey (theIndex + 1);
0166 }
0167
0168
0169 const opencascade::handle<BVH_Tree<Standard_Real, 3> >& BVH(const BVHSubset theSubset) const
0170 {
0171 return myBVH[theSubset];
0172 }
0173
0174
0175 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0176
0177 private:
0178
0179
0180 Standard_Integer appropriateSubset (const Handle(SelectMgr_SelectableObject)& theObject)
0181 {
0182 if (theObject->TransformPersistence().IsNull())
0183 {
0184 const PrsMgr_Presentations& aPresentations = theObject->Presentations();
0185 for (PrsMgr_Presentations::Iterator aPrsIter (aPresentations); aPrsIter.More(); aPrsIter.Next())
0186 {
0187 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue();
0188 if (aPrs3d->CStructure()->HasGroupTransformPersistence())
0189 {
0190 return SelectMgr_SelectableObjectSet::BVHSubset_3dPersistent;
0191 }
0192 }
0193 return SelectMgr_SelectableObjectSet::BVHSubset_3d;
0194 }
0195 else if (theObject->TransformPersistence()->Mode() == Graphic3d_TMF_2d)
0196 {
0197 return SelectMgr_SelectableObjectSet::BVHSubset_2dPersistent;
0198 }
0199 else
0200 {
0201 return SelectMgr_SelectableObjectSet::BVHSubset_3dPersistent;
0202 }
0203 }
0204
0205
0206 Standard_Integer currentSubset (const Handle(SelectMgr_SelectableObject)& theObject)
0207 {
0208 for (Standard_Integer aSubsetIdx = 0; aSubsetIdx < BVHSubsetNb; ++aSubsetIdx)
0209 {
0210 if (myObjects[aSubsetIdx].Contains (theObject))
0211 {
0212 return aSubsetIdx;
0213 }
0214 }
0215 return -1;
0216 }
0217
0218 private:
0219
0220 NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)> myObjects[BVHSubsetNb];
0221 opencascade::handle<BVH_Tree<Standard_Real, 3> > myBVH[BVHSubsetNb];
0222 Handle(Select3D_BVHBuilder3d) myBuilder[BVHSubsetNb];
0223 Standard_Boolean myIsDirty[BVHSubsetNb];
0224 Graphic3d_WorldViewProjState myLastViewState;
0225 Graphic3d_Vec2i myLastWinSize;
0226 friend class Iterator;
0227 };
0228
0229 #endif