X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketch.cpp;h=acd79461dc773c4fb58ba4c62a7b4c97329fe1e3;hb=5bac8bac0b4cd2e4520c0908b2863d747e411fb9;hp=81ba69a079ed80f19ec060c3fe2421f137378751;hpb=b4881868428f03a06a6301539aa92ca16dbe5bed;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 81ba69a07..acd79461d 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -39,10 +39,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) + : PartSet_OperationSketchBase(theId, theParent) { } @@ -61,7 +59,6 @@ std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) return aModes; } - /// Initializes the operation with previously created feature. It is used in sequental operations void PartSet_OperationSketch::initFeature(FeaturePtr theFeature) { @@ -78,7 +75,7 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie const std::list& theSelected, const std::list& theHighlighted) { - if (hasSketchPlane()){ + 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); @@ -88,13 +85,12 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie if (theHighlighted.size() == 1) { ObjectPtr aFeature = theHighlighted.front().object(); if (aFeature) { - std::string anOperationType = (theSelected.size() > 1)? - PartSet_OperationFeatureEditMulti::Type() : - PartSet_OperationFeatureEdit::Type(); + std::string anOperationType = + (theSelected.size() > 1) ? + PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type(); restartOperation(anOperationType, aFeature); } - } - else + } else myFeatures = theHighlighted; } else { @@ -117,23 +113,24 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi /// 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); + ObjectPtr aObject = theSelected.front().object(); + if (aObject) { + restartOperation(PartSet_OperationFeatureEdit::Type(), aObject); + } } } } void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { - if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) + 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(PartSet_OperationFeatureEditMulti::Type(), aFeature); + restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature); } } @@ -147,8 +144,8 @@ std::list PartSet_OperationSketch::subFeatures() const boost::shared_ptr aData = aFeature->data(); if (!aData->isValid()) return std::list(); - boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); + boost::shared_ptr aRefList = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); std::list aList = aRefList->list(); std::list::iterator aIt; @@ -170,8 +167,8 @@ void PartSet_OperationSketch::stopOperation() 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( + *aIt, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); } //ModelAPI_EventCreator::get()->sendUpdated(aFeature, // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); @@ -182,7 +179,6 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const return hasSketchPlane(); } - void PartSet_OperationSketch::startOperation() { PartSet_OperationSketchBase::startOperation(); @@ -197,8 +193,8 @@ bool PartSet_OperationSketch::hasSketchPlane() const if (feature()) { boost::shared_ptr aData = feature()->data(); AttributeDoublePtr anAttr; - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); + boost::shared_ptr aNormal = boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::NORM_ID())); aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); } return aHasPlane; @@ -230,27 +226,36 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) // 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 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(SketchPlugin_Sketch::ORIGIN_ID())); + boost::shared_ptr anOrigin = boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); anOrigin->setValue(anOrigPnt); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::NORM_ID())); + boost::shared_ptr aNormal = boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::NORM_ID())); aNormal->setValue(aNormDir); - boost::shared_ptr aDirX = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRX_ID())); + boost::shared_ptr aDirX = boost::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::DIRX_ID())); aDirX->setValue(aXDir); - boost::shared_ptr aDirY = - boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Sketch::DIRY_ID())); + boost::shared_ptr aDirY = 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()); } + + +bool PartSet_OperationSketch::isValid(ModuleBase_IOperation* theOperation) const +{ + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); + return aPreviewOp != NULL; +} +