From 3458278452f372451f98d4b26f418c9673e5b0bf Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 3 Oct 2017 19:34:58 +0300 Subject: [PATCH] Issue #2204 Display a sketch plane - highlight only source plane, do not create wrapping rectangle. --- src/ModuleBase/ModuleBase_IModule.h | 3 - src/PartSet/PartSet_Module.cpp | 6 - src/PartSet/PartSet_Module.h | 3 - src/PartSet/PartSet_PreviewSketchPlane.cpp | 173 ++++----------------- src/PartSet/PartSet_PreviewSketchPlane.h | 51 +----- src/PartSet/PartSet_SketcherMgr.cpp | 1 - src/PartSet/PartSet_WidgetSketchLabel.cpp | 30 +--- src/XGUI/XGUI_OperationMgr.cpp | 7 - src/XGUI/XGUI_OperationMgr.h | 3 - src/XGUI/XGUI_Workshop.cpp | 2 - 10 files changed, 38 insertions(+), 241 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 8295af761..995e21fe8 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -309,9 +309,6 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theStdActions - a map of standard actions virtual void updateViewerMenu(const QMap& theStdActions) {} - /// Updates the current operation state after undo/redo actions calling - virtual void updateOperationByUndoRedo() {} - /// Returns true if the action should be always enabled /// \param theActionId an action index: Accept or Accept All /// \return boolean value diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 078b18236..282f82889 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -550,12 +550,6 @@ void PartSet_Module::updateViewerMenu(const QMap& theStdActio myMenuMgr->updateViewerMenu(theStdActions); } -void PartSet_Module::updateOperationByUndoRedo() -{ - PartSet_SketcherMgr* aSketchMgr = sketchMgr(); - aSketchMgr->previewSketchPlane()->updatePlaneSize(aSketchMgr->activeSketch(), workshop()); -} - bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const { bool isEnabledFixed = false; diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index cc9bd9ed5..4a70c942f 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -331,9 +331,6 @@ public: /// \param theStdActions - a map of standard actions virtual void updateViewerMenu(const QMap& theStdActions); - /// Updates the current operation state after undo/redo actions calling - virtual void updateOperationByUndoRedo(); - /// Returns true if the action should be always enabled /// \param theActionId an action index: Accept or Accept All /// \return boolean value diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index 28b5c8491..bb60cc17d 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include @@ -40,134 +40,70 @@ #include #include -#include - -double maximumSize(double theXmin, double theYmin, double theZmin, - double theXmax, double theYmax, double theZmax) -{ - double aSize = fabs(theXmax - theXmin); - double aSizeToCompare = fabs(theYmax - theYmin); - if (aSizeToCompare > aSize) - aSize = aSizeToCompare; - aSizeToCompare = fabs(theZmax - theZmin); - if (aSizeToCompare > aSize) - aSize = aSizeToCompare; - - return aSize; -} - PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane() - : mySketchDisplayed(false), myOtherSketchSize(0) -{ -} - -void PartSet_PreviewSketchPlane::setOtherSketchParameters(const GeomShapePtr& theOtherSketchFace) + : myPreviewIsDisplayed(false) { - myOtherSketchOrigin = std::shared_ptr(); - myOtherSketchSize = 0; - if (!theOtherSketchFace) - return; - - getShapeParameters(theOtherSketchFace, myOtherSketchOrigin, myOtherSketchSize); } void PartSet_PreviewSketchPlane::eraseSketchPlane(ModuleBase_IWorkshop* theWorkshop, const bool isClearPlane) { - if (mySketchDisplayed) { + if (myPreviewIsDisplayed) { XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); aDisp->eraseAIS(myPlane, false); if (isClearPlane) { myPlane = NULL; - myOrigin = NULL; - myNormal = NULL; + myShape = NULL; } - mySketchDisplayed = false; + myPreviewIsDisplayed = false; } } void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch, ModuleBase_IWorkshop* theWorkshop) { - if (mySketchDisplayed) + // the preview plane has been already created and displayed + if (myPreviewIsDisplayed) return; // plane is visualized only if sketch plane is filled - std::shared_ptr aPlane = PartSet_Tools::sketchPlane(theSketch); - if (!aPlane.get()) + if (!PartSet_Tools::sketchPlane(theSketch).get()) return; if (!myPlane) { // If planes are not created - std::shared_ptr anOrigin = std::dynamic_pointer_cast( - theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNormal = std::dynamic_pointer_cast( - theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - // Create Preview - // default planes parameters - std::shared_ptr anOriginPnt = anOrigin->pnt(); - double aSize = Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"); - // another sketch parameters - if (myOtherSketchOrigin) { - anOriginPnt = myOtherSketchOrigin; - aSize = myOtherSketchSize; - setOtherSketchParameters(GeomShapePtr()); - } - else { - // selected linear face parameters - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - std::shared_ptr aSketchExternalFace = aSelAttr->value(); - if (aSketchExternalFace) - getShapeParameters(aSketchExternalFace, anOriginPnt, aSize); - } + // selected linear face parameters + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) + myShape = aSelAttr->value(); + + if (!myShape.get()) { + // Create Preview for default planes + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(), + Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size")); } - double aSketchSize = getSketchBoundingBoxSize(theSketch, anOriginPnt); - if (aSketchSize > 0) - aSize = aSketchSize; - - myOrigin = anOriginPnt; - myNormal = aNormal->dir(); - myPlane = createPreviewPlane(aSize); + myPlane = createPreviewPlane(); } XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); aDisp->displayAIS(myPlane, true, 1/*shaded*/, false); - mySketchDisplayed = true; -} - -void PartSet_PreviewSketchPlane::updatePlaneSize(const CompositeFeaturePtr& theSketch, - ModuleBase_IWorkshop* theWorkshop) -{ - std::shared_ptr anOriginPnt; - double aSize = getSketchBoundingBoxSize(theSketch, anOriginPnt); - if (aSize <= 0) - return; - myOrigin = anOriginPnt; - createPreviewPlane(aSize); + myPreviewIsDisplayed = true; } -AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize) +AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane() { - std::vector aYZRGB(3, 0); -#ifdef SET_PLANES_COLOR_IN_PREFERENCES - aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color"); -#else - aYZRGB[0] = 225; -#endif - int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]}; - - std::shared_ptr aFace = - GeomAlgoAPI_FaceBuilder::squareFace(myOrigin, myNormal, theSize); - if (myPlane.get()) { - myPlane->createShape(aFace); + myPlane->createShape(myShape); return myPlane; } else { AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject()); - aAIS->createShape(aFace); + aAIS->createShape(myShape); std::vector aColor = Config_PropManager::color("Visualization", "sketch_preview_plane"); if (aColor.size() == 3) aAIS->setColor(aColor[0], aColor[1], aColor[2]); @@ -182,58 +118,3 @@ AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize) return aAIS; } } - -void PartSet_PreviewSketchPlane::getShapeParameters(const GeomShapePtr& theShape, - std::shared_ptr& theOrigin, - double& theSize) -{ - theOrigin = GeomAlgoAPI_ShapeTools::centreOfMass(theShape); - - // Create rectangular face close to the selected - double aXmin, anYmin, aZmin, aXmax, anYmax, aZmax; - theShape->computeSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - - theSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); -} - -double PartSet_PreviewSketchPlane::getSketchBoundingBoxSize( - const std::shared_ptr& theSketch, - std::shared_ptr& theCentralPnt) -{ - if (!theSketch.get() || theSketch->numberOfSubs() == 0) - return 0; - - Bnd_Box aBox; - for (int aSubFeatureId = 0; aSubFeatureId < theSketch->numberOfSubs(); aSubFeatureId++) { - FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId); - if (!aFeature.get()) - continue; - - std::list aResults = aFeature->results(); - std::list::const_iterator aResultIt; - for (aResultIt = aResults.begin(); aResultIt != aResults.end(); ++aResultIt) { - ResultPtr aResult = *aResultIt; - std::shared_ptr aShapePtr = aResult->shape(); - if (aShapePtr.get()) { - TopoDS_Shape aShape = aShapePtr->impl(); - if (aShape.IsNull()) - continue; - BRepBndLib::Add(aShape, aBox); - } - } - } - if (aBox.IsVoid()) - return 0; - - double aXmin, aXmax, anYmin, anYmax, aZmin, aZmax; - aBox.Get(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - - double aSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax); - if (aSize > 0) { - gp_Pnt aCentre(aXmax-fabs(aXmax-aXmin)/2., anYmax-fabs(anYmax-anYmin)/2., - aZmax - fabs(aZmax-aZmin)/2.); - theCentralPnt = std::shared_ptr(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), - aCentre.Z())); - } - return aSize; -} \ No newline at end of file diff --git a/src/PartSet/PartSet_PreviewSketchPlane.h b/src/PartSet/PartSet_PreviewSketchPlane.h index b2d32c843..11eabebd6 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.h +++ b/src/PartSet/PartSet_PreviewSketchPlane.h @@ -21,15 +21,14 @@ #ifndef PartSet_PreviewSketchPlane_H #define PartSet_PreviewSketchPlane_H -#include - -#include -#include -#include +class GeomAPI_AISObject; +class GeomAPI_Shape; class ModuleBase_IWorkshop; class ModelAPI_CompositeFeature; +#include + /** * \class PartSet_PreviewSketchPlane * \ingroup Modules @@ -43,14 +42,6 @@ public: ~PartSet_PreviewSketchPlane() {}; - /// Returns if the sketch plane was displayed - /// \return boolean value - bool isSketchDisplayed() const { return mySketchDisplayed; } - - /// Sets parameters of another sketch to be used in createSketchPlane(). - /// \param theOtherSketchFace a shape of other selected sketch. It is a planar face. - void setOtherSketchParameters(const std::shared_ptr& theOtherSketchFace); - /// Erase preview planes /// \param theWorkshop the application workshop /// \param isClearPlane flag whether the plane, origin and normal should be nullified @@ -62,40 +53,14 @@ public: void createSketchPlane(const std::shared_ptr& theSketch, ModuleBase_IWorkshop* theWorkshop); - /// Resize plane size by sketch content - /// \param theSketch source sketch to build sketch sub features bounding box - /// \param theWorkshop the application workshop - void updatePlaneSize(const std::shared_ptr& theSketch, - ModuleBase_IWorkshop* theWorkshop); - private: /// Create a square face by parameters - /// \param theSize a size of created square - AISObjectPtr createPreviewPlane(double theSize); - - /// Finds origin and maximum size of the shape - /// \param theShape source shape - /// \param theOrigin a shape center of mass - /// \param theSize maximum of delta X, Y or Z - void getShapeParameters(const std::shared_ptr& theShape, - std::shared_ptr& theOrigin, - double& theSize); - - /// Calculate maximum bounding box size of sketch sub features - /// \param theSketch source sketch to build sketch sub features bounding box - /// \param theCentralPoint central point of the sketch sub features - /// \return double value - double getSketchBoundingBoxSize(const std::shared_ptr& theSketch, - std::shared_ptr& theCentralPnt); + std::shared_ptr createPreviewPlane(); private: - bool mySketchDisplayed; - AISObjectPtr myPlane; - std::shared_ptr myOrigin; //! an origin of the plane - std::shared_ptr myNormal; //! a normal vector of the plane - - std::shared_ptr myOtherSketchOrigin; - double myOtherSketchSize; + bool myPreviewIsDisplayed; + std::shared_ptr myPlane; //! visualized presentation + std::shared_ptr myShape; //! current shape to be displayed }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 88334e9ee..abaadd311 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -1118,7 +1118,6 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) { - previewSketchPlane()->updatePlaneSize(activeSketch(), myModule->workshop()); myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); // when sketch nested operation is stopped the cursor should be restored unconditionally diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 8485a1b49..d3908d81e 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -277,20 +277,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); if (aModule) { - // if selected object is a shape of another sketch, the origin of selected shape does not stored - // in argument, so we need to find parameters of selected shape on the sketch - if (thePrs->object() && (feature() != thePrs->object())) { - FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object()); - if (aFeature.get() && (aFeature != feature())) { - if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { - CompositeFeaturePtr aSketch = - std::dynamic_pointer_cast(aFeature); - std::shared_ptr aPlane = PartSet_Tools::sketchPlane(aSketch); - if (aPlane.get()) - aModule->sketchMgr()->previewSketchPlane()->setOtherSketchParameters(thePrs->shape()); - } - } - } CompositeFeaturePtr aSketch = std::dynamic_pointer_cast(myFeature); aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop); } @@ -314,7 +300,8 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs // If the selected object is a sketch then use its plane std::shared_ptr aPlane; ObjectPtr aObj = thePrs->object(); - if (aObj.get()) { + // obsolete as selected sketch is stored in external attribute + /*if (aObj.get()) { FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); if (aFeature.get() && (aFeature != feature())) { if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { @@ -323,7 +310,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs aPlane = PartSet_Tools::sketchPlane(aSketch); } } - } + }*/ if (aGShape.get() != NULL) { // get plane parameters if (!aPlane.get()) { @@ -472,17 +459,6 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View if (thePrs->object() && (feature() != thePrs->object())) { FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object()); - if (aFeature.get() && (aFeature != feature())) { - if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { - CompositeFeaturePtr aSketch = - std::dynamic_pointer_cast(aFeature); - std::shared_ptr aPlane = PartSet_Tools::sketchPlane(aSketch); - if (aPlane.get()) { - aDir = setSketchPlane(aPlane); - return aDir.get(); - } - } - } DataPtr aData = feature()->data(); AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 3c6073c7f..6abe0d130 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -316,13 +316,6 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati onValidateOperation(); } -void XGUI_OperationMgr::updateOperationByUndoRedo() -{ - ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) - aModule->updateOperationByUndoRedo(); -} - bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation, const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind) { diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index b180436b3..97cc7426c 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -181,9 +181,6 @@ public: // TEMPORARY, it should be protected and be performed automatically /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent. void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0); - /// Updates the current operation state after undo/redo actions calling - void updateOperationByUndoRedo(); - protected: // TEMPORARY /// Sets the current operation or NULL /// \param theOperation the started operation diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 05f7d43f2..7a11ee1bb 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -999,7 +999,6 @@ void XGUI_Workshop::onUndo(int theTimes) } operationMgr()->updateApplyOfOperations(); - operationMgr()->updateOperationByUndoRedo(); updateCommandStatus(); } @@ -1028,7 +1027,6 @@ void XGUI_Workshop::onRedo(int theTimes) myObjectBrowser->rebuildDataTree(); } operationMgr()->updateApplyOfOperations(); - operationMgr()->updateOperationByUndoRedo(); updateCommandStatus(); // unblock the viewer update functionality and make update on purpose -- 2.39.2