X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketch.cpp;h=fdf2ff6721173667c5ac723faaf663ac3fa9df94;hb=6f1da290c7a4db4432c28887ad9d4073c8d443cb;hp=2da18786e8835ea8c220f5dd8cbe9143270a03bb;hpb=9e13b623ba4b01a718693653ff25f2b84dff956d;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 2da18786e..fdf2ff672 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -3,9 +3,6 @@ // Author: Natalia ERMOLAEVA #include - -#include -#include #include #include @@ -14,20 +11,17 @@ #include #include #include +#include #include #include #include #include -#include - -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #ifdef _DEBUG #include @@ -37,9 +31,8 @@ using namespace std; -PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, - QObject* theParent) -: PartSet_OperationSketchBase(theId, theParent) +PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) + : ModuleBase_Operation(theId, theParent) { } @@ -47,203 +40,15 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(FeaturePtr theFeature) const -{ - std::list aModes; - if (!hasSketchPlane()) - aModes.push_back(TopAbs_FACE); - else - aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); - - return aModes; -} - -void PartSet_OperationSketch::init(FeaturePtr theFeature, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) -{ - setFeature(theFeature); -} - -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) -{ - if (!hasSketchPlane()) { - if (!theHighlighted.empty()) { - XGUI_ViewerPrs aPrs = theHighlighted.front(); - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) - setSketchPlane(aShape); - } - } - else { - // 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) { - FeaturePtr aFeature = theHighlighted.front().feature(); - if (aFeature) - restartOperation(getOperationType(aFeature), aFeature); - } - else - myFeatures = theHighlighted; - - } -} - -void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) -{ - if (!hasSketchPlane()) { - } - else { - if (theSelected.size() == 1) { - FeaturePtr aFeature = theSelected.front().feature(); - if (aFeature) - restartOperation(getOperationType(aFeature), aFeature); - } - } -} - -void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) -{ - if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) - return; - - if (myFeatures.size() != 1) { - FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(), - myFeatures); - if (aFeature) - restartOperation(getOperationType(aFeature), aFeature); - } -} - -std::map > - PartSet_OperationSketch::subPreview() const -{ - std::map > aPreviewMap; - - boost::shared_ptr aFeature; - - boost::shared_ptr aData = feature()->data(); - if (!aData->isValid()) - return aPreviewMap; - 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; - } - return aPreviewMap; -} - -void PartSet_OperationSketch::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - emit featureConstructed(feature(), FM_Hide); - emit closeLocalContext(); -} - bool PartSet_OperationSketch::isNestedOperationsEnabled() const { - return hasSketchPlane(); -} - -void PartSet_OperationSketch::startOperation() -{ - if (!feature()) { - setFeature(createFeature()); - emit fitAllView(); - } -} - -bool PartSet_OperationSketch::hasSketchPlane() const -{ - bool aHasPlane = false; - + bool aHasSketchPlane = false; if (feature()) { - boost::shared_ptr aData = feature()->data(); + std::shared_ptr aData = feature()->data(); AttributeDoublePtr anAttr; - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); - } - return aHasPlane; -} - -void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) -{ - if (theShape.IsNull()) - return; - - // get selected shape - boost::shared_ptr aGShape(new GeomAPI_Shape); - aGShape->setImpl(new TopoDS_Shape(theShape)); - - // get plane parameters - boost::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); - - // set plane parameters to feature - boost::shared_ptr aData = feature()->data(); - double anA, aB, aC, aD; - aPlane->coefficients(anA, aB, aC, aD); - - // 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(anOrigPnt); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - aNormal->setValue(aNormDir); - boost::shared_ptr aDirX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); - aDirX->setValue(aXDir); - boost::shared_ptr aDirY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); - 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()); -} - -std::string PartSet_OperationSketch::getOperationType(FeaturePtr theFeature) -{ - std::string aType = PartSet_OperationEditFeature::Type(); - - if (PartSet_Tools::isConstraintFeature(theFeature->getKind())) { - aType = PartSet_OperationEditConstraint::Type(); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::NORM_ID())); + aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); } - return aType; + return aHasSketchPlane; }