]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Removed unused attributes from fillet.
authordbv <dbv@opencascade.com>
Fri, 19 Feb 2016 11:33:30 +0000 (14:33 +0300)
committerdbv <dbv@opencascade.com>
Fri, 19 Feb 2016 12:19:07 +0000 (15:19 +0300)
src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp
src/SketchPlugin/SketchPlugin_ConstraintFillet.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index afbd1407a6e63cbc3e4280135d707e016462ea20..b5a80228058e273ae967bb033a67b8ac9da6f58e 100644 (file)
@@ -70,13 +70,6 @@ void SketchPlugin_ConstraintFillet::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
-  AttributePtr aResultEdgesRefList = data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); // Used to store result edges.
-  AttributePtr aBasePointsRefAttrList = data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefAttrList::typeId()); // Used to store base points.
-  // Initialize attribute not applicable for user.
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_B());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_C());
-  aResultEdgesRefList->setIsArgument(false);
-  aBasePointsRefAttrList->setIsArgument(false);
 }
 
 void SketchPlugin_ConstraintFillet::execute()
@@ -96,9 +89,7 @@ void SketchPlugin_ConstraintFillet::execute()
     aData->attribute(SketchPlugin_Constraint::VALUE()))->value();
 
   // Check the fillet result edges is not initialized yet.
-  AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
-    aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
-  bool anIsNeedNewObjects = aResultEdgesRefList->size() == 0;
+  bool anIsNeedNewObjects = myResultEdges.size() == 0;
 
   // Wait all constraints being created, then send update events
   static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
@@ -106,6 +97,7 @@ void SketchPlugin_ConstraintFillet::execute()
   if (isUpdateFlushed)
     Events_Loop::loop()->setFlushed(anUpdateEvent, false);
 
+  std::list<FeaturePtr>::iterator aResultEdgesIt = myResultEdges.begin();
   for(int anIndex = 0; anIndex < aPointsRefList->size(); ++anIndex) {
     std::shared_ptr<GeomDataAPI_Point2D> aFilletPoint2d =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointsRefList->attribute(anIndex));
@@ -182,9 +174,9 @@ void SketchPlugin_ConstraintFillet::execute()
       aResultArc = sketch()->addFeature(SketchPlugin_Arc::ID());
     } else {
       // Obtain features from the list.
-      aResultEdgeA = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3));
-      aResultEdgeB = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 1));
-      aResultArc = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 2));
+      aResultEdgeA = *aResultEdgesIt++;
+      aResultEdgeB = *aResultEdgesIt++;
+      aResultArc = *aResultEdgesIt++;
     }
 
     // Calculate arc attributes
@@ -204,7 +196,7 @@ void SketchPlugin_ConstraintFillet::execute()
         aStartAttr = SketchPlugin_Arc::START_ID();
         aEndAttr = SketchPlugin_Arc::END_ID();
       } else { // wrong argument
-        aResultEdgesRefList->clear();
+        myResultEdges.clear();
         setError("Error: One of the points has wrong coincide feature");
         return;
       }
@@ -291,9 +283,9 @@ void SketchPlugin_ConstraintFillet::execute()
 
     if(anIsNeedNewObjects) {
       // attach new arc to the list
-      aResultEdgesRefList->append(aResultEdgeA->lastResult());
-      aResultEdgesRefList->append(aResultEdgeB->lastResult());
-      aResultEdgesRefList->append(aResultArc->lastResult());
+      myResultEdges.push_back(aResultEdgeA);
+      myResultEdges.push_back(aResultEdgeB);
+      myResultEdges.push_back(aResultArc);
 
       myProducedFeatures.push_back(aResultEdgeA);
       myProducedFeatures.push_back(aResultEdgeB);
@@ -442,14 +434,10 @@ void SketchPlugin_ConstraintFillet::attributeChanged(const std::string& theID)
     }
 
     // Clear the list of fillet entities.
-    AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
-      data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
-    aResultEdgesRefList->clear();
+    myResultEdges.clear();
 
     // Clear the list of base points.
-    AttributeRefAttrListPtr aBasePointsRefAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(
-        data()->attribute(SketchPlugin_Constraint::ENTITY_C()));
-    aBasePointsRefAttrList->clear();
+    myBasePoints.clear();
 
     // Clear auxiliary flag on initial objects.
     std::list<FeaturePtr>::const_iterator aFeatureIt;
@@ -606,7 +594,7 @@ void SketchPlugin_ConstraintFillet::attributeChanged(const std::string& theID)
 
       // Store base point for fillet.
       aBasePoints.insert(aFilletPointAttr);
-      aBasePointsRefAttrList->append(aFilletPointAttr);
+      myBasePoints.push_back(aFilletPointAttr);
 
       // Get base lines for fillet.
       FeaturePtr anOldFeatureA, anOldFeatureB;
index 5865c0746f726b70f65460dcf6ce4c1d03b4e39b..6a1dfa8f09f14b13914dc1d81c594f5eebaa8573 100644 (file)
@@ -58,9 +58,20 @@ class SketchPlugin_ConstraintFillet : public SketchPlugin_ConstraintBase
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintFillet();
 
+  /// \return base points list;
+  SKETCHPLUGIN_EXPORT const std::list<AttributePtr> basePoints() const {return myBasePoints;};
+
+  /// \return base edges list;
+  SKETCHPLUGIN_EXPORT const std::list<FeaturePtr> baseEdges() const {return myBaseEdges;};
+
+  /// \return result edges list;
+  SKETCHPLUGIN_EXPORT const std::list<FeaturePtr> resultEdges() const {return myResultEdges;};
+
 private:
-  std::list<FeaturePtr> myProducedFeatures; ///< list of constraints provided by the fillet
+  std::list<AttributePtr> myBasePoints; ///< list of base points
   std::list<FeaturePtr> myBaseEdges;      ///< list of objects the fillet is based
+  std::list<FeaturePtr> myResultEdges;      ///< list of result edges
+  std::list<FeaturePtr> myProducedFeatures; ///< list of constraints provided by the fillet
   bool myListOfPointsChangedInCode; ///< flag to track that list of points changed in code
   bool myRadiusChangedByUser; ///< flag to track that radius changed by user
   bool myRadiusChangedInCode; ///< flag to track that radius changed in code
index 4fa4856f6eced0e5649dd7f597484efbd912d461..e3a42ecf1d0bb6cefb5ef6410f333ea722c3a529 100755 (executable)
@@ -10,6 +10,7 @@
 #include "SketchPlugin_Circle.h"
 #include "SketchPlugin_ConstraintCoincidence.h"
 #include "SketchPlugin_ConstraintDistance.h"
+#include "SketchPlugin_ConstraintFillet.h"
 #include "SketchPlugin_ConstraintRigid.h"
 #include "SketchPlugin_Line.h"
 #include "SketchPlugin_Point.h"
@@ -35,6 +36,7 @@
 #include <GeomAPI_Vertex.h>
 #include <GeomDataAPI_Point2D.h>
 
+#include <algorithm>
 #include <cmath>
 
 const double tolerance = 1.e-7;
@@ -464,17 +466,15 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
     return false;
   }
 
-  FeaturePtr aFilletFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  std::shared_ptr<SketchPlugin_ConstraintFillet> aFilletFeature = std::dynamic_pointer_cast<SketchPlugin_ConstraintFillet>(theAttribute->owner());
   AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
   if(aPointsRefList->size() == 0) {
     theError = "Error: List of points is empty.";
     return false;
   }
 
-  AttributeRefAttrListPtr aBasePointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(
-    aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
-  AttributeRefListPtr aResultEdgesRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
-    aFilletFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+  std::list<AttributePtr> aBasePointsList = aFilletFeature->basePoints();
+  std::list<FeaturePtr> aResultEdgesList = aFilletFeature->resultEdges();
 
   std::list<std::pair<ObjectPtr, AttributePtr>> aPointsList = aPointsRefList->list();
   for(std::list<std::pair<ObjectPtr, AttributePtr>>::const_iterator aPointsIt = aPointsList.cbegin(); aPointsIt != aPointsList.cend(); aPointsIt++) {
@@ -485,16 +485,18 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
     // If we alredy have some result then:
     // - if it is the same point all ok, just skip it
     // - if it is point on the fillet arc then it is not valid
-    if(aBasePointsRefList->size() > 0) {
-      if(aBasePointsRefList->isInList(aPointAttribute)) {
+    if(!aBasePointsList.empty()) {
+      if(std::find(aBasePointsList.begin(), aBasePointsList.end(), aPointAttribute) != aBasePointsList.end()) {
         continue;
       }
 
       // Check that selected point not on the one of the result fillet arc.
-      for(int anIndex = 0; anIndex < aBasePointsRefList->size(); anIndex++) {
-        if(aResultEdgesRefList->size() > 0) {
+      std::list<FeaturePtr>::iterator aResultEdgesIt = aResultEdgesList.begin();
+      for(unsigned int anIndex = 0; anIndex < aBasePointsList.size(); anIndex++) {
+        if(aResultEdgesList.size() > 0) {
           FeaturePtr aResultArc;
-          aResultArc = ModelAPI_Feature::feature(aResultEdgesRefList->object(anIndex * 3 + 2));
+          std::advance(aResultEdgesIt, 2);
+          aResultArc = *aResultEdgesIt++;
           AttributePtr anArcStart = aResultArc->attribute(SketchPlugin_Arc::START_ID());
           AttributePtr anArcEnd = aResultArc->attribute(SketchPlugin_Arc::END_ID());
           std::shared_ptr<GeomAPI_Pnt2d> anArcStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anArcStart)->pnt();