From ee32391a69cf3aa5bc7d0a4d6ec53150f1f4a467 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 18 Mar 2016 12:13:34 +0300 Subject: [PATCH] Issue #1343 Improvement of Extrusion and Revolution operations: sketch is filled by selected presentation. --- src/PartSet/PartSet_WidgetSketchCreator.cpp | 8 ++++++-- src/PartSet/PartSet_WidgetSketchCreator.h | 3 ++- src/PartSet/PartSet_WidgetSketchLabel.cpp | 15 +++++++++++---- src/PartSet/PartSet_WidgetSketchLabel.h | 6 +++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 71069fe36..874d917b1 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -6,6 +6,7 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" +#include "PartSet_WidgetSketchLabel.h" #include @@ -180,7 +181,7 @@ void PartSet_WidgetSketchCreator::onSelectionChanged() QList aSelected = getFilteredSelected(); if (aSelected.size() == 1) { // plane or planar face of not sketch object - startSketchOperation(); + startSketchOperation(aSelected.front()); } else if (aSelected.size() > 1) { QList::const_iterator anIt = aSelected.begin(), aLast = aSelected.end(); @@ -223,7 +224,7 @@ void PartSet_WidgetSketchCreator::onStarted() setVisibleSelectionControl(true); } -void PartSet_WidgetSketchCreator::startSketchOperation() +void PartSet_WidgetSketchCreator::startSketchOperation(const ModuleBase_ViewerPrs& theValue) { // Check that model already has bodies /*XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); @@ -254,6 +255,9 @@ void PartSet_WidgetSketchCreator::startSketchOperation() DocumentPtr aDoc = aMgr->activeDocument(); FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false); FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); + + PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, theValue); + aDoc->setCurrentFeature(aPreviousCurrentFeature, false); // start edit operation for the sketch diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index 7349d1615..e14352a0c 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -93,7 +93,8 @@ private slots: private: /// Append new Sketch, set the selected plane for the sketch and start Edit operation. - void startSketchOperation(); + /// \param theValue a selected object to obtain a plane for sketch + void startSketchOperation(const ModuleBase_ViewerPrs& theValue); private: std::string myAttributeListID; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 8718bf149..81ba4a898 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -316,14 +316,20 @@ void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid) } bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + return fillSketchPlaneBySelection(feature(), thePrs); +} + +bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature, + const ModuleBase_ViewerPrs& thePrs) { bool isOwnerSet = false; const GeomShapePtr& aShape = thePrs.shape(); std::shared_ptr aDir; - if (thePrs.object() && (feature() != thePrs.object())) { - DataPtr aData = feature()->data(); + if (thePrs.object() && (theFeature != thePrs.object())) { + DataPtr aData = theFeature->data(); AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); @@ -477,7 +483,8 @@ AISObjectPtr PartSet_WidgetSketchLabel::createPreviewPlane(std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape) +std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const FeaturePtr& theFeature, + const TopoDS_Shape& theShape) { if (theShape.IsNull()) return std::shared_ptr(); @@ -494,7 +501,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Top return std::shared_ptr(); // set plane parameters to feature - std::shared_ptr aData = feature()->data(); + std::shared_ptr aData = theFeature->data(); double anA, aB, aC, aD; aPlane->coefficients(anA, aB, aC, aD); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 90c291bcd..ff6689d1c 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -79,6 +79,9 @@ public: virtual void setHighlighted(bool) { /*do nothing*/ }; virtual void enableFocusProcessing(); + static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature, + const ModuleBase_ViewerPrs& thePrs); + signals: /// Signal on plane selection void planeSelected(const std::shared_ptr& thePln); @@ -163,7 +166,8 @@ protected: /// Set sketch plane by shape /// \param theShape a planar face - std::shared_ptr setSketchPlane(const TopoDS_Shape& theShape); + static std::shared_ptr setSketchPlane(const FeaturePtr& theFeature, + const TopoDS_Shape& theShape); /// Erase preview planes void erasePreviewPlanes(); -- 2.30.2