From 771603e0ec2357cfac6a2f11bb180d0b75c82521 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 16 Oct 2014 18:00:34 +0400 Subject: [PATCH] Redesign of selection process --- src/PartSet/PartSet_Listener.cpp | 34 ++- src/PartSet/PartSet_Module.cpp | 205 +++++++++--------- src/PartSet/PartSet_Module.h | 21 +- .../PartSet_OperationFeatureCreate.cpp | 8 - src/PartSet/PartSet_OperationFeatureCreate.h | 5 - src/PartSet/PartSet_OperationSketch.cpp | 13 -- src/PartSet/PartSet_OperationSketch.h | 5 - src/PartSet/PartSet_OperationSketchBase.cpp | 14 -- src/PartSet/PartSet_OperationSketchBase.h | 8 - src/XGUI/XGUI_Displayer.cpp | 73 ++++++- src/XGUI/XGUI_Displayer.h | 20 +- src/XGUI/XGUI_ModuleConnector.cpp | 15 +- src/XGUI/XGUI_Workshop.cpp | 3 +- 13 files changed, 217 insertions(+), 207 deletions(-) diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index 989b66880..24c78b60f 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,7 @@ #include #include +#include #ifdef _DEBUG #include @@ -57,22 +59,36 @@ void PartSet_Listener::processEvent(const boost::shared_ptr& the std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { ObjectPtr aObj = (*anIt); - aDisplayer->deactivate(aObj); - boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(aObj); - if (aFeature && (aFeature->getKind() == "Sketch")) // Activate sketcher for planes selection - myModule->activateFeature(aFeature, false); // If current operation is Sketch then there is no active sketching operation - // and possible the object was created by Redo operatgion - else if (aSketchOp) { + // and possible the object was created by Redo operation + if (aSketchOp) { XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer(); // Very possible it is not displayed aDisplayer->display(aObj, false); - std::list aModes = aSketchOp->getSelectionModes(aObj); - myModule->activateInLocalContext(aObj, aModes, false); } } + } else if (aType == EVENT_OBJECT_TO_REDISPLAY) { + PartSet_OperationFeatureCreate* aCreationOp = + dynamic_cast + (myModule->xWorkshop()->operationMgr()->currentOperation()); + if (aCreationOp) { + // Deactivate currently creating objects for selection + XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer(); + FeaturePtr aFeature = aCreationOp->feature(); + const std::list& aResults = aFeature->results(); + boost::shared_ptr aUpdMsg = + boost::dynamic_pointer_cast(theMessage); + std::set aFeatures = aUpdMsg->objects(); + std::set::const_iterator aObjIt, aNoObj = aFeatures.cend(); + std::list::const_iterator anIt = aResults.begin(), aLast = aResults.end(); + for (; anIt != aLast; anIt++) { + aObjIt = aFeatures.find(*anIt); + if (aObjIt != aNoObj) { + aDisplayer->deactivate(*aObjIt); + } + } + } } else if (aType == EVENT_OBJECT_DELETED) { boost::shared_ptr aDelMsg = boost::dynamic_pointer_cast(theMessage); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index fcfc9e903..e2de98ee0 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -46,8 +46,8 @@ #include #include #include +#include -#include #include #include @@ -143,20 +143,32 @@ void PartSet_Module::onFeatureTriggered() void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) { + XGUI_Workshop* aXWshp = xWorkshop(); + XGUI_Displayer* aDisplayer = aXWshp->displayer(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); if (aPreviewOp) { - XGUI_Workshop* aXWshp = xWorkshop(); XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection); - XGUI_Displayer* aDisplayer = aXWshp->displayer(); - aDisplayer->openLocalContext(); - aDisplayer->deactivateObjectsOutOfContext(); + //aDisplayer->deactivateObjectsOutOfContext(); + PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); + if (aSketchOp) { + if (aSketchOp->isEditOperation()) { + aDisplayer->openLocalContext(); + //setSketchingMode(); + } else { + aDisplayer->openLocalContext(); + aDisplayer->activateObjectsOutOfContext(); + myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane); + aDisplayer->addSelectionFilter(myPlaneFilter); + QIntList aModes = sketchSelectionModes(aPreviewOp->feature()); + aDisplayer->setSelectionModes(aModes); + } + } } else { - Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext(); //TODO (VSV): We have to open Local context because at neutral point filters don't work (bug 25340) - aAIS->AddFilter(myDocumentShapeFilter); + aDisplayer->addSelectionFilter(myDocumentShapeFilter); } } @@ -165,22 +177,44 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) if (!theOperation) return; XGUI_Workshop* aXWshp = xWorkshop(); + XGUI_Displayer* aDisplayer = aXWshp->displayer(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); if (aPreviewOp) { XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); + + PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); + if (aSketchOp) { + aDisplayer->closeLocalContexts(); + } else { + PartSet_OperationFeatureCreate* aCreationOp = + dynamic_cast(aPreviewOp); + if (aCreationOp) { + // Activate just created object for selection + FeaturePtr aFeature = aCreationOp->feature(); + QIntList aModes = sketchSelectionModes(aFeature); + const std::list& aResults = aFeature->results(); + std::list::const_iterator anIt, aLast = aResults.end(); + for (anIt = aResults.begin(); anIt != aLast; anIt++) { + aDisplayer->activate(*anIt, aModes); + } + aDisplayer->activate(aFeature, aModes); + } + } } else { // Activate results of current feature for selection - FeaturePtr aFeature = theOperation->feature(); - XGUI_Displayer* aDisplayer = aXWshp->displayer(); - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - aDisplayer->activate(*aIt); - } - - Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext(); - aAIS->RemoveFilter(myDocumentShapeFilter); + //FeaturePtr aFeature = theOperation->feature(); + //XGUI_Displayer* aDisplayer = aXWshp->displayer(); + //std::list aResults = aFeature->results(); + //std::list::const_iterator aIt; + //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + // aDisplayer->activate(*aIt); + //} + + // The document limitation selection has to be only during operation + aDisplayer->removeSelectionFilter(myDocumentShapeFilter); } + // Clear selection done during operation + aDisplayer->clearSelected(); } void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) @@ -258,11 +292,9 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) { - //erasePlanes(); myWorkshop->viewer()->setViewProjection(theX, theY, theZ); - xWorkshop()->actionsMgr()->update(); - - //PartSet_TestOCC::testSelection(myWorkshop); + xWorkshop()->actionsMgr()->update(); + setSketchingMode(); } void PartSet_Module::onFitAllView() @@ -290,16 +322,16 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); aSketchOp->initSelection(aSelected, aHighlighted); - } else if (aFeature) { - anOperation->setFeature(aFeature); - //Deactivate result of current feature in order to avoid its selection - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - aDisplayer->deactivate(*aIt); - } - } + } //else if (aFeature) { + //anOperation->setFeature(aFeature); + ////Deactivate result of current feature in order to avoid its selection + //XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); + //std::list aResults = aFeature->results(); + //std::list::const_iterator aIt; + //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + // aDisplayer->deactivate(*aIt); + //} + //} sendOperation(anOperation); xWorkshop()->actionsMgr()->updateCheckState(); } @@ -313,12 +345,11 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) void PartSet_Module::onStopSelection(const QList& theFeatures, const bool isStop) { XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - if (!isStop) { - foreach(ObjectPtr aObject, theFeatures) - { - activateFeature(aObject, false); - } - } + //if (!isStop) { + // foreach(ObjectPtr aObject, theFeatures) { + // activateFeature(aObject); + // } + //} aDisplayer->stopSelection(theFeatures, isStop, false); ModuleBase_IViewer* aViewer = myWorkshop->viewer(); @@ -334,11 +365,17 @@ void PartSet_Module::onSetSelection(const QList& theFeatures) aDisplayer->updateViewer(); } -void PartSet_Module::onCloseLocalContext() +void PartSet_Module::setSketchingMode() { XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - aDisplayer->deactivateObjectsOutOfContext(); - aDisplayer->closeLocalContexts(); + if (!myPlaneFilter.IsNull()) { + aDisplayer->removeSelectionFilter(myPlaneFilter); + myPlaneFilter.Nullify(); + } + QIntList aModes; + //aModes << TopAbs_VERTEX << TopAbs_EDGE; + //aModes << AIS_DSM_Text << AIS_DSM_Line; + aDisplayer->setSelectionModes(aModes); } void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode) @@ -349,21 +386,19 @@ void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode) if (aPrevOp) { std::list aList = aPrevOp->subFeatures(); XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - std::list aModes = aPrevOp->getSelectionModes(aPrevOp->feature()); + QIntList aModes = sketchSelectionModes(aPrevOp->feature()); std::list::iterator aSFIt; for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) { std::list aResults = (*aSFIt)->results(); std::list::iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - if (isDisplay) - activateInLocalContext((*aIt), aModes, false); - else + if (!isDisplay) aDisplayer->erase((*aIt), false); } if (!isDisplay) aDisplayer->erase((*aSFIt), false); } - aDisplayer->deactivateObjectsOutOfContext(); + //aDisplayer->deactivateObjectsOutOfContext(); } if (isDisplay) ModelAPI_EventCreator::get()->sendUpdated( @@ -424,8 +459,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI connect(aPreviewOp, SIGNAL(setSelection(const QList&)), this, SLOT(onSetSelection(const QList&))); - connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext())); - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this, @@ -437,34 +470,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI return anOperation; } -//void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) -//{ -// static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED); -// boost::shared_ptr aMessage = -// boost::shared_ptr(new Config_PointerMessage(aModuleEvent, this)); -// aMessage->setPointer(theOperation); -// Events_Loop::loop()->send(aMessage); -//} - -void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer) -{ - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - std::list aModes = aPreviewOp->getSelectionModes(theFeature); - activateInLocalContext(theFeature, aModes, isUpdateViewer); - - // If this is a Sketcher then activate objects (planar faces) outside of context - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane); - aDisplayer->activateObjectsOutOfContext(aModes, aFilter); - } else { - aDisplayer->deactivateObjectsOutOfContext(); - } - } -} void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) { @@ -488,7 +493,6 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) aDisplayer->erase(*aIt, false); std::list aList = aPreviewOp->subFeatures(); - std::list aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature()); std::list::const_iterator anIt = aList.begin(), aLast = aList.end(); for (; anIt != aLast; anIt++) { @@ -500,10 +504,10 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) std::list::const_iterator aRIt; for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) { aDisplayer->display((*aRIt), false); - activateInLocalContext((*aRIt), aModes, false); + aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt))); } aDisplayer->display(aSPFeature, false); - activateInLocalContext(aSPFeature, aModes, false); + aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature)); } aDisplayer->updateViewer(); } @@ -567,36 +571,21 @@ XGUI_Workshop* PartSet_Module::xWorkshop() const } -void PartSet_Module::activateInLocalContext(ObjectPtr theResult, const std::list& theModes, - const bool isUpdateViewer) +QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature) { - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - Handle(AIS_InteractiveContext) aContext = xWorkshop()->viewer()->AISContext(); - if (aContext.IsNull()) - return; - // Open local context if there is no one - if (!aContext->HasOpenedContext()) { - aContext->ClearCurrents(false); - //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/); - aContext->OpenLocalContext(); - aContext->NotUseDisplayedObjects(); - } - // display or redisplay presentation - boost::shared_ptr anAIS = aDisplayer->getAISObject(theResult); - // Activate selection of objects from prs - if (anAIS) { - Handle(AIS_InteractiveObject) aAISObj = anAIS->impl(); - aContext->ClearSelected(false); // ToCheck - //aContext->upClearSelected(false); // ToCheck - aContext->Load(aAISObj, -1, true/*allow decomposition*/); - aContext->Deactivate(aAISObj); - - std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); - for (; anIt != aLast; anIt++) { - aContext->Activate(aAISObj, (*anIt)); + QIntList aModes; + FeaturePtr aFeature = boost::dynamic_pointer_cast(theFeature); + if (aFeature) { + if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { + aModes.append(TopAbs_FACE); + return aModes; + } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) { + aModes.append(AIS_DSM_Text); + aModes.append(AIS_DSM_Line); + return aModes; } - } - - if (isUpdateViewer) - aDisplayer->updateViewer(); + } + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); + return aModes; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 44322b359..a91f67943 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -45,11 +46,6 @@ Q_OBJECT /// \param theCmdId the operation name //virtual void launchOperation(const QString& theCmdId); - /// Activates the feature in the displayer - /// \param theFeature the feature instance to be displayed - /// \param isUpdateViewer the flag whether the viewer should be updated - void activateFeature(ObjectPtr theFeature, const bool isUpdateViewer); - /// Updates current operation preview, if it has it. /// \param theCmdId the operation name void updateCurrentPreview(const std::string& theCmdId); @@ -61,13 +57,9 @@ Q_OBJECT XGUI_Workshop* xWorkshop() const; - /// Display the shape and activate selection of sub-shapes - /// \param theFeature a feature instance - /// \param theShape a shape - /// \param theMode a list of local selection modes - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void activateInLocalContext(ObjectPtr theFeature, const std::list& theModes, - const bool isUpdateViewer = true); + + /// Returns list of selection modes for the given object for sketch operation + static QIntList sketchSelectionModes(ObjectPtr theFeature); public slots: void onFeatureTriggered(); @@ -123,8 +115,8 @@ Q_OBJECT /// \param theFeatures a list of features to be selected void onSetSelection(const QList& theFeatures); - /// SLOT, to close the viewer local context - void onCloseLocalContext(); + /// SLOT, Defines Sketch editing mode + void setSketchingMode(); /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode @@ -156,6 +148,7 @@ Q_OBJECT /// A filter which provides selection within a current document or whole PartSet Handle(XGUI_ShapeDocumentFilter) myDocumentShapeFilter; + Handle(StdSelect_FaceFilter) myPlaneFilter; }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 8f4a6930a..fe4b73858 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -77,14 +77,6 @@ bool PartSet_OperationFeatureCreate::canBeCommitted() const return false; } -std::list PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const -{ - std::list aModes; - if (theFeature != feature()) - aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); - return aModes; -} - void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { double aX, anY; diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index fcd92be95..531b4ff22 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -38,11 +38,6 @@ Q_OBJECT /// Destructor virtual ~PartSet_OperationFeatureCreate(); - /// Returns the operation local selection mode - /// \param theFeature the feature object to get the selection mode - /// \return the selection mode - virtual std::list getSelectionModes(ObjectPtr theFeature) const; - /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 2c8426c04..b98436a07 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -48,17 +48,6 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const -{ - std::list aModes; - if (!hasSketchPlane()) - aModes.push_back(TopAbs_FACE); - else - aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); - - return aModes; -} - FeaturePtr PartSet_OperationSketch::sketch() const { return feature(); @@ -154,7 +143,6 @@ void PartSet_OperationSketch::stopOperation() { PartSet_OperationSketchBase::stopOperation(); emit featureConstructed(feature(), FM_Hide); - emit closeLocalContext(); } void PartSet_OperationSketch::afterCommitOperation() @@ -243,7 +231,6 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) flushUpdated(); emit featureConstructed(feature(), FM_Hide); - emit closeLocalContext(); emit planeSelected(aDir->x(), aDir->y(), aDir->z()); } diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index f885503e3..92d2c4fa1 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -41,11 +41,6 @@ Q_OBJECT virtual bool isGranted(ModuleBase_Operation* theOperation) const; - /// Returns the operation local selection mode - /// \param theFeature the feature object to get the selection mode - /// \return the selection mode - virtual std::list getSelectionModes(ObjectPtr theFeature) const; - /// Returns the operation sketch feature /// \returns the sketch instance virtual FeaturePtr sketch() const; diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 2ce61d8ef..d8cd8ec7e 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -52,20 +52,6 @@ std::list PartSet_OperationSketchBase::subFeatures() const return std::list(); } -std::list PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const -{ - //TODO: Define position of selection modes definition - std::list aModes; - FeaturePtr aFeature = boost::dynamic_pointer_cast(theFeature); - if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) { - aModes.push_back(AIS_DSM_Text); - aModes.push_back(AIS_DSM_Line); - } else { - aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); - aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); - } - return aModes; -} FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage) { ModuleBase_Operation::createFeature(theFlushMessage); diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 25f714830..39fbaf082 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -60,11 +60,6 @@ Q_OBJECT /// \return the list of subfeatures virtual std::list subFeatures() const; - /// Returns the operation local selection mode - /// \param theFeature the feature object to get the selection mode - /// \return the selection mode - virtual std::list getSelectionModes(ObjectPtr theFeature) const; - /// Returns the operation sketch feature /// \returns the sketch instance virtual FeaturePtr sketch() const = 0; @@ -139,9 +134,6 @@ signals: /// \param theFeatures a list of features to be disabled void setSelection(const QList& theFeatures); - /// signal to close the operation local context if it is opened - void closeLocalContext(); - protected: /// Creates an operation new feature /// In addition to the default realization it appends the created line feature to diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index cf39a413f..35d688661 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include @@ -153,7 +155,7 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject) } } -void XGUI_Displayer::activate(ObjectPtr theObject) +void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes) { if (isVisible(theObject)) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -162,7 +164,15 @@ void XGUI_Displayer::activate(ObjectPtr theObject) boost::shared_ptr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - aContext->Activate(anAIS); + if (aContext->HasOpenedContext()) { + aContext->Load(anAIS, -1, true); + } + if (theModes.size() > 0) { + foreach(int aMode, theModes) { + aContext->Activate(anAIS, aMode); + } + } else + aContext->Activate(anAIS); } } @@ -244,6 +254,14 @@ void XGUI_Displayer::setSelected(const QList& theResults, const bool updateViewer(); } + +void XGUI_Displayer::clearSelected() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext) + aContext->ClearSelected(); +} + void XGUI_Displayer::eraseAll(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) ic = AISContext(); @@ -378,8 +396,7 @@ void XGUI_Displayer::erase(boost::shared_ptr theAIS, const bo } } -void XGUI_Displayer::activateObjectsOutOfContext(const std::list& theModes, - Handle(SelectMgr_Filter) theFilter) +void XGUI_Displayer::activateObjectsOutOfContext() { Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one @@ -387,13 +404,12 @@ void XGUI_Displayer::activateObjectsOutOfContext(const std::list& theModes, return; aContext->UseDisplayedObjects(); - std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); - for (; anIt != aLast; anIt++) { - aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt)); + ResultToAISMap::iterator aIt; + Handle(AIS_InteractiveObject) anAISIO; + for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) { + anAISIO = (*aIt).second->impl(); + aContext->Load(anAISIO, -1, true); } - - if (!theFilter.IsNull()) - aContext->AddFilter(theFilter); } @@ -404,7 +420,6 @@ void XGUI_Displayer::deactivateObjectsOutOfContext() if (!aContext->HasOpenedContext()) return; - aContext->RemoveFilters(); aContext->NotUseDisplayedObjects(); } @@ -426,6 +441,27 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo aContext->SetDisplayMode(aAISIO, theMode, toUpdate); } +void XGUI_Displayer::setSelectionModes(const QIntList& theModes) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + if (!aContext->HasOpenedContext()) + return; + // Clear previous mode + const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes(); + if (!aModes.IsEmpty()) { + TColStd_ListOfInteger aMModes; + aMModes.Assign(aModes); + TColStd_ListIteratorOfListOfInteger it(aMModes); + for(; it.More(); it.Next()) { + aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value()); + } + } + foreach(int aMode, theModes) { + aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode); + } +} XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const { @@ -441,3 +477,18 @@ XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) con return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode(); } +void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + aContext->AddFilter(theFilter); +} + +void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + aContext->RemoveFilter(theFilter); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 4562e6d08..4902fbceb 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -72,6 +72,10 @@ class XGUI_EXPORT XGUI_Displayer */ void setSelected(const QList& theFeatures, bool isUpdateViewer = true); + + /// Un select all objects + void clearSelected(); + /// Erase the feature and a shape. /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly @@ -94,6 +98,17 @@ class XGUI_EXPORT XGUI_Displayer /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly void closeLocalContexts(const bool isUpdateViewer = true); + /* + * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum. + * It doesn't manages a local context + * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared. + */ + void setSelectionModes(const QIntList& theModes); + + void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + + void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); + /// Updates the viewer void updateViewer(); @@ -111,7 +126,7 @@ class XGUI_EXPORT XGUI_Displayer void deactivate(ObjectPtr theFeature); /// Activates the given object (it can be selected) - void activate(ObjectPtr theFeature); + void activate(ObjectPtr theFeature, const QIntList& theModes); /// Returns true if the given object can be selected bool isActive(ObjectPtr theObject) const; @@ -119,8 +134,7 @@ class XGUI_EXPORT XGUI_Displayer /// Activates in local context displayed outside of the context. /// \param theModes - selection modes to activate /// \param theFilter - filter for selection - void activateObjectsOutOfContext(const std::list& theModes, - Handle(SelectMgr_Filter) theFilter); + void activateObjectsOutOfContext(); void deactivateObjectsOutOfContext(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 8ebed4c15..a63b56356 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -8,6 +8,7 @@ #include "XGUI_SelectionMgr.h" #include "XGUI_Selection.h" #include "XGUI_OperationMgr.h" +#include "XGUI_Displayer.h" XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop) : ModuleBase_IWorkshop(theWorkshop), @@ -51,16 +52,14 @@ ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) { - Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext(); - if (!aAIS->HasOpenedContext()) - aAIS->OpenLocalContext(); - foreach(int aType, theTypes) { - aAIS->ActivateStandardMode((TopAbs_ShapeEnum)aType); - } + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->openLocalContext(); + aDisp->activateObjectsOutOfContext(); + aDisp->setSelectionModes(theTypes); } void XGUI_ModuleConnector::deactivateSubShapesSelection() { - Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext(); - aAIS->CloseAllContexts(); + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->closeLocalContexts(false); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6df891cd4..8ca4729a3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -416,6 +416,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const boost::shared_ptr aObjects = theMsg->objects(); std::set::const_iterator aIt; + QIntList aModes; for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { ObjectPtr aObj = (*aIt); if (!aObj->data() || !aObj->data()->isValid() || aObj->document()->isConcealed(aObj)) @@ -427,7 +428,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const boost::shared_ptrcurrentOperation(); if (!aOperation->hasObject(aObj)) if (!myDisplayer->isActive(aObj)) - myDisplayer->activate(aObj); + myDisplayer->activate(aObj, aModes); } } else { if (myOperationMgr->hasOperation()) { -- 2.39.2