X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketch.cpp;h=e57a113b73ebc39cc1a6cd82a708afc48c8c795d;hb=ad247cf594a7a560b656c70c96e1b1a360b8c1c3;hp=3b4e5bd8d89b49ab98a2a5e8c4f1175ce350a656;hpb=2eeb7eb916ca36bb522a2c65011d2bb8b0894fbc;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 3b4e5bd8d..e57a113b7 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -1,31 +1,169 @@ +// File: PartSet_OperationSketch.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + #include -#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include #ifdef _DEBUG #include #endif +#include + using namespace std; PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) -: PartSet_OperationSketchBase(theId, theParent) +: PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false) { } -/*! - * \brief Destructor - */ PartSet_OperationSketch::~PartSet_OperationSketch() { } -/** - * The sketch can not be created immediately, firstly a plane should be set - * \return false value - */ -bool PartSet_OperationSketch::isPerformedImmediately() const +std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature) const +{ + std::list aModes; + if (!myIsEditMode) + aModes.push_back(TopAbs_FACE); + else + aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); + return aModes; +} + +boost::shared_ptr PartSet_OperationSketch::sketch() const { - return false; + return feature(); +} + +void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& /*theSelected*/, + const std::list& theHighlighted) +{ + if (!myIsEditMode) { + XGUI_ViewerPrs aPrs = theHighlighted.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + setSketchPlane(aShape); + myIsEditMode = true; + } + } + else { + if (theHighlighted.size() == 1) { + boost::shared_ptr aFeature = theHighlighted.front().feature(); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + } + else + myFeatures = theHighlighted; + } +} + +void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +{ + if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) + return; + + if (myFeatures.size() != 1) { + boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), + theView, feature(), myFeatures); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); + } +} + +std::map, boost::shared_ptr > + PartSet_OperationSketch::subPreview() const +{ + std::map, boost::shared_ptr > aPreviewMap; + + boost::shared_ptr aFeature; + + boost::shared_ptr aData = feature()->data(); + 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(); +} + +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); + + boost::shared_ptr anAttr; + /* + aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA); + aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB); + aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC); + aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD); + */ + // temporary solution for main planes only + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + anOrigin->setValue(0, 0, 0); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + aNormal->setValue(anA, aB, aC); + boost::shared_ptr aDirX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + aDirX->setValue(aB, aC, anA); + boost::shared_ptr aDirY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + aDirY->setValue(aC, anA, aB); + boost::shared_ptr aDir = aPlane->direction(); + + flushUpdated(); + + emit featureConstructed(feature(), FM_Hide); + emit closeLocalContext(); + emit planeSelected(aDir->x(), aDir->y(), aDir->z()); }