Salome HOME
Fix problems in sketch unit tests
authorazv <azv@opencascade.com>
Mon, 22 Aug 2016 13:00:32 +0000 (16:00 +0300)
committerazv <azv@opencascade.com>
Mon, 22 Aug 2016 13:00:32 +0000 (16:00 +0300)
src/GeomAPI/GeomAPI_Circ2d.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/SketchPlugin/Test/TestConstraintAngle.py
src/SketchPlugin/Test/TestConstraintMirror.py
src/SketchPlugin/Test/TestFillet.py
src/SketchPlugin/Test/TestSketchArcCircle.py
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp

index 4ac7458640a9e61f1ef6681aa0c3eb6689615353..cbb16dd4be9757a23c4c84b90dc6cef6553a33ca 100644 (file)
@@ -39,7 +39,7 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
   if (aCenter.IsEqual(aPoint, Precision::Confusion()))
     return NULL;
 
-  gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
+  gp_Dir2d aDir(thePointX - theCenterX, thePointY - theCenterY);
 
   return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
 }
index 7f4e3e58ae1c8f63c1c246dee2e58203b11b0d27..ce17351bc7b6f90f45c9f8d30e80a5cfb6bb4edd 100644 (file)
@@ -36,7 +36,7 @@
 #include <ios>
 #include <cmath>
 
-#define PRECISION 7
+#define PRECISION 6
 #define TOLERANCE (1.e-7)
 
 ModelHighAPI_FeatureStore::ModelHighAPI_FeatureStore(FeaturePtr theFeature) {
@@ -117,12 +117,12 @@ std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data
   return "";
 }
 
-static void dumpArray(std::ostringstream& theOutput, const double theArray[], int theSize)
+static void dumpArray(std::ostringstream& theOutput, const double theArray[], int theSize, int thePrecision = PRECISION)
 {
   for (int i = 0; i < theSize; ++i) {
     if (i > 0)
       theOutput << " ";
-    theOutput << std::fixed << setprecision(PRECISION)
+    theOutput << std::fixed << setprecision(thePrecision)
               << (fabs(theArray[i]) < TOLERANCE ? 0.0 : theArray[i]);
   }
 }
@@ -168,9 +168,14 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       aResult<<anAttr->text();
   } else if (aType == ModelAPI_AttributeDouble::typeId()) {
     AttributeDoublePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttr);
+    int aPrecision = PRECISION;
+    // Special case - precision for the arc angle. It is calculated with tolerance 1e-4,
+    // so the value has only 4 correct digits
+    if (anAttr->id() == "ArcAngle")
+      aPrecision = 1;
     if (anAttr->text().empty()) {
       double aVal = anAttr->value();
-      dumpArray(aResult, &aVal, 1);
+      dumpArray(aResult, &aVal, 1, aPrecision);
     } else
       aResult<<anAttr->text();
   } else if (aType == ModelAPI_AttributeBoolean::typeId()) {
@@ -298,7 +303,9 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>&
   // output the main characteristics
   aResult<<"Volume: "<<setprecision(2)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
-  aResult<<"Center of mass: "<<std::fixed<<setprecision(PRECISION)
-    <<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
+  aResult<<"Center of mass: ";
+  double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()};
+  dumpArray(aResult, aCenterVals, 3);
+  aResult<<std::endl;
   return aResult.str();
 }
index ac56c287c20fbe718ed8beaa04d5bef1d220778e..3070252604dc486fe525174beb2565cb5dcd841a 100644 (file)
@@ -113,7 +113,7 @@ assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE)
 #=========================================================================
 aSession.startOperation()
 aStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
-aStartPoint.setValue(0., 30.)
+aStartPoint.setValue(0., -30.)
 aConstraint.execute()
 aSession.finishOperation()
 assert (angle(aSketchLineA, aSketchLineB) == ANGLE_DEGREE)
index 30e8570f41d43859049d537079c851990be69ae9..25b7eeecb6c7cf97def16038767e34f3df2827c7 100644 (file)
@@ -202,5 +202,26 @@ checkMirror(aRefListB, aRefListC, aMirrorLine)
 # End of test
 #=========================================================================
 
+
+# make second line fixed
+aSession.startOperation()
+aFixed = aSketchFeature.addFeature("SketchConstraintRigid")
+aRefObjectA = aFixed.refattr("ConstraintEntityA")
+anObjectA = modelAPI_ResultConstruction(aSketchLine2.lastResult())
+assert (anObjectA is not None)
+aRefObjectA.setObject(anObjectA)
+aFixed.execute()
+aSession.finishOperation()
+# set mirror for first line to check dumping
+aSession.startOperation()
+aRefListInitial.clear()
+assert (aRefListB.size() == 0)
+assert (aRefListC.size() == 0)
+aRefListInitial.append(aSketchLine1.lastResult())
+aSession.finishOperation()
+assert (aRefListB.size() == 1)
+assert (aRefListC.size() == 1)
+checkMirror(aRefListB, aRefListC, aMirrorLine)
+
 import model
 assert(model.checkPythonDump())
index 69a2d6fc18dcc0532014b397faea2aef809c344a..5b7bebb299b69bc36d8a83011de13677b8ff5ea1 100644 (file)
@@ -66,7 +66,7 @@ def createSketch2(theSketch):
     aStartPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
     aEndPoint1   = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
     aStartPoint1.setValue(10., 10.)
-    aEndPoint1.setValue(30., 5.)
+    aEndPoint1.setValue(30., 15.)
     allFeatures.append(aSketchLine)
     # Arc
     aSketchArc = theSketch.addFeature("SketchArc")
@@ -219,6 +219,7 @@ checkFillet(aResObjects, FILLET_RADIUS1)
 # Change Fillet radius
 #=========================================================================
 aRadius.setValue(FILLET_RADIUS2)
+aFillet.execute()
 aSession.finishOperation()
 checkFillet(aResObjects, FILLET_RADIUS2)
 
@@ -271,6 +272,7 @@ checkFillet(aResObjects, FILLET_RADIUS1)
 # Change Fillet radius
 #=========================================================================
 aRadius.setValue(FILLET_RADIUS2)
+aFillet.execute()
 aSession.finishOperation()
 checkFillet(aResObjects, FILLET_RADIUS2)
 #=========================================================================
index 897e9bb779a14c4c9cc9402bb77d6b52d6e0e915..ed61f3fae28c84de90367df65fc08423bb4835f1 100644 (file)
@@ -210,6 +210,12 @@ aLineStart.setValue(0., 0.)
 aLineEnd.setValue(50., 0.)
 aSession.finishOperation()
 aSession.startOperation()
+aFixed = aSketchFeature.addFeature("SketchConstraintRigid")
+aRefObjectA = aFixed.refattr("ConstraintEntityA")
+aRefObjectA.setObject(modelAPI_ResultConstruction(aSketchLine.lastResult()))
+aFixed.execute()
+aSession.finishOperation()
+aSession.startOperation()
 aSketchArcTangent = aSketchFeature.addFeature("SketchArc")
 aSketchArcTangent.string("ArcType").setValue("Tangent")
 anArcEndPoint = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcEndPoint"))
@@ -232,10 +238,7 @@ aSketchArcTangent2.string("ArcType").setValue("Tangent")
 anArcEndPoint2 = geomDataAPI_Point2D(aSketchArcTangent2.attribute("ArcEndPoint"))
 aTangent = aSketchArcTangent2.refattr("ArcTangentPoint")
 aTangent.setAttr(anArcEndPoint)
-anArcEndPoint2.setValue(anArcEndPoint.x() + 1, anArcEndPoint.y() + 1)
-aSession.finishOperation()
-aSession.startOperation()
-anArcEndPoint2.setValue(50., 50.)
+anArcEndPoint2.setValue(50., 150.)
 aSession.finishOperation()
 #=========================================================================
 # End of test
index b73391a9175c22212a054b603c2b4f17ca892ef4..a7c348db78a0c00b73b3ee9be87ea8a550d2c90d 100644 (file)
@@ -856,7 +856,7 @@ ConstraintWrapperPtr createConstraintMiddlePoint(
   aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintPointOnLine(*aPoint, *aLine)));
   double aDist = lineLength(*aLine);
   std::shared_ptr<PlaneGCSSolver_ParameterWrapper> aDistance =
-      std::dynamic_pointer_cast<PlaneGCSSolver_ParameterWrapper>(createParameter(theGroupID, aDist));
+      std::dynamic_pointer_cast<PlaneGCSSolver_ParameterWrapper>(createParameter(theGroupID, aDist * 0.5));
   aConstrList.push_back(GCSConstraintPtr(
       new GCS::ConstraintP2PDistance(*aPoint, aLine->p1, aDistance->parameter())));
   aConstrList.push_back(GCSConstraintPtr(