]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Verification of constraint attributes to be objects, not features
authorazv <azv@opencascade.com>
Fri, 3 Apr 2015 08:36:06 +0000 (11:36 +0300)
committerazv <azv@opencascade.com>
Fri, 3 Apr 2015 08:53:00 +0000 (11:53 +0300)
src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp
src/SketchSolver/SketchSolver_Builder.cpp
src/SketchSolver/SketchSolver_Error.h

index e51c221295034499d99e5ba6066f25c634eb8c3e..41bb3738839cb011145d41171ad7766ac218e5a2 100644 (file)
@@ -121,16 +121,14 @@ void SketchPlugin_ConstraintFillet::execute()
   FeaturePtr aNewFeatureA = sketch()->addFeature(aFeatureA->getKind());
   aFeatureA->data()->copyTo(aNewFeatureA->data());
   aNewFeatureA->execute();
-  aRefListOfFillet->append(aNewFeatureA);
+  aRefListOfFillet->append(aNewFeatureA->firstResult());
   // copy aFeatureB
   FeaturePtr aNewFeatureB = sketch()->addFeature(aFeatureB->getKind());
   aFeatureB->data()->copyTo(aNewFeatureB->data());
   aNewFeatureB->execute();
-  aRefListOfFillet->append(aNewFeatureB);
-  // create filleting arc
+  aRefListOfFillet->append(aNewFeatureB->firstResult());
+  // create filleting arc (it will be attached to the list later)
   FeaturePtr aNewArc = sketch()->addFeature(SketchPlugin_Arc::ID());
-  aRefListOfFillet->append(aNewArc);
-  aRefListOfFillet->setInitialized();
 
   // Wait all constraints being created, then send update events
   static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
@@ -221,6 +219,9 @@ void SketchPlugin_ConstraintFillet::execute()
       aNewArc->attribute(SketchPlugin_Arc::END_ID()))->setValue(
       aCenter->x() + aStep->y(), aCenter->y() - aStep->x());
   aNewArc->execute();
+  // attach new arc to the list
+  aRefListOfFillet->append(aNewArc->lastResult());
+  aRefListOfFillet->setInitialized();
 
   // Create list of additional constraints:
   // 1. Coincidence of boundary points of features and fillet arc
index c46ec2c956742de333afb03115cab7f4c7b4238a..82cf9669c37a143123ad6413c4487984076c78bc 100644 (file)
 #include <SketchSolver_ConstraintMirror.h>
 #include <SketchSolver_ConstraintRigid.h>
 #include <SketchSolver_ConstraintTangent.h>
+#include <SketchSolver_Error.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
+#include <Events_Error.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -61,6 +63,35 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons
   if (!aData || !aData->isValid())
     return aResult;
 
+#ifdef _DEBUG
+  // Verify attributes of constraint and generate errors
+  std::list<AttributePtr> anAttrList = aData->attributes(std::string());
+  std::list<AttributePtr>::iterator anIter = anAttrList.begin();
+  for (; anIter != anAttrList.end(); anIter++) {
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
+    if (aRefAttr) {
+      if (aRefAttr->isObject() && aRefAttr->object()) {
+        ResultConstructionPtr aRC =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRefAttr->object());
+        if (!aRC)
+          Events_Error::send(SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this);
+      }
+      continue;
+    }
+    AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIter);
+    if (aRefList) {
+      std::list<ObjectPtr> aList = aRefList->list();
+      std::list<ObjectPtr>::iterator aListIter = aList.begin();
+      for (; aListIter != aList.end(); aListIter++) {
+        ResultConstructionPtr aRC =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aListIter);
+        if (*aListIter && !aRC)
+          Events_Error::send(SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this);
+      }
+    }
+  }
+#endif
+
   if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
index 1a5718a8d8548e24b02f7a37fe265e0a33b873c4..3623354b196aa582c6fb4233eb8825702e852a73 100644 (file)
@@ -23,6 +23,12 @@ class SketchSolver_Error
     static const std::string MY_ERROR_VALUE("Conflicting constraints");
     return MY_ERROR_VALUE;
   }
+  /// Constraints should use objects instead of features as attributes
+  inline static const std::string& NEED_OBJECT_NOT_FEATURE()
+  {
+    static const std::string MY_ERROR_VALUE("Constraint should be based on object instead of feature");
+    return MY_ERROR_VALUE;
+  }
   /// The entities need to have shared point, but they have not
   inline static const std::string& NO_COINCIDENT_POINTS()
   {