From: vsv Date: Thu, 30 May 2019 07:30:20 +0000 (+0300) Subject: Issue #2923: Change sketch plane X-Git-Tag: VEDF2019Lot4~114^2~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4fcd7c5e40f2bdbb084fa348afd5dcce7ba9882a;p=modules%2Fshaper.git Issue #2923: Change sketch plane --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 0e6514374..8ba7db2cb 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -205,7 +205,7 @@ Q_OBJECT virtual void updateAfterActivation() {} /// The method called if widget should be activated always - virtual bool needToBeActiated() { return false; } + virtual bool needToBeActivated() { return false; } /// Returns list of widget controls /// \return a control list diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 65be58122..ee3f43ae5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -177,6 +177,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop)); registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop)); @@ -1512,6 +1513,12 @@ void PartSet_Module::processEvent(const std::shared_ptr& theMess } } } + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { + CompositeFeaturePtr aSketch = mySketchMgr->activeSketch(); + if (aSketch.get()) { + mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop); + } + } } //****************************************************** diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index f8790b45a..55db2ece6 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -64,45 +64,43 @@ void PartSet_PreviewSketchPlane::eraseSketchPlane(ModuleBase_IWorkshop* theWorks void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch, ModuleBase_IWorkshop* theWorkshop) { - // the preview plane has been already created and displayed - if (myPreviewIsDisplayed) - return; - // plane is visualized only if sketch plane is filled if (!PartSet_Tools::sketchPlane(theSketch).get()) return; - if (!myPlane) { // If planes are not created - // Create Preview - // selected linear face parameters - AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr) { - myShape = aSelAttr->value(); - // this case is needed by constructing sketch on a plane, where result shape is equal - // to context result, therefore value() returns NULL and we should use shape of context. - if (!myShape.get() && aSelAttr->context().get()) - myShape = aSelAttr->context()->shape(); - } - 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())); - - double aFaceSize = myIsUseSizeOfView ? mySizeOfView - : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size"); - if (aFaceSize <= Precision::Confusion()) - aFaceSize = 200; // Set default value - - myShape = GeomAlgoAPI_FaceBuilder::squareFace( - myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize); - } - myPlane = createPreviewPlane(); + XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); + if (myPreviewIsDisplayed) { + aDisp->eraseAIS(myPlane, false); } - XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer(); + // Create Preview + // selected linear face parameters + AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast + (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr) { + myShape = aSelAttr->value(); + // this case is needed by constructing sketch on a plane, where result shape is equal + // to context result, therefore value() returns NULL and we should use shape of context. + if (!myShape.get() && aSelAttr->context().get()) + myShape = aSelAttr->context()->shape(); + } + 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())); + + double aFaceSize = myIsUseSizeOfView ? mySizeOfView + : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size"); + if (aFaceSize <= Precision::Confusion()) + aFaceSize = 200; // Set default value + + myShape = GeomAlgoAPI_FaceBuilder::squareFace( + myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize); + } + myPlane = createPreviewPlane(); + aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false); myPreviewIsDisplayed = true; } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 5779d33bb..3ef5b735f 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -311,6 +311,17 @@ std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theS return aPlane; } +void PartSet_Tools::nullifySketchPlane(CompositeFeaturePtr theSketch) +{ + 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())); + + aNormal->reset(); + anOrigin->reset(); +} + std::shared_ptr PartSet_Tools::point3D(std::shared_ptr thePoint2D, CompositeFeaturePtr theSketch) { diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 0bd4159c4..0de36c1e2 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -143,6 +143,11 @@ public: /// \return API object of geom plane static std::shared_ptr sketchPlane(CompositeFeaturePtr theSketch); + /// Create a sketch plane instance + /// \param theSketch a sketch feature + /// \return API object of geom plane + static void nullifySketchPlane(CompositeFeaturePtr theSketch); + /// Create a point 3D on a basis of point 2D and sketch feature /// \param thePoint2D a point on a sketch /// \param theSketch a sketch feature diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 7f4fcd8ae..f8e8d3924 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -84,7 +85,7 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const QMap& toShowConstraints) -: ModuleBase_WidgetValidated(theParent, theWorkshop, theData) +: ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false) { QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -160,6 +161,11 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, aShowConstraints->setChecked(toShowConstraints[aState]); } + + QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt); + connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane())); + aLayout->addWidget(aPlaneBtn); + myStackWidget->addWidget(aSecondWgt); //setLayout(aLayout); @@ -331,6 +337,11 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs if (aModule) aModule->onViewTransformed(); + if (myOpenTransaction) { + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->finishOperation(); + myOpenTransaction = false; + } // 3. Clear text in the label myStackWidget->setCurrentIndex(1); //myLabel->setText(""); @@ -643,3 +654,30 @@ QList> PartSet_WidgetSketchLabel::findCirc } return aResult; } + +//****************************************************** +void PartSet_WidgetSketchLabel::onChangePlane() +{ + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + if (aModule) { + mySizeOfViewWidget->setVisible(false); + myStackWidget->setCurrentIndex(0); + + CompositeFeaturePtr aSketch = std::dynamic_pointer_cast(myFeature); + PartSet_Tools::nullifySketchPlane(aSketch); + + Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter); + if (!aFilter.IsNull()) { + std::shared_ptr aPln; + Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln); + } + XGUI_Workshop* aWorkshop = aModule->getWorkshop(); + + aWorkshop->selectionActivate()->updateSelectionFilters(); + aWorkshop->selectionActivate()->updateSelectionModes(); + + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->startOperation(); + myOpenTransaction = true; + } +} \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 3bfcf883c..6f7b1a8d0 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -91,7 +91,7 @@ public: virtual void deactivate(); /// The method called if widget should be activated always - virtual bool needToBeActiated() { return true; } + virtual bool needToBeActivated() { return true; } /// Returns sketcher plane std::shared_ptr plane() const; @@ -192,6 +192,8 @@ private slots: /// \param theOn a flag show constraints or not void onShowConstraint(bool theOn); + void onChangePlane(); + private: /// Set sketch plane by shape /// \param theShape a planar face @@ -219,6 +221,8 @@ private: QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown QLineEdit* mySizeOfView; ///< Value of square of size of View QStackedWidget* myStackWidget; + + bool myOpenTransaction; }; #endif diff --git a/src/XGUI/XGUI_ActiveControlMgr.cpp b/src/XGUI/XGUI_ActiveControlMgr.cpp index beffebcee..775985d76 100644 --- a/src/XGUI/XGUI_ActiveControlMgr.cpp +++ b/src/XGUI/XGUI_ActiveControlMgr.cpp @@ -106,7 +106,7 @@ void XGUI_ActiveControlMgr::onSelectorDeactivated() XGUI_ActiveControlSelector* aSelectorToBeActivated = 0; for (int i = 0, aCount = mySelectors.count(); i < aCount; i++) { - if (!mySelectors[i]->needToBeActiated()) + if (!mySelectors[i]->needToBeActivated()) continue; aSelectorToBeActivated = mySelectors[i]; break; diff --git a/src/XGUI/XGUI_ActiveControlSelector.h b/src/XGUI/XGUI_ActiveControlSelector.h index eb4500084..f39abd8cf 100644 --- a/src/XGUI/XGUI_ActiveControlSelector.h +++ b/src/XGUI/XGUI_ActiveControlSelector.h @@ -59,7 +59,7 @@ public: /// Returns whether the selector should be activated as soon as possible (by deactivatate other) /// \return boolean result - XGUI_EXPORT virtual bool needToBeActiated() const { return false; } + XGUI_EXPORT virtual bool needToBeActivated() const { return false; } /// Processes current selection of workshop. Reaction to selection change in workshop. XGUI_EXPORT virtual void processSelection() = 0; diff --git a/src/XGUI/XGUI_PropertyPanelSelector.cpp b/src/XGUI/XGUI_PropertyPanelSelector.cpp index 8e797ebc5..c206ab95a 100644 --- a/src/XGUI/XGUI_PropertyPanelSelector.cpp +++ b/src/XGUI/XGUI_PropertyPanelSelector.cpp @@ -46,7 +46,7 @@ void XGUI_PropertyPanelSelector::setActive(const bool& isActive) if (!isActive) { // on deactivating, store previous active widget ModuleBase_ModelWidget* aWidget = myPanel->activeWidget(); - if (aWidget && aWidget->needToBeActiated()) + if (aWidget && aWidget->needToBeActivated()) { myWidgetToBeActivated = aWidget; } @@ -55,7 +55,7 @@ void XGUI_PropertyPanelSelector::setActive(const bool& isActive) } //******************************************************************** -bool XGUI_PropertyPanelSelector::needToBeActiated() const +bool XGUI_PropertyPanelSelector::needToBeActivated() const { return myWidgetToBeActivated != NULL; } diff --git a/src/XGUI/XGUI_PropertyPanelSelector.h b/src/XGUI/XGUI_PropertyPanelSelector.h index 2341f0913..522562750 100644 --- a/src/XGUI/XGUI_PropertyPanelSelector.h +++ b/src/XGUI/XGUI_PropertyPanelSelector.h @@ -56,7 +56,7 @@ public: /// Returns whether the selector should be activated as soon as possible (by deactivatate other) /// \return boolean result - XGUI_EXPORT virtual bool needToBeActiated() const; + XGUI_EXPORT virtual bool needToBeActivated() const; /// Processes current selection of workshop. Reaction to selection change in workshop. XGUI_EXPORT virtual void processSelection();