From: nds Date: Fri, 16 May 2014 14:09:02 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~55 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f4797a246fbd855f80f8a2f5c620e1aae1701000;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Edit for multi selection. --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 17998703c..b68326fce 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -138,13 +138,7 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - XGUI_SelectionMgr* aSelector = myWorkshop->selector(); - std::list aPresentations; - if (aSelector) { - NCollection_List aList; - aSelector->selectedShapes(aList); - aPresentations = myWorkshop->displayer()->GetViewerPrs(aList); - } + std::list aPresentations = myWorkshop->displayer()->GetViewerPrs(); aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations); } } @@ -155,13 +149,7 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - XGUI_SelectionMgr* aSelector = myWorkshop->selector(); - std::list aPresentations; - if (aSelector) { - NCollection_List aList; - aSelector->selectedShapes(aList); - aPresentations = myWorkshop->displayer()->GetViewerPrs(aList); - } + std::list aPresentations = myWorkshop->displayer()->GetViewerPrs(); aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView(), aPresentations); } } @@ -196,7 +184,8 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr(anOperation); if (aPreviewOp) { - aPreviewOp->init(theFeature); + std::list aPresentations = myWorkshop->displayer()->GetViewerPrs(); + aPreviewOp->init(theFeature, aPresentations); } myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true); sendOperation(anOperation); @@ -208,12 +197,6 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) aViewer->enableMultiselection(theEnabled); } -void PartSet_Module::onSelectionEnabled(bool theEnabled) -{ - XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); - aViewer->enableSelection(theEnabled); -} - void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { @@ -264,8 +247,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, SLOT(onMultiSelectionEnabled(bool))); - connect(aPreviewOp, SIGNAL(selectionEnabled(bool)), - this, SLOT(onSelectionEnabled(bool))); PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 14a418d01..86c2d95f6 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -83,10 +83,6 @@ public slots: /// \param theEnabled the enabled state void onMultiSelectionEnabled(bool theEnabled); - /// SLOT, to switch on/off the selection in the viewer - /// \param theEnabled the enabled state - void onSelectionEnabled(bool theEnabled); - /// 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 f0049b007..ee98295b5 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -48,9 +48,11 @@ std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) +void PartSet_OperationEditLine::init(boost::shared_ptr theFeature, + const std::list& thePresentations) { setFeature(theFeature); + myFeatures = thePresentations; } void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView) @@ -66,6 +68,7 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie { if (!(theEvent->buttons() & Qt::LeftButton)) return; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); if (myCurPoint.myIsInitialized) { @@ -81,14 +84,14 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START); moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END); - /*std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); + std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { boost::shared_ptr aFeature = (*anIt).feature(); - if (!aFeature) + if (!aFeature || aFeature == feature()) continue; moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START); moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END); - }*/ + } } myCurPoint.setPoint(aPoint); } @@ -96,28 +99,41 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, const std::list& theSelected) { - boost::shared_ptr aFeature; - if (!theSelected.empty()) - aFeature = theSelected.front().feature(); - - if (aFeature == feature()) - return; + std::list aFeatures = myFeatures; + if (myFeatures.size() == 1) { + boost::shared_ptr aFeature; + if (!theSelected.empty()) + aFeature = theSelected.front().feature(); + + if (aFeature == feature()) + return; - commit(); - if (aFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + commit(); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + } + else { + commit(); + std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).feature(); + if (aFeature) + emit featureConstructed(aFeature, FM_Deactivation); + } + } } void PartSet_OperationEditLine::startOperation() { // do nothing in order to do not create a new feature - emit selectionEnabled(false); + emit multiSelectionEnabled(false); myCurPoint.clear(); } void PartSet_OperationEditLine::stopOperation() { - emit selectionEnabled(true); + emit multiSelectionEnabled(true); + myFeatures.clear(); } boost::shared_ptr PartSet_OperationEditLine::createFeature() diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index 826a5f9ae..58b911b26 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -71,7 +71,9 @@ public: /// Initializes some fields accorging to the feature /// \param theFeature the feature - virtual void init(boost::shared_ptr theFeature); + /// \param thePresentations the list of additional presentations + virtual void init(boost::shared_ptr theFeature, + const std::list& thePresentations); /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer @@ -116,6 +118,7 @@ protected: private: boost::shared_ptr mySketch; ///< the sketch feature + std::list myFeatures; ///< the features to apply the edit operation Point myCurPoint; ///< the current 3D point clicked or moved gp_Pnt myCurPressed; ///< the current 3D point clicked or moved }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index bcbbf1571..d96ddc4ac 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -67,6 +67,13 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi myIsEditMode = true; } } + else { + if (theSelected.size() == 1) { + boost::shared_ptr aFeature = theSelected.front().feature(); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + } + } } void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, @@ -75,10 +82,12 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty()) return; - boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), - theView, feature(), theSelected); - if (aFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + if (theSelected.size() != 1) { + boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), + theView, feature(), theSelected); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + } } std::map, boost::shared_ptr > diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index cce1c5511..ad6886c33 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -56,7 +56,9 @@ public: /// Initializes some fields accorging to the feature /// \param theFeature the feature - virtual void init(boost::shared_ptr theFeature) {} + /// \param thePresentations the list of additional presentations + virtual void init(boost::shared_ptr theFeature, + const std::list& thePresentations) {} /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer @@ -95,10 +97,6 @@ signals: /// \param theEnabled the boolean state void multiSelectionEnabled(bool theEnabled); - /// signal to enable/disable usual selection in the viewer - /// \param theEnabled the boolean state - void selectionEnabled(bool theEnabled); - protected: /// Creates an operation new feature /// In addition to the default realization it appends the created line feature to diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index ba194d6ba..5d456d875 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -65,7 +65,8 @@ std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr< return aModes; } -void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature) +void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature, + const std::list& /*thePresentations*/) { if (!theFeature) return; diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index b048ef8a7..f6a281c63 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -46,7 +46,9 @@ public: /// Initializes some fields accorging to the feature /// \param theFeature the feature - virtual void init(boost::shared_ptr theFeature); + /// \param thePresentations the list of additional presentations + virtual void init(boost::shared_ptr theFeature, + const std::list& thePresentations); /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 8daeaa9ed..ee091f19b 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -6,6 +6,7 @@ #include "XGUI_Viewer.h" #include "XGUI_Workshop.h" #include "XGUI_ViewerProxy.h" +#include "XGUI_Tools.h" #include #include @@ -16,6 +17,8 @@ #include +#include + XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) { myWorkshop = theWorkshop; @@ -35,7 +38,7 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, { } -void XGUI_Displayer::Display(boost::shared_ptr theFeature, +/*void XGUI_Displayer::Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -46,39 +49,32 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, aContext->Display(anAIS, Standard_False); if (isUpdateViewer) aContext->UpdateCurrentViewer(); -} +}*/ -boost::shared_ptr XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape) -{ - boost::shared_ptr aFeature; - FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), - aFLast = myFeature2AISObjectMap.end(); - for (; aFIt != aFLast && !aFeature; aFIt++) - { - Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); - if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) { - aFeature = (*aFIt).first; - } - } - return aFeature; -} - -std::list XGUI_Displayer::GetViewerPrs - (const NCollection_List& theShapes) +std::list XGUI_Displayer::GetViewerPrs() { + std::set > aPrsFeatures; std::list aPresentations; - if (theShapes.IsEmpty()) - return aPresentations; - NCollection_List::Iterator anIt(theShapes); - for (; anIt.More(); anIt.Next()) { - const TopoDS_Shape& aShape = anIt.Value(); - if (aShape.IsNull()) + Handle(AIS_InteractiveContext) aContext = AISContext(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + TopoDS_Shape aShape = aContext->SelectedShape(); + + boost::shared_ptr aFeature; + FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), + aFLast = myFeature2AISObjectMap.end(); + for (; aFIt != aFLast && !aFeature; aFIt++) { + Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; + if (anAIS != anIO) + continue; + aFeature = (*aFIt).first; + } + if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) continue; - boost::shared_ptr aFeature = GetFeature(aShape); aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + aPrsFeatures.insert(aFeature); } return aPresentations; @@ -119,8 +115,18 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr if (IsVisible(theFeature)) { anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); if (!anAIS.IsNull()) { + // if the AIS object is displayed in the opened local context in some mode, additional + // AIS sub objects are created there. They should be rebuild for correct selecting. + // It is possible to correct it by closing local context before the shape set and opening + // after. Another workaround to thrown down the selection and reselecting the AIS. + // 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); + //aContext->SetSelected(anAIS, false); + } } } else { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index c03157885..118d7268e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -55,17 +55,12 @@ public: /// \param theFeature a feature instance /// \param theShape a shape /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, - const bool isUpdateViewer = true); + //void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, + // const bool isUpdateViewer = true); - /// Returns the feature, that was displayed with this shape - /// \param theShape a shape - boost::shared_ptr GetFeature(const TopoDS_Shape& theShape); - /// Returns a list of viewer presentations - /// \param theShapes list of shapes to find corresponded features /// \return list of presentations - std::list GetViewerPrs(const NCollection_List& theShapes); + std::list GetViewerPrs(); /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 77c38599d..962680299 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -1,7 +1,13 @@ #include "XGUI_Tools.h" +#include +#include + #include +#include +#include + //****************************************************************** QString dir(const QString& path, bool isAbs) { @@ -46,3 +52,13 @@ QRect makeRect(const int x1, const int y1, const int x2, const int y2) { return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1)); } + +//****************************************************************** +std::string featureInfo(boost::shared_ptr theFeature) +{ + std::ostringstream aStream; + if (theFeature) + aStream << theFeature.get(); + return QString(aStream.str().c_str()).toStdString(); +} + diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index aebea7f6e..5c8be08e8 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -5,6 +5,10 @@ #include #include +#include + +class TopoDS_Shape; +class ModelAPI_Feature; /*! \brief Return directory part of the file path. @@ -52,4 +56,9 @@ QString XGUI_EXPORT addSlash(const QString& path); */ QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2); +/*! + Returns the string presentation of the given feature + \param theFeature a feature +*/ +std::string XGUI_EXPORT featureInfo(boost::shared_ptr theFeature); #endif