]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix errors and adjust unit tests
authorazv <azv@opencascade.com>
Wed, 17 Aug 2016 13:13:32 +0000 (16:13 +0300)
committerazv <azv@opencascade.com>
Wed, 17 Aug 2016 13:13:32 +0000 (16:13 +0300)
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/SketchAPI/SketchAPI_Projection.h
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchPlugin/SketchPlugin_Projection.cpp
src/SketchPlugin/Test/TestConstraintAngle.py
src/SketchPlugin/Test/TestConstraintEqual.py
src/SketchPlugin/Test/TestConstraintTangent.py
src/SketchPlugin/Test/TestFillet.py
src/SketchPlugin/Test/TestHighload.py
src/SketchPlugin/Test/TestProjection.py

index 32dbc5776b8cc15b5c563ed86eec5162598ddb6c..dfc6c389bc5146cd3f3087baec294ea9abe7e5cf 100644 (file)
@@ -105,10 +105,10 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity)
       int anId = std::stoi(anIdStr);
 
       // Check number of already registered objects of such kind. Index of current object
-      // should be greater than it to identify feature's name as automatically generated.
-      if (aNbFeatures < anId) {
+      // should be the same to identify feature's name as automatically generated.
+      if (aNbFeatures + 1 == anId) {
         isUserDefined = false;
-        aNbFeatures = anId - 1;
+        //aNbFeatures = anId - 1;
       }
     }
 
index f45f90017fcb98620c307b6c01fc393e35f02749..326f4a16ba960b2347e040961c4fc15090d280da 100644 (file)
@@ -118,11 +118,22 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
   if (aFeatOwner.get() && !aFactory->isCase(aFeatOwner, theAttr->id())) {
     return "__notcase__";
   }
+  std::string aType = theAttr->attributeType();
+  std::ostringstream aResult;
   if (!theAttr->isInitialized()) {
+    if (aType == ModelAPI_AttributeBoolean::typeId()) {
+      // special case for Boolean attribute (mean it false if not initialized)
+      aResult << false;
+      return aResult.str();
+    } else if (aType == ModelAPI_AttributeString::typeId()) {
+      // special case for attribute "SolverError"
+      if (theAttr->id() == "SolverError" && 
+          std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner())->getKind() == "Sketch")
+        return "";
+    }
+
     return "__notinitialized__";
   }
-  std::string aType = theAttr->attributeType();
-  std::ostringstream aResult;
   if (aType == ModelAPI_AttributeDocRef::typeId()) {
     AttributeDocRefPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDocRef>(theAttr);
     DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
@@ -143,7 +154,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
   } else if (aType == ModelAPI_AttributeDouble::typeId()) {
     AttributeDoublePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttr);
     if (anAttr->text().empty())
-      aResult<<anAttr->value();
+      aResult<<std::fixed<<setprecision(7)<<anAttr->value();
     else
       aResult<<anAttr->text();
   } else if (aType == ModelAPI_AttributeBoolean::typeId()) {
index b704f3f715d82c34a7574138b8ec9f9108607bd3..59508e767a1fea46bf378ffd159d97264777a9d1 100644 (file)
@@ -40,7 +40,7 @@ public:
 
   INTERFACE_3(SketchPlugin_Projection::ID(),
               externalFeature, SketchPlugin_Projection::EXTERNAL_FEATURE_ID(), ModelAPI_AttributeSelection, /** External feature */,
-              projectedFeature, SketchPlugin_Projection::EXTERNAL_FEATURE_ID(), ModelAPI_AttributeRefAttr, /** Projected feature */,
+              projectedFeature, SketchPlugin_Projection::PROJECTED_FEATURE_ID(), ModelAPI_AttributeRefAttr, /** Projected feature */,
               external, SketchPlugin_Projection::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */
   )
 
index 5690ddfd711f66d5e6dd6117809c863195f950c5..ad2e2b55d2e96fa4bd26b95d5b9cd8cee212be22 100644 (file)
@@ -236,16 +236,12 @@ std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(
 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
-  LinePtr aLine(new SketchAPI_Line(aFeature, theExternal));
-  setFixed(InterfacePtr(aLine));
-  return aLine;
+  return LinePtr(new SketchAPI_Line(aFeature, theExternal));
 }
 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID());
-  LinePtr aLine(new SketchAPI_Line(aFeature, theExternalName));
-  setFixed(InterfacePtr(aLine));
-  return aLine;
+  return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
 }
 
 //--------------------------------------------------------------------------------------
index eaf073c8b7702a9caeda15e061116fb724df09ee..85dade4280451efbcb8cefba8724157a992674d5 100644 (file)
@@ -187,6 +187,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     aCenterPnt->setValue(aCenterInSketch);
   }
 
+  aProjection->boolean(COPY_ID())->setValue(true);
   aProjection->execute();
   aRefAttr->setObject(aProjection);
 
index 593349f77ff4ab1b596205bd98919c6db7f7c8c8..ac56c287c20fbe718ed8beaa04d5bef1d220778e 100644 (file)
@@ -78,7 +78,7 @@ aEndPoint.setValue(100., 25.)
 aSketchLineB = aSketchFeature.addFeature("SketchLine")
 aStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
 aEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
-aStartPoint.setValue(-20., 15.)
+aStartPoint.setValue(-10., 15.)
 aEndPoint.setValue(80., 50.)
 aSession.finishOperation()
 #=========================================================================
@@ -97,10 +97,13 @@ assert (not refattrB.isInitialized())
 refattrA.setObject(aSketchLineA.firstResult())
 refattrB.setObject(aSketchLineB.firstResult())
 anAngleVal.setValue(ANGLE_DEGREE)
+aConstraint.execute()
+aSession.finishOperation()
+aSession.startOperation()
 aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
 aFlyoutPoint.setValue(50.0, 100.0)
-aConstraint.execute()
 aSession.finishOperation()
+aSession.abortOperation()
 assert (anAngleVal.isInitialized())
 assert (refattrA.isInitialized())
 assert (refattrB.isInitialized())
index 492ecb6fe65127fdbb046453d2f5e453225cda12..2d38a28f858a4388a4503c62fe6d7c94a595153f 100644 (file)
@@ -117,16 +117,12 @@ assert (math.fabs(aCircRadius - anArcRadius) <= 1.e-10)
 # A constraint to make equal radii of arc and external circle
 #=========================================================================
 aSession.startOperation()
-anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1"))
-assert(anExtCircRes)
-anExtCircShape = anExtCircRes.shape()
-assert(anExtCircShape)
 anExtCircle = aSketchFeature.addFeature("SketchCircle")
 anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("CircleCenter"))
 anExtCircleRadius = anExtCircle.real("CircleRadius")
 anExtCircleCenter.setValue(-50., 50.)
 anExtCircleRadius.setValue(10.)
-anExtCircle.selection("External").setValue(anExtCircRes, anExtCircShape)
+anExtCircle.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
 aSession.finishOperation()
 aSession.startOperation()
 aConstraintEqRad2 = aSketchFeature.addFeature("SketchConstraintEqual")
@@ -182,16 +178,12 @@ assert (math.fabs(aLine1Len - aLine2Len) < 1.e-10)
 # A constraint to make equal length of line with external line
 #=========================================================================
 aSession.startOperation()
-anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
-assert(anExtLineRes)
-anExtLineShape = anExtLineRes.shape()
-assert(anExtLineShape)
 anExtLine = aSketchFeature.addFeature("SketchLine")
 anExtLineStart = geomDataAPI_Point2D(anExtLine.attribute("StartPoint"))
 anExtLineEnd = geomDataAPI_Point2D(anExtLine.attribute("EndPoint"))
 anExtLineStart.setValue(-40., 35.)
 anExtLineEnd.setValue(-60., 25.)
-anExtLine.selection("External").setValue(anExtLineRes, anExtLineShape)
+anExtLine.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
 anExtLineLen = lineLength(anExtLine)
 aSession.finishOperation()
 aSession.startOperation()
index 69991a49a1d0de630b0c577d3efae282a6b23ea1..24762159ff842198eddc5b244a3465dc5c5e6ac4 100644 (file)
@@ -246,7 +246,7 @@ assert(anArc2CenterNew == anArc2CenterPrev)
 assert(anArc2StartPointNew == anArc2StartPointPrev)
 assert(anArc2EndPointNew == anArc2EndPointPrev)
 aSession.startOperation()
-aSketchFeature.removeFeature(aTangency)
+aDocument.removeFeature(aTangency)
 aSession.finishOperation()
 
 #=========================================================================
index 2ca48e60dcbcbded3d1e16058586d9c424681113..69a2d6fc18dcc0532014b397faea2aef809c344a 100644 (file)
@@ -103,13 +103,13 @@ def checkFillet(theObjects, theRadius):
 
     anArcPoints = []
     aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcStartPoint"))
-    print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
+    #print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
     anArcPoints.append((aPoint.x(), aPoint.y()))
     aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcEndPoint"))
-    print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
+    #print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
     anArcPoints.append((aPoint.x(), aPoint.y()))
     aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcCenter"))
-    print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
+    #print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
     aCenterX = aPoint.x()
     aCenterY = aPoint.y()
     aFilletRadius = math.hypot(anArcPoints[0][0]-aCenterX, anArcPoints[0][1]-aCenterY)
@@ -120,9 +120,9 @@ def checkFillet(theObjects, theRadius):
 
         aLinePoints = []
         aLinePoints.append((aStartPoint.x(), aStartPoint.y()))
-        print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
+        #print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
         aLinePoints.append((aEndPoint.x(), aEndPoint.y()))
-        print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
+        #print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
 
         aLineDirX = aEndPoint.x() - aStartPoint.x()
         aLineDirY = aEndPoint.y() - aStartPoint.y()
@@ -145,10 +145,10 @@ def checkFillet(theObjects, theRadius):
 
             aBaseArcPoints = []
             aBaseArcPoints.append((aStartPoint.x(), aStartPoint.y()))
-            print "anArcStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
+            #print "anArcStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
             aBaseArcPoints.append((aEndPoint.x(), aEndPoint.y()))
-            print "anArcEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
-            print "anArcCenter " + repr(aCenterPoint.x()) + " " + repr(aCenterPoint.y())
+            #print "anArcEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
+            #print "anArcCenter " + repr(aCenterPoint.x()) + " " + repr(aCenterPoint.y())
 
             aRadius = math.hypot(aStartPoint.x()-aCenterPoint.x(), aStartPoint.y()-aCenterPoint.y())
             aDist = math.hypot(aCenterPoint.x() - aCenterX, aCenterPoint.y() - aCenterY)
index 372bd4dad1b9d26967cabe967c9cf6cbcbd4df11..82075373941b56c8f5f03bbc14f4c920afbbd744 100644 (file)
@@ -41,6 +41,7 @@ def createNAngle(theSketch, theN, theRadius, theEdgeLength=0):
         anEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
         aStartPoint.setValue(begin[0], begin[1])
         anEndPoint.setValue(end[0], end[1])
+        aSketchLine.execute()
         allStartPoints.append(aStartPoint)
         allEndPoints.append(anEndPoint)
         allLines.append(aSketchLine)
index 0b89eca5fee9378ebc98f2f7ec090f95d5beaa4e..ee3151c430e805a7d029d7df1a85c1e3fcba54d6 100644 (file)
@@ -70,28 +70,16 @@ aSession.finishOperation()
 # Project all features onto the new sketch
 #=========================================================================
 aSession.startOperation()
-anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
-assert(anExtLineRes)
-anExtLineShape = anExtLineRes.shape()
-assert(anExtLineShape)
 aLineProjector = aSketchFeature.addFeature("SketchProjection")
-aLineProjector.selection("ExternalFeature").setValue(anExtLineRes, anExtLineShape)
+aLineProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
 aLineProjector.execute()
 
-anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1_2"))
-assert(anExtCircRes)
-anExtCircShape = anExtCircRes.shape()
-assert(anExtCircShape)
 aCircleProjector = aSketchFeature.addFeature("SketchProjection")
-aCircleProjector.selection("ExternalFeature").setValue(anExtCircRes, anExtCircShape)
+aCircleProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
 aCircleProjector.execute()
 
-anExtArcRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchArc_1_2"))
-assert(anExtArcRes)
-anExtArcShape = anExtArcRes.shape()
-assert(anExtArcShape)
 anArcProjector = aSketchFeature.addFeature("SketchProjection")
-anArcProjector.selection("ExternalFeature").setValue(anExtArcRes, anExtArcShape)
+anArcProjector.selection("ExternalFeature").selectSubShape("EDGE", "Sketch_1/Edge-SketchArc_1_2")
 anArcProjector.execute()
 aSession.finishOperation()
 #=========================================================================