X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Displayer.cpp;h=f0ac7b3b355543ec2d90bf2be69e3955557d619f;hb=b73fb7468bea81901dbeed8e229d742f788ec282;hp=6c2f216e38dc4f4b9f61017dab69fbb0c9b61295;hpb=dc75c390f0aa6108d6983a8618dc4b9a4cd5949e;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 6c2f216e3..f0ac7b3b3 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include @@ -163,8 +165,13 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); bool isShading = false; if (aPrs.get() != NULL) { + GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast(theObject); + if (aScreen.get()) { + aScreen->setScreenPlane(getScreenPlane()); + aScreen->setViewScale(getViewScale()); + } anAIS = aPrs->getAISObject(anAIS); - if (anAIS.get()) { + //if (anAIS.get()) { // correct deviation coefficient for /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl(); if (!anAISPrs.IsNull()) { @@ -175,7 +182,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes()); } }*/ - } + //} } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult.get() != NULL) { @@ -285,7 +292,7 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) if (aContext.IsNull()) return aErased; - AISObjectPtr anObject = myResult2AISObjectMap[theObject]; + AISObjectPtr anObject = myResult2AISObjectMap.value(theObject); if (anObject) { Handle(AIS_InteractiveObject) anAIS = anObject->impl(); if (!anAIS.IsNull()) { @@ -324,6 +331,11 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); if (aPrs) { + GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast(theObject); + if (aScreen.get()) { + aScreen->setScreenPlane(getScreenPlane()); + aScreen->setViewScale(getViewScale()); + } AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj); if (!aAIS_Obj) { aRedisplayed = erase(theObject, theUpdateViewer); @@ -435,9 +447,8 @@ bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& th // compsolid is not visualized in the viewer, // but should have presentation when all sub solids are // visible. It is useful for highlight presentation where compsolid shape is selectable - if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) { - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(aResult); + if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) { + ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast(aResult); if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0; for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) { @@ -503,7 +514,7 @@ void XGUI_Displayer::setSelected(const QList& theValue ObjectPtr anObject = aPrs->object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get() && isVisible(aResult)) { - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; + AISObjectPtr anObj = myResult2AISObjectMap.value(aResult); Handle(AIS_InteractiveObject) anAIS = anObj->impl(); if (!anAIS.IsNull()) { // The methods are replaced in order to provide multi-selection, e.g. restore selection @@ -545,8 +556,13 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) bool aErased = false; Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { - foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) { +#ifdef OPTIMIZE_PRS + foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) { + AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj); +#else + foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) { AISObjectPtr aAISObj = myResult2AISObjectMap[aObj]; +#endif // erase an object Handle(AIS_InteractiveObject) anIO = aAISObj->impl(); if (!anIO.IsNull()) { @@ -573,10 +589,14 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) //************************************************************** AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const { +#ifdef OPTIMIZE_PRS + return myResult2AISObjectMap.value(theObject); +#else AISObjectPtr anIO; if (myResult2AISObjectMap.contains(theObject)) anIO = myResult2AISObjectMap[theObject]; return anIO; +#endif } //************************************************************** @@ -589,15 +609,20 @@ ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const //************************************************************** ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const { +#ifdef OPTIMIZE_PRS + ObjectPtr anObject = myResult2AISObjectMap.value(theIO); +#else ObjectPtr anObject; - foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) { - AISObjectPtr aAIS = myResult2AISObjectMap[anObj]; + ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin(); + for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) { + const AISObjectPtr& aAIS = aMapIter.value(); Handle(AIS_InteractiveObject) anAIS = aAIS->impl(); if (anAIS == theIO) - anObject = anObj; + anObject = aMapIter.key(); if (anObject.get()) break; } +#endif if (!anObject.get()) { std::shared_ptr anAISObj = AISObjectPtr(new GeomAPI_AISObject()); if (!theIO.IsNull()) { @@ -860,7 +885,11 @@ void XGUI_Displayer::removeFilters() //************************************************************** void XGUI_Displayer::showOnly(const QObjectPtrList& theList) { +#ifdef OPTIMIZE_PRS + QObjectPtrList aDispList = myResult2AISObjectMap.objects(); +#else QObjectPtrList aDispList = myResult2AISObjectMap.keys(); +#endif foreach(ObjectPtr aObj, aDispList) { if (!theList.contains(aObj)) erase(aObj, false); @@ -939,7 +968,11 @@ QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, //************************************************************** void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS) { +#ifdef OPTIMIZE_PRS + myResult2AISObjectMap.add(theObject, theAIS); +#else myResult2AISObjectMap[theObject] = theAIS; +#endif #ifdef DEBUG_DISPLAY std::ostringstream aPtrStr; @@ -954,8 +987,13 @@ void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS std::string XGUI_Displayer::getResult2AISObjectMapInfo() const { QStringList aContent; - foreach (ObjectPtr aObj, myResult2AISObjectMap.keys()) { +#ifdef OPTIMIZE_PRS + foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) { + AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj); +#else + foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) { AISObjectPtr aAISObj = myResult2AISObjectMap[aObj]; +#endif std::ostringstream aPtrStr; aPtrStr << "aObj = " << aObj.get() << ":"; aPtrStr << "anAIS = " << aAISObj.get() << ":"; @@ -978,7 +1016,7 @@ void XGUI_Displayer::getPresentations(const ObjectPtr& theObject, if (aAISObj.get() == NULL) { // if result is a result of a composite feature, it is visualized by visualization of // composite children, so we should get one of this presentations - ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast(aResult); + ResultBodyPtr aCompSolid = std::dynamic_pointer_cast(aResult); if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) { aAISObj = getAISObject(aCompSolid->subResult(0)); } @@ -1069,12 +1107,12 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th /// If count of calls setSelectec is even, the object stays in the previous state /// (selected, deselected) /// OCCT: to write about the problem that active owners method returns one owner several times - QList aSelectedIds; // Remember of selected address in order to avoid duplicates + QList aSelectedIds; // Remember of selected address in order to avoid duplicates for (; anOwnersIt.More(); anOwnersIt.Next()) { anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value()); - if (aSelectedIds.contains((long)anOwner.get())) + if (aSelectedIds.contains((size_t)anOwner.get())) continue; - aSelectedIds.append((long)anOwner.get()); + aSelectedIds.append((size_t)anOwner.get()); Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner); if (!BROwnr.IsNull() && BROwnr->HasShape()) { @@ -1131,3 +1169,46 @@ XGUI_SelectionActivate* XGUI_Displayer::selectionActivate() const { return myWorkshop->selectionActivate(); } + +//************************************************************** +GeomPlanePtr XGUI_Displayer::getScreenPlane() const +{ + GeomPlanePtr aResult; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Handle(V3d_Viewer) aViewer = aContext->CurrentViewer(); + Handle(V3d_View) aView; + for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) { + aView = aViewer->ActiveView(); + break; + } + if (!aView.IsNull()) { + double aEyeX, aEyeY, aEyeZ; + aView->Eye(aEyeX, aEyeY, aEyeZ); + + double aProjX, aProjY, aProjZ; + aView->Proj(aProjX, aProjY, aProjZ); + + GeomPointPtr aPnt = GeomPointPtr(new GeomAPI_Pnt(aEyeX, aEyeY, aEyeZ)); + GeomDirPtr aDir = GeomDirPtr(new GeomAPI_Dir(aProjX, aProjY, aProjZ)); + + aResult = GeomPlanePtr(new GeomAPI_Pln(aPnt, aDir)); + } + } + return aResult; +} + +double XGUI_Displayer::getViewScale() const +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Handle(V3d_Viewer) aViewer = aContext->CurrentViewer(); + Handle(V3d_View) aView; + for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) { + aView = aViewer->ActiveView(); + break; + } + return aView->Camera()->Scale(); + } + return 1; +}