X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationFeatureEditMulti.cpp;h=4b10858a0bc40ff31371022d816479a616c610e3;hb=a226d633772b2f4c5e327b7451147912e4f84efb;hp=ac2cd698268690709d071e4cea9565324222ddf2;hpb=3868952ce179012a7ca56f6c8d1f271ecdb17f73;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index ac2cd6982..4b10858a0 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include @@ -24,97 +26,118 @@ #include +#include #ifdef _DEBUG #include #endif -#include - -using namespace std; +//using namespace std; PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId, - QObject* theParent, - FeaturePtr theFeature) -: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false) + QObject* theParent, + CompositeFeaturePtr theFeature) + : PartSet_OperationSketchBase(theId, theParent), + mySketch(theFeature), + myIsBlockedSelection(false) { + myIsEditing = true; } PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti() { } -bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOperation) const -{ - return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); -} -void PartSet_OperationFeatureEditMulti::initSelection(const std::list& theSelected, - const std::list& theHighlighted) +bool isContains(const QList& theSelected, const ModuleBase_ViewerPrs& thePrs) { - if (!theHighlighted.empty()) { - // if there is highlighted object, we check whether it is in the list of selected objects - // in that case this object is a handle of the moved lines. If there no such object in the selection, - // the hightlighted object should moved and the selection is skipped. The skipped selection will be - // deselected in the viewer by blockSelection signal in the startOperation method. - bool isSelected = false; - std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); - for (; anIt != aLast && !isSelected; anIt++) { - isSelected = (*anIt).feature() == feature(); - } - if (!isSelected) - myFeatures = theHighlighted; - else - myFeatures = theSelected; + foreach (ModuleBase_ViewerPrs aPrs, theSelected) { + if (aPrs.object() == thePrs.object()) + return true; } - else - myFeatures = theSelected; + return false; } -void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature) + +void PartSet_OperationFeatureEditMulti::initSelection(ModuleBase_ISelection* theSelection) { - setEditingFeature(theFeature); + //if (!theHighlighted.empty()) { + // // if there is highlighted object, we check whether it is in the list of selected objects + // // in that case this object is a handle of the moved lines. If there no such object in the selection, + // // the hightlighted object should moved and the selection is skipped. The skipped selection will be + // // deselected in the viewer by blockSelection signal in the startOperation method. + // bool isSelected = false; + // std::list::const_iterator anIt = theSelected.begin(), + // aLast = theSelected.end(); + // for (; anIt != aLast && !isSelected; anIt++) { + // isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature(); + // } + // if (!isSelected) + // myFeatures = theHighlighted; + // else + // myFeatures = theSelected; + //} else + myFeatures = theSelection->getSelected(); + QList aHighlighted = theSelection->getHighlighted(); + // add highlighted elements if they are not selected + foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) { + if (!isContains(myFeatures, aPrs)) + myFeatures.append(aPrs); + } + // Remove current feature if it is in the list (it will be moved as main feature) + foreach (ModuleBase_ViewerPrs aPrs, myFeatures) { + FeaturePtr aF = ModelAPI_Feature::feature(aPrs.object()); + if (ModelAPI_Feature::feature(aPrs.object()) == feature()) { + myFeatures.removeOne(aPrs); + break; + } + } } -FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const +CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const { return mySketch; } -void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, - const std::list& theHighlighted) -{ -} +//void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) +//{ +//} -void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) { - if (!(theEvent->buttons() & Qt::LeftButton)) + if (!(theEvent->buttons() & Qt::LeftButton)) return; - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); + if (theViewer->isSelectionEnabled()) + theViewer->enableSelection(false); + + Handle(V3d_View) aView = theViewer->activeView(); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - blockSelection(true); + //blockSelection(true); if (myCurPoint.myIsInitialized) { double aCurX, aCurY; - PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY); + PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY); double aX, anY; - PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; - boost::shared_ptr aSketchFeature = - boost::dynamic_pointer_cast(feature()); + boost::shared_ptr aSketchFeature = boost::dynamic_pointer_cast< + SketchPlugin_Feature>(feature()); aSketchFeature->move(aDeltaX, aDeltaY); - std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); - for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = (*anIt).feature(); - if (!aFeature || aFeature == feature()) + foreach (ModuleBase_ViewerPrs aPrs, myFeatures) { + ObjectPtr aObject = aPrs.object(); + if (!aObject || aObject == feature()) continue; - aSketchFeature = boost::dynamic_pointer_cast(aFeature); - aSketchFeature->move(aDeltaX, aDeltaY); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature) { + aSketchFeature = boost::dynamic_pointer_cast(aFeature); + if (aSketchFeature) + aSketchFeature->move(aDeltaX, aDeltaY); + } } } sendFeatures(); @@ -122,71 +145,69 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle myCurPoint.setPoint(aPoint); } -void PartSet_OperationFeatureEditMulti::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) +void PartSet_OperationFeatureEditMulti::mouseReleased( + QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, + ModuleBase_ISelection* theSelection) { - std::list aFeatures = myFeatures; - commit(); - std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); - for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = (*anIt).feature(); - if (aFeature) { - emit featureConstructed(aFeature, FM_Deactivation); - } + theViewer->enableSelection(true); + if (commit()) { + foreach (ModuleBase_ViewerPrs aPrs, myFeatures) { + ObjectPtr aFeature = aPrs.object(); + if (aFeature) { + emit featureConstructed(aFeature, FM_Deactivation); + } + } } } void PartSet_OperationFeatureEditMulti::startOperation() { PartSet_OperationSketchBase::startOperation(); - emit multiSelectionEnabled(false); + //emit multiSelectionEnabled(false); - blockSelection(true); + //blockSelection(true); myCurPoint.clear(); } void PartSet_OperationFeatureEditMulti::stopOperation() { - emit multiSelectionEnabled(true); + //emit multiSelectionEnabled(true); - blockSelection(false, true); + //blockSelection(false, true); myFeatures.clear(); } -void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked, const bool isRestoreSelection) -{ - if (myIsBlockedSelection == isBlocked) - return; - - myIsBlockedSelection = isBlocked; - QFeatureList aFeatureList; - std::list::const_iterator anIt = myFeatures.begin(), - aLast = myFeatures.end(); - for(; anIt != aLast; anIt++) - aFeatureList.append((*anIt).feature()); - if (isBlocked) { - emit setSelection(QFeatureList()); - emit stopSelection(aFeatureList, true); - } - else { - emit stopSelection(aFeatureList, false); - if (isRestoreSelection) { - emit setSelection(aFeatureList); - } - } -} +//void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked, +// const bool isRestoreSelection) +//{ +// if (myIsBlockedSelection == isBlocked) +// return; +// +// myIsBlockedSelection = isBlocked; +// QList aFeatureList; +//// std::list::const_iterator anIt = myFeatures.begin(), aLast = +//// myFeatures.end(); +// /*for(; anIt != aLast; anIt++) +// aFeatureList.append((*anIt).feature());*/ +// //if (isBlocked) { +// // emit setSelection(QList()); +// // emit stopSelection(aFeatureList, true); +// //} else { +// // emit stopSelection(aFeatureList, false); +// // if (isRestoreSelection) { +// // emit setSelection(aFeatureList); +// // } +// //} +//} void PartSet_OperationFeatureEditMulti::sendFeatures() { - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); - std::list aFeatures; - std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); - for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = (*anIt).feature(); + foreach (ModuleBase_ViewerPrs aPrs, myFeatures) { + ObjectPtr aFeature = aPrs.object(); if (!aFeature) continue;