From 7df76a8390c4b44a0f31742b3a85fe05491269bb Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 19 May 2014 19:24:40 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Restore selection after operation edit. --- src/PartSet/PartSet_Module.cpp | 12 ++++++-- src/XGUI/XGUI_Displayer.cpp | 52 +++++++++++++++++++++------------- src/XGUI/XGUI_Displayer.h | 9 +++++- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8f2ef6e4f..198cfbe64 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -198,8 +198,16 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) void PartSet_Module::onStopSelection(const std::list& theFeatures, const bool isStop) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->StopSelection(theFeatures, isStop); - + aDisplayer->StopSelection(theFeatures, isStop, false); + if (!isStop) { + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + boost::shared_ptr aFeature; + for (; anIt != aLast; anIt++) { + activateFeature((*anIt).feature(), false); + } + } + aDisplayer->SetSelected(theFeatures, false); + aDisplayer->UpdateViewer(); } void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index cbfb9413c..d597eda0c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -120,6 +120,7 @@ void XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, // If there was a problem here, try the first solution with close/open local context. anAIS->Set(theShape); anAIS->Redisplay(); + /*if (aContext->IsSelected(anAIS)) { aContext->AddOrRemoveSelected(anAIS, false); aContext->AddOrRemoveSelected(anAIS, false); @@ -147,8 +148,6 @@ void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr Handle(AIS_Shape) anAIS; if (IsVisible(theFeature)) anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); - //if (!anAIS.IsNull()) - // return; // Activate selection of objects from prs if (!anAIS.IsNull()) { @@ -156,30 +155,19 @@ void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr aContext->Deactivate(anAIS); std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); - QString aDebugStr = QString(featureInfo(theFeature).c_str()) + QString("; modes: "); for (; anIt != aLast; anIt++) { aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)); - aDebugStr += QString("%1").arg(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)) + QString(", "); } - /*if (theModes.empty()) { - aContext->Deactivate(anAIS); - aContext->Activate(anAIS, -1); - aContext->ClearSelected(); - aDebugStr += " deactivated"; - QColor aColor(Qt::white); - anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB)); - }*/ - qDebug(aDebugStr.toStdString().c_str()); } if (isUpdateViewer) aContext->UpdateCurrentViewer(); } -void XGUI_Displayer::StopSelection(const std::list& theFeatures, const bool isStop) +void XGUI_Displayer::StopSelection(const std::list& theFeatures, const bool isStop, + const bool isUpdateViewer) { - return; Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_Shape) anAIS; @@ -193,19 +181,43 @@ void XGUI_Displayer::StopSelection(const std::list& theFeatures, continue; if (isStop) { - aContext->Deactivate(anAIS); - aContext->Activate(anAIS, -1); aContext->ClearSelected(); + aContext->Deactivate(anAIS); - //aDebugStr += " deactivated"; QColor aColor(Qt::white); anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB)); + anAIS->Redisplay(); } else { - //QColor aColor(Qt::red); - //anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB)); + QColor aColor(Qt::red); + anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB)); + anAIS->Redisplay(); } } + if (isUpdateViewer) + aContext->UpdateCurrentViewer(); +} + +void XGUI_Displayer::SetSelected(const std::list& theFeatures, const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + boost::shared_ptr aFeature; + + Handle(AIS_Shape) anAIS; + aContext->ClearSelected(); + + for (; anIt != aLast; anIt++) { + aFeature = (*anIt).feature(); + if (IsVisible(aFeature)) + anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]); + if (anAIS.IsNull()) + continue; + aContext->AddOrRemoveSelected(anAIS, false); + } + if (isUpdateViewer) + aContext->UpdateCurrentViewer(); } void XGUI_Displayer::EraseAll(const bool isUpdateViewer) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 5e0b334e5..5973cd67e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -81,7 +81,14 @@ public: /// Stop the current selection and color the given features to the selection color /// \param theFeatures a list of features to be disabled /// \param theToStop the boolean state whether it it stopped or non stopped - void StopSelection(const std::list& theFeatures, const bool isStop); + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void StopSelection(const std::list& theFeatures, const bool isStop, + const bool isUpdateViewer); + + /// Set the features are selected + /// \param theFeatures a list of features to be selected + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void SetSelected(const std::list& theFeatures, const bool isUpdateViewer); /// Erase the feature and a shape. /// \param theFeature a feature instance -- 2.39.2