]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
The problem with constraint parameters given as reference to attribute and to feature...
authorazv <azv@opencascade.com>
Fri, 30 May 2014 09:02:10 +0000 (13:02 +0400)
committerazv <azv@opencascade.com>
Fri, 30 May 2014 09:02:10 +0000 (13:02 +0400)
12 files changed:
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintDiameter.cpp [deleted file]
src/SketchPlugin/SketchPlugin_ConstraintDiameter.h [deleted file]
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintLength.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintRadius.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h

index a1ee7a3620d1000b3af52e54e21091f7644d9585..9a4d7cf766d9adef77756ab45bf4048da12d68cd 100644 (file)
@@ -12,9 +12,10 @@ SET(PROJECT_HEADERS
     SketchPlugin_Constraint.h
     SketchPlugin_ConstraintCoincidence.h
     SketchPlugin_ConstraintDistance.h
-    SketchPlugin_ConstraintDiameter.h
+    SketchPlugin_ConstraintLength.h
     SketchPlugin_ConstraintParallel.h
     SketchPlugin_ConstraintPerpendicular.h
+    SketchPlugin_ConstraintRadius.h
 )
 
 SET(PROJECT_SOURCES
@@ -27,9 +28,10 @@ SET(PROJECT_SOURCES
     SketchPlugin_Arc.cpp
     SketchPlugin_ConstraintCoincidence.cpp
     SketchPlugin_ConstraintDistance.cpp
-    SketchPlugin_ConstraintDiameter.cpp
+    SketchPlugin_ConstraintLength.cpp
     SketchPlugin_ConstraintParallel.cpp
     SketchPlugin_ConstraintPerpendicular.cpp
+    SketchPlugin_ConstraintRadius.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDiameter.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDiameter.cpp
deleted file mode 100644 (file)
index 179cce9..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// File:    SketchPlugin_ConstraintDiameter.cpp
-// Created: 26 May 2014
-// Author:  Artem ZHIDKOV
-
-#include "SketchPlugin_ConstraintDiameter.h"
-
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
-
-SketchPlugin_ConstraintDiameter::SketchPlugin_ConstraintDiameter()
-{
-}
-
-void SketchPlugin_ConstraintDiameter::initAttributes()
-{
-  data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
-  data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
-}
-
-void SketchPlugin_ConstraintDiameter::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintDiameter::preview()
-{
-  /// \todo Preview for diameter constraint
-  return getPreview();
-}
-
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDiameter.h b/src/SketchPlugin/SketchPlugin_ConstraintDiameter.h
deleted file mode 100644 (file)
index 1ac7a32..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// File:    SketchPlugin_ConstraintDiameter.h
-// Created: 26 May 2014
-// Author:  Artem ZHIDKOV
-
-#ifndef SketchPlugin_ConstraintDiameter_HeaderFile
-#define SketchPlugin_ConstraintDiameter_HeaderFile
-
-#include "SketchPlugin.h"
-#include "SketchPlugin_Constraint.h"
-
-
-/** \class SketchPlugin_ConstraintDiameter
- *  \ingroup DataModel
- *  \brief Feature for creation of a new constraint which defines a diameter of a circle
- *
- *  These constraint has two attributes:
- *  CONSTRAINT_ATTR_VALUE (diameter), CONSTRAINT_ATTR_ENTITY_A (a circle)
- */
-class SketchPlugin_ConstraintDiameter: public SketchPlugin_Constraint
-{
-public:
-  /// \brief Returns the kind of a feature
-  SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
-  {static std::string MY_KIND = "SketchConstraintDiameter"; return MY_KIND;}
-
-  /// \brief Returns to which group in the document must be added feature
-  SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
-  {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
-
-  /// \brief Creates a new part document if needed
-  SKETCHPLUGIN_EXPORT virtual void execute();
-
-  /// \brief Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
-  /// \brief Returns the sketch preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
-  /// \brief Use plugin manager for features creation
-  SketchPlugin_ConstraintDiameter();
-};
-
-#endif
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
new file mode 100644 (file)
index 0000000..07a8690
--- /dev/null
@@ -0,0 +1,29 @@
+// File:    SketchPlugin_ConstraintLength.cpp
+// Created: 30 May 2014
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintLength.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+
+SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
+{
+}
+
+void SketchPlugin_ConstraintLength::initAttributes()
+{
+  data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
+  data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintLength::execute()
+{
+}
+
+const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintLength::preview()
+{
+  /// \todo Preview for distance constraint
+  return getPreview();
+}
+
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h
new file mode 100644 (file)
index 0000000..3e4cde4
--- /dev/null
@@ -0,0 +1,44 @@
+// File:    SketchPlugin_ConstraintLength.h
+// Created: 30 May 2014
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintLength_HeaderFile
+#define SketchPlugin_ConstraintLength_HeaderFile
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_Constraint.h"
+#include <list>
+
+
+/** \class SketchPlugin_ConstraintLength
+ *  \ingroup DataModel
+ *  \brief Feature for creation of a new constraint which defines a length of a line segment
+ *
+ *  These constraint has two attributes:
+ *  CONSTRAINT_ATTR_VALUE (length) and CONSTRAINT_ATTR_ENTITY_A (segment)
+ */
+class SketchPlugin_ConstraintLength: public SketchPlugin_Constraint
+{
+public:
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
+  {static std::string MY_KIND = "SketchConstraintLength"; return MY_KIND;}
+
+  /// \brief Returns to which group in the document must be added feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
+  {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// \brief Returns the sketch preview
+  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintLength();
+};
+
+#endif
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
new file mode 100644 (file)
index 0000000..6eb620f
--- /dev/null
@@ -0,0 +1,30 @@
+// File:    SketchPlugin_ConstraintRadius.cpp
+// Created: 26 May 2014
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintRadius.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <SketchPlugin_Point.h>
+
+SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
+{
+}
+
+void SketchPlugin_ConstraintRadius::initAttributes()
+{
+  data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
+  data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintRadius::execute()
+{
+}
+
+const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintRadius::preview()
+{
+  /// \todo Preview for diameter constraint
+  return getPreview();
+}
+
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h
new file mode 100644 (file)
index 0000000..26a0ecb
--- /dev/null
@@ -0,0 +1,44 @@
+// File:    SketchPlugin_ConstraintRadius.h
+// Created: 26 May 2014
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintRadius_HeaderFile
+#define SketchPlugin_ConstraintRadius_HeaderFile
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_Constraint.h"
+
+
+/** \class SketchPlugin_ConstraintRadius
+ *  \ingroup DataModel
+ *  \brief Feature for creation of a new constraint which defines 
+ *         a radius of a circle or an arc of circle
+ *
+ *  These constraint has two attributes:
+ *  CONSTRAINT_ATTR_VALUE (radius), CONSTRAINT_ATTR_ENTITY_A (a circle)
+ */
+class SketchPlugin_ConstraintRadius: public SketchPlugin_Constraint
+{
+public:
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
+  {static std::string MY_KIND = "SketchConstraintRadius"; return MY_KIND;}
+
+  /// \brief Returns to which group in the document must be added feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
+  {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// \brief Returns the sketch preview
+  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintRadius();
+};
+
+#endif
index bbbbd878e55ae9b791ddae879d7c0b9981293837..23a6cf05a17cc3fb364a10d7f616943df9d71c6b 100644 (file)
@@ -6,9 +6,10 @@
 #include "SketchPlugin_Arc.h"
 #include "SketchPlugin_ConstraintCoincidence.h"
 #include "SketchPlugin_ConstraintDistance.h"
-#include "SketchPlugin_ConstraintDiameter.h"
+#include "SketchPlugin_ConstraintLength.h"
 #include "SketchPlugin_ConstraintParallel.h"
 #include "SketchPlugin_ConstraintPerpendicular.h"
+#include "SketchPlugin_ConstraintRadius.h"
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
 
@@ -43,8 +44,8 @@ boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Plugin::createFeature(string th
   else if (theFeatureID == "SketchConstraintDistance") {
     return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintDistance);
   }
-  else if (theFeatureID == "SketchConstraintDiameter") {
-    return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintDiameter);
+  else if (theFeatureID == "SketchConstraintLength") {
+    return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintLength);
   }
   else if (theFeatureID == "SketchConstraintParallel") {
     return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintParallel);
@@ -52,6 +53,9 @@ boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Plugin::createFeature(string th
   else if (theFeatureID == "SketchConstraintPerpendicular") {
     return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintPerpendicular);
   }
+  else if (theFeatureID == "SketchConstraintRadius") {
+    return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintRadius);
+  }
   // feature of such kind is not found
   return boost::shared_ptr<ModelAPI_Feature>();
 }
index ff3007d33ccd65fcf67797bda938336235ff8883..d91e6066c9fd86126cf4a318f0d94d8f649a628e 100644 (file)
@@ -20,7 +20,8 @@
       </feature>
       <feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
       <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object" internal="1"/>
-      <feature id="SketchConstraintDiameter" title="Diameter of a circle" tooltip="Create constraint for the given diameter of a circle" internal="1"/>
+      <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment" internal="1"/>
+      <feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc" internal="1"/>
       <feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines" internal="1"/>
       <feature id="SketchConstraintPerpendicular" title="Orthgonality of a lines" tooltip="Create constraint defining two perpendicular lines" internal="1"/>
     </group>
index 2bfd8e697780bd2265b8c903347d3d017870868d..2e8a1fae82df22d5e3ba133b0d157b112ea4971e 100644 (file)
@@ -138,6 +138,28 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr<SketchPlugin_Const
     return getType();
   }
 
+  // Constraint for the given length of a line
+  if (aConstraintKind.compare("SketchConstraintLength") == 0)
+  {
+    int aNbLines = 0;
+    for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
+    {
+      boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
+        );
+      if (!anAttr) continue;
+      if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0)
+      {
+        myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr];
+        break;
+      }
+    }
+    if (aNbLines == 1)
+      myType = SLVS_C_PT_PT_DISTANCE;
+    return getType();
+  }
+
   // Constraint for two parallel/perpendicular lines
   bool isParallel = (aConstraintKind.compare("SketchConstraintParallel") == 0);
   bool isPerpendicular = (aConstraintKind.compare("SketchConstraintPerpendicular") == 0);
@@ -163,8 +185,8 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr<SketchPlugin_Const
     return getType();
   }
 
-  // Constraint for diameter of a circle
-  if (aConstraintKind.compare("SketchConstraintDiameter") == 0)
+  // Constraint for radius of a circle or an arc of circle
+  if (aConstraintKind.compare("SketchConstraintRadius") == 0)
   {
     int aNbEntities = 2; // lines in SolveSpace constraints should started from CONSTRAINT_ATTR_ENTITY_C attribute
     for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
@@ -175,7 +197,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr<SketchPlugin_Const
         );
       if (!anAttr || !anAttr->isFeature()) continue;
       const std::string& aKind = anAttr->feature()->getKind();
-      if (aKind.compare("SketchCircle") == 0)
+      if (aKind.compare("SketchCircle") == 0 || aKind.compare("SketchArc") == 0)
       {
         myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr];
         continue;
index 3b8a08211c51475eed4cd5c70dfb7049566c2069..944d4ce4b90a4f7082049a0559a8b3c64bb6aeee 100644 (file)
@@ -116,7 +116,11 @@ bool SketchSolver_ConstraintGroup::isInteract(
         theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i])
       );
     if (!aCAttrRef) continue;
-    if (myEntityMap.find(aCAttrRef->attr()) != myEntityMap.end())
+    if (!aCAttrRef->isFeature() && 
+        myEntityAttrMap.find(aCAttrRef->attr()) != myEntityAttrMap.end())
+      return true;
+    if (aCAttrRef->isFeature() && 
+        myEntityFeatMap.find(aCAttrRef->feature()) != myEntityFeatMap.end())
       return true;
   }
 
@@ -166,6 +170,9 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
       myNeedToSolve = true;
       aConstrIter->valA = aDistance;
     }
+    // SketchPlugin circle defined by its radius, but SolveSpace uses constraint for diameter
+    if (aConstrType == SLVS_C_DIAMETER)
+      aDistance *= 2.0;
   }
 
   Slvs_hEntity aConstrEnt[CONSTRAINT_ATTR_SIZE]; // parameters of the constraint
@@ -177,7 +184,19 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
         theConstraint->data()->attribute(aConstraintAttributes[indAttr])
       );
     if (!aConstrAttr) continue;
-    aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
+
+    // For the length constraint the start and end points of the line should be added to the entities list instead of line
+    if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare("SketchConstraintLength") == 0)
+    {
+      boost::shared_ptr<ModelAPI_Data> aData = aConstrAttr->feature()->data();
+      aConstrEnt[indAttr]   = changeEntity(aData->attribute(LINE_ATTR_START));
+      aConstrEnt[indAttr+1] = changeEntity(aData->attribute(LINE_ATTR_END));
+      break; // there should be no other entities
+    }
+    else if (aConstrAttr->isFeature())
+      aConstrEnt[indAttr] = changeEntity(aConstrAttr->feature());
+    else
+      aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
   }
 
   if (aConstrMapIter == myConstraintMap.end())
@@ -247,9 +266,9 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
 {
   // If the entity is already in the group, try to find it
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
-    aEntIter = myEntityMap.find(theEntity);
+    aEntIter = myEntityAttrMap.find(theEntity);
   std::vector<Slvs_Param>::const_iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise
-  if (aEntIter == myEntityMap.end()) // no such entity => should be created
+  if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created
     aParamIter = myParams.end();
   else
   { // the entity already exists
@@ -257,6 +276,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
     int aParamPos = Search(myEntities[aEntPos].param[0], myParams);
     aParamIter = myParams.begin() + aParamPos;
   }
+  const bool isEntExists = (aEntIter != myEntityAttrMap.end()); // defines that the entity already exists
 
   // Look over supported types of entities
 
@@ -269,13 +289,13 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
     Slvs_hParam aY = changeParameter(aPoint->y(), aParamIter);
     Slvs_hParam aZ = changeParameter(aPoint->z(), aParamIter);
 
-    if (aEntIter != myEntityMap.end()) // the entity already exists
+    if (isEntExists)
       return aEntIter->second;
 
     // New entity
     Slvs_Entity aPtEntity = Slvs_MakePoint3d(++myEntityMaxID, myID, aX, aY, aZ);
     myEntities.push_back(aPtEntity);
-    myEntityMap[theEntity] = aPtEntity.h;
+    myEntityAttrMap[theEntity] = aPtEntity.h;
     return aPtEntity.h;
   }
 
@@ -291,13 +311,13 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
     Slvs_hParam aU = changeParameter(aPoint2D->x(), aParamIter);
     Slvs_hParam aV = changeParameter(aPoint2D->y(), aParamIter);
 
-    if (aEntIter != myEntityMap.end()) // the entity already exists
+    if (isEntExists)
       return aEntIter->second;
 
     // New entity
     Slvs_Entity aPt2DEntity = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, aU, aV);
     myEntities.push_back(aPt2DEntity);
-    myEntityMap[theEntity] = aPt2DEntity.h;
+    myEntityAttrMap[theEntity] = aPt2DEntity.h;
     return aPt2DEntity.h;
   }
 
@@ -308,18 +328,39 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
   {
     Slvs_hParam aValue = changeParameter(aScalar->value(), aParamIter);
 
-    if (aEntIter != myEntityMap.end()) // the entity already exists
+    if (isEntExists)
       return aEntIter->second;
 
     // New entity
     Slvs_Entity aDistance = Slvs_MakeDistance(++myEntityMaxID, myID, myWorkplane.h, aValue);
     myEntities.push_back(aDistance);
-    myEntityMap[theEntity] = aDistance.h;
+    myEntityAttrMap[theEntity] = aDistance.h;
     return aDistance.h;
   }
 
+  /// \todo Other types of entities
+
+  // Unsupported or wrong entity type
+  return SLVS_E_UNKNOWN;
+}
+
+
+// ============================================================================
+//  Function: changeEntity
+//  Class:    SketchSolver_ConstraintGroup
+//  Purpose:  create/update the element defined by the feature affected by any constraint
+// ============================================================================
+Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
+                boost::shared_ptr<ModelAPI_Feature> theEntity)
+{
+  // If the entity is already in the group, try to find it
+  std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::const_iterator
+    aEntIter = myEntityFeatMap.find(theEntity);
+  // defines that the entity already exists
+  const bool isEntExists = (myEntityFeatMap.find(theEntity) != myEntityFeatMap.end());
+
   // SketchPlugin features
-  boost::shared_ptr<SketchPlugin_Feature> aFeature =
+  boost::shared_ptr<SketchPlugin_Feature> aFeature;
     boost::dynamic_pointer_cast<SketchPlugin_Feature>(theEntity);
   if (aFeature)
   { // Verify the feature by its kind
@@ -331,13 +372,13 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
       Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(LINE_ATTR_START));
       Slvs_hEntity aEnd   = changeEntity(aFeature->data()->attribute(LINE_ATTR_END));
 
-      if (aEntIter != myEntityMap.end()) // the entity already exists
+      if (isEntExists)
         return aEntIter->second;
 
       // New entity
       Slvs_Entity aLineEntity = Slvs_MakeLineSegment(++myEntityMaxID, myID, myWorkplane.h, aStart, aEnd);
       myEntities.push_back(aLineEntity);
-      myEntityMap[theEntity] = aLineEntity.h;
+      myEntityFeatMap[theEntity] = aLineEntity.h;
       return aLineEntity.h;
     }
     // Circle
@@ -346,14 +387,14 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
       Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_CENTER));
       Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_RADIUS));
 
-      if (aEntIter != myEntityMap.end()) // the entity already exists
+      if (isEntExists)
         return aEntIter->second;
 
       // New entity
       Slvs_Entity aCircleEntity = 
         Slvs_MakeCircle(++myEntityMaxID, myID, myWorkplane.h, aCenter, myWorkplane.normal, aRadius);
       myEntities.push_back(aCircleEntity);
-      myEntityMap[theEntity] = aCircleEntity.h;
+      myEntityFeatMap[theEntity] = aCircleEntity.h;
       return aCircleEntity.h;
     }
     // Arc
@@ -363,13 +404,13 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
       Slvs_hEntity aStart  = changeEntity(aFeature->data()->attribute(ARC_ATTR_START));
       Slvs_hEntity aEnd    = changeEntity(aFeature->data()->attribute(ARC_ATTR_END));
 
-      if (aEntIter != myEntityMap.end()) // the entity already exists
+      if (isEntExists)
         return aEntIter->second;
 
       Slvs_Entity anArcEntity = Slvs_MakeArcOfCircle(++myEntityMaxID, myID, 
                                   myWorkplane.h, myWorkplane.normal, aCenter, aStart, aEnd);
       myEntities.push_back(anArcEntity);
-      myEntityMap[theEntity] = anArcEntity.h;
+      myEntityFeatMap[theEntity] = anArcEntity.h;
       return anArcEntity.h;
     }
     // Point (it has low probability to be an attribute of constraint, so it is checked at the end)
@@ -377,16 +418,16 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
     {
       Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(POINT_ATTR_COORD));
 
-      if (aEntIter != myEntityMap.end()) // the entity already exists
+      if (isEntExists)
         return aEntIter->second;
 
       // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier
-      myEntityMap[theEntity] = aPoint;
+      myEntityFeatMap[theEntity] = aPoint;
       return aPoint;
     }
   }
 
-  /// \todo Other types of entities
+  /// \todo Other types of features
 
   // Unsupported or wrong entity type
   return SLVS_E_UNKNOWN;
@@ -420,9 +461,9 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal(
 
   // Try to find existent normal
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
-    aEntIter = myEntityMap.find(theNorm);
+    aEntIter = myEntityAttrMap.find(theNorm);
   std::vector<Slvs_Param>::const_iterator aParamIter; // looks to the first parameter of already existent entity or to the end of vector otherwise
-  if (aEntIter == myEntityMap.end()) // no such entity => should be created
+  if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created
     aParamIter = myParams.end();
   else
   { // the entity already exists, update it
@@ -436,14 +477,14 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal(
   for (int i = 0; i < 4; i++)
     aNormParams[i] = changeParameter(aNormCoord[i], aParamIter);
 
-  if (aEntIter != myEntityMap.end()) // the entity already exists
+  if (aEntIter != myEntityAttrMap.end()) // the entity already exists
     return aEntIter->second;
 
   // Create a normal
   Slvs_Entity aNormal = Slvs_MakeNormal3d(++myEntityMaxID, myID,
                 aNormParams[0], aNormParams[1], aNormParams[2], aNormParams[3]);
   myEntities.push_back(aNormal);
-  myEntityMap[theNorm] = aNormal.h;
+  myEntityAttrMap[theNorm] = aNormal.h;
   return aNormal.h;
 }
 
@@ -545,9 +586,10 @@ void SketchSolver_ConstraintGroup::resolveConstraints()
     if (!myConstrSolver.getResult(myParams))
       return;
 
+    // We should go through the attributes map, because only attributes have valued parameters
     std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
-      anEntIter = myEntityMap.begin();
-    for ( ; anEntIter != myEntityMap.end(); anEntIter++)
+      anEntIter = myEntityAttrMap.begin();
+    for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++)
       updateAttribute(anEntIter->first, anEntIter->second);
   }
   /// \todo Implement error handling
@@ -592,8 +634,8 @@ void SketchSolver_ConstraintGroup::mergeGroups(
   else if (!theGroup.myTempPointWhereDragged.empty())
   { // Need to create additional transient constraint
     std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
-      aFeatureIter = theGroup.myEntityMap.begin();
-    for (; aFeatureIter != theGroup.myEntityMap.end(); aFeatureIter++)
+      aFeatureIter = theGroup.myEntityAttrMap.begin();
+    for (; aFeatureIter != theGroup.myEntityAttrMap.end(); aFeatureIter++)
       if (aFeatureIter->second == myTempPointWDrgdID)
       {
         addTemporaryConstraintWhereDragged(aFeatureIter->first);
@@ -797,7 +839,7 @@ void SketchSolver_ConstraintGroup::updateAttribute(
 void SketchSolver_ConstraintGroup::updateEntityIfPossible(
                 boost::shared_ptr<ModelAPI_Attribute> theEntity)
 {
-  if (myEntityMap.find(theEntity) != myEntityMap.end())
+  if (myEntityAttrMap.find(theEntity) != myEntityAttrMap.end())
   {
     // If the attribute is a point and it is changed (the group needs to rebuild),
     // probably user has dragged this point into this position,
@@ -836,8 +878,8 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
 {
   // Find identifier of the entity
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
-    anEntIter = myEntityMap.find(theEntity);
-  if (anEntIter == myEntityMap.end())
+    anEntIter = myEntityAttrMap.find(theEntity);
+  if (anEntIter == myEntityAttrMap.end())
     return ;
 
   // If this is a first dragged point, its parameters should be placed 
@@ -952,17 +994,30 @@ void SketchSolver_ConstraintGroup::removeConstraint(boost::shared_ptr<SketchPlug
 
   // Remove unused entities
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
-    anEntMapIter = myEntityMap.begin();
-  while (anEntMapIter != myEntityMap.end())
+    anEntAttrIter = myEntityAttrMap.begin();
+  while (anEntAttrIter != myEntityAttrMap.end())
   {
-    if (anEntToRemove.find(anEntMapIter->second) != anEntToRemove.end())
+    if (anEntToRemove.find(anEntAttrIter->second) != anEntToRemove.end())
     {
       std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
-        aRemovedIter = anEntMapIter;
-      anEntMapIter++;
-      myEntityMap.erase(aRemovedIter);
+        aRemovedIter = anEntAttrIter;
+      anEntAttrIter++;
+      myEntityAttrMap.erase(aRemovedIter);
+    }
+    else anEntAttrIter++;
+  }
+  std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+    anEntFeatIter = myEntityFeatMap.begin();
+  while (anEntFeatIter != myEntityFeatMap.end())
+  {
+    if (anEntToRemove.find(anEntFeatIter->second) != anEntToRemove.end())
+    {
+      std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+        aRemovedIter = anEntFeatIter;
+      anEntFeatIter++;
+      myEntityFeatMap.erase(aRemovedIter);
     }
-    else anEntMapIter++;
+    else anEntFeatIter++;
   }
   std::set<Slvs_hEntity>::const_reverse_iterator aRemIter = anEntToRemove.rbegin();
   for ( ; aRemIter != anEntToRemove.rend(); aRemIter++)
index fe629046b16ef4ed3b8f9bcd7dce62cfe2b74ae8..3d0ef2245c68875f82e794b1cb7b2d34509eaf35 100644 (file)
@@ -104,6 +104,7 @@ protected:
    *  \return identifier of changed entity or 0 if entity could not be changed
    */
   Slvs_hEntity changeEntity(boost::shared_ptr<ModelAPI_Attribute> theEntity);
+  Slvs_hEntity changeEntity(boost::shared_ptr<ModelAPI_Feature>   theEntity);
 
   /** \brief Adds or updates a normal in the group
    *
@@ -182,7 +183,9 @@ private:
   std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>
                                myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>
-                               myEntityMap;     ///< The map between parameters of constraints and their equivalent SolveSpace entities
+                               myEntityAttrMap;     ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities
+  std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>
+                               myEntityFeatMap;     ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
 
   // Conincident items
   std::vector< std::set<Slvs_hEntity> >