Salome HOME
Receive DoF from the solver. Update test cases to check DoF.
[modules/shaper.git] / src / SketchPlugin / Test / TestHighload.py
1 """
2     TestHighload.py
3 """
4 from GeomAPI import *
5 from GeomDataAPI import *
6 from ModelAPI import *
7 import math
8
9
10 #=========================================================================
11 # Useful subroutines
12 #=========================================================================
13 def distance(pointA, pointB):
14     """
15     subroutine to calculate distance between two points
16     result of calculated distance is has 10**-5 precision
17     """
18     xdiff = math.pow((pointA.x() - pointB.x()), 2)
19     ydiff = math.pow((pointA.y() - pointB.y()), 2)
20     return round(math.sqrt(xdiff + ydiff), 5)
21
22
23 def createNAngle(theSketch, theN, theRadius, theEdgeLength=0):
24     # Create an N-Angle at (0,0)
25     rad = 2. * math.pi / theN
26     points = []
27     for a in xrange(theN):
28         x = round(math.cos(rad * a), 10) * theRadius
29         y = round(math.sin(rad * a), 10) * theRadius
30         points.append((x, y))
31     # Close the contour
32     points.append(points[0])
33
34     # Create lines iterating over (A,B), (B,C), ... (N,A)
35     allStartPoints = []
36     allEndPoints = []
37     allLines = []
38     for begin, end in zip(points[:-1], points[1:]):
39         aSketchLine = theSketch.addFeature("SketchLine")
40         aStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
41         anEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
42         aStartPoint.setValue(begin[0], begin[1])
43         anEndPoint.setValue(end[0], end[1])
44         aSketchLine.execute()
45         allStartPoints.append(aStartPoint)
46         allEndPoints.append(anEndPoint)
47         allLines.append(aSketchLine)
48     theSketch.execute()
49     # Shift a start point to the end of list:
50     # (Bb, Cb, Ab) zip (Ae, Be, Ce) --> ((Ae, Bb), (Cb, Be), (Ab, Ce))
51     allStartPoints.append(allStartPoints.pop(0))
52     # Make lines coincident:
53     for pointA, pointB in zip(allStartPoints, allEndPoints):
54         aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
55         aCoincidence.refattr("ConstraintEntityA").setAttr(pointA)
56         aCoincidence.refattr("ConstraintEntityB").setAttr(pointB)
57     return allLines
58
59
60 def fixLineLength(theSketch, theLines, theEdgeLength=0):
61     aFirstLineLength = theEdgeLength
62     # Make give lines fixed length:
63     for aLine in theLines:
64         aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
65         refattrA = aLengthConstraint.refattr("ConstraintEntityA")
66         refattrA.setObject(modelAPI_ResultConstruction(aLine.firstResult()))
67         if aFirstLineLength == 0:
68             pointA = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
69             pointB = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
70             aFirstLineLength = distance(pointA, pointB)
71         aLengthConstraint.real("ConstraintValue").setValue(aFirstLineLength)
72
73
74 def moveTo(theLines, theDeltaX, theDeltaY):
75     for aLine in theLines:
76         aStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
77         anEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
78         aStart.setValue(aStart.x() + theDeltaX, aStart.y() + theDeltaY)
79         anEnd.setValue(anEnd.x() + theDeltaX, anEnd.y() + theDeltaY)
80
81 #=========================================================================
82 # Initialization of the test
83 #=========================================================================
84
85 __updated__ = "2014-11-27"
86
87 aSession = ModelAPI_Session.get()
88 aDocument = aSession.moduleDocument()
89 #=========================================================================
90 # Creation of a sketch
91 #=========================================================================
92 aSession.startOperation()
93 aSketchCommonFeature = aDocument.addFeature("Sketch")
94 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
95 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
96 origin.setValue(0, 0, 0)
97 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
98 dirx.setValue(1, 0, 0)
99 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
100 norm.setValue(0, 0, 1)
101 aSession.finishOperation()
102 #=========================================================================
103 # Create 4x4 polygons N = {5, 21}
104 #=========================================================================
105 aDOF = 0
106 deltaX = deltaY = 50.
107 n = 5
108 aSession.startOperation()
109 for i in xrange(4):
110     for j in xrange(4):
111         allNangleLines = createNAngle(aSketchFeature, n, 50)
112         fixLineLength(aSketchFeature, allNangleLines)
113         moveTo(allNangleLines, deltaX, deltaY)
114         aDOF += n
115         n += 1
116         deltaX += 110.
117     deltaY += 110.
118     deltaX = 50.
119 aSession.finishOperation()
120
121
122 #=========================================================================
123 # End of test
124 #=========================================================================
125
126 from salome.shaper import model
127 assert(model.dof(aSketchFeature) == aDOF)
128 assert(model.checkPythonDump())