]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Collinear and coinciding point constraints problem (issue #1318)
authorazv <azv@opencascade.com>
Mon, 29 Feb 2016 13:54:35 +0000 (16:54 +0300)
committerazv <azv@opencascade.com>
Mon, 29 Feb 2016 13:55:32 +0000 (16:55 +0300)
Improve working with coincident points.

src/SketchSolver/CMakeLists.txt
src/SketchSolver/SketchSolver_Builder.cpp
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Constraint.h
src/SketchSolver/SketchSolver_ConstraintCollinear.cpp [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintCollinear.h [new file with mode: 0644]
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h

index e8ebc506c114a3edcfada67adda3634b40adde58..b2eb5473852d5c464dc5cd6f91822e05421a5bbe 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
     SketchSolver_Constraint.h
     SketchSolver_ConstraintAngle.h
     SketchSolver_ConstraintCoincidence.h
+    SketchSolver_ConstraintCollinear.h
     SketchSolver_ConstraintDistance.h
     SketchSolver_ConstraintEqual.h
     SketchSolver_ConstraintLength.h
@@ -33,6 +34,7 @@ SET(PROJECT_SOURCES
     SketchSolver_Constraint.cpp
     SketchSolver_ConstraintAngle.cpp
     SketchSolver_ConstraintCoincidence.cpp
+    SketchSolver_ConstraintCollinear.cpp
     SketchSolver_ConstraintDistance.cpp
     SketchSolver_ConstraintEqual.cpp
     SketchSolver_ConstraintLength.cpp
index dece279ca8e054703f825bcdef9aec4440168637..4709e683388b2b7acb4c035ef31ce48c683a71be 100644 (file)
@@ -8,6 +8,7 @@
 #include <SketchSolver_Constraint.h>
 #include <SketchSolver_ConstraintAngle.h>
 #include <SketchSolver_ConstraintCoincidence.h>
+#include <SketchSolver_ConstraintCollinear.h>
 #include <SketchSolver_ConstraintDistance.h>
 #include <SketchSolver_ConstraintEqual.h>
 #include <SketchSolver_ConstraintFixed.h>
@@ -28,6 +29,7 @@
 
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintEqual.h>
 #include <SketchPlugin_ConstraintLength.h>
@@ -77,6 +79,8 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons
 
   if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint));
+  } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) {
+    return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) {
index 1d765142e4fee658c7a4953ef5ad680fc80e88d3..fcb2a1fc138371fb94e349c6886f9cd1b60249a1 100644 (file)
@@ -201,6 +201,7 @@ void SketchSolver_Constraint::getAttributes(
 {
   static const int anInitNbOfAttr = 4;
   theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr());
+  myAttributes.clear();
 
   DataPtr aData = myBaseConstraint->data();
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
@@ -225,6 +226,7 @@ void SketchSolver_Constraint::getAttributes(
 
     myStorage->update(*anIter/*, myGroupID*/);
     EntityWrapperPtr anEntity = myStorage->entity(*anIter);
+    myAttributes.push_back(anEntity);
 
     SketchSolver_EntityType aType = anEntity->type();
     if (aType == ENTITY_UNKNOWN)
index 3f6e0f281ff300455c1dd650d3f4c46d3002ca54..dbb64762394677943d612f1cf8faa6e13257b0f1 100644 (file)
@@ -57,11 +57,19 @@ public:
   virtual SketchSolver_ConstraintType getType() const
   { return myType; }
 
+  /// \brief Returns list of attributes of constraint
+  const std::list<EntityWrapperPtr>& attributes() const
+  { return myAttributes; }
+
   /// \brief Verify the feature or any its attribute is used by constraint
   virtual bool isUsed(FeaturePtr theFeature) const;
   /// \brief Verify the attribute is used by constraint
   virtual bool isUsed(AttributePtr theAttribute) const;
 
+  /// \brief Notify constraint, that coincidence appears or removed
+  virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2)
+  { /* implement in derived class */ }
+
   /// \brief Shows error message
   const std::string& error() const
   { return myErrorMsg; }
@@ -90,6 +98,7 @@ protected:
   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
   StoragePtr    myStorage; ///< storage, which contains all information about entities and constraints
   SketchSolver_ConstraintType myType; ///< type of constraint
+  std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
 
   std::string   myErrorMsg; ///< error message
 };
diff --git a/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp b/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp
new file mode 100644 (file)
index 0000000..6827826
--- /dev/null
@@ -0,0 +1,54 @@
+#include <SketchSolver_ConstraintCollinear.h>
+#include <SketchSolver_Manager.h>
+
+#include <SketchPlugin_Line.h>
+
+SketchSolver_ConstraintCollinear::SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint)
+  : SketchSolver_Constraint(theConstraint)
+{
+}
+
+void SketchSolver_ConstraintCollinear::notifyCoincidenceChanged(
+    EntityWrapperPtr theCoincAttr1,
+    EntityWrapperPtr theCoincAttr2)
+{
+  bool used = true;
+
+  // obtain IDs of all boundary points of lines
+  EntityID aPointIDs[4];
+  for (int i = 0; i < 2; ++i) {
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
+    if (!aRefAttr->object())
+      continue;
+    FeaturePtr aLine = ModelAPI_Feature::feature(aRefAttr->object());
+    AttributePtr aLinePt = aLine->attribute(SketchPlugin_Line::START_ID());
+    aPointIDs[2*i] = myStorage->entity(aLinePt)->id();
+    aLinePt = aLine->attribute(SketchPlugin_Line::END_ID());
+    aPointIDs[2*i + 1] = myStorage->entity(aLinePt)->id();
+  }
+
+  EntityWrapperPtr anAttrs[2] = {theCoincAttr1, theCoincAttr2};
+  for (int i = 0; i < 2 && used; ++i) {
+    if (anAttrs[i]->baseAttribute())
+      used = used && isUsed(anAttrs[i]->baseAttribute());
+    else
+      used = used && isUsed(anAttrs[i]->baseFeature());
+
+    if (!used) {
+      if (anAttrs[i]->type() == ENTITY_POINT) {
+        EntityID anID = anAttrs[i]->id();
+        for (int j = 0; j < 4; ++j)
+          if (anID == aPointIDs[j]) {
+            used = true;
+            break;
+          }
+      }
+    }
+  }
+
+  if (used) {
+    remove();
+    process();
+  }
+}
diff --git a/src/SketchSolver/SketchSolver_ConstraintCollinear.h b/src/SketchSolver/SketchSolver_ConstraintCollinear.h
new file mode 100644 (file)
index 0000000..6299740
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    SketchSolver_ConstraintCollinear.h
+// Created: 27 May 2014
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintCollinear_H_
+#define SketchSolver_ConstraintCollinear_H_
+
+#include <SketchSolver_Constraint.h>
+
+/** \class   SketchSolver_ConstraintCollinear
+ *  \ingroup Plugins
+ *  \brief   Converts collinear constraint to the constraint applicable for solver
+ */
+class SketchSolver_ConstraintCollinear : public SketchSolver_Constraint
+{
+public:
+  /// Constructor based on SketchPlugin constraint
+  SKETCHSOLVER_EXPORT SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint);
+
+  virtual ~SketchSolver_ConstraintCollinear() {}
+
+  /// \brief Notify constraint, that coincidence appears or removed
+  virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2);
+};
+
+#endif
index c2034c1576d3f703cda07d094aedd0db8721c458..6a2dc0a0009fa1f0f095baf48ab67a5df3dfcd38 100644 (file)
@@ -169,6 +169,9 @@ bool SketchSolver_Group::changeConstraint(
       Events_Error::send(aConstraint->error(), this);
     }
     myConstraints[theConstraint] = aConstraint;
+
+    if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+      notifyCoincidenceChanged(myConstraints[theConstraint]);
   }
   else
     myConstraints[theConstraint]->update();
@@ -561,6 +564,8 @@ void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
   for (; aCIter != myConstraints.end(); aCIter++)
     if (aCIter->first == theConstraint) {
       aCIter->second->remove(); // the constraint is not fully removed
+      if (aCIter->first->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+        notifyCoincidenceChanged(aCIter->second);
       break;
     }
   if (aCIter != myConstraints.end())
@@ -674,3 +679,13 @@ std::list<FeaturePtr> SketchSolver_Group::selectApplicableFeatures(const std::se
   return aResult;
 }
 
+void SketchSolver_Group::notifyCoincidenceChanged(SolverConstraintPtr theCoincidence)
+{
+  const std::list<EntityWrapperPtr>& aCoincident = theCoincidence->attributes();
+  EntityWrapperPtr anAttr1 = aCoincident.front();
+  EntityWrapperPtr anAttr2 = aCoincident.back();
+
+  ConstraintConstraintMap::iterator anIt = myConstraints.begin();
+  for (; anIt != myConstraints.end(); ++anIt)
+    anIt->second->notifyCoincidenceChanged(anAttr1, anAttr2);
+}
index f814dda84a19e87a8586fd46197b8c8a0a46070b..89a14f49072f636f22721367182e52d385c498a5 100644 (file)
@@ -155,6 +155,10 @@ private:
   /// \brief Verifies is the feature valid
   bool checkFeatureValidity(FeaturePtr theFeature);
 
+  /// \brief Notify all interested constraints that coincidence appears or removed
+  /// \param[in] theCoincidence  coincidence constraint
+  void notifyCoincidenceChanged(SolverConstraintPtr theCoincidence);
+
 private:
   GroupID  myID; ///< Index of the group
   EntityID myWorkplaneID; ///< Index of workplane, the group is based on