]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Checking isInitialized for attributes is SketchPlugin and SketchSolver
authorazv <azv@opencascade.com>
Fri, 26 Aug 2016 06:11:12 +0000 (09:11 +0300)
committerazv <azv@opencascade.com>
Fri, 26 Aug 2016 07:47:17 +0000 (10:47 +0300)
src/PartSet/PartSet_Tools.cpp
src/PythonAddons/macros/rectangle/feature.py
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 70a6138dcb8e40ebaa6a0fdea7df912795e77765..6639c3aa91b49353ce3b376befe29b8153896c81 100755 (executable)
@@ -917,6 +917,8 @@ AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
         for (; anIt != aLast && !anAttribute; anIt++) {
           std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+          if (!aCurPoint->isInitialized())
+            continue;
 
           std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
           if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
index 8ce3a4b4fc5a85a53d536ff0494ff72bfc904ce0..3fa05afc18df8502ebd2f7da8ebb7d523afaab56 100644 (file)
@@ -82,6 +82,7 @@ class SketchPlugin_Rectangle(model.Feature):
             for i in range (0, 3):
                 aLine = self.__sketch.addFeature("SketchLine")
                 aLinesList.append(aLine)
+            self.updateLines()
             aNbLines = aLinesList.size()
             # Create constraints to keep the rectangle
             for i in range (0, aNbLines):
index ab27bbbe8e6e7dd98f50a45f761603efefc98a6b..aa1d29096bd266db346a0ef9a0a738ff46c0f954 100644 (file)
@@ -272,21 +272,25 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   myEndUpdate = true;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(SketchPlugin_Arc::START_ID()));
-  aPoint2->move(theDeltaX, theDeltaY);
+  if (aPoint2->isInitialized())
+    aPoint2->move(theDeltaX, theDeltaY);
 
   std::shared_ptr<GeomDataAPI_Point2D> aPoint3 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(SketchPlugin_Arc::END_ID()));
-  aPoint3->move(theDeltaX, theDeltaY);
+  if (aPoint3->isInitialized())
+    aPoint3->move(theDeltaX, theDeltaY);
   myStartUpdate = false;
   myEndUpdate = false;
 
   std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(SketchPlugin_Arc::CENTER_ID()));
-  aPoint1->move(theDeltaX, theDeltaY);
+  if (aPoint1->isInitialized())
+    aPoint1->move(theDeltaX, theDeltaY);
 
   std::shared_ptr<GeomDataAPI_Point2D> aPassedPoint =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(PASSED_POINT_ID()));
-  aPassedPoint->move(theDeltaX, theDeltaY);
+  if (aPassedPoint->isInitialized())
+    aPassedPoint->move(theDeltaX, theDeltaY);
   aData->blockSendAttributeUpdated(false);
 }
 
index babdd6f14e01dcff3da73c1b76c1f4f01ac1a09f..cc8a992bc21e96f554272838a27198b21f7413fe 100644 (file)
@@ -171,14 +171,18 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
 
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(CENTER_ID()));
-  aPoint->move(theDeltaX, theDeltaY);
+  if (aPoint->isInitialized())
+    aPoint->move(theDeltaX, theDeltaY);
 
   aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(FIRST_POINT_ID()));
-  aPoint->move(theDeltaX, theDeltaY);
+  if (aPoint->isInitialized())
+    aPoint->move(theDeltaX, theDeltaY);
   aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SECOND_POINT_ID()));
-  aPoint->move(theDeltaX, theDeltaY);
+  if (aPoint->isInitialized())
+    aPoint->move(theDeltaX, theDeltaY);
   aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(THIRD_POINT_ID()));
-  aPoint->move(theDeltaX, theDeltaY);
+  if (aPoint->isInitialized())
+    aPoint->move(theDeltaX, theDeltaY);
 }
 
 bool SketchPlugin_Circle::isFixed() {
@@ -281,7 +285,11 @@ void SketchPlugin_Circle::adjustThreePoints()
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(THIRD_POINT_ID()));
   double aRadius = aRadiusAttr->value();
 
-  if (fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
+  bool isInitialized = aFirstPnt->isInitialized() &&
+      aSecondPnt->isInitialized() && aThirdPnt->isInitialized();
+
+  if (!isInitialized ||
+      fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
       fabs(aSecondPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
       fabs(aThirdPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance) {
     aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y());
index c402ec7dd8adf39f515464d760625ba65f64518d..eeabd7478946db8f218095a51cf9b93be51f0196 100644 (file)
@@ -224,12 +224,12 @@ void SketchSolver_Constraint::getAttributes(
       return;
     }
 
-    myStorage->update(*anIter/*, myGroupID*/);
-    EntityWrapperPtr anEntity = myStorage->entity(*anIter);
+    myStorage->update(aRefAttr/*, myGroupID*/);
+    EntityWrapperPtr anEntity = myStorage->entity(aRefAttr);
     if (!anEntity) {
       // Force creation of an entity
-      myStorage->update(*anIter, GID_UNKNOWN, true);
-      anEntity = myStorage->entity(*anIter);
+      myStorage->update(aRefAttr, GID_UNKNOWN, true);
+      anEntity = myStorage->entity(aRefAttr);
     }
     myAttributes.push_back(anEntity);
 
index 4dc1800d14575f859bbf734c8693a5e127968a04..88f56124e0c4249c35934685d6c89d4dd1beb617 100644 (file)
@@ -190,6 +190,8 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
     std::list<AttributePtr> anAttrs = pointAttributes(theFeature);
     std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
     for (; anIt != anAttrs.end(); ++anIt) {
+      if (!(*anIt)->isInitialized())
+        return false;
       isUpdated = update(*anIt, theGroup, theForce) || isUpdated;
       aSubs.push_back(entity(*anIt));
     }
@@ -222,14 +224,20 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
 
 bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup, bool theForce)
 {
+  if (!theAttribute->isInitialized())
+    return false;
+
   AttributePtr anAttribute = theAttribute;
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
   if (aRefAttr) {
     if (aRefAttr->isObject()) {
       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
       return update(aFeature, theGroup, theForce);
-    } else
+    } else {
       anAttribute = aRefAttr->attr();
+      if (!anAttribute->isInitialized())
+        return false;
+    }
   }
 
   EntityWrapperPtr aRelated = entity(anAttribute);