X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationFeatureEditMulti.cpp;h=b36e16ca201c7c71418bcf4261ab577522116abb;hb=7778069b85fb13f2cd02c3cf5ad8ba6233b24e11;hp=960cab6b481cb917bfc602f28930b86af507b23b;hpb=c0565e75ce0bd2f2994dc9874c4775cf7a4cb7ad;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index 960cab6b4..b36e16ca2 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -33,46 +33,67 @@ using namespace std; PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId, - QObject* theParent, - FeaturePtr theFeature) -: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false) + QObject* theParent, + FeaturePtr 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 std::list& 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; + std::list::const_iterator anIt; + for (anIt = theSelected.cbegin(); anIt != theSelected.cend(); ++anIt) { + if ((*anIt).object() == thePrs.object()) + return true; } - else - myFeatures = theSelected; + return false; } -void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature) + +void PartSet_OperationFeatureEditMulti::initSelection( + const std::list& theSelected, + const std::list& theHighlighted) { - 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 = theSelected; + // add highlighted elements if they are not selected + std::list::const_iterator anIt; + for (anIt = theHighlighted.cbegin(); anIt != theHighlighted.cend(); ++anIt) { + if (!isContains(myFeatures, (*anIt))) + myFeatures.push_back(*anIt); + } + // Remove current feature if it is in the list (it will be moved as main feature) + FeaturePtr aFea = feature(); + for (anIt = myFeatures.cbegin(); anIt != myFeatures.cend(); ++anIt) { + FeaturePtr aF = ModelAPI_Feature::feature((*anIt).object()); + if (ModelAPI_Feature::feature((*anIt).object()) == feature()) { + myFeatures.erase(anIt); + break; + } + } } FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const @@ -80,15 +101,16 @@ FeaturePtr 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, Handle(V3d_View) theView, + const std::list& /*theSelected*/, + const std::list& theHighlighted) { } void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { - if (!(theEvent->buttons() & Qt::LeftButton)) + if (!(theEvent->buttons() & Qt::LeftButton)) return; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); @@ -104,17 +126,22 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle 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(); + std::list::const_iterator anIt = myFeatures.begin(), + aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = (*anIt).feature(); - if (!aFeature || aFeature == feature()) + ObjectPtr aObject = (*anIt).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,18 +149,21 @@ 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, Handle(V3d_View) theView, + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) { - 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); - } + if (commit()) { + std::list aFeatures = myFeatures; + std::list::const_iterator anIt = aFeatures.begin(), aLast = + aFeatures.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr aFeature = (*anIt).object(); + if (aFeature) { + emit featureConstructed(aFeature, FM_Deactivation); + } + } } } @@ -156,22 +186,22 @@ void PartSet_OperationFeatureEditMulti::stopOperation() myFeatures.clear(); } -void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked, const bool isRestoreSelection) +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()); + QList 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 setSelection(QList()); emit stopSelection(aFeatureList, true); - } - else { + } else { emit stopSelection(aFeatureList, false); if (isRestoreSelection) { emit setSelection(aFeatureList); @@ -183,10 +213,11 @@ void PartSet_OperationFeatureEditMulti::sendFeatures() { static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); - std::list aFeatures; - std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); + std::list aFeatures; + std::list::const_iterator anIt = myFeatures.begin(), aLast = + myFeatures.end(); for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = (*anIt).feature(); + ObjectPtr aFeature = (*anIt).object(); if (!aFeature) continue;