]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task #3231: Sketcher Offset of a curve
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Fri, 26 Jun 2020 20:09:42 +0000 (23:09 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Sat, 27 Jun 2020 17:37:51 +0000 (20:37 +0300)
Improvements

src/SketchPlugin/SketchPlugin_Offset.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/plugin-Sketch.xml
src/SketcherPrs/SketcherPrs_Tools.cpp

index fbbbf9a0d496aa83ca7d8cfe66b8439b1574c7ed..30de8d22cebc4a857d294bff17bc1f9600c5d8a3 100644 (file)
@@ -216,9 +216,11 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
   for (; aPointsIt != anAllCoincPoints.end(); aPointsIt++) {
     AttributePtr aP = (*aPointsIt);
     FeaturePtr aCoincFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aP->owner());
+    bool isInSet = (theEdgesSet.find(aCoincFeature) != theEdgesSet.end());
 
     // Condition 0: not auxiliary
-    if (aCoincFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) continue;
+    if (!isInSet && aCoincFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value())
+      continue;
 
     // Condition 1: not a point feature
     if (aCoincFeature->getKind() != SketchPlugin_Point::ID()) {
@@ -226,11 +228,7 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
       if (aCoincFeature != theEdge) {
         // Condition 3: it is in the set of interest.
         //              Empty set means all sketch edges.
-        bool isInSet = true;
-        if (theEdgesSet.size()) {
-          isInSet = (theEdgesSet.find(aCoincFeature) != theEdgesSet.end());
-        }
-        if (isInSet) {
+        if (isInSet || theEdgesSet.empty()) {
           // Condition 4: consider only features with two end points
           std::shared_ptr<GeomDataAPI_Point2D> aP1, aP2;
           SketchPlugin_SegmentationTools::getFeaturePoints(aCoincFeature, aP1, aP2);
@@ -450,6 +448,14 @@ static void findOrCreateFeatureByKind(SketchPlugin_Sketch* theSketch,
                                       FeaturePtr& theFeature,
                                       std::list<ObjectPtr>& thePoolOfFeatures)
 {
+  if (theFeature) {
+    // check the feature type is the same as required
+    if (theFeature->getKind() != theFeatureKind) {
+      // return feature to the pool and try to find the most appropriate
+      thePoolOfFeatures.push_back(theFeature);
+      theFeature = FeaturePtr();
+    }
+  }
   if (!theFeature) {
     // try to find appropriate feature in the pool
     for (std::list<ObjectPtr>::iterator it = thePoolOfFeatures.begin();
index 50d14b6a45f878e61735c8ab58cc5e3b9993f52b..883c0cbb13e9e0acde7c67cfea610eafc3be9256 100644 (file)
@@ -36,6 +36,7 @@
 #include "SketchPlugin_MacroArc.h"
 #include "SketchPlugin_MacroCircle.h"
 #include "SketchPlugin_MultiRotation.h"
+#include "SketchPlugin_Offset.h"
 #include "SketchPlugin_Point.h"
 #include "SketchPlugin_Sketch.h"
 #include "SketchPlugin_Trim.h"
@@ -535,20 +536,32 @@ bool SketchPlugin_CopyValidator::isValid(const AttributePtr& theAttribute,
 
     // B-splines are not supported in Copying features
     FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
-    if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
+    if (aFeature->getKind() != SketchPlugin_Offset::ID() &&
+        aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
         aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
       theError = "Not supported";
       return false;
     }
 
     anObjIter = aCopiedObjects.begin();
-    for (; anObjIter != aCopiedObjects.end(); anObjIter++)
-      if (aSelObject == *anObjIter) {
+    for (; anObjIter != aCopiedObjects.end(); anObjIter++) {
+      bool isFound = aSelObject == *anObjIter;
+      if (!isFound) {
+        // check in the results of the feature
+        FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIter);
+        const std::list<ResultPtr>& aResults = aFeature->results();
+        for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
+             aResIt != aResults.end() && !isFound; ++aResIt) {
+          isFound = aSelObject == *aResIt;
+        }
+      }
+      if (isFound) {
         std::wstring aName = aSelObject.get() ? aSelObject->data()->name() : L"";
         theError = "The object %1 is a result of copy";
         theError.arg(aName);
         return false;
       }
+    }
   }
   return true;
 }
index 2295a3f5e7fb6f461e1d358deba289498ca53c7d..ef62acfca3bb04f0e0c12e64477916fa5ed6fe81 100644 (file)
                                shape_types="Edges"
                                use_external="true"
                                greed="true">
+          <validator id="SketchPlugin_CopyValidator" />
         </sketch_multi_selector>
         <doublevalue id="offset_value"
                      label="Offset value"
index 91a1dedee7a1d859ce84f46a7491d74d7dd13881..c4d5df6e8e663dbf3d8acbbeae57f5c3cb74816f 100644 (file)
@@ -98,7 +98,7 @@ std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject)
   if (!aRes.get()) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
     if (aFeature.get())
-      aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFeature->firstResult());
+      aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFeature->lastResult());
   }
   if (aRes.get() != NULL && aRes->data()->isValid()) {
     /// essential check as it is called in openGl thread