]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3123: Provide chain of create Angle constraint operations
authorvsv <vsv@opencascade.com>
Wed, 18 Dec 2019 15:31:28 +0000 (18:31 +0300)
committervsv <vsv@opencascade.com>
Wed, 18 Dec 2019 15:33:15 +0000 (18:33 +0300)
src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
src/PartSet/PartSet_WidgetFeaturePointSelector.h
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp

index c5a4dec3b83dc19eb63f36a9264749248dec0811..4a58427c1dc7a81e0a405084d078e2446510e8eb 100644 (file)
@@ -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<int> 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<ModuleBase_ViewerPrs>& 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<ModelAPI_AttributeReference> aRef =
                             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
                             feature()->data()->attribute(myPreviewObjectAttribute));
     aRef->setValue(myPreviewObject);
-
-    std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
-                    std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                    feature()->data()->attribute(myPreviewPointAttribute));
-    anAttributePoint->setValue(myPreviewPoint);
+    if (myPreviewPoint.get()) {
+      std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+          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<GeomDataAPI_Point2D> aPointSelectedAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+          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<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeS
 }
 
 //********************************************************************
-bool PartSet_WidgetFeaturePointSelector::setSelection(
-                                          QList<std::shared_ptr<ModuleBase_ViewerPrs>>& 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<ModuleBase_ViewerPrs>& thePreSelected,
+                                  const ModuleBase_ViewerPrsPtr& thePreSelected,
                                   ModuleBase_IViewWindow* theWnd,
                                   QMouseEvent* theEvent)
 {
index 445303133b239d8f484161de12757ef7dee54b72..36c6878f7b60e17701e089315ea3b6deea9909a0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <ModelAPI_CompositeFeature.h>
 #include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ViewerPrs.h>
 
 #include "PartSet.h"
 #include "PartSet_MouseProcessor.h"
@@ -73,10 +74,6 @@ Q_OBJECT
   /// \return a boolean value
   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& 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<std::shared_ptr<ModuleBase_ViewerPrs>>& 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<ModuleBase_ViewerPrs>& 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<ModuleBase_ViewerPrs>& theSelectedPrs,
-                   ModuleBase_IViewWindow* theWnd,
-                   QMouseEvent* theEvent);
+  bool fillFeature();
 
   /// Pointer to a sketch
   CompositeFeaturePtr mySketch;
index 10d27ee1c24069b400354b80b2b4404678d6f05b..861f37731cb591f66172cf88643d08a2c0390edb 100644 (file)
@@ -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<ModelAPI_EventReentrantMessage> aMessage(
-      new ModelAPI_EventReentrantMessage(anId, this));
-  Events_Loop::loop()->send(aMessage);
 }
 
 AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious)
index 454a476ee2a6498ceaad57ed083b46071744b8c5..8e1bccbf6c655d459453992cfb33d4a09a6b2f5e 100644 (file)
@@ -946,8 +946,16 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
   }
   AttributeReferencePtr aFeatureAttr =
             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+  std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
+    std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
 
   ObjectPtr anAttrObject = aFeatureAttr->value();
+  if (!anAttrObject) {
+    AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
+    aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
+    anAttrObject = aFeatureAttr->value();
+  }
+
   FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
   if (!anAttrFeature)
     return aValid;