From b240d1def415f30a9569bd71f6715c72c0a92291 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 18 Dec 2019 18:31:28 +0300 Subject: [PATCH] Issue #3123: Provide chain of create Angle constraint operations --- .../PartSet_WidgetFeaturePointSelector.cpp | 111 ++++++++---------- .../PartSet_WidgetFeaturePointSelector.h | 23 ++-- .../SketchPlugin_ConstraintAngle.cpp | 5 - src/SketchPlugin/SketchPlugin_Validators.cpp | 8 ++ 4 files changed, 67 insertions(+), 80 deletions(-) diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp index c5a4dec3b..4a58427c1 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp @@ -93,37 +93,6 @@ bool PartSet_WidgetFeaturePointSelector::isValidSelection( //return true; } -//******************************************************************** -void PartSet_WidgetFeaturePointSelector::updateSelectionModesAndFilters(bool toActivate) -{ -#ifdef HIGHLIGHT_STAYS_PROBLEM - Handle(AIS_InteractiveContext) aContext = - XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext(); - Quantity_Color aColor; - Handle(Prs3d_Drawer) aHStyle = aContext->HighlightStyle(); - Handle(Prs3d_Drawer) aSStyle = aContext->SelectionStyle(); - if (toActivate) { - std::vector aColors; - aColors = Config_PropManager::color("Visualization", "sketch_entity_color"); - aColor = Quantity_Color(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255., - Quantity_TOC_RGB); - myHighlightColor = aHStyle->Color(); - mySelectionColor = aSStyle->Color(); - } - else { - aColor = myHighlightColor; - } - aHStyle->SetColor(aColor); - aContext->SetHighlightStyle(aHStyle); - - aSStyle->SetColor(aColor); - aContext->SetSelectionStyle(aSStyle); - -#endif - - ModuleBase_WidgetShapeSelector::updateSelectionModesAndFilters(toActivate); -} - //******************************************************************** void PartSet_WidgetFeaturePointSelector::activateCustom() { @@ -148,7 +117,16 @@ void PartSet_WidgetFeaturePointSelector::mouseMoved(ModuleBase_IViewWindow* theW ModuleBase_ViewerPrsPtr aPrs = !aHighlighted.empty() ? aHighlighted.first() : ModuleBase_ViewerPrsPtr(); - fillFeature(aPrs, theWindow, theEvent); + myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch); + if (myHasPreview) { + if (aPrs.get() && aPrs->object().get()) + myPreviewObject = aPrs->object(); + else + myPreviewObject = ObjectPtr(); + fillFeature(); + updateObject(feature()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } } //******************************************************************** @@ -195,7 +173,7 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t return; // Do not use non-sketcher objects - if (!sketch()->isSub(myPreviewObject)) + if (!sketch()->isSub(aPreviewObject)) return; // set parameters of preview into parameters of selection in the feature @@ -224,38 +202,47 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t } //******************************************************************** -bool PartSet_WidgetFeaturePointSelector::fillFeature( - const std::shared_ptr& theSelectedPrs, - ModuleBase_IViewWindow* theWindow, - QMouseEvent* theEvent) +bool PartSet_WidgetFeaturePointSelector::fillFeature() { - bool aFilled = false; - if (theSelectedPrs.get() && theSelectedPrs->object().get()) - myPreviewObject = theSelectedPrs->object(); - myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch); - if (myHasPreview) { std::shared_ptr aRef = std::dynamic_pointer_cast( feature()->data()->attribute(myPreviewObjectAttribute)); aRef->setValue(myPreviewObject); - - std::shared_ptr anAttributePoint = - std::dynamic_pointer_cast( - feature()->data()->attribute(myPreviewPointAttribute)); - anAttributePoint->setValue(myPreviewPoint); + if (myPreviewPoint.get()) { + std::shared_ptr anAttributePoint = + std::dynamic_pointer_cast( + feature()->data()->attribute(myPreviewPointAttribute)); + anAttributePoint->setValue(myPreviewPoint); + } + } + else { + // Do not use non-sketcher objects + if (!sketch()->isSub(myPreviewObject)) + return false; + + // set parameters of preview into parameters of selection in the feature + if (myPreviewPoint.get()) { + std::shared_ptr aPointSelectedAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(mySelectedPointAttribute)); + aPointSelectedAttr->setValue(myPreviewPoint); + } + AttributeReferencePtr aRefSelectedAttr = feature()->reference(mySelectedObjectAttribute); + if (aRefSelectedAttr) + aRefSelectedAttr->setValue(myPreviewObject); + else { + AttributeRefAttrPtr aRefAttrSelectedAttr = feature()->refattr(mySelectedObjectAttribute); + if (aRefAttrSelectedAttr) + aRefAttrSelectedAttr->setObject(myPreviewObject); + } } // redisplay AIS presentation in viewer #ifndef HIGHLIGHT_STAYS_PROBLEM // an attempt to clear highlighted item in the viewer: but of OCCT XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true); #endif - updateObject(feature()); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - - aFilled = true; - - return aFilled; + return true; } //******************************************************************** @@ -265,16 +252,22 @@ QList PartSet_WidgetFeaturePointSelector::getAttributeS } //******************************************************************** -bool PartSet_WidgetFeaturePointSelector::setSelection( - QList>& theValues, - const bool theToValidate) +bool PartSet_WidgetFeaturePointSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) { - // false is returned to do not emit focus out widget by selected sub-shape - return false; + if (!thePrs.get() || !thePrs->object().get()) + return false; + + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + myPreviewObject = aSelection->getResult(thePrs); + GeomShapePtr aShape = aSelection->getShape(thePrs); + myExternalObjectMgr->getGeomSelection(thePrs, myPreviewObject, aShape, myWorkshop, + sketch(), true); + return fillFeature(); } +//******************************************************************** void PartSet_WidgetFeaturePointSelector::setPreSelection( - const std::shared_ptr& thePreSelected, + const ModuleBase_ViewerPrsPtr& thePreSelected, ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.h b/src/PartSet/PartSet_WidgetFeaturePointSelector.h index 445303133..36c6878f7 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.h +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.h @@ -22,6 +22,7 @@ #include #include +#include #include "PartSet.h" #include "PartSet_MouseProcessor.h" @@ -73,10 +74,6 @@ Q_OBJECT /// \return a boolean value virtual bool isValidSelection(const std::shared_ptr& theValue); - /// Activate or deactivate selection and selection filters - /// \return true if the selection filter of the widget is activated in viewer context - virtual void updateSelectionModesAndFilters(bool toActivate); - /// Set sketcher /// \param theSketch a sketcher object void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } @@ -97,17 +94,13 @@ Q_OBJECT /// \param theEvent a mouse event virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent); - /// Set the given wrapped value to the current widget - /// This value should be processed in the widget according to the needs - /// The method is called by the current operation to process the operation preselection. - /// It is redefined to fill attributes responsible for the sub selection - /// \param theValues the wrapped selection values - /// \param theToValidate a flag on validation of the values - virtual bool setSelection(QList>& theValues, - const bool theToValidate); + + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs); /// Fill preselection used in mouseReleased - virtual void setPreSelection(const std::shared_ptr& thePreSelected, + virtual void setPreSelection(const ModuleBase_ViewerPrsPtr& thePreSelected, ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); protected: @@ -134,9 +127,7 @@ protected: void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid); protected: - bool fillFeature(const std::shared_ptr& theSelectedPrs, - ModuleBase_IViewWindow* theWnd, - QMouseEvent* theEvent); + bool fillFeature(); /// Pointer to a sketch CompositeFeaturePtr mySketch; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 10d27ee1c..861f37731 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -131,11 +131,6 @@ void SketchPlugin_ConstraintAngle::execute() GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if(!aFlyOutAttr->isInitialized()) compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); - - static Events_ID anId = ModelAPI_EventReentrantMessage::eventId(); - std::shared_ptr aMessage( - new ModelAPI_EventReentrantMessage(anId, this)); - Events_Loop::loop()->send(aMessage); } AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious) diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 454a476ee..8e1bccbf6 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -946,8 +946,16 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, } AttributeReferencePtr aFeatureAttr = std::dynamic_pointer_cast(theAttribute); + std::shared_ptr aSplitFeature = + std::dynamic_pointer_cast(theAttribute->owner()); ObjectPtr anAttrObject = aFeatureAttr->value(); + if (!anAttrObject) { + AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()); + aFeatureAttr = std::dynamic_pointer_cast(aPreviewAttr); + anAttrObject = aFeatureAttr->value(); + } + FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject); if (!anAttrFeature) return aValid; -- 2.39.2