]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. AttrRefAttribute...
authornds <nds@opencascade.com>
Tue, 26 Jul 2016 08:10:00 +0000 (11:10 +0300)
committernds <nds@opencascade.com>
Tue, 26 Jul 2016 08:10:28 +0000 (11:10 +0300)
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.h
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp

index 72e0738bf063600a6a2ac41ba643dbdc3a9fe028..9ec849c487ed452b608969c8ce90707dd1062a39 100755 (executable)
@@ -15,6 +15,8 @@
 #include <GeomDataAPI_Point2D.h>
 
 #include <GeomDataAPI_Point.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt2d.h>
 
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <ModelGeomAlgo_Point2D.h>
@@ -110,24 +112,65 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo
 }
 
 //********************************************************************
-bool PartSet_WidgetSubShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
+bool PartSet_WidgetSubShapeSelector::setSelection(
+                                          QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+                                          const bool theToValidate)
 {
-  bool aResult = ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
-
-  //if (aResult)
-  //GeomShapePtr aBaseShape = *anIt;
-  //           myCurrentSubShape->setShape(aBaseShape);
-  
-  FeaturePtr aFeature = feature();
-  AttributePoint2DPtr anAPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                     aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  AttributePoint2DPtr aBPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                     aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
-
+  bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
+
+  if (aResult && !theToValidate) {
+    ObjectPtr aBaseObject = myCurrentSubShape->object();
+    GeomShapePtr aBaseShape = myCurrentSubShape->shape();
+
+    if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
+
+      std::shared_ptr<GeomAPI_Pln> aSketchPlane = PartSet_Tools::sketchPlane(mySketch);
+      std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
+      std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
+      std::shared_ptr<GeomAPI_Pnt2d> aFirstPnt2D = aFirstPnt->to2D(aSketchPlane);
+      std::shared_ptr<GeomAPI_Pnt2d> aLastPnt2D = aLastPnt->to2D(aSketchPlane);
+
+      /// find the points in feature attributes
+      FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
+      std::list<AttributePtr> a2DPointAttributes = aBaseFeature->data()->attributes(
+                                                        GeomDataAPI_Point2D::typeId());
+      std::list<AttributePtr>::const_iterator anIt = a2DPointAttributes.begin(), 
+                                              aLast = a2DPointAttributes.end();
+      std::shared_ptr<GeomDataAPI_Point2D> aFirstPointAttr, aLastPointAttr;
+      for (; anIt != aLast; anIt++) {
+        std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = 
+                                      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+        if (aFirstPnt2D->isEqual(anAttributePoint->pnt()))
+          aFirstPointAttr = anAttributePoint;
+        else if (aLastPnt2D->isEqual(anAttributePoint->pnt()))
+          aLastPointAttr = anAttributePoint;
+      }
+      /// find the points in coincident features
+      if (!aFirstPointAttr.get() || !aLastPointAttr.get()) {
+        std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes = myCashedReferences[aBaseObject];
+        std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator aRefIt = aRefAttributes.begin(),
+                                                                        aRefLast = aRefAttributes.end();
+        for (; aRefIt != aRefLast; aRefIt++) {
+          std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = *aRefIt;
+          if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt()))
+              aFirstPointAttr = anAttributePoint;
+          if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt()))
+              aLastPointAttr = anAttributePoint;
+          if (aFirstPointAttr.get() && aLastPointAttr.get())
+            break;
+        }
+      }
 
-   //GeomDataAPI_Point2D anAPointAttr = aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())
-  //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
-  //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
+      FeaturePtr aFeature = feature();
+      AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+                                         aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+                                         aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      anAPointAttr->setAttr(aFirstPointAttr);
+      aBPointAttr->setAttr(aLastPointAttr);
+    }
+  }
 
   return aResult;
 }
@@ -144,6 +187,7 @@ void PartSet_WidgetSubShapeSelector::getHighlighted(
 void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject)
 {
   std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
+  std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
 
   // current feature
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
@@ -154,7 +198,6 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject
     GeomShapePtr aFeatureShape = *anEdgeShapes.begin();
 
     // coincidences to the feature
-    std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
     ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
                          aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
     // layed on feature coincidences to divide it on several shapes
@@ -174,6 +217,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject
     GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPoints, aShapes);
   }
   myCashedShapes[theObject] = aShapes;
+  myCashedReferences[theObject] = aRefAttributes;
 }
 
 //********************************************************************
index 86ac40a9df59f551cabd5eb5b585f2b8591812ad..5797683bba080dd31a5ba9e84d7f45dc6f1ffc7e 100644 (file)
@@ -14,6 +14,7 @@
 #include <PartSet_MouseProcessor.h>
 
 #include <ModelAPI_CompositeFeature.h>
+#include <GeomDataAPI_Point2D.h>
 
 #include <QObject>
 
@@ -67,9 +68,14 @@ Q_OBJECT
   /// \param theValues a list of presentations
   virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param thePrs a selected owner
-  virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+  /// 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);
 
 protected:
   /// Checks the widget validity. By default, it returns true.
@@ -93,6 +99,7 @@ protected:
 protected:
   std::shared_ptr<ModuleBase_ViewerPrs> myCurrentSubShape;
   std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
+  std::map<ObjectPtr, std::set<AttributePoint2DPtr> > myCashedReferences;
 
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
index 09f8dbcb6030459c7fdfccf8c25259259ecc7ccd..af88d14d0a561d4da10c56f6cf5c45ca45701bfb 100755 (executable)
@@ -15,7 +15,7 @@
 //#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeReference.h>
 //#include <ModelAPI_AttributeRefList.h>
-//#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_AttributeRefAttr.h>
 //#include <ModelAPI_Data.h>
 //#include <ModelAPI_Events.h>
 //#include <ModelAPI_Session.h>
@@ -71,8 +71,8 @@ SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit()
 void SketchPlugin_ConstraintSplit::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
 
   //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
   //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());