]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment. Validator for selecti...
authornds <nds@opencascade.com>
Mon, 25 Jul 2016 17:45:00 +0000 (20:45 +0300)
committernds <nds@opencascade.com>
Mon, 25 Jul 2016 17:45:00 +0000 (20:45 +0300)
src/Model/Model_AttributeReference.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/PartSet/PartSet_WidgetSubShapeSelector.h
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp

index d63b4e3737cc2812d7b53c04aa72480471a2fa66..b1707c006857736f8bfb9f5bcc6fd88e028141a4 100644 (file)
@@ -25,6 +25,7 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
   //  return;
   ObjectPtr aValue = value();
   if (!myIsInitialized || aValue != theObject) {
+    myIsInitialized = true;
     REMOVE_BACK_REF(aValue);
 
     TDF_Label anObjLab;
index e7a360e78f0ca69116408e6d1046c5bdbc233986..5621684a472a3d38ce58f19f603bc4adbecd491e 100755 (executable)
@@ -19,6 +19,7 @@
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Circ.h>
 
 namespace ModelGeomAlgo_Point2D {
   std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(ModelAPI_Feature* theFeature,
@@ -55,9 +56,12 @@ namespace ModelGeomAlgo_Point2D {
                             const std::string& theReferenceFeatureKind,
                             std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
                             const std::string& theObjectFeatureKind,
-                            const std::string& theObjectFeatureAttribute)
+                            const std::string& theObjectFeatureAttribute,
+                            const bool isSkipFeatureAttributes)
   {
     // find by feature
+    FeaturePtr aSourceFeature = ModelAPI_Feature::feature(theObject);
+
     const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
     std::set<AttributePtr>::const_iterator aIt;
     for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
@@ -66,15 +70,32 @@ namespace ModelGeomAlgo_Point2D {
       if (aRefFeature->getKind() == theReferenceFeatureKind) {
         std::list<AttributePtr> anAttributes =
                          aRefFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
-        std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+        std::list<AttributePtr>::iterator anIter = anAttributes.begin(), aLast = anAttributes.end();
+        bool isSkippedAttribute = false;
+        if (isSkipFeatureAttributes) {
+          for(anIter = anAttributes.begin(); anIter != aLast && !isSkippedAttribute; anIter++) {
+            AttributeRefAttrPtr aRefAttribute =
+              std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
+            if (aRefAttribute.get() && !aRefAttribute->isObject()) {
+              std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+                             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttribute->attr());
+              FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aPointAttr->owner());
+              isSkippedAttribute = aSourceFeature == anAttributeFeature;
+            }
+          }
+        }
+        if (isSkippedAttribute)
+          continue;
+
         // it searches the first point of AttributeRefAtt
         std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
-        for(; anIter != anAttributes.end() && !aPointAttr.get(); anIter++) {
+        for(anIter = anAttributes.begin(); anIter != aLast && !aPointAttr.get(); anIter++) {
           AttributeRefAttrPtr aRefAttribute =
             std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
-          if (aRefAttribute.get())
+          if (aRefAttribute.get()) {
             aPointAttr = getPointOfRefAttr(aRefFeature.get(), aRefAttribute->id(),
-                                           theObjectFeatureKind, theObjectFeatureAttribute);
+                         theObjectFeatureKind, theObjectFeatureAttribute);
+          }
         }
         if (aPointAttr.get()) {
           theAttributes.insert(aPointAttr);
@@ -119,13 +140,20 @@ namespace ModelGeomAlgo_Point2D {
   {
     bool isInside = false;
     if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
-      std::shared_ptr<GeomAPI_Edge> aLineEdge(new GeomAPI_Edge(theBaseShape));
-      std::shared_ptr<GeomAPI_Lin> aLine = aLineEdge->line();
-      theProjectedPoint = aLine->project(thePoint);
-
-      std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
-                                                theProjectedPoint->y(), theProjectedPoint->z()));
-      isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
+      if (anEdge->isLine()) {
+        std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+        theProjectedPoint = aLine->project(thePoint);
+      }
+      else if (anEdge->isCircle() || anEdge->isArc()) {
+        std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
+        theProjectedPoint = aCircle->project(thePoint);
+      }
+      if (theProjectedPoint.get()) {
+        std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
+                                                  theProjectedPoint->y(), theProjectedPoint->z()));
+        isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
+      }
     }
     return isInside;
   }
index b70ef961e3a62e19ff9dc97a94368d9fb2098252..be1521bdc460313c56fb54362784d1b42d7d7099 100755 (executable)
@@ -8,6 +8,7 @@
 #define ModelGeomAlgo_Point2D_H
 
 #include "ModelGeomAlgo.h"
+#include "ModelAPI_Feature.h"
 
 class ModelAPI_Feature;
 class ModelAPI_Object;
@@ -29,12 +30,13 @@ namespace ModelGeomAlgo_Point2D {
   /// \param theAttribute a name of AttributeRefAttr on the given feature
   /// \param theObjectFeatureKind a feature kind in object of attribute that satisfies the search
   /// \param theObjectFeatureAttribute a feature attribute in object that satisfies the search
+  /// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
   /// \returns found point attribute or NULL
   MODELGEOMALGO_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(
-                                                ModelAPI_Feature* theFeature,
-                                                const std::string& theAttribute,
-                                                const std::string& theObjectFeatureKind = "",
-                                                const std::string& theObjectFeatureAttribute = "");
+                        ModelAPI_Feature* theFeature,
+                        const std::string& theAttribute,
+                        const std::string& theObjectFeatureKind = "",
+                        const std::string& theObjectFeatureAttribute = "");
 
   /// Fills container of point 2D attributes, which refer to the feature through the references
   /// features with the given kind
@@ -43,12 +45,15 @@ namespace ModelGeomAlgo_Point2D {
   /// \param theAttributes a container of found point 2D attributes
   /// \param theObjectFeatureKind a feature kind in object of attribute that satisfies the search
   /// \param theObjectFeatureAttribute a feature attribute in object that satisfies the search
+  /// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
+  /// should be skipped
   /// \returns found point attribute or NULL
   MODELGEOMALGO_EXPORT void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
                                           const std::string& theReferenceFeatureKind,
                                           std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
                                           const std::string& theObjectFeatureKind = "",
-                                          const std::string& theObjectFeatureAttribute = "");
+                                          const std::string& theObjectFeatureAttribute = "",
+                                          const bool isSkipFeatureAttributes = true);
 
   /// Removes attributes which points are out of the base shape
   /// \param theBaseShape a shape of check
index f73d61e98299a71da30b84fd8d2e4350cfa2215b..bdb039aad75c63fc8d111a42a2bea30246de16a1 100755 (executable)
 PartSet_WidgetSubShapeSelector::PartSet_WidgetSubShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData)
-: PartSet_WidgetShapeSelector(theParent, theWorkshop, theData)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
 {
   myCurrentSubShape = std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs());
-
-  //myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
-  //myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), true);
 }
 
 PartSet_WidgetSubShapeSelector::~PartSet_WidgetSubShapeSelector()
 {
+  myCashedShapes.clear();
 }
 
 //********************************************************************
 void PartSet_WidgetSubShapeSelector::activateCustom()
 {
-  PartSet_WidgetShapeSelector::activateCustom();
+  ModuleBase_WidgetShapeSelector::activateCustom();
 
   myWorkshop->module()->activateCustomPrs(myFeature,
                             ModuleBase_IModule::CustomizeHighlightedObjects, true);
@@ -64,7 +62,7 @@ void PartSet_WidgetSubShapeSelector::activateCustom()
 //********************************************************************
 void PartSet_WidgetSubShapeSelector::deactivate()
 {
-  PartSet_WidgetShapeSelector::deactivate();
+  ModuleBase_WidgetShapeSelector::deactivate();
 
   myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
 }
index 34e7b371a4cc6fd6135f2e4e175730dc5b1a1267..feee61b01ee6d6ad9670b05638214a1033d2a3dd 100644 (file)
 
 #include "PartSet.h"
 
-#include <PartSet_WidgetShapeSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
 #include <PartSet_MouseProcessor.h>
 
+#include <ModelAPI_CompositeFeature.h>
+
 #include <QObject>
 
 #include <set>
@@ -32,7 +34,7 @@ class QMouseEvent;
 * by mouse move over shape in the viewer. Split of the object is performed by
 * coincident points to the object. Segment between nearest coincidence is highlighted
 */
-class PARTSET_EXPORT PartSet_WidgetSubShapeSelector: public PartSet_WidgetShapeSelector,
+class PARTSET_EXPORT PartSet_WidgetSubShapeSelector: public ModuleBase_WidgetShapeSelector,
                                                      public PartSet_MouseProcessor
 {
 Q_OBJECT
@@ -46,6 +48,13 @@ Q_OBJECT
 
   virtual ~PartSet_WidgetSubShapeSelector();
 
+  /// Set sketcher
+  /// \param theSketch a sketcher object
+  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+
+  /// Retrurns installed sketcher
+  CompositeFeaturePtr sketch() const { return mySketch; }
+
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
@@ -80,6 +89,9 @@ protected:
 protected:
   std::shared_ptr<ModuleBase_ViewerPrs> myCurrentSubShape;
   std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
+
+  /// Pointer to a sketch 
+  CompositeFeaturePtr mySketch;
 };
 
 #endif
\ No newline at end of file
index b029f638ea7f506a79cffacdc8c6577059624505..472cf8725db403ed1161abae8b02fc66f307a3ef 100755 (executable)
@@ -13,7 +13,7 @@
 //#include <GeomAPI_XY.h>
 //#include <GeomDataAPI_Point2D.h>
 //#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeReference.h>
 //#include <ModelAPI_AttributeRefList.h>
 //#include <ModelAPI_AttributeRefAttrList.h>
 //#include <ModelAPI_Data.h>
@@ -70,7 +70,7 @@ SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit()
 
 void SketchPlugin_ConstraintSplit::initAttributes()
 {
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeReference::typeId());
 
   //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
   //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
index b488d4fa0d30a2c2569691fd49f3099e61ac3640..bbb3bdc50f2b8c6d54bb9389ea10a901b096e70c 100755 (executable)
@@ -856,15 +856,15 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
 {
   bool aValid = false;
 
-  if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
+  if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
     theError = "The attribute with the %1 type is not processed";
     theError.arg(theAttribute->attributeType());
     return aValid;
   }
-  AttributeSelectionPtr aFeatureAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeReferencePtr aFeatureAttr =
+            std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
 
-  ObjectPtr anAttrObject = aFeatureAttr->context();
+  ObjectPtr anAttrObject = aFeatureAttr->value();
   FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
   if (!anAttrFeature)
     return aValid;
@@ -876,28 +876,38 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
 
     std::set<GeomShapePtr> anEdgeShapes;
     ModelAPI_Tools::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
-    if (anEdgeShapes.empty())
+    if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
       return aValid;
 
-    GeomShapePtr anAttrShape = *anEdgeShapes.begin();
-
-  //std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = ModelGeomAlgo_Point2D::getPointOfRefAttr(
-  //             anAttrFeature, theAttribute, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
-
+    // coincidences to the feature
     std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
-    //ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature.get(), SketchPlugin_ConstraintCoincidence::ID(),
-    //                          aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
-
-    //ModelGeomAlgo_Point2D::filterPointsToBeInsideShape(anAttrShape, aRefAttributes, );
+    ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature, SketchPlugin_ConstraintCoincidence::ID(),
+                         aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
 
-    int aCoincidentToFeature = aRefAttributes.size();
+    GeomShapePtr anAttrShape = *anEdgeShapes.begin();
+    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()));
+    std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        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::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+    ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
+                                                aX->dir(), aY, aPoints);
+
+    int aCoincidentToFeature = aPoints.size();
     if (aKind == SketchPlugin_Circle::ID())
-      aValid = aCoincidentToFeature > 2;
+      aValid = aCoincidentToFeature >= 2;
     else
-      aValid = aCoincidentToFeature > 1;
+      aValid = aCoincidentToFeature >= 1;
   }
 
-  return true;
+  return aValid;
 }
 
 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,