From: nds Date: Mon, 19 May 2014 14:17:59 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d97a927cc9674862395b439b3dd5de5341bc2b92;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Separation of AIS objects activation in the local selection from the feature display/redisplay --- diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index b97b34f8e..937973542 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -40,8 +40,12 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); boost::shared_ptr aFeature = aUpdMsg->feature(); if (myModule->workshop()->displayer()->IsVisible(aFeature) || - aType == EVENT_FEATURE_CREATED) - myModule->visualizePreview(aFeature, true); + aType == EVENT_FEATURE_CREATED) { + myModule->visualizePreview(aFeature, true, false); + if (aType == EVENT_FEATURE_CREATED) + myModule->activateFeature(aFeature, true); + myModule->workshop()->displayer()->UpdateViewer(); + } } if (aType == EVENT_FEATURE_DELETED) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 08b5bf2b6..24d9044fa 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -195,11 +195,21 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) aViewer->enableMultiselection(theEnabled); } +void PartSet_Module::onStopSelection(const std::list& theFeatures, const bool isStop) +{ + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->StopSelection(theFeatures, isStop); + +} + void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort; - visualizePreview(theFeature, isDisplay); + visualizePreview(theFeature, isDisplay, false); + + if (theMode == FM_Activation || theMode == FM_Deactivation) + activateFeature(theFeature, true); } ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId) @@ -246,6 +256,11 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, SLOT(onMultiSelectionEnabled(bool))); + connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), + this, SLOT(onMultiSelectionEnabled(bool))); + connect(aPreviewOp, SIGNAL(stopSelection(const std::list&, const bool)), + this, SLOT(onStopSelection(const std::list&, const bool))); + PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), @@ -265,7 +280,8 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) Events_Loop::loop()->send(aMessage); } -void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay) +void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay, + const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); if (!anOperation) @@ -278,13 +294,25 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - aDisplayer->RedisplayInLocalContext(theFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), - aPreviewOp->getSelectionModes(theFeature)); + aDisplayer->Redisplay(theFeature, + aPreview ? aPreview->impl() : TopoDS_Shape(), false); } - else { - //aDisplayer->CloseLocalContexts(false); - aDisplayer->Erase(anOperation->feature()); + else + aDisplayer->Erase(anOperation->feature(), false); + + if (isUpdateViewer) + aDisplayer->UpdateViewer(); +} + +void PartSet_Module::activateFeature(boost::shared_ptr theFeature, + const bool isUpdateViewer) +{ + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) { + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), + isUpdateViewer); } } @@ -312,9 +340,9 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) for (; anIt != aLast; anIt++) { boost::shared_ptr aFeature = (*anIt).first; boost::shared_ptr aPreview = (*anIt).second; - aDisplayer->RedisplayInLocalContext(aFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), - aModes, false); + aDisplayer->Redisplay(aFeature, + aPreview ? aPreview->impl() : TopoDS_Shape(), false); + aDisplayer->ActivateInLocalContext(aFeature, aModes, false); } aDisplayer->UpdateViewer(); } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 86c2d95f6..cba0367e6 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -17,6 +17,7 @@ class QMouseEvent; class QKeyEvent; class PartSet_Listener; class ModelAPI_Feature; +class XGUI_ViewerPrs; class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module { @@ -40,9 +41,17 @@ public: virtual void launchOperation(const QString& theCmdId); /// Displays or erase the current operation preview, if it has it. - /// \param theF + /// \param theFeature the feature instance to be displayed /// \param isDisplay the state whether the presentation should be displayed or erased - void visualizePreview(boost::shared_ptr theFeature, bool isDisplay); + /// \param isUpdateViewer the flag whether the viewer should be updated + void visualizePreview(boost::shared_ptr theFeature, bool isDisplay, + const bool isUpdateViewer = true); + + /// 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(boost::shared_ptr theFeature, + const bool isUpdateViewer); /// Updates current operation preview, if it has it. /// \param theCmdId the operation name @@ -83,6 +92,11 @@ public slots: /// \param theEnabled the enabled state void onMultiSelectionEnabled(bool theEnabled); + /// SLOT, to stop or start selection for the features + /// \param theFeatures a list of features to be disabled + /// \param theToStop the boolean state whether it it stopped or non stopped + void onStopSelection(const std::list& theFeatures, const bool isStop); + /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index c9fbbfd86..2c39948d7 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -43,9 +43,9 @@ bool PartSet_OperationEditLine::isGranted() const std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - aModes.push_back(TopAbs_VERTEX); - aModes.push_back(TopAbs_EDGE); + aModes.push_back(-1); return aModes; + //return PartSet_OperationSketchBase::getSelectionModes(theFeature); } void PartSet_OperationEditLine::init(boost::shared_ptr theFeature, @@ -126,12 +126,14 @@ void PartSet_OperationEditLine::startOperation() { // do nothing in order to do not create a new feature emit multiSelectionEnabled(false); + emit stopSelection(myFeatures, true); myCurPoint.clear(); } void PartSet_OperationEditLine::stopOperation() { emit multiSelectionEnabled(true); + emit stopSelection(myFeatures, false); myFeatures.clear(); } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index be977401b..3bb916fab 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -46,10 +46,8 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr aModes; if (!myIsEditMode) aModes.push_back(TopAbs_FACE); - else { - aModes.push_back(TopAbs_VERTEX); - aModes.push_back(TopAbs_EDGE); - } + else + aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); return aModes; } diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 9eac6c82a..3412a2e19 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -38,6 +38,13 @@ std::map, boost::shared_ptr > return std::map, boost::shared_ptr >(); } +std::list PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr theFeature) const +{ + std::list aModes; + aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); + return aModes; +} boost::shared_ptr PartSet_OperationSketchBase::createFeature() { boost::shared_ptr aFeature = ModuleBase_Operation::createFeature(); diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 62de3116b..4fb941df9 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -100,6 +100,11 @@ signals: /// \param theEnabled the boolean state void multiSelectionEnabled(bool theEnabled); + /// signal to enable/disable selection in the viewer + /// \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 theToStop); + /// signal to enable/disable usual selection in the viewer /// \param theEnabled the boolean state void selectionEnabled(bool theEnabled); diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index a4e09b856..0b05a8ef9 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -58,10 +58,7 @@ std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr< { std::list aModes; if (theFeature != feature()) - { - aModes.push_back(TopAbs_VERTEX); - aModes.push_back(TopAbs_EDGE); - } + aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); return aModes; } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index ee091f19b..cbfb9413c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -99,16 +99,14 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, aContext->UpdateCurrentViewer(); } -void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, - const std::list& theModes, const bool isUpdateViewer) +void XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one if (!aContext->HasOpenedContext()) { aContext->ClearCurrents(false); - aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/, - true/*allow shape decomposition*/); + aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/); } // display or redisplay presentation Handle(AIS_Shape) anAIS; @@ -122,11 +120,11 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr // If there was a problem here, try the first solution with close/open local context. anAIS->Set(theShape); anAIS->Redisplay(); - if (aContext->IsSelected(anAIS)) { + /*if (aContext->IsSelected(anAIS)) { aContext->AddOrRemoveSelected(anAIS, false); aContext->AddOrRemoveSelected(anAIS, false); //aContext->SetSelected(anAIS, false); - } + }*/ } } else { @@ -134,20 +132,82 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr myFeature2AISObjectMap[theFeature] = anAIS; aContext->Display(anAIS, false); } +} + +void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr theFeature, + const std::list& theModes, const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + // Open local context if there is no one + if (!aContext->HasOpenedContext()) { + aContext->ClearCurrents(false); + aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/); + } + // display or redisplay presentation + 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()) { - aContext->Load(anAIS, -1, true/*allow decomposition*/); + aContext->Load(anAIS, -1, true/*allow decomposition*/); + 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) +{ + return; + Handle(AIS_InteractiveContext) aContext = AISContext(); + + Handle(AIS_Shape) anAIS; + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + boost::shared_ptr aFeature; + for (; anIt != aLast; anIt++) { + aFeature = (*anIt).feature(); + if (IsVisible(aFeature)) + anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]); + if (anAIS.IsNull()) + continue; + + if (isStop) { + 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)); + } + else { + //QColor aColor(Qt::red); + //anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB)); + } + } +} + void XGUI_Displayer::EraseAll(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) ic = AISContext(); diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 118d7268e..5e0b334e5 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -67,9 +67,21 @@ public: /// \param theShape a shape /// \param theMode a local selection mode /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void RedisplayInLocalContext(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, - const std::list& theMode, const bool isUpdateViewer = true); + void Redisplay(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, const bool isUpdateViewer = true); + + /// 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(boost::shared_ptr theFeature, + const std::list& theModes, const bool isUpdateViewer = true); + + /// 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); /// Erase the feature and a shape. /// \param theFeature a feature instance @@ -106,4 +118,5 @@ protected: FeatureToAISMap myFeature2AISObjectMap; }; + #endif diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 962680299..8ce0a36ac 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -58,7 +58,7 @@ std::string featureInfo(boost::shared_ptr theFeature) { std::ostringstream aStream; if (theFeature) - aStream << theFeature.get(); + aStream << theFeature.get() << " " << theFeature->getKind(); return QString(aStream.str().c_str()).toStdString(); }