Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.cpp
index 980c51879e3574c5c2b008545912f2c6ce3339a6..e4af2a0643970b1518b35cd344566ccaffdce20a 100644 (file)
@@ -20,6 +20,7 @@
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintRadius.h>
 #include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
@@ -229,8 +230,7 @@ const int& SketchSolver_Constraint::getType(
       std::shared_ptr<ModelAPI_Attribute> anAttr = 
           aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
       AttrType aType = typeOfAttribute(anAttr);
-      if (aType == LINE)
-      {
+      if (aType == LINE) {
         myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
         aNbLines++;
       }
@@ -242,6 +242,26 @@ const int& SketchSolver_Constraint::getType(
     return getType();
   }
 
+  if (aConstraintKind.compare(SketchPlugin_ConstraintTangent::ID()) == 0)
+  {
+    static const int anArcPosDefault = 2;
+    static const int aLinePosDefault = 3;
+    int anArcPos = anArcPosDefault; // arc in tangency constraint should be placed before line
+    int aLinePos = aLinePosDefault;
+    for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+      std::shared_ptr<ModelAPI_Attribute> anAttr = 
+          aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+      AttrType aType = typeOfAttribute(anAttr);
+      if (aType == LINE && aLinePos < CONSTRAINT_ATTR_SIZE)
+        myAttributesList[aLinePos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+      else if (aType == ARC)
+        myAttributesList[anArcPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+    }
+    if (anArcPos - anArcPosDefault + aLinePos - aLinePosDefault == 2)
+      myType = aLinePos > 3 ? SLVS_C_ARC_LINE_TANGENT : SLVS_C_CURVE_CURVE_TANGENT;
+    return getType();
+  }
+
   /// \todo Implement other kind of constraints
 
   return getType();