From 94581487c6eb2ab39101070bb60fd6562903b989 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 17 Aug 2016 16:13:32 +0300 Subject: [PATCH] Fix errors and adjust unit tests --- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 6 +++--- src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp | 17 ++++++++++++++--- src/SketchAPI/SketchAPI_Projection.h | 2 +- src/SketchAPI/SketchAPI_Sketch.cpp | 8 ++------ src/SketchPlugin/SketchPlugin_Projection.cpp | 1 + src/SketchPlugin/Test/TestConstraintAngle.py | 7 +++++-- src/SketchPlugin/Test/TestConstraintEqual.py | 12 ++---------- src/SketchPlugin/Test/TestConstraintTangent.py | 2 +- src/SketchPlugin/Test/TestFillet.py | 16 ++++++++-------- src/SketchPlugin/Test/TestHighload.py | 1 + src/SketchPlugin/Test/TestProjection.py | 18 +++--------------- 11 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 32dbc5776..dfc6c389b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -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; } } diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index f45f90017..326f4a16b 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -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(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(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(theAttr); if (anAttr->text().empty()) - aResult<value(); + aResult<value(); else aResult<text(); } else if (aType == ModelAPI_AttributeBoolean::typeId()) { diff --git a/src/SketchAPI/SketchAPI_Projection.h b/src/SketchAPI/SketchAPI_Projection.h index b704f3f71..59508e767 100644 --- a/src/SketchAPI/SketchAPI_Projection.h +++ b/src/SketchAPI/SketchAPI_Projection.h @@ -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 */ ) diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 5690ddfd7..ad2e2b55d 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -236,16 +236,12 @@ std::shared_ptr SketchAPI_Sketch::addLine( std::shared_ptr SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal) { std::shared_ptr 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_Sketch::addLine(const std::string & theExternalName) { std::shared_ptr 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)); } //-------------------------------------------------------------------------------------- diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index eaf073c8b..85dade428 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -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); diff --git a/src/SketchPlugin/Test/TestConstraintAngle.py b/src/SketchPlugin/Test/TestConstraintAngle.py index 593349f77..ac56c287c 100644 --- a/src/SketchPlugin/Test/TestConstraintAngle.py +++ b/src/SketchPlugin/Test/TestConstraintAngle.py @@ -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()) diff --git a/src/SketchPlugin/Test/TestConstraintEqual.py b/src/SketchPlugin/Test/TestConstraintEqual.py index 492ecb6fe..2d38a28f8 100644 --- a/src/SketchPlugin/Test/TestConstraintEqual.py +++ b/src/SketchPlugin/Test/TestConstraintEqual.py @@ -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() diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index 69991a49a..24762159f 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -246,7 +246,7 @@ assert(anArc2CenterNew == anArc2CenterPrev) assert(anArc2StartPointNew == anArc2StartPointPrev) assert(anArc2EndPointNew == anArc2EndPointPrev) aSession.startOperation() -aSketchFeature.removeFeature(aTangency) +aDocument.removeFeature(aTangency) aSession.finishOperation() #========================================================================= diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index 2ca48e60d..69a2d6fc1 100644 --- a/src/SketchPlugin/Test/TestFillet.py +++ b/src/SketchPlugin/Test/TestFillet.py @@ -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) diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py index 372bd4dad..820753739 100644 --- a/src/SketchPlugin/Test/TestHighload.py +++ b/src/SketchPlugin/Test/TestHighload.py @@ -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) diff --git a/src/SketchPlugin/Test/TestProjection.py b/src/SketchPlugin/Test/TestProjection.py index 0b89eca5f..ee3151c43 100644 --- a/src/SketchPlugin/Test/TestProjection.py +++ b/src/SketchPlugin/Test/TestProjection.py @@ -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() #========================================================================= -- 2.30.2