if (aContext.IsNull())
return aErased;
- AISObjectPtr anObject = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObject = myResult2AISObjectMap.value(theObject);
if (anObject) {
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
ObjectPtr anObject = aPrs->object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
if (aResult.get() && isVisible(aResult)) {
- AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+ AISObjectPtr anObj = myResult2AISObjectMap.value(aResult);
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
// The methods are replaced in order to provide multi-selection, e.g. restore selection
bool aErased = false;
Handle(AIS_InteractiveContext) aContext = AISContext();
if (!aContext.IsNull()) {
- foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
- AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+ foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+ AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
// erase an object
Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
if (!anIO.IsNull()) {
//**************************************************************
AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
{
- AISObjectPtr anIO;
- if (myResult2AISObjectMap.contains(theObject))
- anIO = myResult2AISObjectMap[theObject];
- return anIO;
+ return myResult2AISObjectMap.value(theObject);
}
//**************************************************************
//**************************************************************
ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
{
- ObjectPtr anObject;
- ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin();
- for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) {
- const AISObjectPtr& aAIS = aMapIter.value();
- Handle(AIS_InteractiveObject) anAIS = aAIS->impl<Handle(AIS_InteractiveObject)>();
- if (anAIS == theIO)
- anObject = aMapIter.key();
- if (anObject.get())
- break;
- }
+ ObjectPtr anObject = myResult2AISObjectMap.value(theIO);
if (!anObject.get()) {
std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
if (!theIO.IsNull()) {
//**************************************************************
void XGUI_Displayer::showOnly(const QObjectPtrList& theList)
{
- QObjectPtrList aDispList = myResult2AISObjectMap.keys();
+ QObjectPtrList aDispList = myResult2AISObjectMap.objects();
foreach(ObjectPtr aObj, aDispList) {
if (!theList.contains(aObj))
erase(aObj, false);
//**************************************************************
void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS)
{
- myResult2AISObjectMap[theObject] = theAIS;
+ myResult2AISObjectMap.add(theObject, theAIS);
#ifdef DEBUG_DISPLAY
std::ostringstream aPtrStr;
std::string XGUI_Displayer::getResult2AISObjectMapInfo() const
{
QStringList aContent;
- foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) {
- AISObjectPtr aAISObj = myResult2AISObjectMap[aObj];
+ foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) {
+ AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj);
std::ostringstream aPtrStr;
aPtrStr << "aObj = " << aObj.get() << ":";
aPtrStr << "anAIS = " << aAISObj.get() << ":";
class VInspectorAPI_CallBack;
#endif
+
+class XGUI_TwoSidePresentationMap
+{
+public:
+ ~XGUI_TwoSidePresentationMap() { clear(); }
+
+ /// Add new values pair to the map
+ /// \param theObj an object
+ /// \param theAIS a corresponded presentation
+ bool add(const ObjectPtr& theObj, const AISObjectPtr& theAIS)
+ {
+ if (myResultToAISMap.contains(theObj))
+ return false;
+ Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ myResultToAISMap[theObj] = anAIS;
+ myAIStoResultMap[anAIS] = theObj;
+ return true;
+ }
+
+ /// Removes values by object
+ /// \param theObj an object
+ bool remove(const ObjectPtr& theObj)
+ {
+ if (!myResultToAISMap.contains(theObj))
+ return false;
+ Handle(AIS_InteractiveObject) aAIS = myResultToAISMap[theObj];
+ myResultToAISMap.remove(theObj);
+ myAIStoResultMap.remove(aAIS);
+ return true;
+ }
+
+ /// Removes values by presentation
+ /// \param theAIS a presentation
+ bool remove(const AISObjectPtr& theAIS)
+ {
+ Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ if (!myAIStoResultMap.contains(anAIS))
+ return false;
+ ObjectPtr aObj = myAIStoResultMap[anAIS];
+ myResultToAISMap.remove(aObj);
+ myAIStoResultMap.remove(anAIS);
+ return true;
+ }
+
+ /// Removes all values
+ void clear()
+ {
+ myResultToAISMap.clear();
+ myAIStoResultMap.clear();
+ }
+
+ /// Returns presentation by object
+ /// \param theObj an object
+ AISObjectPtr value(const ObjectPtr& theObj) const
+ {
+ if (myResultToAISMap.contains(theObj)) {
+ Handle(AIS_InteractiveObject) anAIS = myResultToAISMap[theObj];
+ AISObjectPtr anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(anAIS));
+ return anAISObj;
+ }
+ return AISObjectPtr();
+ }
+
+ /// Returns object by presentation
+ /// \param theAIS a presentation
+ ObjectPtr value(const AISObjectPtr& theAIS) const
+ {
+ Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ if (myAIStoResultMap.contains(anAIS))
+ return myAIStoResultMap[anAIS];
+ return ObjectPtr();
+ }
+
+ /// Returns object by presentation
+ /// \param theAIS a presentation
+ ObjectPtr value(const Handle(AIS_InteractiveObject)& theAIS) const
+ {
+ if (myAIStoResultMap.contains(theAIS))
+ return myAIStoResultMap[theAIS];
+ return ObjectPtr();
+ }
+
+ /// Returns number of values
+ int size() const { return myResultToAISMap.size(); }
+
+ /// Returns list of objects
+ QObjectPtrList objects() const { return myResultToAISMap.keys(); }
+
+ /// returns list of presentations
+ QList<Handle(AIS_InteractiveObject)> presentations() const { return myAIStoResultMap.keys(); }
+
+ /// Returns true if the Map contains the object
+ /// \param theObj an object
+ bool contains(const ObjectPtr& theObj) const { return myResultToAISMap.contains(theObj); }
+
+ /// Returns true if the Map contains the presentation
+ /// \param theAIS a presentation
+ bool contains(const AISObjectPtr& theAIS) const
+ {
+ Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ return myAIStoResultMap.contains(anAIS);
+ }
+
+private:
+ QMap<ObjectPtr, Handle(AIS_InteractiveObject)> myResultToAISMap;
+ QMap<Handle(AIS_InteractiveObject), ObjectPtr> myAIStoResultMap;
+};
+
+
/**\class XGUI_Displayer
* \ingroup GUI
* \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
int objectsCount() const { return myResult2AISObjectMap.size(); }
/// Returns list of displayed objects
- QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
+ QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.objects(); }
/// Returns list of displayed objects
- QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
+ QList<Handle(AIS_InteractiveObject)> displayedPresentations() const
+ {
+ return myResult2AISObjectMap.presentations();
+ }
/// Returns true if the given object can be shown in shaded mode
/// \param theObject object to check
GeomCustomPrsPtr myCustomPrs;
/// Definition of a type of map which defines correspondance between objects and presentations
- typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
- ResultToAISMap myResult2AISObjectMap; ///< A map of displayed objects
+ XGUI_TwoSidePresentationMap myResult2AISObjectMap; ///< A map of displayed objects
/// Number of blocking of the viewer update. The viewer is updated only if it is zero
int myViewerBlockedRecursiveCount;