X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Displayer.cpp;h=fd4fae9d704fb2c1ff00116a3f0ea9642a3c995d;hb=c6745a6b1ad00c0285fab5aeac2cb0d57afef5cc;hp=cb1ea4bcd9196b4837a77ed52fc75bf7b22082ca;hpb=86583cd5648c0db788809624bebc41a8a6a4b333;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index cb1ea4bcd..fd4fae9d7 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,15 +12,13 @@ // // 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" -#include "XGUI_CustomPrs.h" #include "XGUI_FacesPanel.h" #include "XGUI_Selection.h" #include "XGUI_SelectionActivate.h" @@ -37,18 +35,21 @@ #include #include #include -#include +#include +#include #include #include #include -#include #include #include +#include #include #include #include +#include +#include #include @@ -83,6 +84,7 @@ #include #include +#include #include @@ -93,8 +95,6 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; //#define DEBUG_FEATURE_REDISPLAY //#define DEBUG_SELECTION_FILTERS -//#define DEBUG_COMPOSILID_DISPLAY - //#define DEBUG_OCCT_SHAPE_SELECTION #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY @@ -121,9 +121,8 @@ QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QS //************************************************************** XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop), myNeedUpdate(false), - myViewerBlockedRecursiveCount(0), myIsFirstAISContextUse(true) + myViewerBlockedRecursiveCount(0), myContextId(0) { - myCustomPrs = std::shared_ptr(new XGUI_CustomPrs(theWorkshop)); } //************************************************************** @@ -142,83 +141,29 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) { bool aDisplayed = false; if (isVisible(theObject)) { -#ifdef DEBUG_COMPOSILID_DISPLAY - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(theObject); - if (aCompsolidResult.get()) { - for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) { - ResultPtr aSubResult = aCompsolidResult->subResult(i); - if (aSubResult.get()) - redisplay(aSubResult, false); - } - if (theUpdateViewer) - updateViewer(); - } - else -#endif aDisplayed = redisplay(theObject, theUpdateViewer); } else { AISObjectPtr anAIS; GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); bool isShading = false; if (aPrs.get() != NULL) { - anAIS = aPrs->getAISObject(anAIS); - if (anAIS.get()) { - // correct deviation coefficient for - /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl(); - if (!anAISPrs.IsNull()) { - Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); - if (!aShapePrs.IsNull()) { - TopoDS_Shape aShape = aShapePrs->Shape(); - if (!aShape.IsNull()) - //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes()); - } - }*/ + GeomScreenParamsPtr aScreen = std::dynamic_pointer_cast(theObject); + if (aScreen.get()) { + aScreen->setScreenPlane(getScreenPlane()); + aScreen->setViewScale(getViewScale()); } + anAIS = aPrs->getAISObject(anAIS); } else { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL) { -#ifdef DEBUG_COMPOSILID_DISPLAY - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(theObject); - if (aCompsolidResult.get()) { - for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) { - ResultPtr aSubResult = aCompsolidResult->subResult(i); - if (aSubResult.get()) - display(aSubResult, false); - } - if (theUpdateViewer) - updateViewer(); - } - else { -#endif - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr.get() != NULL) { - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - Handle(AIS_InteractiveObject) anAISPrs = - myWorkshop->module()->createPresentation(aResult); - if (anAISPrs.IsNull()) - anAISPrs = new ModuleBase_ResultPrs(aResult); - else { - Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); - if (!aShapePrs.IsNull()) - ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get()); - } - anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); - //anAIS->createShape(aShapePtr); - isShading = true; - } -#ifdef DEBUG_COMPOSILID_DISPLAY - } // close else -#endif - } + anAIS = myWorkshop->module()->createPresentation(theObject); + isShading = true; } - if (anAIS) + if (anAIS.get()) aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer); } return aDisplayed; } + //************************************************************** bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule) { @@ -252,7 +197,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, if (!anAISIO.IsNull()) { appendResultObject(theObject, theAIS); - bool isCustomized = customizeObject(theObject); + //bool isCustomized = customizeObject(theObject); int aDispMode = isShading? Shading : Wireframe; if (isShading) @@ -284,7 +229,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()) { @@ -315,27 +260,39 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) { bool aRedisplayed = false; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return aRedisplayed; + if (!isVisible(theObject)) return aRedisplayed; AISObjectPtr aAISObj = getAISObject(theObject); - Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); + Handle(AIS_InteractiveObject) aAISIO; 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(); } + else { + aAISIO = aAISObj->impl(); + } - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull() && !aAISIO.IsNull()) { + if (!aAISIO.IsNull()) { // Check that the visualized shape is the same and the redisplay is not necessary // Redisplay of AIS object leads to this object selection compute and the selection // in the browser is lost @@ -343,51 +300,56 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) // before and after the values modification. // Moreother, this check avoids customize and redisplay presentation if the presentable // parameter is changed. - bool isEqualShapes = false; - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL) { - Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); - if (!aShapePrs.IsNull()) { - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr.get()) { - const TopoDS_Shape& aOldShape = aShapePrs->Shape(); - if (!aOldShape.IsNull()) - isEqualShapes = aOldShape.IsEqual(aShapePtr->impl()); - } - } - } + //bool isEqualShapes = false; + //ResultPtr aResult = std::dynamic_pointer_cast(theObject); + //if (aResult.get() != NULL) { + // Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); + // if (!aShapePrs.IsNull()) { + // std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); + // if (aShapePtr.get()) { + // const TopoDS_Shape& aOldShape = aShapePrs->Shape(); + // if (!aOldShape.IsNull()) + // isEqualShapes = aOldShape.IsEqual(aShapePtr->impl()); + // } + // } + //} // Customization of presentation - bool isCustomized = customizeObject(theObject); + //bool isCustomized = customizeObject(theObject); #ifdef DEBUG_FEATURE_REDISPLAY - qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3"). - arg(!isEqualShapes || isCustomized).arg(isEqualShapes) - .arg(isCustomized).toStdString().c_str()); + qDebug(QString("Redisplay: %1, isEqualShapes=%2"). + arg(!isEqualShapes/* || isCustomized*/).arg(isEqualShapes) + .toStdString().c_str()); #endif - if (!isEqualShapes || isCustomized) { - /// if shapes are equal and presentation are customized, selection should be restored - bool aNeedToRestoreSelection = isEqualShapes && isCustomized; - if (aNeedToRestoreSelection) - myWorkshop->module()->storeSelection(); + //if (!isEqualShapes/* || isCustomized*/) { + // /// if shapes are equal and presentation are customized, selection should be restored + // bool aNeedToRestoreSelection = isEqualShapes/* && isCustomized*/; + // if (aNeedToRestoreSelection) + if (aAISObj.get() && myWorkshop->facesPanel()) + myWorkshop->facesPanel()->customizeObject(theObject, aAISObj); + + myWorkshop->module()->storeSelection(); #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY - myWorkshop->selector()->deselectPresentation(aAISIO); + myWorkshop->selector()->deselectPresentation(aAISIO); #endif + if (aContext->IsDisplayed(aAISIO)) aContext->Redisplay(aAISIO, false); - + else { + aContext->Display(aAISIO, false); + } #ifdef TINSPECTOR if (getCallBack()) getCallBack()->Redisplay(aAISIO); #endif - if (aNeedToRestoreSelection) - myWorkshop->module()->restoreSelection(); + //if (aNeedToRestoreSelection) + myWorkshop->module()->restoreSelection(); - aRedisplayed = true; - #ifdef DEBUG_FEATURE_REDISPLAY - qDebug(" Redisplay happens"); - #endif - if (theUpdateViewer) - updateViewer(); - } + aRedisplayed = true; + #ifdef DEBUG_FEATURE_REDISPLAY + qDebug(" Redisplay happens"); + #endif + if (theUpdateViewer) + updateViewer(); } return aRedisplayed; } @@ -398,11 +360,16 @@ void XGUI_Displayer::redisplayObjects() // redisplay objects visualized in the viewer static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects(); + QObjectPtrList aDisplayed = displayedObjects(); QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end(); for (; anIt != aLast; anIt++) { aECreator->sendUpdated(*anIt, EVENT_DISP); } + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + if (aViewer->isColorScaleVisible()) { + aViewer->setupColorScale(); + aViewer->setColorScaleShown(true); + } Events_Loop::loop()->flush(EVENT_DISP); } @@ -434,12 +401,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; @@ -502,7 +469,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 @@ -544,8 +511,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()) { @@ -572,10 +544,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 } //************************************************************** @@ -588,15 +564,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()) { @@ -627,19 +608,14 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled) return aWasEnabled; } -//************************************************************** -bool XGUI_Displayer::isUpdateEnabled() const -{ - return myViewerBlockedRecursiveCount == 0; -} - //************************************************************** void XGUI_Displayer::updateViewer() const { Handle(AIS_InteractiveContext) aContext = AISContext(); #ifdef DEBUG_VIEWER_BLOCKED_COUNT - std::cout << "updateViewer: " << (myViewerBlockedRecursiveCount == 0 ? " done" : " later") << std::endl; + std::cout << "updateViewer: " << (myViewerBlockedRecursiveCount == 0 ? " done" : " later") + << std::endl; #endif if (!aContext.IsNull() && isUpdateEnabled()) { @@ -654,17 +630,63 @@ void XGUI_Displayer::updateViewer() const Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (!aContext.IsNull() && myIsFirstAISContextUse/*&& !aContext->HasOpenedContext()*/) { - XGUI_Displayer* aDisplayer = (XGUI_Displayer*)this; - aDisplayer->myIsFirstAISContextUse = false; + if (!aContext.IsNull() && (myContextId != aContext.get())) { + myContextId = aContext.get(); if (!myWorkshop->selectionActivate()->isTrihedronActive()) selectionActivate()->deactivateTrihedron(true); aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0); aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0); + + //Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron(); + //aTrihedron->getHighlightPointAspect()->SetScale(2.0); + //aTrihedron->getHighlightPointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR); + + // Commented out according to discussion in bug #2825 + //ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle(); + //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; } +//************************************************************** +void XGUI_Displayer::setSelectionColor(const std::vector& theColor) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Quantity_Color aQColor(theColor[0] / 255., + theColor[1] / 255., + theColor[2] / 255., Quantity_TOC_RGB); + aContext->SelectionStyle()->SetColor(aQColor); + aContext->SelectionStyle()->PointAspect()->SetColor(aQColor); + aContext->SelectionStyle()->LineAspect()->SetColor(aQColor); + aContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor(aQColor); + } +} + + +//************************************************************** +std::vector XGUI_Displayer::selectionColor() const +{ + std::vector aColor; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aContext.IsNull()) { + Quantity_Color aQColor = aContext->SelectionStyle()->Color(); + aColor.push_back((int)(aQColor.Red() * 255)); + aColor.push_back((int)(aQColor.Green() * 255)); + aColor.push_back((int)(aQColor.Blue() * 255)); + } + return aColor; +} + + //************************************************************** Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() { @@ -857,7 +879,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); @@ -884,37 +910,37 @@ bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const } //************************************************************** -bool XGUI_Displayer::customizeObject(ObjectPtr theObject) -{ - AISObjectPtr anAISObj = getAISObject(theObject); - // correct the result's color it it has the attribute - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - - // Customization of presentation - GeomCustomPrsPtr aCustomPrs; - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() != NULL) { - GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); - if (aCustPrs.get() != NULL) - aCustomPrs = aCustPrs; - } - if (aCustomPrs.get() == NULL) { - GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); - // we ignore presentable not customized objects - if (aPrs.get() == NULL) - aCustomPrs = myCustomPrs; - } - bool isCustomized = aCustomPrs.get() && - aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); - isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) - || isCustomized; - - // update presentation state if faces panel is active - if (anAISObj.get() && myWorkshop->facesPanel()) - isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized; - - return isCustomized; -} +//bool XGUI_Displayer::customizeObject(ObjectPtr theObject) +//{ +// AISObjectPtr anAISObj = getAISObject(theObject); +// // correct the result's color it it has the attribute +// ResultPtr aResult = std::dynamic_pointer_cast(theObject); +// +// // Customization of presentation +// GeomCustomPrsPtr aCustomPrs; +// FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); +// if (aFeature.get() != NULL) { +// GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); +// if (aCustPrs.get() != NULL) +// aCustomPrs = aCustPrs; +// } +// if (aCustomPrs.get() == NULL) { +// GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); +// // we ignore presentable not customized objects +// if (aPrs.get() == NULL) +// aCustomPrs = myCustomPrs; +// } +// bool isCustomized = aCustomPrs.get() && +// aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); +// isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) +// || isCustomized; +// +// // update presentation state if faces panel is active +// if (anAISObj.get() && myWorkshop->facesPanel()) +// isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized; +// +// return isCustomized; +//} //************************************************************** QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, @@ -936,7 +962,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; @@ -951,8 +981,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() << ":"; @@ -975,7 +1010,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)); } @@ -1044,8 +1079,6 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const if (getCallBack()) getCallBack()->Remove(aTrihedron); #endif } - - updateViewer(); } //************************************************************** @@ -1066,12 +1099,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()) { @@ -1085,17 +1118,21 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th ::Iterator aShapeIt(theShapesToBeSelected); for (; aShapeIt.More(); aShapeIt.Next()) { const TopoDS_Shape& aParameterShape = aShapeIt.Key(); - // isSame should be used here as it does not check orientation of shapes - // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is - // different for Edges shapes in model shape and owner even if this is the same shape - if (aParameterShape.IsSame(aShape)) { + // In case of compound we cannot rely on simple comparison method. + // If the compound is generated by Group feature then this compound is alwais new. + // So, we have to compare content of these compounds + + // isSame should be used here as it does not check orientation of shapes + // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is + // different for Edges shapes in model shape and owner even if this is the same shape + if (ModuleBase_Tools::isSameShape(aParameterShape, aShape)) { Handle(AIS_InteractiveObject) anOwnerPresentation = - Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); + Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); NCollection_Map aPresentations = - theShapesToBeSelected.Find(aParameterShape); + theShapesToBeSelected.Find(aParameterShape); if (aPresentations.Contains(anOwnerPresentation)) { theContext->AddOrRemoveSelected(anOwner, Standard_False); - anOwner->SetSelected (Standard_True); + anOwner->SetSelected(Standard_True); // collect selected presentations to do not select them if compsolid is selected if (!aSelectedPresentations.Contains(anOwnerPresentation)) aSelectedPresentations.Add(anOwnerPresentation); @@ -1128,3 +1165,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; +}