X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestHighload.py;h=f745cdfa56eb1d48da1d8f93b3922f57973c84f7;hb=29e40e5c48e4ac68c20cfc0bf202d6e01f7fb2e3;hp=e2ca33704f282c6ca91de481213e40c869112a6a;hpb=1264006edf1221473f3a70ef31bcee6bbf78d23b;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py index e2ca33704..f745cdfa5 100644 --- a/src/SketchPlugin/Test/TestHighload.py +++ b/src/SketchPlugin/Test/TestHighload.py @@ -1,14 +1,87 @@ """ TestHighload.py """ +from GeomAPI import * from GeomDataAPI import * from ModelAPI import * -from GeomAPI import * +import math + + +#========================================================================= +# Useful subroutines +#========================================================================= +def distance(pointA, pointB): + """ + subroutine to calculate distance between two points + result of calculated distance is has 10**-5 precision + """ + xdiff = math.pow((pointA.x() - pointB.x()), 2) + ydiff = math.pow((pointA.y() - pointB.y()), 2) + return round(math.sqrt(xdiff + ydiff), 5) + + +def createNAngle(theSketch, theN, theRadius, theEdgeLength=0): + # Create an N-Angle at (0,0) + rad = 2. * math.pi / theN + points = [] + for a in xrange(theN): + x = round(math.cos(rad * a), 10) * theRadius + y = round(math.sin(rad * a), 10) * theRadius + points.append((x, y)) + # Close the contour + points.append(points[0]) + + # Create lines iterating over (A,B), (B,C), ... (N,A) + allStartPoints = [] + allEndPoints = [] + allLines = [] + for begin, end in zip(points[:-1], points[1:]): + aSketchLine = theSketch.addFeature("SketchLine") + aStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) + anEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) + aStartPoint.setValue(begin[0], begin[1]) + anEndPoint.setValue(end[0], end[1]) + allStartPoints.append(aStartPoint) + allEndPoints.append(anEndPoint) + allLines.append(aSketchLine) + theSketch.execute() + # Shift a start point to the end of list: + # (Bb, Cb, Ab) zip (Ae, Be, Ce) --> ((Ae, Bb), (Cb, Be), (Ab, Ce)) + allStartPoints.append(allStartPoints.pop(0)) + # Make lines coincident: + for pointA, pointB in zip(allStartPoints, allEndPoints): + aCoincidence = theSketch.addFeature("SketchConstraintCoincidence") + aCoincidence.refattr("ConstraintEntityA").setAttr(pointA) + aCoincidence.refattr("ConstraintEntityB").setAttr(pointB) + return allLines + + +def fixLineLength(theSketch, theLines, theEdgeLength=0): + aFirstLineLength = theEdgeLength + # Make give lines fixed length: + for aLine in theLines: + aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength") + refattrA = aLengthConstraint.refattr("ConstraintEntityA") + refattrA.setObject(modelAPI_ResultConstruction(aLine.firstResult())) + if aFirstLineLength == 0: + pointA = geomDataAPI_Point2D(aLine.attribute("StartPoint")) + pointB = geomDataAPI_Point2D(aLine.attribute("EndPoint")) + aFirstLineLength = distance(pointA, pointB) + aLengthConstraint.real("ConstraintValue").setValue(aFirstLineLength) + + +def moveTo(theLines, theDeltaX, theDeltaY): + for aLine in theLines: + aStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")) + anEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")) + aStart.setValue(aStart.x() + theDeltaX, aStart.y() + theDeltaY) + anEnd.setValue(anEnd.x() + theDeltaX, anEnd.y() + theDeltaY) + #========================================================================= # Initialization of the test #========================================================================= -__updated__ = "2014-11-21" +__updated__ = "2014-11-27" aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() @@ -17,20 +90,32 @@ aDocument = aSession.moduleDocument() #========================================================================= aSession.startOperation() aSketchCommonFeature = aDocument.addFeature("Sketch") -aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature) +aSketchFeature = featureToCompositeFeature(aSketchCommonFeature) origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) origin.setValue(0, 0, 0) dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) dirx.setValue(1, 0, 0) -diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY")) -diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) norm.setValue(0, 0, 1) aSession.finishOperation() #========================================================================= -# TODO: implement test +# Create 4x4 polygons N = {5, 21} #========================================================================= -assert (False) +deltaX = deltaY = 50. +n = 5 +aSession.startOperation() +for i in xrange(4): + for j in xrange(4): + allNangleLines = createNAngle(aSketchFeature, n, 50) + fixLineLength(aSketchFeature, allNangleLines) + moveTo(allNangleLines, deltaX, deltaY) + n += 1 + deltaX += 110. + deltaY += 110. + deltaX = 50. +aSession.finishOperation() + + #========================================================================= # End of test #=========================================================================