Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRotation.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22       TestRotation.py
23       Unit test of FeaturesPlugin_Rotation class
24
25       class FeaturesPlugin_Movement : public ModelAPI_Feature
26         static const std::string MY_ROTATION_ID("Rotation");
27         static const std::string MY_OBJECTS_LIST_ID("main_objects");
28         static const std::string MY_AXIS_OBJECT_ID("axis_object");
29         static const std::string MY_ANGLE_ID("angle");
30
31         data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
32         data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
33         data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
34 """
35 #=========================================================================
36 # Initialization of the test
37 #=========================================================================
38 from ModelAPI import *
39 from GeomDataAPI import *
40 from GeomAlgoAPI import *
41 from GeomAPI import *
42 import math
43
44 aSession = ModelAPI_Session.get()
45 aDocument = aSession.moduleDocument()
46 # Create a part for movement
47 aSession.startOperation()
48 aPartFeature = aDocument.addFeature("Part")
49 aSession.finishOperation()
50 assert (len(aPartFeature.results()) == 1)
51 # Another way is:
52 # aPart = aSession.activeDocument()
53 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
54 aPart = aPartResult.partDoc()
55
56 #=========================================================================
57 # Create a sketch circle to extrude
58 #=========================================================================
59 aSession.startOperation()
60 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
61 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
62 origin.setValue(0, 0, 0)
63 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
64 dirx.setValue(1, 0, 0)
65 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
66 norm.setValue(0, 0, 1)
67 # Create circle
68 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
69 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
70 aCircleRadius = aSketchCircle.real("circle_radius")
71 anCircleCentr.setValue(50, 50)
72 aCircleRadius.setValue(20)
73 aSession.finishOperation()
74 #=========================================================================
75 # Make extrusion on circle
76 #=========================================================================
77 # Build shape from sketcher results
78 aCircleSketchResult = aCircleSketchFeature.firstResult()
79 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
80 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
81 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
82 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
83 aCircleSketchFaces = ShapeList()
84 GeomAlgoAPI_SketchBuilder.createFaces(
85     origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
86 assert (len(aCircleSketchFaces) > 0)
87 assert (aCircleSketchFaces[0] is not None)
88 # Create extrusion
89 aSession.startOperation()
90 anExtrusionFt = aPart.addFeature("Extrusion")
91 assert (anExtrusionFt.getKind() == "Extrusion")
92 # selection type FACE=4
93 anExtrusionFt.selectionList("base").append(
94     aCircleSketchResult, aCircleSketchFaces[0])
95 anExtrusionFt.string("CreationMethod").setValue("BySizes")
96 anExtrusionFt.real("to_size").setValue(50)
97 anExtrusionFt.real("from_size").setValue(0)
98 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
99 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
100 anExtrusionFt.execute()
101 aSession.finishOperation()
102 assert (anExtrusionFt.real("to_size").value() == 50)
103
104 # Check extrusion results
105 assert (len(anExtrusionFt.results()) > 0)
106 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
107 assert (anExtrusionResult is not None)
108
109 #=========================================================================
110 # Create a sketch line to rotation
111 #=========================================================================
112 aSession.startOperation()
113 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
114 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
115 origin.setValue(0, 0, 0)
116 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
117 dirx.setValue(1, 0, 0)
118 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
119 norm.setValue(0, 0, 1)
120
121 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
122 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
123 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
124 aLineStartPoint.setValue(-100, -100)
125 aLineEndPoint.setValue(100, -100)
126 aSession.finishOperation()
127
128 # Build shape from sketcher results
129 aLineSketchResult = aLineSketchFeature.firstResult()
130 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
131 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
132 aLineEdge = aShapeExplorer.current()
133
134 #=========================================================================
135 # Test rotation
136 #=========================================================================
137 aSession.startOperation()
138 aRotateFt = aPart.addFeature("Rotation")
139 assert (aRotateFt.getKind() == "Rotation")
140 aRotateFt.selectionList("main_objects").append(
141     anExtrusionResult, anExtrusionResult.shape())
142 aRotateFt.string("CreationMethod").setValue("ByAxisAndAngle")
143 aRotateFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
144 aRotateFt.real("angle").setValue(90)
145 aRotateFt.execute()
146 aSession.finishOperation()
147 assert (aRotateFt.real("angle").value() == 90)
148
149 # Check rotation results
150 aFactory = ModelAPI_Session.get().validators()
151 assert (aFactory.validate(aRotateFt))
152 assert (len(aRotateFt.results()) > 0)
153 aMoveResult = modelAPI_ResultBody(aRotateFt.firstResult())
154 assert (aMoveResult is not None)
155
156 from salome.shaper import model
157 assert(model.checkPythonDump())