X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketch.cpp;h=c3ca9d922d802d974e962a87ac41eddf62f6983c;hb=d22fc665c79c31c9eea0625e04c2e941adfdf7be;hp=4ff87cae1414d760c31a3e2f7bcddacf5b8df636;hpb=8dc74f82810d5f597b78633b457efb0ef4f89f9f;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 4ff87cae1..c3ca9d922 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -22,6 +21,8 @@ #include #include +#include +#include #include #include @@ -48,89 +49,124 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const +CompositeFeaturePtr PartSet_OperationSketch::sketch() const { - std::list aModes; - if (!hasSketchPlane()) - aModes.push_back(TopAbs_FACE); - else - aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); - - return aModes; -} - -/// Initializes the operation with previously created feature. It is used in sequental operations -void PartSet_OperationSketch::initFeature(FeaturePtr theFeature) -{ - if (theFeature) - setEditingFeature(theFeature); -} - -FeaturePtr PartSet_OperationSketch::sketch() const -{ - return feature(); + return boost::dynamic_pointer_cast(feature()); } -void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) +void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) { if (hasSketchPlane()) { // if shift button is pressed and there are some already selected objects, the operation should // not be started. We just want to combine some selected objects. bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - if (aHasShift && theSelected.size() > 0) - return; - - if (theHighlighted.size() == 1) { - ObjectPtr aFeature = theHighlighted.front().object(); - if (aFeature) { - std::string anOperationType = - (theSelected.size() > 1) ? - PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type(); - restartOperation(anOperationType, aFeature); + QList aSelected = theSelection->getSelected(); + QList aHighlighted = theSelection->getHighlighted(); + // commented: the next code is commented because the nearestFeature check the highlighting + // and selection inside + //if (aHasShift && (aSelected.size() > 0)) { + // foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) + // aSelected.append(aPrs); + //} + //if (aHasShift && aSelected.size() > 0) + // return; + + // there should be a start of operation, which uses the pre-highlighted objects, + // the selected ones are collected here and are processed by a mouse move + //if (aHighlighted.size() == 1) { + //if (aSelected.size() > 0) { + // ObjectPtr aFeature = aSelected.first().object(); + // if (aFeature) { + // commented: end + Handle(V3d_View) aView = theViewer->activeView(); + ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(), + aSelected, aHighlighted); + if (aFeature) + restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); + //} + //} + //else + // myFeatures = aHighlighted; + //else + //myFeatures = aSelected; + } +} + + +void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelection) +{ + if (hasSketchPlane()) + return; + + QList aSelected = theSelection->getSelected(); + if (!aSelected.empty()) { + ModuleBase_ViewerPrs aPrs = aSelected.first(); + // We have to select a plane before any operation + TopoDS_Shape aShape = aPrs.shape(); + if (!aShape.IsNull()) { + boost::shared_ptr aDir = setSketchPlane(aShape); + flushUpdated(); + emit featureConstructed(feature(), FM_Hide); + // If selection is not a sketcher presentation then it has to be stored as + // External shape + if (feature() != aPrs.object()) { + //boost::shared_ptr aSketch = + // boost::dynamic_pointer_cast(feature()); + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = + boost::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + if (aSelAttr) { + ResultPtr aRes = boost::dynamic_pointer_cast(aPrs.object()); + if (aRes) { + GeomShapePtr aShapePtr(new GeomAPI_Shape()); + aShapePtr->setImpl(new TopoDS_Shape(aShape)); + aSelAttr->setValue(aRes, aShapePtr); + } + } + } else { + // Turn viewer to the plane + emit planeSelected(aDir->x(), aDir->y(), aDir->z()); } - } else - myFeatures = theHighlighted; - - } else { - if (!theHighlighted.empty()) { - ModuleBase_ViewerPrs aPrs = theHighlighted.front(); - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) - setSketchPlane(aShape); + emit updatePropPanel(); + emit launchSketch(); } } } -void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + +void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, + ModuleBase_ISelection* theSelection) { + QList aSelected = theSelection->getSelected(); if (hasSketchPlane()) { /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape /// but for other IO, for example constraint dimensions. /// It is empty and we have to use the process mouse release to start edition operation /// for these objects - if (theSelected.size() == 1) { - ObjectPtr aFeature = theSelected.front().object(); - if (aFeature) - restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); + if (aSelected.size() == 1) { + ObjectPtr aObject = aSelected.first().object(); + if (aObject) { + restartOperation(PartSet_OperationFeatureEdit::Type(), aObject); + } } } } -void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) { if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) return; - if (myFeatures.size() != 1) { - FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(), - myFeatures); + // myFeatures are not filled in the previous realization, so, this code is just commented + // because has no effect + /*if (myFeatures.size() != 1) { + Handle(V3d_View) aView = theViewer->activeView(); + ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(), + myFeatures); if (aFeature) - restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature); - } + restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); + }*/ } std::list PartSet_OperationSketch::subFeatures() const @@ -160,17 +196,18 @@ void PartSet_OperationSketch::stopOperation() { PartSet_OperationSketchBase::stopOperation(); emit featureConstructed(feature(), FM_Hide); - emit closeLocalContext(); +} +void PartSet_OperationSketch::afterCommitOperation() +{ FeaturePtr aFeature = feature(); std::list aResults = aFeature->results(); std::list::const_iterator aIt; + Events_ID anEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW); for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - ModelAPI_EventCreator::get()->sendUpdated( - *aIt, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + ModelAPI_EventCreator::get()->sendUpdated(*aIt, anEvent); } - //ModelAPI_EventCreator::get()->sendUpdated(aFeature, - // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + Events_Loop::loop()->flush(anEvent); } bool PartSet_OperationSketch::isNestedOperationsEnabled() const @@ -199,10 +236,10 @@ bool PartSet_OperationSketch::hasSketchPlane() const return aHasPlane; } -void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) +boost::shared_ptr PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) { if (theShape.IsNull()) - return; + return boost::shared_ptr(); // get selected shape boost::shared_ptr aGShape(new GeomAPI_Shape); @@ -243,10 +280,13 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) aData->attribute(SketchPlugin_Sketch::DIRY_ID())); aDirY->setValue(aYDir); boost::shared_ptr aDir = aPlane->direction(); + return aDir; +} - flushUpdated(); - emit featureConstructed(feature(), FM_Hide); - emit closeLocalContext(); - emit planeSelected(aDir->x(), aDir->y(), aDir->z()); +bool PartSet_OperationSketch::isGranted(ModuleBase_Operation* theOperation) const +{ + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); + return aPreviewOp != NULL; } +