From: vsv Date: Mon, 22 Dec 2014 10:04:24 +0000 (+0300) Subject: Operations without closing of selection context X-Git-Tag: V_0.7.0_rc1~56^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa02df7ff3d57ad43a857d14bca2e68ea127781c;p=modules%2Fshaper.git Operations without closing of selection context --- diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 454d0e1fc..eeb38baaa 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -110,7 +110,7 @@ void PartSet_WidgetSketchLabel::onPlaneSelected() // Clear selection mode and define sketching mode XGUI_Displayer* aDisp = myWorkshop->displayer(); aDisp->removeSelectionFilter(myFaceFilter); - aDisp->closeLocalContexts(); + //aDisp->closeLocalContexts(); emit planeSelected(plane()); setSketchingMode(); @@ -141,8 +141,8 @@ void PartSet_WidgetSketchLabel::activate() showPreviewPlanes(); XGUI_Displayer* aDisp = myWorkshop->displayer(); - aDisp->openLocalContext(); - aDisp->activateObjects(QIntList()); + //aDisp->openLocalContext(); + //aDisp->activateObjects(QIntList()); if (myFaceFilter.IsNull()) myFaceFilter = new StdSelect_FaceFilter(StdSelect_Plane); aDisp->addSelectionFilter(myFaceFilter); @@ -165,7 +165,7 @@ void PartSet_WidgetSketchLabel::deactivate() XGUI_Displayer* aDisp = myWorkshop->displayer(); aDisp->removeSelectionFilter(myFaceFilter); //aDisp->removeSelectionFilter(mySketchFilter); - aDisp->closeLocalContexts(); + //aDisp->closeLocalContexts(); erasePreviewPlanes(); } @@ -275,21 +275,12 @@ void PartSet_WidgetSketchLabel::setSketchingMode() qDebug("### Set sketching mode"); XGUI_Displayer* aDisp = myWorkshop->displayer(); - QIntList aModes; // Clear standard selection modes if they are defined - aDisp->activateObjects(aModes); - aDisp->openLocalContext(); - - // Set filter - std::shared_ptr aPlane = plane(); - double aA, aB, aC, aD; - aPlane->coefficients(aA, aB, aC, aD); - gp_Pln aPln(aA, aB, aC, aD); - // No selection of external objects - //mySketchFilter = new ModuleBase_ShapeInPlaneFilter(aPln); - //aDisp->addSelectionFilter(mySketchFilter); + //aDisp->activateObjects(aModes); + //aDisp->openLocalContext(); // Get default selection modes + QIntList aModes; aModes.append(AIS_DSM_Text); aModes.append(AIS_DSM_Line); aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dfed75b1f..b0a119a70 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -32,12 +32,15 @@ #include #include +#include +#include + #include const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) - : myUseExternalObjects(false), myWorkshop(theWorkshop) + : myWorkshop(theWorkshop) { } @@ -88,26 +91,31 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull()) { myResult2AISObjectMap[theObject] = theAIS; + + closeLocalContexts(false); aContext->Display(anAISIO, false); aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false); - + // Customization of presentation FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (aFeature.get() != NULL) { GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); if (aCustPrs.get() != NULL) aCustPrs->customisePresentation(theAIS); } - if (aContext->HasOpenedContext()) { - if (myUseExternalObjects) { - if (myActiveSelectionModes.size() == 0) - aContext->Activate(anAISIO); - else { - foreach(int aMode, myActiveSelectionModes) { - aContext->Activate(anAISIO, aMode); - } - } - } - } + openLocalContext(); + aContext->Load(anAISIO, -1, true); + activate(theObject); + //if (aContext->HasOpenedContext()) { + //if (myUseExternalObjects) { + //if (myActiveSelectionModes.size() == 0) + // aContext->Activate(anAISIO); + //else { + // foreach(int aMode, myActiveSelectionModes) { + // aContext->Activate(anAISIO, aMode); + // } + //} + //} + //} } if (isUpdateViewer) updateViewer(); @@ -175,8 +183,7 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject) void XGUI_Displayer::activate(ObjectPtr theFeature) { - QIntList aModes; - activate(theFeature, aModes); + activate(theFeature, myActiveSelectionModes); } void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes) @@ -188,10 +195,11 @@ void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes) AISObjectPtr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (aContext->HasOpenedContext()) { - aContext->Load(anAIS, -1, true); - } aContext->Deactivate(anAIS); + //if (aContext->HasOpenedContext()) { + // aContext->Load(anAIS, -1, true); + //} + // In order to clear active modes list if (theModes.size() > 0) { foreach(int aMode, theModes) { aContext->Activate(anAIS, aMode); @@ -201,6 +209,78 @@ void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes) } } +void XGUI_Displayer::activateObjects(const QIntList& theModes) +{ + // In order to avoid doblications of selection modes + myActiveSelectionModes.clear(); + foreach (int aMode, theModes) { + if (!myActiveSelectionModes.contains(aMode)) + myActiveSelectionModes.append(aMode); + } + Handle(AIS_InteractiveContext) aContext = AISContext(); + // Open local context if there is no one + if (!aContext->HasOpenedContext()) + return; + + //aContext->UseDisplayedObjects(); + //myUseExternalObjects = true; + + AIS_ListOfInteractive aPrsList; + aContext->DisplayedObjects(aPrsList, true); + //Deactivate trihedron which can be activated in local selector + + Handle(AIS_Trihedron) aTrihedron; + AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); + Handle(AIS_InteractiveObject) anAISIO; + for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ + anAISIO = aLIt.Value(); + aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO); + if (!aTrihedron.IsNull()) { + aContext->Deactivate(aTrihedron); + } else { + //aContext->Load(anAISIO, -1, true); + // In order to clear active modes list + aContext->Deactivate(anAISIO); + if (myActiveSelectionModes.size() == 0) + aContext->Activate(anAISIO); + else { + foreach(int aMode, myActiveSelectionModes) { + aContext->Activate(anAISIO, aMode); + } + } + } + } +} + + +void XGUI_Displayer::deactivateObjects() +{ + myActiveSelectionModes.clear(); + Handle(AIS_InteractiveContext) aContext = AISContext(); + // Open local context if there is no one + if (!aContext->HasOpenedContext()) + return; + + aContext->NotUseDisplayedObjects(); + AIS_ListOfInteractive aPrsList; + aContext->DisplayedObjects(aPrsList); + + AIS_ListIteratorOfListOfInteractive aLIt; + Handle(AIS_Trihedron) aTrihedron; + Handle(AIS_InteractiveObject) anAISIO; + for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ + anAISIO = aLIt.Value(); + aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO); + if (!aTrihedron.IsNull()) { + aContext->Deactivate(aTrihedron); + } else { + //aContext->Load(anAISIO, -1, true); + aContext->Deactivate(anAISIO); + //aContext->Activate(anAISIO); + } + } +} + bool XGUI_Displayer::isActive(ObjectPtr theObject) const { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -312,32 +392,32 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer) updateViewer(); } -void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return; - - QObjectPtrList aRemoved; - foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) { - if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) { - AISObjectPtr anObj = myResult2AISObjectMap[aFeature]; - if (!anObj) - continue; - Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (!anAIS.IsNull()) { - aContext->Remove(anAIS, false); - aRemoved.append(aFeature); - } - } - } - foreach(ObjectPtr aObj, aRemoved) { - myResult2AISObjectMap.remove(aObj); - } - - if (isUpdateViewer) - updateViewer(); -} +//void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer) +//{ +// Handle(AIS_InteractiveContext) aContext = AISContext(); +// if (aContext.IsNull()) +// return; +// +// QObjectPtrList aRemoved; +// foreach (ObjectPtr aFeature, myResult2AISObjectMap.keys()) { +// if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) { +// AISObjectPtr anObj = myResult2AISObjectMap[aFeature]; +// if (!anObj) +// continue; +// Handle(AIS_InteractiveObject) anAIS = anObj->impl(); +// if (!anAIS.IsNull()) { +// aContext->Remove(anAIS, false); +// aRemoved.append(aFeature); +// } +// } +// } +// foreach(ObjectPtr aObj, aRemoved) { +// myResult2AISObjectMap.remove(aObj); +// } +// +// if (isUpdateViewer) +// updateViewer(); +//} void XGUI_Displayer::openLocalContext() { @@ -359,14 +439,11 @@ void XGUI_Displayer::openLocalContext() // in the closeLocalContex, which restore the global context filters aContext->RemoveFilters(); - //aContext->ClearCurrents(); + aContext->ClearCurrents(); aContext->OpenLocalContext(); + //aContext->NotUseDisplayedObjects(); - qDebug("### Open Local context"); - - aContext->NotUseDisplayedObjects(); - - myUseExternalObjects = false; + //myUseExternalObjects = false; myActiveSelectionModes.clear(); SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); @@ -395,11 +472,9 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) SelectMgr_ListOfFilter aFilters; aFilters.Assign(aContext->Filters()); - //aContext->ClearSelected(); + aContext->ClearSelected(); aContext->CloseAllContexts(false); - qDebug("### Close Local context"); - // Redisplay all object if they were displayed in localContext Handle(AIS_InteractiveObject) aAISIO; foreach (AISObjectPtr aAIS, myResult2AISObjectMap) { @@ -419,7 +494,7 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) if (isUpdateViewer) updateViewer(); - myUseExternalObjects = false; + //myUseExternalObjects = false; myActiveSelectionModes.clear(); // Restore selection @@ -466,7 +541,11 @@ void XGUI_Displayer::updateViewer() Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const { - return myWorkshop->viewer()->AISContext(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) { + aContext->OpenLocalContext(); + } + return aContext; } Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() @@ -486,8 +565,7 @@ void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate) if (!anAISIO.IsNull()) { aContext->Display(anAISIO, isUpdate); if (aContext->HasOpenedContext()) { - if (myUseExternalObjects) { - aContext->Deactivate(anAISIO); + //if (myUseExternalObjects) { if (myActiveSelectionModes.size() == 0) aContext->Activate(anAISIO); else { @@ -495,7 +573,7 @@ void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate) aContext->Activate(anAISIO, aMode); } } - } + //} } } } @@ -509,52 +587,6 @@ void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate) } } -void XGUI_Displayer::activateObjects(const QIntList& theModes) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - // Open local context if there is no one - if (!aContext->HasOpenedContext()) - return; - - aContext->UseDisplayedObjects(); - myUseExternalObjects = true; - myActiveSelectionModes = theModes; - - //Deactivate trihedron which can be activated in local selector - AIS_ListOfInteractive aPrsList; - aContext->DisplayedObjects(aPrsList, true); - - AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); - Handle(AIS_InteractiveObject) anAISIO; - Handle(AIS_Trihedron) aTrihedron; - for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ - anAISIO = aLIt.Value(); - aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO); - aContext->Deactivate(anAISIO); - if (aTrihedron.IsNull()) { - aContext->Load(anAISIO, -1, true); - if (theModes.size() == 0) - aContext->Activate(anAISIO); - else { - foreach(int aMode, theModes) { - aContext->Activate(anAISIO, aMode); - } - } - } - } -} - - -void XGUI_Displayer::deactivateObjects() -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - // Open local context if there is no one - if (!aContext->HasOpenedContext()) - return; - - aContext->NotUseDisplayedObjects(); -} - void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 7fbbd814d..2cc3bd4ef 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -88,10 +88,7 @@ class XGUI_EXPORT XGUI_Displayer /// Erase AIS interactive objects, which has an empty feature in the internal map /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void eraseDeletedResults(const bool isUpdateViewer = true); - - /// Opens local context. Does nothing if it is already opened. - void openLocalContext(); + //void eraseDeletedResults(const bool isUpdateViewer = true); /// Deactivates selection of sub-shapes /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly @@ -182,6 +179,9 @@ class XGUI_EXPORT XGUI_Displayer */ void redisplay(ObjectPtr theObject, bool isUpdateViewer = true); + /// Opens local context. Does nothing if it is already opened. + void openLocalContext(); + protected: XGUI_Workshop* myWorkshop; @@ -191,7 +191,7 @@ class XGUI_EXPORT XGUI_Displayer ResultToAISMap myResult2AISObjectMap; // A flag of initialization of external objects selection - bool myUseExternalObjects; + //bool myUseExternalObjects; // Selection modes installed for external objects in local context QIntList myActiveSelectionModes; }; diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index d1b2d8d2b..970cb045c 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -57,8 +57,8 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) { XGUI_Displayer* aDisp = myWorkshop->displayer(); // Close context if it was opened in order to clear stsndard selection modes - aDisp->closeLocalContexts(false); - aDisp->openLocalContext(); + //aDisp->closeLocalContexts(false); + //aDisp->openLocalContext(); // Convert shape types to selection types QIntList aModes; foreach(int aType, theTypes) { @@ -74,7 +74,7 @@ void XGUI_ModuleConnector::deactivateSubShapesSelection() XGUI_Displayer* aDisp = myWorkshop->displayer(); // The document limitation selection has to be only during operation //aDisp->removeSelectionFilter(myDocumentShapeFilter); - aDisp->closeLocalContexts(false); + //aDisp->closeLocalContexts(false); } AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const