Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. Fill Split attributes...
authornds <nds@opencascade.com>
Tue, 26 Jul 2016 11:18:53 +0000 (14:18 +0300)
committernds <nds@opencascade.com>
Tue, 26 Jul 2016 11:18:53 +0000 (14:18 +0300)
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index a4e44a736698eb1ede7e54b2340645a77456a739..5e22fd68a9bb96c7c40a32c65a0db343b8c79236 100755 (executable)
@@ -395,32 +395,15 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
 
 std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
 {
-  std::shared_ptr<GeomAPI_Pln> aPlane;
+  std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+      theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
 
-  std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  if (aData) {
-    std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-        aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-    std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-    if (aNormal.get() && aNormal->isInitialized() &&
-        anOrigin.get() && anOrigin->isInitialized()) {
-      double adX = aNormal->x();
-      double adY = aNormal->y();
-      double adZ = aNormal->z();
-
-      if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
-        double aX = anOrigin->x();
-        double aY = anOrigin->y();
-        double aZ = anOrigin->z();
-        gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
-        double aA, aB, aC, aD;
-        aPln.Coefficients(aA, aB, aC, aD);
-        aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
-      }
-    }
-  }
-  return aPlane;
+  if (!anOrigin || !aNorm)
+    return std::shared_ptr<GeomAPI_Pln>();
+
+  return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
 }
 
 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
index 9ec849c487ed452b608969c8ce90707dd1062a39..2057b467c2ee848e2c79303e6af01c9e0f61753c 100755 (executable)
@@ -111,25 +111,46 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo
   }
 }
 
+//********************************************************************
+void PartSet_WidgetSubShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+                                                      ObjectPtr& theObject,
+                                                      GeomShapePtr& theShape)
+{
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  theObject = aSelection->getResult(thePrs);
+  if (!theObject.get() && myCurrentSubShape->object())
+    theObject = myCurrentSubShape->object();
+}
+
 //********************************************************************
 bool PartSet_WidgetSubShapeSelector::setSelection(
                                           QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
                                           const bool theToValidate)
 {
-  bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
-
-  if (aResult && !theToValidate) {
-    ObjectPtr aBaseObject = myCurrentSubShape->object();
-    GeomShapePtr aBaseShape = myCurrentSubShape->shape();
-
+  //if (theToValidate)
+  //  bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
+  //else {
+  // the sub-shape is selected, initial shape is not highlighted/selected, we need to use
+  // the sub-shape to fill attribute;
+  ObjectPtr aBaseObject = myCurrentSubShape->object();
+  GeomShapePtr aBaseShape = myCurrentSubShape->shape();
+  bool aResult = aBaseObject.get() && aBaseShape.get();
+  // firstly set the selection to the attribute
+  if (aResult) {
+    QList<ModuleBase_ViewerPrsPtr> aValues;
+    aValues.append(myCurrentSubShape);
+    aResult = ModuleBase_WidgetShapeSelector::setSelection(aValues, theToValidate);
+  }
+  // secondly fill additional attributes
+  if (aResult) {
     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);
+      std::shared_ptr<GeomAPI_Pnt2d> aFirstPnt2D = PartSet_Tools::convertTo2D(mySketch, aFirstPnt);
+      std::shared_ptr<GeomAPI_Pnt2d> aLastPnt2D = PartSet_Tools::convertTo2D(mySketch, aLastPnt);
+
 
       /// find the points in feature attributes
       FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
@@ -153,6 +174,8 @@ bool PartSet_WidgetSubShapeSelector::setSelection(
                                                                         aRefLast = aRefAttributes.end();
         for (; aRefIt != aRefLast; aRefIt++) {
           std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = *aRefIt;
+          double anX = anAttributePoint->x();
+          double anY = anAttributePoint->y();
           if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt()))
               aFirstPointAttr = anAttributePoint;
           if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt()))
@@ -162,15 +185,19 @@ bool PartSet_WidgetSubShapeSelector::setSelection(
         }
       }
 
+      if (!aFirstPointAttr.get() || !aLastPointAttr)
+        return false;
+
       FeaturePtr aFeature = feature();
       AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
-                                         aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+                                          aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
       AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
-                                         aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+                                          aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
       anAPointAttr->setAttr(aFirstPointAttr);
       aBPointAttr->setAttr(aLastPointAttr);
     }
   }
+  //}
 
   return aResult;
 }
@@ -201,7 +228,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject
     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
-    FeaturePtr aSketch = sketch();
+    CompositeFeaturePtr aSketch = sketch();
     std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
     std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
index 5797683bba080dd31a5ba9e84d7f45dc6f1ffc7e..2831dfdb6d9217325223171099beac204a3d1358 100644 (file)
@@ -92,6 +92,14 @@ protected:
   //                              GeomShapePtr& theShape);
   void fillObjectShapes(const ObjectPtr& theObject);
 
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape);
+
 protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
index bbb3bdc50f2b8c6d54bb9389ea10a901b096e70c..d309ce8cbe9014f150a04b11ea763c49439d02c5 100755 (executable)
@@ -888,6 +888,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
     std::shared_ptr<SketchPlugin_Feature> aSFeature =
                                  std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
     SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+    
     std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
     std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
@@ -895,10 +896,12 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
         aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
     std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-    std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+    std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+    
     std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+
     ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
-                                                aX->dir(), aY, aPoints);
+                                                aX->dir(), aDirY, aPoints);
 
     int aCoincidentToFeature = aPoints.size();
     if (aKind == SketchPlugin_Circle::ID())