X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Displayer.cpp;h=7e690a0f1d1acf6a414c13d839b025026c5ce885;hb=814a346c0ef4b2625779c5ef96be5ff87980acbb;hp=30f94ef70929ad744c19856f8bc2b01c9a579453;hpb=5fc0009dcf8207a684f84f64c746ad421346a72f;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 30f94ef70..7e690a0f1 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -19,7 +19,6 @@ #include "XGUI_Displayer.h" -#include "XGUI_CustomPrs.h" #include "XGUI_FacesPanel.h" #include "XGUI_Selection.h" #include "XGUI_SelectionActivate.h" @@ -38,12 +37,10 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -80,6 +77,7 @@ #include #include +#include #ifdef TINSPECTOR #include @@ -108,7 +106,11 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList) { // Get from null point - theAIS->DisplayedObjects(theList, true); +#if OCC_VERSION_HEX < 0x070400 + theAIS->DisplayedObjects(theList, true); +#else + theAIS->DisplayedObjects(theList); +#endif } QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", ")) @@ -124,9 +126,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)); } //************************************************************** @@ -158,56 +159,16 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) } anAIS = aPrs->getAISObject(anAIS); } else { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL) { - anAIS = createPresentation(aResult); - isShading = true; - } - else { - FieldStepPtr aStep = - std::dynamic_pointer_cast(theObject); - if (aStep) { - GeomShapePtr aShapePtr = aStep->field()->shape(); - if (aShapePtr.get() != NULL) { - Handle(AIS_InteractiveObject) anAISPrs = new ModuleBase_ResultPrs(aStep); - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); - isShading = true; - } - } - } + anAIS = myWorkshop->module()->createPresentation(theObject); + isShading = true; } - if (anAIS) + if (anAIS.get()) aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer); } return aDisplayed; } -//************************************************************** -AISObjectPtr XGUI_Displayer::createPresentation(const ResultPtr& theResult) const -{ - AISObjectPtr anAIS; - if (theResult.get() != NULL) { - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); - if (aShapePtr.get() != NULL) { - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - Handle(AIS_InteractiveObject) anAISPrs = - myWorkshop->module()->createPresentation(theResult); - if (anAISPrs.IsNull()) - anAISPrs = new ModuleBase_ResultPrs(theResult); - 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)); - } - } - return anAIS; -} - - //************************************************************** bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule) { @@ -241,11 +202,9 @@ 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) - anAISIO->Attributes()->SetFaceBoundaryDraw( Standard_True ); anAISIO->SetDisplayMode(aDispMode); aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed); #ifdef TINSPECTOR @@ -304,11 +263,15 @@ 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) { @@ -328,64 +291,60 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) } aAISIO = aAIS_Obj->impl(); } + else { + aAISIO = aAISObj->impl(); + } - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull() && !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 - // this check is not necessary anymore because the selection store/restore is realized - // before and after the values modification. - // Moreother, this check avoids customize and redisplay presentation if the presentable - // parameter is changed. - bool isEqualShapes = false; + if (!aAISIO.IsNull()) { 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()); - } + if (aResult.get()) { + // Set color + std::vector aColor; + ModelAPI_Tools::getColor(aResult, aColor); + if (aColor.size() > 0) { + Quantity_Color + aCol(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB); + aAISIO->SetColor(aCol); } + // Set deflection + double aDeflection = ModelAPI_Tools::getDeflection(aResult); + if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection())) + aAISObj->setDeflection(aDeflection); + + // Set transparency + double aTransparency = ModelAPI_Tools::getTransparency(aResult); + if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency())) + aAISObj->setTransparency(aTransparency); + + // Set Iso-Lines + Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO); + if (!aResPrs.IsNull()) + aResPrs->updateIsoLines(); } - // Customization of presentation - 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()); - #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(); + 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); + 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; } @@ -396,11 +355,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); } @@ -614,7 +578,8 @@ ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) if (!theIO.IsNull()) { anAISObj->setImpl(new Handle(AIS_InteractiveObject)(theIO)); } - anObject = myWorkshop->module()->findPresentedObject(anAISObj); + if (myWorkshop->module()) + anObject = myWorkshop->module()->findPresentedObject(anAISObj); } return anObject; } @@ -639,12 +604,6 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled) return aWasEnabled; } -//************************************************************** -bool XGUI_Displayer::isUpdateEnabled() const -{ - return myViewerBlockedRecursiveCount == 0; -} - //************************************************************** void XGUI_Displayer::updateViewer() const { @@ -667,16 +626,20 @@ 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); + // Do not modify default drawer. The same is done in ModuleBase_ResultPrs + //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); - ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle(); // 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(); @@ -690,6 +653,37 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const 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() { @@ -913,37 +907,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, @@ -1082,8 +1076,6 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const if (getCallBack()) getCallBack()->Remove(aTrihedron); #endif } - - updateViewer(); } //************************************************************** @@ -1123,17 +1115,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);