]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix the problem with changing base entities of fillet (issue #760)
authorazv <azv@opencascade.com>
Fri, 21 Aug 2015 09:12:06 +0000 (12:12 +0300)
committerazv <azv@opencascade.com>
Fri, 21 Aug 2015 09:13:06 +0000 (12:13 +0300)
src/PartSet/PartSet_Tools.cpp
src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp
src/SketchPlugin/SketchPlugin_ConstraintFillet.h

index a44a47e0b2b43792291f2c30d6930ec3552f059c..ebd22fdef4bb2f141db3a920f0634712224e269f 100755 (executable)
@@ -714,8 +714,10 @@ std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::getPoint(std::shared_ptr<ModelAPI_
   FeaturePtr aFeature;
   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
-  if (anAttr)
-    aFeature = ModelAPI_Feature::feature(anAttr->object());
+  if (!anAttr)
+    return std::shared_ptr<GeomAPI_Pnt2d>();
+
+  aFeature = ModelAPI_Feature::feature(anAttr->object());
 
   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
     aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -733,6 +735,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
                                      std::string theAttr)
 {
   AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
+  if (!aPnt) return;
   FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
   if (!theList.contains(aObj)) {
     std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
index 450621fa9f2d3cb2ad0a26b6b0889ffdafa3f22d..6cf6da8f669062a579482109de07df6828394d46 100644 (file)
@@ -225,6 +225,10 @@ void SketchPlugin_ConstraintFillet::execute()
     aRefListOfFillet->append(aNewFeatureB->lastResult());
     aRefListOfFillet->append(aNewArc->lastResult());
 
+    myProducedFeatures.push_back(aNewFeatureA);
+    myProducedFeatures.push_back(aNewFeatureB);
+    myProducedFeatures.push_back(aNewArc);
+
     // Create list of additional constraints:
     // 1. Coincidence of boundary points of features (copied lines/arcs) and fillet arc
     // 1.1. coincidence
@@ -239,6 +243,7 @@ void SketchPlugin_ConstraintFillet::execute()
     aRefAttr->setAttr(aNewFeature[aFeatInd]->attribute(aFeatAttributes[anAttrInd]));
     recalculateAttributes(aNewArc, SketchPlugin_Arc::START_ID(), aNewFeature[aFeatInd], aFeatAttributes[anAttrInd]);
     aConstraint->execute();
+    myProducedFeatures.push_back(aConstraint);
     ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
     // 1.2. coincidence
     aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
@@ -252,6 +257,7 @@ void SketchPlugin_ConstraintFillet::execute()
     aRefAttr->setAttr(aNewFeature[aFeatInd]->attribute(aFeatAttributes[anAttrInd]));
     recalculateAttributes(aNewArc, SketchPlugin_Arc::END_ID(), aNewFeature[aFeatInd], aFeatAttributes[anAttrInd]);
     aConstraint->execute();
+    myProducedFeatures.push_back(aConstraint);
     ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
     // 2. Fillet arc radius
     aConstraint = sketch()->addFeature(SketchPlugin_ConstraintRadius::ID());
@@ -264,6 +270,7 @@ void SketchPlugin_ConstraintFillet::execute()
         aConstraint->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()))->setValue(
         isStart[0] ? aStartEndPnt[0] : aStartEndPnt[1]);
     aConstraint->execute();
+    myProducedFeatures.push_back(aConstraint);
     ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
     // 3. Tangency of fillet arc and features
     for (int i = 0; i < aNbFeatures; i++) {
@@ -276,6 +283,7 @@ void SketchPlugin_ConstraintFillet::execute()
       bool isArc = aNewFeature[i]->getKind() == SketchPlugin_Arc::ID();
       aRefAttr->setObject(isArc ? aNewFeature[i]->lastResult() : aNewFeature[i]->firstResult());
       aConstraint->execute();
+      myProducedFeatures.push_back(aConstraint);
       ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
     }
     // 4. Coincidence of free boundaries of base and copied features
@@ -288,6 +296,7 @@ void SketchPlugin_ConstraintFillet::execute()
       aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
           aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
       aRefAttr->setAttr(aNewFeature[i]->attribute(aFeatAttributes[anAttrInd]));
+      myProducedFeatures.push_back(aConstraint);
     }
     // 5. Tangent points should be placed on the base features
     for (int i = 0; i < aNbFeatures; i++) {
@@ -299,10 +308,14 @@ void SketchPlugin_ConstraintFillet::execute()
       aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
           aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
       aRefAttr->setObject(aFeature[i]->lastResult());
+      myProducedFeatures.push_back(aConstraint);
     }
     // make base features auxiliary
     aFeatureA->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
     aFeatureB->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
+    myBaseObjects.clear();
+    myBaseObjects.push_back(aFeatureA);
+    myBaseObjects.push_back(aFeatureB);
   } else {
     // Update radius value
     int aNbSubs = sketch()->numberOfSubs();
@@ -336,6 +349,29 @@ void SketchPlugin_ConstraintFillet::execute()
   //Events_Loop::loop()->send(aMsg);
 }
 
+void SketchPlugin_ConstraintFillet::attributeChanged(const std::string& theID)
+{
+  if (theID == SketchPlugin_Constraint::ENTITY_A() ||
+      theID == SketchPlugin_Constraint::ENTITY_B()) {
+    // clear the list of fillet entities
+    AttributeRefListPtr aRefListOfFillet = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+        data()->attribute(SketchPlugin_Constraint::ENTITY_C()));
+    aRefListOfFillet->clear();
+
+    // remove all produced objects and constraints
+    DocumentPtr aDoc = sketch()->document();
+    std::list<FeaturePtr>::iterator aCIt = myProducedFeatures.begin();
+    for (; aCIt != myProducedFeatures.end(); ++aCIt)
+      aDoc->removeFeature(*aCIt);
+    myProducedFeatures.clear();
+
+    // clear auxiliary flag on initial objects
+    for (aCIt = myBaseObjects.begin(); aCIt != myBaseObjects.end(); ++aCIt)
+      (*aCIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(false);
+    myBaseObjects.clear();
+  }
+}
+
 AISObjectPtr SketchPlugin_ConstraintFillet::getAISObject(AISObjectPtr thePrevious)
 {
   if (!sketch())
index 8701917978856768b09c5c6f6c6b477fa75f7124..909473bac93b853fff613d26ab42dc83a28a8878 100644 (file)
@@ -44,6 +44,10 @@ class SketchPlugin_ConstraintFillet : public SketchPlugin_ConstraintBase
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
@@ -53,6 +57,10 @@ class SketchPlugin_ConstraintFillet : public SketchPlugin_ConstraintBase
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintFillet();
+
+private:
+  std::list<FeaturePtr> myProducedFeatures; ///< list of constraints provided by the fillet
+  std::list<FeaturePtr> myBaseObjects;      ///< list of objects the fillet is based
 };
 
 #endif