X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Displayer.cpp;h=e83f1f14328bbe221d9e655f12e29f123d3bd95c;hb=689bd6ca04a18da1645152760ba12ca7c2de146d;hp=9df154d64edcc7f1e15b834a1cddb9c42f02552f;hpb=b34e67df02366fafb9d8ecc149f476f30e91cdd0;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 9df154d64..e83f1f143 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "XGUI_Displayer.h" @@ -37,7 +36,8 @@ #include #include #include -#include +#include +#include #include #include @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include @@ -84,6 +86,7 @@ #include #include +#include #include @@ -163,8 +166,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 +183,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) { @@ -324,12 +332,18 @@ 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); return aRedisplayed; } if (aAIS_Obj != aAISObj) { + erase(theObject, theUpdateViewer); appendResultObject(theObject, aAIS_Obj); } aAISIO = aAIS_Obj->impl(); @@ -373,7 +387,10 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY myWorkshop->selector()->deselectPresentation(aAISIO); #endif - aContext->Redisplay(aAISIO, false); + if (aContext->IsDisplayed(aAISIO)) + aContext->Redisplay(aAISIO, false); + else + aContext->Display(aAISIO, false); #ifdef TINSPECTOR if (getCallBack()) getCallBack()->Redisplay(aAISIO); @@ -435,12 +452,12 @@ 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++) { + int aNumberOfSubs = aCompsolidResult->numberOfSubs(); + bool anAllSubsVisible = aNumberOfSubs > 0; + for(int i = 0; i < aNumberOfSubs && anAllSubsVisible; i++) { anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i)); } aVisible = anAllSubsVisible; @@ -545,8 +562,13 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) bool aErased = false; Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { - foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) { +#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,7 +595,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 } //************************************************************** @@ -586,7 +615,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; + 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 = aMapIter.key(); + if (anObject.get()) + break; + } +#endif if (!anObject.get()) { std::shared_ptr anAISObj = AISObjectPtr(new GeomAPI_AISObject()); if (!theIO.IsNull()) { @@ -652,7 +694,18 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const selectionActivate()->deactivateTrihedron(true); aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0); aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0); + ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle(); + // Commented out according to discussion in bug #2825 + //Handle(Prs3d_Drawer) aSelStyle = aContext->SelectionStyle(); + //double aDeflection = + // QString(ModelAPI_ResultConstruction::DEFAULT_DEFLECTION().c_str()).toDouble(); + //try { + // aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + //} catch (...) {} + + //ModuleBase_IViewer::DefaultHighlightDrawer->SetDeviationCoefficient(aDeflection); + //aSelStyle->SetDeviationCoefficient(aDeflection); } return aContext; } @@ -849,7 +902,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); @@ -928,7 +985,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; @@ -943,8 +1004,13 @@ void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS std::string XGUI_Displayer::getResult2AISObjectMapInfo() const { QStringList aContent; - foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) { +#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() << ":"; @@ -967,7 +1033,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)); } @@ -1058,12 +1124,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()) { @@ -1120,3 +1186,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; +}