X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketch.cpp;h=81ba69a079ed80f19ec060c3fe2421f137378751;hb=a26ab6459775c0e8454af689aab40629db3fb502;hp=7deb0ef54c44d670e467ac214ba58afb10d74a8a;hpb=8fb6099964adb7a3dd335727ce87ddcdbaf9e8da;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 7deb0ef54..81ba69a07 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -4,23 +4,31 @@ #include -#include +#include +#include #include #include +#include #include #include #include +#include #include #include #include +#include -#include +#include +#include #include #include +#include +#include +#include #include #ifdef _DEBUG @@ -31,6 +39,7 @@ using namespace std; + PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) : PartSet_OperationSketchBase(theId, theParent) @@ -41,41 +50,35 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature) const +std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const { std::list aModes; if (!hasSketchPlane()) aModes.push_back(TopAbs_FACE); else aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); + return aModes; } -void PartSet_OperationSketch::init(boost::shared_ptr theFeature, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) + +/// Initializes the operation with previously created feature. It is used in sequental operations +void PartSet_OperationSketch::initFeature(FeaturePtr theFeature) { - setFeature(theFeature); + if (theFeature) + setEditingFeature(theFeature); } -boost::shared_ptr PartSet_OperationSketch::sketch() const +FeaturePtr PartSet_OperationSketch::sketch() const { return feature(); } void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { - if (!hasSketchPlane()) { - if (!theHighlighted.empty()) { - XGUI_ViewerPrs aPrs = theHighlighted.front(); - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) - setSketchPlane(aShape); - } - } - else { + 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); @@ -83,12 +86,41 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie return; if (theHighlighted.size() == 1) { - boost::shared_ptr aFeature = theHighlighted.front().feature(); - if (aFeature) - restartOperation(PartSet_OperationEditLine::Type(), aFeature); + ObjectPtr aFeature = theHighlighted.front().object(); + if (aFeature) { + std::string anOperationType = (theSelected.size() > 1)? + PartSet_OperationFeatureEditMulti::Type() : + PartSet_OperationFeatureEdit::Type(); + restartOperation(anOperationType, aFeature); + } } else myFeatures = theHighlighted; + + } else { + if (!theHighlighted.empty()) { + ModuleBase_ViewerPrs aPrs = theHighlighted.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) + setSketchPlane(aShape); + } + } +} + +void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted) +{ + 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); + } } } @@ -98,36 +130,34 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) return; if (myFeatures.size() != 1) { - boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), - theView, feature(), myFeatures); + FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(), + myFeatures); if (aFeature) - restartOperation(PartSet_OperationEditLine::Type(), aFeature); + restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature); } } -std::map, boost::shared_ptr > - PartSet_OperationSketch::subPreview() const +std::list PartSet_OperationSketch::subFeatures() const { - std::map, boost::shared_ptr > aPreviewMap; + std::list aFeaList; + FeaturePtr aFeature = feature(); + if (!aFeature) + return aFeaList; - boost::shared_ptr aFeature; - - boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aData = aFeature->data(); if (!aData->isValid()) - return aPreviewMap; + return std::list(); boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); - - std::list > aFeatures = aRefList->list(); - std::list >::const_iterator anIt = aFeatures.begin(), - aLast = aFeatures.end(); - for (; anIt != aLast; anIt++) { - aFeature = boost::dynamic_pointer_cast(*anIt); - boost::shared_ptr aPreview = aFeature->preview(); - if (aPreview) - aPreviewMap[aFeature] = aPreview; + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); + + std::list aList = aRefList->list(); + std::list::iterator aIt; + for (aIt = aList.begin(); aIt != aList.end(); ++aIt) { + FeaturePtr aFeature = boost::dynamic_pointer_cast(*aIt); + if (aFeature) + aFeaList.push_back(aFeature); } - return aPreviewMap; + return aFeaList; } void PartSet_OperationSketch::stopOperation() @@ -135,6 +165,16 @@ void PartSet_OperationSketch::stopOperation() PartSet_OperationSketchBase::stopOperation(); emit featureConstructed(feature(), FM_Hide); emit closeLocalContext(); + + FeaturePtr aFeature = feature(); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + 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(aFeature, + // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); } bool PartSet_OperationSketch::isNestedOperationsEnabled() const @@ -142,12 +182,12 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const return hasSketchPlane(); } + void PartSet_OperationSketch::startOperation() { - if (!feature()) { - setFeature(createFeature()); + PartSet_OperationSketchBase::startOperation(); + if (!isEditOperation()) emit fitAllView(); - } } bool PartSet_OperationSketch::hasSketchPlane() const @@ -156,9 +196,9 @@ bool PartSet_OperationSketch::hasSketchPlane() const if (feature()) { boost::shared_ptr aData = feature()->data(); - boost::shared_ptr anAttr; + AttributeDoublePtr anAttr; boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); } return aHasPlane; @@ -181,24 +221,35 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) double anA, aB, aC, aD; aPlane->coefficients(anA, aB, aC, aD); - boost::shared_ptr anAttr; - // temporary solution for main planes only + // calculate attributes of the sketch + boost::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); + boost::shared_ptr aCoords = aNormDir->xyz(); + boost::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); + aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); + boost::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); + // X axis is preferable to be dirX on the sketch + const double tol = Precision::Confusion(); + bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; + boost::shared_ptr aTempDir(isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); + boost::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); + boost::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); + boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - anOrigin->setValue(0, 0, 0); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + anOrigin->setValue(anOrigPnt); boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - aNormal->setValue(anA, aB, aC); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); + aNormal->setValue(aNormDir); boost::shared_ptr aDirX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); - aDirX->setValue(aB, aC, anA); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRX_ID())); + aDirX->setValue(aXDir); boost::shared_ptr aDirY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); - aDirY->setValue(aC, anA, aB); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRY_ID())); + aDirY->setValue(aYDir); boost::shared_ptr aDir = aPlane->direction(); flushUpdated(); - + emit featureConstructed(feature(), FM_Hide); emit closeLocalContext(); emit planeSelected(aDir->x(), aDir->y(), aDir->z());